phpcs - Fix error, "Visibility must be declared on method"
[civicrm-core.git] / CRM / Report / Form / Contact / Detail.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
32 * $Id$
33 *
34 */
35 class CRM_Report_Form_Contact_Detail extends CRM_Report_Form {
36 const ROW_COUNT_LIMIT = 10;
37
38 protected $_summary = NULL;
39
40 protected $_customGroupExtends = array(
41 'Contact',
42 'Individual',
43 'Household',
44 'Organization'
45 );
46
47 /**
48 *
49 */
50 /**
51 *
52 */
53 public function __construct() {
54 $this->_autoIncludeIndexedFieldsAsOrderBys = 1;
55 $this->_columns = array(
56 'civicrm_contact' => array(
57 'dao' => 'CRM_Contact_DAO_Contact',
58 'fields' => array(
59 'sort_name' => array(
60 'title' => ts('Contact Name'),
61 'required' => TRUE,
62 'no_repeat' => TRUE,
63 ),
64 'first_name' => array(
65 'title' => ts('First Name'),
66 ),
67 'last_name' => array(
68 'title' => ts('Last Name'),
69 ),
70 'id' => array(
71 'no_display' => TRUE,
72 'required' => TRUE,
73 ),
74 'contact_type' => array(
75 'title' => ts('Contact Type'),
76 ),
77 'contact_sub_type' => array(
78 'title' => ts('Contact Subtype'),
79 ),
80 'birth_date' => array(
81 'title' => ts('Birth Date'),
82 ),
83 ),
84 'filters' => array(
85 'id' => array(
86 'title' => ts('Contact ID'),
87 'no_display' => TRUE,
88 ),
89 'sort_name' => array(
90 'title' => ts('Contact Name'),
91 ),
92 'birth_date' => array(
93 'title' => ts('Birth Date'),
94 'operatorType' => CRM_Report_Form::OP_DATE,
95 ),
96 ),
97 'grouping' => 'contact-fields',
98 'order_bys' => array(
99 'sort_name' => array(
100 'title' => ts('Last Name, First Name'),
101 'default' => '1',
102 'default_weight' => '0',
103 'default_order' => 'ASC'
104 ),
105 ),
106 ),
107 'civicrm_address' => array(
108 'dao' => 'CRM_Core_DAO_Address',
109 'grouping' => 'contact-fields',
110 'fields' => array(
111 'street_address' => NULL,
112 'city' => NULL,
113 'postal_code' => NULL,
114 'state_province_id' => array(
115 'title' => ts('State/Province'),
116 ),
117 ),
118 'order_bys' => array(
119 'state_province_id' => array('title' => 'State/Province'),
120 'city' => array('title' => 'City'),
121 'postal_code' => array('title' => 'Postal Code'),
122 ),
123 ),
124 'civicrm_country' => array(
125 'dao' => 'CRM_Core_DAO_Country',
126 'fields' => array(
127 'name' => array('title' => 'Country', 'default' => TRUE),
128 ),
129 'order_bys' => array(
130 'name' => array('title' => 'Country'),
131 ),
132 'grouping' => 'contact-fields',
133 ),
134 'civicrm_email' => array(
135 'dao' => 'CRM_Core_DAO_Email',
136 'fields' => array(
137 'email' => array(
138 'title' => ts('Email'),
139 'no_repeat' => TRUE,
140 ),
141 ),
142 'grouping' => 'contact-fields',
143 'order_bys' => array(
144 'email' => array(
145 'title' => ts('Email'),
146 ),
147 ),
148 ),
149 'civicrm_contribution' => array(
150 'dao' => 'CRM_Contribute_DAO_Contribution',
151 'fields' => array(
152 'contact_id' => array(
153 'no_display' => TRUE,
154 'required' => TRUE,
155 ),
156 'contribution_id' => array(
157 'title' => ts('Contribution'),
158 'no_repeat' => TRUE,
159 'default' => TRUE,
160 ),
161 'total_amount' => array('default' => TRUE),
162 'financial_type_id' => array(
163 'title' => ts('Financial Type'),
164 'default' => TRUE,
165 ),
166 'trxn_id' => NULL,
167 'receive_date' => array('default' => TRUE),
168 'receipt_date' => NULL,
169 'contribution_status_id' => array(
170 'title' => ts('Contribution Status'),
171 'default' => TRUE,
172 ),
173 'contribution_source' => NULL,
174 ),
175 ),
176 'civicrm_membership' => array(
177 'dao' => 'CRM_Member_DAO_Membership',
178 'fields' => array(
179 'contact_id' => array(
180 'no_display' => TRUE,
181 'required' => TRUE,
182 ),
183 'membership_id' => array(
184 'title' => ts('Membership'),
185 'no_repeat' => TRUE,
186 'default' => TRUE,
187 ),
188 'membership_type_id' => array(
189 'title' => ts('Membership Type'),
190 'default' => TRUE,
191 ),
192 'join_date' => NULL,
193 'membership_start_date' => array(
194 'title' => ts('Start Date'),
195 'default' => TRUE,
196 ),
197 'membership_end_date' => array(
198 'title' => ts('End Date'),
199 'default' => TRUE,
200 ),
201 'membership_status_id' => array(
202 'name' => 'status_id',
203 'title' => ts('Membership Status'),
204 'default' => TRUE,
205 ),
206 'source' => array('title' => 'Membership Source'),
207 ),
208 ),
209 'civicrm_participant' => array(
210 'dao' => 'CRM_Event_DAO_Participant',
211 'fields' => array(
212 'contact_id' => array(
213 'no_display' => TRUE,
214 'required' => TRUE,
215 ),
216 'participant_id' => array(
217 'title' => ts('Participant'),
218 'no_repeat' => TRUE,
219 'default' => TRUE,
220 ),
221 'event_id' => array('default' => TRUE),
222 'participant_status_id' => array(
223 'name' => 'status_id',
224 'title' => ts('Participant Status'),
225 'default' => TRUE,
226 ),
227 'role_id' => array(
228 'title' => ts('Role'),
229 'default' => TRUE,
230 ),
231 'participant_register_date' => array(
232 'title' => ts('Register Date'),
233 'default' => TRUE,
234 ),
235 'fee_level' => array(
236 'title' => ts('Fee Level'),
237 'default' => TRUE,
238 ),
239 'fee_amount' => array(
240 'title' => ts('Fee Amount'),
241 'default' => TRUE,
242 ),
243 ),
244 ),
245 'civicrm_relationship' => array(
246 'dao' => 'CRM_Contact_DAO_Relationship',
247 'fields' => array(
248 'relationship_id' => array(
249 'name' => 'id',
250 'title' => ts('Relationship'),
251 'no_repeat' => TRUE,
252 'default' => TRUE,
253 ),
254 'relationship_type_id' => array(
255 'title' => ts('Relationship Type'),
256 'default' => TRUE,
257 ),
258 'contact_id_b' => array(
259 'title' => ts('Relationship With'),
260 'default' => TRUE,
261 ),
262 'start_date' => array(
263 'title' => 'Start Date ',
264 'type' => CRM_Report_Form::OP_DATE,
265 ),
266 'end_date' => array(
267 'title' => 'End Date ',
268 'type' => CRM_Report_Form::OP_DATE,
269 ),
270 ),
271 ),
272 'civicrm_activity' => array(
273 'dao' => 'CRM_Activity_DAO_Activity',
274 'fields' => array(
275 'id' => array(
276 'title' => ts('Activity'),
277 'no_repeat' => TRUE,
278 'default' => TRUE,
279 ),
280 'activity_type_id' => array(
281 'title' => ts('Activity Type'),
282 'default' => TRUE,
283 ),
284 'subject' => array(
285 'title' => ts('Subject'),
286 'default' => TRUE,
287 ),
288 'activity_date_time' => array(
289 'title' => ts('Activity Date'),
290 'default' => TRUE,
291 ),
292 'activity_status_id' => array(
293 'name' => 'status_id',
294 'title' => ts('Activity Status'),
295 'default' => TRUE,
296 ),
297 ),
298 'grouping' => 'activity-fields',
299 ),
300 'civicrm_activity_target' => array(
301 'dao' => 'CRM_Activity_DAO_ActivityContact',
302 'fields' => array(
303 'target_contact_id' => array(
304 'title' => ts('With Contact'),
305 'name' => 'contact_id',
306 'default' => TRUE,
307 ),
308 ),
309 'grouping' => 'activity-fields',
310 ),
311 'civicrm_activity_assignment' => array(
312 'dao' => 'CRM_Activity_DAO_ActivityContact',
313 'fields' => array(
314 'assignee_contact_id' => array(
315 'title' => ts('Assigned to'),
316 'name' => 'contact_id',
317 'default' => TRUE,
318 ),
319 ),
320 'grouping' => 'activity-fields',
321 ),
322 'civicrm_activity_source' => array(
323 'dao' => 'CRM_Activity_DAO_ActivityContact',
324 'fields' => array(
325 'source_contact_id' => array(
326 'title' => ts('Added By'),
327 'name' => 'contact_id',
328 'default' => TRUE,
329 ),
330 ),
331 'grouping' => 'activity-fields',
332 ),
333 'civicrm_phone' => array(
334 'dao' => 'CRM_Core_DAO_Phone',
335 'fields' => array(
336 'phone' => NULL,
337 'phone_ext' => array(
338 'title' => ts('Phone Extension')
339 )
340 ),
341 'grouping' => 'contact-fields',
342 ),
343 );
344 $this->_groupFilter = TRUE;
345 $this->_tagFilter = TRUE;
346 parent::__construct();
347 }
348
349 public function preProcess() {
350 $this->_csvSupported = FALSE;
351 parent::preProcess();
352 }
353
354 public function select() {
355 $select = array();
356 $this->_columnHeaders = array();
357 $this->_component = array(
358 'contribution_civireport',
359 'membership_civireport',
360 'participant_civireport',
361 'relationship_civireport',
362 'activity_civireport'
363 );
364 foreach ($this->_columns as $tableName => $table) {
365 if (array_key_exists('fields', $table)) {
366 foreach ($table['fields'] as $fieldName => $field) {
367 if (!empty($field['required']) ||
368 !empty($this->_params['fields'][$fieldName])
369 ) {
370 //isolate the select clause compoenent wise
371 if (in_array($table['alias'], $this->_component)) {
372 $select[$table['alias']][] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
373 $this->_columnHeadersComponent[$table['alias']]["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field);
374 $this->_columnHeadersComponent[$table['alias']]["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array::value('title', $field);
375 }
376 elseif ($table['alias'] ==
377 $this->_aliases['civicrm_activity_target'] ||
378 $table['alias'] ==
379 $this->_aliases['civicrm_activity_assignment'] ||
380 $table['alias'] == $this->_aliases['civicrm_activity_source']
381 ) {
382 if ($table['alias'] == $this->_aliases['civicrm_activity_target']
383 ) {
384 $addContactId = 'civicrm_activity_target.contact_id as target_contact_id';
385 }
386 elseif ($table['alias'] ==
387 $this->_aliases['civicrm_activity_source']
388 ) {
389 $addContactId = 'civicrm_activity_source.contact_id';
390 }
391 else {
392 $addContactId = 'civicrm_activity_assignment.contact_id as assignee_contact_id';
393 }
394
395 $tableName = $table['alias'];
396 $select['activity_civireport'][] = "$tableName.display_name as {$tableName}_{$fieldName}, $addContactId ";
397 $this->_columnHeadersComponent['activity_civireport']["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field);
398 $this->_columnHeadersComponent['activity_civireport']["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array::value('title', $field);
399 }
400 else {
401 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
402 $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field);
403 $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title'];
404 }
405 }
406 }
407 }
408 }
409
410 foreach ($this->_component as $val) {
411 if (!empty($select[$val])) {
412 $this->_selectComponent[$val] =
413 "SELECT " . implode(', ', $select[$val]) . " ";
414 unset($select[$val]);
415 }
416 }
417
418 $this->_select = "SELECT " . implode(', ', $select) . " ";
419 }
420
421 /**
422 * @param $fields
423 * @param $files
424 * @param $self
425 *
426 * @return array
427 */
428 public static function formRule($fields, $files, $self) {
429 $errors = array();
430 return $errors;
431 }
432
433 public function from() {
434 $group = " ";
435 $this->_from = "
436 FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}";
437
438 if ($this->isTableSelected('civicrm_country') ||
439 $this->isTableSelected('civicrm_address')
440 ) {
441 $this->_from .= "
442 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
443 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND
444 {$this->_aliases['civicrm_address']}.is_primary = 1 ) ";
445 }
446
447 if ($this->isTableSelected('civicrm_email')) {
448 $this->_from .= "
449 LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
450 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND
451 {$this->_aliases['civicrm_email']}.is_primary = 1) ";
452 }
453
454 if ($this->isTableSelected('civicrm_phone')) {
455 $this->_from .= "
456 LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
457 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
458 {$this->_aliases['civicrm_phone']}.is_primary = 1 ";
459 }
460
461 if ($this->isTableSelected('civicrm_country')) {
462 $this->_from .= "
463 LEFT JOIN civicrm_country {$this->_aliases['civicrm_country']}
464 ON {$this->_aliases['civicrm_address']}.country_id = {$this->_aliases['civicrm_country']}.id AND
465 {$this->_aliases['civicrm_address']}.is_primary = 1 ";
466 }
467
468 $this->_from .= "{$group}";
469
470 foreach ($this->_component as $val) {
471 if (!empty($this->_selectComponent['contribution_civireport'])) {
472 $this->_formComponent['contribution_civireport'] = " FROM
473 civicrm_contact {$this->_aliases['civicrm_contact']}
474 INNER JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']}
475 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_contribution']}.contact_id
476 {$group}
477 ";
478 }
479 if (!empty($this->_selectComponent['membership_civireport'])) {
480 $this->_formComponent['membership_civireport'] = " FROM
481 civicrm_contact {$this->_aliases['civicrm_contact']}
482 INNER JOIN civicrm_membership {$this->_aliases['civicrm_membership']}
483 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_membership']}.contact_id
484 {$group} ";
485 }
486 if (!empty($this->_selectComponent['participant_civireport'])) {
487 $this->_formComponent['participant_civireport'] = " FROM
488 civicrm_contact {$this->_aliases['civicrm_contact']}
489 INNER JOIN civicrm_participant {$this->_aliases['civicrm_participant']}
490 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_participant']}.contact_id
491 {$group} ";
492 }
493
494 if (!empty($this->_selectComponent['activity_civireport'])) {
495 $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
496 $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
497 $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
498 $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
499
500 $this->_formComponent['activity_civireport'] = "FROM
501 civicrm_activity {$this->_aliases['civicrm_activity']}
502 LEFT JOIN civicrm_activity_contact civicrm_activity_target ON
503 {$this->_aliases['civicrm_activity']}.id = civicrm_activity_target.activity_id AND
504 civicrm_activity_target.record_type_id = {$targetID}
505 LEFT JOIN civicrm_activity_contact civicrm_activity_assignment ON
506 {$this->_aliases['civicrm_activity']}.id = civicrm_activity_assignment.activity_id AND civicrm_activity_assignment.record_type_id = {$assigneeID}
507 LEFT JOIN civicrm_activity_contact civicrm_activity_source
508 ON {$this->_aliases['civicrm_activity']}.id = civicrm_activity_source.activity_id AND
509 civicrm_activity_source.record_type_id = {$sourceID}
510 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_activity_target']} ON
511 civicrm_activity_target.contact_id = {$this->_aliases['civicrm_activity_target']}.id
512
513 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_activity_assignment']} ON
514 civicrm_activity_assignment.contact_id = {$this->_aliases['civicrm_activity_assignment']}.id
515 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_activity_source']} ON
516 civicrm_activity_source.contact_id = {$this->_aliases['civicrm_activity_source']}.id
517 LEFT JOIN civicrm_option_value ON
518 ( {$this->_aliases['civicrm_activity']}.activity_type_id = civicrm_option_value.value )
519 LEFT JOIN civicrm_option_group ON
520 civicrm_option_group.id = civicrm_option_value.option_group_id
521 LEFT JOIN civicrm_case_activity ON
522 civicrm_case_activity.activity_id = {$this->_aliases['civicrm_activity']}.id
523 LEFT JOIN civicrm_case ON
524 civicrm_case_activity.case_id = civicrm_case.id
525 LEFT JOIN civicrm_case_contact ON
526 civicrm_case_contact.case_id = civicrm_case.id ";
527 }
528
529 if (!empty($this->_selectComponent['relationship_civireport'])) {
530 $this->_formComponent['relationship_civireport'] = "FROM
531 civicrm_relationship {$this->_aliases['civicrm_relationship']}
532
533 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']} ON
534 {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_relationship']}.contact_id_b
535 LEFT JOIN civicrm_contact contact_a ON
536 contact_a.id = {$this->_aliases['civicrm_relationship']}.contact_id_a ";
537 }
538 }
539 }
540
541 public function where() {
542 $clauses = array();
543
544 foreach ($this->_columns as $tableName => $table) {
545 if (array_key_exists('filters', $table)) {
546 foreach ($table['filters'] as $fieldName => $field) {
547 $clause = NULL;
548 if (CRM_Utils_Array::value('operatorType', $field) &
549 CRM_Report_Form::OP_DATE
550 ) {
551 $relative = CRM_Utils_Array::value("{$fieldName}_relative", $this->_params);
552 $from = CRM_Utils_Array::value("{$fieldName}_from", $this->_params);
553 $to = CRM_Utils_Array::value("{$fieldName}_to", $this->_params);
554
555 $clause = $this->dateClause($field['dbAlias'], $relative, $from, $to);
556 }
557 else {
558 $op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params);
559 $clause = $this->whereClause($field,
560 $op,
561 CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
562 CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
563 CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
564 );
565 }
566 if (!empty($clause)) {
567 $clauses[] = $clause;
568 }
569 }
570 }
571 }
572
573 if (empty($clauses)) {
574 $this->_where = "WHERE ( 1 ) ";
575 }
576 else {
577 $this->_where = "WHERE " . implode(' AND ', $clauses);
578 }
579
580 if ($this->_aclWhere) {
581 $this->_where .= " AND {$this->_aclWhere} ";
582 }
583
584 $this->_where .= " GROUP BY {$this->_aliases['civicrm_contact']}.id ";
585 }
586
587 /**
588 * @return array
589 */
590 public function clauseComponent() {
591 $selectedContacts = implode(',', $this->_contactSelected);
592 $contribution = $membership = $participant = NULL;
593 $eligibleResult = $rows = $tempArray = array();
594 foreach ($this->_component as $val) {
595 if (!empty($this->_selectComponent[$val]) &&
596 ($val != 'activity_civireport' && $val != 'relationship_civireport')
597 ) {
598 $sql = "{$this->_selectComponent[$val]} {$this->_formComponent[$val]}
599 WHERE {$this->_aliases['civicrm_contact']}.id IN ( $selectedContacts )
600 GROUP BY {$this->_aliases['civicrm_contact']}.id,{$val}.id ";
601
602 $dao = CRM_Core_DAO::executeQuery($sql);
603 while ($dao->fetch()) {
604 $countRecord = 0;
605 $eligibleResult[$val] = $val;
606 $CC = 'civicrm_' . substr_replace($val, '', -11, 11) . '_contact_id';
607 $row = array();
608 foreach ($this->_columnHeadersComponent[$val] as $key => $value) {
609 $countRecord++;
610 $row[$key] = $dao->$key;
611 }
612
613 //if record exist for component(except contact_id)
614 //since contact_id is selected for every component
615 if ($countRecord > 1) {
616 $rows[$dao->$CC][$val][] = $row;
617 }
618 $tempArray[$dao->$CC] = $dao->$CC;
619 }
620 }
621 }
622
623 if (!empty($this->_selectComponent['relationship_civireport'])) {
624
625 $relTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, NULL, TRUE);
626
627 $val = 'relationship_civireport';
628 $eligibleResult[$val] = $val;
629 $sql = "{$this->_selectComponent[$val]},{$this->_aliases['civicrm_contact']}.display_name as contact_b_name, contact_a.id as contact_a_id , contact_a.display_name as contact_a_name {$this->_formComponent[$val]}
630 WHERE ({$this->_aliases['civicrm_contact']}.id IN ( $selectedContacts )
631 OR
632 contact_a.id IN ( $selectedContacts ) ) AND
633 {$this->_aliases['civicrm_relationship']}.is_active = 1 AND
634 contact_a.is_deleted = 0 AND
635 {$this->_aliases['civicrm_contact']}.is_deleted = 0
636 GROUP BY {$this->_aliases['civicrm_relationship']}.id";
637
638 $dao = CRM_Core_DAO::executeQuery($sql);
639 while ($dao->fetch()) {
640 foreach ($this->_columnHeadersComponent[$val] as $key => $value) {
641 if ($key == 'civicrm_relationship_contact_id_b') {
642 $row[$key] = $dao->contact_b_name;
643 continue;
644 }
645
646 $row[$key] = $dao->$key;
647 }
648
649 $relTitle = "" . $dao->civicrm_relationship_relationship_type_id .
650 '_a_b';
651 $row['civicrm_relationship_relationship_type_id'] = $relTypes[$relTitle];
652
653 $rows[$dao->contact_a_id][$val][] = $row;
654
655 $row['civicrm_relationship_contact_id_b'] = $dao->contact_a_name;
656 $relTitle = "" . $dao->civicrm_relationship_relationship_type_id .
657 '_b_a';
658 if (isset($relTypes[$relTitle])) {
659 $row['civicrm_relationship_relationship_type_id'] = $relTypes[$relTitle];
660 }
661 $rows[$dao->civicrm_relationship_contact_id_b][$val][] = $row;
662 }
663 }
664
665 if (!empty($this->_selectComponent['activity_civireport'])) {
666
667 $componentClause = "civicrm_option_value.component_id IS NULL";
668 $componentsIn = NULL;
669 $compInfo = CRM_Core_Component::getEnabledComponents();
670 foreach ($compInfo as $compObj) {
671 if ($compObj->info['showActivitiesInCore']) {
672 $componentsIn = $componentsIn ? ($componentsIn . ', ' .
673 $compObj->componentID) : $compObj->componentID;
674 }
675 }
676 if ($componentsIn) {
677 $componentClause = "( $componentClause OR
678 civicrm_option_value.component_id IN ($componentsIn) )";
679 }
680
681 $val = 'activity_civireport';
682 $eligibleResult[$val] = $val;
683 $sql = "{$this->_selectComponent[$val]} ,
684 {$this->_aliases['civicrm_activity_source']}.display_name as added_by {$this->_formComponent[$val]}
685
686 WHERE ( civicrm_activity_source.contact_id IN ($selectedContacts) OR
687 civicrm_activity_target.contact_id IN ($selectedContacts) OR
688 civicrm_activity_assignment.contact_id IN ($selectedContacts) OR
689 civicrm_case_contact.contact_id IN ($selectedContacts) ) AND
690 civicrm_option_group.name = 'activity_type' AND
691 {$this->_aliases['civicrm_activity']}.is_test = 0 AND
692 ($componentClause)
693
694 GROUP BY {$this->_aliases['civicrm_activity']}.id
695
696 ORDER BY {$this->_aliases['civicrm_activity']}.activity_date_time desc ";
697
698 $dao = CRM_Core_DAO::executeQuery($sql);
699 while ($dao->fetch()) {
700 foreach ($this->_columnHeadersComponent[$val] as $key => $value) {
701 if ($key == 'civicrm_activity_source_contact_id') {
702 $row[$key] = $dao->added_by;
703 continue;
704 }
705 $row[$key] = $dao->$key;
706 }
707
708 if (isset($dao->civicrm_activity_source_contact_id)) {
709 $rows[$dao->civicrm_activity_source_contact_id][$val][] = $row;
710 }
711 if (isset($dao->target_contact_id)) {
712 $rows[$dao->target_contact_id][$val][] = $row;
713 }
714 if (isset($dao->assignee_contact_id)) {
715 $rows[$dao->assignee_contact_id][$val][] = $row;
716 }
717 }
718
719 //unset the component header if data is not present
720 foreach ($this->_component as $val) {
721 if (!in_array($val, $eligibleResult)) {
722
723 unset($this->_columnHeadersComponent[$val]);
724 }
725 }
726 }
727
728 return $rows;
729 }
730
731 /**
732 * @param $rows
733 *
734 * @return array
735 */
736 public function statistics(&$rows) {
737 $statistics = array();
738
739 $count = count($rows);
740 if ($this->_rollup && ($this->_rollup != '')) {
741 $count++;
742 }
743
744 $this->countStat($statistics, $count);
745 $this->filterStat($statistics);
746
747 return $statistics;
748 }
749
750 //Override to set limit is 10
751 /**
752 * @param int $rowCount
753 */
754 public function limit($rowCount = self::ROW_COUNT_LIMIT) {
755 parent::limit($rowCount);
756 }
757
758 //Override to set pager with limit is 10
759 /**
760 * @param int $rowCount
761 */
762 public function setPager($rowCount = self::ROW_COUNT_LIMIT) {
763 parent::setPager($rowCount);
764 }
765
766 public function postProcess() {
767
768 $this->beginPostProcess();
769
770 // get the acl clauses built before we assemble the query
771 $this->buildACLClause($this->_aliases['civicrm_contact']);
772
773 $sql = $this->buildQuery(TRUE);
774
775 $rows = $graphRows = $this->_contactSelected = array();
776 $this->buildRows($sql, $rows);
777 foreach ($rows as $key => $val) {
778 $rows[$key]['contactID'] = $val['civicrm_contact_id'];
779 $this->_contactSelected[] = $val['civicrm_contact_id'];
780 }
781
782 $this->formatDisplay($rows);
783
784 if (!empty($this->_contactSelected)) {
785 $componentRows = $this->clauseComponent();
786 $this->alterComponentDisplay($componentRows);
787
788 //unset Conmponent id and contact id from display
789 foreach ($this->_columnHeadersComponent as $componentTitle => $headers) {
790 $id_header =
791 'civicrm_' . substr_replace($componentTitle, '', -11, 11) . '_' .
792 substr_replace($componentTitle, '', -11, 11) . '_id';
793 $contact_header =
794 'civicrm_' . substr_replace($componentTitle, '', -11, 11) .
795 '_contact_id';
796 if ($componentTitle == 'activity_civireport') {
797 $id_header =
798 'civicrm_' . substr_replace($componentTitle, '', -11, 11) . '_id';
799 }
800
801 unset($this->_columnHeadersComponent[$componentTitle][$id_header]);
802 unset($this->_columnHeadersComponent[$componentTitle][$contact_header]);
803 }
804
805 $this->assign_by_ref('columnHeadersComponent', $this->_columnHeadersComponent);
806 $this->assign_by_ref('componentRows', $componentRows);
807 }
808
809 $this->doTemplateAssignment($rows);
810 $this->endPostProcess();
811 }
812
813 /**
814 * @param $rows
815 */
816 public function alterDisplay(&$rows) {
817 // custom code to alter rows
818
819 $entryFound = FALSE;
820
821 foreach ($rows as $rowNum => $row) {
822 // make count columns point to detail report
823
824 // change contact name with link
825 if (array_key_exists('civicrm_contact_sort_name', $row) &&
826 array_key_exists('civicrm_contact_id', $row)
827 ) {
828
829 $url = CRM_Utils_System::url('civicrm/contact/view',
830 'reset=1&cid=' . $row['civicrm_contact_id'],
831 $this->_absoluteUrl
832 );
833 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
834 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts('View Contact Summary for this Contact');
835 $entryFound = TRUE;
836 }
837
838 if (array_key_exists('civicrm_address_state_province_id', $row)) {
839 if ($value = $row['civicrm_address_state_province_id']) {
840 $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($value, FALSE);
841 }
842 $entryFound = TRUE;
843 }
844
845
846 // skip looking further in rows, if first row itself doesn't
847 // have the column we need
848 if (!$entryFound) {
849 break;
850 }
851 }
852 }
853
854 /**
855 * @param $componentRows
856 */
857 public function alterComponentDisplay(&$componentRows) {
858 // custom code to alter rows
859 $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE);
860 $activityStatus = CRM_Core_PseudoConstant::activityStatus();
861
862 $entryFound = FALSE;
863 foreach ($componentRows as $contactID => $components) {
864 foreach ($components as $component => $rows) {
865 foreach ($rows as $rowNum => $row) {
866 // handle contribution
867 if ($component == 'contribution_civireport') {
868 if ($val = CRM_Utils_Array::value('civicrm_contribution_financial_type_id', $row)) {
869 $componentRows[$contactID][$component][$rowNum]['civicrm_contribution_financial_type_id'] =
870 CRM_Contribute_PseudoConstant::financialType($val, FALSE);
871 }
872
873 if ($val = CRM_Utils_Array::value('civicrm_contribution_contribution_status_id', $row)) {
874 $componentRows[$contactID][$component][$rowNum]['civicrm_contribution_contribution_status_id'] = CRM_Contribute_PseudoConstant::contributionStatus($val);
875 }
876 $entryFound = TRUE;
877 }
878
879 if ($component == 'membership_civireport') {
880 if ($val = CRM_Utils_Array::value('civicrm_membership_membership_type_id', $row)) {
881 $componentRows[$contactID][$component][$rowNum]['civicrm_membership_membership_type_id'] = CRM_Member_PseudoConstant::membershipType($val, FALSE);
882 }
883
884 if ($val = CRM_Utils_Array::value('civicrm_membership_status_id', $row)) {
885 $componentRows[$contactID][$component][$rowNum]['civicrm_membership_status_id'] = CRM_Member_PseudoConstant::membershipStatus($val, FALSE);
886 }
887 $entryFound = TRUE;
888 }
889
890 if ($component == 'participant_civireport') {
891 if ($val = CRM_Utils_Array::value('civicrm_participant_event_id', $row)) {
892 $componentRows[$contactID][$component][$rowNum]['civicrm_participant_event_id'] = CRM_Event_PseudoConstant::event($val, FALSE);
893 $url = CRM_Report_Utils_Report::getNextUrl('event/income',
894 'reset=1&force=1&id_op=in&id_value=' . $val,
895 $this->_absoluteUrl, $this->_id
896 );
897 $componentRows[$contactID][$component][$rowNum]['civicrm_participant_event_id_link'] = $url;
898 $componentRows[$contactID][$component][$rowNum]['civicrm_participant_event_id_hover'] = ts('View Event Income details for this Event.');
899 $entryFound = TRUE;
900 }
901
902 if ($val = CRM_Utils_Array::value('civicrm_participant_participant_status_id', $row)) {
903 $componentRows[$contactID][$component][$rowNum]['civicrm_participant_participant_status_id'] = CRM_Event_PseudoConstant::participantStatus($val, FALSE);
904 }
905 if ($val = CRM_Utils_Array::value('civicrm_participant_role_id', $row)) {
906 $roles = explode(CRM_Core_DAO::VALUE_SEPARATOR, $val);
907 $value = array();
908 foreach ($roles as $role) {
909 $value[$role] = CRM_Event_PseudoConstant::participantRole($role, FALSE);
910 }
911 $componentRows[$contactID][$component][$rowNum]['civicrm_participant_role_id'] = implode(', ', $value);
912 }
913
914 $entryFound = TRUE;
915 }
916
917 if ($component == 'activity_civireport') {
918 if ($val = CRM_Utils_Array::value('civicrm_activity_activity_type_id', $row)) {
919 $componentRows[$contactID][$component][$rowNum]['civicrm_activity_activity_type_id'] = $activityTypes[$val];
920 }
921 if ($val = CRM_Utils_Array::value('civicrm_activity_activity_status_id', $row)) {
922 $componentRows[$contactID][$component][$rowNum]['civicrm_activity_activity_status_id'] = $activityStatus[$val];
923 }
924
925 $entryFound = TRUE;
926 }
927 if ($component == 'membership_civireport') {
928 if ($val = CRM_Utils_Array::value('civicrm_membership_membership_status_id', $row)) {
929 $componentRows[$contactID][$component][$rowNum]['civicrm_membership_membership_status_id'] = CRM_Member_PseudoConstant::membershipStatus($val);
930 }
931 $entryFound = TRUE;
932 }
933
934 // skip looking further in rows, if first row itself doesn't
935 // have the column we need
936 if (!$entryFound) {
937 break;
938 }
939 }
940 }
941 }
942 }
943 }
944