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_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');
52 function __construct() {
54 $this->_columns
= array(
57 'dao' => 'CRM_Event_DAO_Event',
64 'title' => array('title' => ts('Event Title'),
67 'event_type_id' => array('title' => ts('Event Type'),
70 'fee_label' => array('title' => ts('Fee Label')),
71 'event_start_date' => array('title' => ts('Event Start Date'),
73 'event_end_date' => array('title' => ts('Event End Date')),
74 'max_participants' => array('title' => ts('Capacity'),
75 'type' => CRM_Utils_Type
::T_INT
,
80 'id' => array('title' => ts('Event Title'),
81 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
82 'options' => $this->getEventFilterOptions(),
84 'event_type_id' => array(
85 'name' => 'event_type_id',
86 'title' => ts('Event Type'),
87 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
88 'options' => CRM_Core_OptionGroup
::values('event_type'),
90 'event_start_date' => array(
91 'title' => 'Event Start Date',
92 'operatorType' => CRM_Report_Form
::OP_DATE
,
94 'event_end_date' => array(
95 'title' => 'Event End Date',
96 'operatorType' => CRM_Report_Form
::OP_DATE
,
101 $this->_currencyColumn
= 'civicrm_participant_fee_currency';
102 parent
::__construct();
105 function preProcess() {
106 parent
::preProcess();
111 foreach ($this->_columns
as $tableName => $table) {
112 if (array_key_exists('fields', $table)) {
113 foreach ($table['fields'] as $fieldName => $field) {
114 if (!empty($field['required']) ||
!empty($this->_params
['fields'][$fieldName])) {
115 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
121 $this->_select
= 'SELECT ' . implode(', ', $select);
125 $this->_from
= " FROM civicrm_event {$this->_aliases['civicrm_event']} ";
130 $this->_participantWhere
= "";
131 foreach ($this->_columns
as $tableName => $table) {
132 if (array_key_exists('filters', $table)) {
133 foreach ($table['filters'] as $fieldName => $field) {
135 if (CRM_Utils_Array
::value('type', $field) & CRM_Utils_Type
::T_DATE
) {
136 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
137 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
138 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
140 if ($relative ||
$from ||
$to) {
141 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
145 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
147 $clause = $this->whereClause($field,
149 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
150 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
151 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
155 if (!empty($this->_params
['id_value'])) {
156 $participant = implode(', ', $this->_params
['id_value']);
157 $this->_participantWhere
= " AND civicrm_participant.event_id IN ( {$participant} ) ";
160 if (!empty($clause)) {
161 $clauses[] = $clause;
166 $clauses[] = "({$this->_aliases['civicrm_event']}.is_template IS NULL OR {$this->_aliases['civicrm_event']}.is_template = 0)";
167 $this->_where
= 'WHERE ' . implode(' AND ', $clauses);
171 $this->assign('chartSupported', TRUE);
172 $this->_groupBy
= " GROUP BY {$this->_aliases['civicrm_event']}.id";
175 //get participants information for events
176 function participantInfo() {
178 $statusType1 = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1');
179 $statusType2 = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 0');
182 SELECT civicrm_participant.event_id AS event_id,
183 civicrm_participant.status_id AS statusId,
184 COUNT( civicrm_participant.id ) AS participant,
185 SUM( civicrm_participant.fee_amount ) AS amount,
186 civicrm_participant.fee_currency
188 FROM civicrm_participant
190 WHERE civicrm_participant.is_test = 0
191 $this->_participantWhere
193 GROUP BY civicrm_participant.event_id,
194 civicrm_participant.status_id";
196 $info = CRM_Core_DAO
::executeQuery($sql);
197 $participant_data = $participant_info = $currency = array();
199 while ($info->fetch()) {
200 $participant_data[$info->event_id
][$info->statusId
]['participant'] = $info->participant
;
201 $participant_data[$info->event_id
][$info->statusId
]['amount'] = $info->amount
;
202 $currency[$info->event_id
] = $info->fee_currency
;
205 $amt = $particiType1 = $particiType2 = 0;
207 foreach ($participant_data as $event_id => $event_data) {
208 foreach ($event_data as $status_id => $data) {
210 if (array_key_exists($status_id, $statusType1)) {
211 //total income of event
212 $amt = $amt +
$data['amount'];
214 //number of Registered/Attended participants
215 $particiType1 = $particiType1 +
$data['participant'];
217 elseif (array_key_exists($status_id, $statusType2)) {
219 //number of No-show/Cancelled/Pending participants
220 $particiType2 = $particiType2 +
$data['participant'];
224 $participant_info[$event_id]['totalAmount'] = $amt;
225 $participant_info[$event_id]['statusType1'] = $particiType1;
226 $participant_info[$event_id]['statusType2'] = $particiType2;
227 $participant_info[$event_id]['currency'] = $currency[$event_id];
228 $amt = $particiType1 = $particiType2 = 0;
231 return $participant_info;
234 //build header for table
235 function buildColumnHeaders() {
237 $this->_columnHeaders
= array();
238 foreach ($this->_columns
as $tableName => $table) {
239 if (array_key_exists('fields', $table)) {
240 foreach ($table['fields'] as $fieldName => $field) {
241 if (!empty($field['required']) ||
!empty($this->_params
['fields'][$fieldName])) {
243 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
244 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array
::value('title', $field);
250 $statusType1 = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1');
251 $statusType2 = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 0');
253 //make column header for participant status Registered/Attended
254 $type1_header = implode('/', $statusType1);
256 //make column header for participant status No-show/Cancelled/Pending
257 $type2_header = implode('/', $statusType2);
259 $this->_columnHeaders
['statusType1'] = array(
260 'title' => $type1_header,
261 'type' => CRM_Utils_Type
::T_INT
,
263 $this->_columnHeaders
['statusType2'] = array(
264 'title' => $type2_header,
265 'type' => CRM_Utils_Type
::T_INT
,
267 $this->_columnHeaders
['totalAmount'] = array(
268 'title' => 'Total Income',
269 'type' => CRM_Utils_Type
::T_STRING
,
273 function postProcess() {
275 $this->beginPostProcess();
277 $this->buildColumnHeaders();
279 $sql = $this->buildQuery(TRUE);
281 $dao = CRM_Core_DAO
::executeQuery($sql);
283 //set pager before exicution of query in function participantInfo()
286 $rows = $graphRows = array();
288 while ($dao->fetch()) {
290 foreach ($this->_columnHeaders
as $key => $value) {
291 if (($key == 'civicrm_event_start_date') ||
($key == 'civicrm_event_end_date')) {
292 //get event start date and end date in custom datetime format
293 $row[$key] = CRM_Utils_Date
::customFormat($dao->$key);
296 if (isset($dao->$key)) {
297 $row[$key] = $dao->$key;
304 $participant_info = $this->participantInfo();
305 foreach ($rows as $key => $value) {
306 if (array_key_exists($value['civicrm_event_id'], $participant_info)) {
307 foreach ($participant_info[$value['civicrm_event_id']] as $k => $v) {
308 $rows[$key][$k] = $v;
313 // do not call pager here
314 $this->formatDisplay($rows, FALSE);
315 unset($this->_columnHeaders
['civicrm_event_id']);
317 $this->doTemplateAssignment($rows);
319 $this->endPostProcess($rows);
322 function buildChart(&$rows) {
323 $this->_interval
= 'events';
325 if (!empty($this->_params
['charts'])) {
326 foreach ($rows as $key => $value) {
327 $graphRows['totalAmount'][] = $graphRows['value'][] = CRM_Utils_Array
::value('totalAmount', $rows[$key]);
328 $graphRows[$this->_interval
][] = substr($rows[$key]['civicrm_event_title'], 0, 12) . "..(" . $rows[$key]['civicrm_event_id'] . ") ";
331 if (CRM_Utils_Array
::value('totalAmount', $rows[$key]) == 0) {
332 $countEvent = count($rows);
335 if ((!empty($rows)) && $countEvent != 1) {
336 $config = CRM_Core_Config
::Singleton();
338 'legend' => 'Event Summary',
340 'yname' => "Total Amount ({$config->defaultCurrency})",
342 if (!empty($graphRows)) {
343 foreach ($graphRows[$this->_interval
] as $key => $val) {
344 $graph[$val] = $graphRows['value'][$key];
346 $chartInfo['values'] = $graph;
347 $chartInfo['xLabelAngle'] = 20;
350 CRM_Utils_OpenFlashChart
::buildChart($chartInfo, $this->_params
['charts']);
351 $this->assign('chartType', $this->_params
['charts']);
357 function alterDisplay(&$rows) {
359 if (is_array($rows)) {
360 $eventType = CRM_Core_OptionGroup
::values('event_type');
362 foreach ($rows as $rowNum => $row) {
363 if (array_key_exists('totalAmount', $row) && array_key_exists('currency', $row)) {
364 $rows[$rowNum]['totalAmount'] = CRM_Utils_Money
::format($rows[$rowNum]['totalAmount'], $rows[$rowNum]['currency']);
366 if (array_key_exists('civicrm_event_title', $row)) {
367 if ($value = $row['civicrm_event_id']) {
368 //CRM_Event_PseudoConstant::event( $value, false );
369 $url = CRM_Report_Utils_Report
::getNextUrl('event/income',
370 'reset=1&force=1&id_op=in&id_value=' . $value,
371 $this->_absoluteUrl
, $this->_id
, $this->_drilldownReport
373 $rows[$rowNum]['civicrm_event_title_link'] = $url;
374 $rows[$rowNum]['civicrm_event_title_hover'] = ts('View Event Income For this Event');
379 if (array_key_exists('civicrm_event_event_type_id', $row)) {
380 if ($value = $row['civicrm_event_event_type_id']) {
381 $rows[$rowNum]['civicrm_event_event_type_id'] = $eventType[$value];