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