'type' => CRM_Utils_Type::T_INT,
'FKClassName' => 'CRM_Case_DAO_Case',
'FKApiName' => 'Case',
+ 'supports_joins' => TRUE,
);
$params['contact_id'] = array(
'title' => 'Activity Contact ID',
}
$tagGet = array('tag_id', 'entity_id');
+ $caseGet = $caseIds = array();
foreach (array_keys($returns) as $key) {
if (strpos($key, 'tag_id.') === 0) {
$tagGet[] = $key;
$returns['tag_id'] = 1;
}
+ if (strpos($key, 'case_id.') === 0) {
+ $caseGet[] = str_replace('case_id.', '', $key);
+ $returns['case_id'] = 1;
+ }
}
foreach ($returns as $n => $v) {
array(1 => array(implode(',', array_keys($activities)), 'String', CRM_Core_DAO::QUERY_FORMAT_NO_QUOTES)));
while ($dao->fetch()) {
$activities[$dao->activity_id]['case_id'][] = $dao->case_id;
+ $caseIds[$dao->case_id] = $dao->case_id;
}
break;
}
}
+ // Fetch case fields via the join syntax
+ // Note this is limited to the first case if the activity belongs to more than one
+ if ($caseGet && $caseIds) {
+ $cases = civicrm_api3('Case', 'get', array(
+ 'id' => array('IN' => $caseIds),
+ 'options' => array('limit' => 0),
+ 'check_permissions' => !empty($params['check_permissions']),
+ 'return' => $caseGet,
+ ));
+ foreach ($activities as &$activity) {
+ if (!empty($activity['case_id'])) {
+ $case = CRM_Utils_Array::value($activity['case_id'][0], $cases['values']);
+ if ($case) {
+ foreach ($case as $key => $value) {
+ if ($key != 'id') {
+ $activity['case_id.' . $key] = $value;
+ }
+ }
+ }
+ }
+ }
+ }
+
// Legacy extras
if (!empty($params['contact_id'])) {
$statusOptions = CRM_Activity_BAO_Activity::buildOptions('status_id', 'get');