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_ParticipantListCount
extends CRM_Report_Form_Event
{
38 protected $_summary = NULL;
39 protected $_groupFilter = TRUE;
40 protected $_tagFilter = TRUE;
41 protected $_customGroupExtends = array(
46 public $_drilldownReport = array('event/income' => 'Link to Detail Report');
54 function __construct() {
55 $this->_columns
= array(
58 'dao' => 'CRM_Contact_DAO_Contact',
62 array('title' => ts('Name'),
73 'grouping' => 'contact-fields',
76 array('title' => ts('Participant Name'),
83 'dao' => 'CRM_Contact_DAO_Contact',
84 'grouping' => 'contact-fields',
90 'organization_name' => array(
91 'title' => 'Employer',
99 'dao' => 'CRM_Core_DAO_Email',
102 array('title' => ts('Email'),
106 'grouping' => 'contact-fields',
110 array('title' => ts('Participant E-mail'),
111 'operator' => 'like',
117 'dao' => 'CRM_Core_DAO_Phone',
118 'grouping' => 'contact-fields',
121 'title' => ts( 'Phone No' ),
128 'dao' => 'CRM_Core_DAO_Address',
131 'street_address' => NULL,
133 'postal_code' => NULL,
134 'state_province_id' =>
135 array('title' => ts('State/Province'),
138 array('title' => ts('Country'),
141 'grouping' => 'contact-fields',
143 'civicrm_participant' =>
145 'dao' => 'CRM_Event_DAO_Participant',
149 array('title' => ts('Participant ID'),
153 array('title' => ts('Event'),
154 'type' => CRM_Utils_Type
::T_STRING
,
157 array('title' => ts('Role'),
161 array('title' => ts('Status'),
164 'participant_register_date' =>
165 array('title' => ts('Registration Date'),
168 'grouping' => 'event-fields',
172 'name' => 'event_id',
173 'title' => ts('Event'),
174 'operatorType' => CRM_Report_Form
::OP_ENTITYREF
,
175 'type' => CRM_Utils_Type
::T_INT
,
176 'attributes' => array('entity' => 'event', 'select' => array('minimumInputLength' => 0)),
180 'name' => 'status_id',
181 'title' => ts('Participant Status'),
182 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
183 'options' => CRM_Event_PseudoConstant
::participantStatus(NULL, NULL, 'label'),
188 'title' => ts('Participant Role'),
189 'operatorType' => CRM_Report_Form
::OP_MULTISELECT_SEPARATOR
,
190 'options' => CRM_Event_PseudoConstant
::participantRole(),
192 'participant_register_date' => array('title' => ts('Registration Date'),
193 'operatorType' => CRM_Report_Form
::OP_DATE
,
199 array('title' => ts('Event'),
205 'dao' => 'CRM_Event_DAO_Event',
209 array('title' => ts('Event Type'),
212 array('title' => ts('Event Start Date'),
215 array('title' => ts('Event End Date'),
218 'grouping' => 'event-fields',
222 'name' => 'event_type_id',
223 'title' => ts('Event Type'),
224 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
225 'options' => CRM_Core_OptionGroup
::values('event_type'),
227 'event_start_date' =>
229 'name' => 'start_date',
230 'title' => ts('Event Start Date'),
231 'operatorType' => CRM_Report_Form
::OP_DATE
,
235 'name' => 'end_date',
236 'title' => ts('Event End Date'),
237 'operatorType' => CRM_Report_Form
::OP_DATE
,
243 array('title' => ts('Event Type '),
247 'civicrm_line_item' =>
249 'dao' => 'CRM_Price_DAO_LineItem',
253 array('title' => ts('Income'),
256 array('sum' => ts('Amount'),
257 'avg' => ts('Average'),
260 'participant_count' =>
261 array('title' => ts('Count'),
264 array('sum' => ts('Count'),
271 $this->_options
= array(
272 'blank_column_begin' =>
273 array('title' => ts('Blank column at the Begining'),
274 'type' => 'checkbox',
276 'blank_column_end' =>
277 array('title' => ts('Blank column at the End'),
287 parent
::__construct();
290 function preProcess() {
291 parent
::preProcess();
300 function statistics(&$rows) {
302 $statistics = parent
::statistics($rows);
304 $select = " SELECT SUM( {$this->_aliases['civicrm_line_item']}.participant_count ) as count,
305 SUM( {$this->_aliases['civicrm_line_item']}.line_total ) as amount
307 $sql = "{$select} {$this->_from} {$this->_where}";
308 $dao = CRM_Core_DAO
::executeQuery($sql);
311 if ($dao->count
&& $dao->amount
) {
312 $avg = $dao->amount
/ $dao->count
;
314 $statistics['counts']['count'] = array(
315 'value' => $dao->count
,
316 'title' => 'Total Participants',
317 'type' => CRM_Utils_Type
::T_INT
,
319 $statistics['counts']['amount'] = array(
320 'value' => $dao->amount
,
321 'title' => 'Total Income',
322 'type' => CRM_Utils_Type
::T_MONEY
,
324 $statistics['counts']['avg '] = array(
326 'title' => 'Average',
327 'type' => CRM_Utils_Type
::T_MONEY
,
336 $this->_columnHeaders
= array();
338 //add blank column at the Start
339 if (array_key_exists('options', $this->_params
) && !empty($this->_params
['options']['blank_column_begin'])) {
340 $select[] = " '' as blankColumnBegin";
341 $this->_columnHeaders
['blankColumnBegin']['title'] = '_ _ _ _';
343 foreach ($this->_columns
as $tableName => $table) {
344 if (array_key_exists('fields', $table)) {
345 foreach ($table['fields'] as $fieldName => $field) {
346 if (!empty($field['required']) ||
!empty($this->_params
['fields'][$fieldName])) {
347 if (!empty($field['statistics'])) {
348 foreach ($field['statistics'] as $stat => $label) {
349 switch (strtolower($stat)) {
351 $select[] = "SUM({$field['dbAlias']}) as {$tableName}_{$fieldName}_{$stat}";
352 $this->_columnHeaders
["{$tableName}_{$fieldName}_{$stat}"]['type'] = CRM_Utils_Type
::T_INT
;
353 $this->_columnHeaders
["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
354 $this->_statFields
[] = "{$tableName}_{$fieldName}_{$stat}";
360 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
361 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
362 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = $field['title'];
368 //add blank column at the end
369 if ($blankcols = CRM_Utils_Array
::value('blank_column_end', $this->_params
)) {
370 for ($i = 1; $i <= $blankcols; $i++
) {
371 $select[] = " '' as blankColumnEnd_{$i}";
372 $this->_columnHeaders
["blank_{$i}"]['title'] = "_ _ _ _";
375 $this->_select
= "SELECT " . implode(', ', $select) . " ";
385 static function formRule($fields, $files, $self) {
386 $errors = $grouping = array();
392 FROM civicrm_participant {$this->_aliases['civicrm_participant']}
393 LEFT JOIN civicrm_event {$this->_aliases['civicrm_event']}
394 ON ({$this->_aliases['civicrm_event']}.id = {$this->_aliases['civicrm_participant']}.event_id ) AND {$this->_aliases['civicrm_event']}.is_template = 0
395 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
396 ON ({$this->_aliases['civicrm_participant']}.contact_id = {$this->_aliases['civicrm_contact']}.id )
398 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_employer']}
399 ON ({$this->_aliases['civicrm_employer']}.id = {$this->_aliases['civicrm_contact']}.employer_id )
400 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
401 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND
402 {$this->_aliases['civicrm_address']}.is_primary = 1
403 LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
404 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND
405 {$this->_aliases['civicrm_email']}.is_primary = 1)
406 LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
407 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
408 {$this->_aliases['civicrm_phone']}.is_primary = 1
409 LEFT JOIN civicrm_line_item {$this->_aliases['civicrm_line_item']}
410 ON {$this->_aliases['civicrm_line_item']}.entity_table = 'civicrm_participant' AND {$this->_aliases['civicrm_participant']}.id ={$this->_aliases['civicrm_line_item']}.entity_id";
413 function storeWhereHavingClauseArray() {
414 parent
::storeWhereHavingClauseArray();
415 $this->_whereClauses
[] = "{$this->_aliases['civicrm_participant']}.is_test = 0";
419 $this->_groupBy
= "";
420 if (!empty($this->_params
['group_bys']) &&
421 is_array($this->_params
['group_bys']) &&
422 !empty($this->_params
['group_bys'])
424 foreach ($this->_columns
as $tableName => $table) {
425 if (array_key_exists('group_bys', $table)) {
426 foreach ($table['group_bys'] as $fieldName => $field) {
427 if (!empty($this->_params
['group_bys'][$fieldName])) {
428 $this->_groupBy
[] = $field['dbAlias'];
435 if (!empty($this->_groupBy
)) {
436 $this->_groupBy
= "ORDER BY " . implode(', ', $this->_groupBy
) . ", {$this->_aliases['civicrm_contact']}.sort_name";
439 $this->_groupBy
= "ORDER BY {$this->_aliases['civicrm_contact']}.sort_name";
441 $this->_groupBy
= "GROUP BY {$this->_aliases['civicrm_participant']}.id " . $this->_groupBy
;
444 function postProcess() {
446 // get ready with post process params
447 $this->beginPostProcess();
449 // get the acl clauses built before we assemble the query
450 $this->buildACLClause($this->_aliases
['civicrm_contact']);
452 $sql = $this->buildQuery(TRUE);
454 // build array of result based on column headers. This method also allows
455 // modifying column headers before using it to build result set i.e $rows.
456 $this->buildRows($sql, $rows);
458 // format result set.
459 $this->formatDisplay($rows);
461 // assign variables to templates
462 $this->doTemplateAssignment($rows);
464 // do print / pdf / instance stuff if needed
465 $this->endPostProcess($rows);
471 function alterDisplay(&$rows) {
474 $eventType = CRM_Core_OptionGroup
::values('event_type');
476 foreach ($rows as $rowNum => $row) {
478 // convert sort name to links
479 if (array_key_exists('civicrm_contact_sort_name', $row) &&
480 array_key_exists('civicrm_contact_id', $row)
482 if ($value = $row['civicrm_contact_sort_name']) {
483 $url = CRM_Utils_System
::url("civicrm/contact/view",
484 'reset=1&cid=' . $row['civicrm_contact_id'],
487 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
488 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact Summary for this Contact.");
493 // convert participant ID to links
494 if (array_key_exists('civicrm_participant_participant_id', $row) &&
495 array_key_exists('civicrm_contact_id', $row)
497 if ($value = $row['civicrm_participant_participant_id']) {
498 $url = CRM_Utils_System
::url("civicrm/contact/view/participant",
499 'reset=1&id=' . $row['civicrm_participant_participant_id'] . '&cid=' . $row['civicrm_contact_id'] . '&action=view&context=participant',
502 $rows[$rowNum]['civicrm_participant_participant_id_link'] = $url;
503 $rows[$rowNum]['civicrm_participant_participant_id_hover'] = ts("View Participant Record for this Contact.");
508 // convert event name to links
509 if (array_key_exists('civicrm_participant_event_id', $row)) {
510 if ($value = $row['civicrm_participant_event_id']) {
511 $rows[$rowNum]['civicrm_participant_event_id'] = CRM_Event_PseudoConstant
::event($value, FALSE);
512 $url = CRM_Report_Utils_Report
::getNextUrl('event/Income',
513 'reset=1&force=1&event_id_op=eq&event_id_value=' . $value,
514 $this->_absoluteUrl
, $this->_id
, $this->_drilldownReport
516 $rows[$rowNum]['civicrm_participant_event_id_link'] = $url;
517 $rows[$rowNum]['civicrm_participant_event_id_hover'] = ts("View Event Income Details for this Event");
522 // handle event type id
523 if (array_key_exists('civicrm_event_event_type_id', $row)) {
524 if ($value = $row['civicrm_event_event_type_id']) {
525 $rows[$rowNum]['civicrm_event_event_type_id'] = $eventType[$value];
530 // handle participant status id
531 if (array_key_exists('civicrm_participant_status_id', $row)) {
532 if ($value = $row['civicrm_participant_status_id']) {
533 $rows[$rowNum]['civicrm_participant_status_id'] = CRM_Event_PseudoConstant
::participantStatus($value, FALSE);
538 // handle participant role id
539 if (array_key_exists('civicrm_participant_role_id', $row)) {
540 if ($value = $row['civicrm_participant_role_id']) {
541 $roles = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $value);
543 foreach ($roles as $role) {
544 $value[$role] = CRM_Event_PseudoConstant
::participantRole($role, FALSE);
546 $rows[$rowNum]['civicrm_participant_role_id'] = implode(', ', $value);
552 // skip looking further in rows, if first row itself doesn't
553 // have the column we need