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'),
58 array('title' => ts('Supporter Name'),
59 'type' => CRM_Utils_Type
::T_STRING
,
63 array('title' => ts('Contact ID'),
67 'grouping' => 'pcp-fields',
69 'civicrm_contribution_page' =>
71 'dao' => 'CRM_Contribute_DAO_ContributionPage',
75 array('title' => ts('Contribution Page Title'),
83 array('title' => ts('Contribution Page Title'),
85 'type' => CRM_Utils_Type
::T_STRING
,
88 'grouping' => 'pcp-fields',
92 'dao' => 'CRM_PCP_DAO_PCP',
96 array('title' => ts('Personal Campaign Title'),
100 array('title' => ts('Goal Amount'),
101 'type' => CRM_Utils_Type
::T_MONEY
,
108 array('title' => ts('Personal Campaign Title'),
109 'type' => CRM_Utils_Type
::T_STRING
,
112 'grouping' => 'pcp-fields',
114 'civicrm_contribution_soft' =>
116 'dao' => 'CRM_Contribute_DAO_ContributionSoft',
120 array('title' => ts('Committed Amount'),
122 'type' => CRM_Utils_Type
::T_MONEY
,
125 array('sum' => ts('Committed Amount'),
129 array('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 array('title' => ts('Number of Donors'),
141 array('count' => ts('Number of Donors'),
148 array('title' => ts('Amount Received'),
149 'type' => CRM_Utils_Type
::T_MONEY
,
150 'dbAlias' => 'SUM(IF( contribution_civireport.contribution_status_id > 1, 0, contribution_soft_civireport.amount))',
153 'grouping' => 'pcp-fields',
155 'civicrm_contribution' =>
157 'dao' => 'CRM_Contribute_DAO_Contribution',
163 'no_display' => TRUE,
167 array('title' => ts('Most Recent Donation'),
170 array('max' => ts('Most Recent Donation'),
174 'grouping' => 'pcp-fields',
178 parent
::__construct();
183 FROM civicrm_pcp {$this->_aliases['civicrm_pcp']}
185 LEFT JOIN civicrm_contribution_soft {$this->_aliases['civicrm_contribution_soft']}
186 ON {$this->_aliases['civicrm_pcp']}.id =
187 {$this->_aliases['civicrm_contribution_soft']}.pcp_id
189 LEFT JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']}
190 ON {$this->_aliases['civicrm_contribution_soft']}.contribution_id =
191 {$this->_aliases['civicrm_contribution']}.id
193 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
194 ON {$this->_aliases['civicrm_pcp']}.contact_id =
195 {$this->_aliases['civicrm_contact']}.id
197 LEFT JOIN civicrm_contribution_page {$this->_aliases['civicrm_contribution_page']}
198 ON {$this->_aliases['civicrm_pcp']}.page_id =
199 {$this->_aliases['civicrm_contribution_page']}.id";
203 $this->_groupBy
= "GROUP BY {$this->_aliases['civicrm_pcp']}.id";
207 $this->_orderBy
= " ORDER BY {$this->_aliases['civicrm_contact']}.sort_name ";
211 $whereClauses = $havingClauses = array();
213 foreach ($this->_columns
as $tableName => $table) {
214 if (array_key_exists('filters', $table)) {
215 foreach ($table['filters'] as $fieldName => $field) {
218 if (CRM_Utils_Array
::value('type', $field) & CRM_Utils_Type
::T_DATE
) {
219 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
220 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
221 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
222 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
225 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
228 $clause = $this->whereClause($field,
230 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
231 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
232 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
237 if (!empty($clause)) {
238 if ($tableName == 'civicrm_contribution_soft' &&
239 $fieldName == 'amount_2'
241 $havingClauses[] = $clause;
244 $whereClauses[] = $clause;
250 if (empty($whereClauses)) {
251 $this->_where
= "WHERE ( 1 ) ";
254 $this->_where
= "WHERE " . implode(' AND ', $whereClauses);
256 if ($this->_aclWhere
) {
257 $this->_where
.= " AND {$this->_aclWhere} ";
260 if (!empty($havingClauses)) {
261 // use this clause to construct group by clause.
262 $this->_having
= "HAVING " . implode(' AND ', $havingClauses);
266 function alterDisplay(&$rows) {
267 // custom code to alter rows
269 $checkList = array();
270 foreach ($rows as $rowNum => $row) {
271 if (!empty($this->_noRepeats
) && $this->_outputMode
!= 'csv') {
272 // not repeat contact sort names if it matches with the one
274 $repeatFound = FALSE;
276 foreach ($row as $colName => $colVal) {
277 if (CRM_Utils_Array
::value($colName, $checkList) &&
278 is_array($checkList[$colName]) &&
279 in_array($colVal, $checkList[$colName])
281 $rows[$rowNum][$colName] = "";
284 if (in_array($colName, $this->_noRepeats
)) {
285 $checkList[$colName][] = $colVal;
290 if (array_key_exists('civicrm_contact_sort_name', $row) &&
291 $rows[$rowNum]['civicrm_contact_sort_name'] &&
292 array_key_exists('civicrm_contact_id', $row)
294 $url = CRM_Utils_System
::url("civicrm/contact/view",
295 'reset=1&cid=' . $row['civicrm_contact_id'],
298 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
299 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact Summary for this Contact.");