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_Event_Summary
extends CRM_Report_Form_Event
{
38 protected $_summary = NULL;
40 protected $_charts = array(
42 'barChart' => 'Bar Chart',
43 'pieChart' => 'Pie Chart',
46 protected $_add2groupSupported = FALSE;
48 protected $_customGroupExtends = array(
50 public $_drilldownReport = array('event/income' => 'Link to Detail Report');
58 function __construct() {
60 $this->_columns
= array(
63 'dao' => 'CRM_Event_DAO_Event',
70 'title' => array('title' => ts('Event Title'),
73 'event_type_id' => array('title' => ts('Event Type'),
76 'fee_label' => array('title' => ts('Fee Label')),
77 'event_start_date' => array('title' => ts('Event Start Date'),
79 'event_end_date' => array('title' => ts('Event End Date')),
80 'max_participants' => array('title' => ts('Capacity'),
81 'type' => CRM_Utils_Type
::T_INT
,
87 'title' => ts('Event'),
88 'operatorType' => CRM_Report_Form
::OP_ENTITYREF
,
89 'type' => CRM_Utils_Type
::T_INT
,
90 'attributes' => array('select' => array('minimumInputLength' => 0)),
92 'event_type_id' => array(
93 'name' => 'event_type_id',
94 'title' => ts('Event Type'),
95 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
96 'options' => CRM_Core_OptionGroup
::values('event_type'),
98 'event_start_date' => array(
99 'title' => 'Event Start Date',
100 'operatorType' => CRM_Report_Form
::OP_DATE
,
102 'event_end_date' => array(
103 'title' => 'Event End Date',
104 'operatorType' => CRM_Report_Form
::OP_DATE
,
109 $this->_currencyColumn
= 'civicrm_participant_fee_currency';
110 parent
::__construct();
113 function preProcess() {
114 parent
::preProcess();
119 foreach ($this->_columns
as $tableName => $table) {
120 if (array_key_exists('fields', $table)) {
121 foreach ($table['fields'] as $fieldName => $field) {
122 if (!empty($field['required']) ||
!empty($this->_params
['fields'][$fieldName])) {
123 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
129 $this->_select
= 'SELECT ' . implode(', ', $select);
133 $this->_from
= " FROM civicrm_event {$this->_aliases['civicrm_event']} ";
138 $this->_participantWhere
= "";
139 foreach ($this->_columns
as $tableName => $table) {
140 if (array_key_exists('filters', $table)) {
141 foreach ($table['filters'] as $fieldName => $field) {
143 if (CRM_Utils_Array
::value('type', $field) & CRM_Utils_Type
::T_DATE
) {
144 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
145 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
146 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
148 if ($relative ||
$from ||
$to) {
149 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
153 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
155 $clause = $this->whereClause($field,
157 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
158 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
159 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
163 if (!empty($this->_params
['id_value'])) {
164 $this->_participantWhere
= " AND civicrm_participant.event_id IN ( {$this->_params['id_value']} ) ";
167 if (!empty($clause)) {
168 $clauses[] = $clause;
173 $clauses[] = "{$this->_aliases['civicrm_event']}.is_template = 0";
174 $this->_where
= 'WHERE ' . implode(' AND ', $clauses);
178 $this->assign('chartSupported', TRUE);
179 $this->_groupBy
= " GROUP BY {$this->_aliases['civicrm_event']}.id";
182 //get participants information for events
186 function participantInfo() {
188 $statusType1 = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1');
189 $statusType2 = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 0');
192 SELECT civicrm_participant.event_id AS event_id,
193 civicrm_participant.status_id AS statusId,
194 COUNT( civicrm_participant.id ) AS participant,
195 SUM( civicrm_participant.fee_amount ) AS amount,
196 civicrm_participant.fee_currency
198 FROM civicrm_participant
200 WHERE civicrm_participant.is_test = 0
201 $this->_participantWhere
203 GROUP BY civicrm_participant.event_id,
204 civicrm_participant.status_id";
206 $info = CRM_Core_DAO
::executeQuery($sql);
207 $participant_data = $participant_info = $currency = array();
209 while ($info->fetch()) {
210 $participant_data[$info->event_id
][$info->statusId
]['participant'] = $info->participant
;
211 $participant_data[$info->event_id
][$info->statusId
]['amount'] = $info->amount
;
212 $currency[$info->event_id
] = $info->fee_currency
;
215 $amt = $particiType1 = $particiType2 = 0;
217 foreach ($participant_data as $event_id => $event_data) {
218 foreach ($event_data as $status_id => $data) {
220 if (array_key_exists($status_id, $statusType1)) {
221 //total income of event
222 $amt = $amt +
$data['amount'];
224 //number of Registered/Attended participants
225 $particiType1 = $particiType1 +
$data['participant'];
227 elseif (array_key_exists($status_id, $statusType2)) {
229 //number of No-show/Cancelled/Pending participants
230 $particiType2 = $particiType2 +
$data['participant'];
234 $participant_info[$event_id]['totalAmount'] = $amt;
235 $participant_info[$event_id]['statusType1'] = $particiType1;
236 $participant_info[$event_id]['statusType2'] = $particiType2;
237 $participant_info[$event_id]['currency'] = $currency[$event_id];
238 $amt = $particiType1 = $particiType2 = 0;
241 return $participant_info;
244 //build header for table
245 function buildColumnHeaders() {
247 $this->_columnHeaders
= array();
248 foreach ($this->_columns
as $tableName => $table) {
249 if (array_key_exists('fields', $table)) {
250 foreach ($table['fields'] as $fieldName => $field) {
251 if (!empty($field['required']) ||
!empty($this->_params
['fields'][$fieldName])) {
253 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
254 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array
::value('title', $field);
260 $statusType1 = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1');
261 $statusType2 = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 0');
263 //make column header for participant status Registered/Attended
264 $type1_header = implode('/', $statusType1);
266 //make column header for participant status No-show/Cancelled/Pending
267 $type2_header = implode('/', $statusType2);
269 $this->_columnHeaders
['statusType1'] = array(
270 'title' => $type1_header,
271 'type' => CRM_Utils_Type
::T_INT
,
273 $this->_columnHeaders
['statusType2'] = array(
274 'title' => $type2_header,
275 'type' => CRM_Utils_Type
::T_INT
,
277 $this->_columnHeaders
['totalAmount'] = array(
278 'title' => 'Total Income',
279 'type' => CRM_Utils_Type
::T_STRING
,
283 function postProcess() {
285 $this->beginPostProcess();
287 $this->buildColumnHeaders();
289 $sql = $this->buildQuery(TRUE);
291 $dao = CRM_Core_DAO
::executeQuery($sql);
293 //set pager before exicution of query in function participantInfo()
296 $rows = $graphRows = array();
298 while ($dao->fetch()) {
300 foreach ($this->_columnHeaders
as $key => $value) {
301 if (($key == 'civicrm_event_start_date') ||
($key == 'civicrm_event_end_date')) {
302 //get event start date and end date in custom datetime format
303 $row[$key] = CRM_Utils_Date
::customFormat($dao->$key);
306 if (isset($dao->$key)) {
307 $row[$key] = $dao->$key;
314 $participant_info = $this->participantInfo();
315 foreach ($rows as $key => $value) {
316 if (array_key_exists($value['civicrm_event_id'], $participant_info)) {
317 foreach ($participant_info[$value['civicrm_event_id']] as $k => $v) {
318 $rows[$key][$k] = $v;
323 // do not call pager here
324 $this->formatDisplay($rows, FALSE);
325 unset($this->_columnHeaders
['civicrm_event_id']);
327 $this->doTemplateAssignment($rows);
329 $this->endPostProcess($rows);
335 function buildChart(&$rows) {
336 $this->_interval
= 'events';
338 if (!empty($this->_params
['charts'])) {
339 foreach ($rows as $key => $value) {
340 $graphRows['totalAmount'][] = $graphRows['value'][] = CRM_Utils_Array
::value('totalAmount', $rows[$key]);
341 $graphRows[$this->_interval
][] = substr($rows[$key]['civicrm_event_title'], 0, 12) . "..(" . $rows[$key]['civicrm_event_id'] . ") ";
344 if (CRM_Utils_Array
::value('totalAmount', $rows[$key]) == 0) {
345 $countEvent = count($rows);
348 if ((!empty($rows)) && $countEvent != 1) {
349 $config = CRM_Core_Config
::Singleton();
351 'legend' => 'Event Summary',
353 'yname' => "Total Amount ({$config->defaultCurrency})",
355 if (!empty($graphRows)) {
356 foreach ($graphRows[$this->_interval
] as $key => $val) {
357 $graph[$val] = $graphRows['value'][$key];
359 $chartInfo['values'] = $graph;
360 $chartInfo['xLabelAngle'] = 20;
363 CRM_Utils_OpenFlashChart
::buildChart($chartInfo, $this->_params
['charts']);
364 $this->assign('chartType', $this->_params
['charts']);
373 function alterDisplay(&$rows) {
375 if (is_array($rows)) {
376 $eventType = CRM_Core_OptionGroup
::values('event_type');
378 foreach ($rows as $rowNum => $row) {
379 if (array_key_exists('totalAmount', $row) && array_key_exists('currency', $row)) {
380 $rows[$rowNum]['totalAmount'] = CRM_Utils_Money
::format($rows[$rowNum]['totalAmount'], $rows[$rowNum]['currency']);
382 if (array_key_exists('civicrm_event_title', $row)) {
383 if ($value = $row['civicrm_event_id']) {
384 //CRM_Event_PseudoConstant::event( $value, false );
385 $url = CRM_Report_Utils_Report
::getNextUrl('event/income',
386 'reset=1&force=1&id_op=in&id_value=' . $value,
387 $this->_absoluteUrl
, $this->_id
, $this->_drilldownReport
389 $rows[$rowNum]['civicrm_event_title_link'] = $url;
390 $rows[$rowNum]['civicrm_event_title_hover'] = ts('View Event Income For this Event');
395 if (array_key_exists('civicrm_event_event_type_id', $row)) {
396 if ($value = $row['civicrm_event_event_type_id']) {
397 $rows[$rowNum]['civicrm_event_event_type_id'] = $eventType[$value];