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