4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.5 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2014 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
32 * @copyright CiviCRM LLC (c) 2004-2014
36 class CRM_Report_Form_Contribute_PCP
extends CRM_Report_Form
{
43 function __construct() {
44 $this->_columns
= array(
47 'dao' => 'CRM_Contact_DAO_Contact',
51 array('title' => ts('Supporter'),
62 'title' => ts('Supporter Contact Type'),
66 'title' => ts('Supporter Contact SubType'),
72 array('title' => ts('Supporter Name'),
73 'type' => CRM_Utils_Type
::T_STRING
,
77 array('title' => ts('Contact ID'),
81 'grouping' => 'pcp-fields',
83 'civicrm_contribution_page' =>
85 'dao' => 'CRM_Contribute_DAO_ContributionPage',
89 array('title' => ts('Contribution Page Title'),
97 array('title' => ts('Contribution Page Title'),
99 'type' => CRM_Utils_Type
::T_STRING
,
102 'grouping' => 'pcp-fields',
106 'dao' => 'CRM_PCP_DAO_PCP',
110 array('title' => ts('Personal Campaign Title'),
114 array('title' => ts('Goal Amount'),
115 'type' => CRM_Utils_Type
::T_MONEY
,
122 array('title' => ts('Personal Campaign Title'),
123 'type' => CRM_Utils_Type
::T_STRING
,
126 'grouping' => 'pcp-fields',
128 'civicrm_contribution_soft' =>
130 'dao' => 'CRM_Contribute_DAO_ContributionSoft',
134 array('title' => ts('Committed Amount'),
136 'type' => CRM_Utils_Type
::T_MONEY
,
139 array('sum' => ts('Committed Amount'),
143 array('title' => ts('Amount Received'),
145 'type' => CRM_Utils_Type
::T_MONEY
,
147 // nice trick with dbAlias
148 'dbAlias' => 'SUM(IF( contribution_civireport.contribution_status_id > 1, 0, contribution_soft_civireport.amount))',
151 array('title' => ts('Number of Donors'),
155 array('count' => ts('Number of Donors'),
162 array('title' => ts('Amount Received'),
163 'type' => CRM_Utils_Type
::T_MONEY
,
164 'dbAlias' => 'SUM(IF( contribution_civireport.contribution_status_id > 1, 0, contribution_soft_civireport.amount))',
167 'grouping' => 'pcp-fields',
169 'civicrm_contribution' =>
171 'dao' => 'CRM_Contribute_DAO_Contribution',
177 'no_display' => TRUE,
181 array('title' => ts('Most Recent Donation'),
184 array('max' => ts('Most Recent Donation'),
188 'grouping' => 'pcp-fields',
192 parent
::__construct();
197 FROM civicrm_pcp {$this->_aliases['civicrm_pcp']}
199 LEFT JOIN civicrm_contribution_soft {$this->_aliases['civicrm_contribution_soft']}
200 ON {$this->_aliases['civicrm_pcp']}.id =
201 {$this->_aliases['civicrm_contribution_soft']}.pcp_id
203 LEFT JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']}
204 ON {$this->_aliases['civicrm_contribution_soft']}.contribution_id =
205 {$this->_aliases['civicrm_contribution']}.id
207 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
208 ON {$this->_aliases['civicrm_pcp']}.contact_id =
209 {$this->_aliases['civicrm_contact']}.id
211 LEFT JOIN civicrm_contribution_page {$this->_aliases['civicrm_contribution_page']}
212 ON {$this->_aliases['civicrm_pcp']}.page_id =
213 {$this->_aliases['civicrm_contribution_page']}.id";
217 $this->_groupBy
= "GROUP BY {$this->_aliases['civicrm_pcp']}.id";
221 $this->_orderBy
= " ORDER BY {$this->_aliases['civicrm_contact']}.sort_name ";
225 $whereClauses = $havingClauses = array();
227 foreach ($this->_columns
as $tableName => $table) {
228 if (array_key_exists('filters', $table)) {
229 foreach ($table['filters'] as $fieldName => $field) {
232 if (CRM_Utils_Array
::value('type', $field) & CRM_Utils_Type
::T_DATE
) {
233 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
234 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
235 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
236 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
239 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
242 $clause = $this->whereClause($field,
244 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
245 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
246 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
251 if (!empty($clause)) {
252 if ($tableName == 'civicrm_contribution_soft' &&
253 $fieldName == 'amount_2'
255 $havingClauses[] = $clause;
258 $whereClauses[] = $clause;
264 if (empty($whereClauses)) {
265 $this->_where
= "WHERE ( 1 ) ";
268 $this->_where
= "WHERE " . implode(' AND ', $whereClauses);
270 if ($this->_aclWhere
) {
271 $this->_where
.= " AND {$this->_aclWhere} ";
274 if (!empty($havingClauses)) {
275 // use this clause to construct group by clause.
276 $this->_having
= "HAVING " . implode(' AND ', $havingClauses);
285 function statistics(&$rows) {
286 $statistics = parent
::statistics($rows);
288 $select = "SELECT SUM({$this->_aliases['civicrm_pcp']}.goal_amount) as goal_total, ".
289 "SUM({$this->_aliases['civicrm_contribution_soft']}.amount) as committed_total, ".
290 "COUNT({$this->_aliases['civicrm_contribution_soft']}.id) as donors_total, ".
291 "SUM(IF( contribution_civireport.contribution_status_id > 1, 0, contribution_soft_civireport.amount)) AS received_total ";
292 $sql = "{$select} {$this->_from} {$this->_where}";
293 $dao = CRM_Core_DAO
::executeQuery($sql);
295 $statistics['counts']['goal_total'] = array(
296 'title' => ts('Goal Total'),
297 'value' => $dao->goal_total
,
298 'type' => CRM_Utils_Type
::T_MONEY
300 $statistics['counts']['committed_total'] = array(
301 'title' => ts('Total Committed'),
302 'value' => $dao->committed_total
,
303 'type' => CRM_Utils_Type
::T_MONEY
305 $statistics['counts']['received_total'] = array(
306 'title' => ts('Total Received'),
307 'value' => $dao->received_total
,
308 'type' => CRM_Utils_Type
::T_MONEY
310 $statistics['counts']['donors_total'] = array(
311 'title' => ts('Total Donors'),
312 'value' => $dao->donors_total
,
313 'type' => CRM_Utils_Type
::T_INT
321 function alterDisplay(&$rows) {
322 // custom code to alter rows
324 $checkList = array();
325 foreach ($rows as $rowNum => $row) {
326 if (!empty($this->_noRepeats
) && $this->_outputMode
!= 'csv') {
327 // not repeat contact sort names if it matches with the one
329 $repeatFound = FALSE;
331 foreach ($row as $colName => $colVal) {
332 if (!empty($checkList[$colName]) &&
333 is_array($checkList[$colName]) &&
334 in_array($colVal, $checkList[$colName])
336 $rows[$rowNum][$colName] = "";
339 if (in_array($colName, $this->_noRepeats
)) {
340 $checkList[$colName][] = $colVal;
345 if (array_key_exists('civicrm_contact_sort_name', $row) &&
346 $rows[$rowNum]['civicrm_contact_sort_name'] &&
347 array_key_exists('civicrm_contact_id', $row)
349 $url = CRM_Utils_System
::url("civicrm/contact/view",
350 'reset=1&cid=' . $row['civicrm_contact_id'],
353 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
354 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact Summary for this Contact.");