3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
35 class CRM_Report_Form_Contribute_History
extends CRM_Report_Form
{
36 // Primary Contacts count limitCONSTROW_COUNT_LIMIT = 10;
38 protected $_addressField = FALSE;
39 protected $_emailField = FALSE;
40 protected $_phoneField = FALSE;
41 protected $_relationshipColumns = array();
43 protected $_customGroupExtends = array(
49 protected $_referenceYear = array(
53 protected $_yearStatisticsFrom = '';
55 protected $_yearStatisticsTo = '';
59 public function __construct() {
60 $this->_autoIncludeIndexedFieldsAsOrderBys
= 1;
62 $date = CRM_Core_SelectValues
::date('custom', NULL, $yearsInPast, 0);
63 $count = $date['maxYear'];
64 $optionYear = array('' => ts('- select -'));
66 $this->_yearStatisticsFrom
= $date['minYear'];
67 $this->_yearStatisticsTo
= $date['maxYear'];
69 while ($date['minYear'] <= $count) {
70 $optionYear[$date['minYear']] = $date['minYear'];
74 $relationTypeOp = array();
75 $relationshipTypes = CRM_Core_PseudoConstant
::relationshipType();
76 foreach ($relationshipTypes as $rid => $rtype) {
77 if ($rtype['label_a_b'] != $rtype['label_b_a']) {
78 $relationTypeOp[$rid] = "{$rtype['label_a_b']}/{$rtype['label_b_a']}";
81 $relationTypeOp[$rid] = $rtype['label_a_b'];
85 $this->_columns
= array(
86 'civicrm_contact' => array(
87 'dao' => 'CRM_Contact_DAO_Contact',
90 'title' => ts('Contact Name'),
95 'first_name' => array(
96 'title' => ts('First Name'),
98 'middle_name' => array(
99 'title' => ts('Middle Name'),
101 'last_name' => array(
102 'title' => ts('Last Name'),
105 'no_display' => TRUE,
109 'gender_id' => array(
110 'title' => ts('Gender'),
112 'birth_date' => array(
113 'title' => ts('Birth Date'),
116 'title' => ts('Age'),
117 'dbAlias' => 'TIMESTAMPDIFF(YEAR, contact_civireport.birth_date, CURDATE())',
119 'contact_type' => array(
120 'title' => ts('Contact Type'),
122 'contact_sub_type' => array(
123 'title' => ts('Contact Subtype'),
126 'grouping' => 'contact-fields',
127 'order_bys' => array(
128 'sort_name' => array(
129 'title' => ts('Last Name, First Name'),
131 'default_weight' => '0',
132 'default_order' => 'ASC',
134 'first_name' => array(
135 'name' => 'first_name',
136 'title' => ts('First Name'),
138 'gender_id' => array(
139 'name' => 'gender_id',
140 'title' => ts('Gender'),
142 'birth_date' => array(
143 'name' => 'birth_date',
144 'title' => ts('Birth Date'),
146 'contact_type' => array(
147 'title' => ts('Contact Type'),
149 'contact_sub_type' => array(
150 'title' => ts('Contact Subtype'),
154 'sort_name' => array('title' => ts('Contact Name')),
156 'title' => ts('Contact ID'),
157 'no_display' => TRUE,
159 'gender_id' => array(
160 'title' => ts('Gender'),
161 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
162 'options' => CRM_Core_PseudoConstant
::get('CRM_Contact_DAO_Contact', 'gender_id'),
164 'birth_date' => array(
165 'title' => ts('Birth Date'),
166 'operatorType' => CRM_Report_Form
::OP_DATE
,
168 'contact_type' => array(
169 'title' => ts('Contact Type'),
171 'contact_sub_type' => array(
172 'title' => ts('Contact Subtype'),
176 'civicrm_email' => array(
177 'dao' => 'CRM_Core_DAO_Email',
180 'title' => ts('Email'),
184 'grouping' => 'contact-fields',
186 'civicrm_phone' => array(
187 'dao' => 'CRM_Core_DAO_Phone',
190 'title' => ts('Phone'),
194 'grouping' => 'contact-fields',
196 ) +
$this->addAddressFields(FALSE, FALSE, FALSE, array()) +
array(
197 'civicrm_relationship' => array(
198 'dao' => 'CRM_Contact_DAO_Relationship',
200 'relationship_type_id' => array(
201 'title' => ts('Relationship Type'),
204 'contact_id_a' => array('no_display' => TRUE),
205 'contact_id_b' => array('no_display' => TRUE),
208 'relationship_type_id' => array(
209 'title' => ts('Relationship Type'),
210 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
211 'options' => $relationTypeOp,
212 'type' => CRM_Utils_Type
::T_STRING
,
217 'civicrm_contribution' => array(
218 'dao' => 'CRM_Contribute_DAO_Contribution',
220 'total_amount' => array(
221 'title' => ts('Amount Statistics'),
224 'no_display' => TRUE,
225 'statistics' => array('sum' => ts('Aggregate Amount')),
227 'receive_date' => array(
230 'no_display' => TRUE,
233 'grouping' => 'contri-fields',
235 'this_year' => array(
236 'title' => ts('This Year'),
237 'operatorType' => CRM_Report_Form
::OP_SELECT
,
238 'options' => $optionYear,
241 'other_year' => array(
242 'title' => ts('Other Years'),
243 'operatorType' => CRM_Report_Form
::OP_SELECT
,
244 'options' => $optionYear,
247 'receive_date' => array('operatorType' => CRM_Report_Form
::OP_DATE
),
248 'contribution_status_id' => array(
249 'title' => ts('Contribution Status'),
250 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
251 'options' => CRM_Contribute_PseudoConstant
::contributionStatus(),
252 'default' => array(1),
254 'financial_type_id' => array(
255 'title' => ts('Financial Type'),
256 'type' => CRM_Utils_Type
::T_INT
,
257 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
258 'options' => CRM_Contribute_PseudoConstant
::financialType(),
260 'total_amount' => array(
261 'title' => ts('Contribution Amount'),
263 'total_sum' => array(
264 'title' => ts('Aggregate Amount'),
265 'type' => CRM_Report_Form
::OP_INT
,
266 'dbAlias' => 'civicrm_contribution_total_amount_sum',
273 $this->_columns
['civicrm_contribution']['fields']['civicrm_upto_' .
274 $this->_yearStatisticsFrom
] = array(
275 'title' => ts('Up To %1 Donation', array(1 => $this->_yearStatisticsFrom
)),
277 'type' => CRM_Utils_Type
::T_MONEY
,
278 'is_statistics' => TRUE,
281 $yearConter = $this->_yearStatisticsFrom
;
283 while ($yearConter <= $this->_yearStatisticsTo
) {
284 $this->_columns
['civicrm_contribution']['fields'][$yearConter] = array(
285 'title' => ts('%1 Donation', array(1 => $yearConter)),
287 'type' => CRM_Utils_Type
::T_MONEY
,
288 'is_statistics' => TRUE,
293 $this->_columns
['civicrm_contribution']['fields']['aggregate_amount'] = array(
294 'title' => ts('Aggregate Amount'),
295 'type' => CRM_Utils_Type
::T_MONEY
,
296 'is_statistics' => TRUE,
299 $this->_groupFilter
= TRUE;
300 $this->_tagFilter
= TRUE;
301 parent
::__construct();
304 public function preProcess() {
305 parent
::preProcess();
308 public function select() {
310 $this->_columnHeaders
= array();
312 foreach ($this->_columns
as $tableName => $table) {
313 if (array_key_exists('fields', $table)) {
314 foreach ($table['fields'] as $fieldName => $field) {
316 if (!empty($field['required']) ||
317 !empty($this->_params
['fields'][$fieldName])
319 if ($tableName == 'civicrm_address') {
320 $this->_addressField
= TRUE;
322 if ($tableName == 'civicrm_email') {
323 $this->_emailField
= TRUE;
325 if ($tableName == 'civicrm_phone') {
326 $this->_phoneField
= TRUE;
328 if ($tableName == 'civicrm_relationship') {
329 $this->_relationshipColumns
["{$tableName}_{$fieldName}"] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
330 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
331 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = $field['title'];
335 if (!empty($field['is_statistics'])) {
336 $this->_columnHeaders
[$fieldName]['type'] = $field['type'];
337 $this->_columnHeaders
[$fieldName]['title'] = $field['title'];
340 elseif ($fieldName == 'receive_date') {
341 if ((CRM_Utils_Array
::value('this_year_op', $this->_params
) ==
342 'fiscal' && !empty($this->_params
['this_year_value'])) ||
343 (CRM_Utils_Array
::value('other_year_op', $this->_params
==
344 'fiscal') && !empty($this->_params
['other_year_value']))
346 $select[] = self
::fiscalYearOffset($field['dbAlias']) .
347 " as {$tableName}_{$fieldName}";
350 $select[] = " YEAR(" . $field['dbAlias'] . ")" .
351 " as {$tableName}_{$fieldName}";
354 elseif ($fieldName == 'total_amount') {
355 $select[] = "SUM({$field['dbAlias']}) as {$tableName}_{$fieldName}";
358 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
359 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
360 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = $field['title'];
362 if (!empty($field['no_display'])) {
363 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['no_display'] = TRUE;
370 $this->_select
= "SELECT " . implode(', ', $select) . " ";
373 public function from() {
375 FROM civicrm_contact {$this->_aliases['civicrm_contact']}
376 INNER JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']}
377 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_contribution']}.contact_id AND
378 {$this->_aliases['civicrm_contribution']}.is_test = 0 ";
380 if ($this->_emailField
) {
381 $this->_from
.= " LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
382 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND
383 {$this->_aliases['civicrm_email']}.is_primary = 1) ";
386 if ($this->_phoneField
) {
387 $this->_from
.= " LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
388 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
389 {$this->_aliases['civicrm_phone']}.is_primary = 1) ";
392 $relContacAlias = 'contact_relationship';
393 $this->_relationshipFrom
= " INNER JOIN civicrm_relationship {$this->_aliases['civicrm_relationship']}
394 ON (({$this->_aliases['civicrm_relationship']}.contact_id_a = {$relContacAlias}.id OR {$this->_aliases['civicrm_relationship']}.contact_id_b = {$relContacAlias}.id ) AND {$this->_aliases['civicrm_relationship']}.is_active = 1) ";
396 if ($this->_addressField
) {
398 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
399 ON {$this->_aliases['civicrm_contact']}.id =
400 {$this->_aliases['civicrm_address']}.contact_id AND
401 {$this->_aliases['civicrm_address']}.is_primary = 1\n";
405 public function where() {
406 $whereClauses = $havingClauses = $relationshipWhere = array();
407 $this->_relationshipWhere
= '';
408 $this->_statusClause
= '';
410 foreach ($this->_columns
as $tableName => $table) {
411 if (array_key_exists('filters', $table)) {
412 foreach ($table['filters'] as $fieldName => $field) {
414 if ($fieldName == 'this_year' ||
$fieldName == 'other_year') {
417 elseif (CRM_Utils_Array
::value('type', $field) & CRM_Utils_Type
::T_DATE
419 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
420 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
421 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
423 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
426 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
428 $clause = $this->whereClause($field,
430 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
431 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
432 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
437 if (!empty($clause)) {
438 if ($tableName == 'civicrm_relationship') {
439 $relationshipWhere[] = $clause;
443 if ($fieldName == 'contribution_status_id') {
444 $this->_statusClause
= " AND " . $clause;
447 if (!empty($field['having'])) {
448 $havingClauses[] = $clause;
451 $whereClauses[] = $clause;
458 if (empty($whereClauses)) {
459 $this->_where
= "WHERE ( 1 ) ";
463 $this->_where
= "WHERE " . implode(' AND ', $whereClauses);
466 if ($this->_aclWhere
) {
467 $this->_where
.= " AND {$this->_aclWhere} ";
470 if (!empty($havingClauses)) {
471 // use this clause to construct group by clause.
472 $this->_having
= "HAVING " . implode(' AND ', $havingClauses);
475 if (!empty($relationshipWhere)) {
476 $this->_relationshipWhere
= ' AND ' .
477 implode(' AND ', $relationshipWhere);
481 public function groupBy() {
482 $this->_groupBy
= "GROUP BY {$this->_aliases['civicrm_contribution']}.contact_id, YEAR({$this->_aliases['civicrm_contribution']}.receive_date)";
486 * Override to set limit to 10.
488 * @param int $rowCount
492 public function limit($rowCount = self
::ROW_COUNT_LIMIT
) {
493 return parent
::limit($rowCount);
497 * Override to set pager with limit is 10.
499 * @param int $rowCount
501 public function setPager($rowCount = self
::ROW_COUNT_LIMIT
) {
502 parent
::setPager($rowCount);
510 public function statistics(&$rows) {
511 $statistics = parent
::statistics($rows);
513 foreach ($rows as $rownum => $row) {
514 if (is_numeric($rownum)) {
518 $statistics['counts']['rowCount'] = array(
519 'title' => ts('Primary Contact(s) Listed'),
523 if ($this->_rowsFound
&& ($this->_rowsFound
> $count)) {
524 $statistics['counts']['rowsFound'] = array(
525 'title' => ts('Total Primary Contact(s)'),
526 'value' => $this->_rowsFound
,
540 public static function formRule($fields, $files, $self) {
542 if (!empty($fields['this_year_value']) &&
543 !empty($fields['other_year_value']) &&
544 ($fields['this_year_value'] == $fields['other_year_value'])
546 $errors['other_year_value'] = ts("Value for filters 'This Year' and 'Other Years' can not be same.");
551 public function postProcess() {
552 // get ready with post process params
553 $this->beginPostProcess();
554 $this->fixReportParams();
556 $this->buildACLClause($this->_aliases
['civicrm_contact']);
560 $this->customDataFrom();
566 // build array of result based on column headers. This method also allows
567 // modifying column headers before using it to build result set i.e $rows.
568 $this->buildRows($sql, $rows);
570 // format result set.
571 $this->formatDisplay($rows, FALSE);
573 // assign variables to templates
574 $this->doTemplateAssignment($rows);
576 // do print / pdf / instance stuff if needed
577 $this->endPostProcess($rows);
580 public function fixReportParams() {
581 if (!empty($this->_params
['this_year_value'])) {
582 $this->_referenceYear
['this_year'] = $this->_params
['this_year_value'];
584 if (!empty($this->_params
['other_year_value'])) {
585 $this->_referenceYear
['other_year'] = $this->_params
['other_year_value'];
593 public function buildRows($sql, &$rows) {
594 $contactIds = array();
598 if (!empty($this->_referenceYear
['other_year'])) {
599 (CRM_Utils_Array
::value('other_year_op', $this->_params
) ==
600 'calendar') ?
$other_receive_date = 'YEAR (contri.receive_date)' : $other_receive_date = self
::fiscalYearOffset('contri.receive_date');
601 $addWhere .= " AND {$this->_aliases['civicrm_contact']}.id NOT IN ( SELECT DISTINCT cont.id FROM civicrm_contact cont, civicrm_contribution contri WHERE cont.id = contri.contact_id AND {$other_receive_date} = {$this->_referenceYear['other_year']} AND contri.is_test = 0 ) ";
603 if (!empty($this->_referenceYear
['this_year'])) {
604 (CRM_Utils_Array
::value('this_year_op', $this->_params
) ==
605 'calendar') ?
$receive_date = 'YEAR (contri.receive_date)' : $receive_date = self
::fiscalYearOffset('contri.receive_date');
606 $addWhere .= " AND {$this->_aliases['civicrm_contact']}.id IN ( SELECT DISTINCT cont.id FROM civicrm_contact cont, civicrm_contribution contri WHERE cont.id = contri.contact_id AND {$receive_date} = {$this->_referenceYear['this_year']} AND contri.is_test = 0 ) ";
609 $getContacts = "SELECT SQL_CALC_FOUND_ROWS {$this->_aliases['civicrm_contact']}.id as cid, SUM({$this->_aliases['civicrm_contribution']}.total_amount) as civicrm_contribution_total_amount_sum {$this->_from} {$this->_where} {$addWhere} GROUP BY {$this->_aliases['civicrm_contact']}.id {$this->_having} {$this->_limit}";
611 $dao = CRM_Core_DAO
::executeQuery($getContacts);
613 while ($dao->fetch()) {
614 $contactIds[] = $dao->cid
;
619 $relationshipRows = array();
620 if (empty($contactIds)) {
624 $primaryContributions = $this->buildContributionRows($contactIds);
626 list($relationshipRows, $relatedContactIds) = $this->buildRelationshipRows($contactIds);
628 if (empty($relatedContactIds)) {
629 $rows = $primaryContributions;
633 $relatedContributions = $this->buildContributionRows($relatedContactIds);
635 $summaryYears = array();
636 $summaryYears[] = "civicrm_upto_{$this->_yearStatisticsFrom}";
637 $yearConter = $this->_yearStatisticsFrom
;
639 while ($yearConter <= $this->_yearStatisticsTo
) {
640 $summaryYears[] = $yearConter;
643 $summaryYears[] = 'aggregate_amount';
645 foreach ($primaryContributions as $cid => $primaryRow) {
647 if (!isset($relationshipRows[$cid])) {
652 $total['civicrm_contact_sort_name'] = ts('Total');
653 foreach ($summaryYears as $year) {
654 $total[$year] = CRM_Utils_Array
::value($year, $primaryRow, 0);
657 $relatedContact = FALSE;
659 foreach ($relationshipRows[$cid] as $relcid => $relRow) {
660 if (!isset($relatedContributions[$relcid])) {
663 $relatedContact = TRUE;
664 $relatedRow = $relatedContributions[$relcid];
665 foreach ($summaryYears as $year) {
666 $total[$year] +
= CRM_Utils_Array
::value($year, $relatedRow, 0);
669 foreach (array_keys($this->_relationshipColumns
) as $col) {
670 if (!empty($relRow[$col])) {
671 $relatedRow[$col] = $relRow[$col];
674 $rows["{$cid}_{$relcid}"] = $relatedRow;
676 if ($relatedContact) {
677 $rows["{$cid}_total"] = $total;
678 $rows["{$cid}_bank"] = array('civicrm_contact_sort_name' => ' ');
688 public function buildContributionRows($contactIds) {
690 if (empty($contactIds)) {
694 $sqlContribution = "{$this->_select} {$this->_from} WHERE {$this->_aliases['civicrm_contact']}.id IN (" .
695 implode(',', $contactIds) .
696 ") AND {$this->_aliases['civicrm_contribution']}.is_test = 0 {$this->_statusClause} {$this->_groupBy} ";
698 $dao = CRM_Core_DAO
::executeQuery($sqlContribution);
699 $contributionSum = 0;
701 while ($dao->fetch()) {
702 if (!$dao->civicrm_contact_id
) {
706 foreach ($this->_columnHeaders
as $key => $value) {
707 if (property_exists($dao, $key)) {
708 $rows[$dao->civicrm_contact_id
][$key] = $dao->$key;
711 if ($dao->civicrm_contribution_receive_date
) {
712 if ($dao->civicrm_contribution_receive_date
>
713 $this->_yearStatisticsFrom
715 $rows[$dao->civicrm_contact_id
][$dao->civicrm_contribution_receive_date
] = $dao->civicrm_contribution_total_amount
;
718 if (!isset($rows[$dao->civicrm_contact_id
]["civicrm_upto_{$this->_yearStatisticsFrom}"])) {
719 $rows[$dao->civicrm_contact_id
]["civicrm_upto_{$this->_yearStatisticsFrom}"] = 0;
722 $rows[$dao->civicrm_contact_id
]["civicrm_upto_{$this->_yearStatisticsFrom}"] +
= $dao->civicrm_contribution_total_amount
;
726 if (!isset($rows[$dao->civicrm_contact_id
]['aggregate_amount'])) {
727 $rows[$dao->civicrm_contact_id
]['aggregate_amount'] = 0;
729 $rows[$dao->civicrm_contact_id
]['aggregate_amount'] +
= $dao->civicrm_contribution_total_amount
;
740 public function buildRelationshipRows($contactIds) {
741 $relationshipRows = $relatedContactIds = array();
742 if (empty($contactIds)) {
743 return array($relationshipRows, $relatedContactIds);
746 $relContactAlias = 'contact_relationship';
748 if (!empty($this->_relationshipColumns
)) {
749 $addRelSelect = ', ' . implode(', ', $this->_relationshipColumns
);
751 $sqlRelationship = "SELECT {$this->_aliases['civicrm_relationship']}.relationship_type_id as relationship_type_id, {$this->_aliases['civicrm_relationship']}.contact_id_a as contact_id_a, {$this->_aliases['civicrm_relationship']}.contact_id_b as contact_id_b {$addRelSelect} FROM civicrm_contact {$relContactAlias} {$this->_relationshipFrom} WHERE {$relContactAlias}.id IN (" .
752 implode(',', $contactIds) .
753 ") AND {$this->_aliases['civicrm_relationship']}.is_active = 1 {$this->_relationshipWhere} GROUP BY {$this->_aliases['civicrm_relationship']}.contact_id_a, {$this->_aliases['civicrm_relationship']}.contact_id_b";
754 $relationshipTypes = CRM_Core_PseudoConstant
::relationshipType();
756 $dao = CRM_Core_DAO
::executeQuery($sqlRelationship);
757 while ($dao->fetch()) {
759 foreach (array_keys($this->_relationshipColumns
) as $rel_column) {
760 $row[$rel_column] = $dao->$rel_column;
762 if (in_array($dao->contact_id_a
, $contactIds)) {
763 $row['civicrm_relationship_relationship_type_id'] = $relationshipTypes[$dao->relationship_type_id
]['label_a_b'];
764 $row['civicrm_relationship_contact_id'] = $dao->contact_id_b
;
765 $relationshipRows[$dao->contact_id_a
][$dao->contact_id_b
] = $row;
766 $relatedContactIds[$dao->contact_id_b
] = $dao->contact_id_b
;
768 if (in_array($dao->contact_id_b
, $contactIds)) {
769 $row['civicrm_relationship_contact_id'] = $dao->contact_id_a
;
770 $row['civicrm_relationship_relationship_type_id'] = $relationshipTypes[$dao->relationship_type_id
]['label_b_a'];
771 $relationshipRows[$dao->contact_id_b
][$dao->contact_id_a
] = $row;
772 $relatedContactIds[$dao->contact_id_a
] = $dao->contact_id_a
;
776 return array($relationshipRows, $relatedContactIds);
780 * Override "This Year" $op options
781 * @param string $type
782 * @param null $fieldName
786 public function getOperationPair($type = "string", $fieldName = NULL) {
787 if ($fieldName == 'this_year' ||
$fieldName == 'other_year') {
789 'calendar' => ts('Is Calendar Year'),
790 'fiscal' => ts('Fiscal Year Starting'),
793 return parent
::getOperationPair($type, $fieldName);
797 * Alter display of rows.
799 * Iterate through the rows retrieved via SQL and make changes for display purposes,
800 * such as rendering contacts as links.
803 * Rows generated by SQL, with an array for each row.
805 public function alterDisplay(&$rows) {
810 $last_primary = NULL;
811 foreach ($rows as $rowNum => $row) {
813 if (array_key_exists('civicrm_contact_gender_id', $row)) {
814 if ($value = $row['civicrm_contact_gender_id']) {
815 $gender = CRM_Core_PseudoConstant
::get('CRM_Contact_DAO_Contact', 'gender_id');
816 $row['civicrm_contact_gender_id'] = $rows[$rowNum]['civicrm_contact_gender_id'] = $gender[$value];
821 // Highlight primary contact and amount row
822 if (is_numeric($rowNum) ||
823 ($last_primary && ($rowNum == "{$last_primary}_total"))
825 if (is_numeric($rowNum)) {
826 $last_primary = $rowNum;
828 foreach ($row as $key => $value) {
829 if ($key == 'civicrm_contact_id') {
837 if ($last_primary && ($rowNum == "{$last_primary}_total")) {
838 $value = CRM_Utils_Money
::format($value, ' ');
840 $row[$key] = '<strong>' . $value . '</strong>';
842 $rows[$rowNum] = $row;
845 // Convert Display name into link
846 if (!empty($row['civicrm_contact_sort_name']) &&
847 !empty($row['civicrm_contact_id'])
849 $url = CRM_Report_Utils_Report
::getNextUrl('contribute/detail',
850 'reset=1&force=1&id_op=eq&id_value=' . $row['civicrm_contact_id'],
851 $this->_absoluteUrl
, $this->_id
853 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
854 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contribution Details for this Contact.");
857 // display birthday in the configured custom format
858 if (array_key_exists('civicrm_contact_birth_date', $row)) {
859 $birthDate = $row['civicrm_contact_birth_date'];
861 $rows[$rowNum]['civicrm_contact_birth_date'] = CRM_Utils_Date
::customFormat($birthDate, '%Y%m%d');