5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2013 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
12 | CiviCRM is free software; you can copy, modify, and distribute it |
13 | under the terms of the GNU Affero General Public License |
14 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
16 | CiviCRM is distributed in the hope that it will be useful, but |
17 | WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
19 | See the GNU Affero General Public License for more details. |
21 | You should have received a copy of the GNU Affero General Public |
22 | License and the CiviCRM Licensing Exception along |
23 | with this program; if not, contact CiviCRM LLC |
24 | at info[AT]civicrm[DOT]org. If you have questions about the |
25 | GNU Affero General Public License or the licensing of CiviCRM, |
26 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
27 +--------------------------------------------------------------------+
33 * @copyright CiviCRM LLC (c) 2004-2013
37 class CRM_Report_Form_Event_ParticipantListCount
extends CRM_Report_Form_Event
{
39 protected $_summary = NULL;
41 protected $_customGroupExtends = array(
44 public $_drilldownReport = array('event/income' => 'Link to Detail Report');
45 function __construct() {
46 $this->_columns
= array(
49 'dao' => 'CRM_Contact_DAO_Contact',
53 array('title' => ts('Name'),
64 'grouping' => 'contact-fields',
67 array('title' => ts('Participant Name'),
74 'dao' => 'CRM_Contact_DAO_Contact',
75 'grouping' => 'contact-fields',
81 'organization_name' => array(
82 'title' => 'Employer',
90 'dao' => 'CRM_Core_DAO_Email',
93 array('title' => ts('Email'),
97 'grouping' => 'contact-fields',
101 array('title' => ts('Participant E-mail'),
102 'operator' => 'like',
108 'dao' => 'CRM_Core_DAO_Phone',
109 'grouping' => 'contact-fields',
112 'title' => ts( 'Phone No' ),
119 'dao' => 'CRM_Core_DAO_Address',
122 'street_address' => NULL,
124 'postal_code' => NULL,
125 'state_province_id' =>
126 array('title' => ts('State/Province'),
129 array('title' => ts('Country'),
132 'grouping' => 'contact-fields',
134 'civicrm_participant' =>
136 'dao' => 'CRM_Event_DAO_Participant',
140 array('title' => ts('Participant ID'),
144 array('title' => ts('Event'),
145 'type' => CRM_Utils_Type
::T_STRING
,
148 array('title' => ts('Role'),
152 array('title' => ts('Status'),
155 'participant_register_date' =>
156 array('title' => ts('Registration Date'),
159 'grouping' => 'event-fields',
164 'name' => 'event_id',
165 'title' => ts('Event'),
166 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
167 'options' => $this->getEventFilterOptions(),
171 'name' => 'status_id',
172 'title' => ts('Participant Status'),
173 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
174 'options' => CRM_Event_PseudoConstant
::participantStatus(NULL, NULL, 'label'),
179 'title' => ts('Participant Role'),
180 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
181 'options' => CRM_Event_PseudoConstant
::participantRole(),
183 'participant_register_date' => array('title' => ts('Registration Date'),
184 'operatorType' => CRM_Report_Form
::OP_DATE
,
190 array('title' => ts('Event'),
196 'dao' => 'CRM_Event_DAO_Event',
200 array('title' => ts('Event Type'),
203 array('title' => ts('Event Start Date'),
206 array('title' => ts('Event End Date'),
209 'grouping' => 'event-fields',
213 'name' => 'event_type_id',
214 'title' => ts('Event Type'),
215 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
216 'options' => CRM_Core_OptionGroup
::values('event_type'),
218 'event_start_date' =>
220 'name' => 'start_date',
221 'title' => ts('Event Start Date'),
222 'operatorType' => CRM_Report_Form
::OP_DATE
,
226 'name' => 'end_date',
227 'title' => ts('Event End Date'),
228 'operatorType' => CRM_Report_Form
::OP_DATE
,
234 array('title' => ts('Event Type '),
238 'civicrm_line_item' =>
240 'dao' => 'CRM_Price_DAO_LineItem',
244 array('title' => ts('Income'),
247 array('sum' => ts('Amount'),
248 'avg' => ts('Average'),
251 'participant_count' =>
252 array('title' => ts('Count'),
255 array('sum' => ts('Count'),
262 $this->_options
= array(
263 'blank_column_begin' =>
264 array('title' => ts('Blank column at the Begining'),
265 'type' => 'checkbox',
267 'blank_column_end' =>
268 array('title' => ts('Blank column at the End'),
278 parent
::__construct();
281 function preProcess() {
282 parent
::preProcess();
286 function statistics(&$rows) {
288 $statistics = parent
::statistics($rows);
290 $select = " SELECT SUM( {$this->_aliases['civicrm_line_item']}.participant_count ) as count,
291 SUM( {$this->_aliases['civicrm_line_item']}.line_total ) as amount
293 $sql = "{$select} {$this->_from} {$this->_where}";
294 $dao = CRM_Core_DAO
::executeQuery($sql);
297 if ($dao->count
&& $dao->amount
) {
298 $avg = $dao->amount
/ $dao->count
;
300 $statistics['counts']['count'] = array(
301 'value' => $dao->count
,
302 'title' => 'Total Participants',
303 'type' => CRM_Utils_Type
::T_INT
,
305 $statistics['counts']['amount'] = array(
306 'value' => $dao->amount
,
307 'title' => 'Total Income',
308 'type' => CRM_Utils_Type
::T_MONEY
,
310 $statistics['counts']['avg '] = array(
312 'title' => 'Average',
313 'type' => CRM_Utils_Type
::T_MONEY
,
322 $this->_columnHeaders
= array();
324 //add blank column at the Start
325 if (array_key_exists('options', $this->_params
) && CRM_Utils_Array
::value('blank_column_begin', $this->_params
['options'])) {
326 $select[] = " '' as blankColumnBegin";
327 $this->_columnHeaders
['blankColumnBegin']['title'] = '_ _ _ _';
329 foreach ($this->_columns
as $tableName => $table) {
330 if (array_key_exists('fields', $table)) {
331 foreach ($table['fields'] as $fieldName => $field) {
332 if (CRM_Utils_Array
::value('required', $field) ||
333 CRM_Utils_Array
::value($fieldName, $this->_params
['fields'])
335 if (CRM_Utils_Array
::value('statistics', $field)) {
336 foreach ($field['statistics'] as $stat => $label) {
337 switch (strtolower($stat)) {
339 $select[] = "SUM({$field['dbAlias']}) as {$tableName}_{$fieldName}_{$stat}";
340 $this->_columnHeaders
["{$tableName}_{$fieldName}_{$stat}"]['type'] = CRM_Utils_Type
::T_INT
;
341 $this->_columnHeaders
["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
342 $this->_statFields
[] = "{$tableName}_{$fieldName}_{$stat}";
348 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
349 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
350 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = $field['title'];
356 //add blank column at the end
357 if ($blankcols = CRM_Utils_Array
::value('blank_column_end', $this->_params
)) {
358 for ($i = 1; $i <= $blankcols; $i++
) {
359 $select[] = " '' as blankColumnEnd_{$i}";
360 $this->_columnHeaders
["blank_{$i}"]['title'] = "_ _ _ _";
363 $this->_select
= "SELECT " . implode(', ', $select) . " ";
366 static function formRule($fields, $files, $self) {
367 $errors = $grouping = array();
373 FROM civicrm_participant {$this->_aliases['civicrm_participant']}
374 LEFT JOIN civicrm_event {$this->_aliases['civicrm_event']}
375 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)
376 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
377 ON ({$this->_aliases['civicrm_participant']}.contact_id = {$this->_aliases['civicrm_contact']}.id )
379 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_employer']}
380 ON ({$this->_aliases['civicrm_employer']}.id = {$this->_aliases['civicrm_contact']}.employer_id )
381 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
382 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND
383 {$this->_aliases['civicrm_address']}.is_primary = 1
384 LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
385 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND
386 {$this->_aliases['civicrm_email']}.is_primary = 1)
387 LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
388 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
389 {$this->_aliases['civicrm_phone']}.is_primary = 1
390 LEFT JOIN civicrm_line_item {$this->_aliases['civicrm_line_item']}
391 ON {$this->_aliases['civicrm_participant']}.id ={$this->_aliases['civicrm_line_item']}.entity_id AND {$this->_aliases['civicrm_line_item']}.entity_table = 'civicrm_participant'";
396 foreach ($this->_columns
as $tableName => $table) {
397 if (array_key_exists('filters', $table)) {
398 foreach ($table['filters'] as $fieldName => $field) {
400 if (CRM_Utils_Array
::value('type', $field) & CRM_Utils_Type
::T_DATE
) {
401 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
402 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
403 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
405 if ($relative ||
$from ||
$to) {
406 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
410 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
412 if ($fieldName == 'rid') {
413 $value = CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
);
414 if (!empty($value)) {
415 $clause = "( {$field['dbAlias']} REGEXP '[[:<:]]" . implode('[[:>:]]|[[:<:]]', $value) . "[[:>:]]' )";
421 $clause = $this->whereClause($field,
423 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
424 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
425 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
430 if (!empty($clause)) {
431 $clauses[] = $clause;
437 if (empty($clauses)) {
438 $this->_where
= "WHERE {$this->_aliases['civicrm_participant']}.is_test = 0 ";
441 $this->_where
= "WHERE {$this->_aliases['civicrm_participant']}.is_test = 0 AND " . implode(' AND ', $clauses);
443 if ($this->_aclWhere
) {
444 $this->_where
.= " AND {$this->_aclWhere} ";
449 $this->_groupBy
= "";
450 if (CRM_Utils_Array
::value('group_bys', $this->_params
) &&
451 is_array($this->_params
['group_bys']) &&
452 !empty($this->_params
['group_bys'])
454 foreach ($this->_columns
as $tableName => $table) {
455 if (array_key_exists('group_bys', $table)) {
456 foreach ($table['group_bys'] as $fieldName => $field) {
457 if (CRM_Utils_Array
::value($fieldName, $this->_params
['group_bys'])) {
458 $this->_groupBy
[] = $field['dbAlias'];
465 if (!empty($this->_groupBy
)) {
466 $this->_groupBy
= "ORDER BY " . implode(', ', $this->_groupBy
) . ", {$this->_aliases['civicrm_contact']}.sort_name";
469 $this->_groupBy
= "ORDER BY {$this->_aliases['civicrm_contact']}.sort_name";
471 $this->_groupBy
= "GROUP BY {$this->_aliases['civicrm_participant']}.id " . $this->_groupBy
;
474 function postProcess() {
476 // get ready with post process params
477 $this->beginPostProcess();
479 // get the acl clauses built before we assemble the query
480 $this->buildACLClause($this->_aliases
['civicrm_contact']);
482 $sql = $this->buildQuery(TRUE);
484 // build array of result based on column headers. This method also allows
485 // modifying column headers before using it to build result set i.e $rows.
486 $this->buildRows($sql, $rows);
488 // format result set.
489 $this->formatDisplay($rows);
491 // assign variables to templates
492 $this->doTemplateAssignment($rows);
494 // do print / pdf / instance stuff if needed
495 $this->endPostProcess($rows);
498 function alterDisplay(&$rows) {
501 $eventType = CRM_Core_OptionGroup
::values('event_type');
503 foreach ($rows as $rowNum => $row) {
505 // convert sort name to links
506 if (array_key_exists('civicrm_contact_sort_name', $row) &&
507 array_key_exists('civicrm_contact_id', $row)
509 if ($value = $row['civicrm_contact_sort_name']) {
510 $url = CRM_Utils_System
::url("civicrm/contact/view",
511 'reset=1&cid=' . $row['civicrm_contact_id'],
514 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
515 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact Summary for this Contact.");
520 // convert participant ID to links
521 if (array_key_exists('civicrm_participant_participant_id', $row) &&
522 array_key_exists('civicrm_contact_id', $row)
524 if ($value = $row['civicrm_participant_participant_id']) {
525 $url = CRM_Utils_System
::url("civicrm/contact/view/participant",
526 'reset=1&id=' . $row['civicrm_participant_participant_id'] . '&cid=' . $row['civicrm_contact_id'] . '&action=view&context=participant',
529 $rows[$rowNum]['civicrm_participant_participant_id_link'] = $url;
530 $rows[$rowNum]['civicrm_participant_participant_id_hover'] = ts("View Participant Record for this Contact.");
535 // convert event name to links
536 if (array_key_exists('civicrm_participant_event_id', $row)) {
537 if ($value = $row['civicrm_participant_event_id']) {
538 $rows[$rowNum]['civicrm_participant_event_id'] = CRM_Event_PseudoConstant
::event($value, FALSE);
539 $url = CRM_Report_Utils_Report
::getNextUrl('event/Income',
540 'reset=1&force=1&event_id_op=eq&event_id_value=' . $value,
541 $this->_absoluteUrl
, $this->_id
, $this->_drilldownReport
543 $rows[$rowNum]['civicrm_participant_event_id_link'] = $url;
544 $rows[$rowNum]['civicrm_participant_event_id_hover'] = ts("View Event Income Details for this Event");
549 // handle event type id
550 if (array_key_exists('civicrm_event_event_type_id', $row)) {
551 if ($value = $row['civicrm_event_event_type_id']) {
552 $rows[$rowNum]['civicrm_event_event_type_id'] = $eventType[$value];
557 // handle participant status id
558 if (array_key_exists('civicrm_participant_status_id', $row)) {
559 if ($value = $row['civicrm_participant_status_id']) {
560 $rows[$rowNum]['civicrm_participant_status_id'] = CRM_Event_PseudoConstant
::participantStatus($value, FALSE);
565 // handle participant role id
566 if (array_key_exists('civicrm_participant_role_id', $row)) {
567 if ($value = $row['civicrm_participant_role_id']) {
568 $roles = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $value);
570 foreach ($roles as $role) {
571 $value[$role] = CRM_Event_PseudoConstant
::participantRole($role, FALSE);
573 $rows[$rowNum]['civicrm_participant_role_id'] = implode(', ', $value);
579 // skip looking further in rows, if first row itself doesn't
580 // have the column we need