3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2017
33 class CRM_Report_Form_Contact_Detail
extends CRM_Report_Form
{
34 const ROW_COUNT_LIMIT
= 10;
36 protected $_summary = NULL;
38 protected $_customGroupExtends = array(
46 * This report has not been optimised for group filtering.
48 * The functionality for group filtering has been improved but not
49 * all reports have been adjusted to take care of it. This report has not
50 * and will run an inefficient query until fixed.
56 protected $groupFilterNotOptimised = TRUE;
61 public function __construct() {
62 $this->_autoIncludeIndexedFieldsAsOrderBys
= 1;
63 $this->_columns
= array(
64 'civicrm_contact' => array(
65 'dao' => 'CRM_Contact_DAO_Contact',
68 'title' => ts('Contact Name'),
72 'first_name' => array(
73 'title' => ts('First Name'),
75 'middle_name' => array(
76 'title' => ts('Middle Name'),
79 'title' => ts('Last Name'),
86 'title' => ts('Gender'),
88 'birth_date' => array(
89 'title' => ts('Birth Date'),
93 'dbAlias' => 'TIMESTAMPDIFF(YEAR, contact_civireport.birth_date, CURDATE())',
95 'contact_type' => array(
96 'title' => ts('Contact Type'),
98 'contact_sub_type' => array(
99 'title' => ts('Contact Subtype'),
102 'filters' => $this->getBasicContactFilters(),
103 'grouping' => 'contact-fields',
104 'order_bys' => array(
105 'sort_name' => array(
106 'title' => ts('Last Name, First Name'),
108 'default_weight' => '0',
109 'default_order' => 'ASC',
111 'first_name' => array(
112 'title' => ts('First Name'),
114 'gender_id' => array(
115 'name' => 'gender_id',
116 'title' => ts('Gender'),
118 'birth_date' => array(
119 'name' => 'birth_date',
120 'title' => ts('Birth Date'),
122 'contact_type' => array(
123 'title' => ts('Contact Type'),
125 'contact_sub_type' => array(
126 'title' => ts('Contact Subtype'),
130 'civicrm_address' => array(
131 'dao' => 'CRM_Core_DAO_Address',
132 'grouping' => 'contact-fields',
134 'street_address' => NULL,
136 'postal_code' => NULL,
137 'state_province_id' => array(
138 'title' => ts('State/Province'),
141 'order_bys' => array(
142 'state_province_id' => array('title' => ts('State/Province')),
143 'city' => array('title' => ts('City')),
144 'postal_code' => array('title' => ts('Postal Code')),
147 'civicrm_country' => array(
148 'dao' => 'CRM_Core_DAO_Country',
150 'name' => array('title' => ts('Country'), 'default' => TRUE),
152 'order_bys' => array(
153 'name' => array('title' => ts('Country')),
155 'grouping' => 'contact-fields',
157 'civicrm_email' => array(
158 'dao' => 'CRM_Core_DAO_Email',
161 'title' => ts('Email'),
165 'grouping' => 'contact-fields',
166 'order_bys' => array(
168 'title' => ts('Email'),
172 'civicrm_contribution' => array(
173 'dao' => 'CRM_Contribute_DAO_Contribution',
175 'contact_id' => array(
176 'no_display' => TRUE,
179 'contribution_id' => array(
180 'title' => ts('Contribution'),
184 'total_amount' => array('default' => TRUE),
185 'financial_type_id' => array(
186 'title' => ts('Financial Type'),
190 'receive_date' => array('default' => TRUE),
191 'receipt_date' => NULL,
192 'contribution_status_id' => array(
193 'title' => ts('Contribution Status'),
196 'contribution_source' => NULL,
199 'civicrm_membership' => array(
200 'dao' => 'CRM_Member_DAO_Membership',
202 'contact_id' => array(
203 'no_display' => TRUE,
206 'membership_id' => array(
207 'title' => ts('Membership'),
211 'membership_type_id' => array(
212 'title' => ts('Membership Type'),
216 'membership_start_date' => array(
217 'title' => ts('Start Date'),
220 'membership_end_date' => array(
221 'title' => ts('End Date'),
224 'membership_status_id' => array(
225 'name' => 'status_id',
226 'title' => ts('Membership Status'),
229 'source' => array('title' => ts('Membership Source')),
232 'civicrm_participant' => array(
233 'dao' => 'CRM_Event_DAO_Participant',
235 'contact_id' => array(
236 'no_display' => TRUE,
239 'participant_id' => array(
240 'title' => ts('Participant'),
244 'event_id' => array('default' => TRUE),
245 'participant_status_id' => array(
246 'name' => 'status_id',
247 'title' => ts('Participant Status'),
251 'title' => ts('Role'),
254 'participant_register_date' => array(
255 'title' => ts('Register Date'),
258 'fee_level' => array(
259 'title' => ts('Fee Level'),
262 'fee_amount' => array(
263 'title' => ts('Fee Amount'),
268 'civicrm_relationship' => array(
269 'dao' => 'CRM_Contact_DAO_Relationship',
271 'relationship_id' => array(
273 'title' => ts('Relationship'),
277 'relationship_type_id' => array(
278 'title' => ts('Relationship Type'),
281 'contact_id_b' => array(
282 'title' => ts('Relationship With'),
285 'start_date' => array(
286 'title' => ts('Start Date'),
287 'type' => CRM_Report_Form
::OP_DATE
,
290 'title' => ts('End Date'),
291 'type' => CRM_Report_Form
::OP_DATE
,
295 'civicrm_activity' => array(
296 'dao' => 'CRM_Activity_DAO_Activity',
299 'title' => ts('Activity'),
303 'activity_type_id' => array(
304 'title' => ts('Activity Type'),
308 'title' => ts('Subject'),
311 'activity_date_time' => array(
312 'title' => ts('Activity Date'),
315 'activity_status_id' => array(
316 'name' => 'status_id',
317 'title' => ts('Activity Status'),
321 'grouping' => 'activity-fields',
323 'civicrm_activity_target' => array(
324 'dao' => 'CRM_Activity_DAO_ActivityContact',
326 'target_contact_id' => array(
327 'title' => ts('With Contact'),
328 'name' => 'contact_id',
332 'grouping' => 'activity-fields',
334 'civicrm_activity_assignment' => array(
335 'dao' => 'CRM_Activity_DAO_ActivityContact',
337 'assignee_contact_id' => array(
338 'title' => ts('Assigned to'),
339 'name' => 'contact_id',
343 'grouping' => 'activity-fields',
345 'civicrm_activity_source' => array(
346 'dao' => 'CRM_Activity_DAO_ActivityContact',
348 'source_contact_id' => array(
349 'title' => ts('Added By'),
350 'name' => 'contact_id',
354 'grouping' => 'activity-fields',
356 'civicrm_phone' => array(
357 'dao' => 'CRM_Core_DAO_Phone',
360 'phone_ext' => array(
361 'title' => ts('Phone Extension'),
364 'grouping' => 'contact-fields',
367 $this->_groupFilter
= TRUE;
368 $this->_tagFilter
= TRUE;
369 parent
::__construct();
372 public function preProcess() {
373 $this->_csvSupported
= FALSE;
374 parent
::preProcess();
377 public function select() {
379 $this->_columnHeaders
= array();
380 $this->_component
= array(
381 'contribution_civireport',
382 'membership_civireport',
383 'participant_civireport',
384 'relationship_civireport',
385 'activity_civireport',
387 foreach ($this->_columns
as $tableName => $table) {
388 if (array_key_exists('fields', $table)) {
389 foreach ($table['fields'] as $fieldName => $field) {
390 if (!empty($field['required']) ||
391 !empty($this->_params
['fields'][$fieldName])
393 //isolate the select clause compoenent wise
394 if (in_array($table['alias'], $this->_component
)) {
395 $select[$table['alias']][] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
396 $this->_columnHeadersComponent
[$table['alias']]["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
397 $this->_columnHeadersComponent
[$table['alias']]["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array
::value('title', $field);
399 elseif ($table['alias'] ==
400 $this->_aliases
['civicrm_activity_target'] ||
402 $this->_aliases
['civicrm_activity_assignment'] ||
403 $table['alias'] == $this->_aliases
['civicrm_activity_source']
405 if ($table['alias'] == $this->_aliases
['civicrm_activity_target']
407 $addContactId = 'civicrm_activity_target.contact_id as target_contact_id';
409 elseif ($table['alias'] ==
410 $this->_aliases
['civicrm_activity_source']
412 $addContactId = 'civicrm_activity_source.contact_id';
415 $addContactId = 'civicrm_activity_assignment.contact_id as assignee_contact_id';
418 $tableName = $table['alias'];
419 $select['activity_civireport'][] = "$tableName.display_name as {$tableName}_{$fieldName}, $addContactId ";
420 $this->_columnHeadersComponent
['activity_civireport']["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
421 $this->_columnHeadersComponent
['activity_civireport']["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array
::value('title', $field);
424 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
425 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
426 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = $field['title'];
433 foreach ($this->_component
as $val) {
434 if (!empty($select[$val])) {
435 $this->_selectComponent
[$val] = "SELECT " . implode(', ', $select[$val]) . " ";
436 unset($select[$val]);
440 $this->_select
= "SELECT " . implode(', ', $select) . " ";
450 public static function formRule($fields, $files, $self) {
455 public function from() {
458 FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}";
460 if ($this->isTableSelected('civicrm_country') ||
461 $this->isTableSelected('civicrm_address')
464 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
465 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND
466 {$this->_aliases['civicrm_address']}.is_primary = 1 ) ";
469 if ($this->isTableSelected('civicrm_email')) {
471 LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
472 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND
473 {$this->_aliases['civicrm_email']}.is_primary = 1) ";
476 if ($this->isTableSelected('civicrm_phone')) {
478 LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
479 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
480 {$this->_aliases['civicrm_phone']}.is_primary = 1 ";
483 if ($this->isTableSelected('civicrm_country')) {
485 LEFT JOIN civicrm_country {$this->_aliases['civicrm_country']}
486 ON {$this->_aliases['civicrm_address']}.country_id = {$this->_aliases['civicrm_country']}.id AND
487 {$this->_aliases['civicrm_address']}.is_primary = 1 ";
490 $this->_from
.= "{$group}";
492 foreach ($this->_component
as $val) {
493 if (!empty($this->_selectComponent
['contribution_civireport'])) {
494 $this->_formComponent
['contribution_civireport'] = " FROM
495 civicrm_contact {$this->_aliases['civicrm_contact']}
496 INNER JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']}
497 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_contribution']}.contact_id
501 if (!empty($this->_selectComponent
['membership_civireport'])) {
502 $this->_formComponent
['membership_civireport'] = " FROM
503 civicrm_contact {$this->_aliases['civicrm_contact']}
504 INNER JOIN civicrm_membership {$this->_aliases['civicrm_membership']}
505 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_membership']}.contact_id
508 if (!empty($this->_selectComponent
['participant_civireport'])) {
509 $this->_formComponent
['participant_civireport'] = " FROM
510 civicrm_contact {$this->_aliases['civicrm_contact']}
511 INNER JOIN civicrm_participant {$this->_aliases['civicrm_participant']}
512 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_participant']}.contact_id
516 if (!empty($this->_selectComponent
['activity_civireport'])) {
517 $activityContacts = CRM_Activity_BAO_ActivityContact
::buildOptions('record_type_id', 'validate');
518 $assigneeID = CRM_Utils_Array
::key('Activity Assignees', $activityContacts);
519 $targetID = CRM_Utils_Array
::key('Activity Targets', $activityContacts);
520 $sourceID = CRM_Utils_Array
::key('Activity Source', $activityContacts);
522 $this->_formComponent
['activity_civireport'] = "FROM
523 civicrm_activity {$this->_aliases['civicrm_activity']}
524 LEFT JOIN civicrm_activity_contact civicrm_activity_target ON
525 {$this->_aliases['civicrm_activity']}.id = civicrm_activity_target.activity_id AND
526 civicrm_activity_target.record_type_id = {$targetID}
527 LEFT JOIN civicrm_activity_contact civicrm_activity_assignment ON
528 {$this->_aliases['civicrm_activity']}.id = civicrm_activity_assignment.activity_id AND civicrm_activity_assignment.record_type_id = {$assigneeID}
529 LEFT JOIN civicrm_activity_contact civicrm_activity_source
530 ON {$this->_aliases['civicrm_activity']}.id = civicrm_activity_source.activity_id AND
531 civicrm_activity_source.record_type_id = {$sourceID}
532 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_activity_target']} ON
533 civicrm_activity_target.contact_id = {$this->_aliases['civicrm_activity_target']}.id
535 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_activity_assignment']} ON
536 civicrm_activity_assignment.contact_id = {$this->_aliases['civicrm_activity_assignment']}.id
537 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_activity_source']} ON
538 civicrm_activity_source.contact_id = {$this->_aliases['civicrm_activity_source']}.id
539 LEFT JOIN civicrm_option_value ON
540 ( {$this->_aliases['civicrm_activity']}.activity_type_id = civicrm_option_value.value )
541 LEFT JOIN civicrm_option_group ON
542 civicrm_option_group.id = civicrm_option_value.option_group_id
543 LEFT JOIN civicrm_case_activity ON
544 civicrm_case_activity.activity_id = {$this->_aliases['civicrm_activity']}.id
545 LEFT JOIN civicrm_case ON
546 civicrm_case_activity.case_id = civicrm_case.id
547 LEFT JOIN civicrm_case_contact ON
548 civicrm_case_contact.case_id = civicrm_case.id ";
551 if (!empty($this->_selectComponent
['relationship_civireport'])) {
552 $this->_formComponent
['relationship_civireport'] = "FROM
553 civicrm_relationship {$this->_aliases['civicrm_relationship']}
555 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']} ON
556 {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_relationship']}.contact_id_b
557 LEFT JOIN civicrm_contact contact_a ON
558 contact_a.id = {$this->_aliases['civicrm_relationship']}.contact_id_a ";
563 public function where() {
566 foreach ($this->_columns
as $tableName => $table) {
567 if (array_key_exists('filters', $table)) {
568 foreach ($table['filters'] as $fieldName => $field) {
570 if (CRM_Utils_Array
::value('operatorType', $field) & CRM_Report_Form
::OP_DATE
572 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
573 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
574 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
576 $clause = $this->dateClause($field['dbAlias'], $relative, $from, $to);
579 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
580 $clause = $this->whereClause($field,
582 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
583 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
584 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
587 if (!empty($clause)) {
588 $clauses[] = $clause;
594 if (empty($clauses)) {
595 $this->_where
= "WHERE ( 1 ) ";
598 $this->_where
= "WHERE " . implode(' AND ', $clauses);
601 if ($this->_aclWhere
) {
602 $this->_where
.= " AND {$this->_aclWhere} ";
609 public function clauseComponent() {
610 $selectedContacts = implode(',', $this->_contactSelected
);
611 $contribution = $membership = $participant = NULL;
612 $eligibleResult = $rows = $tempArray = array();
613 foreach ($this->_component
as $val) {
614 if (!empty($this->_selectComponent
[$val]) &&
615 ($val != 'activity_civireport' && $val != 'relationship_civireport')
617 $sql = "{$this->_selectComponent[$val]} {$this->_formComponent[$val]}
618 WHERE {$this->_aliases['civicrm_contact']}.id IN ( $selectedContacts )
621 $dao = CRM_Core_DAO
::executeQuery($sql);
622 while ($dao->fetch()) {
624 $eligibleResult[$val] = $val;
625 $CC = 'civicrm_' . substr_replace($val, '', -11, 11) . '_contact_id';
627 foreach ($this->_columnHeadersComponent
[$val] as $key => $value) {
629 $row[$key] = $dao->$key;
632 //if record exist for component(except contact_id)
633 //since contact_id is selected for every component
634 if ($countRecord > 1) {
635 $rows[$dao->$CC][$val][] = $row;
637 $tempArray[$dao->$CC] = $dao->$CC;
642 if (!empty($this->_selectComponent
['relationship_civireport'])) {
644 $relTypes = CRM_Contact_BAO_Relationship
::getContactRelationshipType(NULL, NULL, NULL, NULL, TRUE);
646 $val = 'relationship_civireport';
647 $eligibleResult[$val] = $val;
648 $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]}
649 WHERE ({$this->_aliases['civicrm_contact']}.id IN ( $selectedContacts )
651 contact_a.id IN ( $selectedContacts ) ) AND
652 {$this->_aliases['civicrm_relationship']}.is_active = 1 AND
653 contact_a.is_deleted = 0 AND
654 {$this->_aliases['civicrm_contact']}.is_deleted = 0
657 $dao = CRM_Core_DAO
::executeQuery($sql);
658 while ($dao->fetch()) {
659 foreach ($this->_columnHeadersComponent
[$val] as $key => $value) {
660 if ($key == 'civicrm_relationship_contact_id_b') {
661 $row[$key] = $dao->contact_b_name
;
665 $row[$key] = $dao->$key;
668 $relTitle = "" . $dao->civicrm_relationship_relationship_type_id
.
670 $row['civicrm_relationship_relationship_type_id'] = $relTypes[$relTitle];
672 $rows[$dao->contact_a_id
][$val][] = $row;
674 $row['civicrm_relationship_contact_id_b'] = $dao->contact_a_name
;
675 $relTitle = "" . $dao->civicrm_relationship_relationship_type_id
.
677 if (isset($relTypes[$relTitle])) {
678 $row['civicrm_relationship_relationship_type_id'] = $relTypes[$relTitle];
680 $rows[$dao->civicrm_relationship_contact_id_b
][$val][] = $row;
684 if (!empty($this->_selectComponent
['activity_civireport'])) {
686 $componentClause = "civicrm_option_value.component_id IS NULL";
687 $componentsIn = NULL;
688 $compInfo = CRM_Core_Component
::getEnabledComponents();
689 foreach ($compInfo as $compObj) {
690 if ($compObj->info
['showActivitiesInCore']) {
691 $componentsIn = $componentsIn ?
($componentsIn . ', ' .
692 $compObj->componentID
) : $compObj->componentID
;
696 $componentClause = "( $componentClause OR
697 civicrm_option_value.component_id IN ($componentsIn) )";
700 $val = 'activity_civireport';
701 $eligibleResult[$val] = $val;
702 $sql = "{$this->_selectComponent[$val]} ,
703 {$this->_aliases['civicrm_activity_source']}.display_name as added_by {$this->_formComponent[$val]}
705 WHERE ( civicrm_activity_source.contact_id IN ($selectedContacts) OR
706 civicrm_activity_target.contact_id IN ($selectedContacts) OR
707 civicrm_activity_assignment.contact_id IN ($selectedContacts) OR
708 civicrm_case_contact.contact_id IN ($selectedContacts) ) AND
709 civicrm_option_group.name = 'activity_type' AND
710 {$this->_aliases['civicrm_activity']}.is_test = 0 AND
712 ORDER BY {$this->_aliases['civicrm_activity']}.activity_date_time desc ";
714 $dao = CRM_Core_DAO
::executeQuery($sql);
715 while ($dao->fetch()) {
716 foreach ($this->_columnHeadersComponent
[$val] as $key => $value) {
717 if ($key == 'civicrm_activity_source_contact_id') {
718 $row[$key] = $dao->added_by
;
721 $row[$key] = $dao->$key;
724 if (isset($dao->civicrm_activity_source_contact_id
)) {
725 $rows[$dao->civicrm_activity_source_contact_id
][$val][] = $row;
727 if (isset($dao->target_contact_id
)) {
728 $rows[$dao->target_contact_id
][$val][] = $row;
730 if (isset($dao->assignee_contact_id
)) {
731 $rows[$dao->assignee_contact_id
][$val][] = $row;
735 //unset the component header if data is not present
736 foreach ($this->_component
as $val) {
737 if (!in_array($val, $eligibleResult)) {
739 unset($this->_columnHeadersComponent
[$val]);
752 public function statistics(&$rows) {
753 $statistics = array();
755 $count = count($rows);
756 if ($this->_rollup
&& ($this->_rollup
!= '')) {
760 $this->countStat($statistics, $count);
761 $this->filterStat($statistics);
767 * Override to set limit is 10
768 * @param int $rowCount
770 public function limit($rowCount = self
::ROW_COUNT_LIMIT
) {
771 parent
::limit($rowCount);
775 * Override to set pager with limit is 10
776 * @param int $rowCount
778 public function setPager($rowCount = self
::ROW_COUNT_LIMIT
) {
779 parent
::setPager($rowCount);
782 public function postProcess() {
784 $this->beginPostProcess();
786 // get the acl clauses built before we assemble the query
787 $this->buildACLClause($this->_aliases
['civicrm_contact']);
789 $sql = $this->buildQuery(TRUE);
791 $rows = $graphRows = $this->_contactSelected
= array();
792 $this->buildRows($sql, $rows);
793 foreach ($rows as $key => $val) {
794 $rows[$key]['contactID'] = $val['civicrm_contact_id'];
795 $this->_contactSelected
[] = $val['civicrm_contact_id'];
798 $this->formatDisplay($rows);
800 if (!empty($this->_contactSelected
)) {
801 $componentRows = $this->clauseComponent();
802 $this->alterComponentDisplay($componentRows);
804 //unset Conmponent id and contact id from display
805 foreach ($this->_columnHeadersComponent
as $componentTitle => $headers) {
806 $id_header = 'civicrm_' . substr_replace($componentTitle, '', -11, 11) . '_' .
807 substr_replace($componentTitle, '', -11, 11) . '_id';
808 $contact_header = 'civicrm_' . substr_replace($componentTitle, '', -11, 11) .
810 if ($componentTitle == 'activity_civireport') {
811 $id_header = 'civicrm_' . substr_replace($componentTitle, '', -11, 11) . '_id';
814 unset($this->_columnHeadersComponent
[$componentTitle][$id_header]);
815 unset($this->_columnHeadersComponent
[$componentTitle][$contact_header]);
818 $this->assign_by_ref('columnHeadersComponent', $this->_columnHeadersComponent
);
819 $this->assign_by_ref('componentRows', $componentRows);
822 $this->doTemplateAssignment($rows);
823 $this->endPostProcess();
827 * Alter display of rows.
829 * Iterate through the rows retrieved via SQL and make changes for display purposes,
830 * such as rendering contacts as links.
833 * Rows generated by SQL, with an array for each row.
835 public function alterDisplay(&$rows) {
839 foreach ($rows as $rowNum => $row) {
840 // make count columns point to detail report
842 // change contact name with link
843 if (array_key_exists('civicrm_contact_sort_name', $row) &&
844 array_key_exists('civicrm_contact_id', $row)
847 $url = CRM_Utils_System
::url('civicrm/contact/view',
848 'reset=1&cid=' . $row['civicrm_contact_id'],
851 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
852 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts('View Contact Record');
856 // Handle ID to label conversion for contact fields
857 $entryFound = $this->alterDisplayContactFields($row, $rows, $rowNum, NULL, NULL) ?
TRUE : $entryFound;
859 // display birthday in the configured custom format
860 if (array_key_exists('civicrm_contact_birth_date', $row)) {
861 $birthDate = $row['civicrm_contact_birth_date'];
863 $rows[$rowNum]['civicrm_contact_birth_date'] = CRM_Utils_Date
::customFormat($birthDate, '%Y%m%d');
868 if (array_key_exists('civicrm_address_state_province_id', $row)) {
869 if ($value = $row['civicrm_address_state_province_id']) {
870 $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant
::stateProvince($value, FALSE);
875 // skip looking further in rows, if first row itself doesn't
876 // have the column we need
884 * @param $componentRows
886 public function alterComponentDisplay(&$componentRows) {
887 // custom code to alter rows
888 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, FALSE, 'label', TRUE);
889 $activityStatus = CRM_Core_PseudoConstant
::activityStatus();
892 foreach ($componentRows as $contactID => $components) {
893 foreach ($components as $component => $rows) {
894 foreach ($rows as $rowNum => $row) {
895 // handle contribution
896 if ($component == 'contribution_civireport') {
897 if ($val = CRM_Utils_Array
::value('civicrm_contribution_financial_type_id', $row)) {
898 $componentRows[$contactID][$component][$rowNum]['civicrm_contribution_financial_type_id'] = CRM_Contribute_PseudoConstant
::financialType($val, FALSE);
901 if ($val = CRM_Utils_Array
::value('civicrm_contribution_contribution_status_id', $row)) {
902 $componentRows[$contactID][$component][$rowNum]['civicrm_contribution_contribution_status_id'] = CRM_Contribute_PseudoConstant
::contributionStatus($val);
907 if ($component == 'membership_civireport') {
908 if ($val = CRM_Utils_Array
::value('civicrm_membership_membership_type_id', $row)) {
909 $componentRows[$contactID][$component][$rowNum]['civicrm_membership_membership_type_id'] = CRM_Member_PseudoConstant
::membershipType($val, FALSE);
912 if ($val = CRM_Utils_Array
::value('civicrm_membership_status_id', $row)) {
913 $componentRows[$contactID][$component][$rowNum]['civicrm_membership_status_id'] = CRM_Member_PseudoConstant
::membershipStatus($val, FALSE);
918 if ($component == 'participant_civireport') {
919 if ($val = CRM_Utils_Array
::value('civicrm_participant_event_id', $row)) {
920 $componentRows[$contactID][$component][$rowNum]['civicrm_participant_event_id'] = CRM_Event_PseudoConstant
::event($val, FALSE);
921 $url = CRM_Report_Utils_Report
::getNextUrl('event/income',
922 'reset=1&force=1&id_op=in&id_value=' . $val,
923 $this->_absoluteUrl
, $this->_id
925 $componentRows[$contactID][$component][$rowNum]['civicrm_participant_event_id_link'] = $url;
926 $componentRows[$contactID][$component][$rowNum]['civicrm_participant_event_id_hover'] = ts('View Event Income details for this Event.');
930 if ($val = CRM_Utils_Array
::value('civicrm_participant_participant_status_id', $row)) {
931 $componentRows[$contactID][$component][$rowNum]['civicrm_participant_participant_status_id'] = CRM_Event_PseudoConstant
::participantStatus($val, FALSE);
933 if ($val = CRM_Utils_Array
::value('civicrm_participant_role_id', $row)) {
934 $roles = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $val);
936 foreach ($roles as $role) {
937 $value[$role] = CRM_Event_PseudoConstant
::participantRole($role, FALSE);
939 $componentRows[$contactID][$component][$rowNum]['civicrm_participant_role_id'] = implode(', ', $value);
945 if ($component == 'activity_civireport') {
946 if ($val = CRM_Utils_Array
::value('civicrm_activity_activity_type_id', $row)) {
947 $componentRows[$contactID][$component][$rowNum]['civicrm_activity_activity_type_id'] = $activityTypes[$val];
949 if ($val = CRM_Utils_Array
::value('civicrm_activity_activity_status_id', $row)) {
950 $componentRows[$contactID][$component][$rowNum]['civicrm_activity_activity_status_id'] = $activityStatus[$val];
955 if ($component == 'membership_civireport') {
956 if ($val = CRM_Utils_Array
::value('civicrm_membership_membership_status_id', $row)) {
957 $componentRows[$contactID][$component][$rowNum]['civicrm_membership_membership_status_id'] = CRM_Member_PseudoConstant
::membershipStatus($val);
962 // skip looking further in rows, if first row itself doesn't
963 // have the column we need