3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | 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-2015
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(
51 public $_drilldownReport = array('event/participantlist' => 'Link to Detail Report');
57 public function __construct() {
59 $this->_columns
= array(
60 'civicrm_event' => array(
61 'dao' => 'CRM_Event_DAO_Event',
64 'title' => ts('Event'),
68 'title' => 'Event ID',
72 'event_type_id' => array(
73 'title' => ts('Event Type'),
76 'title' => ts('Fee Label'),
78 'event_start_date' => array(
79 'title' => ts('Event Start Date'),
81 'event_end_date' => array(
82 'title' => ts('Event End Date'),
84 'max_participants' => array(
85 'title' => ts('Capacity'),
86 'type' => CRM_Utils_Type
::T_INT
,
91 'title' => ts('Event'),
92 'operatorType' => CRM_Report_Form
::OP_ENTITYREF
,
93 'type' => CRM_Utils_Type
::T_INT
,
94 'attributes' => array('select' => array('minimumInputLength' => 0)),
96 'event_type_id' => array(
97 'name' => 'event_type_id',
98 'title' => ts('Event Type'),
99 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
100 'options' => CRM_Core_OptionGroup
::values('event_type'),
102 'event_start_date' => array(
103 'title' => ts('Event Start Date'),
104 'operatorType' => CRM_Report_Form
::OP_DATE
,
106 'event_end_date' => array(
107 'title' => ts('Event End Date'),
108 'operatorType' => CRM_Report_Form
::OP_DATE
,
112 'civicrm_line_item' => array(
113 'dao' => 'CRM_Price_DAO_LineItem',
115 'participant_count' => array(
116 'title' => ts('Participants'),
118 'statistics' => array(
119 'count' => ts('Participants'),
122 'line_total' => array(
123 'title' => ts('Income Statistics'),
124 'type' => CRM_Utils_Type
::T_MONEY
,
126 'statistics' => array(
127 'sum' => ts('Income'),
128 'avg' => ts('Average'),
133 'civicrm_participant' => array(
134 'dao' => 'CRM_Event_DAO_Participant',
137 'name' => 'status_id',
138 'title' => ts('Participant Status'),
139 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
140 'options' => CRM_Event_PseudoConstant
::participantStatus(),
144 'title' => ts('Participant Role'),
145 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
146 'options' => CRM_Event_PseudoConstant
::participantRole(),
148 'participant_register_date' => array(
149 'title' => ts('Registration Date'),
150 'operatorType' => CRM_Report_Form
::OP_DATE
,
155 parent
::__construct();
158 public function preProcess() {
159 parent
::preProcess();
162 public function select() {
164 foreach ($this->_columns
as $tableName => $table) {
165 if (array_key_exists('fields', $table)) {
166 foreach ($table['fields'] as $fieldName => $field) {
167 if (!empty($field['required']) ||
168 !empty($this->_params
['fields'][$fieldName])
170 if (!empty($field['statistics'])) {
171 foreach ($field['statistics'] as $stat => $label) {
172 switch (strtolower($stat)) {
174 $select[] = "SUM({$field['dbAlias']}) as {$tableName}_{$fieldName}_{$stat}";
175 $this->_columnHeaders
["{$tableName}_{$fieldName}_{$stat}"]['type'] = CRM_Utils_Type
::T_INT
;
176 $this->_columnHeaders
["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
177 $this->_statFields
[] = "{$tableName}_{$fieldName}_{$stat}";
181 $select[] = "SUM({$field['dbAlias']}) as {$tableName}_{$fieldName}_{$stat}";
182 $this->_columnHeaders
["{$tableName}_{$fieldName}_{$stat}"]['type'] = CRM_Utils_Type
::T_MONEY
;
184 $this->_columnHeaders
["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
185 $this->_statFields
[] = "{$tableName}_{$fieldName}_{$stat}";
189 $this->_columnHeaders
["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
191 $this->_columnHeaders
["{$tableName}_{$fieldName}_{$stat}"]['type'] = CRM_Utils_Type
::T_MONEY
;
192 $this->_statFields
[] = "{$tableName}_{$fieldName}_{$stat}";
197 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
198 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
199 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = $field['title'];
206 $this->_select
= "SELECT " . implode(', ', $select);
209 public function from() {
211 FROM civicrm_event {$this->_aliases['civicrm_event']}
212 LEFT JOIN civicrm_participant {$this->_aliases['civicrm_participant']}
213 ON {$this->_aliases['civicrm_event']}.id = {$this->_aliases['civicrm_participant']}.event_id AND
214 {$this->_aliases['civicrm_participant']}.is_test = 0
215 LEFT JOIN civicrm_line_item {$this->_aliases['civicrm_line_item']}
216 ON {$this->_aliases['civicrm_participant']}.id ={$this->_aliases['civicrm_line_item']}.entity_id AND
217 {$this->_aliases['civicrm_line_item']}.entity_table = 'civicrm_participant' ";
220 public function where() {
222 $this->_participantWhere
= "";
223 foreach ($this->_columns
as $tableName => $table) {
224 if (array_key_exists('filters', $table)) {
225 foreach ($table['filters'] as $fieldName => $field) {
227 if (CRM_Utils_Array
::value('type', $field) & CRM_Utils_Type
::T_DATE
) {
228 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
229 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
230 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
232 if ($relative ||
$from ||
$to) {
233 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
237 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
239 $clause = $this->whereClause($field,
241 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
242 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
243 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
247 if (!empty($this->_params
['id_value'])) {
248 $idValue = is_array($this->_params
['id_value']) ?
implode(',', $this->_params
['id_value']) : $this->_params
['id_value'];
249 $this->_participantWhere
= " AND civicrm_participant.event_id IN ( $idValue ) ";
252 if (!empty($clause)) {
253 $clauses[] = $clause;
258 $clauses[] = "{$this->_aliases['civicrm_event']}.is_template = 0";
259 $this->_where
= "WHERE " . implode(' AND ', $clauses);
267 public function statistics(&$rows) {
268 $statistics = parent
::statistics($rows);
270 SELECT SUM( {$this->_aliases['civicrm_line_item']}.participant_count ) as count,
271 SUM( {$this->_aliases['civicrm_line_item']}.line_total ) as amount";
273 $sql = "{$select} {$this->_from} {$this->_where}";
275 $dao = CRM_Core_DAO
::executeQuery($sql);
279 if ($dao->count
&& $dao->amount
) {
280 $avg = $dao->amount
/ $dao->count
;
282 $statistics['counts']['count'] = array(
283 'value' => $dao->count
,
284 'title' => 'Total Participants',
285 'type' => CRM_Utils_Type
::T_INT
,
287 $statistics['counts']['amount'] = array(
288 'value' => $dao->amount
,
289 'title' => 'Total Income',
290 'type' => CRM_Utils_Type
::T_MONEY
,
292 $statistics['counts']['avg'] = array(
294 'title' => 'Average',
295 'type' => CRM_Utils_Type
::T_MONEY
,
301 public function groupBy() {
302 $this->assign('chartSupported', TRUE);
303 $this->_rollup
= " WITH ROLLUP";
304 $this->_groupBy
= " GROUP BY {$this->_aliases['civicrm_event']}.id {$this->_rollup}";
307 public function postProcess() {
309 $this->beginPostProcess();
311 $sql = $this->buildQuery(TRUE);
313 $dao = CRM_Core_DAO
::executeQuery($sql);
315 //set pager before execution of query in function participantInfo()
318 $rows = $graphRows = array();
321 while ($dao->fetch()) {
323 foreach ($this->_columnHeaders
as $key => $value) {
324 if (($key == 'civicrm_event_start_date') ||
325 ($key == 'civicrm_event_end_date')
327 //get event start date and end date in custom datetime format
328 $row[$key] = CRM_Utils_Date
::customFormat($dao->$key);
330 elseif ($key == 'civicrm_participant_fee_amount_avg') {
331 if ($dao->civicrm_participant_fee_amount_sum
&&
332 $dao->civicrm_line_item_participant_count_count
334 $row[$key] = $dao->civicrm_participant_fee_amount_sum
/
335 $dao->civicrm_line_item_participant_count_count
;
338 elseif ($key == 'civicrm_line_item_line_total_avg') {
339 if ($dao->civicrm_line_item_line_total_sum
&&
340 $dao->civicrm_line_item_participant_count_count
342 $row[$key] = $dao->civicrm_line_item_line_total_sum
/
343 $dao->civicrm_line_item_participant_count_count
;
347 if (isset($dao->$key)) {
348 $row[$key] = $dao->$key;
355 // do not call pager here
356 $this->formatDisplay($rows, FALSE);
357 unset($this->_columnHeaders
['civicrm_event_id']);
359 $this->doTemplateAssignment($rows);
361 $this->endPostProcess($rows);
367 public function buildChart(&$rows) {
369 $this->_interval
= 'events';
371 if (!empty($this->_params
['charts'])) {
372 foreach ($rows as $key => $value) {
373 if ($value['civicrm_event_id']) {
374 $graphRows['totalParticipants'][] = ($rows[$key]['civicrm_line_item_participant_count_count']);
375 $graphRows[$this->_interval
][] = substr($rows[$key]['civicrm_event_title'], 0, 12) . "..(" .
376 $rows[$key]['civicrm_event_id'] . ") ";
377 $graphRows['value'][] = ($rows[$key]['civicrm_line_item_participant_count_count']);
381 if (($rows[$key]['civicrm_line_item_participant_count_count']) == 0) {
382 $countEvent = count($rows);
385 if ((!empty($rows)) && $countEvent != 1) {
387 'legend' => 'Participants Summary',
389 'yname' => 'Total Participants',
391 if (!empty($graphRows)) {
392 foreach ($graphRows[$this->_interval
] as $key => $val) {
393 $graph[$val] = $graphRows['value'][$key];
395 $chartInfo['values'] = $graph;
396 $chartInfo['tip'] = 'Participants : #val#';
397 $chartInfo['xLabelAngle'] = 20;
400 CRM_Utils_OpenFlashChart
::buildChart($chartInfo, $this->_params
['charts']);
407 * Alter display of rows.
409 * Iterate through the rows retrieved via SQL and make changes for display purposes,
410 * such as rendering contacts as links.
413 * Rows generated by SQL, with an array for each row.
415 public function alterDisplay(&$rows) {
417 if (is_array($rows)) {
418 $eventType = CRM_Core_OptionGroup
::values('event_type');
420 foreach ($rows as $rowNum => $row) {
421 if (array_key_exists('civicrm_event_title', $row)) {
422 if ($value = $row['civicrm_event_id']) {
423 CRM_Event_PseudoConstant
::event($value, FALSE);
424 $url = CRM_Report_Utils_Report
::getNextUrl('event/participantlist',
425 'reset=1&force=1&event_id_op=eq&event_id_value=' . $value,
426 $this->_absoluteUrl
, $this->_id
, $this->_drilldownReport
428 $rows[$rowNum]['civicrm_event_title_link'] = $url;
429 $rows[$rowNum]['civicrm_event_title_hover'] = ts("View Event Participants For this Event");
434 if (array_key_exists('civicrm_event_event_type_id', $row)) {
435 if ($value = $row['civicrm_event_event_type_id']) {
436 $rows[$rowNum]['civicrm_event_event_type_id'] = $eventType[$value];