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
,
86 'id' => array('title' => ts('Event Title'),
87 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
88 'options' => $this->getEventFilterOptions(),
90 'event_type_id' => array(
91 'name' => 'event_type_id',
92 'title' => ts('Event Type'),
93 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
94 'options' => CRM_Core_OptionGroup
::values('event_type'),
96 'event_start_date' => array(
97 'title' => 'Event Start Date',
98 'operatorType' => CRM_Report_Form
::OP_DATE
,
100 'event_end_date' => array(
101 'title' => 'Event End Date',
102 'operatorType' => CRM_Report_Form
::OP_DATE
,
107 $this->_currencyColumn
= 'civicrm_participant_fee_currency';
108 parent
::__construct();
111 function preProcess() {
112 parent
::preProcess();
117 foreach ($this->_columns
as $tableName => $table) {
118 if (array_key_exists('fields', $table)) {
119 foreach ($table['fields'] as $fieldName => $field) {
120 if (!empty($field['required']) ||
!empty($this->_params
['fields'][$fieldName])) {
121 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
127 $this->_select
= 'SELECT ' . implode(', ', $select);
131 $this->_from
= " FROM civicrm_event {$this->_aliases['civicrm_event']} ";
136 $this->_participantWhere
= "";
137 foreach ($this->_columns
as $tableName => $table) {
138 if (array_key_exists('filters', $table)) {
139 foreach ($table['filters'] as $fieldName => $field) {
141 if (CRM_Utils_Array
::value('type', $field) & CRM_Utils_Type
::T_DATE
) {
142 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
143 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
144 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
146 if ($relative ||
$from ||
$to) {
147 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
151 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
153 $clause = $this->whereClause($field,
155 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
156 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
157 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
161 if (!empty($this->_params
['id_value'])) {
162 $participant = implode(', ', $this->_params
['id_value']);
163 $this->_participantWhere
= " AND civicrm_participant.event_id IN ( {$participant} ) ";
166 if (!empty($clause)) {
167 $clauses[] = $clause;
172 $clauses[] = "{$this->_aliases['civicrm_event']}.is_template = 0";
173 $this->_where
= 'WHERE ' . implode(' AND ', $clauses);
177 $this->assign('chartSupported', TRUE);
178 $this->_groupBy
= " GROUP BY {$this->_aliases['civicrm_event']}.id";
181 //get participants information for events
185 function participantInfo() {
187 $statusType1 = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1');
188 $statusType2 = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 0');
191 SELECT civicrm_participant.event_id AS event_id,
192 civicrm_participant.status_id AS statusId,
193 COUNT( civicrm_participant.id ) AS participant,
194 SUM( civicrm_participant.fee_amount ) AS amount,
195 civicrm_participant.fee_currency
197 FROM civicrm_participant
199 WHERE civicrm_participant.is_test = 0
200 $this->_participantWhere
202 GROUP BY civicrm_participant.event_id,
203 civicrm_participant.status_id";
205 $info = CRM_Core_DAO
::executeQuery($sql);
206 $participant_data = $participant_info = $currency = array();
208 while ($info->fetch()) {
209 $participant_data[$info->event_id
][$info->statusId
]['participant'] = $info->participant
;
210 $participant_data[$info->event_id
][$info->statusId
]['amount'] = $info->amount
;
211 $currency[$info->event_id
] = $info->fee_currency
;
214 $amt = $particiType1 = $particiType2 = 0;
216 foreach ($participant_data as $event_id => $event_data) {
217 foreach ($event_data as $status_id => $data) {
219 if (array_key_exists($status_id, $statusType1)) {
220 //total income of event
221 $amt = $amt +
$data['amount'];
223 //number of Registered/Attended participants
224 $particiType1 = $particiType1 +
$data['participant'];
226 elseif (array_key_exists($status_id, $statusType2)) {
228 //number of No-show/Cancelled/Pending participants
229 $particiType2 = $particiType2 +
$data['participant'];
233 $participant_info[$event_id]['totalAmount'] = $amt;
234 $participant_info[$event_id]['statusType1'] = $particiType1;
235 $participant_info[$event_id]['statusType2'] = $particiType2;
236 $participant_info[$event_id]['currency'] = $currency[$event_id];
237 $amt = $particiType1 = $particiType2 = 0;
240 return $participant_info;
243 //build header for table
244 function buildColumnHeaders() {
246 $this->_columnHeaders
= array();
247 foreach ($this->_columns
as $tableName => $table) {
248 if (array_key_exists('fields', $table)) {
249 foreach ($table['fields'] as $fieldName => $field) {
250 if (!empty($field['required']) ||
!empty($this->_params
['fields'][$fieldName])) {
252 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
253 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array
::value('title', $field);
259 $statusType1 = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1');
260 $statusType2 = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 0');
262 //make column header for participant status Registered/Attended
263 $type1_header = implode('/', $statusType1);
265 //make column header for participant status No-show/Cancelled/Pending
266 $type2_header = implode('/', $statusType2);
268 $this->_columnHeaders
['statusType1'] = array(
269 'title' => $type1_header,
270 'type' => CRM_Utils_Type
::T_INT
,
272 $this->_columnHeaders
['statusType2'] = array(
273 'title' => $type2_header,
274 'type' => CRM_Utils_Type
::T_INT
,
276 $this->_columnHeaders
['totalAmount'] = array(
277 'title' => 'Total Income',
278 'type' => CRM_Utils_Type
::T_STRING
,
282 function postProcess() {
284 $this->beginPostProcess();
286 $this->buildColumnHeaders();
288 $sql = $this->buildQuery(TRUE);
290 $dao = CRM_Core_DAO
::executeQuery($sql);
292 //set pager before exicution of query in function participantInfo()
295 $rows = $graphRows = array();
297 while ($dao->fetch()) {
299 foreach ($this->_columnHeaders
as $key => $value) {
300 if (($key == 'civicrm_event_start_date') ||
($key == 'civicrm_event_end_date')) {
301 //get event start date and end date in custom datetime format
302 $row[$key] = CRM_Utils_Date
::customFormat($dao->$key);
305 if (isset($dao->$key)) {
306 $row[$key] = $dao->$key;
313 $participant_info = $this->participantInfo();
314 foreach ($rows as $key => $value) {
315 if (array_key_exists($value['civicrm_event_id'], $participant_info)) {
316 foreach ($participant_info[$value['civicrm_event_id']] as $k => $v) {
317 $rows[$key][$k] = $v;
322 // do not call pager here
323 $this->formatDisplay($rows, FALSE);
324 unset($this->_columnHeaders
['civicrm_event_id']);
326 $this->doTemplateAssignment($rows);
328 $this->endPostProcess($rows);
334 function buildChart(&$rows) {
335 $this->_interval
= 'events';
337 if (!empty($this->_params
['charts'])) {
338 foreach ($rows as $key => $value) {
339 $graphRows['totalAmount'][] = $graphRows['value'][] = CRM_Utils_Array
::value('totalAmount', $rows[$key]);
340 $graphRows[$this->_interval
][] = substr($rows[$key]['civicrm_event_title'], 0, 12) . "..(" . $rows[$key]['civicrm_event_id'] . ") ";
343 if (CRM_Utils_Array
::value('totalAmount', $rows[$key]) == 0) {
344 $countEvent = count($rows);
347 if ((!empty($rows)) && $countEvent != 1) {
348 $config = CRM_Core_Config
::Singleton();
350 'legend' => 'Event Summary',
352 'yname' => "Total Amount ({$config->defaultCurrency})",
354 if (!empty($graphRows)) {
355 foreach ($graphRows[$this->_interval
] as $key => $val) {
356 $graph[$val] = $graphRows['value'][$key];
358 $chartInfo['values'] = $graph;
359 $chartInfo['xLabelAngle'] = 20;
362 CRM_Utils_OpenFlashChart
::buildChart($chartInfo, $this->_params
['charts']);
363 $this->assign('chartType', $this->_params
['charts']);
372 function alterDisplay(&$rows) {
374 if (is_array($rows)) {
375 $eventType = CRM_Core_OptionGroup
::values('event_type');
377 foreach ($rows as $rowNum => $row) {
378 if (array_key_exists('totalAmount', $row) && array_key_exists('currency', $row)) {
379 $rows[$rowNum]['totalAmount'] = CRM_Utils_Money
::format($rows[$rowNum]['totalAmount'], $rows[$rowNum]['currency']);
381 if (array_key_exists('civicrm_event_title', $row)) {
382 if ($value = $row['civicrm_event_id']) {
383 //CRM_Event_PseudoConstant::event( $value, false );
384 $url = CRM_Report_Utils_Report
::getNextUrl('event/income',
385 'reset=1&force=1&id_op=in&id_value=' . $value,
386 $this->_absoluteUrl
, $this->_id
, $this->_drilldownReport
388 $rows[$rowNum]['civicrm_event_title_link'] = $url;
389 $rows[$rowNum]['civicrm_event_title_hover'] = ts('View Event Income For this Event');
394 if (array_key_exists('civicrm_event_event_type_id', $row)) {
395 if ($value = $row['civicrm_event_event_type_id']) {
396 $rows[$rowNum]['civicrm_event_event_type_id'] = $eventType[$value];