5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2013 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
12 | CiviCRM is free software; you can copy, modify, and distribute it |
13 | under the terms of the GNU Affero General Public License |
14 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
16 | CiviCRM is distributed in the hope that it will be useful, but |
17 | WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
19 | See the GNU Affero General Public License for more details. |
21 | You should have received a copy of the GNU Affero General Public |
22 | License and the CiviCRM Licensing Exception along |
23 | with this program; if not, contact CiviCRM LLC |
24 | at info[AT]civicrm[DOT]org. If you have questions about the |
25 | GNU Affero General Public License or the licensing of CiviCRM, |
26 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
27 +--------------------------------------------------------------------+
33 * @copyright CiviCRM LLC (c) 2004-2013
37 class CRM_Report_Form_Event_Summary
extends CRM_Report_Form_Event
{
39 protected $_summary = NULL;
41 protected $_charts = array(
43 'barChart' => 'Bar Chart',
44 'pieChart' => 'Pie Chart',
47 protected $_add2groupSupported = FALSE;
49 protected $_customGroupExtends = array(
51 public $_drilldownReport = array('event/income' => 'Link to Detail Report');
53 function __construct() {
55 $this->_columns
= array(
58 'dao' => 'CRM_Event_DAO_Event',
65 'title' => array('title' => ts('Event Title'),
68 'event_type_id' => array('title' => ts('Event Type'),
71 'fee_label' => array('title' => ts('Fee Label')),
72 'event_start_date' => array('title' => ts('Event Start Date'),
74 'event_end_date' => array('title' => ts('Event End Date')),
75 'max_participants' => array('title' => ts('Capacity'),
76 'type' => CRM_Utils_Type
::T_INT
,
81 'id' => array('title' => ts('Event Title'),
82 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
83 'options' => $this->getEventFilterOptions(),
85 'event_type_id' => array(
86 'name' => 'event_type_id',
87 'title' => ts('Event Type'),
88 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
89 'options' => CRM_Core_OptionGroup
::values('event_type'),
91 'event_start_date' => array(
92 'title' => 'Event Start Date',
93 'operatorType' => CRM_Report_Form
::OP_DATE
,
95 'event_end_date' => array(
96 'title' => 'Event End Date',
97 'operatorType' => CRM_Report_Form
::OP_DATE
,
103 parent
::__construct();
106 function preProcess() {
107 parent
::preProcess();
112 foreach ($this->_columns
as $tableName => $table) {
113 if (array_key_exists('fields', $table)) {
114 foreach ($table['fields'] as $fieldName => $field) {
115 if (CRM_Utils_Array
::value('required', $field) ||
116 CRM_Utils_Array
::value($fieldName, $this->_params
['fields'])
118 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
124 $this->_select
= 'SELECT ' . implode(', ', $select);
128 $this->_from
= " FROM civicrm_event {$this->_aliases['civicrm_event']} ";
133 $this->_participantWhere
= "";
134 foreach ($this->_columns
as $tableName => $table) {
135 if (array_key_exists('filters', $table)) {
136 foreach ($table['filters'] as $fieldName => $field) {
138 if (CRM_Utils_Array
::value('type', $field) & CRM_Utils_Type
::T_DATE
) {
139 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
140 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
141 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
143 if ($relative ||
$from ||
$to) {
144 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
148 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
150 $clause = $this->whereClause($field,
152 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
153 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
154 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
158 if (!empty($this->_params
['id_value'])) {
159 $participant = implode(', ', $this->_params
['id_value']);
160 $this->_participantWhere
= " AND civicrm_participant.event_id IN ( {$participant} ) ";
163 if (!empty($clause)) {
164 $clauses[] = $clause;
169 $clauses[] = "({$this->_aliases['civicrm_event']}.is_template IS NULL OR {$this->_aliases['civicrm_event']}.is_template = 0)";
170 $this->_where
= 'WHERE ' . implode(' AND ', $clauses);
174 $this->assign('chartSupported', TRUE);
175 $this->_groupBy
= " GROUP BY {$this->_aliases['civicrm_event']}.id";
178 //get participants information for events
179 function participantInfo() {
181 $statusType1 = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1');
182 $statusType2 = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 0');
185 SELECT civicrm_participant.event_id AS event_id,
186 civicrm_participant.status_id AS statusId,
187 COUNT( civicrm_participant.id ) AS participant,
188 SUM( civicrm_participant.fee_amount ) AS amount,
189 civicrm_participant.fee_currency
191 FROM civicrm_participant
193 WHERE civicrm_participant.is_test = 0
194 $this->_participantWhere
196 GROUP BY civicrm_participant.event_id,
197 civicrm_participant.status_id";
199 $info = CRM_Core_DAO
::executeQuery($sql);
200 $participant_data = $participant_info = $currency = array();
202 while ($info->fetch()) {
203 $participant_data[$info->event_id
][$info->statusId
]['participant'] = $info->participant
;
204 $participant_data[$info->event_id
][$info->statusId
]['amount'] = $info->amount
;
205 $currency[$info->event_id
] = $info->fee_currency
;
208 $amt = $particiType1 = $particiType2 = 0;
210 foreach ($participant_data as $event_id => $event_data) {
211 foreach ($event_data as $status_id => $data) {
213 if (array_key_exists($status_id, $statusType1)) {
214 //total income of event
215 $amt = $amt +
$data['amount'];
217 //number of Registered/Attended participants
218 $particiType1 = $particiType1 +
$data['participant'];
220 elseif (array_key_exists($status_id, $statusType2)) {
222 //number of No-show/Cancelled/Pending participants
223 $particiType2 = $particiType2 +
$data['participant'];
227 $participant_info[$event_id]['totalAmount'] = CRM_Utils_Money
::format($amt, $currency[$event_id]);
228 $participant_info[$event_id]['statusType1'] = $particiType1;
229 $participant_info[$event_id]['statusType2'] = $particiType2;
230 $amt = $particiType1 = $particiType2 = 0;
233 return $participant_info;
236 //build header for table
237 function buildColumnHeaders() {
239 $this->_columnHeaders
= array();
240 foreach ($this->_columns
as $tableName => $table) {
241 if (array_key_exists('fields', $table)) {
242 foreach ($table['fields'] as $fieldName => $field) {
243 if (CRM_Utils_Array
::value('required', $field) ||
244 CRM_Utils_Array
::value($fieldName, $this->_params
['fields'])
247 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
248 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array
::value('title', $field);
254 $statusType1 = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1');
255 $statusType2 = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 0');
257 //make column header for participant status Registered/Attended
258 $type1_header = implode('/', $statusType1);
260 //make column header for participant status No-show/Cancelled/Pending
261 $type2_header = implode('/', $statusType2);
263 $this->_columnHeaders
['statusType1'] = array(
264 'title' => $type1_header,
265 'type' => CRM_Utils_Type
::T_INT
,
267 $this->_columnHeaders
['statusType2'] = array(
268 'title' => $type2_header,
269 'type' => CRM_Utils_Type
::T_INT
,
271 $this->_columnHeaders
['totalAmount'] = array(
272 'title' => 'Total Income',
273 'type' => CRM_Utils_Type
::T_STRING
,
277 function postProcess() {
279 $this->beginPostProcess();
281 $this->buildColumnHeaders();
283 $sql = $this->buildQuery(TRUE);
285 $dao = CRM_Core_DAO
::executeQuery($sql);
287 //set pager before exicution of query in function participantInfo()
290 $rows = $graphRows = array();
292 while ($dao->fetch()) {
294 foreach ($this->_columnHeaders
as $key => $value) {
295 if (($key == 'civicrm_event_start_date') ||
($key == 'civicrm_event_end_date')) {
296 //get event start date and end date in custom datetime format
297 $row[$key] = CRM_Utils_Date
::customFormat($dao->$key);
300 if (isset($dao->$key)) {
301 $row[$key] = $dao->$key;
308 $participant_info = $this->participantInfo();
309 foreach ($rows as $key => $value) {
310 if (array_key_exists($value['civicrm_event_id'], $participant_info)) {
311 foreach ($participant_info[$value['civicrm_event_id']] as $k => $v) {
312 $rows[$key][$k] = $v;
317 // do not call pager here
318 $this->formatDisplay($rows, FALSE);
319 unset($this->_columnHeaders
['civicrm_event_id']);
321 $this->doTemplateAssignment($rows);
323 $this->endPostProcess($rows);
326 function buildChart(&$rows) {
327 $this->_interval
= 'events';
329 if (CRM_Utils_Array
::value('charts', $this->_params
)) {
330 foreach ($rows as $key => $value) {
331 $graphRows['totalAmount'][] = $graphRows['value'][] = CRM_Utils_Array
::value('totalAmount', $rows[$key]);
332 $graphRows[$this->_interval
][] = substr($rows[$key]['civicrm_event_title'], 0, 12) . "..(" . $rows[$key]['civicrm_event_id'] . ") ";
335 if (CRM_Utils_Array
::value('totalAmount', $rows[$key]) == 0) {
336 $countEvent = count($rows);
339 if ((!empty($rows)) && $countEvent != 1) {
340 $config = CRM_Core_Config
::Singleton();
342 'legend' => 'Event Summary',
344 'yname' => "Total Amount ({$config->defaultCurrency})",
346 if (!empty($graphRows)) {
347 foreach ($graphRows[$this->_interval
] as $key => $val) {
348 $graph[$val] = $graphRows['value'][$key];
350 $chartInfo['values'] = $graph;
351 $chartInfo['xLabelAngle'] = 20;
354 CRM_Utils_OpenFlashChart
::buildChart($chartInfo, $this->_params
['charts']);
355 $this->assign('chartType', $this->_params
['charts']);
361 function alterDisplay(&$rows) {
363 if (is_array($rows)) {
364 $eventType = CRM_Core_OptionGroup
::values('event_type');
365 foreach ($rows as $rowNum => $row) {
367 if (array_key_exists('civicrm_event_title', $row)) {
368 if ($value = $row['civicrm_event_id']) {
369 //CRM_Event_PseudoConstant::event( $value, false );
370 $url = CRM_Report_Utils_Report
::getNextUrl('event/income',
371 'reset=1&force=1&id_op=in&id_value=' . $value,
372 $this->_absoluteUrl
, $this->_id
, $this->_drilldownReport
374 $rows[$rowNum]['civicrm_event_title_link'] = $url;
375 $rows[$rowNum]['civicrm_event_title_hover'] = ts('View Event Income For this Event');
380 if (array_key_exists('civicrm_event_event_type_id', $row)) {
381 if ($value = $row['civicrm_event_event_type_id']) {
382 $rows[$rowNum]['civicrm_event_event_type_id'] = $eventType[$value];