Merge pull request #1875 from mlutfy/crm13354
[civicrm-core.git] / CRM / Report / Form / Activity.php
CommitLineData
6a488035 1<?php
6a488035
TO
2/*
3 +--------------------------------------------------------------------+
232624b1 4 | CiviCRM version 4.4 |
6a488035
TO
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 */
35class CRM_Report_Form_Activity extends CRM_Report_Form {
1f220d30 36 protected $_selectAliasesTotal = array();
6a488035
TO
37
38 protected $_customGroupExtends = array(
430ae6dd
TO
39 'Activity'
40 );
41
42 function __construct() {
83e74860
DS
43 // There could be multiple contacts. We not clear on which contact id to display.
44 // Lets hide it for now.
45 $this->_exposeContactID = FALSE;
46
6a488035
TO
47 $config = CRM_Core_Config::singleton();
48 $campaignEnabled = in_array("CiviCampaign", $config->enableComponents);
49 if ($campaignEnabled) {
50 $getCampaigns = CRM_Campaign_BAO_Campaign::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE);
51 $this->activeCampaigns = $getCampaigns['campaigns'];
52 asort($this->activeCampaigns);
53 $this->engagementLevels = CRM_Campaign_PseudoConstant::engagementLevel();
54 }
55 $this->activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, FALSE, FALSE, 'label', TRUE);
56 asort($this->activityTypes);
57
58 $this->_columns = array(
59 'civicrm_contact' =>
60 array(
61 'dao' => 'CRM_Contact_DAO_Contact',
62 'fields' =>
63 array(
6a488035
TO
64 'contact_source' =>
65 array(
66 'name' => 'sort_name',
67 'title' => ts('Source Contact Name'),
68 'alias' => 'civicrm_contact_source',
69 'no_repeat' => TRUE,
70 ),
71 'contact_assignee' =>
72 array(
73 'name' => 'sort_name',
74 'title' => ts('Assignee Contact Name'),
75 'alias' => 'civicrm_contact_assignee',
1f220d30 76 'dbAlias' => "civicrm_contact_assignee.sort_name",
6a488035
TO
77 'default' => TRUE,
78 ),
79 'contact_target' =>
80 array(
81 'name' => 'sort_name',
82 'title' => ts('Target Contact Name'),
2f4b4d54 83 'alias' => 'civicrm_contact_target',
1f220d30 84 'dbAlias' => "civicrm_contact_target.sort_name",
6a488035
TO
85 'default' => TRUE,
86 ),
87 ),
88 'filters' =>
89 array(
90 'contact_source' =>
91 array(
92 'name' => 'sort_name',
93 'alias' => 'civicrm_contact_source',
94 'title' => ts('Source Contact Name'),
95 'operator' => 'like',
96 'type' => CRM_Report_Form::OP_STRING,
97 ),
98 'contact_assignee' =>
99 array(
100 'name' => 'sort_name',
101 'alias' => 'civicrm_contact_assignee',
102 'title' => ts('Assignee Contact Name'),
103 'operator' => 'like',
104 'type' => CRM_Report_Form::OP_STRING,
105 ),
106 'contact_target' =>
107 array(
108 'name' => 'sort_name',
2f4b4d54 109 'alias' => 'civicrm_contact_target',
6a488035
TO
110 'title' => ts('Target Contact Name'),
111 'operator' => 'like',
112 'type' => CRM_Report_Form::OP_STRING,
113 ),
114 'current_user' =>
115 array(
116 'name' => 'current_user',
117 'title' => ts('Limit To Current User'),
118 'type' => CRM_Utils_Type::T_INT,
119 'operatorType' => CRM_Report_Form::OP_SELECT,
120 'options' => array('0' => ts('No'), '1' => ts('Yes')),
121 ),
122 ),
123 'grouping' => 'contact-fields',
124 ),
125 'civicrm_email' =>
126 array(
127 'dao' => 'CRM_Core_DAO_Email',
128 'fields' =>
129 array(
130 'contact_source_email' =>
131 array(
132 'name' => 'email',
133 'title' => ts('Source Contact Email'),
134 'alias' => 'civicrm_email_source',
135 ),
136 'contact_assignee_email' =>
137 array(
138 'name' => 'email',
139 'title' => ts('Assignee Contact Email'),
140 'alias' => 'civicrm_email_assignee',
141 ),
142 'contact_target_email' =>
143 array(
144 'name' => 'email',
145 'title' => ts('Target Contact Email'),
146 'alias' => 'civicrm_email_target',
147 ),
148 ),
149 'order_bys' =>
150 array(
151 'source_contact_email' =>
152 array(
153 'name' => 'email',
154 'title' => ts('Source Contact Email'),
83e74860 155 'dbAlias' => 'civicrm_email_contact_source_email',
6a488035
TO
156 ),
157 ),
158 ),
159 'civicrm_activity' =>
160 array(
161 'dao' => 'CRM_Activity_DAO_Activity',
162 'fields' =>
163 array(
164 'id' =>
165 array(
83e74860 166 'no_display' => TRUE,
2f4b4d54 167 'title' => ts('Activity ID'),
1f220d30 168 'required' => TRUE,
6a488035
TO
169 ),
170 'source_record_id' =>
171 array(
172 'no_display' => TRUE,
173 'required' => TRUE,
174 ),
175 'activity_type_id' =>
176 array('title' => ts('Activity Type'),
177 'default' => TRUE,
178 'type' => CRM_Utils_Type::T_STRING,
179 ),
180 'activity_subject' =>
181 array('title' => ts('Subject'),
182 'default' => TRUE,
183 ),
6a488035
TO
184 'activity_date_time' =>
185 array('title' => ts('Activity Date'),
186 'default' => TRUE,
187 ),
188 'status_id' =>
189 array('title' => ts('Activity Status'),
190 'default' => TRUE,
191 'type' => CRM_Utils_Type::T_STRING,
192 ),
193 'duration' =>
194 array('title' => ts('Duration'),
195 'type' => CRM_Utils_Type::T_INT,
196 ),
197 ),
198 'filters' =>
199 array(
200 'activity_date_time' =>
201 array(
202 'default' => 'this.month',
203 'operatorType' => CRM_Report_Form::OP_DATE,
204 ),
205 'activity_subject' =>
206 array('title' => ts('Activity Subject')),
207 'activity_type_id' =>
208 array('title' => ts('Activity Type'),
209 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
210 'options' => $this->activityTypes,
211 ),
212 'status_id' =>
213 array('title' => ts('Activity Status'),
214 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
215 'options' => CRM_Core_PseudoConstant::activityStatus(),
216 ),
217 ),
218 'order_bys' =>
219 array(
6a488035 220 'activity_date_time' =>
83e74860 221 array('title' => ts('Activity Date'), 'default_weight' => '1', 'dbAlias' => 'civicrm_activity_activity_date_time'),
6a488035 222 'activity_type_id' =>
83e74860 223 array('title' => ts('Activity Type'), 'default_weight' => '2', 'dbAlias' => 'civicrm_activity_activity_type_id'),
6a488035
TO
224 ),
225 'grouping' => 'activity-fields',
226 'alias' => 'activity',
227 ),
1f220d30 228 'civicrm_activity_contact' =>
6a488035 229 array(
38ba593b 230 'dao' => 'CRM_Activity_DAO_ActivityContact',
6a488035
TO
231 'fields' =>
232 array(
1f220d30 233 // so we have $this->_alias populated
6a488035 234 ),
6a488035 235 ),
6a488035
TO
236 ) + $this->addAddressFields(FALSE, TRUE);
237
238 if ($campaignEnabled) {
239 // Add display column and filter for Survey Results, Campaign and Engagement Index if CiviCampaign is enabled
240
241 $this->_columns['civicrm_activity']['fields']['result'] = array(
242 'title' => 'Survey Result',
243 'default' => 'false',
244 );
245 $this->_columns['civicrm_activity']['filters']['result'] = array('title' => ts('Survey Result'),
246 'operator' => 'like',
247 'type' => CRM_Utils_Type::T_STRING,
248 );
249 if (!empty($this->activeCampaigns)) {
250 $this->_columns['civicrm_activity']['fields']['campaign_id'] = array(
251 'title' => 'Campaign',
252 'default' => 'false',
253 );
254 $this->_columns['civicrm_activity']['filters']['campaign_id'] = array('title' => ts('Campaign'),
255 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
256 'options' => $this->activeCampaigns,
257 );
258 }
259 if (!empty($this->engagementLevels)) {
260 $this->_columns['civicrm_activity']['fields']['engagement_level'] = array(
261 'title' => 'Engagement Index',
262 'default' => 'false',
263 );
264 $this->_columns['civicrm_activity']['filters']['engagement_level'] = array('title' => ts('Engagement Index'),
265 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
266 'options' => $this->engagementLevels,
267 );
268 }
269 }
270 $this->_groupFilter = TRUE;
271 $this->_tagFilter = TRUE;
272 parent::__construct();
273 }
274
1f220d30
DS
275 function select($recordType = NULL) {
276 parent::select();
1f220d30
DS
277
278 if (empty($this->_selectAliasesTotal)) {
279 $this->_selectAliasesTotal = $this->_selectAliases;
280 }
281
282 $removeKeys = array();
283 if ($recordType == 'target') {
284 foreach ($this->_selectClauses as $key => $clause) {
285 if (strstr($clause, 'civicrm_contact_assignee.') ||
286 strstr($clause, 'civicrm_contact_source.') ||
287 strstr($clause, 'civicrm_email_assignee.') ||
288 strstr($clause, 'civicrm_email_source.')
289 ) {
290 $removeKeys[] = $key;
291 unset($this->_selectClauses[$key]);
292 }
293 }
294 } else if ($recordType == 'assignee') {
295 foreach ($this->_selectClauses as $key => $clause) {
296 if (strstr($clause, 'civicrm_contact_target.') ||
297 strstr($clause, 'civicrm_contact_source.') ||
298 strstr($clause, 'civicrm_email_target.') ||
b07bb2f0
DS
299 strstr($clause, 'civicrm_email_source.') ||
300 strstr($clause, 'address_civireport.')
1f220d30
DS
301 ) {
302 $removeKeys[] = $key;
303 unset($this->_selectClauses[$key]);
304 }
305 }
306 } else if ($recordType == 'source') {
307 foreach ($this->_selectClauses as $key => $clause) {
308 if (strstr($clause, 'civicrm_contact_target.') ||
309 strstr($clause, 'civicrm_contact_assignee.') ||
310 strstr($clause, 'civicrm_email_target.') ||
b07bb2f0
DS
311 strstr($clause, 'civicrm_email_assignee.') ||
312 strstr($clause, 'address_civireport.')
1f220d30
DS
313 ) {
314 $removeKeys[] = $key;
315 unset($this->_selectClauses[$key]);
316 }
317 }
318 } else if ($recordType == 'final') {
319 $this->_selectClauses = $this->_selectAliasesTotal;
320 foreach ($this->_selectClauses as $key => $clause) {
321 if (strstr($clause, 'civicrm_contact_contact_target') ||
322 strstr($clause, 'civicrm_contact_contact_assignee') ||
323 strstr($clause, 'civicrm_contact_contact_source') ) {
324 $this->_selectClauses[$key] = "GROUP_CONCAT($clause) as $clause";
6a488035
TO
325 }
326 }
327 }
328
1f220d30
DS
329 if ($recordType) {
330 foreach ($removeKeys as $key) {
331 unset($this->_selectAliases[$key]);
332 }
333
1f220d30 334 $this->_select = "SELECT " . implode(', ', $this->_selectClauses) . " ";
1f220d30 335 }
6a488035
TO
336 }
337
2f4b4d54 338 function from($recordType) {
e7e657f0 339 $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
9e74e3ce 340 $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
2f4b4d54
DS
341 $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
342 $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
6a488035 343
2f4b4d54
DS
344 if ($recordType == 'target') {
345 $this->_from = "
346 FROM civicrm_activity {$this->_aliases['civicrm_activity']}
1f220d30
DS
347 INNER JOIN civicrm_activity_contact {$this->_aliases['civicrm_activity_contact']}
348 ON {$this->_aliases['civicrm_activity']}.id = {$this->_aliases['civicrm_activity_contact']}.activity_id AND
349 {$this->_aliases['civicrm_activity_contact']}.record_type_id = {$targetID}
2f4b4d54 350 INNER JOIN civicrm_contact civicrm_contact_target
1f220d30 351 ON {$this->_aliases['civicrm_activity_contact']}.contact_id = civicrm_contact_target.id
2f4b4d54
DS
352 {$this->_aclFrom}";
353
354 if ($this->isTableSelected('civicrm_email')) {
355 $this->_from .= "
1f220d30
DS
356 LEFT JOIN civicrm_email civicrm_email_target
357 ON {$this->_aliases['civicrm_activity_contact']}.contact_id = civicrm_email_target.contact_id AND
358 civicrm_email_target.is_primary = 1";
2f4b4d54 359 }
1f220d30 360 $this->_aliases['civicrm_contact'] = 'civicrm_contact_target';
2f4b4d54
DS
361 $this->addAddressFromClause();
362 }
363
364 if ($recordType == 'assignee') {
365 $this->_from = "
366 FROM civicrm_activity {$this->_aliases['civicrm_activity']}
1f220d30
DS
367 INNER JOIN civicrm_activity_contact {$this->_aliases['civicrm_activity_contact']}
368 ON {$this->_aliases['civicrm_activity']}.id = {$this->_aliases['civicrm_activity_contact']}.activity_id AND
369 {$this->_aliases['civicrm_activity_contact']}.record_type_id = {$assigneeID}
2f4b4d54 370 INNER JOIN civicrm_contact civicrm_contact_assignee
1f220d30 371 ON {$this->_aliases['civicrm_activity_contact']}.contact_id = civicrm_contact_assignee.id
2f4b4d54
DS
372 {$this->_aclFrom}";
373
374 if ($this->isTableSelected('civicrm_email')) {
375 $this->_from .= "
1f220d30
DS
376 LEFT JOIN civicrm_email civicrm_email_assignee
377 ON {$this->_aliases['civicrm_activity_contact']}.contact_id = civicrm_email_assignee.contact_id AND
378 civicrm_email_assignee.is_primary = 1";
2f4b4d54
DS
379 }
380 }
381
382 if ($recordType == 'source') {
383 $this->_from = "
384 FROM civicrm_activity {$this->_aliases['civicrm_activity']}
1f220d30
DS
385 INNER JOIN civicrm_activity_contact {$this->_aliases['civicrm_activity_contact']}
386 ON {$this->_aliases['civicrm_activity']}.id = {$this->_aliases['civicrm_activity_contact']}.activity_id AND
387 {$this->_aliases['civicrm_activity_contact']}.record_type_id = {$sourceID}
2f4b4d54 388 INNER JOIN civicrm_contact civicrm_contact_source
1f220d30 389 ON {$this->_aliases['civicrm_activity_contact']}.contact_id = civicrm_contact_source.id
2f4b4d54
DS
390 {$this->_aclFrom}";
391
392 if ($this->isTableSelected('civicrm_email')) {
393 $this->_from .= "
1f220d30
DS
394 LEFT JOIN civicrm_email civicrm_email_source
395 ON {$this->_aliases['civicrm_activity_contact']}.contact_id = civicrm_email_source.contact_id AND
396 civicrm_email_source.is_primary = 1";
2f4b4d54 397 }
6a488035 398 }
6a488035
TO
399 }
400
401 function where() {
2f4b4d54 402 $this->_where = " WHERE {$this->_aliases['civicrm_activity']}.is_test = 0 AND
6a488035
TO
403 {$this->_aliases['civicrm_activity']}.is_deleted = 0 AND
404 {$this->_aliases['civicrm_activity']}.is_current_revision = 1";
405
406 $clauses = array();
407 foreach ($this->_columns as $tableName => $table) {
408 if (array_key_exists('filters', $table)) {
409
410 foreach ($table['filters'] as $fieldName => $field) {
411 $clause = NULL;
412 if (CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE) {
413 $relative = CRM_Utils_Array::value("{$fieldName}_relative", $this->_params);
414 $from = CRM_Utils_Array::value("{$fieldName}_from", $this->_params);
415 $to = CRM_Utils_Array::value("{$fieldName}_to", $this->_params);
416
417 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
418 }
419 else {
420 $op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params);
421 if ($op) {
422 $clause = $this->whereClause($field,
423 $op,
424 CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
425 CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
426 CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
427 );
428 }
429 }
430
431 if ($field['name'] == 'current_user') {
432 if (CRM_Utils_Array::value("{$fieldName}_value", $this->_params) == 1) {
433 // get current user
434 $session = CRM_Core_Session::singleton();
435 if ($contactID = $session->get('userID')) {
2f4b4d54 436 $clause = "( civicrm_contact_source.id = " . $contactID . " OR civicrm_contact_assignee.id = " . $contactID . " OR civicrm_contact_target.id = " . $contactID . " )";
6a488035
TO
437 }
438 else {
439 $clause = NULL;
440 }
441 }
442 else {
443 $clause = NULL;
444 }
445 }
446 if (!empty($clause)) {
447 $clauses[] = $clause;
448 }
449 }
450 }
451 }
452
453 if (empty($clauses)) {
454 $this->_where .= " ";
455 }
456 else {
457 $this->_where .= " AND " . implode(' AND ', $clauses);
458 }
459
460 if ($this->_aclWhere) {
461 $this->_where .= " AND {$this->_aclWhere} ";
462 }
463 }
464
465 function groupBy() {
466 $this->_groupBy = "GROUP BY {$this->_aliases['civicrm_activity']}.id";
467 }
468
469 function buildACLClause($tableAlias = 'contact_a') {
2a3c101f 470 //override for ACL( Since Contact may be source
6a488035
TO
471 //contact/assignee or target also it may be null )
472
473 if (CRM_Core_Permission::check('view all contacts')) {
474 $this->_aclFrom = $this->_aclWhere = NULL;
475 return;
476 }
477
478 $session = CRM_Core_Session::singleton();
479 $contactID = $session->get('userID');
480 if (!$contactID) {
481 $contactID = 0;
482 }
483 $contactID = CRM_Utils_Type::escape($contactID, 'Integer');
484
485 CRM_Contact_BAO_Contact_Permission::cache($contactID);
486 $clauses = array();
487 foreach ($tableAlias as $k => $alias) {
488 $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 ";
489 }
490
491 $this->_aclFrom = implode(" ", $clauses);
492 $this->_aclWhere = NULL;
493 }
494
495 function postProcess() {
83e74860 496 $this->buildACLClause(array('civicrm_contact_source', 'civicrm_contact_target', 'civicrm_contact_assignee'));
2f4b4d54
DS
497 $this->beginPostProcess();
498
2f4b4d54 499 // 1. fill temp table with target results
1f220d30 500 $this->select('target');
2f4b4d54
DS
501 $this->from('target');
502 $this->where();
1f220d30 503 $insertCols = implode(',', $this->_selectAliases);
83e74860 504 $tempQuery = "CREATE TEMPORARY TABLE civireport_activity_temp_target AS
1f220d30 505{$this->_select} {$this->_from} {$this->_where}";
2f4b4d54 506 CRM_Core_DAO::executeQuery($tempQuery);
2f4b4d54 507
1f220d30
DS
508 // 2. add new columns to hold assignee and source results
509 // fixme: add when required
510 $tempQuery = "
511 ALTER TABLE civireport_activity_temp_target
512 ADD COLUMN civicrm_contact_contact_assignee VARCHAR(128),
513 ADD COLUMN civicrm_contact_contact_source VARCHAR(128),
514 ADD COLUMN civicrm_email_contact_assignee_email VARCHAR(128),
515 ADD COLUMN civicrm_email_contact_source_email VARCHAR(128)";
516 CRM_Core_DAO::executeQuery($tempQuery);
517
518 // 3. fill temp table with assignee results
b07bb2f0
DS
519 if (CRM_Utils_Array::value("contact_assignee", $this->_params['fields']) ||
520 CRM_Utils_Array::value("contact_assignee_email", $this->_params['fields'])) {
521 $this->select('assignee');
522 $this->from('assignee');
523 $this->where();
524 $insertCols = implode(',', $this->_selectAliases);
525 $tempQuery = "INSERT INTO civireport_activity_temp_target ({$insertCols})
1f220d30 526{$this->_select}
83e74860 527{$this->_from} {$this->_where}";
b07bb2f0
DS
528 CRM_Core_DAO::executeQuery($tempQuery);
529 }
2f4b4d54 530
1f220d30 531 // 4. fill temp table with source results
b07bb2f0
DS
532 if (CRM_Utils_Array::value("contact_source", $this->_params['fields']) ||
533 CRM_Utils_Array::value("contact_source_email", $this->_params['fields'])) {
534 $this->select('source');
535 $this->from('source');
536 $this->where();
537 $insertCols = implode(',', $this->_selectAliases);
538 $tempQuery = "INSERT INTO civireport_activity_temp_target ({$insertCols})
1f220d30 539{$this->_select}
83e74860 540{$this->_from} {$this->_where}";
b07bb2f0
DS
541 CRM_Core_DAO::executeQuery($tempQuery);
542 }
2f4b4d54 543
1f220d30 544 // 5. show final result set from temp table
2f4b4d54 545 $rows = array();
1f220d30 546 $this->select('final');
83e74860 547 $this->orderBy();
1f220d30 548 $this->limit();
83e74860
DS
549 $sql = "{$this->_select}
550FROM civireport_activity_temp_target tar
551GROUP BY civicrm_activity_id {$this->_orderBy} {$this->_limit}";
2f4b4d54
DS
552 $this->buildRows($sql, $rows);
553
554 // format result set.
1f220d30 555 $this->formatDisplay($rows);
2f4b4d54
DS
556
557 // assign variables to templates
558 $this->doTemplateAssignment($rows);
559
560 // do print / pdf / instance stuff if needed
561 $this->endPostProcess($rows);
6a488035
TO
562 }
563
564 function alterDisplay(&$rows) {
565 // custom code to alter rows
566
567 $entryFound = FALSE;
568 $activityType = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE);
569 $activityStatus = CRM_Core_PseudoConstant::activityStatus();
570 $viewLinks = FALSE;
571 $seperator = CRM_CORE_DAO::VALUE_SEPARATOR;
572 $context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'report');
573
574 if (CRM_Core_Permission::check('access CiviCRM')) {
575 $viewLinks = TRUE;
576 $onHover = ts('View Contact Summary for this Contact');
577 $onHoverAct = ts('View Activity Record');
578 }
6a488035 579
38ba593b 580 foreach ($rows as $rowNum => $row) {
6a488035
TO
581 if (array_key_exists('civicrm_activity_activity_type_id', $row)) {
582 if ($value = $row['civicrm_activity_activity_type_id']) {
583 $rows[$rowNum]['civicrm_activity_activity_type_id'] = $activityType[$value];
6a488035
TO
584 $entryFound = TRUE;
585 }
586 }
587
588 if (array_key_exists('civicrm_activity_status_id', $row)) {
589 if ($value = $row['civicrm_activity_status_id']) {
590 $rows[$rowNum]['civicrm_activity_status_id'] = $activityStatus[$value];
591 $entryFound = TRUE;
592 }
593 }
594
595 if (array_key_exists('civicrm_activity_campaign_id', $row)) {
596 if ($value = $row['civicrm_activity_campaign_id']) {
597 $rows[$rowNum]['civicrm_activity_campaign_id'] = $this->activeCampaigns[$value];
598 $entryFound = TRUE;
599 }
600 }
601
602 if (array_key_exists('civicrm_activity_engagement_level', $row)) {
603 if ($value = $row['civicrm_activity_engagement_level']) {
604 $rows[$rowNum]['civicrm_activity_engagement_level'] = $this->engagementLevels[$value];
605 $entryFound = TRUE;
606 }
607 }
608
609 if (array_key_exists('civicrm_activity_activity_date_time', $row) && array_key_exists('civicrm_activity_status_id', $row)) {
610 if (CRM_Utils_Date::overdue($rows[$rowNum]['civicrm_activity_activity_date_time']) &&
611 $activityStatus[$row['civicrm_activity_status_id']] != 'Completed'
612 ) {
613 $rows[$rowNum]['class'] = "status-overdue";
614 $entryFound = TRUE;
615 }
616 }
617
6a488035
TO
618 if (!$entryFound) {
619 break;
620 }
621 }
622 }
6a488035
TO
623}
624