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( | |
38ba593b | 234 | 'dao' => 'CRM_Activity_DAO_ActivityContact', |
6a488035 TO |
235 | 'fields' => |
236 | array( | |
38ba593b | 237 | 'contact_id' => |
6a488035 TO |
238 | array( |
239 | 'no_display' => TRUE, | |
240 | 'required' => TRUE, | |
241 | ), | |
242 | ), | |
243 | 'alias' => 'activity_assignment', | |
244 | ), | |
245 | 'civicrm_activity_target' => | |
246 | array( | |
38ba593b | 247 | 'dao' => 'CRM_Activity_DAO_ActivityContact', |
6a488035 TO |
248 | 'fields' => |
249 | array( | |
38ba593b | 250 | 'contact_id' => |
6a488035 TO |
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() { | |
9e74e3ce | 351 | $activityContacts = CRM_Core_PseudoConstant::activityContacts('name'); |
352 | $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); | |
353 | $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts); | |
354 | ||
6a488035 TO |
355 | $this->_from = " |
356 | FROM civicrm_activity {$this->_aliases['civicrm_activity']} | |
357 | ||
38ba593b | 358 | LEFT JOIN civicrm_activity_contact {$this->_aliases['civicrm_activity_target']} |
359 | ON {$this->_aliases['civicrm_activity']}.id = {$this->_aliases['civicrm_activity_target']}.activity_id AND | |
9e74e3ce | 360 | {$this->_aliases['civicrm_activity_target']}.record_type_id = {$targetID} |
38ba593b | 361 | LEFT JOIN civicrm_activity_contact {$this->_aliases['civicrm_activity_assignment']} |
362 | ON {$this->_aliases['civicrm_activity']}.id = {$this->_aliases['civicrm_activity_assignment']}.activity_id AND | |
9e74e3ce | 363 | {$this->_aliases['civicrm_activity_assignment']}.record_type_id = {$assigneeID} |
6a488035 TO |
364 | LEFT JOIN civicrm_contact civicrm_contact_source |
365 | ON {$this->_aliases['civicrm_activity']}.source_contact_id = civicrm_contact_source.id | |
366 | LEFT JOIN civicrm_contact contact_civireport | |
38ba593b | 367 | ON {$this->_aliases['civicrm_activity_target']}.contact_id = contact_civireport.id |
6a488035 | 368 | LEFT JOIN civicrm_contact civicrm_contact_assignee |
38ba593b | 369 | ON {$this->_aliases['civicrm_activity_assignment']}.contact_id = civicrm_contact_assignee.id |
6a488035 TO |
370 | |
371 | {$this->_aclFrom} | |
372 | LEFT JOIN civicrm_option_value | |
373 | ON ( {$this->_aliases['civicrm_activity']}.activity_type_id = civicrm_option_value.value ) | |
374 | LEFT JOIN civicrm_option_group | |
375 | ON civicrm_option_group.id = civicrm_option_value.option_group_id | |
376 | LEFT JOIN civicrm_case_activity case_activity_civireport | |
377 | ON case_activity_civireport.activity_id = {$this->_aliases['civicrm_activity']}.id | |
378 | LEFT JOIN civicrm_case | |
379 | ON case_activity_civireport.case_id = civicrm_case.id | |
380 | LEFT JOIN civicrm_case_contact | |
381 | ON civicrm_case_contact.case_id = civicrm_case.id "; | |
382 | ||
383 | if ($this->isTableSelected('civicrm_email')) { | |
384 | $this->_from .= " | |
385 | LEFT JOIN civicrm_email civicrm_email_source | |
386 | ON {$this->_aliases['civicrm_activity']}.source_contact_id = civicrm_email_source.contact_id AND | |
387 | civicrm_email_source.is_primary = 1 | |
388 | ||
389 | LEFT JOIN civicrm_email civicrm_email_target | |
390 | ON {$this->_aliases['civicrm_activity_target']}.target_contact_id = civicrm_email_target.contact_id AND | |
391 | civicrm_email_target.is_primary = 1 | |
392 | ||
393 | LEFT JOIN civicrm_email civicrm_email_assignee | |
394 | ON {$this->_aliases['civicrm_activity_assignment']}.assignee_contact_id = civicrm_email_assignee.contact_id AND | |
395 | civicrm_email_assignee.is_primary = 1 "; | |
396 | } | |
397 | $this->addAddressFromClause(); | |
398 | } | |
399 | ||
400 | function where() { | |
401 | $this->_where = " WHERE civicrm_option_group.name = 'activity_type' AND | |
402 | {$this->_aliases['civicrm_activity']}.is_test = 0 AND | |
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')) { | |
436 | $clause = "( civicrm_contact_source.id = " . $contactID . " OR civicrm_contact_assignee.id = " . $contactID . " OR contact_civireport.id = " . $contactID . " )"; | |
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') { | |
470 | //override for ACL( Since Cotact may be source | |
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() { | |
496 | ||
497 | $this->buildACLClause(array('civicrm_contact_source', 'contact_civireport', 'civicrm_contact_assignee')); | |
498 | parent::postProcess(); | |
499 | } | |
500 | ||
501 | function alterDisplay(&$rows) { | |
502 | // custom code to alter rows | |
503 | ||
504 | $entryFound = FALSE; | |
505 | $activityType = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE); | |
506 | $activityStatus = CRM_Core_PseudoConstant::activityStatus(); | |
507 | $viewLinks = FALSE; | |
508 | $seperator = CRM_CORE_DAO::VALUE_SEPARATOR; | |
509 | $context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'report'); | |
510 | ||
511 | if (CRM_Core_Permission::check('access CiviCRM')) { | |
512 | $viewLinks = TRUE; | |
513 | $onHover = ts('View Contact Summary for this Contact'); | |
514 | $onHoverAct = ts('View Activity Record'); | |
515 | } | |
6a488035 | 516 | |
38ba593b | 517 | foreach ($rows as $rowNum => $row) { |
6a488035 | 518 | if (array_key_exists('civicrm_contact_contact_source', $row)) { |
38ba593b | 519 | if ($value = $row['civicrm_activity_assignment_contact_id']) { |
6a488035 TO |
520 | if ($viewLinks) { |
521 | $url = CRM_Utils_System::url("civicrm/contact/view", | |
522 | 'reset=1&cid=' . $value, | |
523 | $this->_absoluteUrl | |
524 | ); | |
525 | $rows[$rowNum]['civicrm_contact_contact_source_link'] = $url; | |
526 | $rows[$rowNum]['civicrm_contact_contact_source_hover'] = $onHover; | |
527 | } | |
528 | $entryFound = TRUE; | |
529 | } | |
530 | } | |
531 | ||
532 | if (array_key_exists('civicrm_contact_contact_assignee', $row)) { | |
533 | $assigneeNames = explode($seperator, $row['civicrm_contact_contact_assignee']); | |
38ba593b | 534 | if ($value = $row['civicrm_activity_assignment_contact_id']) { |
6a488035 TO |
535 | $assigneeContactIds = explode($seperator, $value); |
536 | $link = array(); | |
537 | if ($viewLinks) { | |
538 | foreach ($assigneeContactIds as $id => $value) { | |
539 | $url = CRM_Utils_System::url("civicrm/contact/view", | |
540 | 'reset=1&cid=' . $value, | |
541 | $this->_absoluteUrl | |
542 | ); | |
543 | $link[] = "<a title='" . $onHover . "' href='" . $url . "'>{$assigneeNames[$id]}</a>"; | |
544 | } | |
545 | $rows[$rowNum]['civicrm_contact_contact_assignee'] = implode('; ', $link); | |
546 | } | |
547 | $entryFound = TRUE; | |
548 | } | |
549 | } | |
550 | ||
551 | if (array_key_exists('civicrm_contact_contact_target', $row)) { | |
552 | $targetNames = explode($seperator, $row['civicrm_contact_contact_target']); | |
38ba593b | 553 | if ($value = $row['civicrm_activity_target_contact_id']) { |
6a488035 TO |
554 | $targetContactIds = explode($seperator, $value); |
555 | $link = array(); | |
556 | if ($viewLinks) { | |
557 | foreach ($targetContactIds as $id => $value) { | |
558 | $url = CRM_Utils_System::url("civicrm/contact/view", | |
559 | 'reset=1&cid=' . $value, | |
560 | $this->_absoluteUrl | |
561 | ); | |
562 | $link[] = "<a title='" . $onHover . "' href='" . $url . "'>{$targetNames[$id]}</a>"; | |
563 | } | |
564 | $rows[$rowNum]['civicrm_contact_contact_target'] = implode('; ', $link); | |
565 | } | |
566 | $entryFound = TRUE; | |
567 | } | |
568 | } | |
569 | ||
570 | if (array_key_exists('civicrm_activity_activity_type_id', $row)) { | |
571 | if ($value = $row['civicrm_activity_activity_type_id']) { | |
572 | $rows[$rowNum]['civicrm_activity_activity_type_id'] = $activityType[$value]; | |
573 | if ($viewLinks) { | |
574 | // Check for target contact id(s) and use the first contact id in that list for view activity link if found, | |
575 | // else use source contact id | |
576 | if (!empty($rows[$rowNum]['civicrm_activity_target_target_contact_id'])) { | |
577 | $targets = explode($seperator, $rows[$rowNum]['civicrm_activity_target_target_contact_id']); | |
578 | $cid = $targets[0]; | |
579 | } | |
580 | else { | |
581 | $cid = $rows[$rowNum]['civicrm_activity_source_contact_id']; | |
582 | } | |
583 | ||
584 | $actionLinks = CRM_Activity_Selector_Activity::actionLinks($row['civicrm_activity_activity_type_id'], | |
585 | CRM_Utils_Array::value('civicrm_activity_source_record_id', $rows[$rowNum]), | |
586 | FALSE, | |
587 | $rows[$rowNum]['civicrm_activity_id'] | |
588 | ); | |
589 | ||
590 | $linkValues = array( | |
591 | 'id' => $rows[$rowNum]['civicrm_activity_id'], | |
592 | 'cid' => $cid, | |
593 | 'cxt' => $context, | |
594 | ); | |
595 | $url = CRM_Utils_System::url($actionLinks[CRM_Core_Action::VIEW]['url'], | |
596 | CRM_Core_Action::replace($actionLinks[CRM_Core_Action::VIEW]['qs'], $linkValues), TRUE | |
597 | ); | |
598 | $rows[$rowNum]['civicrm_activity_activity_type_id_link'] = $url; | |
599 | $rows[$rowNum]['civicrm_activity_activity_type_id_hover'] = $onHoverAct; | |
600 | } | |
601 | $entryFound = TRUE; | |
602 | } | |
603 | } | |
604 | ||
605 | if (array_key_exists('civicrm_activity_status_id', $row)) { | |
606 | if ($value = $row['civicrm_activity_status_id']) { | |
607 | $rows[$rowNum]['civicrm_activity_status_id'] = $activityStatus[$value]; | |
608 | $entryFound = TRUE; | |
609 | } | |
610 | } | |
611 | ||
612 | if (array_key_exists('civicrm_activity_campaign_id', $row)) { | |
613 | if ($value = $row['civicrm_activity_campaign_id']) { | |
614 | $rows[$rowNum]['civicrm_activity_campaign_id'] = $this->activeCampaigns[$value]; | |
615 | $entryFound = TRUE; | |
616 | } | |
617 | } | |
618 | ||
619 | if (array_key_exists('civicrm_activity_engagement_level', $row)) { | |
620 | if ($value = $row['civicrm_activity_engagement_level']) { | |
621 | $rows[$rowNum]['civicrm_activity_engagement_level'] = $this->engagementLevels[$value]; | |
622 | $entryFound = TRUE; | |
623 | } | |
624 | } | |
625 | ||
626 | if (array_key_exists('civicrm_activity_activity_date_time', $row) && array_key_exists('civicrm_activity_status_id', $row)) { | |
627 | if (CRM_Utils_Date::overdue($rows[$rowNum]['civicrm_activity_activity_date_time']) && | |
628 | $activityStatus[$row['civicrm_activity_status_id']] != 'Completed' | |
629 | ) { | |
630 | $rows[$rowNum]['class'] = "status-overdue"; | |
631 | $entryFound = TRUE; | |
632 | } | |
633 | } | |
634 | ||
635 | $entryFound = $this->alterDisplayAddressFields($row, $rows, $rowNum, 'activity', 'List all activities for this ') ? TRUE : $entryFound; | |
636 | ||
637 | if (!$entryFound) { | |
638 | break; | |
639 | } | |
640 | } | |
641 | } | |
642 | ||
643 | ||
644 | /* | |
645 | * Add Target Contact Address into From Table if required | |
646 | */ | |
647 | function addAddressFromClause() { | |
648 | // include address field if address column is to be included | |
649 | if ((isset($this->_addressField) && | |
650 | $this->_addressField | |
651 | ) || | |
652 | $this->isTableSelected('civicrm_address') | |
653 | ) { | |
654 | $this->_from .= " | |
655 | LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']} | |
656 | ON ({$this->_aliases['civicrm_activity_target']}.target_contact_id = | |
657 | {$this->_aliases['civicrm_address']}.contact_id) AND | |
658 | {$this->_aliases['civicrm_address']}.is_primary = 1\n"; | |
659 | } | |
660 | } | |
661 | } | |
662 |