From 72a9af52a656e0e1a633e8c365b5887ef40c2ce9 Mon Sep 17 00:00:00 2001 From: Nicolas Ganivet Date: Tue, 24 Sep 2013 13:00:42 -0600 Subject: [PATCH] Converted to the address functions in base class Added missing $entryFound logic in alterDisplay() --- CRM/Report/Form/Contribute/Lybunt.php | 53 +++++++------------------- CRM/Report/Form/Contribute/Sybunt.php | 54 +++++++-------------------- 2 files changed, 27 insertions(+), 80 deletions(-) diff --git a/CRM/Report/Form/Contribute/Lybunt.php b/CRM/Report/Form/Contribute/Lybunt.php index 44c21ad122..cfeef63098 100644 --- a/CRM/Report/Form/Contribute/Lybunt.php +++ b/CRM/Report/Form/Contribute/Lybunt.php @@ -124,32 +124,9 @@ class CRM_Report_Form_Contribute_Lybunt extends CRM_Report_Form { ), ), ), - 'civicrm_address' => - array( - 'dao' => 'CRM_Core_DAO_Address', - 'grouping' => 'contact-fields', - 'fields' => - array( - 'street_address' => array('default' => TRUE), - 'city' => array('default' => TRUE), - 'postal_code' => NULL, - 'state_province_id' => array('title' => ts('State/Province')), - 'country_id' => array('title' => ts('Country')), - ), - 'filters' => - array( - 'country_id' => - array('title' => ts('Country'), - 'operatorType' => CRM_Report_Form::OP_MULTISELECT, - 'options' => CRM_Core_PseudoConstant::country(), - ), - 'state_province_id' => - array('title' => ts('State / Province'), - 'operatorType' => CRM_Report_Form::OP_MULTISELECT, - 'options' => CRM_Core_PseudoConstant::stateProvince(), - ), - ), - ), + ) + + $this->addAddressFields() + + array( 'civicrm_contribution' => array( 'dao' => 'CRM_Contribute_DAO_Contribution', @@ -299,12 +276,7 @@ class CRM_Report_Form_Contribute_Lybunt extends CRM_Report_Form { ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND {$this->_aliases['civicrm_phone']}.is_primary = 1"; } - if ($this->isTableSelected('civicrm_address')) { - $this->_from .= " - LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']} - ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND - {$this->_aliases['civicrm_address']}.is_primary = 1"; - } + $this->addAddressFromClause(); } function where() { @@ -489,6 +461,9 @@ class CRM_Report_Form_Contribute_Lybunt extends CRM_Report_Form { } function alterDisplay(&$rows) { + // custom code to alter rows + $entryFound = FALSE; + foreach ($rows as $rowNum => $row) { //Convert Display name into link if (array_key_exists('civicrm_contact_sort_name', $row) && @@ -500,6 +475,7 @@ class CRM_Report_Form_Contribute_Lybunt extends CRM_Report_Form { ); $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url; $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contribution Details for this Contact."); + $entryFound = TRUE; } // convert campaign_id to campaign title @@ -510,13 +486,12 @@ class CRM_Report_Form_Contribute_Lybunt extends CRM_Report_Form { } } - if ($value = CRM_Utils_Array::value('civicrm_address_state_province_id', $row)) { - $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($value, FALSE); - $entryFound = TRUE; - } - if ($value = CRM_Utils_Array::value('civicrm_address_country_id', $row)) { - $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant::country($value, FALSE); - $entryFound = TRUE; + $entryFound = $this->alterDisplayAddressFields($row, $rows, $rowNum, 'contribute/detail', 'List all contribution(s)') ? TRUE : $entryFound; + + // skip looking further in rows, if first row itself doesn't + // have the column we need + if (!$entryFound) { + break; } } } diff --git a/CRM/Report/Form/Contribute/Sybunt.php b/CRM/Report/Form/Contribute/Sybunt.php index d39c486ecc..8abe6ccd7d 100644 --- a/CRM/Report/Form/Contribute/Sybunt.php +++ b/CRM/Report/Form/Contribute/Sybunt.php @@ -120,34 +120,9 @@ class CRM_Report_Form_Contribute_Sybunt extends CRM_Report_Form { ), ), ), - 'civicrm_address' => - array( - 'dao' => 'CRM_Core_DAO_Address', - 'grouping' => 'contact-fields', - 'fields' => - array( - 'street_address' => array('default' => TRUE), - 'city' => array('default' => TRUE), - 'postal_code' => NULL, - 'state_province_id' => array('title' => ts('State/Province')), - 'country_id' => array('title' => ts('Country')), - ), - 'filters' => - array( - 'country_id' => - array( - 'title' => ts('Country'), - 'operatorType' => CRM_Report_Form::OP_MULTISELECT, - 'options' => CRM_Core_PseudoConstant::country(), - ), - 'state_province_id' => - array( - 'title' => ts('State / Province'), - 'operatorType' => CRM_Report_Form::OP_MULTISELECT, - 'options' => CRM_Core_PseudoConstant::stateProvince(), - ), - ), - ), + ) + + $this->addAddressFields() + + array( 'civicrm_contribution' => array( 'dao' => 'CRM_Contribute_DAO_Contribution', @@ -306,12 +281,7 @@ class CRM_Report_Form_Contribute_Sybunt extends CRM_Report_Form { ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND {$this->_aliases['civicrm_phone']}.is_primary = 1"; } - if ($this->isTableSelected('civicrm_address')) { - $this->_from .= " - LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']} - ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND - {$this->_aliases['civicrm_address']}.is_primary = 1"; - } + $this->addAddressFromClause(); } function where() { @@ -504,6 +474,8 @@ class CRM_Report_Form_Contribute_Sybunt extends CRM_Report_Form { } function alterDisplay(&$rows) { + // custom code to alter rows + $entryFound = FALSE; foreach ($rows as $rowNum => $row) { //Convert Display name into link @@ -516,6 +488,7 @@ class CRM_Report_Form_Contribute_Sybunt extends CRM_Report_Form { ); $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url; $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contribution Details for this Contact."); + $entryFound = TRUE; } // convert campaign_id to campaign title @@ -526,13 +499,12 @@ class CRM_Report_Form_Contribute_Sybunt extends CRM_Report_Form { } } - if ($value = CRM_Utils_Array::value('civicrm_address_state_province_id', $row)) { - $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($value, FALSE); - $entryFound = TRUE; - } - if ($value = CRM_Utils_Array::value('civicrm_address_country_id', $row)) { - $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant::country($value, FALSE); - $entryFound = TRUE; + $entryFound = $this->alterDisplayAddressFields($row, $rows, $rowNum, 'contribute/detail', 'List all contribution(s)') ? TRUE : $entryFound; + + // skip looking further in rows, if first row itself doesn't + // have the column we need + if (!$entryFound) { + break; } } } -- 2.25.1