commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / drupal / modules / views / civicrm / civicrm_handler_sort_pcp_raised_amount.inc
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | This file is a part of CiviCRM. |
7 | |
8 | CiviCRM is free software; you can copy, modify, and distribute it |
9 | under the terms of the GNU Affero General Public License |
10 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
11 | |
12 | CiviCRM is distributed in the hope that it will be useful, but |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
15 | See the GNU Affero General Public License for more details. |
16 | |
17 | You should have received a copy of the GNU Affero General Public |
18 | License and the CiviCRM Licensing Exception along |
19 | with this program; if not, contact CiviCRM LLC |
20 | at info[AT]civicrm[DOT]org. If you have questions about the |
21 | GNU Affero General Public License or the licensing of CiviCRM, |
22 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
23 +--------------------------------------------------------------------+
24 */
25
26 /**
27 * sorting handler to calcuate the total amount raised for PCPs.
28 *
29 */
30 class civicrm_handler_sort_pcp_raised_amount extends views_handler_sort {
31 function query() {
32 $this->ensure_my_table();
33
34 // @see CRM_PCP_BAO_PCP::thermoMeter for the source of this SQL
35 $formula = "
36 (SELECT SUM(cc.total_amount) as total
37 FROM {civicrm_pcp} pcp2
38 LEFT JOIN {civicrm_contribution_soft} cs ON ( pcp2.id = cs.pcp_id )
39 LEFT JOIN {civicrm_contribution} cc ON ( cs.contribution_id = cc.id)
40 WHERE pcp2.id = " . $this->table_alias . "." . $this->real_field . " AND cc.contribution_status_id =1 AND cc.is_test = 0)";
41
42 $this->query->add_orderby(NULL, $formula, $this->options['order'], $this->table_alias . '_' . $this->field);
43 }
44 }
45