CRM-17115 extra/ stdise fields on CiviReport
authoreileenmcnaugton <eileen@fuzion.co.nz>
Mon, 31 Aug 2015 04:13:53 +0000 (16:13 +1200)
committereileenmcnaugton <eileen@fuzion.co.nz>
Mon, 31 Aug 2015 04:13:53 +0000 (16:13 +1200)
CRM/Report/Form.php
CRM/Report/Form/Contribute/Summary.php
CRM/Report/Form/Member/Detail.php

index 42f4393e2bbe4449bf1602bbb5fff774f2ac0fe0..89b47f51ab103bb6f42363311312cfd045fdff99 100644 (file)
@@ -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.
    *
index 3eaf0dd56738eb647b4bf5cd7e2ca97a92bc1359..9219ba6a6a3e544a9e69e3d16b7c94b1222a186f 100644 (file)
@@ -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
index d5fb73c29d27f846dca83f5723876f0033877a3d..53009043f69cc1f8a046609900a8986c5ca412f9 100644 (file)
@@ -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;