Merge pull request #1521 from yashodha/4.4.CRM-13212
[civicrm-core.git] / CRM / Report / Form / Activity.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2013
32 * $Id$
33 *
34 */
35 class CRM_Report_Form_Activity extends CRM_Report_Form {
36
37 protected $_customGroupExtends = array(
38 'Activity'
39 );
40
41 function __construct() {
42 $config = CRM_Core_Config::singleton();
43 $campaignEnabled = in_array("CiviCampaign", $config->enableComponents);
44 if ($campaignEnabled) {
45 $getCampaigns = CRM_Campaign_BAO_Campaign::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE);
46 $this->activeCampaigns = $getCampaigns['campaigns'];
47 asort($this->activeCampaigns);
48 $this->engagementLevels = CRM_Campaign_PseudoConstant::engagementLevel();
49 }
50 $this->activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, FALSE, FALSE, 'label', TRUE);
51 asort($this->activityTypes);
52
53 $this->_columns = array(
54 'civicrm_contact' =>
55 array(
56 'dao' => 'CRM_Contact_DAO_Contact',
57 'fields' =>
58 array(
59 'contact_source' =>
60 array(
61 'name' => 'sort_name',
62 'title' => ts('Source Contact Name'),
63 'alias' => 'civicrm_contact_source',
64 'no_repeat' => TRUE,
65 ),
66 'contact_assignee' =>
67 array(
68 'name' => 'sort_name',
69 'title' => ts('Assignee Contact Name'),
70 'alias' => 'civicrm_contact_assignee',
71 'default' => TRUE,
72 ),
73 'contact_target' =>
74 array(
75 'name' => 'sort_name',
76 'title' => ts('Target Contact Name'),
77 'alias' => 'contact_civireport',
78 'default' => TRUE,
79 ),
80 ),
81 'filters' =>
82 array(
83 'contact_source' =>
84 array(
85 'name' => 'sort_name',
86 'alias' => 'civicrm_contact_source',
87 'title' => ts('Source Contact Name'),
88 'operator' => 'like',
89 'type' => CRM_Report_Form::OP_STRING,
90 ),
91 'contact_assignee' =>
92 array(
93 'name' => 'sort_name',
94 'alias' => 'civicrm_contact_assignee',
95 'title' => ts('Assignee Contact Name'),
96 'operator' => 'like',
97 'type' => CRM_Report_Form::OP_STRING,
98 ),
99 'contact_target' =>
100 array(
101 'name' => 'sort_name',
102 'alias' => 'contact_civireport',
103 'title' => ts('Target Contact Name'),
104 'operator' => 'like',
105 'type' => CRM_Report_Form::OP_STRING,
106 ),
107 'current_user' =>
108 array(
109 'name' => 'current_user',
110 'title' => ts('Limit To Current User'),
111 'type' => CRM_Utils_Type::T_INT,
112 'operatorType' => CRM_Report_Form::OP_SELECT,
113 'options' => array('0' => ts('No'), '1' => ts('Yes')),
114 ),
115 ),
116 'grouping' => 'contact-fields',
117 ),
118 'civicrm_email' =>
119 array(
120 'dao' => 'CRM_Core_DAO_Email',
121 'fields' =>
122 array(
123 'contact_source_email' =>
124 array(
125 'name' => 'email',
126 'title' => ts('Source Contact Email'),
127 'alias' => 'civicrm_email_source',
128 ),
129 'contact_assignee_email' =>
130 array(
131 'name' => 'email',
132 'title' => ts('Assignee Contact Email'),
133 'alias' => 'civicrm_email_assignee',
134 ),
135 'contact_target_email' =>
136 array(
137 'name' => 'email',
138 'title' => ts('Target Contact Email'),
139 'alias' => 'civicrm_email_target',
140 ),
141 ),
142 'order_bys' =>
143 array(
144 'source_contact_email' =>
145 array(
146 'name' => 'email',
147 'title' => ts('Source Contact Email'),
148 'alias' => 'civicrm_email_source',
149 ),
150 ),
151 ),
152 'civicrm_activity' =>
153 array(
154 'dao' => 'CRM_Activity_DAO_Activity',
155 'fields' =>
156 array(
157 'id' =>
158 array(
159 'no_display' => TRUE,
160 'required' => TRUE,
161 ),
162 'source_record_id' =>
163 array(
164 'no_display' => TRUE,
165 'required' => TRUE,
166 ),
167 'activity_type_id' =>
168 array('title' => ts('Activity Type'),
169 'default' => TRUE,
170 'type' => CRM_Utils_Type::T_STRING,
171 ),
172 'activity_subject' =>
173 array('title' => ts('Subject'),
174 'default' => TRUE,
175 ),
176 'activity_date_time' =>
177 array('title' => ts('Activity Date'),
178 'default' => TRUE,
179 ),
180 'status_id' =>
181 array('title' => ts('Activity Status'),
182 'default' => TRUE,
183 'type' => CRM_Utils_Type::T_STRING,
184 ),
185 'duration' =>
186 array('title' => ts('Duration'),
187 'type' => CRM_Utils_Type::T_INT,
188 ),
189 ),
190 'filters' =>
191 array(
192 'activity_date_time' =>
193 array(
194 'default' => 'this.month',
195 'operatorType' => CRM_Report_Form::OP_DATE,
196 ),
197 'activity_subject' =>
198 array('title' => ts('Activity Subject')),
199 'activity_type_id' =>
200 array('title' => ts('Activity Type'),
201 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
202 'options' => $this->activityTypes,
203 ),
204 'status_id' =>
205 array('title' => ts('Activity Status'),
206 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
207 'options' => CRM_Core_PseudoConstant::activityStatus(),
208 ),
209 ),
210 'order_bys' =>
211 array(
212 'source_contact_id' =>
213 array('title' => ts('Source Contact'), 'default_weight' => '0'),
214 'activity_date_time' =>
215 array('title' => ts('Activity Date'), 'default_weight' => '1'),
216 'activity_type_id' =>
217 array('title' => ts('Activity Type'), 'default_weight' => '2'),
218 ),
219 'grouping' => 'activity-fields',
220 'alias' => 'activity',
221 ),
222 'civicrm_activity_assignment' =>
223 array(
224 'dao' => 'CRM_Activity_DAO_ActivityContact',
225 'fields' =>
226 array(
227 'contact_id' =>
228 array(
229 'no_display' => TRUE,
230 'required' => TRUE,
231 ),
232 ),
233 'alias' => 'activity_assignment',
234 ),
235 'civicrm_activity_target' =>
236 array(
237 'dao' => 'CRM_Activity_DAO_ActivityContact',
238 'fields' =>
239 array(
240 'contact_id' =>
241 array(
242 'no_display' => TRUE,
243 'required' => TRUE,
244 ),
245 ),
246 'alias' => 'activity_target',
247 ),
248 'civicrm_activity_source' =>
249 array(
250 'dao' => 'CRM_Activity_DAO_ActivityContact',
251 'fields' =>
252 array(
253 'contact_id' =>
254 array(
255 'no_display' => TRUE,
256 'required' => TRUE,
257 ),
258 ),
259 'alias' => 'activity_source',
260 ),
261
262 'civicrm_case_activity' =>
263 array(
264 'dao' => 'CRM_Case_DAO_CaseActivity',
265 'fields' =>
266 array(
267 'case_id' =>
268 array(
269 'name' => 'case_id',
270 'no_display' => TRUE,
271 'required' => TRUE,
272 ),
273 ),
274 'alias' => 'case_activity',
275 ),
276 ) + $this->addAddressFields(FALSE, TRUE);
277
278 if ($campaignEnabled) {
279 // Add display column and filter for Survey Results, Campaign and Engagement Index if CiviCampaign is enabled
280
281 $this->_columns['civicrm_activity']['fields']['result'] = array(
282 'title' => 'Survey Result',
283 'default' => 'false',
284 );
285 $this->_columns['civicrm_activity']['filters']['result'] = array('title' => ts('Survey Result'),
286 'operator' => 'like',
287 'type' => CRM_Utils_Type::T_STRING,
288 );
289 if (!empty($this->activeCampaigns)) {
290 $this->_columns['civicrm_activity']['fields']['campaign_id'] = array(
291 'title' => 'Campaign',
292 'default' => 'false',
293 );
294 $this->_columns['civicrm_activity']['filters']['campaign_id'] = array('title' => ts('Campaign'),
295 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
296 'options' => $this->activeCampaigns,
297 );
298 }
299 if (!empty($this->engagementLevels)) {
300 $this->_columns['civicrm_activity']['fields']['engagement_level'] = array(
301 'title' => 'Engagement Index',
302 'default' => 'false',
303 );
304 $this->_columns['civicrm_activity']['filters']['engagement_level'] = array('title' => ts('Engagement Index'),
305 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
306 'options' => $this->engagementLevels,
307 );
308 }
309 }
310 $this->_groupFilter = TRUE;
311 $this->_tagFilter = TRUE;
312 parent::__construct();
313 }
314
315 function select() {
316 $select = array();
317 $seperator = CRM_CORE_DAO::VALUE_SEPARATOR;
318 $this->_columnHeaders = array();
319 foreach ($this->_columns as $tableName => $table) {
320 if (array_key_exists('fields', $table)) {
321 foreach ($table['fields'] as $fieldName => $field) {
322 if (CRM_Utils_Array::value('required', $field) ||
323 CRM_Utils_Array::value($fieldName, $this->_params['fields'])
324 ) {
325
326 if (isset($this->_params['group_bys']) &&
327 !CRM_Utils_Array::value('activity_type_id', $this->_params['group_bys']) &&
328 (in_array($fieldName, array(
329 'contact_assignee', 'assignee_contact_id')) ||
330 in_array($fieldName, array('contact_target', 'target_contact_id'))
331 )
332 ) {
333 $orderByRef = "activity_assignment_civireport.contact_id";
334 if (in_array($fieldName, array(
335 'contact_target', 'target_contact_id'))) {
336 $orderByRef = "activity_target_civireport.contact_id";
337 }
338 $select[] = "GROUP_CONCAT(DISTINCT {$field['dbAlias']} ORDER BY {$orderByRef} SEPARATOR '{$seperator}') as {$tableName}_{$fieldName}";
339 }
340 else {
341 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
342 }
343 $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field);
344 $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array::value('title', $field);
345 $this->_columnHeaders["{$tableName}_{$fieldName}"]['no_display'] = CRM_Utils_Array::value('no_display', $field);
346 }
347 }
348 }
349 }
350
351 $this->_select = "SELECT " . implode(', ', $select) . " ";
352 }
353
354 function from() {
355 $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
356 $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
357 $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
358 $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
359 $this->_from = "
360 FROM civicrm_activity {$this->_aliases['civicrm_activity']}
361
362 LEFT JOIN civicrm_activity_contact {$this->_aliases['civicrm_activity_target']}
363 ON {$this->_aliases['civicrm_activity']}.id = {$this->_aliases['civicrm_activity_target']}.activity_id AND
364 {$this->_aliases['civicrm_activity_target']}.record_type_id = {$targetID}
365 LEFT JOIN civicrm_activity_contact {$this->_aliases['civicrm_activity_assignment']}
366 ON {$this->_aliases['civicrm_activity']}.id = {$this->_aliases['civicrm_activity_assignment']}.activity_id AND
367 {$this->_aliases['civicrm_activity_assignment']}.record_type_id = {$assigneeID}
368 LEFT JOIN civicrm_activity_contact {$this->_aliases['civicrm_activity_source']}
369 ON {$this->_aliases['civicrm_activity']}.id = {$this->_aliases['civicrm_activity_source']}.activity_id AND
370 {$this->_aliases['civicrm_activity_source']}.record_type_id = {$sourceID}
371 LEFT JOIN civicrm_contact contact_civireport
372 ON {$this->_aliases['civicrm_activity_target']}.contact_id = contact_civireport.id
373 LEFT JOIN civicrm_contact civicrm_contact_assignee
374 ON {$this->_aliases['civicrm_activity_assignment']}.contact_id = civicrm_contact_assignee.id
375 LEFT JOIN civicrm_contact civicrm_contact_source
376 ON {$this->_aliases['civicrm_activity_source']}.contact_id = civicrm_contact_source.id
377 {$this->_aclFrom}
378 LEFT JOIN civicrm_option_value
379 ON ( {$this->_aliases['civicrm_activity']}.activity_type_id = civicrm_option_value.value )
380 LEFT JOIN civicrm_option_group
381 ON civicrm_option_group.id = civicrm_option_value.option_group_id
382 LEFT JOIN civicrm_case_activity case_activity_civireport
383 ON case_activity_civireport.activity_id = {$this->_aliases['civicrm_activity']}.id
384 LEFT JOIN civicrm_case
385 ON case_activity_civireport.case_id = civicrm_case.id
386 LEFT JOIN civicrm_case_contact
387 ON civicrm_case_contact.case_id = civicrm_case.id ";
388
389 if ($this->isTableSelected('civicrm_email')) {
390 $this->_from .= "
391 LEFT JOIN civicrm_email civicrm_email_source
392 ON {$this->_aliases['civicrm_activity_source']}.contact_id = civicrm_email_source.contact_id AND
393 civicrm_email_source.is_primary = 1
394
395 LEFT JOIN civicrm_email civicrm_email_target
396 ON {$this->_aliases['civicrm_activity_target']}.contact_id = civicrm_email_target.contact_id AND
397 civicrm_email_target.is_primary = 1
398
399 LEFT JOIN civicrm_email civicrm_email_assignee
400 ON {$this->_aliases['civicrm_activity_assignment']}.contact_id = civicrm_email_assignee.contact_id AND
401 civicrm_email_assignee.is_primary = 1 ";
402 }
403 $this->addAddressFromClause();
404 }
405
406 function where() {
407 $this->_where = " WHERE civicrm_option_group.name = 'activity_type' AND
408 {$this->_aliases['civicrm_activity']}.is_test = 0 AND
409 {$this->_aliases['civicrm_activity']}.is_deleted = 0 AND
410 {$this->_aliases['civicrm_activity']}.is_current_revision = 1";
411
412 $clauses = array();
413 foreach ($this->_columns as $tableName => $table) {
414 if (array_key_exists('filters', $table)) {
415
416 foreach ($table['filters'] as $fieldName => $field) {
417 $clause = NULL;
418 if (CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE) {
419 $relative = CRM_Utils_Array::value("{$fieldName}_relative", $this->_params);
420 $from = CRM_Utils_Array::value("{$fieldName}_from", $this->_params);
421 $to = CRM_Utils_Array::value("{$fieldName}_to", $this->_params);
422
423 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
424 }
425 else {
426 $op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params);
427 if ($op) {
428 $clause = $this->whereClause($field,
429 $op,
430 CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
431 CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
432 CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
433 );
434 }
435 }
436
437 if ($field['name'] == 'current_user') {
438 if (CRM_Utils_Array::value("{$fieldName}_value", $this->_params) == 1) {
439 // get current user
440 $session = CRM_Core_Session::singleton();
441 if ($contactID = $session->get('userID')) {
442 $clause = "( civicrm_contact_source.id = " . $contactID . " OR civicrm_contact_assignee.id = " . $contactID . " OR contact_civireport.id = " . $contactID . " )";
443 }
444 else {
445 $clause = NULL;
446 }
447 }
448 else {
449 $clause = NULL;
450 }
451 }
452 if (!empty($clause)) {
453 $clauses[] = $clause;
454 }
455 }
456 }
457 }
458
459 if (empty($clauses)) {
460 $this->_where .= " ";
461 }
462 else {
463 $this->_where .= " AND " . implode(' AND ', $clauses);
464 }
465
466 if ($this->_aclWhere) {
467 $this->_where .= " AND {$this->_aclWhere} ";
468 }
469 }
470
471 function groupBy() {
472 $this->_groupBy = "GROUP BY {$this->_aliases['civicrm_activity']}.id";
473 }
474
475 function buildACLClause($tableAlias = 'contact_a') {
476 //override for ACL( Since Contact may be source
477 //contact/assignee or target also it may be null )
478
479 if (CRM_Core_Permission::check('view all contacts')) {
480 $this->_aclFrom = $this->_aclWhere = NULL;
481 return;
482 }
483
484 $session = CRM_Core_Session::singleton();
485 $contactID = $session->get('userID');
486 if (!$contactID) {
487 $contactID = 0;
488 }
489 $contactID = CRM_Utils_Type::escape($contactID, 'Integer');
490
491 CRM_Contact_BAO_Contact_Permission::cache($contactID);
492 $clauses = array();
493 foreach ($tableAlias as $k => $alias) {
494 $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 ";
495 }
496
497 $this->_aclFrom = implode(" ", $clauses);
498 $this->_aclWhere = NULL;
499 }
500
501 function postProcess() {
502
503 $this->buildACLClause(array('civicrm_contact_source', 'contact_civireport', 'civicrm_contact_assignee'));
504 parent::postProcess();
505 }
506
507 function alterDisplay(&$rows) {
508 // custom code to alter rows
509
510 $entryFound = FALSE;
511 $activityType = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE);
512 $activityStatus = CRM_Core_PseudoConstant::activityStatus();
513 $viewLinks = FALSE;
514 $seperator = CRM_CORE_DAO::VALUE_SEPARATOR;
515 $context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'report');
516
517 if (CRM_Core_Permission::check('access CiviCRM')) {
518 $viewLinks = TRUE;
519 $onHover = ts('View Contact Summary for this Contact');
520 $onHoverAct = ts('View Activity Record');
521 }
522
523 foreach ($rows as $rowNum => $row) {
524 if (array_key_exists('civicrm_contact_contact_source', $row)) {
525 if ($value = $row['civicrm_activity_assignment_contact_id']) {
526 if ($viewLinks) {
527 $url = CRM_Utils_System::url("civicrm/contact/view",
528 'reset=1&cid=' . $value,
529 $this->_absoluteUrl
530 );
531 $rows[$rowNum]['civicrm_contact_contact_source_link'] = $url;
532 $rows[$rowNum]['civicrm_contact_contact_source_hover'] = $onHover;
533 }
534 $entryFound = TRUE;
535 }
536 }
537
538 if (array_key_exists('civicrm_contact_contact_assignee', $row)) {
539 $assigneeNames = explode($seperator, $row['civicrm_contact_contact_assignee']);
540 if ($value = $row['civicrm_activity_assignment_contact_id']) {
541 $assigneeContactIds = explode($seperator, $value);
542 $link = array();
543 if ($viewLinks) {
544 foreach ($assigneeContactIds as $id => $value) {
545 $url = CRM_Utils_System::url("civicrm/contact/view",
546 'reset=1&cid=' . $value,
547 $this->_absoluteUrl
548 );
549 $link[] = "<a title='" . $onHover . "' href='" . $url . "'>{$assigneeNames[$id]}</a>";
550 }
551 $rows[$rowNum]['civicrm_contact_contact_assignee'] = implode('; ', $link);
552 }
553 $entryFound = TRUE;
554 }
555 }
556
557 if (array_key_exists('civicrm_contact_contact_target', $row)) {
558 $targetNames = explode($seperator, $row['civicrm_contact_contact_target']);
559 if ($value = $row['civicrm_activity_target_contact_id']) {
560 $targetContactIds = explode($seperator, $value);
561 $link = array();
562 if ($viewLinks) {
563 foreach ($targetContactIds as $id => $value) {
564 $url = CRM_Utils_System::url("civicrm/contact/view",
565 'reset=1&cid=' . $value,
566 $this->_absoluteUrl
567 );
568 $link[] = "<a title='" . $onHover . "' href='" . $url . "'>{$targetNames[$id]}</a>";
569 }
570 $rows[$rowNum]['civicrm_contact_contact_target'] = implode('; ', $link);
571 }
572 $entryFound = TRUE;
573 }
574 }
575
576 if (array_key_exists('civicrm_activity_activity_type_id', $row)) {
577 if ($value = $row['civicrm_activity_activity_type_id']) {
578 $rows[$rowNum]['civicrm_activity_activity_type_id'] = $activityType[$value];
579 if ($viewLinks) {
580 // Check for target contact id(s) and use the first contact id in that list for view activity link if found,
581 // else use source contact id
582 if (!empty($rows[$rowNum]['civicrm_activity_target_target_contact_id'])) {
583 $targets = explode($seperator, $rows[$rowNum]['civicrm_activity_target_target_contact_id']);
584 $cid = $targets[0];
585 }
586 else {
587 $cid = $rows[$rowNum]['civicrm_activity_source_contact_id'];
588 }
589
590 $actionLinks = CRM_Activity_Selector_Activity::actionLinks($row['civicrm_activity_activity_type_id'],
591 CRM_Utils_Array::value('civicrm_activity_source_record_id', $rows[$rowNum]),
592 FALSE,
593 $rows[$rowNum]['civicrm_activity_id']
594 );
595
596 $linkValues = array(
597 'id' => $rows[$rowNum]['civicrm_activity_id'],
598 'cid' => $cid,
599 'cxt' => $context,
600 );
601 $url = CRM_Utils_System::url($actionLinks[CRM_Core_Action::VIEW]['url'],
602 CRM_Core_Action::replace($actionLinks[CRM_Core_Action::VIEW]['qs'], $linkValues), TRUE
603 );
604 $rows[$rowNum]['civicrm_activity_activity_type_id_link'] = $url;
605 $rows[$rowNum]['civicrm_activity_activity_type_id_hover'] = $onHoverAct;
606 }
607 $entryFound = TRUE;
608 }
609 }
610
611 if (array_key_exists('civicrm_activity_status_id', $row)) {
612 if ($value = $row['civicrm_activity_status_id']) {
613 $rows[$rowNum]['civicrm_activity_status_id'] = $activityStatus[$value];
614 $entryFound = TRUE;
615 }
616 }
617
618 if (array_key_exists('civicrm_activity_campaign_id', $row)) {
619 if ($value = $row['civicrm_activity_campaign_id']) {
620 $rows[$rowNum]['civicrm_activity_campaign_id'] = $this->activeCampaigns[$value];
621 $entryFound = TRUE;
622 }
623 }
624
625 if (array_key_exists('civicrm_activity_engagement_level', $row)) {
626 if ($value = $row['civicrm_activity_engagement_level']) {
627 $rows[$rowNum]['civicrm_activity_engagement_level'] = $this->engagementLevels[$value];
628 $entryFound = TRUE;
629 }
630 }
631
632 if (array_key_exists('civicrm_activity_activity_date_time', $row) && array_key_exists('civicrm_activity_status_id', $row)) {
633 if (CRM_Utils_Date::overdue($rows[$rowNum]['civicrm_activity_activity_date_time']) &&
634 $activityStatus[$row['civicrm_activity_status_id']] != 'Completed'
635 ) {
636 $rows[$rowNum]['class'] = "status-overdue";
637 $entryFound = TRUE;
638 }
639 }
640
641 $entryFound = $this->alterDisplayAddressFields($row, $rows, $rowNum, 'activity', 'List all activities for this ') ? TRUE : $entryFound;
642
643 if (!$entryFound) {
644 break;
645 }
646 }
647 }
648
649
650 /*
651 * Add Target Contact Address into From Table if required
652 */
653 function addAddressFromClause() {
654 // include address field if address column is to be included
655 if ((isset($this->_addressField) &&
656 $this->_addressField
657 ) ||
658 $this->isTableSelected('civicrm_address')
659 ) {
660 $this->_from .= "
661 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
662 ON ({$this->_aliases['civicrm_activity_target']}.contact_id =
663 {$this->_aliases['civicrm_address']}.contact_id) AND
664 {$this->_aliases['civicrm_address']}.is_primary = 1\n";
665 }
666 }
667 }
668