From 1fd5431f9805aee4666dc5b694a3b3b6beccb23b Mon Sep 17 00:00:00 2001 From: magnolia61 <richard.van.oosterhout@gmail.com> Date: Tue, 2 Sep 2014 23:37:43 +0200 Subject: [PATCH] Include gender & age in Constituent Summary Report This is a follow up of issue CRM-13279 which was resolved for the Participant Listing report only. In the Constituent Summary Report the gender and age are missing from selectable fields, order-by and filter. The fix follows the same pattern as the one for issue CRM-13279 --- CRM/Report/Form/Contact/Summary.php | 51 +++++++++++++++++++ templates/CRM/Report/Form/Contact/Summary.tpl | 9 ++++ 2 files changed, 60 insertions(+) diff --git a/CRM/Report/Form/Contact/Summary.php b/CRM/Report/Form/Contact/Summary.php index 7dbc2b3863..7a6a1aa0ec 100644 --- a/CRM/Report/Form/Contact/Summary.php +++ b/CRM/Report/Form/Contact/Summary.php @@ -65,6 +65,9 @@ class CRM_Report_Form_Contact_Summary extends CRM_Report_Form { 'first_name' => array( 'title' => ts('First Name'), ), + 'middle_name' => array( + 'title' => ts('Middle Name'), + ), 'last_name' => array( 'title' => ts('Last Name'), ), @@ -81,10 +84,17 @@ class CRM_Report_Form_Contact_Summary extends CRM_Report_Form { 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())', + ), ), 'filters' => array( @@ -98,6 +108,11 @@ class CRM_Report_Form_Contact_Summary extends CRM_Report_Form { array('title' => ts('Contact ID'), 'no_display' => TRUE, ), + 'gender_id' => + array('title' => ts('Gender'), + 'operatorType' => CRM_Report_Form::OP_MULTISELECT, + 'options' => CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'), + ), 'birth_date' => array( 'title' => ts('Birth Date'), @@ -111,6 +126,16 @@ class CRM_Report_Form_Contact_Summary extends CRM_Report_Form { array( 'title' => ts('Last Name, First Name'), 'default' => '1', 'default_weight' => '0', 'default_order' => 'ASC', ), + 'gender_id' => + array( + 'name' => 'gender_id', + 'title' => ts('Gender'), + ), + 'birth_date' => + array( + 'name' => 'birth_date', + 'title' => ts('Birth Date'), + ), ), ), 'civicrm_email' => @@ -246,9 +271,24 @@ class CRM_Report_Form_Contact_Summary extends CRM_Report_Form { /** * @param $rows */ + private function _initBasicRow(&$rows, &$entryFound, $row, $rowId, $rowNum, $types){ + if (!array_key_exists($rowId, $row)) { + return FALSE; + } + + $value = $row[$rowId]; + if ($value) { + $rows[$rowNum][$rowId] = $types[$value]; + } + $entryFound = TRUE; + } + function alterDisplay(&$rows) { // custom code to alter rows $entryFound = FALSE; + + $genders = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id', array('localize' => TRUE)); + foreach ($rows as $rowNum => $row) { // make count columns point to detail report // convert sort name to links @@ -271,6 +311,17 @@ class CRM_Report_Form_Contact_Summary extends CRM_Report_Form { $entryFound = TRUE; } + // handle gender id + $this->_initBasicRow($rows, $entryFound, $row, 'civicrm_contact_gender_id', $rowNum, $genders); + + // display birthday in the configured custom format + if (array_key_exists('civicrm_contact_birth_date', $row)) { + $birthDate = $row['civicrm_contact_birth_date']; + if ($birthDate) { + $rows[$rowNum]['civicrm_contact_birth_date'] = CRM_Utils_Date::customFormat($birthDate, '%Y%m%d'); + } + $entryFound = TRUE; + } // skip looking further in rows, if first row itself doesn't // have the column we need diff --git a/templates/CRM/Report/Form/Contact/Summary.tpl b/templates/CRM/Report/Form/Contact/Summary.tpl index 9d72b48002..7519db6d23 100644 --- a/templates/CRM/Report/Form/Contact/Summary.tpl +++ b/templates/CRM/Report/Form/Contact/Summary.tpl @@ -23,4 +23,13 @@ | see the CiviCRM license FAQ at http://civicrm.org/licensing | +--------------------------------------------------------------------+ *} + +{literal} +<script type="text/javascript"> + CRM.$(function($) { + $('#birth_date_from, #birth_date_to').attr({startOffset: '200', endoffset: '0'}); + }); +</script> +{/literal} + {include file="CRM/Report/Form.tpl"} -- 2.25.1