CRM-14106 - Regex targeting other conditionals
[civicrm-core.git] / CRM / Report / Form / Contribute / History.php
index 6cf7575057fc971a5cac757f521f63637cae3049..7542ebaf9d2e4db43ee4f470cc8c5b629cc2dcc6 100644 (file)
@@ -1,9 +1,8 @@
 <?php
-// $Id$
 
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.4                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2013                                |
  +--------------------------------------------------------------------+
@@ -94,6 +93,14 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
             'default' => TRUE,
             'required' => TRUE,
           ),
+          'contact_type' =>
+          array(
+            'title' => ts('Contact Type'),
+          ),
+          'contact_sub_type' =>
+          array(
+            'title' => ts('Contact SubType'),
+          ),
         ),
         'grouping' => 'contact-fields',
         'filters' =>
@@ -201,8 +208,8 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
             'options' => CRM_Contribute_PseudoConstant::contributionStatus(),
             'default' => array(1),
           ),
-          'financial_type_id' => array( 
-            'title' => ts('Financial Type'), 
+          'financial_type_id' => array(
+            'title' => ts('Financial Type'),
             'operatorType' => CRM_Report_Form::OP_MULTISELECT,
             'options' => CRM_Contribute_PseudoConstant::financialType(),
           ),
@@ -274,9 +281,7 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
       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])) {
             if ($tableName == 'civicrm_address') {
               $this->_addressField = TRUE;
             }
@@ -293,32 +298,28 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
               continue;
             }
 
-            if ($fieldName == 'total_amount') {
-              $select[] = "SUM({$field['dbAlias']}) as {$tableName}_{$fieldName}";
-            }
-
-            if (CRM_Utils_Array::value('is_statistics', $field)) {
+            if (!empty($field['is_statistics'])) {
               $this->_columnHeaders[$fieldName]['type'] = $field['type'];
               $this->_columnHeaders[$fieldName]['title'] = $field['title'];
               continue;
             }
-            elseif ($fieldName == 'receive_date') { 
-                if ((CRM_Utils_Array::value('this_year_op', $this->_params) == 'fiscal' && 
-                     CRM_Utils_Array::value('this_year_value', $this->_params)) ||
-                    (CRM_Utils_Array::value('other_year_op', $this->_params == 'fiscal') && 
-                      CRM_Utils_Array::value('other_year_value', $this->_params)
-                     )){
+            elseif ($fieldName == 'receive_date') {
+                if ((CRM_Utils_Array::value('this_year_op', $this->_params) == 'fiscal' && !empty($this->_params['this_year_value'])) ||
+                    (CRM_Utils_Array::value('other_year_op', $this->_params == 'fiscal') && !empty($this->_params['other_year_value']))){
                     $select[] = self::fiscalYearOffset($field['dbAlias']) . " as {$tableName}_{$fieldName}";
                 }else{
                     $select[] = " YEAR(".$field['dbAlias'].")" . " as {$tableName}_{$fieldName}";
                 }
             }
+            elseif ($fieldName == 'total_amount') {
+              $select[] = "SUM({$field['dbAlias']}) as {$tableName}_{$fieldName}";
+            }
             else {
               $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
               $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field);
               $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title'];
             }
-            if (CRM_Utils_Array::value('no_display', $field)) {
+            if (!empty($field['no_display'])) {
               $this->_columnHeaders["{$tableName}_{$fieldName}"]['no_display'] = TRUE;
             }
           }
@@ -332,31 +333,31 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
   function from() {
     $this->_from = "
         FROM civicrm_contact  {$this->_aliases['civicrm_contact']}
-             INNER JOIN civicrm_contribution   {$this->_aliases['civicrm_contribution']} 
+             INNER JOIN civicrm_contribution   {$this->_aliases['civicrm_contribution']}
                      ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_contribution']}.contact_id AND
                         {$this->_aliases['civicrm_contribution']}.is_test = 0 ";
 
     if ($this->_emailField) {
-      $this->_from .= " LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']} 
-                     ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND 
+      $this->_from .= " LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
+                     ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND
                         {$this->_aliases['civicrm_email']}.is_primary = 1) ";
     }
 
     if ($this->_phoneField) {
-      $this->_from .= " LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']} 
-                     ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND 
+      $this->_from .= " LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
+                     ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
                         {$this->_aliases['civicrm_phone']}.is_primary = 1) ";
     }
 
     $relContacAlias = 'contact_relationship';
-    $this->_relationshipFrom = " INNER JOIN civicrm_relationship {$this->_aliases['civicrm_relationship']} 
+    $this->_relationshipFrom = " INNER JOIN civicrm_relationship {$this->_aliases['civicrm_relationship']}
                      ON (({$this->_aliases['civicrm_relationship']}.contact_id_a = {$relContacAlias}.id OR {$this->_aliases['civicrm_relationship']}.contact_id_b = {$relContacAlias}.id ) AND {$this->_aliases['civicrm_relationship']}.is_active = 1) ";
 
     if ($this->_addressField) {
       $this->_from .= "
-                  LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']} 
-                         ON {$this->_aliases['civicrm_contact']}.id = 
-                            {$this->_aliases['civicrm_address']}.contact_id AND 
+                  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";
     }
   }
@@ -401,7 +402,7 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
               $this->_statusClause = " AND " . $clause;
             }
 
-            if (CRM_Utils_Array::value('having', $field)) {
+            if (!empty($field['having'])) {
               $havingClauses[] = $clause;
             }
             else {
@@ -471,8 +472,7 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
 
   static function formRule($fields, $files, $self) {
     $errors = array();
-    if (CRM_Utils_Array::value('this_year_value', $fields) &&
-      CRM_Utils_Array::value('other_year_value', $fields) &&
+    if (!empty($fields['this_year_value']) && !empty($fields['other_year_value']) &&
       ($fields['this_year_value'] == $fields['other_year_value'])
     ) {
       $errors['other_year_value'] = ts("Value for filters 'This Year' and 'Other Years' can not be same.");
@@ -508,10 +508,10 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
   }
 
   function fixReportParams() {
-    if (CRM_Utils_Array::value('this_year_value', $this->_params)) {
+    if (!empty($this->_params['this_year_value'])) {
       $this->_referenceYear['this_year'] = $this->_params['this_year_value'];
     }
-    if (CRM_Utils_Array::value('other_year_value', $this->_params)) {
+    if (!empty($this->_params['other_year_value'])) {
       $this->_referenceYear['other_year'] = $this->_params['other_year_value'];
     }
   }
@@ -521,17 +521,17 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
 
     $addWhere = '';
 
-    if (CRM_Utils_Array::value('other_year', $this->_referenceYear)) {
+    if (!empty($this->_referenceYear['other_year'])) {
         (CRM_Utils_Array::value('other_year_op', $this->_params) == 'calendar') ? $other_receive_date = 'YEAR (contri.receive_date)' : $other_receive_date = self::fiscalYearOffset('contri.receive_date');
         $addWhere .= " AND {$this->_aliases['civicrm_contact']}.id NOT IN ( SELECT DISTINCT cont.id FROM civicrm_contact cont, civicrm_contribution contri WHERE  cont.id = contri.contact_id AND {$other_receive_date} = {$this->_referenceYear['other_year']} AND contri.is_test = 0 ) ";
     }
-    if (CRM_Utils_Array::value('this_year', $this->_referenceYear)) {
+    if (!empty($this->_referenceYear['this_year'])) {
         (CRM_Utils_Array::value('this_year_op', $this->_params) == 'calendar') ? $receive_date = 'YEAR (contri.receive_date)' : $receive_date = self::fiscalYearOffset('contri.receive_date');
         $addWhere .= " AND {$this->_aliases['civicrm_contact']}.id IN ( SELECT DISTINCT cont.id FROM civicrm_contact cont, civicrm_contribution contri WHERE cont.id = contri.contact_id AND {$receive_date} = {$this->_referenceYear['this_year']} AND contri.is_test = 0 ) ";
-    }  
+    }
     $this->limit();
     $getContacts = "SELECT SQL_CALC_FOUND_ROWS {$this->_aliases['civicrm_contact']}.id as cid, SUM({$this->_aliases['civicrm_contribution']}.total_amount) as civicrm_contribution_total_amount_sum {$this->_from} {$this->_where} {$addWhere} GROUP BY {$this->_aliases['civicrm_contact']}.id {$this->_having} {$this->_limit}";
-    
+
     $dao = CRM_Core_DAO::executeQuery($getContacts);
 
     while ($dao->fetch()) {
@@ -591,7 +591,7 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
         }
 
         foreach (array_keys($this->_relationshipColumns) as $col) {
-          if (CRM_Utils_Array::value($col, $relRow)) {
+          if (!empty($relRow[$col])) {
             $relatedRow[$col] = $relRow[$col];
           }
         }
@@ -683,16 +683,14 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
     $dao->free();
     return array($relationshipRows, $relatedContactIds);
   }
-  
+
   // Override "This Year" $op options
   function getOperationPair($type = "string", $fieldName = NULL) {
-      if ($fieldName == 'this_year' || $fieldName == 'other_year') {
-          return array('calendar' => ts('Is Calendar Year'), 'fiscal' => ts('Fiscal Year Starting'));
-      }
-      return parent::getOperationPair($type, $fieldName);
+    if ($fieldName == 'this_year' || $fieldName == 'other_year') {
+      return array('calendar' => ts('Is Calendar Year'), 'fiscal' => ts('Fiscal Year Starting'));
+    }
+    return parent::getOperationPair($type, $fieldName);
   }
-  
-  
 
   function alterDisplay(&$rows) {
     if (empty($rows)) {
@@ -727,9 +725,7 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
       }
 
       // Convert Display name into link
-      if (CRM_Utils_Array::value('civicrm_contact_sort_name', $row) &&
-        CRM_Utils_Array::value('civicrm_contact_id', $row)
-      ) {
+      if (!empty($row['civicrm_contact_sort_name']) && !empty($row['civicrm_contact_id'])) {
         $url = CRM_Report_Utils_Report::getNextUrl('contribute/detail',
           'reset=1&force=1&id_op=eq&id_value=' . $row['civicrm_contact_id'],
           $this->_absoluteUrl, $this->_id