Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
fa938177 | 6 | | Copyright CiviCRM LLC (c) 2004-2016 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
fa938177 | 31 | * @copyright CiviCRM LLC (c) 2004-2016 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | class CRM_Report_Form_Contribute_HouseholdSummary extends CRM_Report_Form { | |
36 | ||
37 | protected $_addressField = FALSE; | |
38 | ||
39 | protected $_emailField = FALSE; | |
40 | ||
41 | public $_drilldownReport = array('contribute/detail' => 'Link to Detail Report'); | |
42 | ||
eb3b4c04 | 43 | protected $_summary = NULL; |
2f4c2f5d | 44 | |
74cf4551 | 45 | /** |
74cf4551 EM |
46 | */ |
47 | /** | |
74cf4551 | 48 | */ |
00be9182 | 49 | public function __construct() { |
6a488035 TO |
50 | self::validRelationships(); |
51 | ||
52 | $config = CRM_Core_Config::singleton(); | |
53 | $campaignEnabled = in_array("CiviCampaign", $config->enableComponents); | |
54 | if ($campaignEnabled) { | |
55 | $getCampaigns = CRM_Campaign_BAO_Campaign::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE); | |
56 | $this->activeCampaigns = $getCampaigns['campaigns']; | |
57 | asort($this->activeCampaigns); | |
58 | } | |
59 | ||
60 | $this->_columns = array( | |
a92f4449 | 61 | 'civicrm_contact_household' => array( |
6a488035 | 62 | 'dao' => 'CRM_Contact_DAO_Contact', |
a92f4449 | 63 | 'fields' => array( |
9d72cede EM |
64 | 'household_name' => array( |
65 | 'title' => ts('Household Name'), | |
66 | 'required' => TRUE, | |
67 | ), | |
a92f4449 | 68 | 'id' => array( |
6a488035 TO |
69 | 'no_display' => TRUE, |
70 | 'required' => TRUE, | |
71 | ), | |
a92f4449 | 72 | 'contact_type' => array( |
30f85891 RN |
73 | 'title' => ts('Contact Type'), |
74 | ), | |
a92f4449 | 75 | 'contact_sub_type' => array( |
b8f96eb8 | 76 | 'title' => ts('Contact Subtype'), |
30f85891 | 77 | ), |
6a488035 | 78 | ), |
a92f4449 EM |
79 | 'filters' => array( |
80 | 'household_name' => array('title' => ts('Household Name')), | |
6a488035 TO |
81 | ), |
82 | 'grouping' => 'household-fields', | |
83 | ), | |
08dd3452 E |
84 | 'civicrm_line_item' => array( |
85 | 'dao' => 'CRM_Price_DAO_LineItem', | |
86 | ), | |
a92f4449 | 87 | 'civicrm_relationship' => array( |
6a488035 | 88 | 'dao' => 'CRM_Contact_DAO_Relationship', |
a92f4449 EM |
89 | 'fields' => array( |
90 | 'relationship_type_id' => array( | |
91 | 'title' => ts('Relationship Type'), | |
6a488035 TO |
92 | ), |
93 | ), | |
a92f4449 EM |
94 | 'filters' => array( |
95 | 'relationship_type_id' => array( | |
6a488035 TO |
96 | 'title' => ts('Relationship Type'), |
97 | 'type' => CRM_Utils_Type::T_INT, | |
98 | 'operatorType' => CRM_Report_Form::OP_SELECT, | |
99 | 'options' => $this->relationTypes, | |
75f23035 | 100 | 'default' => key($this->relationTypes), |
6a488035 TO |
101 | ), |
102 | ), | |
103 | 'grouping' => 'household-fields', | |
104 | ), | |
a92f4449 | 105 | 'civicrm_contact' => array( |
6a488035 | 106 | 'dao' => 'CRM_Contact_DAO_Contact', |
a92f4449 EM |
107 | 'fields' => array( |
108 | 'sort_name' => array( | |
109 | 'title' => ts('Contact Name'), | |
6a488035 TO |
110 | 'required' => TRUE, |
111 | ), | |
a92f4449 | 112 | 'id' => array( |
6a488035 TO |
113 | 'no_display' => TRUE, |
114 | 'required' => TRUE, | |
115 | ), | |
116 | ), | |
117 | 'grouping' => 'contact-fields', | |
118 | ), | |
a92f4449 | 119 | 'civicrm_contribution' => array( |
6a488035 | 120 | 'dao' => 'CRM_Contribute_DAO_Contribution', |
a92f4449 EM |
121 | 'fields' => array( |
122 | 'total_amount' => array( | |
123 | 'title' => ts('Amount'), | |
6a488035 TO |
124 | 'required' => TRUE, |
125 | ), | |
126 | 'id' => array( | |
127 | 'no_display' => TRUE, | |
128 | 'required' => TRUE, | |
129 | ), | |
130 | 'contribution_status_id' => array( | |
fd6a6828 | 131 | 'title' => ts('Contribution Status'), |
6a488035 TO |
132 | 'default' => TRUE, |
133 | ), | |
a92f4449 EM |
134 | 'check_number' => array( |
135 | 'title' => ts('Check Number'), | |
f5aace12 | 136 | ), |
eb3b4c04 | 137 | 'currency' => array( |
138 | 'required' => TRUE, | |
139 | 'no_display' => TRUE, | |
140 | ), | |
6a488035 TO |
141 | 'trxn_id' => NULL, |
142 | 'receive_date' => array('default' => TRUE), | |
143 | 'receipt_date' => NULL, | |
144 | ), | |
a92f4449 EM |
145 | 'filters' => array( |
146 | 'receive_date' => array('operatorType' => CRM_Report_Form::OP_DATE), | |
147 | 'total_amount' => array('title' => ts('Amount Between')), | |
148 | 'currency' => array( | |
fd6a6828 | 149 | 'title' => ts('Currency'), |
eb3b4c04 | 150 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, |
151 | 'options' => CRM_Core_OptionGroup::values('currencies_enabled'), | |
d1b0931b | 152 | 'default' => NULL, |
eb3b4c04 | 153 | 'type' => CRM_Utils_Type::T_STRING, |
154 | ), | |
a92f4449 EM |
155 | 'contribution_status_id' => array( |
156 | 'title' => ts('Contribution Status'), | |
6a488035 TO |
157 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, |
158 | 'options' => CRM_Contribute_PseudoConstant::contributionStatus(), | |
159 | 'default' => array(1), | |
160 | ), | |
161 | ), | |
162 | 'grouping' => 'contri-fields', | |
163 | ), | |
a92f4449 | 164 | 'civicrm_address' => array( |
6a488035 | 165 | 'dao' => 'CRM_Core_DAO_Address', |
a92f4449 | 166 | 'fields' => array( |
6a488035 TO |
167 | 'street_address' => NULL, |
168 | 'city' => NULL, | |
169 | 'postal_code' => NULL, | |
a92f4449 EM |
170 | 'state_province_id' => array( |
171 | 'title' => ts('State/Province'), | |
6a488035 | 172 | ), |
a92f4449 EM |
173 | 'country_id' => array( |
174 | 'title' => ts('Country'), | |
6a488035 TO |
175 | ), |
176 | ), | |
177 | 'grouping' => 'contact-fields', | |
178 | ), | |
a92f4449 | 179 | 'civicrm_email' => array( |
6a488035 | 180 | 'dao' => 'CRM_Core_DAO_Email', |
a92f4449 | 181 | 'fields' => array( |
21dfd5f5 | 182 | 'email' => NULL, |
a92f4449 | 183 | ), |
6a488035 TO |
184 | 'grouping' => 'contact-fields', |
185 | ), | |
186 | ); | |
187 | ||
188 | if ($campaignEnabled && !empty($this->activeCampaigns)) { | |
189 | $this->_columns['civicrm_contribution']['fields']['campaign_id'] = array( | |
fd6a6828 | 190 | 'title' => ts('Campaign'), |
6a488035 TO |
191 | 'default' => 'false', |
192 | ); | |
a92f4449 EM |
193 | $this->_columns['civicrm_contribution']['filters']['campaign_id'] = array( |
194 | 'title' => ts('Campaign'), | |
6a488035 TO |
195 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, |
196 | 'options' => $this->activeCampaigns, | |
942b1d01 | 197 | 'type' => CRM_Utils_Type::T_INT, |
6a488035 TO |
198 | ); |
199 | } | |
eb3b4c04 | 200 | $this->_currencyColumn = 'civicrm_contribution_currency'; |
6a488035 TO |
201 | parent::__construct(); |
202 | } | |
203 | ||
00be9182 | 204 | public function preProcess() { |
6a488035 TO |
205 | parent::preProcess(); |
206 | } | |
207 | ||
00be9182 | 208 | public function select() { |
6a488035 TO |
209 | $this->_columnHeaders = $select = array(); |
210 | foreach ($this->_columns as $tableName => $table) { | |
211 | if (array_key_exists('fields', $table)) { | |
212 | foreach ($table['fields'] as $fieldName => $field) { | |
9d72cede EM |
213 | if (!empty($field['required']) || |
214 | !empty($this->_params['fields'][$fieldName]) | |
215 | ) { | |
6a488035 TO |
216 | if ($tableName == 'civicrm_address') { |
217 | $this->_addressField = TRUE; | |
218 | } | |
219 | elseif ($tableName == 'civicrm_email') { | |
220 | $this->_emailField = TRUE; | |
221 | } | |
222 | ||
a7488080 | 223 | if (!empty($field['statistics'])) { |
6a488035 TO |
224 | foreach ($field['statistics'] as $stat => $label) { |
225 | $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}_{$stat}"; | |
226 | $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label; | |
227 | $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['type'] = $field['type']; | |
228 | $this->_statFields[] = "{$tableName}_{$fieldName}_{$stat}"; | |
229 | } | |
230 | } | |
231 | else { | |
22a17535 | 232 | $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}"; |
6a488035 TO |
233 | |
234 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array::value('title', $field); | |
235 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field); | |
236 | } | |
237 | } | |
238 | } | |
239 | } | |
240 | } | |
d1641c51 | 241 | $this->_selectClauses = $select; |
6a488035 TO |
242 | $this->_select = "SELECT " . implode(', ', $select) . " "; |
243 | } | |
244 | ||
00be9182 | 245 | public function from() { |
6a488035 TO |
246 | |
247 | $this->_from = NULL; | |
248 | $this->_from = " | |
39eb89f4 DL |
249 | FROM civicrm_relationship {$this->_aliases['civicrm_relationship']} |
250 | LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact_household']} ON | |
6a488035 | 251 | ({$this->_aliases['civicrm_contact_household']}.id = {$this->_aliases['civicrm_relationship']}.$this->householdContact AND {$this->_aliases['civicrm_contact_household']}.contact_type='Household') |
39eb89f4 DL |
252 | LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']} ON |
253 | ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_relationship']}.$this->otherContact ) | |
6a488035 TO |
254 | {$this->_aclFrom} |
255 | INNER JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']} ON | |
e280410d | 256 | ({$this->_aliases['civicrm_contribution']}.contact_id = {$this->_aliases['civicrm_relationship']}.$this->otherContact ) AND {$this->_aliases['civicrm_contribution']}.is_test = 0 "; |
6a488035 TO |
257 | |
258 | if ($this->_addressField) { | |
39eb89f4 DL |
259 | $this->_from .= " |
260 | LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']} ON | |
261 | {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND | |
6a488035 TO |
262 | {$this->_aliases['civicrm_address']}.is_primary = 1\n "; |
263 | } | |
264 | if ($this->_emailField) { | |
265 | $this->_from .= " | |
39eb89f4 DL |
266 | LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']} ON |
267 | {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND | |
6a488035 TO |
268 | {$this->_aliases['civicrm_email']}.is_primary = 1\n "; |
269 | } | |
270 | } | |
40c655aa | 271 | |
00be9182 | 272 | public function where() { |
6a488035 TO |
273 | $clauses = array(); |
274 | foreach ($this->_columns as $tableName => $table) { | |
275 | if (array_key_exists('filters', $table)) { | |
276 | foreach ($table['filters'] as $fieldName => $field) { | |
277 | $clause = NULL; | |
278 | if (CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE) { | |
279 | $relative = CRM_Utils_Array::value("{$fieldName}_relative", $this->_params); | |
a92f4449 EM |
280 | $from = CRM_Utils_Array::value("{$fieldName}_from", $this->_params); |
281 | $to = CRM_Utils_Array::value("{$fieldName}_to", $this->_params); | |
6a488035 TO |
282 | $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']); |
283 | } | |
284 | else { | |
285 | $op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params); | |
286 | if ($op) { | |
287 | if ($fieldName == 'relationship_type_id') { | |
389bcebf | 288 | $clause = "{$this->_aliases['civicrm_relationship']}.relationship_type_id=" . $this->relationshipId; |
6a488035 TO |
289 | } |
290 | else { | |
291 | $clause = $this->whereClause($field, | |
292 | $op, | |
293 | CRM_Utils_Array::value("{$fieldName}_value", $this->_params), | |
294 | CRM_Utils_Array::value("{$fieldName}_min", $this->_params), | |
295 | CRM_Utils_Array::value("{$fieldName}_max", $this->_params) | |
296 | ); | |
297 | } | |
298 | } | |
299 | } | |
300 | ||
301 | if (!empty($clause)) { | |
302 | $clauses[] = $clause; | |
303 | } | |
304 | } | |
305 | } | |
306 | } | |
307 | ||
308 | if (empty($clauses)) { | |
309 | $this->_where = "WHERE ( 1 )"; | |
310 | } | |
311 | else { | |
312 | $this->_where = "WHERE " . implode(' AND ', $clauses); | |
313 | } | |
314 | ||
315 | if ($this->_aclWhere) { | |
316 | $this->_where .= " AND {$this->_aclWhere} "; | |
317 | } | |
318 | } | |
319 | ||
00be9182 | 320 | public function groupBy() { |
d1641c51 | 321 | $groupBy = array( |
322 | "{$this->_aliases['civicrm_relationship']}.$this->householdContact", | |
323 | "{$this->_aliases['civicrm_relationship']}.$this->otherContact", | |
324 | "{$this->_aliases['civicrm_contribution']}.id", | |
325 | "{$this->_aliases['civicrm_relationship']}.relationship_type_id", | |
326 | ); | |
b708c08d | 327 | $this->_groupBy = CRM_Contact_BAO_Query::getGroupByFromSelectColumns($this->_selectClauses, $groupBy); |
6a488035 TO |
328 | } |
329 | ||
00be9182 | 330 | public function orderBy() { |
6a488035 TO |
331 | $this->_orderBy = " ORDER BY {$this->_aliases['civicrm_contact_household']}.household_name, {$this->_aliases['civicrm_relationship']}.$this->householdContact, {$this->_aliases['civicrm_contact']}.sort_name, {$this->_aliases['civicrm_relationship']}.$this->otherContact"; |
332 | } | |
333 | ||
74cf4551 EM |
334 | /** |
335 | * @param $rows | |
336 | * | |
337 | * @return array | |
338 | */ | |
00be9182 | 339 | public function statistics(&$rows) { |
6a488035 TO |
340 | $statistics = parent::statistics($rows); |
341 | ||
342 | //hack filter display for relationship type | |
343 | $type = substr($this->_params['relationship_type_id_value'], -3); | |
344 | foreach ($statistics['filters'] as $id => $value) { | |
39eb89f4 DL |
345 | if ( |
346 | $value['title'] == 'Relationship Type' && | |
347 | isset($this->relationTypes[$this->relationshipId . '_' . $type]) | |
348 | ) { | |
a92f4449 EM |
349 | $statistics['filters'][$id]['value'] = 'Is equal to ' . |
350 | $this->relationTypes[$this->relationshipId . '_' . $type]; | |
6a488035 TO |
351 | } |
352 | } | |
353 | return $statistics; | |
354 | } | |
355 | ||
00be9182 | 356 | public function postProcess() { |
6a488035 TO |
357 | |
358 | $this->beginPostProcess(); | |
9d72cede | 359 | $this->buildACLClause(array( |
353ffa53 TO |
360 | $this->_aliases['civicrm_contact'], |
361 | $this->_aliases['civicrm_contact_household'], | |
362 | )); | |
75f23035 EM |
363 | $sql = $this->buildQuery(TRUE); |
364 | $rows = array(); | |
365 | ||
366 | $this->buildRows($sql, $rows); | |
367 | $this->formatDisplay($rows); | |
368 | $this->doTemplateAssignment($rows); | |
369 | $this->endPostProcess($rows); | |
370 | } | |
371 | ||
372 | /** | |
fe482240 | 373 | * Set variables to be accessed by API and form layer in processing. |
75f23035 | 374 | */ |
00be9182 | 375 | public function beginPostProcessCommon() { |
6a488035 TO |
376 | $getRelationship = $this->_params['relationship_type_id_value']; |
377 | $type = substr($getRelationship, -3); | |
378 | $this->relationshipId = intval((substr($getRelationship, 0, strpos($getRelationship, '_')))); | |
379 | if ($type == 'b_a') { | |
380 | $this->householdContact = 'contact_id_b'; | |
381 | $this->otherContact = 'contact_id_a'; | |
382 | } | |
383 | else { | |
384 | $this->householdContact = 'contact_id_a'; | |
385 | $this->otherContact = 'contact_id_b'; | |
386 | } | |
6a488035 TO |
387 | } |
388 | ||
00be9182 | 389 | public function validRelationships() { |
6a488035 TO |
390 | $this->relationTypes = $relationTypes = array(); |
391 | ||
392 | $params = array('contact_type_b' => 'Household', 'version' => 3); | |
39eb89f4 | 393 | $typesA = civicrm_api('relationship_type', 'get', $params); |
a7488080 | 394 | if (empty($typesA['is_error'])) { |
6a488035 TO |
395 | foreach ($typesA['values'] as $rel) { |
396 | $relationTypes[$rel['id']][$rel['id'] . '_b_a'] = $rel['label_b_a']; | |
397 | } | |
398 | } | |
399 | $params = array('contact_type_a' => 'Household', 'version' => 3); | |
39eb89f4 | 400 | $typesB = civicrm_api('relationship_type', 'get', $params); |
a7488080 | 401 | if (empty($typesB['is_error'])) { |
6a488035 TO |
402 | foreach ($typesB['values'] as $rel) { |
403 | $relationTypes[$rel['id']][$rel['id'] . '_a_b'] = $rel['label_a_b']; | |
404 | //$this->relationTypes[$rel['id'].'_a_b'] = $rel['label_a_b']; | |
405 | } | |
406 | } | |
407 | ||
408 | ksort($relationTypes); | |
409 | foreach ($relationTypes as $relationship) { | |
410 | foreach ($relationship as $index => $label) { | |
411 | $this->relationTypes[$index] = $label; | |
412 | } | |
413 | } | |
414 | } | |
415 | ||
74cf4551 | 416 | /** |
ced9bfed EM |
417 | * Alter display of rows. |
418 | * | |
419 | * Iterate through the rows retrieved via SQL and make changes for display purposes, | |
420 | * such as rendering contacts as links. | |
421 | * | |
422 | * @param array $rows | |
423 | * Rows generated by SQL, with an array for each row. | |
74cf4551 | 424 | */ |
00be9182 | 425 | public function alterDisplay(&$rows) { |
6a488035 TO |
426 | $type = substr($this->_params['relationship_type_id_value'], -3); |
427 | ||
428 | $entryFound = FALSE; | |
429 | $flagHousehold = $flagContact = 0; | |
6a488035 TO |
430 | foreach ($rows as $rowNum => $row) { |
431 | ||
432 | //replace retionship id by relationship name | |
433 | if (array_key_exists('civicrm_relationship_relationship_type_id', $row)) { | |
434 | if ($value = $row['civicrm_relationship_relationship_type_id']) { | |
84178120 | 435 | $rows[$rowNum]['civicrm_relationship_relationship_type_id'] = $this->relationTypes[$value . '_' . $type]; |
6a488035 TO |
436 | $entryFound = TRUE; |
437 | } | |
438 | } | |
439 | ||
440 | //remove duplicate Organization names | |
9d72cede EM |
441 | if (array_key_exists('civicrm_contact_household_household_name', $row) && |
442 | $this->_outputMode != 'csv' | |
443 | ) { | |
6a488035 TO |
444 | if ($value = $row['civicrm_contact_household_household_name']) { |
445 | if ($rowNum == 0) { | |
446 | $priviousHousehold = $value; | |
447 | } | |
448 | else { | |
449 | if ($priviousHousehold == $value) { | |
450 | $flagHousehold = 1; | |
451 | $priviousHousehold = $value; | |
452 | } | |
453 | else { | |
454 | $flagHousehold = 0; | |
455 | $priviousHousehold = $value; | |
456 | } | |
457 | } | |
458 | ||
459 | if ($flagHousehold == 1) { | |
460 | $rows[$rowNum]['civicrm_contact_household_household_name'] = ""; | |
461 | } | |
462 | else { | |
463 | $url = CRM_Utils_System::url('civicrm/contact/view', | |
464 | 'reset=1&cid=' . $rows[$rowNum]['civicrm_contact_household_id'], | |
465 | $this->_absoluteUrl | |
466 | ); | |
467 | ||
389bcebf | 468 | $rows[$rowNum]['civicrm_contact_household_household_name'] = "<a href='$url' title='" . ts('View contact summary for this househould') . "'>" . $value . '</a>'; |
6a488035 TO |
469 | } |
470 | $entryFound = TRUE; | |
471 | } | |
472 | } | |
473 | ||
474 | //remove duplicate Contact names and relationship type | |
9d72cede EM |
475 | if (array_key_exists('civicrm_contact_id', $row) && |
476 | $this->_outputMode != 'csv' | |
477 | ) { | |
6a488035 TO |
478 | if ($value = $row['civicrm_contact_id']) { |
479 | if ($rowNum == 0) { | |
480 | $priviousContact = $value; | |
481 | } | |
482 | else { | |
483 | if ($priviousContact == $value) { | |
484 | $flagContact = 1; | |
485 | $priviousContact = $value; | |
486 | } | |
487 | else { | |
488 | $flagContact = 0; | |
489 | $priviousContact = $value; | |
490 | } | |
491 | } | |
492 | ||
493 | if ($flagContact == 1 && $flagHousehold == 1) { | |
494 | $rows[$rowNum]['civicrm_contact_sort_name'] = ""; | |
495 | $rows[$rowNum]['civicrm_relationship_relationship_type_id'] = ""; | |
496 | } | |
497 | ||
498 | $entryFound = TRUE; | |
499 | } | |
500 | } | |
501 | ||
502 | if (array_key_exists('civicrm_contribution_contribution_status_id', $row)) { | |
503 | if ($value = $row['civicrm_contribution_contribution_status_id']) { | |
504 | $rows[$rowNum]['civicrm_contribution_contribution_status_id'] = CRM_Contribute_PseudoConstant::contributionStatus($value); | |
505 | } | |
506 | } | |
507 | ||
508 | // handle state province | |
509 | if (array_key_exists('civicrm_address_state_province_id', $row)) { | |
510 | if ($value = $row['civicrm_address_state_province_id']) { | |
511 | $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($value, FALSE); | |
512 | } | |
513 | $entryFound = TRUE; | |
514 | } | |
515 | ||
516 | // handle country | |
517 | if (array_key_exists('civicrm_address_country_id', $row)) { | |
518 | if ($value = $row['civicrm_address_country_id']) { | |
519 | $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant::country($value, FALSE); | |
520 | } | |
521 | $entryFound = TRUE; | |
522 | } | |
523 | ||
524 | // convert display name to links | |
525 | if (array_key_exists('civicrm_contact_sort_name', $row) && | |
526 | $rows[$rowNum]['civicrm_contact_sort_name'] && | |
527 | array_key_exists('civicrm_contact_id', $row) | |
528 | ) { | |
529 | $url = CRM_Report_Utils_Report::getNextUrl('contribute/detail', | |
530 | 'reset=1&force=1&id_op=eq&id_value=' . $row['civicrm_contact_id'], | |
531 | $this->_absoluteUrl, $this->_id, $this->_drilldownReport | |
532 | ); | |
533 | $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url; | |
534 | $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts('View contribution details for this individual'); | |
535 | ||
536 | $entryFound = TRUE; | |
537 | } | |
538 | ||
a7488080 | 539 | if (!empty($row['civicrm_contribution_total_amount'])) { |
eb3b4c04 | 540 | $row['civicrm_contribution_total_amount'] = CRM_Utils_Money::format($row['civicrm_contribution_total_amount'], $row['civicrm_contribution_currency']); |
541 | } | |
542 | ||
6a488035 TO |
543 | // Contribution amount links to view contribution |
544 | if (($value = CRM_Utils_Array::value('civicrm_contribution_total_amount', $row)) && | |
545 | CRM_Core_Permission::check('access CiviContribute') | |
546 | ) { | |
547 | $url = CRM_Utils_System::url("civicrm/contact/view/contribution", | |
9d72cede EM |
548 | "reset=1&id=" . $row['civicrm_contribution_id'] . "&cid=" . |
549 | $row['civicrm_contact_id'] . | |
a92f4449 | 550 | "&action=view&context=contribution&selectedChild=contribute", |
6a488035 TO |
551 | $this->_absoluteUrl |
552 | ); | |
553 | $rows[$rowNum]['civicrm_contribution_total_amount_link'] = $url; | |
554 | $rows[$rowNum]['civicrm_contribution_total_amount_hover'] = ts("View this contribution."); | |
555 | $entryFound = TRUE; | |
556 | } | |
557 | ||
558 | // convert campaign_id to campaign title | |
559 | if (array_key_exists('civicrm_contribution_campaign_id', $row)) { | |
560 | if ($value = $row['civicrm_contribution_campaign_id']) { | |
561 | $rows[$rowNum]['civicrm_contribution_campaign_id'] = $this->activeCampaigns[$value]; | |
562 | $entryFound = TRUE; | |
563 | } | |
564 | } | |
565 | ||
566 | // skip looking further in rows, if first row itself doesn't | |
567 | if (!$entryFound) { | |
568 | break; | |
569 | } | |
570 | $lastKey = $rowNum; | |
571 | } | |
572 | } | |
96025800 | 573 | |
6a488035 | 574 | } |