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. |
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 along with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2013
35 class CRM_Report_Form_Event_IncomeCountSummary
extends CRM_Report_Form_Event
{
37 protected $_summary = NULL;
39 protected $_charts = array(
41 'barChart' => 'Bar Chart',
42 'pieChart' => 'Pie Chart',
45 protected $_add2groupSupported = FALSE;
47 protected $_customGroupExtends = array(
50 public $_drilldownReport = array('event/participantlist' => 'Link to Detail Report');
52 function __construct() {
54 $this->_columns
= array(
57 'dao' => 'CRM_Event_DAO_Event',
60 'title' => array('title' => ts('Event'),
67 'event_type_id' => array('title' => ts('Event Type'),
69 'fee_label' => array('title' => ts('Fee Label')),
70 'event_start_date' => array('title' => ts('Event Start Date'),
72 '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('title' => ts('Event Start Date'),
91 'operatorType' => CRM_Report_Form
::OP_DATE
,
93 'event_end_date' => array('title' => ts('Event End Date'),
94 'operatorType' => CRM_Report_Form
::OP_DATE
,
98 'civicrm_line_item' =>
100 'dao' => 'CRM_Price_DAO_LineItem',
103 'participant_count' => array(
104 'title' => ts('Participants'),
107 array('count' => ts('Participants'),
110 'line_total' => array(
111 'title' => ts('Income Statistics'),
112 'type' => CRM_Utils_Type
::T_MONEY
,
115 array('sum' => ts('Income'),
116 'avg' => ts('Average'),
121 'civicrm_participant' =>
123 'dao' => 'CRM_Event_DAO_Participant',
126 'sid' => array('name' => 'status_id',
127 'title' => ts('Participant Status'),
128 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
129 'options' => CRM_Event_PseudoConstant
::participantStatus(),
133 'title' => ts('Participant Role'),
134 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
135 'options' => CRM_Event_PseudoConstant
::participantRole(),
137 'participant_register_date' => array('title' => ts('Registration Date'),
138 'operatorType' => CRM_Report_Form
::OP_DATE
,
143 parent
::__construct();
146 function preProcess() {
147 parent
::preProcess();
152 foreach ($this->_columns
as $tableName => $table) {
153 if (array_key_exists('fields', $table)) {
154 foreach ($table['fields'] as $fieldName => $field) {
155 if (!empty($field['required']) ||
156 CRM_Utils_Array
::value($fieldName, $this->_params
['fields'])
158 if (!empty($field['statistics'])) {
159 foreach ($field['statistics'] as $stat => $label) {
160 switch (strtolower($stat)) {
162 $select[] = "SUM({$field['dbAlias']}) as {$tableName}_{$fieldName}_{$stat}";
163 $this->_columnHeaders
["{$tableName}_{$fieldName}_{$stat}"]['type'] = CRM_Utils_Type
::T_INT
;
164 $this->_columnHeaders
["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
165 $this->_statFields
[] = "{$tableName}_{$fieldName}_{$stat}";
169 $select[] = "SUM({$field['dbAlias']}) as {$tableName}_{$fieldName}_{$stat}";
170 $this->_columnHeaders
["{$tableName}_{$fieldName}_{$stat}"]['type'] = CRM_Utils_Type
::T_MONEY
;
172 $this->_columnHeaders
["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
173 $this->_statFields
[] = "{$tableName}_{$fieldName}_{$stat}";
177 $this->_columnHeaders
["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
179 $this->_columnHeaders
["{$tableName}_{$fieldName}_{$stat}"]['type'] = CRM_Utils_Type
::T_MONEY
;
180 $this->_statFields
[] = "{$tableName}_{$fieldName}_{$stat}";
185 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
186 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
187 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = $field['title'];
194 $this->_select
= "SELECT " . implode(', ', $select);
199 FROM civicrm_event {$this->_aliases['civicrm_event']}
200 LEFT JOIN civicrm_participant {$this->_aliases['civicrm_participant']}
201 ON {$this->_aliases['civicrm_event']}.id = {$this->_aliases['civicrm_participant']}.event_id AND
202 {$this->_aliases['civicrm_participant']}.is_test = 0
203 LEFT JOIN civicrm_line_item {$this->_aliases['civicrm_line_item']}
204 ON {$this->_aliases['civicrm_participant']}.id ={$this->_aliases['civicrm_line_item']}.entity_id AND
205 {$this->_aliases['civicrm_line_item']}.entity_table = 'civicrm_participant' ";
210 $this->_participantWhere
= "";
211 foreach ($this->_columns
as $tableName => $table) {
212 if (array_key_exists('filters', $table)) {
213 foreach ($table['filters'] as $fieldName => $field) {
215 if (CRM_Utils_Array
::value('type', $field) & CRM_Utils_Type
::T_DATE
) {
216 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
217 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
218 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
220 if ($relative ||
$from ||
$to) {
221 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
225 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
227 $clause = $this->whereClause($field,
229 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
230 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
231 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
235 if (!empty($this->_params
['id_value'])) {
236 $participant = implode(', ', $this->_params
['id_value']);
237 $this->_participantWhere
= " AND civicrm_participant.event_id IN ( {$participant} ) ";
240 if (!empty($clause)) {
241 $clauses[] = $clause;
246 $clauses[] = "({$this->_aliases['civicrm_event']}.is_template IS NULL OR {$this->_aliases['civicrm_event']}.is_template = 0)";
247 $this->_where
= "WHERE " . implode(' AND ', $clauses);
250 function statistics(&$rows) {
251 $statistics = parent
::statistics($rows);
253 SELECT SUM( {$this->_aliases['civicrm_line_item']}.participant_count ) as count,
254 SUM( {$this->_aliases['civicrm_line_item']}.line_total ) as amount";
256 $sql = "{$select} {$this->_from} {$this->_where}";
258 $dao = CRM_Core_DAO
::executeQuery($sql);
261 if ($dao->count
&& $dao->amount
) {
262 $avg = $dao->amount
/ $dao->count
;
264 $statistics['counts']['count'] = array(
265 'value' => $dao->count
,
266 'title' => 'Total Participants',
267 'type' => CRM_Utils_Type
::T_INT
,
269 $statistics['counts']['amount'] = array(
270 'value' => $dao->amount
,
271 'title' => 'Total Income',
272 'type' => CRM_Utils_Type
::T_MONEY
,
274 $statistics['counts']['avg '] = array(
276 'title' => 'Average',
277 'type' => CRM_Utils_Type
::T_MONEY
,
284 $this->assign('chartSupported', TRUE);
285 $this->_rollup
= " WITH ROLLUP";
286 $this->_groupBy
= " GROUP BY {$this->_aliases['civicrm_event']}.id {$this->_rollup}";
289 function postProcess() {
291 $this->beginPostProcess();
293 $sql = $this->buildQuery(TRUE);
295 $dao = CRM_Core_DAO
::executeQuery($sql);
297 //set pager before execution of query in function participantInfo()
300 $rows = $graphRows = array();
303 while ($dao->fetch()) {
305 foreach ($this->_columnHeaders
as $key => $value) {
306 if (($key == 'civicrm_event_start_date') ||
($key == 'civicrm_event_end_date')) {
307 //get event start date and end date in custom datetime format
308 $row[$key] = CRM_Utils_Date
::customFormat($dao->$key);
310 elseif ($key == 'civicrm_participant_fee_amount_avg') {
311 if ($dao->civicrm_participant_fee_amount_sum
&& $dao->civicrm_line_item_participant_count_count
) {
312 $row[$key] = $dao->civicrm_participant_fee_amount_sum
/ $dao->civicrm_line_item_participant_count_count
;
315 elseif ($key == 'civicrm_line_item_line_total_avg') {
316 if ($dao->civicrm_line_item_line_total_sum
&& $dao->civicrm_line_item_participant_count_count
) {
317 $row[$key] = $dao->civicrm_line_item_line_total_sum
/ $dao->civicrm_line_item_participant_count_count
;
321 if (isset($dao->$key)) {
322 $row[$key] = $dao->$key;
329 // do not call pager here
330 $this->formatDisplay($rows, FALSE);
331 unset($this->_columnHeaders
['civicrm_event_id']);
333 $this->doTemplateAssignment($rows);
335 $this->endPostProcess($rows);
338 function buildChart(&$rows) {
340 $this->_interval
= 'events';
342 if (!empty($this->_params
['charts'])) {
343 foreach ($rows as $key => $value) {
344 if ($value['civicrm_event_id']) {
345 $graphRows['totalParticipants'][] = ($rows[$key]['civicrm_line_item_participant_count_count']);
346 $graphRows[$this->_interval
][] = substr($rows[$key]['civicrm_event_title'], 0, 12) . "..(" . $rows[$key]['civicrm_event_id'] . ") ";
347 $graphRows['value'][] = ($rows[$key]['civicrm_line_item_participant_count_count']);
351 if (($rows[$key]['civicrm_line_item_participant_count_count']) == 0) {
352 $countEvent = count($rows);
355 if ((!empty($rows)) && $countEvent != 1) {
357 'legend' => 'Participants Summary',
359 'yname' => 'Total Participants',
361 if (!empty($graphRows)) {
362 foreach ($graphRows[$this->_interval
] as $key => $val) {
363 $graph[$val] = $graphRows['value'][$key];
365 $chartInfo['values'] = $graph;
366 $chartInfo['tip'] = 'Participants : #val#';
367 $chartInfo['xLabelAngle'] = 20;
370 CRM_Utils_OpenFlashChart
::buildChart($chartInfo, $this->_params
['charts']);
376 function alterDisplay(&$rows) {
378 if (is_array($rows)) {
379 $eventType = CRM_Core_OptionGroup
::values('event_type');
381 foreach ($rows as $rowNum => $row) {
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/participantlist',
386 'reset=1&force=1&event_id_op=eq&event_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 Participants 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];