4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.6 |
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 public function __construct() {
44 $this->_columns
= array(
45 'civicrm_contact' => array(
46 'dao' => 'CRM_Contact_DAO_Contact',
49 'title' => ts('Supporter'),
57 'contact_type' => array(
58 'title' => ts('Supporter Contact Type'),
60 'contact_sub_type' => array(
61 'title' => ts('Supporter Contact Subtype'),
66 'title' => ts('Supporter Name'),
67 'type' => CRM_Utils_Type
::T_STRING
,
71 'title' => ts('Contact ID'),
75 'grouping' => 'pcp-fields',
77 'civicrm_contribution_page' => array(
78 'dao' => 'CRM_Contribute_DAO_ContributionPage',
80 'page_title' => array(
81 'title' => ts('Contribution Page Title'),
87 'page_title' => array(
88 'title' => ts('Contribution Page Title'),
90 'type' => CRM_Utils_Type
::T_STRING
,
93 'grouping' => 'pcp-fields',
95 'civicrm_pcp' => array(
96 'dao' => 'CRM_PCP_DAO_PCP',
99 'title' => ts('Personal Campaign Title'),
102 'goal_amount' => array(
103 'title' => ts('Goal Amount'),
104 'type' => CRM_Utils_Type
::T_MONEY
,
110 'title' => ts('Personal Campaign Title'),
111 'type' => CRM_Utils_Type
::T_STRING
,
114 'grouping' => 'pcp-fields',
116 'civicrm_contribution_soft' => array(
117 'dao' => 'CRM_Contribute_DAO_ContributionSoft',
120 'title' => ts('Committed Amount'),
122 'type' => CRM_Utils_Type
::T_MONEY
,
124 'statistics' => array(
125 'sum' => ts('Committed Amount'),
129 'title' => ts('Amount Received'),
131 'type' => CRM_Utils_Type
::T_MONEY
,
133 // nice trick with dbAlias
134 'dbAlias' => 'SUM(IF( contribution_civireport.contribution_status_id > 1, 0, contribution_soft_civireport.amount))',
137 'title' => ts('Number of Donors'),
140 'statistics' => array(
141 'count' => ts('Number of Donors'),
147 'title' => ts('Amount Received'),
148 'type' => CRM_Utils_Type
::T_MONEY
,
149 'dbAlias' => 'SUM(IF( contribution_civireport.contribution_status_id > 1, 0, contribution_soft_civireport.amount))',
152 'grouping' => 'pcp-fields',
154 'civicrm_contribution' => array(
155 'dao' => 'CRM_Contribute_DAO_Contribution',
157 'contribution_id' => array(
159 'no_display' => TRUE,
162 'receive_date' => array(
163 'title' => ts('Most Recent Contribution'),
165 'statistics' => array(
166 'max' => ts('Most Recent Contribution'),
170 'grouping' => 'pcp-fields',
174 parent
::__construct();
177 public function from() {
179 FROM civicrm_pcp {$this->_aliases['civicrm_pcp']}
181 LEFT JOIN civicrm_contribution_soft {$this->_aliases['civicrm_contribution_soft']}
182 ON {$this->_aliases['civicrm_pcp']}.id =
183 {$this->_aliases['civicrm_contribution_soft']}.pcp_id
185 LEFT JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']}
186 ON {$this->_aliases['civicrm_contribution_soft']}.contribution_id =
187 {$this->_aliases['civicrm_contribution']}.id
189 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
190 ON {$this->_aliases['civicrm_pcp']}.contact_id =
191 {$this->_aliases['civicrm_contact']}.id
193 LEFT JOIN civicrm_contribution_page {$this->_aliases['civicrm_contribution_page']}
194 ON {$this->_aliases['civicrm_pcp']}.page_id =
195 {$this->_aliases['civicrm_contribution_page']}.id";
198 public function groupBy() {
199 $this->_groupBy
= "GROUP BY {$this->_aliases['civicrm_pcp']}.id";
202 public function orderBy() {
203 $this->_orderBy
= " ORDER BY {$this->_aliases['civicrm_contact']}.sort_name ";
206 public function where() {
207 $whereClauses = $havingClauses = array();
209 foreach ($this->_columns
as $tableName => $table) {
210 if (array_key_exists('filters', $table)) {
211 foreach ($table['filters'] as $fieldName => $field) {
214 if (CRM_Utils_Array
::value('type', $field) & CRM_Utils_Type
::T_DATE
) {
215 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
216 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
217 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
218 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
221 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
224 $clause = $this->whereClause($field,
226 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
227 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
228 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
233 if (!empty($clause)) {
234 if ($tableName == 'civicrm_contribution_soft' &&
235 $fieldName == 'amount_2'
237 $havingClauses[] = $clause;
240 $whereClauses[] = $clause;
246 if (empty($whereClauses)) {
247 $this->_where
= "WHERE ( 1 ) ";
250 $this->_where
= "WHERE " . implode(' AND ', $whereClauses);
252 if ($this->_aclWhere
) {
253 $this->_where
.= " AND {$this->_aclWhere} ";
256 if (!empty($havingClauses)) {
257 // use this clause to construct group by clause.
258 $this->_having
= "HAVING " . implode(' AND ', $havingClauses);
267 public function statistics(&$rows) {
268 $statistics = parent
::statistics($rows);
271 "SELECT SUM({$this->_aliases['civicrm_pcp']}.goal_amount) as goal_total, " .
272 "SUM({$this->_aliases['civicrm_contribution_soft']}.amount) as committed_total, " .
273 "COUNT({$this->_aliases['civicrm_contribution_soft']}.id) as donors_total, " .
274 "SUM(IF( contribution_civireport.contribution_status_id > 1, 0, contribution_soft_civireport.amount)) AS received_total ";
275 $sql = "{$select} {$this->_from} {$this->_where}";
276 $dao = CRM_Core_DAO
::executeQuery($sql);
278 $statistics['counts']['goal_total'] = array(
279 'title' => ts('Goal Total'),
280 'value' => $dao->goal_total
,
281 'type' => CRM_Utils_Type
::T_MONEY
283 $statistics['counts']['committed_total'] = array(
284 'title' => ts('Total Committed'),
285 'value' => $dao->committed_total
,
286 'type' => CRM_Utils_Type
::T_MONEY
288 $statistics['counts']['received_total'] = array(
289 'title' => ts('Total Received'),
290 'value' => $dao->received_total
,
291 'type' => CRM_Utils_Type
::T_MONEY
293 $statistics['counts']['donors_total'] = array(
294 'title' => ts('Total Donors'),
295 'value' => $dao->donors_total
,
296 'type' => CRM_Utils_Type
::T_INT
304 public function alterDisplay(&$rows) {
305 // custom code to alter rows
307 $checkList = array();
308 foreach ($rows as $rowNum => $row) {
309 if (!empty($this->_noRepeats
) && $this->_outputMode
!= 'csv') {
310 // not repeat contact sort names if it matches with the one
312 $repeatFound = FALSE;
314 foreach ($row as $colName => $colVal) {
315 if (!empty($checkList[$colName]) &&
316 is_array($checkList[$colName]) &&
317 in_array($colVal, $checkList[$colName])
319 $rows[$rowNum][$colName] = "";
322 if (in_array($colName, $this->_noRepeats
)) {
323 $checkList[$colName][] = $colVal;
328 if (array_key_exists('civicrm_contact_sort_name', $row) &&
329 $rows[$rowNum]['civicrm_contact_sort_name'] &&
330 array_key_exists('civicrm_contact_id', $row)
332 $url = CRM_Utils_System
::url("civicrm/contact/view",
333 'reset=1&cid=' . $row['civicrm_contact_id'],
336 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
337 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact Summary for this Contact.");