public function statistics(&$rows) {
$statistics = parent::statistics($rows);
+ // Calculate totals from the civicrm_contribution_soft table.
$select
- = "SELECT SUM({$this->_aliases['civicrm_pcp']}.goal_amount) as goal_total, " .
- "SUM({$this->_aliases['civicrm_contribution_soft']}.amount) as committed_total, " .
+ = "SELECT SUM({$this->_aliases['civicrm_contribution_soft']}.amount) as committed_total, " .
"COUNT({$this->_aliases['civicrm_contribution_soft']}.id) as donors_total, " .
"SUM(IF( contribution_civireport.contribution_status_id > 1, 0, contribution_soft_civireport.amount)) AS received_total ";
$sql = "{$select} {$this->_from} {$this->_where}";
$dao = CRM_Core_DAO::executeQuery($sql);
$dao->fetch();
+ $committed_total = $dao->committed_total;
+ $received_total = $dao->received_total;
+ $donors_total = $dao->donors_total;
+
+ // Calculate goal total goal from the PCP table (we only want one result per
+ // PCP page - the query above produces one result per contribution made).
+ $sql =
+ "SELECT SUM(goal_amount) as goal_total FROM civicrm_pcp WHERE ".
+ "goal_amount IS NOT NULL AND id IN (" .
+ "SELECT DISTINCT {$this->_aliases['civicrm_pcp']}.id {$this->_from} ".
+ "{$this->_where}".
+ ")";
+ $dao = CRM_Core_DAO::executeQuery($sql);
+ $dao->fetch();
+ $goal_total = $dao->goal_total;
+
$statistics['counts']['goal_total'] = array(
'title' => ts('Goal Total'),
- 'value' => $dao->goal_total,
+ 'value' => $goal_total,
'type' => CRM_Utils_Type::T_MONEY,
);
$statistics['counts']['committed_total'] = array(
'title' => ts('Total Committed'),
- 'value' => $dao->committed_total,
+ 'value' => $committed_total,
'type' => CRM_Utils_Type::T_MONEY,
);
$statistics['counts']['received_total'] = array(
'title' => ts('Total Received'),
- 'value' => $dao->received_total,
+ 'value' => $received_total,
'type' => CRM_Utils_Type::T_MONEY,
);
$statistics['counts']['donors_total'] = array(
'title' => ts('Total Donors'),
- 'value' => $dao->donors_total,
+ 'value' => $donors_total,
'type' => CRM_Utils_Type::T_INT,
);
return $statistics;