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