From e5575773758a41799eb4a03501cf7abed1c1cfb1 Mon Sep 17 00:00:00 2001 From: eileenmcnaugton Date: Mon, 31 Aug 2015 16:13:53 +1200 Subject: [PATCH] CRM-17115 extra/ stdise fields on CiviReport --- CRM/Report/Form.php | 96 +++++++++++++++++++++++++- CRM/Report/Form/Contribute/Summary.php | 19 +---- CRM/Report/Form/Member/Detail.php | 63 ++++------------- 3 files changed, 109 insertions(+), 69 deletions(-) diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index 42f4393e2b..89b47f51ab 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -3967,9 +3967,10 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a 'civicrm_address' => array( 'dao' => 'CRM_Core_DAO_Address', 'fields' => array( - 'name' => array( + 'address_name' => array( 'title' => ts('Address Name'), 'default' => CRM_Utils_Array::value('name', $defaults, FALSE), + 'name' => 'name', ), 'street_address' => array( 'title' => ts('Street Address'), @@ -4171,6 +4172,41 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a return $entryFound; } + /** + * Do AlterDisplay processing on Address Fields. + * + * @param array $row + * @param array $rows + * @param int $rowNum + * + * @return bool + */ + public function alterDisplayContactFields(&$row, &$rows, &$rowNum) { + $entryFound = FALSE; + if (array_key_exists('civicrm_contact_prefix_id', $row)) { + $prefixes = CRM_Contact_BAO_Contact::buildOptions('prefix_id'); + if ($value = $row['civicrm_contact_prefix_id']) { + $rows[$rowNum]['civicrm_contact_prefix_id'] = $prefixes[$rows[$rowNum]['civicrm_contact_prefix_id']]; + } + $entryFound = TRUE; + } + if (array_key_exists('civicrm_contact_suffix_id', $row)) { + $suffixes = CRM_Contact_BAO_Contact::buildOptions('suffix_id'); + if ($value = $row['civicrm_contact_suffix_id']) { + $rows[$rowNum]['civicrm_contact_suffix_id'] = $suffixes[$rows[$rowNum]['civicrm_contact_suffix_id']]; + } + $entryFound = TRUE; + } + if (array_key_exists('civicrm_contact_gender_id', $row)) { + $genders = CRM_Contact_BAO_Contact::buildOptions('gender_id'); + if ($value = $row['civicrm_contact_gender_id']) { + $rows[$rowNum]['civicrm_contact_gender_id'] = $genders[$rows[$rowNum]['civicrm_contact_gender_id']]; + } + $entryFound = TRUE; + } + return $entryFound; + } + /** * Adjusts dates passed in to YEAR() for fiscal year. * @@ -4282,6 +4318,64 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a ); } + /** + * Get a standard set of contact fields. + * + * @return array + */ + public function getBasicContactFields() { + return array( + 'sort_name' => array( + 'title' => ts('Contact Name'), + 'required' => TRUE, + 'default' => TRUE, + ), + 'id' => array( + 'no_display' => TRUE, + 'required' => TRUE, + ), + 'prefix_id' => array( + 'title' => ts('Contact Prefix'), + ), + 'first_name' => array( + 'title' => ts('First Name'), + ), + 'middle_name' => array( + 'title' => ts('Middle Name'), + ), + 'last_name' => array( + 'title' => ts('Last Name'), + ), + 'suffix_id' => array( + 'title' => ts('Contact Suffix'), + ), + 'postal_greeting_display' => array('title' => ts('Postal Greeting')), + 'email_greeting_display' => array('title' => ts('Email Greeting')), + 'contact_type' => array( + 'title' => ts('Contact Type'), + ), + 'contact_sub_type' => array( + 'title' => ts('Contact Subtype'), + ), + 'gender_id' => array( + 'title' => ts('Gender'), + ), + 'birth_date' => array( + 'title' => ts('Birth Date'), + ), + 'age' => array( + 'title' => ts('Age'), + 'dbAlias' => 'TIMESTAMPDIFF(YEAR, contact_civireport.birth_date, CURDATE())', + ), + 'job_title' => array( + 'title' => ts('Contact Job title'), + ), + 'organization_name' => array( + 'title' => ts('Organization Name'), + ), + ); + } + /** * Add contact to group. * diff --git a/CRM/Report/Form/Contribute/Summary.php b/CRM/Report/Form/Contribute/Summary.php index 3eaf0dd567..9219ba6a6a 100644 --- a/CRM/Report/Form/Contribute/Summary.php +++ b/CRM/Report/Form/Contribute/Summary.php @@ -60,23 +60,7 @@ class CRM_Report_Form_Contribute_Summary extends CRM_Report_Form { $this->_columns = array( 'civicrm_contact' => array( 'dao' => 'CRM_Contact_DAO_Contact', - 'fields' => array( - 'sort_name' => array( - 'title' => ts('Contact Name'), - 'no_repeat' => TRUE, - ), - 'postal_greeting_display' => array('title' => ts('Postal Greeting')), - 'id' => array( - 'no_display' => TRUE, - 'required' => TRUE, - ), - 'contact_type' => array( - 'title' => ts('Contact Type'), - ), - 'contact_sub_type' => array( - 'title' => ts('Contact Subtype'), - ), - ), + 'fields' => $this->getBasicContactFields(), 'grouping' => 'contact-fields', 'group_bys' => array( 'id' => array('title' => ts('Contact ID')), @@ -827,6 +811,7 @@ ROUND(AVG({$this->_aliases['civicrm_contribution_soft']}.amount), 2) as civicrm_ } $entryFound = $this->alterDisplayAddressFields($row, $rows, $rowNum, 'contribute/detail', 'List all contribution(s) for this ') ? TRUE : $entryFound; + $entryFound = $this->alterDisplayContactFields($row, $rows, $rowNum, 'contribute/detail') ? TRUE : $entryFound; // skip looking further in rows, if first row itself doesn't // have the column we need diff --git a/CRM/Report/Form/Member/Detail.php b/CRM/Report/Form/Member/Detail.php index d5fb73c29d..53009043f6 100644 --- a/CRM/Report/Form/Member/Detail.php +++ b/CRM/Report/Form/Member/Detail.php @@ -48,8 +48,7 @@ class CRM_Report_Form_Member_Detail extends CRM_Report_Form { protected $_customGroupGroupBy = FALSE; /** - */ - /** + * Class constructor. */ public function __construct() { @@ -65,33 +64,7 @@ class CRM_Report_Form_Member_Detail extends CRM_Report_Form { $this->_columns = array( 'civicrm_contact' => array( 'dao' => 'CRM_Contact_DAO_Contact', - 'fields' => array( - 'sort_name' => array( - 'title' => ts('Contact Name'), - 'required' => TRUE, - 'default' => TRUE, - ), - 'id' => array( - 'no_display' => TRUE, - 'required' => TRUE, - ), - 'first_name' => array( - 'title' => ts('First Name'), - ), - 'id' => array( - 'no_display' => TRUE, - 'required' => TRUE, - ), - 'last_name' => array( - 'title' => ts('Last Name'), - ), - 'contact_type' => array( - 'title' => ts('Contact Type'), - ), - 'contact_sub_type' => array( - 'title' => ts('Contact Subtype'), - ), - ), + 'fields' => $this->getBasicContactFields(), 'filters' => array( 'sort_name' => array( 'title' => ts('Contact Name'), @@ -183,21 +156,6 @@ class CRM_Report_Form_Member_Detail extends CRM_Report_Form { ), 'grouping' => 'member-fields', ), - 'civicrm_address' => array( - 'dao' => 'CRM_Core_DAO_Address', - 'fields' => array( - 'street_address' => NULL, - 'city' => NULL, - 'postal_code' => NULL, - 'state_province_id' => array( - 'title' => ts('State/Province'), - ), - 'country_id' => array( - 'title' => ts('Country'), - ), - ), - 'grouping' => 'contact-fields', - ), 'civicrm_email' => array( 'dao' => 'CRM_Core_DAO_Email', 'fields' => array('email' => NULL), @@ -271,7 +229,11 @@ class CRM_Report_Form_Member_Detail extends CRM_Report_Form { ), 'grouping' => 'contri-fields', ), - ); + ) + $this->getAddressColumns(array( + // These options are only excluded because they were not previously present. + 'order_by' => FALSE, + 'group_by' => FALSE, + )); $this->_groupFilter = TRUE; $this->_tagFilter = TRUE; @@ -306,10 +268,7 @@ class CRM_Report_Form_Member_Detail extends CRM_Report_Form { if (array_key_exists('fields', $table)) { foreach ($table['fields'] as $fieldName => $field) { if (!empty($field['required']) || !empty($this->_params['fields'][$fieldName])) { - if ($tableName == 'civicrm_address') { - $this->_addressField = TRUE; - } - elseif ($tableName == 'civicrm_email') { + if ($tableName == 'civicrm_email') { $this->_emailField = TRUE; } elseif ($tableName == 'civicrm_phone') { @@ -341,14 +300,14 @@ class CRM_Report_Form_Member_Detail extends CRM_Report_Form { ON {$this->_aliases['civicrm_membership_status']}.id = {$this->_aliases['civicrm_membership']}.status_id "; - //used when address field is selected - if ($this->_addressField) { + 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\n"; } + //used when email field is selected if ($this->_emailField) { $this->_from .= " @@ -495,6 +454,8 @@ class CRM_Report_Form_Member_Detail extends CRM_Report_Form { $entryFound = TRUE; } } + $entryFound = $this->alterDisplayAddressFields($row, $rows, $rowNum, 'member/detail', 'List all memberships(s) for this ') ? TRUE : $entryFound; + $entryFound = $this->alterDisplayContactFields($row, $rows, $rowNum, 'member/detail') ? TRUE : $entryFound; if (!$entryFound) { break; -- 2.25.1