$tableFields = array(
'activity_id' => 'int unsigned',
'activity_date_time' => 'datetime',
+ 'source_record_id' => 'int unsigned',
'status_id' => 'int unsigned',
'subject' => 'varchar(255)',
'source_contact_name' => 'varchar(255)',
$insertSQL = "INSERT INTO {$activityTempTable} (" . implode(',', $insertValueSQL) . " ) ";
$order = $limit = $groupBy = '';
+ $groupBy = " GROUP BY tbl.activity_id ";
if (!empty($input['sort'])) {
if (is_a($input['sort'], 'CRM_Utils_Sort')) {
$activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
$sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
$sourceJoin = "
-INNER JOIN civicrm_activity_contact ac ON ac.activity_id = civicrm_activity.id AND record_type_id = {$sourceID}
+INNER JOIN civicrm_activity_contact ac ON ac.activity_id = civicrm_activity.id
INNER JOIN civicrm_contact contact ON ac.contact_id = contact.id
";
if (!$input['count']) {
$sourceSelect = ',
civicrm_activity.activity_date_time,
+ civicrm_activity.source_record_id,
civicrm_activity.status_id,
civicrm_activity.subject,
contact.sort_name as source_contact_name,
civicrm_activity.campaign_id as campaign_id
';
+ $sourceJoin .= "
+LEFT JOIN civicrm_activity_contact src ON (src.activity_id = ac.activity_id AND src.record_type_id = {$sourceID} AND src.contact_id = contact.id)
+";
}
$sourceClause = "
if (!$input['count']) {
$caseSelect = ',
civicrm_activity.activity_date_time,
+ civicrm_activity.source_record_id,
civicrm_activity.status_id,
civicrm_activity.subject,
- ac.contact_id,
contact.sort_name as source_contact_name,
civicrm_option_value.value as activity_type_id,
civicrm_option_value.label as activity_type,