4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.4 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
36 class CRM_Report_Form_Contribute_PCP
extends CRM_Report_Form
{
37 function __construct() {
38 $this->_columns
= array(
41 'dao' => 'CRM_Contact_DAO_Contact',
45 array('title' => ts('Supporter'),
56 'title' => ts('Supporter Contact Type'),
60 'title' => ts('Supporter Contact SubType'),
66 array('title' => ts('Supporter Name'),
67 'type' => CRM_Utils_Type
::T_STRING
,
71 array('title' => ts('Contact ID'),
75 'grouping' => 'pcp-fields',
77 'civicrm_contribution_page' =>
79 'dao' => 'CRM_Contribute_DAO_ContributionPage',
83 array('title' => ts('Contribution Page Title'),
91 array('title' => ts('Contribution Page Title'),
93 'type' => CRM_Utils_Type
::T_STRING
,
96 'grouping' => 'pcp-fields',
100 'dao' => 'CRM_PCP_DAO_PCP',
104 array('title' => ts('Personal Campaign Title'),
108 array('title' => ts('Goal Amount'),
109 'type' => CRM_Utils_Type
::T_MONEY
,
116 array('title' => ts('Personal Campaign Title'),
117 'type' => CRM_Utils_Type
::T_STRING
,
120 'grouping' => 'pcp-fields',
122 'civicrm_contribution_soft' =>
124 'dao' => 'CRM_Contribute_DAO_ContributionSoft',
128 array('title' => ts('Committed Amount'),
130 'type' => CRM_Utils_Type
::T_MONEY
,
133 array('sum' => ts('Committed Amount'),
137 array('title' => ts('Amount Received'),
139 'type' => CRM_Utils_Type
::T_MONEY
,
141 // nice trick with dbAlias
142 'dbAlias' => 'SUM(IF( contribution_civireport.contribution_status_id > 1, 0, contribution_soft_civireport.amount))',
145 array('title' => ts('Number of Donors'),
149 array('count' => ts('Number of Donors'),
156 array('title' => ts('Amount Received'),
157 'type' => CRM_Utils_Type
::T_MONEY
,
158 'dbAlias' => 'SUM(IF( contribution_civireport.contribution_status_id > 1, 0, contribution_soft_civireport.amount))',
161 'grouping' => 'pcp-fields',
163 'civicrm_contribution' =>
165 'dao' => 'CRM_Contribute_DAO_Contribution',
171 'no_display' => TRUE,
175 array('title' => ts('Most Recent Donation'),
178 array('max' => ts('Most Recent Donation'),
182 'grouping' => 'pcp-fields',
186 parent
::__construct();
191 FROM civicrm_pcp {$this->_aliases['civicrm_pcp']}
193 LEFT JOIN civicrm_contribution_soft {$this->_aliases['civicrm_contribution_soft']}
194 ON {$this->_aliases['civicrm_pcp']}.id =
195 {$this->_aliases['civicrm_contribution_soft']}.pcp_id
197 LEFT JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']}
198 ON {$this->_aliases['civicrm_contribution_soft']}.contribution_id =
199 {$this->_aliases['civicrm_contribution']}.id
201 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
202 ON {$this->_aliases['civicrm_pcp']}.contact_id =
203 {$this->_aliases['civicrm_contact']}.id
205 LEFT JOIN civicrm_contribution_page {$this->_aliases['civicrm_contribution_page']}
206 ON {$this->_aliases['civicrm_pcp']}.page_id =
207 {$this->_aliases['civicrm_contribution_page']}.id";
211 $this->_groupBy
= "GROUP BY {$this->_aliases['civicrm_pcp']}.id";
215 $this->_orderBy
= " ORDER BY {$this->_aliases['civicrm_contact']}.sort_name ";
219 $whereClauses = $havingClauses = array();
221 foreach ($this->_columns
as $tableName => $table) {
222 if (array_key_exists('filters', $table)) {
223 foreach ($table['filters'] as $fieldName => $field) {
226 if (CRM_Utils_Array
::value('type', $field) & CRM_Utils_Type
::T_DATE
) {
227 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
228 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
229 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
230 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
233 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
236 $clause = $this->whereClause($field,
238 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
239 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
240 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
245 if (!empty($clause)) {
246 if ($tableName == 'civicrm_contribution_soft' &&
247 $fieldName == 'amount_2'
249 $havingClauses[] = $clause;
252 $whereClauses[] = $clause;
258 if (empty($whereClauses)) {
259 $this->_where
= "WHERE ( 1 ) ";
262 $this->_where
= "WHERE " . implode(' AND ', $whereClauses);
264 if ($this->_aclWhere
) {
265 $this->_where
.= " AND {$this->_aclWhere} ";
268 if (!empty($havingClauses)) {
269 // use this clause to construct group by clause.
270 $this->_having
= "HAVING " . implode(' AND ', $havingClauses);
274 function statistics(&$rows) {
275 $statistics = parent
::statistics($rows);
277 $select = "SELECT SUM({$this->_aliases['civicrm_pcp']}.goal_amount) as goal_total, ".
278 "SUM({$this->_aliases['civicrm_contribution_soft']}.amount) as committed_total, ".
279 "COUNT({$this->_aliases['civicrm_contribution_soft']}.id) as donors_total, ".
280 "SUM(IF( contribution_civireport.contribution_status_id > 1, 0, contribution_soft_civireport.amount)) AS received_total ";
281 $sql = "{$select} {$this->_from} {$this->_where}";
282 $dao = CRM_Core_DAO
::executeQuery($sql);
284 $statistics['counts']['goal_total'] = array(
285 'title' => ts('Goal Total'),
286 'value' => $dao->goal_total
,
287 'type' => CRM_Utils_Type
::T_MONEY
289 $statistics['counts']['committed_total'] = array(
290 'title' => ts('Total Committed'),
291 'value' => $dao->committed_total
,
292 'type' => CRM_Utils_Type
::T_MONEY
294 $statistics['counts']['received_total'] = array(
295 'title' => ts('Total Received'),
296 'value' => $dao->received_total
,
297 'type' => CRM_Utils_Type
::T_MONEY
299 $statistics['counts']['donors_total'] = array(
300 'title' => ts('Total Donors'),
301 'value' => $dao->donors_total
,
302 'type' => CRM_Utils_Type
::T_INT
306 function alterDisplay(&$rows) {
307 // custom code to alter rows
309 $checkList = array();
310 foreach ($rows as $rowNum => $row) {
311 if (!empty($this->_noRepeats
) && $this->_outputMode
!= 'csv') {
312 // not repeat contact sort names if it matches with the one
314 $repeatFound = FALSE;
316 foreach ($row as $colName => $colVal) {
317 if (!empty($checkList[$colName]) &&
318 is_array($checkList[$colName]) &&
319 in_array($colVal, $checkList[$colName])
321 $rows[$rowNum][$colName] = "";
324 if (in_array($colName, $this->_noRepeats
)) {
325 $checkList[$colName][] = $colVal;
330 if (array_key_exists('civicrm_contact_sort_name', $row) &&
331 $rows[$rowNum]['civicrm_contact_sort_name'] &&
332 array_key_exists('civicrm_contact_id', $row)
334 $url = CRM_Utils_System
::url("civicrm/contact/view",
335 'reset=1&cid=' . $row['civicrm_contact_id'],
338 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
339 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact Summary for this Contact.");