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