3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2013
35 class CRM_Report_Form_Activity
extends CRM_Report_Form
{
36 protected $_selectAliasesTotal = array();
38 protected $_customGroupExtends = array(
42 protected $_nonDisplayFields = array();
44 function __construct() {
45 // There could be multiple contacts. We not clear on which contact id to display.
46 // Lets hide it for now.
47 $this->_exposeContactID
= FALSE;
49 $config = CRM_Core_Config
::singleton();
50 $campaignEnabled = in_array("CiviCampaign", $config->enableComponents
);
51 if ($campaignEnabled) {
52 $getCampaigns = CRM_Campaign_BAO_Campaign
::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE);
53 $this->activeCampaigns
= $getCampaigns['campaigns'];
54 asort($this->activeCampaigns
);
55 $this->engagementLevels
= CRM_Campaign_PseudoConstant
::engagementLevel();
57 $this->activityTypes
= CRM_Core_PseudoConstant
::activityType(TRUE, FALSE, FALSE, 'label', TRUE);
58 asort($this->activityTypes
);
60 $this->_columns
= array(
63 'dao' => 'CRM_Contact_DAO_Contact',
68 'name' => 'sort_name',
69 'title' => ts('Source Contact Name'),
70 'alias' => 'civicrm_contact_source',
75 'name' => 'sort_name',
76 'title' => ts('Assignee Contact Name'),
77 'alias' => 'civicrm_contact_assignee',
78 'dbAlias' => "civicrm_contact_assignee.sort_name",
83 'name' => 'sort_name',
84 'title' => ts('Target Contact Name'),
85 'alias' => 'civicrm_contact_target',
86 'dbAlias' => "civicrm_contact_target.sort_name",
89 'contact_source_id' =>
92 'alias' => 'civicrm_contact_source',
93 'dbAlias' => "civicrm_contact_source.id",
98 'contact_assignee_id' =>
101 'alias' => 'civicrm_contact_assignee',
102 'dbAlias' => "civicrm_contact_assignee.id",
103 'no_display' => TRUE,
107 'contact_target_id' =>
110 'alias' => 'civicrm_contact_target',
111 'dbAlias' => "civicrm_contact_target.id",
112 'no_display' => TRUE,
121 'name' => 'sort_name',
122 'alias' => 'civicrm_contact_source',
123 'title' => ts('Source Contact Name'),
124 'operator' => 'like',
125 'type' => CRM_Report_Form
::OP_STRING
,
127 'contact_assignee' =>
129 'name' => 'sort_name',
130 'alias' => 'civicrm_contact_assignee',
131 'title' => ts('Assignee Contact Name'),
132 'operator' => 'like',
133 'type' => CRM_Report_Form
::OP_STRING
,
137 'name' => 'sort_name',
138 'alias' => 'civicrm_contact_target',
139 'title' => ts('Target Contact Name'),
140 'operator' => 'like',
141 'type' => CRM_Report_Form
::OP_STRING
,
145 'name' => 'current_user',
146 'title' => ts('Limit To Current User'),
147 'type' => CRM_Utils_Type
::T_INT
,
148 'operatorType' => CRM_Report_Form
::OP_SELECT
,
149 'options' => array('0' => ts('No'), '1' => ts('Yes')),
152 'grouping' => 'contact-fields',
156 'dao' => 'CRM_Core_DAO_Email',
159 'contact_source_email' =>
162 'title' => ts('Source Contact Email'),
163 'alias' => 'civicrm_email_source',
165 'contact_assignee_email' =>
168 'title' => ts('Assignee Contact Email'),
169 'alias' => 'civicrm_email_assignee',
171 'contact_target_email' =>
174 'title' => ts('Target Contact Email'),
175 'alias' => 'civicrm_email_target',
180 'source_contact_email' =>
183 'title' => ts('Source Contact Email'),
184 'dbAlias' => 'civicrm_email_contact_source_email',
188 'civicrm_activity' =>
190 'dao' => 'CRM_Activity_DAO_Activity',
195 'no_display' => TRUE,
196 'title' => ts('Activity ID'),
199 'source_record_id' =>
201 'no_display' => TRUE,
204 'activity_type_id' =>
205 array('title' => ts('Activity Type'),
207 'type' => CRM_Utils_Type
::T_STRING
,
209 'activity_subject' =>
210 array('title' => ts('Subject'),
213 'activity_date_time' =>
214 array('title' => ts('Activity Date'),
218 array('title' => ts('Activity Status'),
220 'type' => CRM_Utils_Type
::T_STRING
,
223 array('title' => ts('Duration'),
224 'type' => CRM_Utils_Type
::T_INT
,
229 'activity_date_time' =>
231 'default' => 'this.month',
232 'operatorType' => CRM_Report_Form
::OP_DATE
,
234 'activity_subject' =>
235 array('title' => ts('Activity Subject')),
236 'activity_type_id' =>
237 array('title' => ts('Activity Type'),
238 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
239 'options' => $this->activityTypes
,
242 array('title' => ts('Activity Status'),
243 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
244 'options' => CRM_Core_PseudoConstant
::activityStatus(),
249 'activity_date_time' =>
250 array('title' => ts('Activity Date'), 'default_weight' => '1', 'dbAlias' => 'civicrm_activity_activity_date_time'),
251 'activity_type_id' =>
252 array('title' => ts('Activity Type'), 'default_weight' => '2', 'dbAlias' => 'civicrm_activity_activity_type_id'),
254 'grouping' => 'activity-fields',
255 'alias' => 'activity',
257 'civicrm_activity_contact' =>
259 'dao' => 'CRM_Activity_DAO_ActivityContact',
262 // so we have $this->_alias populated
265 ) +
$this->addAddressFields(FALSE, TRUE);
267 if ($campaignEnabled) {
268 // Add display column and filter for Survey Results, Campaign and Engagement Index if CiviCampaign is enabled
270 $this->_columns
['civicrm_activity']['fields']['result'] = array(
271 'title' => 'Survey Result',
272 'default' => 'false',
274 $this->_columns
['civicrm_activity']['filters']['result'] = array('title' => ts('Survey Result'),
275 'operator' => 'like',
276 'type' => CRM_Utils_Type
::T_STRING
,
278 if (!empty($this->activeCampaigns
)) {
279 $this->_columns
['civicrm_activity']['fields']['campaign_id'] = array(
280 'title' => 'Campaign',
281 'default' => 'false',
283 $this->_columns
['civicrm_activity']['filters']['campaign_id'] = array('title' => ts('Campaign'),
284 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
285 'options' => $this->activeCampaigns
,
288 if (!empty($this->engagementLevels
)) {
289 $this->_columns
['civicrm_activity']['fields']['engagement_level'] = array(
290 'title' => 'Engagement Index',
291 'default' => 'false',
293 $this->_columns
['civicrm_activity']['filters']['engagement_level'] = array('title' => ts('Engagement Index'),
294 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
295 'options' => $this->engagementLevels
,
299 $this->_groupFilter
= TRUE;
300 $this->_tagFilter
= TRUE;
301 parent
::__construct();
304 function select($recordType = NULL) {
305 if (!array_key_exists("contact_{$recordType}", $this->_params
['fields']) && $recordType != 'final') {
306 $this->_nonDisplayFields
[] = "civicrm_contact_contact_{$recordType}";
307 $this->_params
['fields']["contact_{$recordType}"] = 1;
311 if ($recordType == 'final' && !empty($this->_nonDisplayFields
)) {
312 foreach ($this->_nonDisplayFields
as $fieldName) {
313 unset($this->_columnHeaders
[$fieldName]);
317 if (empty($this->_selectAliasesTotal
)) {
318 $this->_selectAliasesTotal
= $this->_selectAliases
;
321 $removeKeys = array();
322 if ($recordType == 'target') {
323 foreach ($this->_selectClauses
as $key => $clause) {
324 if (strstr($clause, 'civicrm_contact_assignee.') ||
325 strstr($clause, 'civicrm_contact_source.') ||
326 strstr($clause, 'civicrm_email_assignee.') ||
327 strstr($clause, 'civicrm_email_source.')
329 $removeKeys[] = $key;
330 unset($this->_selectClauses
[$key]);
333 } else if ($recordType == 'assignee') {
334 foreach ($this->_selectClauses
as $key => $clause) {
335 if (strstr($clause, 'civicrm_contact_target.') ||
336 strstr($clause, 'civicrm_contact_source.') ||
337 strstr($clause, 'civicrm_email_target.') ||
338 strstr($clause, 'civicrm_email_source.')
340 $removeKeys[] = $key;
341 unset($this->_selectClauses
[$key]);
344 } else if ($recordType == 'source') {
345 foreach ($this->_selectClauses
as $key => $clause) {
346 if (strstr($clause, 'civicrm_contact_target.') ||
347 strstr($clause, 'civicrm_contact_assignee.') ||
348 strstr($clause, 'civicrm_email_target.') ||
349 strstr($clause, 'civicrm_email_assignee.')
351 $removeKeys[] = $key;
352 unset($this->_selectClauses
[$key]);
355 } else if ($recordType == 'final') {
356 $this->_selectClauses
= $this->_selectAliasesTotal
;
357 foreach ($this->_selectClauses
as $key => $clause) {
358 if (strstr($clause, 'civicrm_contact_contact_target') ||
359 strstr($clause, 'civicrm_contact_contact_assignee') ||
360 strstr($clause, 'civicrm_contact_contact_source') ) {
361 $this->_selectClauses
[$key] = "GROUP_CONCAT($clause SEPARATOR ';') as $clause";
367 foreach ($removeKeys as $key) {
368 unset($this->_selectAliases
[$key]);
371 $this->_select
= "SELECT " . implode(', ', $this->_selectClauses
) . " ";
375 function from($recordType) {
376 $activityContacts = CRM_Core_OptionGroup
::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
377 $assigneeID = CRM_Utils_Array
::key('Activity Assignees', $activityContacts);
378 $targetID = CRM_Utils_Array
::key('Activity Targets', $activityContacts);
379 $sourceID = CRM_Utils_Array
::key('Activity Source', $activityContacts);
381 if ($recordType == 'target') {
383 FROM civicrm_activity {$this->_aliases['civicrm_activity']}
384 INNER JOIN civicrm_activity_contact {$this->_aliases['civicrm_activity_contact']}
385 ON {$this->_aliases['civicrm_activity']}.id = {$this->_aliases['civicrm_activity_contact']}.activity_id AND
386 {$this->_aliases['civicrm_activity_contact']}.record_type_id = {$targetID}
387 INNER JOIN civicrm_contact civicrm_contact_target
388 ON {$this->_aliases['civicrm_activity_contact']}.contact_id = civicrm_contact_target.id
391 if ($this->isTableSelected('civicrm_email')) {
393 LEFT JOIN civicrm_email civicrm_email_target
394 ON {$this->_aliases['civicrm_activity_contact']}.contact_id = civicrm_email_target.contact_id AND
395 civicrm_email_target.is_primary = 1";
397 $this->_aliases
['civicrm_contact'] = 'civicrm_contact_target';
400 if ($recordType == 'assignee') {
402 FROM civicrm_activity {$this->_aliases['civicrm_activity']}
403 INNER JOIN civicrm_activity_contact {$this->_aliases['civicrm_activity_contact']}
404 ON {$this->_aliases['civicrm_activity']}.id = {$this->_aliases['civicrm_activity_contact']}.activity_id AND
405 {$this->_aliases['civicrm_activity_contact']}.record_type_id = {$assigneeID}
406 INNER JOIN civicrm_contact civicrm_contact_assignee
407 ON {$this->_aliases['civicrm_activity_contact']}.contact_id = civicrm_contact_assignee.id
410 if ($this->isTableSelected('civicrm_email')) {
412 LEFT JOIN civicrm_email civicrm_email_assignee
413 ON {$this->_aliases['civicrm_activity_contact']}.contact_id = civicrm_email_assignee.contact_id AND
414 civicrm_email_assignee.is_primary = 1";
416 $this->_aliases
['civicrm_contact'] = 'civicrm_contact_assignee';
419 if ($recordType == 'source') {
421 FROM civicrm_activity {$this->_aliases['civicrm_activity']}
422 INNER JOIN civicrm_activity_contact {$this->_aliases['civicrm_activity_contact']}
423 ON {$this->_aliases['civicrm_activity']}.id = {$this->_aliases['civicrm_activity_contact']}.activity_id AND
424 {$this->_aliases['civicrm_activity_contact']}.record_type_id = {$sourceID}
425 INNER JOIN civicrm_contact civicrm_contact_source
426 ON {$this->_aliases['civicrm_activity_contact']}.contact_id = civicrm_contact_source.id
429 if ($this->isTableSelected('civicrm_email')) {
431 LEFT JOIN civicrm_email civicrm_email_source
432 ON {$this->_aliases['civicrm_activity_contact']}.contact_id = civicrm_email_source.contact_id AND
433 civicrm_email_source.is_primary = 1";
435 $this->_aliases
['civicrm_contact'] = 'civicrm_contact_source';
437 $this->addAddressFromClause();
440 function where($recordType = NULL) {
441 $this->_where
= " WHERE {$this->_aliases['civicrm_activity']}.is_test = 0 AND
442 {$this->_aliases['civicrm_activity']}.is_deleted = 0 AND
443 {$this->_aliases['civicrm_activity']}.is_current_revision = 1";
446 foreach ($this->_columns
as $tableName => $table) {
447 if (array_key_exists('filters', $table)) {
449 foreach ($table['filters'] as $fieldName => $field) {
451 if ($fieldName != 'contact_' . $recordType &&
452 (strstr($fieldName, '_target') ||
453 strstr($fieldName, '_assignee') ||
454 strstr($fieldName, '_source')
459 if (CRM_Utils_Array
::value('type', $field) & CRM_Utils_Type
::T_DATE
) {
460 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
461 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
462 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
464 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
467 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
468 if ($op && ($op != 'nnll' ||
$op != 'nll')) {
469 $clause = $this->whereClause($field,
471 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
472 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
473 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
478 if ($field['name'] == 'current_user') {
479 if (CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
) == 1) {
481 $session = CRM_Core_Session
::singleton();
482 if ($contactID = $session->get('userID')) {
483 $clause = "{$this->_aliases['civicrm_activity_contact']}.activity_id IN
484 (SELECT activity_id FROM civicrm_activity_contact WHERE contact_id = {$contactID})";
494 if (!empty($clause)) {
495 $clauses[] = $clause;
501 if (empty($clauses)) {
502 $this->_where
.= " ";
505 $this->_where
.= " AND " . implode(' AND ', $clauses);
508 if ($this->_aclWhere
) {
509 $this->_where
.= " AND {$this->_aclWhere} ";
514 $this->_groupBy
= "GROUP BY {$this->_aliases['civicrm_activity']}.id";
517 function buildACLClause($tableAlias = 'contact_a') {
518 //override for ACL( Since Contact may be source
519 //contact/assignee or target also it may be null )
521 if (CRM_Core_Permission
::check('view all contacts')) {
522 $this->_aclFrom
= $this->_aclWhere
= NULL;
526 $session = CRM_Core_Session
::singleton();
527 $contactID = $session->get('userID');
531 $contactID = CRM_Utils_Type
::escape($contactID, 'Integer');
533 CRM_Contact_BAO_Contact_Permission
::cache($contactID);
535 foreach ($tableAlias as $k => $alias) {
536 $clauses[] = " INNER JOIN civicrm_acl_contact_cache aclContactCache_{$k} ON ( {$alias}.id = aclContactCache_{$k}.contact_id OR {$alias}.id IS NULL ) AND aclContactCache_{$k}.user_id = $contactID ";
539 $this->_aclFrom
= implode(" ", $clauses);
540 $this->_aclWhere
= NULL;
543 function add2group($groupID) {
544 if (CRM_Utils_Array
::value("contact_target_op", $this->_params
) == 'nll') {
545 CRM_Core_Error
::fatal(ts('Current filter criteria didn\'t have any target contact to add to group'));
548 $query = "{$this->_select}
549 FROM civireport_activity_temp_target tar
550 GROUP BY civicrm_activity_id {$this->_having} {$this->_orderBy}";
551 $select = 'AS addtogroup_contact_id';
552 $query = str_ireplace('AS civicrm_contact_contact_target_id', $select, $query);
553 $dao = CRM_Core_DAO
::executeQuery($query);
555 $contactIDs = array();
556 // Add resulting contacts to group
557 while ($dao->fetch()) {
558 if ($dao->addtogroup_contact_id
) {
559 $contact_id = explode(';', $dao->addtogroup_contact_id
);
560 if ($contact_id[0]) {
561 $contactIDs[$contact_id[0]] = $contact_id[0];
566 if ( !empty($contactIDs) ) {
567 CRM_Contact_BAO_GroupContact
::addContactsToGroup($contactIDs, $groupID);
568 CRM_Core_Session
::setStatus(ts("Listed contact(s) have been added to the selected group."), ts('Contacts Added'), 'success');
571 CRM_Core_Session
::setStatus(ts("The listed records(s) cannot be added to the group."));
575 function postProcess() {
576 $this->buildACLClause(array('civicrm_contact_source', 'civicrm_contact_target', 'civicrm_contact_assignee'));
577 $this->beginPostProcess();
579 //Assign those recordtype to array which have filter operator as 'Is not empty' or 'Is empty'
580 $nullFilters = array();
581 foreach (array('target', 'source', 'assignee') as $type) {
582 if (CRM_Utils_Array
::value("contact_{$type}_op", $this->_params
) == 'nnll' ||
!empty($this->_params
["contact_{$type}_value"])) {
583 $nullFilters[] = " civicrm_contact_contact_{$type} IS NOT NULL ";
585 else if (CRM_Utils_Array
::value("contact_{$type}_op", $this->_params
) == 'nll') {
586 $nullFilters[] = " civicrm_contact_contact_{$type} IS NULL ";
590 // 1. fill temp table with target results
591 $this->select('target');
592 $this->from('target');
593 $this->customDataFrom();
594 $this->where('target');
595 $insertCols = implode(',', $this->_selectAliases
);
596 $tempQuery = "CREATE TEMPORARY TABLE civireport_activity_temp_target CHARACTER SET utf8 COLLATE utf8_unicode_ci AS
597 {$this->_select} {$this->_from} {$this->_where} ";
598 CRM_Core_DAO
::executeQuery($tempQuery);
600 // 2. add new columns to hold assignee and source results
601 // fixme: add when required
603 ALTER TABLE civireport_activity_temp_target
604 ADD COLUMN civicrm_contact_contact_assignee VARCHAR(128),
605 ADD COLUMN civicrm_contact_contact_source VARCHAR(128),
606 ADD COLUMN civicrm_contact_contact_assignee_id VARCHAR(128),
607 ADD COLUMN civicrm_contact_contact_source_id VARCHAR(128),
608 ADD COLUMN civicrm_email_contact_assignee_email VARCHAR(128),
609 ADD COLUMN civicrm_email_contact_source_email VARCHAR(128)";
610 CRM_Core_DAO
::executeQuery($tempQuery);
612 // 3. fill temp table with assignee results
613 $this->select('assignee');
614 $this->from('assignee');
615 $this->customDataFrom();
616 $this->where('assignee');
617 $insertCols = implode(',', $this->_selectAliases
);
618 $tempQuery = "INSERT INTO civireport_activity_temp_target ({$insertCols})
620 {$this->_from} {$this->_where}";
621 CRM_Core_DAO
::executeQuery($tempQuery);
623 // 4. fill temp table with source results
624 $this->select('source');
625 $this->from('source');
626 $this->customDataFrom();
627 $this->where('source');
628 $insertCols = implode(',', $this->_selectAliases
);
629 $tempQuery = "INSERT INTO civireport_activity_temp_target ({$insertCols})
631 {$this->_from} {$this->_where}";
632 CRM_Core_DAO
::executeQuery($tempQuery);
634 // 5. show final result set from temp table
636 $this->select('final');
638 if (!empty($nullFilters)) {
639 $this->_having
= "HAVING " . implode(' AND ', $nullFilters);
643 $sql = "{$this->_select}
644 FROM civireport_activity_temp_target tar
645 GROUP BY civicrm_activity_id {$this->_having} {$this->_orderBy} {$this->_limit}";
646 $this->buildRows($sql, $rows);
648 // format result set.
649 $this->formatDisplay($rows);
651 // assign variables to templates
652 $this->doTemplateAssignment($rows);
654 // do print / pdf / instance stuff if needed
655 $this->endPostProcess($rows);
658 function alterDisplay(&$rows) {
659 // custom code to alter rows
662 $activityType = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, FALSE, 'label', TRUE);
663 $activityStatus = CRM_Core_PseudoConstant
::activityStatus();
665 $seperator = CRM_Core_DAO
::VALUE_SEPARATOR
;
666 $context = CRM_Utils_Request
::retrieve('context', 'String', $this, FALSE, 'report');
668 if (CRM_Core_Permission
::check('access CiviCRM')) {
670 $onHover = ts('View Contact Summary for this Contact');
671 $onHoverAct = ts('View Activity Record');
674 foreach ($rows as $rowNum => $row) {
675 if (array_key_exists('civicrm_contact_contact_source', $row)) {
676 if ($value = $row['civicrm_contact_contact_source_id']) {
678 $url = CRM_Utils_System
::url("civicrm/contact/view",
679 'reset=1&cid=' . $value,
682 $rows[$rowNum]['civicrm_contact_contact_source_link'] = $url;
683 $rows[$rowNum]['civicrm_contact_contact_source_hover'] = $onHover;
689 if (array_key_exists('civicrm_contact_contact_assignee', $row)) {
690 $assigneeNames = explode(';', $row['civicrm_contact_contact_assignee']);
691 if ($value = $row['civicrm_contact_contact_assignee_id']) {
692 $assigneeContactIds = explode(';', $value);
695 foreach ($assigneeContactIds as $id => $value) {
696 if (isset($value) && isset($assigneeNames[$id])) {
697 $url = CRM_Utils_System
::url("civicrm/contact/view",
698 'reset=1&cid=' . $value,
701 $link[] = "<a title='" . $onHover . "' href='" . $url . "'>{$assigneeNames[$id]}</a>";
704 $rows[$rowNum]['civicrm_contact_contact_assignee'] = implode('; ', $link);
710 if (array_key_exists('civicrm_contact_contact_target', $row)) {
711 $targetNames = explode(';', $row['civicrm_contact_contact_target']);
712 if ($value = $row['civicrm_contact_contact_target_id']) {
713 $targetContactIds = explode(';', $value);
716 foreach ($targetContactIds as $id => $value) {
717 if (isset($value) && isset($targetNames[$id])) {
718 $url = CRM_Utils_System
::url("civicrm/contact/view",
719 'reset=1&cid=' . $value,
722 $link[] = "<a title='" . $onHover . "' href='" . $url . "'>{$targetNames[$id]}</a>";
725 $rows[$rowNum]['civicrm_contact_contact_target'] = implode('; ', $link);
731 if (array_key_exists('civicrm_activity_activity_type_id', $row)) {
732 if ($value = $row['civicrm_activity_activity_type_id']) {
733 $rows[$rowNum]['civicrm_activity_activity_type_id'] = $activityType[$value];
735 // Check for target contact id(s) and use the first contact id in that list for view activity link if found,
736 // else use source contact id
737 if (!empty($rows[$rowNum]['civicrm_contact_contact_target_id'])) {
738 $targets = explode(';', $rows[$rowNum]['civicrm_contact_contact_target_id']);
742 $cid = $rows[$rowNum]['civicrm_contact_contact_source_id'];
745 $actionLinks = CRM_Activity_Selector_Activity
::actionLinks($row['civicrm_activity_activity_type_id'],
746 CRM_Utils_Array
::value('civicrm_activity_source_record_id', $rows[$rowNum]),
748 $rows[$rowNum]['civicrm_activity_id']
752 'id' => $rows[$rowNum]['civicrm_activity_id'],
756 $url = CRM_Utils_System
::url($actionLinks[CRM_Core_Action
::VIEW
]['url'],
757 CRM_Core_Action
::replace($actionLinks[CRM_Core_Action
::VIEW
]['qs'], $linkValues), TRUE
759 $rows[$rowNum]['civicrm_activity_activity_type_id_link'] = $url;
760 $rows[$rowNum]['civicrm_activity_activity_type_id_hover'] = $onHoverAct;
766 if (array_key_exists('civicrm_activity_status_id', $row)) {
767 if ($value = $row['civicrm_activity_status_id']) {
768 $rows[$rowNum]['civicrm_activity_status_id'] = $activityStatus[$value];
773 if (array_key_exists('civicrm_activity_campaign_id', $row)) {
774 if ($value = $row['civicrm_activity_campaign_id']) {
775 $rows[$rowNum]['civicrm_activity_campaign_id'] = $this->activeCampaigns
[$value];
780 if (array_key_exists('civicrm_activity_engagement_level', $row)) {
781 if ($value = $row['civicrm_activity_engagement_level']) {
782 $rows[$rowNum]['civicrm_activity_engagement_level'] = $this->engagementLevels
[$value];
787 if (array_key_exists('civicrm_activity_activity_date_time', $row) && array_key_exists('civicrm_activity_status_id', $row)) {
788 if (CRM_Utils_Date
::overdue($rows[$rowNum]['civicrm_activity_activity_date_time']) &&
789 $activityStatus[$row['civicrm_activity_status_id']] != 'Completed'
791 $rows[$rowNum]['class'] = "status-overdue";
796 $entryFound = $this->alterDisplayAddressFields($row, $rows, $rowNum, 'activity', 'List all activities for this ') ?
TRUE : $entryFound;