Include gender & age in Constituent Summary Report
authormagnolia61 <richard.van.oosterhout@gmail.com>
Tue, 2 Sep 2014 21:37:43 +0000 (23:37 +0200)
committermagnolia61 <richard.van.oosterhout@gmail.com>
Tue, 2 Sep 2014 21:37:43 +0000 (23:37 +0200)
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
templates/CRM/Report/Form/Contact/Summary.tpl

index 7dbc2b3863f2384e1f5f1c7b6a97835ef9e9db6f..7a6a1aa0ec7d79338143d6407612a1f3d2e7927e 100644 (file)
@@ -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
index 9d72b48002e49183eb3814ad8186832e53f61111..7519db6d23688e01851383416bde63da675660d1 100644 (file)
  | 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"}