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