Ensure reports use nested group selector and remove boilerplate
[civicrm-core.git] / CRM / Report / Form / Contact / Detail.php
index 1ab75d81241cefc136542de539aeef970d4ab725..87917f3b13adc6d159b8183a0bdeab0c840cc530 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
@@ -40,6 +40,12 @@ class CRM_Report_Form_Contact_Detail extends CRM_Report_Form {
   protected $_customGroupExtends = array(
     'Contact', 'Individual', 'Household', 'Organization');
 
+  /**
+   *
+   */
+  /**
+   *
+   */
   function __construct() {
     $this->_autoIncludeIndexedFieldsAsOrderBys = 1;
     $this->_columns = array(
@@ -350,28 +356,12 @@ class CRM_Report_Form_Contact_Detail extends CRM_Report_Form {
           ),
         'grouping' => 'activity-fields',
       ),
-      'civicrm_group' =>
-      array(
-        'dao' => 'CRM_Contact_DAO_Group',
-        'alias' => 'cgroup',
-        'filters' =>
-        array(
-          'gid' =>
-          array(
-            'name' => 'group_id',
-            'title' => ts('Group'),
-            'operatorType' => CRM_Report_Form::OP_MULTISELECT,
-            'group' => TRUE,
-            'options' => CRM_Core_PseudoConstant::group(),
-          ),
-        ),
-      ),
       'civicrm_phone' =>
       array(
         'dao' => 'CRM_Core_DAO_Phone',
         'fields' =>
         array(
-          'phone' => NULL,   
+          'phone' => NULL,
           'phone_ext' =>
           array(
             'title' => ts('Phone Extension')
@@ -380,7 +370,7 @@ class CRM_Report_Form_Contact_Detail extends CRM_Report_Form {
         'grouping' => 'contact-fields',
       ),
     );
-
+    $this->_groupFilter = TRUE;
     $this->_tagFilter = TRUE;
     parent::__construct();
   }
@@ -397,9 +387,7 @@ class CRM_Report_Form_Contact_Detail extends CRM_Report_Form {
     foreach ($this->_columns as $tableName => $table) {
       if (array_key_exists('fields', $table)) {
         foreach ($table['fields'] as $fieldName => $field) {
-          if (CRM_Utils_Array::value('required', $field) ||
-            CRM_Utils_Array::value($fieldName, $this->_params['fields'])
-          ) {
+          if (!empty($field['required']) || !empty($this->_params['fields'][$fieldName])) {
             //isolate the select clause compoenent wise
             if (in_array($table['alias'], $this->_component)) {
               $select[$table['alias']][] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
@@ -436,7 +424,7 @@ class CRM_Report_Form_Contact_Detail extends CRM_Report_Form {
     }
 
     foreach ($this->_component as $val) {
-      if (CRM_Utils_Array::value($val, $select)) {
+      if (!empty($select[$val])) {
         $this->_selectComponent[$val] = "SELECT " . implode(', ', $select[$val]) . " ";
         unset($select[$val]);
       }
@@ -445,6 +433,13 @@ class CRM_Report_Form_Contact_Detail extends CRM_Report_Form {
     $this->_select = "SELECT " . implode(', ', $select) . " ";
   }
 
+  /**
+   * @param $fields
+   * @param $files
+   * @param $self
+   *
+   * @return array
+   */
   static function formRule($fields, $files, $self) {
     $errors = array();
     return $errors;
@@ -486,7 +481,7 @@ class CRM_Report_Form_Contact_Detail extends CRM_Report_Form {
     $this->_from .= "{$group}";
 
     foreach ($this->_component as $val) {
-      if (CRM_Utils_Array::value('contribution_civireport', $this->_selectComponent)) {
+      if (!empty($this->_selectComponent['contribution_civireport'])) {
         $this->_formComponent['contribution_civireport'] = " FROM
                             civicrm_contact  {$this->_aliases['civicrm_contact']}
                             INNER JOIN civicrm_contribution       {$this->_aliases['civicrm_contribution']}
@@ -494,14 +489,14 @@ class CRM_Report_Form_Contact_Detail extends CRM_Report_Form {
                             {$group}
                     ";
       }
-      if (CRM_Utils_Array::value('membership_civireport', $this->_selectComponent)) {
+      if (!empty($this->_selectComponent['membership_civireport'])) {
         $this->_formComponent['membership_civireport'] = " FROM
                             civicrm_contact  {$this->_aliases['civicrm_contact']}
                             INNER JOIN civicrm_membership       {$this->_aliases['civicrm_membership']}
                                     ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_membership']}.contact_id
                             {$group} ";
       }
-      if (CRM_Utils_Array::value('participant_civireport', $this->_selectComponent)) {
+      if (!empty($this->_selectComponent['participant_civireport'])) {
         $this->_formComponent['participant_civireport'] = " FROM
                             civicrm_contact  {$this->_aliases['civicrm_contact']}
                             INNER JOIN civicrm_participant       {$this->_aliases['civicrm_participant']}
@@ -509,7 +504,7 @@ class CRM_Report_Form_Contact_Detail extends CRM_Report_Form {
                             {$group} ";
       }
 
-      if (CRM_Utils_Array::value('activity_civireport', $this->_selectComponent)) {
+      if (!empty($this->_selectComponent['activity_civireport'])) {
         $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
         $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
         $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
@@ -544,7 +539,7 @@ class CRM_Report_Form_Contact_Detail extends CRM_Report_Form {
                             civicrm_case_contact.case_id = civicrm_case.id ";
       }
 
-      if (CRM_Utils_Array::value('relationship_civireport', $this->_selectComponent)) {
+      if (!empty($this->_selectComponent['relationship_civireport'])) {
         $this->_formComponent['relationship_civireport'] = "FROM
                             civicrm_relationship {$this->_aliases['civicrm_relationship']}
 
@@ -600,12 +595,15 @@ class CRM_Report_Form_Contact_Detail extends CRM_Report_Form {
     $this->_where .= " GROUP BY {$this->_aliases['civicrm_contact']}.id ";
   }
 
+  /**
+   * @return array
+   */
   function clauseComponent() {
     $selectedContacts = implode(',', $this->_contactSelected);
     $contribution     = $membership = $participant = NULL;
     $eligibleResult   = $rows = $tempArray = array();
     foreach ($this->_component as $val) {
-      if (CRM_Utils_Array::value($val, $this->_selectComponent) && ($val != 'activity_civireport' && $val != 'relationship_civireport')) {
+      if (!empty($this->_selectComponent[$val]) && ($val != 'activity_civireport' && $val != 'relationship_civireport')) {
         $sql = "{$this->_selectComponent[$val]} {$this->_formComponent[$val]}
                          WHERE    {$this->_aliases['civicrm_contact']}.id IN ( $selectedContacts )
                          GROUP BY {$this->_aliases['civicrm_contact']}.id,{$val}.id ";
@@ -631,7 +629,7 @@ class CRM_Report_Form_Contact_Detail extends CRM_Report_Form {
       }
     }
 
-    if (CRM_Utils_Array::value('relationship_civireport', $this->_selectComponent)) {
+    if (!empty($this->_selectComponent['relationship_civireport'])) {
 
       $relTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, NULL, TRUE);
 
@@ -671,7 +669,7 @@ class CRM_Report_Form_Contact_Detail extends CRM_Report_Form {
       }
     }
 
-    if (CRM_Utils_Array::value('activity_civireport', $this->_selectComponent)) {
+    if (!empty($this->_selectComponent['activity_civireport'])) {
 
       $componentClause = "civicrm_option_value.component_id IS NULL";
       $componentsIn    = NULL;
@@ -736,6 +734,11 @@ class CRM_Report_Form_Contact_Detail extends CRM_Report_Form {
     return $rows;
   }
 
+  /**
+   * @param $rows
+   *
+   * @return array
+   */
   function statistics(&$rows) {
     $statistics = array();
 
@@ -751,11 +754,17 @@ class CRM_Report_Form_Contact_Detail extends CRM_Report_Form {
   }
 
   //Override to set limit is 10
+  /**
+   * @param int $rowCount
+   */
   function limit($rowCount = self::ROW_COUNT_LIMIT) {
     parent::limit($rowCount);
   }
 
   //Override to set pager with limit is 10
+  /**
+   * @param int $rowCount
+   */
   function setPager($rowCount = self::ROW_COUNT_LIMIT) {
     parent::setPager($rowCount);
   }
@@ -802,6 +811,9 @@ class CRM_Report_Form_Contact_Detail extends CRM_Report_Form {
     $this->endPostProcess();
   }
 
+  /**
+   * @param $rows
+   */
   function alterDisplay(&$rows) {
     // custom code to alter rows
 
@@ -840,6 +852,9 @@ class CRM_Report_Form_Contact_Detail extends CRM_Report_Form {
     }
   }
 
+  /**
+   * @param $componentRows
+   */
   function alterComponentDisplay(&$componentRows) {
     // custom code to alter rows
     $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE);