civicrm_activity.activity_date_time,
civicrm_activity.status_id,
civicrm_activity.subject,
- civicrm_activity.source_contact_id,
+ ac.contact_id,
civicrm_activity.source_record_id,
civicrm_option_value.value as activity_type_id,
civicrm_option_value.label as activity_type,
AND ca.is_current_revision = 1';
if (CRM_Utils_Array::value('reporter_id', $params)) {
- $where .= " AND ca.source_contact_id = " . CRM_Utils_Type::escape($params['reporter_id'], 'Integer');
+ $where .= " AND cac.contact_id = " . CRM_Utils_Type::escape($params['reporter_id'], 'Integer');
}
if (CRM_Utils_Array::value('status_id', $params)) {
function from() {
$activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
$assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+ $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+ $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
+
return "
- civicrm_contact contact_a
- JOIN civicrm_activity activity
- ON contact_a.id = activity.source_contact_id
+ civicrm_activity activity
+ LEFT JOIN civicrm_activity_contact target
+ ON activity.id = target.activity_id AND target.record_type_id = {$targetID}
+ JOIN civicrm_contact contact_a
+ ON contact_a.id = target.contact_id
JOIN civicrm_option_value ov1
ON activity.activity_type_id = ov1.value AND ov1.option_group_id = 2
JOIN civicrm_option_value ov2
ON activity.status_id = ov2.value AND ov2.option_group_id = {$this->_groupId}
+ LEFT JOIN civicrm_activity_contact sourceContact
+ ON activity.id = sourceContact.activity_id AND sourceContact.record_type_id = {$sourceID}
JOIN civicrm_contact contact_b
- ON activity.source_contact_id = contact_b.id
+ ON sourceContact.contact_id = contact_b.id
LEFT JOIN civicrm_case_activity cca
ON activity.id = cca.activity_id
LEFT JOIN civicrm_activity_contact assignment
{$this->_aliases['civicrm_activity_assignment']}.record_type_id = {$assigneeID}
LEFT JOIN civicrm_activity_contact {$this->_aliases['civicrm_activity_source']}
ON {$this->_aliases['civicrm_activity']}.id = {$this->_aliases['civicrm_activity_source']}.activity_id AND
- {$this->_aliases['civicrm_activity_target']}.record_type_id = {$sourceID}
+ {$this->_aliases['civicrm_activity_source']}.record_type_id = {$sourceID}
LEFT JOIN civicrm_contact contact_civireport
ON {$this->_aliases['civicrm_activity_target']}.contact_id = contact_civireport.id
LEFT JOIN civicrm_contact civicrm_contact_assignee
}
function from() {
+ $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
+ $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+ $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+ $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
$this->_from = "
FROM civicrm_activity {$this->_aliases['civicrm_activity']}
- LEFT JOIN civicrm_activity_target target_activity
- ON {$this->_aliases['civicrm_activity']}.id = target_activity.activity_id
- LEFT JOIN civicrm_activity_assignment assignment_activity
- ON {$this->_aliases['civicrm_activity']}.id = assignment_activity.activity_id
- LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
- ON ({$this->_aliases['civicrm_activity']}.source_contact_id = {$this->_aliases['civicrm_contact']}.id OR
- target_activity.target_contact_id = {$this->_aliases['civicrm_contact']}.id OR
- assignment_activity.assignee_contact_id = {$this->_aliases['civicrm_contact']}.id )
+ LEFT JOIN civicrm_activity_contact target_activity
+ ON {$this->_aliases['civicrm_activity']}.id = target_activity.activity_id AND
+ target_activity.record_type_id = {$targetID}
+ LEFT JOIN civicrm_activity_contact assignment_activity
+ ON {$this->_aliases['civicrm_activity']}.id = assignment_activity.activity_id AND
+ assignment_activity.record_type_id = {$assigneeID}
+ LEFT JOIN civicrm_activity_contact source_activity
+ ON {$this->_aliases['civicrm_activity']}.id = source_activity.activity_id AND
+ source_activity.record_type_id = {$sourceID}
+ LEFT JOIN civicrm_contact contact_civireport
+ ON target_activity.contact_id = contact_civireport.id
+ LEFT JOIN civicrm_contact civicrm_contact_assignee
+ ON assignment_activity.contact_id = civicrm_contact_assignee.id
+ LEFT JOIN civicrm_contact civicrm_contact_source
+ ON source_activity.contact_id = civicrm_contact_source.id
{$this->_aclFrom}
LEFT JOIN civicrm_option_value
ON ( {$this->_aliases['civicrm_activity']}.activity_type_id = civicrm_option_value.value )
'dao' => 'CRM_Activity_DAO_Activity',
'fields' =>
array(
- 'source_contact_id' =>
- array('title' => ts('Contact ID'),
- 'default' => TRUE,
- 'no_display' => TRUE,
- ),
'activity_type_id' =>
array('title' => ts('Activity Type'),
'default' => TRUE,
'options' => $this->activityStatuses,
),
),
- 'group_bys' =>
+ ),
+ 'civicrm_activity_source' =>
array(
- 'source_contact_id' =>
- array('title' => ts('Totals Only'),
- 'default' => TRUE,
+ 'dao' => 'CRM_Activity_DAO_ActivityContact',
+ 'fields' =>
+ array(
+ 'contact_id' =>
+ array(
+ 'title' => ts('Contact ID'),
+ 'default' => TRUE,
+ 'no_display' => TRUE,
+ ),
),
- ),
- ),
+ 'group_bys' =>
+ array(
+ 'contact_id' =>
+ array('title' => ts('Totals Only'),
+ 'default' => TRUE,
+ ),
+ ),
+ 'grouping' => 'activity-fields',
+ ),
'civicrm_case_activity' =>
array(
'dao' => 'CRM_Case_DAO_CaseActivity',
$this->_from = "
FROM civicrm_activity {$this->_aliases['civicrm_activity']}
-
+ LEFT JOIN civicrm_activity_contact {$this->_aliases['civicrm_activity_source']}
+ ON {$this->_aliases['civicrm_activity']}.id = {$this->_aliases['civicrm_activity_source']}.activity_id
LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
- ON {$this->_aliases['civicrm_activity']}.source_contact_id = {$this->_aliases['civicrm_contact']}.id
+ ON {$this->_aliases['civicrm_activity_source']}.contact_id = {$this->_aliases['civicrm_contact']}.id
LEFT JOIN civicrm_case_activity {$this->_aliases['civicrm_case_activity']}
ON {$this->_aliases['civicrm_case_activity']}.activity_id = {$this->_aliases['civicrm_activity']}.id
";
array('title' => ts('Subject'),
'default' => TRUE,
),
- 'source_contact_id' =>
- array('title' => ts('Added By'),
- 'default' => TRUE,
- ),
'activity_date_time' =>
array('title' => ts('Activity Date'),
'default' => TRUE,
'dao' => 'CRM_Activity_DAO_ActivityContact',
'fields' =>
array(
- 'contact_id' =>
+ 'target_contact_id' =>
array('title' => ts('With Contact'),
+ 'name' => 'contact_id',
'default' => TRUE,
),
),
'dao' => 'CRM_Activity_DAO_ActivityContact',
'fields' =>
array(
- 'contact_id' =>
+ 'assignee_contact_id' =>
array('title' => ts('Assigned To'),
+ 'name' => 'contact_id',
'default' => TRUE,
),
),
'grouping' => 'activity-fields',
),
+ 'civicrm_activity_source' =>
+ array(
+ 'dao' => 'CRM_Activity_DAO_ActivityContact',
+ 'fields' =>
+ array(
+ 'source_contact_id' =>
+ array(
+ 'title' => ts('Added By'),
+ 'name' => 'contact_id',
+ 'default' => TRUE,
+ ),
+ ),
+ 'grouping' => 'activity-fields',
+ ),
'civicrm_group' =>
array(
'dao' => 'CRM_Contact_DAO_Group',
$this->_columnHeadersComponent[$table['alias']]["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array::value('title', $field);
}
elseif ($table['alias'] == $this->_aliases['civicrm_activity_target'] ||
- $table['alias'] == $this->_aliases['civicrm_activity_assignment']
+ $table['alias'] == $this->_aliases['civicrm_activity_assignment'] ||
+ $table['alias'] == $this->_aliases['civicrm_activity_source']
) {
if ($table['alias'] == $this->_aliases['civicrm_activity_target']) {
- $addContactId = 'civicrm_activity_target.contact_id';
+ $addContactId = 'civicrm_activity_target.contact_id as target_contact_id';
+ }
+ elseif ($table['alias'] == $this->_aliases['civicrm_activity_source']) {
+ $addContactId = 'civicrm_activity_source.contact_id';
}
else {
- $addContactId = 'civicrm_activity_assignment.contact_id';
+ $addContactId = 'civicrm_activity_assignment.contact_id as assignee_contact_id';
}
$tableName = $table['alias'];
$activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
$assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
$targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+ $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
$this->_formComponent['activity_civireport'] = "FROM
civicrm_activity {$this->_aliases['civicrm_activity']}
{$this->_aliases['civicrm_activity']}.id = civicrm_activity_target.activity_id AND
civicrm_activity_target.record_type_id = {$targetID}
LEFT JOIN civicrm_activity_contact civicrm_activity_assignment ON
- {$this->_aliases['civicrm_activity']}.id = civicrm_activity_assignment.activity_id AND civicrm_activity_assignment.record_type_id = {$assigneeID}
- LEFT JOIN civicrm_contact sourceContact ON
- {$this->_aliases['civicrm_activity']}.source_contact_id = sourceContact.id
+ {$this->_aliases['civicrm_activity']}.id = civicrm_activity_assignment.activity_id AND civicrm_activity_assignment.record_type_id = {$assigneeID}
+ LEFT JOIN civicrm_activity_contact civicrm_activity_source
+ ON {$this->_aliases['civicrm_activity']}.id = civicrm_activity_source.activity_id AND
+ civicrm_activity_source.record_type_id = {$sourceID}
LEFT JOIN civicrm_contact {$this->_aliases['civicrm_activity_target']} ON
civicrm_activity_target.contact_id = {$this->_aliases['civicrm_activity_target']}.id
LEFT JOIN civicrm_contact {$this->_aliases['civicrm_activity_assignment']} ON
civicrm_activity_assignment.contact_id = {$this->_aliases['civicrm_activity_assignment']}.id
+ LEFT JOIN civicrm_contact {$this->_aliases['civicrm_activity_source']} ON
+ civicrm_activity_source.contact_id = {$this->_aliases['civicrm_activity_source']}.id
LEFT JOIN civicrm_option_value ON
( {$this->_aliases['civicrm_activity']}.activity_type_id = civicrm_option_value.value )
LEFT JOIN civicrm_option_group ON
$val = 'activity_civireport';
$eligibleResult[$val] = $val;
$sql = "{$this->_selectComponent[$val]} ,
- sourceContact.display_name as added_by {$this->_formComponent[$val]}
+ {$this->_aliases['civicrm_activity_source']}.display_name as added_by {$this->_formComponent[$val]}
- WHERE ( {$this->_aliases['civicrm_activity']}.source_contact_id IN ($selectedContacts) OR
+ WHERE ( civicrm_activity_source.contact_id IN ($selectedContacts) OR
civicrm_activity_target.contact_id IN ($selectedContacts) OR
civicrm_activity_assignment.contact_id IN ($selectedContacts) OR
civicrm_case_contact.contact_id IN ($selectedContacts) ) AND