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_ParticipantListing
extends CRM_Report_Form_Event
{
38 protected $_summary = NULL;
40 protected $_contribField = FALSE;
41 protected $_lineitemField = FALSE;
42 protected $_groupFilter = TRUE;
43 protected $_tagFilter = TRUE;
44 protected $activeCampaigns;
46 protected $_customGroupExtends = array(
53 public $_drilldownReport = array('event/income' => 'Link to Detail Report');
61 function __construct() {
62 $this->_autoIncludeIndexedFieldsAsOrderBys
= 1;
64 // Check if CiviCampaign is a) enabled and b) has active campaigns
65 $config = CRM_Core_Config
::singleton();
66 $campaignEnabled = in_array("CiviCampaign", $config->enableComponents
);
67 if ($campaignEnabled) {
68 $getCampaigns = CRM_Campaign_BAO_Campaign
::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE);
69 $this->activeCampaigns
= $getCampaigns['campaigns'];
70 asort($this->activeCampaigns
);
73 $this->_columns
= array(
74 'civicrm_contact' => array(
75 'dao' => 'CRM_Contact_DAO_Contact',
77 'sort_name_linked' => array(
78 'title' => ts('Participant Name'),
81 'dbAlias' => 'contact_civireport.sort_name',
83 'first_name' => array(
84 'title' => ts('First Name'),
87 'title' => ts('Last Name'),
94 'title' => ts('Gender'),
96 'birth_date' => array(
97 'title' => ts('Birth Date'),
100 'title' => ts('Age'),
101 'dbAlias' => 'TIMESTAMPDIFF(YEAR, contact_civireport.birth_date, CURDATE())',
103 'age_at_event' => array(
104 'title' => ts('Age at Event'),
105 'dbAlias' => 'TIMESTAMPDIFF(YEAR, contact_civireport.birth_date, event_civireport.start_date)',
107 'employer_id' => array(
108 'title' => ts('Organization'),
111 'grouping' => 'contact-fields',
112 'order_bys' => array(
113 'sort_name' => array(
114 'title' => ts('Last Name, First Name'),
116 'default_weight' => '0',
117 'default_order' => 'ASC',
119 'gender_id' => array(
120 'name' => 'gender_id',
121 'title' => ts('Gender'),
123 'birth_date' => array(
124 'name' => 'birth_date',
125 'title' => ts('Birth Date'),
127 'age_at_event' => array(
128 'name' => 'age_at_event',
129 'title' => ts('Age at Event'),
133 'sort_name' => array(
134 'title' => ts('Participant Name'),
135 'operator' => 'like',
137 'gender_id' => array(
138 'title' => ts('Gender'),
139 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
140 'options' => CRM_Core_PseudoConstant
::get('CRM_Contact_DAO_Contact', 'gender_id'),
142 'birth_date' => array(
143 'title' => 'Birth Date',
144 'operatorType' => CRM_Report_Form
::OP_DATE
,
145 'type' => CRM_Utils_Type
::T_DATE
149 'civicrm_email' => array(
150 'dao' => 'CRM_Core_DAO_Email',
153 'title' => ts('Email'),
157 'grouping' => 'contact-fields',
160 'title' => ts('Participant E-mail'),
161 'operator' => 'like',
165 'civicrm_address' => array(
166 'dao' => 'CRM_Core_DAO_Address',
168 'street_address' => NULL,
170 'postal_code' => NULL,
171 'state_province_id' => array(
172 'title' => ts('State/Province'),
174 'country_id' => array(
175 'title' => ts('Country'),
178 'grouping' => 'contact-fields',
180 'civicrm_participant' => array(
181 'dao' => 'CRM_Event_DAO_Participant',
183 'participant_id' => array('title' => 'Participant ID'),
184 'participant_record' => array(
186 'no_display' => TRUE,
191 'type' => CRM_Utils_Type
::T_STRING
,
193 'status_id' => array(
194 'title' => ts('Status'),
198 'title' => ts('Role'),
201 'fee_currency' => array(
203 'no_display' => TRUE,
205 'participant_fee_level' => NULL,
206 'participant_fee_amount' => NULL,
207 'participant_register_date' => array('title' => ts('Registration Date')),
209 'grouping' => 'event-fields',
212 'name' => 'event_id',
213 'title' => ts('Event'),
214 'operatorType' => CRM_Report_Form
::OP_ENTITYREF
,
215 'type' => CRM_Utils_Type
::T_INT
,
216 'attributes' => array(
218 'select' => array('minimumInputLength' => 0)
222 'name' => 'status_id',
223 'title' => ts('Participant Status'),
224 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
225 'options' => CRM_Event_PseudoConstant
::participantStatus(NULL, NULL, 'label'),
229 'title' => ts('Participant Role'),
230 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
231 'options' => CRM_Event_PseudoConstant
::participantRole(),
233 'participant_register_date' => array(
234 'title' => 'Registration Date',
235 'operatorType' => CRM_Report_Form
::OP_DATE
,
237 'fee_currency' => array(
238 'title' => ts('Fee Currency'),
239 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
240 'options' => CRM_Core_OptionGroup
::values('currencies_enabled'),
242 'type' => CRM_Utils_Type
::T_STRING
,
246 'order_bys' => array(
247 'participant_register_date' => array(
248 'title' => ts('Registration Date'),
249 'default_weight' => '1',
250 'default_order' => 'ASC',
253 'title' => ts('Event'),
254 'default_weight' => '1',
255 'default_order' => 'ASC'
259 'civicrm_phone' => array(
260 'dao' => 'CRM_Core_DAO_Phone',
263 'title' => ts('Phone'),
268 'grouping' => 'contact-fields',
270 'civicrm_event' => array(
271 'dao' => 'CRM_Event_DAO_Event',
273 'event_type_id' => array('title' => ts('Event Type')),
274 'event_start_date' => array('title' => ts('Event Start Date')),
276 'grouping' => 'event-fields',
279 'name' => 'event_type_id',
280 'title' => ts('Event Type'),
281 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
282 'options' => CRM_Core_OptionGroup
::values('event_type'),
284 'event_start_date' => array(
285 'title' => ts('Event Start Date'),
286 'operatorType' => CRM_Report_Form
::OP_DATE
,
289 'order_bys' => array(
290 'event_type_id' => array(
291 'title' => ts('Event Type'),
292 'default_weight' => '2',
293 'default_order' => 'ASC'
297 'civicrm_contribution' => array(
298 'dao' => 'CRM_Contribute_DAO_Contribution',
300 'contribution_id' => array(
302 'no_display' => TRUE,
304 'csv_display' => TRUE,
305 'title' => ts('Contribution ID'),
307 'financial_type_id' => array('title' => ts('Financial Type')),
308 'receive_date' => array('title' => ts('Payment Date')),
309 'contribution_status_id' => array('title' => ts('Contribution Status')),
310 'payment_instrument_id' => array('title' => ts('Payment Type')),
311 'contribution_source' => array(
313 'title' => ts('Contribution Source'),
320 'fee_amount' => array('title' => ts('Transaction Fee')),
323 'grouping' => 'contrib-fields',
325 'receive_date' => array(
326 'title' => 'Payment Date',
327 'operatorType' => CRM_Report_Form
::OP_DATE
,
329 'financial_type_id' => array(
330 'title' => ts('Financial Type'),
331 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
332 'options' => CRM_Contribute_PseudoConstant
::financialType(),
335 'title' => ts('Contribution Currency'),
336 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
337 'options' => CRM_Core_OptionGroup
::values('currencies_enabled'),
339 'type' => CRM_Utils_Type
::T_STRING
,
341 'payment_instrument_id' => array(
342 'title' => ts('Payment Type'),
343 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
344 'options' => CRM_Contribute_PseudoConstant
::paymentInstrument(),
346 'contribution_status_id' => array(
347 'title' => ts('Contribution Status'),
348 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
349 'options' => CRM_Contribute_PseudoConstant
::contributionStatus(),
354 'civicrm_line_item' => array(
355 'dao' => 'CRM_Price_DAO_LineItem',
356 'grouping' => 'priceset-fields',
358 'price_field_value_id' => array(
359 'name' => 'price_field_value_id',
360 'title' => ts('Fee Level'),
361 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
362 'options' => $this->getPriceLevels(),
369 $this->_options
= array(
370 'blank_column_begin' => array(
371 'title' => ts('Blank column at the Begining'),
372 'type' => 'checkbox',
374 'blank_column_end' => array(
375 'title' => ts('Blank column at the End'),
386 // If we have active campaigns add those elements to both the fields and filters
387 if ($campaignEnabled && !empty($this->activeCampaigns
)) {
388 $this->_columns
['civicrm_participant']['fields']['campaign_id'] =
390 'title' => ts('Campaign'),
391 'default' => 'false',
393 $this->_columns
['civicrm_participant']['filters']['campaign_id'] =
395 'title' => ts('Campaign'),
396 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
397 'options' => $this->activeCampaigns
,
399 $this->_columns
['civicrm_participant']['order_bys']['campaign_id'] =
400 array('title' => ts('Campaign'));
404 $this->_currencyColumn
= 'civicrm_participant_fee_currency';
405 parent
::__construct();
411 function getPriceLevels() {
413 SELECT CONCAT(cv.label, ' (', ps.title, ')') label, cv.id
414 FROM civicrm_price_field_value cv
415 LEFT JOIN civicrm_price_field cf
416 ON cv.price_field_id = cf.id
417 LEFT JOIN civicrm_price_set_entity ce
418 ON ce.price_set_id = cf.price_set_id
419 LEFT JOIN civicrm_price_set ps
420 ON ce.price_set_id = ps.id
421 WHERE ce.entity_table = 'civicrm_event'
424 $dao = CRM_Core_DAO
::executeQuery($query);
426 while ($dao->fetch()) {
427 $elements[$dao->id
] = "$dao->label\n";
431 } //searches database for priceset values
434 function preProcess() {
435 parent
::preProcess();
440 $this->_columnHeaders
= array();
442 //add blank column at the Start
443 if (array_key_exists('options', $this->_params
) &&
444 !empty($this->_params
['options']['blank_column_begin'])
446 $select[] = " '' as blankColumnBegin";
447 $this->_columnHeaders
['blankColumnBegin']['title'] = '_ _ _ _';
449 foreach ($this->_columns
as $tableName => $table) {
450 if ($tableName == 'civicrm_line_item') {
451 $this->_lineitemField
= TRUE;
453 if (array_key_exists('fields', $table)) {
454 foreach ($table['fields'] as $fieldName => $field) {
455 if (!empty($field['required']) ||
456 !empty($this->_params
['fields'][$fieldName])
458 if ($tableName == 'civicrm_contribution') {
459 $this->_contribField
= TRUE;
462 $alias = "{$tableName}_{$fieldName}";
463 $select[] = "{$field['dbAlias']} as $alias";
464 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
465 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['no_display'] = CRM_Utils_Array
::value('no_display', $field);
466 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array
::value('title', $field);
467 $this->_selectAliases
[] = $alias;
472 //add blank column at the end
473 $blankcols = CRM_Utils_Array
::value('blank_column_end', $this->_params
);
475 for ($i = 1; $i <= $blankcols; $i++
) {
476 $select[] = " '' as blankColumnEnd_{$i}";
477 $this->_columnHeaders
["blank_{$i}"]['title'] = "_ _ _ _";
481 $this->_select
= "SELECT " . implode(', ', $select) . " ";
491 static function formRule($fields, $files, $self) {
492 $errors = $grouping = array();
498 FROM civicrm_participant {$this->_aliases['civicrm_participant']}
499 LEFT JOIN civicrm_event {$this->_aliases['civicrm_event']}
500 ON ({$this->_aliases['civicrm_event']}.id = {$this->_aliases['civicrm_participant']}.event_id ) AND
501 {$this->_aliases['civicrm_event']}.is_template = 0
502 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
503 ON ({$this->_aliases['civicrm_participant']}.contact_id = {$this->_aliases['civicrm_contact']}.id )
505 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
506 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND
507 {$this->_aliases['civicrm_address']}.is_primary = 1
508 LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
509 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND
510 {$this->_aliases['civicrm_email']}.is_primary = 1)
511 LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
512 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
513 {$this->_aliases['civicrm_phone']}.is_primary = 1
515 if ($this->_contribField
) {
517 LEFT JOIN civicrm_participant_payment pp
518 ON ({$this->_aliases['civicrm_participant']}.id = pp.participant_id)
519 LEFT JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']}
520 ON (pp.contribution_id = {$this->_aliases['civicrm_contribution']}.id)
523 if ($this->_lineitemField
) {
525 LEFT JOIN civicrm_line_item line_item_civireport
526 ON line_item_civireport.entity_table = 'civicrm_participant' AND
527 line_item_civireport.entity_id = {$this->_aliases['civicrm_participant']}.id
534 foreach ($this->_columns
as $tableName => $table) {
535 if (array_key_exists('filters', $table)) {
536 foreach ($table['filters'] as $fieldName => $field) {
539 if (CRM_Utils_Array
::value('type', $field) & CRM_Utils_Type
::T_DATE
) {
540 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
541 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
542 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
544 if ($relative ||
$from ||
$to) {
545 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
549 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
551 if ($fieldName == 'rid') {
552 $value = CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
);
553 if (!empty($value)) {
554 $clause = "( {$field['dbAlias']} REGEXP '[[:<:]]" .
555 implode('[[:>:]]|[[:<:]]', $value) . "[[:>:]]' )";
561 $clause = $this->whereClause($field,
563 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
564 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
565 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
570 if (!empty($clause)) {
571 $clauses[] = $clause;
576 if (empty($clauses)) {
577 $this->_where
= "WHERE {$this->_aliases['civicrm_participant']}.is_test = 0 ";
581 "WHERE {$this->_aliases['civicrm_participant']}.is_test = 0 AND " .
582 implode(' AND ', $clauses);
584 if ($this->_aclWhere
) {
585 $this->_where
.= " AND {$this->_aclWhere} ";
590 $this->_groupBy
= "GROUP BY {$this->_aliases['civicrm_participant']}.id";
593 function postProcess() {
595 // get ready with post process params
596 $this->beginPostProcess();
598 // get the acl clauses built before we assemble the query
599 $this->buildACLClause($this->_aliases
['civicrm_contact']);
601 $sql = $this->buildQuery(TRUE);
604 // build array of result based on column headers. This method also allows
605 // modifying column headers before using it to build result set i.e $rows.
607 $this->buildRows($sql, $rows);
609 // format result set.
610 $this->formatDisplay($rows);
612 // assign variables to templates
613 $this->doTemplateAssignment($rows);
615 // do print / pdf / instance stuff if needed
616 $this->endPostProcess($rows);
627 private function _initBasicRow(&$rows, &$entryFound, $row, $rowId, $rowNum, $types) {
628 if (!array_key_exists($rowId, $row)) {
632 $value = $row[$rowId];
634 $rows[$rowNum][$rowId] = $types[$value];
642 function alterDisplay(&$rows) {
643 // custom code to alter rows
646 $eventType = CRM_Core_OptionGroup
::values('event_type');
648 $financialTypes = CRM_Contribute_PseudoConstant
::financialType();
649 $contributionStatus = CRM_Contribute_PseudoConstant
::contributionStatus();
650 $paymentInstruments = CRM_Contribute_PseudoConstant
::paymentInstrument();
651 $genders = CRM_Core_PseudoConstant
::get('CRM_Contact_DAO_Contact', 'gender_id', array('localize' => TRUE));
653 foreach ($rows as $rowNum => $row) {
654 // make count columns point to detail report
655 // convert display name to links
656 if (array_key_exists('civicrm_participant_event_id', $row)) {
657 $eventId = $row['civicrm_participant_event_id'];
659 $rows[$rowNum]['civicrm_participant_event_id'] = CRM_Event_PseudoConstant
::event($eventId, FALSE);
661 $url = CRM_Report_Utils_Report
::getNextUrl('event/income',
662 'reset=1&force=1&id_op=in&id_value=' . $eventId,
663 $this->_absoluteUrl
, $this->_id
, $this->_drilldownReport
665 $rows[$rowNum]['civicrm_participant_event_id_link'] = $url;
666 $rows[$rowNum]['civicrm_participant_event_id_hover'] = ts("View Event Income Details for this Event");
671 // handle event type id
672 $this->_initBasicRow($rows, $entryFound, $row, 'civicrm_event_event_type_id', $rowNum, $eventType);
674 // handle participant status id
675 if (array_key_exists('civicrm_participant_status_id', $row)) {
676 $statusId = $row['civicrm_participant_status_id'];
678 $rows[$rowNum]['civicrm_participant_status_id'] = CRM_Event_PseudoConstant
::participantStatus($statusId, FALSE, 'label');
683 // handle participant role id
684 if (array_key_exists('civicrm_participant_role_id', $row)) {
685 $roleId = $row['civicrm_participant_role_id'];
687 $roles = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $roleId);
689 foreach ($roles as $role) {
690 $roleId[$role] = CRM_Event_PseudoConstant
::participantRole($role, FALSE);
692 $rows[$rowNum]['civicrm_participant_role_id'] = implode(', ', $roleId);
697 // Handel value seperator in Fee Level
698 if (array_key_exists('civicrm_participant_participant_fee_level', $row)) {
699 $feeLevel = $row['civicrm_participant_participant_fee_level'];
701 CRM_Event_BAO_Participant
::fixEventLevel($feeLevel);
702 $rows[$rowNum]['civicrm_participant_participant_fee_level'] = $feeLevel;
707 // Convert display name to link
708 $displayName = CRM_Utils_Array
::value('civicrm_contact_sort_name_linked', $row);
709 $cid = CRM_Utils_Array
::value('civicrm_contact_id', $row);
710 $id = CRM_Utils_Array
::value('civicrm_participant_participant_record', $row);
712 if ($displayName && $cid && $id) {
713 $url = CRM_Report_Utils_Report
::getNextUrl('contact/detail',
714 "reset=1&force=1&id_op=eq&id_value=$cid",
715 $this->_absoluteUrl
, $this->_id
, $this->_drilldownReport
718 $viewUrl = CRM_Utils_System
::url("civicrm/contact/view/participant",
719 "reset=1&id=$id&cid=$cid&action=view&context=participant"
722 $contactTitle = ts('View Contact Details');
723 $participantTitle = ts('View Participant Record');
725 $rows[$rowNum]['civicrm_contact_sort_name_linked'] = "<a title='$contactTitle' href=$url>$displayName</a>";
726 if ($this->_outputMode
!== 'csv') {
727 $rows[$rowNum]['civicrm_contact_sort_name_linked'] .=
728 "<span style='float: right;'><a title='$participantTitle' href=$viewUrl>" .
729 ts('View') . "</a></span>";
735 if (array_key_exists('civicrm_address_country_id', $row)) {
736 $countryId = $row['civicrm_address_country_id'];
738 $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant
::country($countryId, TRUE);
743 // Handle state/province id
744 if (array_key_exists('civicrm_address_state_province_id', $row)) {
745 $provinceId = $row['civicrm_address_state_province_id'];
747 $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant
::stateProvince($provinceId, TRUE);
752 // Handle employer id
753 if (array_key_exists('civicrm_contact_employer_id', $row)) {
754 $employerId = $row['civicrm_contact_employer_id'];
756 $rows[$rowNum]['civicrm_contact_employer_id'] = CRM_Contact_BAO_Contact
::displayName($employerId);
757 $url = CRM_Utils_System
::url('civicrm/contact/view',
758 'reset=1&cid=' . $employerId, $this->_absoluteUrl
760 $rows[$rowNum]['civicrm_contact_employer_id_link'] = $url;
761 $rows[$rowNum]['civicrm_contact_employer_id_hover'] = ts('View Contact Summary for this Contact.');
765 // Convert campaign_id to campaign title
766 $this->_initBasicRow($rows, $entryFound, $row, 'civicrm_participant_campaign_id', $rowNum, $this->activeCampaigns
);
768 // handle contribution status
769 $this->_initBasicRow($rows, $entryFound, $row, 'civicrm_contribution_contribution_status_id', $rowNum, $contributionStatus);
771 // handle payment instrument
772 $this->_initBasicRow($rows, $entryFound, $row, 'civicrm_contribution_payment_instrument_id', $rowNum, $paymentInstruments);
774 // handle financial type
775 $this->_initBasicRow($rows, $entryFound, $row, 'civicrm_contribution_financial_type_id', $rowNum, $financialTypes);
778 $this->_initBasicRow($rows, $entryFound, $row, 'civicrm_contact_gender_id', $rowNum, $genders);
780 // display birthday in the configured custom format
781 if (array_key_exists('civicrm_contact_birth_date', $row)) {
782 $birthDate = $row['civicrm_contact_birth_date'];
784 $rows[$rowNum]['civicrm_contact_birth_date'] = CRM_Utils_Date
::customFormat($birthDate, '%Y%m%d');
789 // skip looking further in rows, if first row itself doesn't
790 // have the column we need