Merge pull request #4822 from kurund/indentation-fixes
[civicrm-core.git] / CRM / Report / Form / Contribute / History.php
index 37a0e4e63e8db2158b8aa6610c13421de5a29812..fe9aa21ccc5a973fbe1d396736c64253ab111399 100644 (file)
@@ -2,7 +2,7 @@
 
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -57,11 +57,11 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
   /**
    *
    */
-  function __construct() {
+  public function __construct() {
     $yearsInPast = 4;
-    $date        = CRM_Core_SelectValues::date('custom', NULL, $yearsInPast, 0);
-    $count       = $date['maxYear'];
-    $optionYear  = array('' => ts('-- select --'));
+    $date = CRM_Core_SelectValues::date('custom', NULL, $yearsInPast, 0);
+    $count = $date['maxYear'];
+    $optionYear = array('' => ts('- select -'));
 
     $this->_yearStatisticsFrom = $date['minYear'];
     $this->_yearStatisticsTo = $date['maxYear'];
@@ -83,157 +83,135 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
     }
 
     $this->_columns = array(
-      'civicrm_contact' =>
-      array(
-        'dao' => 'CRM_Contact_DAO_Contact',
-        'fields' =>
-        array(
-          'sort_name' =>
-          array('title' => ts('Contact Name'),
-            'default' => TRUE,
-            'required' => TRUE,
-            'no_repeat' => TRUE,
+        'civicrm_contact' => array(
+          'dao' => 'CRM_Contact_DAO_Contact',
+          'fields' => array(
+            'sort_name' => array(
+              'title' => ts('Contact Name'),
+              'default' => TRUE,
+              'required' => TRUE,
+              'no_repeat' => TRUE,
+            ),
+            'id' => array(
+              'no_display' => TRUE,
+              'default' => TRUE,
+              'required' => TRUE,
+            ),
+            'contact_type' => array(
+              'title' => ts('Contact Type'),
+            ),
+            'contact_sub_type' => array(
+              'title' => ts('Contact Subtype'),
+            ),
           ),
-          'id' =>
-          array(
-            'no_display' => TRUE,
-            'default' => TRUE,
-            'required' => TRUE,
-          ),
-          'contact_type' =>
-          array(
-            'title' => ts('Contact Type'),
-          ),
-          'contact_sub_type' =>
-          array(
-            'title' => ts('Contact SubType'),
+          'grouping' => 'contact-fields',
+          'filters' => array(
+            'sort_name' => array('title' => ts('Contact Name')),
+            'id' => array(
+              'title' => ts('Contact ID'),
+              'no_display' => TRUE,
+            ),
           ),
         ),
-        'grouping' => 'contact-fields',
-        'filters' =>
-        array(
-          'sort_name' =>
-          array('title' => ts('Contact Name')),
-          'id' =>
-          array('title' => ts('Contact ID'),
-            'no_display' => TRUE,
+        'civicrm_email' => array(
+          'dao' => 'CRM_Core_DAO_Email',
+          'fields' => array(
+            'email' => array(
+              'title' => ts('Email'),
+              'no_repeat' => TRUE,
+            ),
           ),
+          'grouping' => 'contact-fields',
         ),
-      ),
-      'civicrm_email' =>
-      array(
-        'dao' => 'CRM_Core_DAO_Email',
-        'fields' =>
-        array(
-          'email' =>
-          array('title' => ts('Email'),
-            'no_repeat' => TRUE,
+        'civicrm_phone' => array(
+          'dao' => 'CRM_Core_DAO_Phone',
+          'fields' => array(
+            'phone' => array(
+              'title' => ts('Phone'),
+              'no_repeat' => TRUE,
+            ),
           ),
+          'grouping' => 'contact-fields',
         ),
-        'grouping' => 'contact-fields',
-      ),
-      'civicrm_phone' =>
-      array(
-        'dao' => 'CRM_Core_DAO_Phone',
-        'fields' =>
-        array(
-          'phone' =>
-          array('title' => ts('Phone'),
-            'no_repeat' => TRUE,
+      ) + $this->addAddressFields(FALSE, FALSE, FALSE, array()) + array(
+        'civicrm_relationship' => array(
+          'dao' => 'CRM_Contact_DAO_Relationship',
+          'fields' => array(
+            'relationship_type_id' => array(
+              'title' => ts('Relationship Type'),
+              'default' => TRUE,
+            ),
+            'contact_id_a' => array('no_display' => TRUE),
+            'contact_id_b' => array('no_display' => TRUE),
           ),
-        ),
-        'grouping' => 'contact-fields',
-      ),
-    ) + $this->addAddressFields(FALSE, FALSE, FALSE, array(
-      )) + array('civicrm_relationship' =>
-      array(
-        'dao' => 'CRM_Contact_DAO_Relationship',
-        'fields' =>
-        array(
-          'relationship_type_id' =>
-          array('title' => ts('Relationship Type'),
-            'default' => TRUE,
-          ),
-          'contact_id_a' =>
-          array('no_display' => TRUE),
-          'contact_id_b' =>
-          array('no_display' => TRUE),
-        ),
-        'filters' =>
-        array(
-          'relationship_type_id' =>
-          array('title' => ts('Relationship Type'),
-            'operatorType' => CRM_Report_Form::OP_MULTISELECT,
-            'options' => $relationTypeOp,
-            'type' => CRM_Utils_Type::T_STRING,
+          'filters' => array(
+            'relationship_type_id' => array(
+              'title' => ts('Relationship Type'),
+              'operatorType' => CRM_Report_Form::OP_MULTISELECT,
+              'options' => $relationTypeOp,
+              'type' => CRM_Utils_Type::T_STRING,
+            ),
           ),
         ),
-      ),
-    ) + array(
-      'civicrm_contribution' =>
-      array(
-        'dao' => 'CRM_Contribute_DAO_Contribution',
-        'fields' =>
-        array(
-          'total_amount' =>
-          array('title' => ts('Amount Statistics'),
-            'default' => TRUE,
-            'required' => TRUE,
-            'no_display' => TRUE,
-            'statistics' =>
-            array('sum' => ts('Aggregate Amount')),
+      ) + array(
+        'civicrm_contribution' => array(
+          'dao' => 'CRM_Contribute_DAO_Contribution',
+          'fields' => array(
+            'total_amount' => array(
+              'title' => ts('Amount Statistics'),
+              'default' => TRUE,
+              'required' => TRUE,
+              'no_display' => TRUE,
+              'statistics' => array('sum' => ts('Aggregate Amount')),
+            ),
+            'receive_date' => array(
+              'required' => TRUE,
+              'default' => TRUE,
+              'no_display' => TRUE,
+            ),
           ),
-          'receive_date' =>
-          array(
-            'required' => TRUE,
-            'default' => TRUE,
-            'no_display' => TRUE,
+          'grouping' => 'contri-fields',
+          'filters' => array(
+            'this_year' => array(
+              'title' => ts('This Year'),
+              'operatorType' => CRM_Report_Form::OP_SELECT,
+              'options' => $optionYear,
+              'default' => '',
+            ),
+            'other_year' => array(
+              'title' => ts('Other Years'),
+              'operatorType' => CRM_Report_Form::OP_SELECT,
+              'options' => $optionYear,
+              'default' => '',
+            ),
+            'receive_date' => array('operatorType' => CRM_Report_Form::OP_DATE),
+            'contribution_status_id' => array(
+              'title' => ts('Contribution Status'),
+              'operatorType' => CRM_Report_Form::OP_MULTISELECT,
+              'options' => CRM_Contribute_PseudoConstant::contributionStatus(),
+              'default' => array(1),
+            ),
+            'financial_type_id' => array(
+              'title' => ts('Financial Type'),
+              'operatorType' => CRM_Report_Form::OP_MULTISELECT,
+              'options' => CRM_Contribute_PseudoConstant::financialType(),
+            ),
+            'total_amount' => array(
+              'title' => ts('Contribution Amount'),
+            ),
+            'total_sum' => array(
+              'title' => ts('Aggregate Amount'),
+              'type' => CRM_Report_Form::OP_INT,
+              'dbAlias' => 'civicrm_contribution_total_amount_sum',
+              'having' => TRUE,
+            ),
           ),
         ),
-        'grouping' => 'contri-fields',
-        'filters' =>
-        array(
-          'this_year' =>
-          array(
-            'title' => ts('This Year'),
-            'operatorType' => CRM_Report_Form::OP_SELECT,
-            'options' => $optionYear,
-            'default' => '',
-          ),
-          'other_year' =>
-          array(
-            'title' => ts('Other Years'),
-            'operatorType' => CRM_Report_Form::OP_SELECT,
-            'options' => $optionYear,
-            'default' => '',
-          ),
-          'receive_date' =>
-          array('operatorType' => CRM_Report_Form::OP_DATE),
-          'contribution_status_id' =>
-          array('title' => ts('Donation Status'),
-            'operatorType' => CRM_Report_Form::OP_MULTISELECT,
-            'options' => CRM_Contribute_PseudoConstant::contributionStatus(),
-            'default' => array(1),
-          ),
-          'financial_type_id' => array(
-            'title' => ts('Financial Type'),
-            'operatorType' => CRM_Report_Form::OP_MULTISELECT,
-            'options' => CRM_Contribute_PseudoConstant::financialType(),
-          ),
-          'total_amount' =>
-          array('title' => ts('Donation Amount'),
-          ),
-          'total_sum' =>
-          array('title' => ts('Aggregate Amount'),
-            'type' => CRM_Report_Form::OP_INT,
-            'dbAlias' => 'civicrm_contribution_total_amount_sum',
-            'having' => TRUE,
-          ),
-        ),
-      ),
-    );
+      );
 
-    $this->_columns['civicrm_contribution']['fields']['civicrm_upto_' . $this->_yearStatisticsFrom] = array('title' => ts('Up To %1 Donation', array(1 => $this->_yearStatisticsFrom)),
+    $this->_columns['civicrm_contribution']['fields']['civicrm_upto_' .
+    $this->_yearStatisticsFrom] = array(
+      'title' => ts('Up To %1 Donation', array(1 => $this->_yearStatisticsFrom)),
       'default' => TRUE,
       'type' => CRM_Utils_Type::T_MONEY,
       'is_statistics' => TRUE,
@@ -242,7 +220,8 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
     $yearConter = $this->_yearStatisticsFrom;
     $yearConter++;
     while ($yearConter <= $this->_yearStatisticsTo) {
-      $this->_columns['civicrm_contribution']['fields'][$yearConter] = array('title' => ts('%1 Donation', array(1 => $yearConter)),
+      $this->_columns['civicrm_contribution']['fields'][$yearConter] = array(
+        'title' => ts('%1 Donation', array(1 => $yearConter)),
         'default' => TRUE,
         'type' => CRM_Utils_Type::T_MONEY,
         'is_statistics' => TRUE,
@@ -250,7 +229,8 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
       $yearConter++;
     }
 
-    $this->_columns['civicrm_contribution']['fields']['aggregate_amount'] = array('title' => ts('Aggregate Amount'),
+    $this->_columns['civicrm_contribution']['fields']['aggregate_amount'] = array(
+      'title' => ts('Aggregate Amount'),
       'type' => CRM_Utils_Type::T_MONEY,
       'is_statistics' => TRUE,
     );
@@ -260,11 +240,11 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
     parent::__construct();
   }
 
-  function preProcess() {
+  public function preProcess() {
     parent::preProcess();
   }
 
-  function select() {
+  public function select() {
     $select = array();
     $this->_columnHeaders = array();
 
@@ -272,7 +252,9 @@ class CRM_Report_Form_Contribute_History 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 (!empty($field['required']) ||
+            !empty($this->_params['fields'][$fieldName])
+          ) {
             if ($tableName == 'civicrm_address') {
               $this->_addressField = TRUE;
             }
@@ -295,12 +277,18 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
               continue;
             }
             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}";
-                }
+              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}";
@@ -321,7 +309,7 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
     $this->_select = "SELECT " . implode(', ', $select) . " ";
   }
 
-  function from() {
+  public function from() {
     $this->_from = "
         FROM civicrm_contact  {$this->_aliases['civicrm_contact']}
              INNER JOIN civicrm_contribution   {$this->_aliases['civicrm_contribution']}
@@ -353,7 +341,7 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
     }
   }
 
-  function where() {
+  public function where() {
     $whereClauses = $havingClauses = $relationshipWhere = array();
     $this->_relationshipWhere = '';
     $this->_statusClause = '';
@@ -364,10 +352,13 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
           $clause = NULL;
           if ($fieldName == 'this_year' || $fieldName == 'other_year') {
             continue;
-          }elseif (CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE) {
+          }
+          elseif (CRM_Utils_Array::value('type', $field) &
+            CRM_Utils_Type::T_DATE
+          ) {
             $relative = CRM_Utils_Array::value("{$fieldName}_relative", $this->_params);
-            $from     = CRM_Utils_Array::value("{$fieldName}_from", $this->_params);
-            $to       = CRM_Utils_Array::value("{$fieldName}_to", $this->_params);
+            $from = CRM_Utils_Array::value("{$fieldName}_from", $this->_params);
+            $to = CRM_Utils_Array::value("{$fieldName}_to", $this->_params);
 
             $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
           }
@@ -422,11 +413,12 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
     }
 
     if (!empty($relationshipWhere)) {
-      $this->_relationshipWhere = ' AND ' . implode(' AND ', $relationshipWhere);
+      $this->_relationshipWhere = ' AND ' .
+        implode(' AND ', $relationshipWhere);
     }
   }
 
-  function groupBy() {
+  public function groupBy() {
     $this->_groupBy = "GROUP BY {$this->_aliases['civicrm_contribution']}.contact_id, YEAR({$this->_aliases['civicrm_contribution']}.receive_date)";
   }
 
@@ -434,7 +426,7 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
   /**
    * @param int $rowCount
    */
-  function limit($rowCount = self::ROW_COUNT_LIMIT) {
+  public function limit($rowCount = self::ROW_COUNT_LIMIT) {
     parent::limit($rowCount);
   }
 
@@ -442,7 +434,7 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
   /**
    * @param int $rowCount
    */
-  function setPager($rowCount = self::ROW_COUNT_LIMIT) {
+  public function setPager($rowCount = self::ROW_COUNT_LIMIT) {
     parent::setPager($rowCount);
   }
 
@@ -451,7 +443,7 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
    *
    * @return array
    */
-  function statistics(&$rows) {
+  public function statistics(&$rows) {
     $statistics = parent::statistics($rows);
     $count = 0;
     foreach ($rows as $rownum => $row) {
@@ -459,12 +451,14 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
         $count++;
       }
     }
-    $statistics['counts']['rowCount'] = array('title' => ts('Primary Contact(s) Listed'),
+    $statistics['counts']['rowCount'] = array(
+      'title' => ts('Primary Contact(s) Listed'),
       'value' => $count,
     );
 
     if ($this->_rowsFound && ($this->_rowsFound > $count)) {
-      $statistics['counts']['rowsFound'] = array('title' => ts('Total Primary Contact(s)'),
+      $statistics['counts']['rowsFound'] = array(
+        'title' => ts('Total Primary Contact(s)'),
         'value' => $this->_rowsFound,
       );
     }
@@ -479,9 +473,10 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
    *
    * @return array
    */
-  static function formRule($fields, $files, $self) {
+  public static function formRule($fields, $files, $self) {
     $errors = array();
-    if (!empty($fields['this_year_value']) && !empty($fields['other_year_value']) &&
+    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.");
@@ -489,7 +484,7 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
     return $errors;
   }
 
-  function postProcess() {
+  public function postProcess() {
     // get ready with post process params
     $this->beginPostProcess();
     $this->fixReportParams();
@@ -501,11 +496,12 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
     $this->customDataFrom();
     $this->groupBy();
 
+    $sql = NULL;
     $rows = array();
 
     // build array of result based on column headers. This method also allows
     // modifying column headers before using it to build result set i.e $rows.
-    $this->buildRows($rows);
+    $this->buildRows($sql, $rows);
 
     // format result set.
     $this->formatDisplay($rows, FALSE);
@@ -517,7 +513,7 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
     $this->endPostProcess($rows);
   }
 
-  function fixReportParams() {
+  public function fixReportParams() {
     if (!empty($this->_params['this_year_value'])) {
       $this->_referenceYear['this_year'] = $this->_params['this_year_value'];
     }
@@ -529,18 +525,20 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
   /**
    * @param $rows
    */
-  function buildRows(&$rows) {
+  public function buildRows($sql, &$rows) {
     $contactIds = array();
 
     $addWhere = '';
 
     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 ) ";
+      (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 (!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 ) ";
+      (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}";
@@ -569,9 +567,9 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
 
     $relatedContributions = $this->buildContributionRows($relatedContactIds);
 
-    $summaryYears   = array();
+    $summaryYears = array();
     $summaryYears[] = "civicrm_upto_{$this->_yearStatisticsFrom}";
-    $yearConter     = $this->_yearStatisticsFrom;
+    $yearConter = $this->_yearStatisticsFrom;
     $yearConter++;
     while ($yearConter <= $this->_yearStatisticsTo) {
       $summaryYears[] = $yearConter;
@@ -622,17 +620,20 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
    *
    * @return array
    */
-  function buildContributionRows($contactIds) {
+  public function buildContributionRows($contactIds) {
     $rows = array();
     if (empty($contactIds)) {
       return $rows;
     }
 
-    $sqlContribution = "{$this->_select} {$this->_from} WHERE {$this->_aliases['civicrm_contact']}.id IN (" . implode(',', $contactIds) . ") AND {$this->_aliases['civicrm_contribution']}.is_test = 0 {$this->_statusClause} {$this->_groupBy} ";
+    $sqlContribution =
+      "{$this->_select} {$this->_from} WHERE {$this->_aliases['civicrm_contact']}.id IN (" .
+      implode(',', $contactIds) .
+      ") AND {$this->_aliases['civicrm_contribution']}.is_test = 0 {$this->_statusClause} {$this->_groupBy} ";
 
-    $dao             = CRM_Core_DAO::executeQuery($sqlContribution);
+    $dao = CRM_Core_DAO::executeQuery($sqlContribution);
     $contributionSum = 0;
-    $yearcal         = array();
+    $yearcal = array();
     while ($dao->fetch()) {
       if (!$dao->civicrm_contact_id) {
         continue;
@@ -644,7 +645,9 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
         }
       }
       if ($dao->civicrm_contribution_receive_date) {
-        if ($dao->civicrm_contribution_receive_date > $this->_yearStatisticsFrom) {
+        if ($dao->civicrm_contribution_receive_date >
+          $this->_yearStatisticsFrom
+        ) {
           $rows[$dao->civicrm_contact_id][$dao->civicrm_contribution_receive_date] = $dao->civicrm_contribution_total_amount;
         }
         else {
@@ -670,7 +673,7 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
    *
    * @return array
    */
-  function buildRelationshipRows($contactIds) {
+  public function buildRelationshipRows($contactIds) {
     $relationshipRows = $relatedContactIds = array();
     if (empty($contactIds)) {
       return array($relationshipRows, $relatedContactIds);
@@ -681,7 +684,10 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
     if (!empty($this->_relationshipColumns)) {
       $addRelSelect = ', ' . implode(', ', $this->_relationshipColumns);
     }
-    $sqlRelationship = "SELECT {$this->_aliases['civicrm_relationship']}.relationship_type_id as relationship_type_id, {$this->_aliases['civicrm_relationship']}.contact_id_a as contact_id_a, {$this->_aliases['civicrm_relationship']}.contact_id_b as contact_id_b {$addRelSelect} FROM civicrm_contact {$relContactAlias} {$this->_relationshipFrom} WHERE {$relContactAlias}.id IN (" . implode(',', $contactIds) . ") AND {$this->_aliases['civicrm_relationship']}.is_active = 1 {$this->_relationshipWhere} GROUP BY {$this->_aliases['civicrm_relationship']}.contact_id_a, {$this->_aliases['civicrm_relationship']}.contact_id_b";
+    $sqlRelationship =
+      "SELECT {$this->_aliases['civicrm_relationship']}.relationship_type_id as relationship_type_id, {$this->_aliases['civicrm_relationship']}.contact_id_a as contact_id_a, {$this->_aliases['civicrm_relationship']}.contact_id_b as contact_id_b {$addRelSelect} FROM civicrm_contact {$relContactAlias} {$this->_relationshipFrom} WHERE {$relContactAlias}.id IN (" .
+      implode(',', $contactIds) .
+      ") AND {$this->_aliases['civicrm_relationship']}.is_active = 1 {$this->_relationshipWhere} GROUP BY {$this->_aliases['civicrm_relationship']}.contact_id_a, {$this->_aliases['civicrm_relationship']}.contact_id_b";
     $relationshipTypes = CRM_Core_PseudoConstant::relationshipType();
 
     $dao = CRM_Core_DAO::executeQuery($sqlRelationship);
@@ -714,9 +720,12 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
    *
    * @return array
    */
-  function getOperationPair($type = "string", $fieldName = NULL) {
+  public 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 array(
+        'calendar' => ts('Is Calendar Year'),
+        'fiscal' => ts('Fiscal Year Starting')
+      );
     }
     return parent::getOperationPair($type, $fieldName);
   }
@@ -724,7 +733,7 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
   /**
    * @param $rows
    */
-  function alterDisplay(&$rows) {
+  public function alterDisplay(&$rows) {
     if (empty($rows)) {
       return;
     }
@@ -757,7 +766,9 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
       }
 
       // Convert Display name into link
-      if (!empty($row['civicrm_contact_sort_name']) && !empty($row['civicrm_contact_id'])) {
+      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
@@ -767,5 +778,4 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
       }
     }
   }
- }
-
+}