// If this contact has an open case, supply it as a default
$cid = CRM_Utils_Request::retrieve('cid', 'Integer');
if ($cid) {
- $cases = CRM_Case_BAO_Case::getUnclosedCases(array('contact_id' => $cid), $this->_currentCaseId);
- foreach ($cases as $id => $details) {
- $defaults['file_on_case_unclosed_case_id'] = $id;
- $value = array(
- 'label' => $details['sort_name'] . ' - ' . $details['case_type'],
- 'extra' => array('contact_id' => $cid),
- );
- $this->updateElementAttr('file_on_case_unclosed_case_id', array('data-value' => json_encode($value)));
+ $cases = civicrm_api3('CaseContact', 'get', array(
+ 'contact_id' => $cid,
+ 'case_id' => array('!=' => $this->_currentCaseId),
+ 'case_id.status_id' => array('!=' => "Closed"),
+ 'case_id.is_deleted' => 0,
+ 'case_id.end_date' => array('IS NULL' => 1),
+ 'options' => array('limit' => 1),
+ 'return' => 'case_id',
+ ));
+ foreach ($cases['values'] as $record) {
+ $defaults['file_on_case_unclosed_case_id'] = $record['case_id'];
break;
}
}
-
return $defaults;
}
* Build the form object.
*/
public function buildQuickForm() {
- $this->add('text', 'file_on_case_unclosed_case_id', ts('Select Case'), array('class' => 'huge'), TRUE);
+ $this->addEntityRef('file_on_case_unclosed_case_id', ts('Select Case'), array(
+ 'entity' => 'Case',
+ 'api' => array(
+ 'extra' => array('contact_id'),
+ 'params' => array(
+ 'case_id' => array('!=' => $this->_currentCaseId),
+ 'case_id.is_deleted' => 0,
+ 'case_id.status_id' => array('!=' => "Closed"),
+ 'case_id.end_date' => array('IS NULL' => 1),
+ ),
+ ),
+ ), TRUE);
$this->addEntityRef('file_on_case_target_contact_id', ts('With Contact(s)'), array('multiple' => TRUE));
$this->add('text', 'file_on_case_activity_subject', ts('Subject'), array('size' => 50));
}