Merge pull request #4764 from rohankatkar/CRM-15615
[civicrm-core.git] / CRM / Report / Form / Contribute / HouseholdSummary.php
index 67c5867313c9ddb9cf30ea97b4b7e1a605293fda..351215a14f5b5ee019608f36b980ab8dbde9c4da 100644 (file)
@@ -64,11 +64,10 @@ class CRM_Report_Form_Contribute_HouseholdSummary extends CRM_Report_Form {
       'civicrm_contact_household' => array(
         'dao' => 'CRM_Contact_DAO_Contact',
         'fields' => array(
-          'household_name' =>
-            array(
-              'title' => ts('Household Name'),
-              'required' => TRUE,
-            ),
+          'household_name' => array(
+            'title' => ts('Household Name'),
+            'required' => TRUE,
+          ),
           'id' => array(
             'no_display' => TRUE,
             'required' => TRUE,
@@ -77,7 +76,7 @@ class CRM_Report_Form_Contribute_HouseholdSummary extends CRM_Report_Form {
             'title' => ts('Contact Type'),
           ),
           'contact_sub_type' => array(
-            'title' => ts('Contact SubType'),
+            'title' => ts('Contact Subtype'),
           ),
         ),
         'filters' => array(
@@ -98,7 +97,7 @@ class CRM_Report_Form_Contribute_HouseholdSummary extends CRM_Report_Form {
             'type' => CRM_Utils_Type::T_INT,
             'operatorType' => CRM_Report_Form::OP_SELECT,
             'options' => $this->relationTypes,
-            'default' => array(1),
+            'default' => key($this->relationTypes),
           ),
         ),
         'grouping' => 'household-fields',
@@ -210,7 +209,9 @@ class CRM_Report_Form_Contribute_HouseholdSummary extends CRM_Report_Form {
     foreach ($this->_columns as $tableName => $table) {
       if (array_key_exists('fields', $table)) {
         foreach ($table['fields'] as $fieldName => $field) {
-          if (!empty($field['required']) || !empty($this->_params['fields'][$fieldName])) {
+          if (!empty($field['required']) ||
+            !empty($this->_params['fields'][$fieldName])
+          ) {
             if ($tableName == 'civicrm_address') {
               $this->_addressField = TRUE;
             }
@@ -283,7 +284,9 @@ class CRM_Report_Form_Contribute_HouseholdSummary extends CRM_Report_Form {
             $op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params);
             if ($op) {
               if ($fieldName == 'relationship_type_id') {
-                $clause = "{$this->_aliases['civicrm_relationship']}.relationship_type_id=" . $this->relationshipId;
+                $clause =
+                  "{$this->_aliases['civicrm_relationship']}.relationship_type_id=" .
+                  $this->relationshipId;
               }
               else {
                 $clause = $this->whereClause($field,
@@ -348,6 +351,23 @@ class CRM_Report_Form_Contribute_HouseholdSummary extends CRM_Report_Form {
   function postProcess() {
 
     $this->beginPostProcess();
+    $this->buildACLClause(array(
+        $this->_aliases['civicrm_contact'],
+        $this->_aliases['civicrm_contact_household']
+      ));
+    $sql = $this->buildQuery(TRUE);
+    $rows = array();
+
+    $this->buildRows($sql, $rows);
+    $this->formatDisplay($rows);
+    $this->doTemplateAssignment($rows);
+    $this->endPostProcess($rows);
+  }
+
+  /**
+   * Set variables to be accessed by API and form layer in processing
+   */
+  function beginPostProcessCommon() {
     $getRelationship = $this->_params['relationship_type_id_value'];
     $type = substr($getRelationship, -3);
     $this->relationshipId = intval((substr($getRelationship, 0, strpos($getRelationship, '_'))));
@@ -359,14 +379,6 @@ class CRM_Report_Form_Contribute_HouseholdSummary extends CRM_Report_Form {
       $this->householdContact = 'contact_id_a';
       $this->otherContact = 'contact_id_b';
     }
-    $this->buildACLClause(array($this->_aliases['civicrm_contact'], $this->_aliases['civicrm_contact_household']));
-    $sql = $this->buildQuery(TRUE);
-    $rows = array();
-
-    $this->buildRows($sql, $rows);
-    $this->formatDisplay($rows);
-    $this->doTemplateAssignment($rows);
-    $this->endPostProcess($rows);
   }
 
   function validRelationships() {
@@ -410,13 +422,16 @@ class CRM_Report_Form_Contribute_HouseholdSummary extends CRM_Report_Form {
       //replace retionship id by relationship name
       if (array_key_exists('civicrm_relationship_relationship_type_id', $row)) {
         if ($value = $row['civicrm_relationship_relationship_type_id']) {
-          $rows[$rowNum]['civicrm_relationship_relationship_type_id'] = $this->relationTypes[$value . '_' . $type];
+          $rows[$rowNum]['civicrm_relationship_relationship_type_id'] = $this->relationTypes[
+          $value . '_' . $type];
           $entryFound = TRUE;
         }
       }
 
       //remove duplicate Organization names
-      if (array_key_exists('civicrm_contact_household_household_name', $row) && $this->_outputMode != 'csv') {
+      if (array_key_exists('civicrm_contact_household_household_name', $row) &&
+        $this->_outputMode != 'csv'
+      ) {
         if ($value = $row['civicrm_contact_household_household_name']) {
           if ($rowNum == 0) {
             $priviousHousehold = $value;
@@ -442,14 +457,18 @@ class CRM_Report_Form_Contribute_HouseholdSummary extends CRM_Report_Form {
             );
 
             $rows[$rowNum]['civicrm_contact_household_household_name'] =
-              "<a href='$url' title='" . ts('View contact summary for this househould') . "'>" . $value . '</a>';
+              "<a href='$url' title='" .
+              ts('View contact summary for this househould') . "'>" . $value .
+              '</a>';
           }
           $entryFound = TRUE;
         }
       }
 
       //remove duplicate Contact names and relationship type
-      if (array_key_exists('civicrm_contact_id', $row) && $this->_outputMode != 'csv') {
+      if (array_key_exists('civicrm_contact_id', $row) &&
+        $this->_outputMode != 'csv'
+      ) {
         if ($value = $row['civicrm_contact_id']) {
           if ($rowNum == 0) {
             $priviousContact = $value;
@@ -520,7 +539,8 @@ class CRM_Report_Form_Contribute_HouseholdSummary extends CRM_Report_Form {
         CRM_Core_Permission::check('access CiviContribute')
       ) {
         $url = CRM_Utils_System::url("civicrm/contact/view/contribution",
-          "reset=1&id=" . $row['civicrm_contribution_id'] . "&cid=" . $row['civicrm_contact_id'] .
+          "reset=1&id=" . $row['civicrm_contribution_id'] . "&cid=" .
+          $row['civicrm_contact_id'] .
           "&action=view&context=contribution&selectedChild=contribute",
           $this->_absoluteUrl
         );