| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.6 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
| 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 | +--------------------------------------------------------------------+ |
| 26 | */ |
| 27 | |
| 28 | /** |
| 29 | * |
| 30 | * @package CRM |
| 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
| 32 | * $Id$ |
| 33 | * |
| 34 | */ |
| 35 | class CRM_Report_Form_Contribute_Lybunt extends CRM_Report_Form { |
| 36 | |
| 37 | protected $_charts = array( |
| 38 | '' => 'Tabular', |
| 39 | 'barChart' => 'Bar Chart', |
| 40 | 'pieChart' => 'Pie Chart', |
| 41 | ); |
| 42 | |
| 43 | protected $_customGroupExtends = array( |
| 44 | 'Contact', |
| 45 | 'Individual', |
| 46 | 'Contribution', |
| 47 | ); |
| 48 | |
| 49 | public $_drilldownReport = array('contribute/detail' => 'Link to Detail Report'); |
| 50 | |
| 51 | protected $lifeTime_from = NULL; |
| 52 | protected $lifeTime_where = NULL; |
| 53 | |
| 54 | /** |
| 55 | */ |
| 56 | public function __construct() { |
| 57 | $this->_autoIncludeIndexedFieldsAsOrderBys = 1; |
| 58 | $yearsInPast = 10; |
| 59 | $yearsInFuture = 1; |
| 60 | $date = CRM_Core_SelectValues::date('custom', NULL, $yearsInPast, $yearsInFuture); |
| 61 | $count = $date['maxYear']; |
| 62 | while ($date['minYear'] <= $count) { |
| 63 | $optionYear[$date['minYear']] = $date['minYear']; |
| 64 | $date['minYear']++; |
| 65 | } |
| 66 | |
| 67 | // Check if CiviCampaign is a) enabled and b) has active campaigns |
| 68 | $config = CRM_Core_Config::singleton(); |
| 69 | $campaignEnabled = in_array("CiviCampaign", $config->enableComponents); |
| 70 | if ($campaignEnabled) { |
| 71 | $getCampaigns = CRM_Campaign_BAO_Campaign::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE); |
| 72 | $this->activeCampaigns = $getCampaigns['campaigns']; |
| 73 | asort($this->activeCampaigns); |
| 74 | } |
| 75 | |
| 76 | $this->_columns = array( |
| 77 | 'civicrm_contact' => array( |
| 78 | 'dao' => 'CRM_Contact_DAO_Contact', |
| 79 | 'grouping' => 'contact-field', |
| 80 | 'fields' => array( |
| 81 | 'sort_name' => array( |
| 82 | 'title' => ts('Donor Name'), |
| 83 | 'default' => TRUE, |
| 84 | 'required' => TRUE, |
| 85 | ), |
| 86 | 'first_name' => array( |
| 87 | 'title' => ts('First Name'), |
| 88 | ), |
| 89 | 'middle_name' => array( |
| 90 | 'title' => ts('Middle Name'), |
| 91 | ), |
| 92 | 'last_name' => array( |
| 93 | 'title' => ts('Last Name'), |
| 94 | ), |
| 95 | 'id' => array( |
| 96 | 'no_display' => TRUE, |
| 97 | 'required' => TRUE, |
| 98 | ), |
| 99 | 'gender_id' => array( |
| 100 | 'title' => ts('Gender'), |
| 101 | ), |
| 102 | 'birth_date' => array( |
| 103 | 'title' => ts('Birth Date'), |
| 104 | ), |
| 105 | 'age' => array( |
| 106 | 'title' => ts('Age'), |
| 107 | 'dbAlias' => 'TIMESTAMPDIFF(YEAR, contact_civireport.birth_date, CURDATE())', |
| 108 | ), |
| 109 | 'contact_type' => array( |
| 110 | 'title' => ts('Contact Type'), |
| 111 | ), |
| 112 | 'contact_sub_type' => array( |
| 113 | 'title' => ts('Contact Subtype'), |
| 114 | ), |
| 115 | ), |
| 116 | 'grouping' => 'contact-fields', |
| 117 | 'order_bys' => array( |
| 118 | 'sort_name' => array( |
| 119 | 'title' => ts('Last Name, First Name'), |
| 120 | 'default' => '1', |
| 121 | 'default_weight' => '0', |
| 122 | 'default_order' => 'ASC', |
| 123 | ), |
| 124 | 'first_name' => array( |
| 125 | 'name' => 'first_name', |
| 126 | 'title' => ts('First Name'), |
| 127 | ), |
| 128 | 'gender_id' => array( |
| 129 | 'name' => 'gender_id', |
| 130 | 'title' => ts('Gender'), |
| 131 | ), |
| 132 | 'birth_date' => array( |
| 133 | 'name' => 'birth_date', |
| 134 | 'title' => ts('Birth Date'), |
| 135 | ), |
| 136 | 'contact_type' => array( |
| 137 | 'title' => ts('Contact Type'), |
| 138 | ), |
| 139 | 'contact_sub_type' => array( |
| 140 | 'title' => ts('Contact Subtype'), |
| 141 | ), |
| 142 | ), |
| 143 | 'filters' => array( |
| 144 | 'sort_name' => array( |
| 145 | 'title' => ts('Donor Name'), |
| 146 | 'operator' => 'like', |
| 147 | ), |
| 148 | 'id' => array( |
| 149 | 'title' => ts('Contact ID'), |
| 150 | 'no_display' => TRUE, |
| 151 | ), |
| 152 | 'gender_id' => array( |
| 153 | 'title' => ts('Gender'), |
| 154 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, |
| 155 | 'options' => CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'), |
| 156 | ), |
| 157 | 'birth_date' => array( |
| 158 | 'title' => ts('Birth Date'), |
| 159 | 'operatorType' => CRM_Report_Form::OP_DATE, |
| 160 | ), |
| 161 | 'contact_type' => array( |
| 162 | 'title' => ts('Contact Type'), |
| 163 | ), |
| 164 | 'contact_sub_type' => array( |
| 165 | 'title' => ts('Contact Subtype'), |
| 166 | ), |
| 167 | ), |
| 168 | ), |
| 169 | 'civicrm_email' => array( |
| 170 | 'dao' => 'CRM_Core_DAO_Email', |
| 171 | 'grouping' => 'contact-field', |
| 172 | 'fields' => array( |
| 173 | 'email' => array( |
| 174 | 'title' => ts('Email'), |
| 175 | 'default' => TRUE, |
| 176 | ), |
| 177 | ), |
| 178 | ), |
| 179 | 'civicrm_phone' => array( |
| 180 | 'dao' => 'CRM_Core_DAO_Phone', |
| 181 | 'grouping' => 'contact-field', |
| 182 | 'fields' => array( |
| 183 | 'phone' => array( |
| 184 | 'title' => ts('Phone'), |
| 185 | 'default' => TRUE, |
| 186 | ), |
| 187 | ), |
| 188 | ), |
| 189 | ); |
| 190 | $this->_columns += $this->addAddressFields(); |
| 191 | $this->_columns += array( |
| 192 | 'civicrm_contribution' => array( |
| 193 | 'dao' => 'CRM_Contribute_DAO_Contribution', |
| 194 | 'fields' => array( |
| 195 | 'contact_id' => array( |
| 196 | 'title' => ts('contactId'), |
| 197 | 'no_display' => TRUE, |
| 198 | 'required' => TRUE, |
| 199 | 'no_repeat' => TRUE, |
| 200 | ), |
| 201 | 'total_amount' => array( |
| 202 | 'title' => ts('Total Amount'), |
| 203 | 'no_display' => TRUE, |
| 204 | 'required' => TRUE, |
| 205 | 'no_repeat' => TRUE, |
| 206 | ), |
| 207 | 'receive_date' => array( |
| 208 | 'title' => ts('Year'), |
| 209 | 'no_display' => TRUE, |
| 210 | 'required' => TRUE, |
| 211 | 'no_repeat' => TRUE, |
| 212 | ), |
| 213 | ), |
| 214 | 'filters' => array( |
| 215 | 'yid' => array( |
| 216 | 'name' => 'receive_date', |
| 217 | 'title' => ts('This Year'), |
| 218 | 'operatorType' => CRM_Report_Form::OP_SELECT, |
| 219 | 'options' => $optionYear, |
| 220 | 'default' => date('Y'), |
| 221 | ), |
| 222 | 'financial_type_id' => array( |
| 223 | 'title' => ts('Financial Type'), |
| 224 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, |
| 225 | 'options' => CRM_Contribute_PseudoConstant::financialType(), |
| 226 | ), |
| 227 | 'contribution_status_id' => array( |
| 228 | 'title' => ts('Contribution Status'), |
| 229 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, |
| 230 | 'options' => CRM_Contribute_PseudoConstant::contributionStatus(), |
| 231 | 'default' => array('1'), |
| 232 | ), |
| 233 | ), |
| 234 | ), |
| 235 | ); |
| 236 | |
| 237 | // If we have a campaign, build out the relevant elements |
| 238 | if ($campaignEnabled && !empty($this->activeCampaigns)) { |
| 239 | $this->_columns['civicrm_contribution']['fields']['campaign_id'] = array( |
| 240 | 'title' => ts('Campaign'), |
| 241 | 'default' => 'false', |
| 242 | ); |
| 243 | $this->_columns['civicrm_contribution']['filters']['campaign_id'] = array( |
| 244 | 'title' => ts('Campaign'), |
| 245 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, |
| 246 | 'options' => $this->activeCampaigns, |
| 247 | ); |
| 248 | } |
| 249 | |
| 250 | $this->_groupFilter = TRUE; |
| 251 | $this->_tagFilter = TRUE; |
| 252 | parent::__construct(); |
| 253 | } |
| 254 | |
| 255 | public function preProcess() { |
| 256 | parent::preProcess(); |
| 257 | } |
| 258 | |
| 259 | public function select() { |
| 260 | |
| 261 | $this->_columnHeaders = $select = array(); |
| 262 | $current_year = $this->_params['yid_value']; |
| 263 | $previous_year = $current_year - 1; |
| 264 | |
| 265 | foreach ($this->_columns as $tableName => $table) { |
| 266 | |
| 267 | if (array_key_exists('fields', $table)) { |
| 268 | foreach ($table['fields'] as $fieldName => $field) { |
| 269 | |
| 270 | if (!empty($field['required']) || |
| 271 | !empty($this->_params['fields'][$fieldName]) |
| 272 | ) { |
| 273 | if ($fieldName == 'total_amount') { |
| 274 | $select[] = "SUM({$field['dbAlias']}) as {$tableName}_{$fieldName}"; |
| 275 | |
| 276 | $this->_columnHeaders["{$previous_year}"]['type'] = $field['type']; |
| 277 | $this->_columnHeaders["{$previous_year}"]['title'] = $previous_year; |
| 278 | |
| 279 | $this->_columnHeaders["civicrm_life_time_total"]['type'] = $field['type']; |
| 280 | $this->_columnHeaders["civicrm_life_time_total"]['title'] = 'LifeTime';; |
| 281 | } |
| 282 | elseif ($fieldName == 'receive_date') { |
| 283 | $select[] = self::fiscalYearOffset($field['dbAlias']) . |
| 284 | " as {$tableName}_{$fieldName} "; |
| 285 | } |
| 286 | else { |
| 287 | $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName} "; |
| 288 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field); |
| 289 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array::value('title', $field); |
| 290 | } |
| 291 | |
| 292 | if (!empty($field['no_display'])) { |
| 293 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['no_display'] = TRUE; |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | $this->_select = "SELECT " . implode(', ', $select) . " "; |
| 301 | } |
| 302 | |
| 303 | public function from() { |
| 304 | |
| 305 | $this->_from = " |
| 306 | FROM civicrm_contribution {$this->_aliases['civicrm_contribution']} |
| 307 | INNER JOIN civicrm_contact {$this->_aliases['civicrm_contact']} |
| 308 | ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_contribution']}.contact_id |
| 309 | {$this->_aclFrom}"; |
| 310 | |
| 311 | if ($this->isTableSelected('civicrm_email')) { |
| 312 | $this->_from .= " |
| 313 | LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']} |
| 314 | ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id |
| 315 | AND {$this->_aliases['civicrm_email']}.is_primary = 1"; |
| 316 | } |
| 317 | if ($this->isTableSelected('civicrm_phone')) { |
| 318 | $this->_from .= " |
| 319 | LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']} |
| 320 | ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND |
| 321 | {$this->_aliases['civicrm_phone']}.is_primary = 1"; |
| 322 | } |
| 323 | $this->addAddressFromClause(); |
| 324 | } |
| 325 | |
| 326 | public function where() { |
| 327 | $this->_statusClause = ""; |
| 328 | $clauses = array($this->_aliases['civicrm_contribution'] . '.is_test = 0'); |
| 329 | $current_year = $this->_params['yid_value']; |
| 330 | $previous_year = $current_year - 1; |
| 331 | |
| 332 | foreach ($this->_columns as $tableName => $table) { |
| 333 | if (array_key_exists('filters', $table)) { |
| 334 | foreach ($table['filters'] as $fieldName => $field) { |
| 335 | $clause = NULL; |
| 336 | if ($fieldName == 'yid') { |
| 337 | $clause = "contribution_civireport.contact_id NOT IN |
| 338 | (SELECT distinct contri.contact_id FROM civicrm_contribution contri |
| 339 | WHERE contri.is_test = 0 AND " . |
| 340 | self::fiscalYearOffset('contri.receive_date') . " = $current_year) AND contribution_civireport.contact_id IN (SELECT distinct contri.contact_id FROM civicrm_contribution contri |
| 341 | WHERE " . self::fiscalYearOffset('contri.receive_date') . |
| 342 | " = $previous_year AND contri.is_test = 0)"; |
| 343 | } |
| 344 | elseif (CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE |
| 345 | ) { |
| 346 | $relative = CRM_Utils_Array::value("{$fieldName}_relative", $this->_params); |
| 347 | $from = CRM_Utils_Array::value("{$fieldName}_from", $this->_params); |
| 348 | $to = CRM_Utils_Array::value("{$fieldName}_to", $this->_params); |
| 349 | |
| 350 | if ($relative || $from || $to) { |
| 351 | $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']); |
| 352 | } |
| 353 | } |
| 354 | else { |
| 355 | $op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params); |
| 356 | if ($op) { |
| 357 | $clause = $this->whereClause($field, |
| 358 | $op, |
| 359 | CRM_Utils_Array::value("{$fieldName}_value", $this->_params), |
| 360 | CRM_Utils_Array::value("{$fieldName}_min", $this->_params), |
| 361 | CRM_Utils_Array::value("{$fieldName}_max", $this->_params) |
| 362 | ); |
| 363 | if (($fieldName == 'contribution_status_id' || |
| 364 | $fieldName == 'financial_type_id') && !empty($clause) |
| 365 | ) { |
| 366 | $this->_statusClause .= " AND " . $clause; |
| 367 | } |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | if (!empty($clause)) { |
| 372 | $clauses[] = $clause; |
| 373 | } |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | $this->_where = 'WHERE ' . implode(' AND ', $clauses); |
| 379 | |
| 380 | if ($this->_aclWhere) { |
| 381 | $this->_where .= " AND {$this->_aclWhere} "; |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | public function groupBy() { |
| 386 | $this->_groupBy = "GROUP BY {$this->_aliases['civicrm_contribution']}.contact_id, " . |
| 387 | self::fiscalYearOffset($this->_aliases['civicrm_contribution'] . |
| 388 | '.receive_date') . " WITH ROLLUP"; |
| 389 | $this->assign('chartSupported', TRUE); |
| 390 | } |
| 391 | |
| 392 | /** |
| 393 | * @param $rows |
| 394 | * |
| 395 | * @return array |
| 396 | */ |
| 397 | public function statistics(&$rows) { |
| 398 | $statistics = parent::statistics($rows); |
| 399 | if (!empty($rows)) { |
| 400 | $select = " |
| 401 | SELECT |
| 402 | SUM({$this->_aliases['civicrm_contribution']}.total_amount ) as amount "; |
| 403 | |
| 404 | $sql = "{$select} {$this->_from} {$this->_where}"; |
| 405 | $dao = CRM_Core_DAO::executeQuery($sql); |
| 406 | if ($dao->fetch()) { |
| 407 | $statistics['counts']['amount'] = array( |
| 408 | 'value' => $dao->amount, |
| 409 | 'title' => 'Total LifeTime', |
| 410 | 'type' => CRM_Utils_Type::T_MONEY, |
| 411 | ); |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | return $statistics; |
| 416 | } |
| 417 | |
| 418 | public function postProcess() { |
| 419 | |
| 420 | // get ready with post process params |
| 421 | $this->beginPostProcess(); |
| 422 | |
| 423 | // get the acl clauses built before we assemble the query |
| 424 | $this->buildACLClause($this->_aliases['civicrm_contact']); |
| 425 | $this->select(); |
| 426 | $this->from(); |
| 427 | $this->where(); |
| 428 | $this->groupBy(); |
| 429 | |
| 430 | $rows = $contactIds = array(); |
| 431 | if (empty($this->_params['charts'])) { |
| 432 | $this->limit(); |
| 433 | $getContacts = "SELECT SQL_CALC_FOUND_ROWS {$this->_aliases['civicrm_contact']}.id as cid {$this->_from} {$this->_where} GROUP BY {$this->_aliases['civicrm_contact']}.id {$this->_limit}"; |
| 434 | |
| 435 | $dao = CRM_Core_DAO::executeQuery($getContacts); |
| 436 | |
| 437 | while ($dao->fetch()) { |
| 438 | $contactIds[] = $dao->cid; |
| 439 | } |
| 440 | $dao->free(); |
| 441 | $this->setPager(); |
| 442 | } |
| 443 | |
| 444 | if (!empty($contactIds) || !empty($this->_params['charts'])) { |
| 445 | if (!empty($this->_params['charts'])) { |
| 446 | $sql = "{$this->_select} {$this->_from} {$this->_where} {$this->_groupBy}"; |
| 447 | } |
| 448 | else { |
| 449 | $sql = "{$this->_select} {$this->_from} WHERE {$this->_aliases['civicrm_contact']}.id IN (" . |
| 450 | implode(',', $contactIds) . |
| 451 | ") AND {$this->_aliases['civicrm_contribution']}.is_test = 0 {$this->_statusClause} {$this->_groupBy} "; |
| 452 | } |
| 453 | |
| 454 | $dao = CRM_Core_DAO::executeQuery($sql); |
| 455 | $current_year = $this->_params['yid_value']; |
| 456 | $previous_year = $current_year - 1; |
| 457 | |
| 458 | while ($dao->fetch()) { |
| 459 | |
| 460 | if (!$dao->civicrm_contribution_contact_id) { |
| 461 | continue; |
| 462 | } |
| 463 | |
| 464 | $row = array(); |
| 465 | foreach ($this->_columnHeaders as $key => $value) { |
| 466 | if (property_exists($dao, $key)) { |
| 467 | $rows[$dao->civicrm_contribution_contact_id][$key] = $dao->$key; |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | if ($dao->civicrm_contribution_receive_date) { |
| 472 | if ($dao->civicrm_contribution_receive_date == $previous_year) { |
| 473 | $rows[$dao->civicrm_contribution_contact_id][$dao->civicrm_contribution_receive_date] = $dao->civicrm_contribution_total_amount; |
| 474 | } |
| 475 | } |
| 476 | else { |
| 477 | $rows[$dao->civicrm_contribution_contact_id]['civicrm_life_time_total'] = $dao->civicrm_contribution_total_amount; |
| 478 | } |
| 479 | } |
| 480 | $dao->free(); |
| 481 | } |
| 482 | |
| 483 | $this->formatDisplay($rows, FALSE); |
| 484 | |
| 485 | // assign variables to templates |
| 486 | $this->doTemplateAssignment($rows); |
| 487 | |
| 488 | // do print / pdf / instance stuff if needed |
| 489 | $this->endPostProcess($rows); |
| 490 | } |
| 491 | |
| 492 | /** |
| 493 | * @param $rows |
| 494 | */ |
| 495 | public function buildChart(&$rows) { |
| 496 | |
| 497 | $graphRows = array(); |
| 498 | $count = 0; |
| 499 | $display = array(); |
| 500 | |
| 501 | $current_year = $this->_params['yid_value']; |
| 502 | $previous_year = $current_year - 1; |
| 503 | $interval[$previous_year] = $previous_year; |
| 504 | $interval['life_time'] = 'Life Time'; |
| 505 | |
| 506 | foreach ($rows as $key => $row) { |
| 507 | $display['life_time'] = CRM_Utils_Array::value('life_time', $display) + |
| 508 | $row['civicrm_life_time_total']; |
| 509 | $display[$previous_year] = CRM_Utils_Array::value($previous_year, $display) + $row[$previous_year]; |
| 510 | } |
| 511 | |
| 512 | $config = CRM_Core_Config::Singleton(); |
| 513 | $graphRows['value'] = $display; |
| 514 | $chartInfo = array( |
| 515 | 'legend' => ts('Lybunt Report'), |
| 516 | 'xname' => ts('Year'), |
| 517 | 'yname' => ts('Amount (%1)', array(1 => $config->defaultCurrency)), |
| 518 | ); |
| 519 | if ($this->_params['charts']) { |
| 520 | // build chart. |
| 521 | CRM_Utils_OpenFlashChart::reportChart($graphRows, $this->_params['charts'], $interval, $chartInfo); |
| 522 | $this->assign('chartType', $this->_params['charts']); |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | /** |
| 527 | * Alter display of rows. |
| 528 | * |
| 529 | * Iterate through the rows retrieved via SQL and make changes for display purposes, |
| 530 | * such as rendering contacts as links. |
| 531 | * |
| 532 | * @param array $rows |
| 533 | * Rows generated by SQL, with an array for each row. |
| 534 | */ |
| 535 | public function alterDisplay(&$rows) { |
| 536 | $entryFound = FALSE; |
| 537 | |
| 538 | foreach ($rows as $rowNum => $row) { |
| 539 | //Convert Display name into link |
| 540 | if (array_key_exists('civicrm_contact_sort_name', $row) && |
| 541 | array_key_exists('civicrm_contribution_contact_id', $row) |
| 542 | ) { |
| 543 | $url = CRM_Report_Utils_Report::getNextUrl('contribute/detail', |
| 544 | 'reset=1&force=1&id_op=eq&id_value=' . |
| 545 | $row['civicrm_contribution_contact_id'], |
| 546 | $this->_absoluteUrl, $this->_id, $this->_drilldownReport |
| 547 | ); |
| 548 | $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url; |
| 549 | $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contribution Details for this Contact."); |
| 550 | $entryFound = TRUE; |
| 551 | } |
| 552 | |
| 553 | // convert campaign_id to campaign title |
| 554 | if (array_key_exists('civicrm_contribution_campaign_id', $row)) { |
| 555 | if ($value = $row['civicrm_contribution_campaign_id']) { |
| 556 | $rows[$rowNum]['civicrm_contribution_campaign_id'] = $this->activeCampaigns[$value]; |
| 557 | $entryFound = TRUE; |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | $entryFound = $this->alterDisplayAddressFields($row, $rows, $rowNum, 'contribute/detail', 'List all contribution(s)') ? TRUE : $entryFound; |
| 562 | |
| 563 | //handle gender |
| 564 | if (array_key_exists('civicrm_contact_gender_id', $row)) { |
| 565 | if ($value = $row['civicrm_contact_gender_id']) { |
| 566 | $gender = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'); |
| 567 | $rows[$rowNum]['civicrm_contact_gender_id'] = $gender[$value]; |
| 568 | } |
| 569 | $entryFound = TRUE; |
| 570 | } |
| 571 | |
| 572 | // display birthday in the configured custom format |
| 573 | if (array_key_exists('civicrm_contact_birth_date', $row)) { |
| 574 | $birthDate = $row['civicrm_contact_birth_date']; |
| 575 | if ($birthDate) { |
| 576 | $rows[$rowNum]['civicrm_contact_birth_date'] = CRM_Utils_Date::customFormat($birthDate, '%Y%m%d'); |
| 577 | } |
| 578 | $entryFound = TRUE; |
| 579 | } |
| 580 | |
| 581 | // skip looking further in rows, if first row itself doesn't |
| 582 | // have the column we need |
| 583 | if (!$entryFound) { |
| 584 | break; |
| 585 | } |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | /** |
| 590 | * Override "This Year" $op options |
| 591 | * @param string $type |
| 592 | * @param null $fieldName |
| 593 | * |
| 594 | * @return array |
| 595 | */ |
| 596 | public function getOperationPair($type = "string", $fieldName = NULL) { |
| 597 | if ($fieldName == 'yid') { |
| 598 | return array( |
| 599 | 'calendar' => ts('Is Calendar Year'), |
| 600 | 'fiscal' => ts('Fiscal Year Starting'), |
| 601 | ); |
| 602 | } |
| 603 | return parent::getOperationPair($type, $fieldName); |
| 604 | } |
| 605 | |
| 606 | } |