CRM-13279 Adding filters for Age, Age at Event and Birth Date. Also adding jQuery...
authorDave Greenberg <dave@civicrm.org>
Wed, 2 Oct 2013 13:57:13 +0000 (14:57 +0100)
committerDave Greenberg <dave@civicrm.org>
Wed, 2 Oct 2013 13:57:13 +0000 (14:57 +0100)
----------------------------------------
* CRM-13279: Include gender and date of birth in (participant) reports
  http://issues.civicrm.org/jira/browse/CRM-13279

CRM/Report/Form/Event/ParticipantListing.php
templates/CRM/Report/Form/Event/ParticipantListing.tpl

index 859a3c44d24f1891ad5aabffb9cb0ab9040dfc63..39060238d03d04fba66a7799b929f606852e9bdc 100644 (file)
@@ -38,10 +38,12 @@ class CRM_Report_Form_Event_ParticipantListing extends CRM_Report_Form_Event {
 
   protected $_contribField = FALSE;
 
-  protected $_customGroupExtends = array('Participant');
+  protected $_customGroupExtends = array('Participant', 'Contact', 'Individual',);
+
   public $_drilldownReport = array('event/income' => 'Link to Detail Report');
 
   function __construct() {
+    $this->_autoIncludeIndexedFieldsAsOrderBys = 1;
 
     // Check if CiviCampaign is a) enabled and b) has active campaigns
     $config = CRM_Core_Config::singleton();
@@ -73,11 +75,19 @@ class CRM_Report_Form_Event_ParticipantListing extends CRM_Report_Form_Event {
             'no_display' => TRUE,
             'required' => TRUE,
           ),
+          'gender_id' =>
+          array('title' => ts('Gender'),
+          ),
           'birth_date' =>
           array('title' => ts('Birth Date'),
           ),
-          'gender_id' =>
-          array('title' => ts('Gender'),
+          'age' => array(
+            'title'   => ts('Age'),
+            'dbAlias' => 'TIMESTAMPDIFF(YEAR, contact_civireport.birth_date, CURDATE())',
+          ),
+          'age_at_event' => array(
+            'title'   => ts('Age at Event'),
+            'dbAlias' => 'TIMESTAMPDIFF(YEAR, contact_civireport.birth_date, event_civireport.start_date)',
           ),
           'employer_id' =>
           array('title' => ts('Organization'),
@@ -92,6 +102,21 @@ class CRM_Report_Form_Event_ParticipantListing extends CRM_Report_Form_Event {
             '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'),
+          ),
+          'age_at_event' =>
+          array(
+            'name' => 'age_at_event',
+            'title' => ts('Age at Event'),
+          ),
         ),
         'filters' =>
         array(
@@ -99,6 +124,16 @@ class CRM_Report_Form_Event_ParticipantListing extends CRM_Report_Form_Event {
           array('title' => ts('Participant Name'),
             'operator' => 'like',
           ),
+          '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' => 'Birth Date',
+            'operatorType' => CRM_Report_Form::OP_DATE,
+            'type'         => CRM_Utils_Type::T_DATE
+          ),
         ),
       ),
       'civicrm_email' =>
@@ -656,6 +691,14 @@ class CRM_Report_Form_Event_ParticipantListing extends CRM_Report_Form_Event {
         $entryFound = TRUE;
       }
 
+      // display birthday in the configured custom format
+      if (array_key_exists('civicrm_contact_birth_date', $row)) {
+        if ($value = $row['civicrm_contact_birth_date']) {
+            $rows[$rowNum]['civicrm_contact_birth_date'] = CRM_Utils_Date::customFormat($row['civicrm_contact_birth_date'], '%Y%m%d');
+        }
+        $entryFound = TRUE;
+      }
+
       // skip looking further in rows, if first row itself doesn't
       // have the column we need
       if (!$entryFound) {
@@ -663,4 +706,4 @@ class CRM_Report_Form_Event_ParticipantListing extends CRM_Report_Form_Event {
       }
     }
   }
-}
+}
\ No newline at end of file
index 39c23e75cd6d33cd2c792eb980fc100c3e28c16c..9ed848f0529ad304469083f80b5cb8cee7acd3d6 100644 (file)
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
 *}
+
+{literal}
+<script type="text/javascript">
+  cj(document).ready(function(){
+    cj('#birth_date_from').attr('startOffset',200);
+    cj('#birth_date_from').attr('endoffset',0);
+    cj('#birth_date_to').attr('startOffset',200);
+    cj('#birth_date_to').attr('endoffset',0);
+  });
+</script>
+{/literal}
+
 {include file="CRM/Report/Form.tpl"}