4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.3 |
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_ParticipantListCount
extends CRM_Report_Form_Event
{
38 protected $_summary = NULL;
40 protected $_customGroupExtends = array(
43 public $_drilldownReport = array('event/income' => 'Link to Detail Report');
44 function __construct() {
45 $this->_columns
= array(
48 'dao' => 'CRM_Contact_DAO_Contact',
52 array('title' => ts('Name'),
63 'grouping' => 'contact-fields',
66 array('title' => ts('Participant Name'),
73 'dao' => 'CRM_Core_DAO_Email',
76 array('title' => ts('Email'),
80 'grouping' => 'contact-fields',
84 array('title' => ts('Participant E-mail'),
91 'dao' => 'CRM_Core_DAO_Phone',
92 'grouping' => 'contact-fields',
95 'title' => ts( 'Phone No' ),
102 'dao' => 'CRM_Core_DAO_Address',
105 'street_address' => NULL,
107 'grouping' => 'contact-fields',
109 'civicrm_participant' =>
111 'dao' => 'CRM_Event_DAO_Participant',
115 array('title' => ts('Participant ID'),
119 array('title' => ts('Event'),
120 'type' => CRM_Utils_Type
::T_STRING
,
123 array('title' => ts('Role'),
127 array('title' => ts('Status'),
130 'participant_register_date' =>
131 array('title' => ts('Registration Date'),
134 'grouping' => 'event-fields',
139 'name' => 'event_id',
140 'title' => ts('Event'),
141 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
142 'options' => $this->getEventFilterOptions(),
146 'name' => 'status_id',
147 'title' => ts('Participant Status'),
148 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
149 'options' => CRM_Event_PseudoConstant
::participantStatus(NULL, NULL, 'label'),
154 'title' => ts('Participant Role'),
155 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
156 'options' => CRM_Event_PseudoConstant
::participantRole(),
158 'participant_register_date' => array('title' => ts('Registration Date'),
159 'operatorType' => CRM_Report_Form
::OP_DATE
,
165 array('title' => ts('Event'),
171 'dao' => 'CRM_Event_DAO_Event',
175 array('title' => ts('Event Type'),
178 array('title' => ts('Event Start Date'),
181 array('title' => ts('Event End Date'),
184 'grouping' => 'event-fields',
188 'name' => 'event_type_id',
189 'title' => ts('Event Type'),
190 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
191 'options' => CRM_Core_OptionGroup
::values('event_type'),
193 'event_start_date' =>
195 'name' => 'start_date',
196 'title' => ts('Event Start Date'),
197 'operatorType' => CRM_Report_Form
::OP_DATE
,
201 'name' => 'end_date',
202 'title' => ts('Event End Date'),
203 'operatorType' => CRM_Report_Form
::OP_DATE
,
209 array('title' => ts('Event Type '),
213 'civicrm_line_item' =>
215 'dao' => 'CRM_Price_DAO_LineItem',
219 array('title' => ts('Income'),
222 array('sum' => ts('Amount'),
223 'avg' => ts('Average'),
226 'participant_count' =>
227 array('title' => ts('Count'),
230 array('sum' => ts('Count'),
237 $this->_options
= array(
238 'blank_column_begin' =>
239 array('title' => ts('Blank column at the Begining'),
240 'type' => 'checkbox',
242 'blank_column_end' =>
243 array('title' => ts('Blank column at the End'),
253 parent
::__construct();
256 function preProcess() {
257 parent
::preProcess();
261 function statistics(&$rows) {
263 $statistics = parent
::statistics($rows);
265 $select = " SELECT SUM( {$this->_aliases['civicrm_line_item']}.participant_count ) as count,
266 SUM( {$this->_aliases['civicrm_line_item']}.line_total ) as amount
268 $sql = "{$select} {$this->_from} {$this->_where}";
269 $dao = CRM_Core_DAO
::executeQuery($sql);
272 if ($dao->count
&& $dao->amount
) {
273 $avg = $dao->amount
/ $dao->count
;
275 $statistics['counts']['count'] = array(
276 'value' => $dao->count
,
277 'title' => 'Total Participants',
278 'type' => CRM_Utils_Type
::T_INT
,
280 $statistics['counts']['amount'] = array(
281 'value' => $dao->amount
,
282 'title' => 'Total Income',
283 'type' => CRM_Utils_Type
::T_MONEY
,
285 $statistics['counts']['avg '] = array(
287 'title' => 'Average',
288 'type' => CRM_Utils_Type
::T_MONEY
,
297 $this->_columnHeaders
= array();
299 //add blank column at the Start
300 if (array_key_exists('options', $this->_params
) && CRM_Utils_Array
::value('blank_column_begin', $this->_params
['options'])) {
301 $select[] = " '' as blankColumnBegin";
302 $this->_columnHeaders
['blankColumnBegin']['title'] = '_ _ _ _';
304 foreach ($this->_columns
as $tableName => $table) {
305 if (array_key_exists('fields', $table)) {
306 foreach ($table['fields'] as $fieldName => $field) {
307 if (CRM_Utils_Array
::value('required', $field) ||
308 CRM_Utils_Array
::value($fieldName, $this->_params
['fields'])
310 if (CRM_Utils_Array
::value('statistics', $field)) {
311 foreach ($field['statistics'] as $stat => $label) {
312 switch (strtolower($stat)) {
314 $select[] = "SUM({$field['dbAlias']}) as {$tableName}_{$fieldName}_{$stat}";
315 $this->_columnHeaders
["{$tableName}_{$fieldName}_{$stat}"]['type'] = CRM_Utils_Type
::T_INT
;
316 $this->_columnHeaders
["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
317 $this->_statFields
[] = "{$tableName}_{$fieldName}_{$stat}";
323 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
324 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
325 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = $field['title'];
331 //add blank column at the end
332 if ($blankcols = CRM_Utils_Array
::value('blank_column_end', $this->_params
)) {
333 for ($i = 1; $i <= $blankcols; $i++
) {
334 $select[] = " '' as blankColumnEnd_{$i}";
335 $this->_columnHeaders
["blank_{$i}"]['title'] = "_ _ _ _";
338 $this->_select
= "SELECT " . implode(', ', $select) . " ";
341 static function formRule($fields, $files, $self) {
342 $errors = $grouping = array();
348 FROM civicrm_participant {$this->_aliases['civicrm_participant']}
349 LEFT JOIN civicrm_event {$this->_aliases['civicrm_event']}
350 ON ({$this->_aliases['civicrm_event']}.id = {$this->_aliases['civicrm_participant']}.event_id ) AND ({$this->_aliases['civicrm_event']}.is_template IS NULL OR {$this->_aliases['civicrm_event']}.is_template = 0)
351 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
352 ON ({$this->_aliases['civicrm_participant']}.contact_id = {$this->_aliases['civicrm_contact']}.id )
354 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
355 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND
356 {$this->_aliases['civicrm_address']}.is_primary = 1
357 LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
358 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND
359 {$this->_aliases['civicrm_email']}.is_primary = 1)
360 LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
361 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
362 {$this->_aliases['civicrm_phone']}.is_primary = 1
363 LEFT JOIN civicrm_line_item {$this->_aliases['civicrm_line_item']}
364 ON {$this->_aliases['civicrm_participant']}.id ={$this->_aliases['civicrm_line_item']}.entity_id AND {$this->_aliases['civicrm_line_item']}.entity_table = 'civicrm_participant'";
369 foreach ($this->_columns
as $tableName => $table) {
370 if (array_key_exists('filters', $table)) {
371 foreach ($table['filters'] as $fieldName => $field) {
373 if (CRM_Utils_Array
::value('type', $field) & CRM_Utils_Type
::T_DATE
) {
374 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
375 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
376 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
378 if ($relative ||
$from ||
$to) {
379 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
383 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
385 if ($fieldName == 'rid') {
386 $value = CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
);
387 if (!empty($value)) {
388 $clause = "( {$field['dbAlias']} REGEXP '[[:<:]]" . implode('[[:>:]]|[[:<:]]', $value) . "[[:>:]]' )";
394 $clause = $this->whereClause($field,
396 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
397 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
398 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
403 if (!empty($clause)) {
404 $clauses[] = $clause;
410 if (empty($clauses)) {
411 $this->_where
= "WHERE {$this->_aliases['civicrm_participant']}.is_test = 0 ";
414 $this->_where
= "WHERE {$this->_aliases['civicrm_participant']}.is_test = 0 AND " . implode(' AND ', $clauses);
416 if ($this->_aclWhere
) {
417 $this->_where
.= " AND {$this->_aclWhere} ";
422 $this->_groupBy
= "";
423 if (CRM_Utils_Array
::value('group_bys', $this->_params
) &&
424 is_array($this->_params
['group_bys']) &&
425 !empty($this->_params
['group_bys'])
427 foreach ($this->_columns
as $tableName => $table) {
428 if (array_key_exists('group_bys', $table)) {
429 foreach ($table['group_bys'] as $fieldName => $field) {
430 if (CRM_Utils_Array
::value($fieldName, $this->_params
['group_bys'])) {
431 $this->_groupBy
[] = $field['dbAlias'];
438 if (!empty($this->_groupBy
)) {
439 $this->_groupBy
= "ORDER BY " . implode(', ', $this->_groupBy
) . ", {$this->_aliases['civicrm_contact']}.sort_name";
442 $this->_groupBy
= "ORDER BY {$this->_aliases['civicrm_contact']}.sort_name";
444 $this->_groupBy
= "GROUP BY {$this->_aliases['civicrm_participant']}.id " . $this->_groupBy
;
447 function postProcess() {
449 // get ready with post process params
450 $this->beginPostProcess();
452 // get the acl clauses built before we assemble the query
453 $this->buildACLClause($this->_aliases
['civicrm_contact']);
455 $sql = $this->buildQuery(TRUE);
457 // build array of result based on column headers. This method also allows
458 // modifying column headers before using it to build result set i.e $rows.
459 $this->buildRows($sql, $rows);
461 // format result set.
462 $this->formatDisplay($rows);
464 // assign variables to templates
465 $this->doTemplateAssignment($rows);
467 // do print / pdf / instance stuff if needed
468 $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