4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.4 |
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_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;
45 protected $_customGroupExtends = array('Participant', 'Contact', 'Individual', 'Event');
47 public $_drilldownReport = array('event/income' => 'Link to Detail Report');
49 function __construct() {
50 $this->_autoIncludeIndexedFieldsAsOrderBys
= 1;
52 // Check if CiviCampaign is a) enabled and b) has active campaigns
53 $config = CRM_Core_Config
::singleton();
54 $campaignEnabled = in_array("CiviCampaign", $config->enableComponents
);
55 if ($campaignEnabled) {
56 $getCampaigns = CRM_Campaign_BAO_Campaign
::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE);
57 $this->activeCampaigns
= $getCampaigns['campaigns'];
58 asort($this->activeCampaigns
);
61 $this->_columns
= array(
64 'dao' => 'CRM_Contact_DAO_Contact',
68 array('title' => ts('Participant Name'),
71 'dbAlias' => 'contact_civireport.sort_name',
73 'first_name' => array('title' => ts('First Name'),
75 'last_name' => array('title' => ts('Last Name'),
83 array('title' => ts('Gender'),
86 array('title' => ts('Birth Date'),
90 'dbAlias' => 'TIMESTAMPDIFF(YEAR, contact_civireport.birth_date, CURDATE())',
92 'age_at_event' => array(
93 'title' => ts('Age at Event'),
94 'dbAlias' => 'TIMESTAMPDIFF(YEAR, contact_civireport.birth_date, event_civireport.start_date)',
97 array('title' => ts('Organization'),
100 'grouping' => 'contact-fields',
104 array('title' => ts('Last Name, First Name'),
106 'default_weight' => '0',
107 'default_order' => 'ASC',
111 'name' => 'gender_id',
112 'title' => ts('Gender'),
116 'name' => 'birth_date',
117 'title' => ts('Birth Date'),
121 'name' => 'age_at_event',
122 'title' => ts('Age at Event'),
128 array('title' => ts('Participant Name'),
129 'operator' => 'like',
132 array('title' => ts('Gender'),
133 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
134 'options' => CRM_Core_PseudoConstant
::get('CRM_Contact_DAO_Contact', 'gender_id'),
136 'birth_date' => array(
137 'title' => 'Birth Date',
138 'operatorType' => CRM_Report_Form
::OP_DATE
,
139 'type' => CRM_Utils_Type
::T_DATE
145 'dao' => 'CRM_Core_DAO_Email',
149 array('title' => ts('Email'),
153 'grouping' => 'contact-fields',
157 array('title' => ts('Participant E-mail'),
158 'operator' => 'like',
164 'dao' => 'CRM_Core_DAO_Address',
167 'street_address' => NULL,
169 'postal_code' => NULL,
170 'state_province_id' =>
171 array('title' => ts('State/Province'),
174 array('title' => ts('Country'),
177 'grouping' => 'contact-fields',
179 'civicrm_participant' =>
181 'dao' => 'CRM_Event_DAO_Participant',
183 array('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('title' => ts('Status'),
196 'role_id' => array('title' => ts('Role'),
199 'fee_currency' => array(
201 'no_display' => TRUE,
203 'participant_fee_level' => NULL,
204 'participant_fee_amount' => NULL,
205 'participant_register_date' => array('title' => ts('Registration Date')),
207 'grouping' => 'event-fields',
210 'event_id' => array('name' => 'event_id',
211 'title' => ts('Event'),
212 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
213 'options' => $this->getEventFilterOptions(),
216 'name' => 'status_id',
217 'title' => ts('Participant Status'),
218 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
219 'options' => CRM_Event_PseudoConstant
::participantStatus(NULL, NULL, 'label'),
223 'title' => ts('Participant Role'),
224 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
225 'options' => CRM_Event_PseudoConstant
::participantRole(),
227 'participant_register_date' => array(
228 'title' => 'Registration Date',
229 'operatorType' => CRM_Report_Form
::OP_DATE
,
232 array('title' => ts('Fee Currency'),
233 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
234 'options' => CRM_Core_OptionGroup
::values('currencies_enabled'),
236 'type' => CRM_Utils_Type
::T_STRING
,
243 array('title' => ts('Event'), 'default_weight' => '1', 'default_order' => 'ASC'),
248 'dao' => 'CRM_Core_DAO_Phone',
252 array('title' => ts('Phone'),
257 'grouping' => 'contact-fields',
261 'dao' => 'CRM_Event_DAO_Event',
263 'event_type_id' => array('title' => ts('Event Type')),
264 'event_start_date' => array('title' => ts('Event Start Date')),
266 'grouping' => 'event-fields',
270 'name' => 'event_type_id',
271 'title' => ts('Event Type'),
272 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
273 'options' => CRM_Core_OptionGroup
::values('event_type'),
275 'event_start_date' => array(
276 'title' => ts('Event Start Date'),
277 'operatorType' => CRM_Report_Form
::OP_DATE
,
283 array('title' => ts('Event Type'), 'default_weight' => '2', 'default_order' => 'ASC'),
286 'civicrm_contribution' => array(
287 'dao' => 'CRM_Contribute_DAO_Contribution',
289 'contribution_id' => array(
291 'no_display' => TRUE,
293 'csv_display' => TRUE,
294 'title' => ts('Contribution ID'),
296 'financial_type_id' => array('title' => ts('Financial Type')),
297 'receive_date' => array('title' => ts('Payment Date')),
298 'contribution_status_id' => array('title' => ts('Contribution Status')),
299 'payment_instrument_id' => array('title' => ts('Payment Type')),
300 'contribution_source' => array(
302 'title' => ts('Contribution Source'),
309 'honor_type_id' => array('title' => ts('Honor Type')),
310 'fee_amount' => array('title' => ts('Transaction Fee')),
313 'grouping' => 'contrib-fields',
315 'receive_date' => array(
316 'title' => 'Payment Date',
317 'operatorType' => CRM_Report_Form
::OP_DATE
,
319 'financial_type_id' => array('title' => ts('Financial Type'),
320 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
321 'options' => CRM_Contribute_PseudoConstant
::financialType(),
323 'currency' => array('title' => ts('Contribution Currency'),
324 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
325 'options' => CRM_Core_OptionGroup
::values('currencies_enabled'),
327 'type' => CRM_Utils_Type
::T_STRING
,
329 'payment_instrument_id' => array('title' => ts('Payment Type'),
330 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
331 'options' => CRM_Contribute_PseudoConstant
::paymentInstrument(),
333 'contribution_status_id' => array('title' => ts('Contribution Status'),
334 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
335 'options' => CRM_Contribute_PseudoConstant
::contributionStatus(),
341 'civicrm_line_item' => array(
342 'dao' => 'CRM_Price_DAO_LineItem',
343 'grouping' => 'priceset-fields',
345 'price_field_value_id' => array(
346 'name' => 'price_field_value_id',
347 'title' => ts('Fee Level'),
348 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
349 'options' => $this->getPriceLevels(),
356 $this->_options
= array(
357 'blank_column_begin' => array(
358 'title' => ts('Blank column at the Begining'),
359 'type' => 'checkbox',
361 'blank_column_end' => array(
362 'title' => ts('Blank column at the End'),
373 // If we have active campaigns add those elements to both the fields and filters
374 if ($campaignEnabled && !empty($this->activeCampaigns
)) {
375 $this->_columns
['civicrm_participant']['fields']['campaign_id'] =
377 'title' => ts('Campaign'),
378 'default' => 'false',
380 $this->_columns
['civicrm_participant']['filters']['campaign_id'] =
382 'title' => ts('Campaign'),
383 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
384 'options' => $this->activeCampaigns
,
386 $this->_columns
['civicrm_participant']['order_bys']['campaign_id'] =
387 array('title' => ts('Campaign'));
391 $this->_currencyColumn
= 'civicrm_participant_fee_currency';
392 parent
::__construct();
395 function getPriceLevels() {
397 SELECT DISTINCT cv.label, cv.id
398 FROM civicrm_price_field_value cv
399 LEFT JOIN civicrm_price_field cf ON cv.price_field_id = cf.id
400 LEFT JOIN civicrm_price_set_entity ce ON ce.price_set_id = cf.price_set_id
401 WHERE ce.entity_table = 'civicrm_event'
404 $dao = CRM_Core_DAO
::executeQuery($query);
406 while ($dao->fetch()) {
407 $elements[$dao->id
] = "$dao->label\n";
411 } //searches database for priceset values
414 function preProcess() {
415 parent
::preProcess();
420 $this->_columnHeaders
= array();
422 //add blank column at the Start
423 if (array_key_exists('options', $this->_params
) && !empty($this->_params
['options']['blank_column_begin'])) {
424 $select[] = " '' as blankColumnBegin";
425 $this->_columnHeaders
['blankColumnBegin']['title'] = '_ _ _ _';
427 foreach ($this->_columns
as $tableName => $table) {
428 if ($tableName == 'civicrm_line_item'){
429 $this->_lineitemField
= TRUE;
431 if (array_key_exists('fields', $table)) {
432 foreach ($table['fields'] as $fieldName => $field) {
433 if (!empty($field['required']) ||
!empty($this->_params
['fields'][$fieldName])) {
434 if ($tableName == 'civicrm_contribution') {
435 $this->_contribField
= TRUE;
438 $alias = "{$tableName}_{$fieldName}";
439 $select[] = "{$field['dbAlias']} as $alias";
440 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
441 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['no_display'] = CRM_Utils_Array
::value('no_display', $field);
442 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array
::value('title', $field);
443 $this->_selectAliases
[] = $alias;
448 //add blank column at the end
449 if ($blankcols = CRM_Utils_Array
::value('blank_column_end', $this->_params
)) {
450 for ($i = 1; $i <= $blankcols; $i++
) {
451 $select[] = " '' as blankColumnEnd_{$i}";
452 $this->_columnHeaders
["blank_{$i}"]['title'] = "_ _ _ _";
456 $this->_select
= "SELECT " . implode(', ', $select) . " ";
459 static function formRule($fields, $files, $self) {
460 $errors = $grouping = array();
466 FROM civicrm_participant {$this->_aliases['civicrm_participant']}
467 LEFT JOIN civicrm_event {$this->_aliases['civicrm_event']}
468 ON ({$this->_aliases['civicrm_event']}.id = {$this->_aliases['civicrm_participant']}.event_id ) AND
469 ({$this->_aliases['civicrm_event']}.is_template IS NULL OR
470 {$this->_aliases['civicrm_event']}.is_template = 0)
471 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
472 ON ({$this->_aliases['civicrm_participant']}.contact_id = {$this->_aliases['civicrm_contact']}.id )
474 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
475 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND
476 {$this->_aliases['civicrm_address']}.is_primary = 1
477 LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
478 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND
479 {$this->_aliases['civicrm_email']}.is_primary = 1)
480 LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
481 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
482 {$this->_aliases['civicrm_phone']}.is_primary = 1
484 if ($this->_contribField
) {
486 LEFT JOIN civicrm_participant_payment pp
487 ON ({$this->_aliases['civicrm_participant']}.id = pp.participant_id)
488 LEFT JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']}
489 ON (pp.contribution_id = {$this->_aliases['civicrm_contribution']}.id)
492 if ($this->_lineitemField
){
494 LEFT JOIN civicrm_line_item line_item_civireport
495 ON line_item_civireport.entity_id = {$this->_aliases['civicrm_participant']}.id
502 foreach ($this->_columns
as $tableName => $table) {
503 if (array_key_exists('filters', $table)) {
504 foreach ($table['filters'] as $fieldName => $field) {
507 if (CRM_Utils_Array
::value('type', $field) & CRM_Utils_Type
::T_DATE
) {
508 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
509 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
510 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
512 if ($relative ||
$from ||
$to) {
513 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
517 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
519 if ($fieldName == 'rid') {
520 $value = CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
);
521 if (!empty($value)) {
522 $clause = "( {$field['dbAlias']} REGEXP '[[:<:]]" . implode('[[:>:]]|[[:<:]]', $value) . "[[:>:]]' )";
528 $clause = $this->whereClause($field,
530 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
531 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
532 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
537 if (!empty($clause)) {
538 $clauses[] = $clause;
543 if (empty($clauses)) {
544 $this->_where
= "WHERE {$this->_aliases['civicrm_participant']}.is_test = 0 ";
547 $this->_where
= "WHERE {$this->_aliases['civicrm_participant']}.is_test = 0 AND " . implode(' AND ', $clauses);
549 if ($this->_aclWhere
) {
550 $this->_where
.= " AND {$this->_aclWhere} ";
555 $this->_groupBy
= "GROUP BY {$this->_aliases['civicrm_participant']}.id";
558 function postProcess() {
560 // get ready with post process params
561 $this->beginPostProcess();
563 // get the acl clauses built before we assemble the query
564 $this->buildACLClause($this->_aliases
['civicrm_contact']);
566 $sql = $this->buildQuery(TRUE);
569 // build array of result based on column headers. This method also allows
570 // modifying column headers before using it to build result set i.e $rows.
572 $this->buildRows($sql, $rows);
574 // format result set.
575 $this->formatDisplay($rows);
577 // assign variables to templates
578 $this->doTemplateAssignment($rows);
580 // do print / pdf / instance stuff if needed
581 $this->endPostProcess($rows);
584 function alterDisplay(&$rows) {
585 // custom code to alter rows
588 $eventType = CRM_Core_OptionGroup
::values('event_type');
590 $financialTypes = CRM_Contribute_PseudoConstant
::financialType();
591 $contributionStatus = CRM_Contribute_PseudoConstant
::contributionStatus();
592 $paymentInstruments = CRM_Contribute_PseudoConstant
::paymentInstrument();
593 $honorTypes = CRM_Core_OptionGroup
::values('honor_type', FALSE, FALSE, FALSE, NULL, 'label');
594 $genders = CRM_Core_PseudoConstant
::get('CRM_Contact_DAO_Contact', 'gender_id', array('localize' => TRUE));
596 foreach ($rows as $rowNum => $row) {
597 // make count columns point to detail report
598 // convert display name to links
599 if (array_key_exists('civicrm_participant_event_id', $row)) {
600 if ($value = $row['civicrm_participant_event_id']) {
601 $rows[$rowNum]['civicrm_participant_event_id'] = CRM_Event_PseudoConstant
::event($value, FALSE);
603 $url = CRM_Report_Utils_Report
::getNextUrl('event/income',
604 'reset=1&force=1&id_op=in&id_value=' . $value,
605 $this->_absoluteUrl
, $this->_id
, $this->_drilldownReport
607 $rows[$rowNum]['civicrm_participant_event_id_link'] = $url;
608 $rows[$rowNum]['civicrm_participant_event_id_hover'] = ts("View Event Income Details for this Event");
613 // handle event type id
614 if (array_key_exists('civicrm_event_event_type_id', $row)) {
615 if ($value = $row['civicrm_event_event_type_id']) {
616 $rows[$rowNum]['civicrm_event_event_type_id'] = $eventType[$value];
621 // handle participant status id
622 if (array_key_exists('civicrm_participant_status_id', $row)) {
623 if ($value = $row['civicrm_participant_status_id']) {
624 $rows[$rowNum]['civicrm_participant_status_id'] = CRM_Event_PseudoConstant
::participantStatus($value, FALSE, 'label');
629 // handle participant role id
630 if (array_key_exists('civicrm_participant_role_id', $row)) {
631 if ($value = $row['civicrm_participant_role_id']) {
632 $roles = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $value);
634 foreach ($roles as $role) {
635 $value[$role] = CRM_Event_PseudoConstant
::participantRole($role, FALSE);
637 $rows[$rowNum]['civicrm_participant_role_id'] = implode(', ', $value);
642 // Handel value seperator in Fee Level
643 if (array_key_exists('civicrm_participant_participant_fee_level', $row)) {
644 if ($value = $row['civicrm_participant_participant_fee_level']) {
645 CRM_Event_BAO_Participant
::fixEventLevel($value);
646 $rows[$rowNum]['civicrm_participant_participant_fee_level'] = $value;
651 // Convert display name to link
652 if (($displayName = CRM_Utils_Array
::value('civicrm_contact_sort_name_linked', $row)) &&
653 ($cid = CRM_Utils_Array
::value('civicrm_contact_id', $row)) &&
654 ($id = CRM_Utils_Array
::value('civicrm_participant_participant_record', $row))
656 $url = CRM_Report_Utils_Report
::getNextUrl('contact/detail',
657 "reset=1&force=1&id_op=eq&id_value=$cid",
658 $this->_absoluteUrl
, $this->_id
, $this->_drilldownReport
661 $viewUrl = CRM_Utils_System
::url("civicrm/contact/view/participant",
662 "reset=1&id=$id&cid=$cid&action=view&context=participant"
665 $contactTitle = ts('View Contact Details');
666 $participantTitle = ts('View Participant Record');
668 $rows[$rowNum]['civicrm_contact_sort_name_linked'] = "<a title='$contactTitle' href=$url>$displayName</a>";
669 if ($this->_outputMode
!== 'csv') {
670 $rows[$rowNum]['civicrm_contact_sort_name_linked'] .= "<span style='float: right;'><a title='$participantTitle' href=$viewUrl>" . ts('View') . "</a></span>";
676 if (array_key_exists('civicrm_address_country_id', $row)) {
677 if ($value = $row['civicrm_address_country_id']) {
678 $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant
::country($value, TRUE);
683 // Handle state/province id
684 if (array_key_exists('civicrm_address_state_province_id', $row)) {
685 if ($value = $row['civicrm_address_state_province_id']) {
686 $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant
::stateProvince($value, TRUE);
691 // Handle employer id
692 if (array_key_exists('civicrm_contact_employer_id', $row)) {
693 if ($value = $row['civicrm_contact_employer_id']) {
694 $rows[$rowNum]['civicrm_contact_employer_id'] = CRM_Contact_BAO_Contact
::displayName($value);
695 $url = CRM_Utils_System
::url('civicrm/contact/view',
696 'reset=1&cid=' . $value, $this->_absoluteUrl
698 $rows[$rowNum]['civicrm_contact_employer_id_link'] = $url;
699 $rows[$rowNum]['civicrm_contact_employer_id_hover'] = ts('View Contact Summary for this Contact.');
703 // Convert campaign_id to campaign title
704 if (array_key_exists('civicrm_participant_campaign_id', $row)) {
705 if ($value = $row['civicrm_participant_campaign_id']) {
706 $rows[$rowNum]['civicrm_participant_campaign_id'] = $this->activeCampaigns
[$value];
711 // handle contribution status
712 if (array_key_exists('civicrm_contribution_contribution_status_id', $row)) {
713 if ($value = $row['civicrm_contribution_contribution_status_id']) {
714 $rows[$rowNum]['civicrm_contribution_contribution_status_id'] = $contributionStatus[$value];
719 // handle payment instrument
720 if (array_key_exists('civicrm_contribution_payment_instrument_id', $row)) {
721 if ($value = $row['civicrm_contribution_payment_instrument_id']) {
722 $rows[$rowNum]['civicrm_contribution_payment_instrument_id'] = $paymentInstruments[$value];
727 // handle financial type
728 if (array_key_exists('civicrm_contribution_financial_type_id', $row)) {
729 if ($value = $row['civicrm_contribution_financial_type_id']) {
730 $rows[$rowNum]['civicrm_contribution_financial_type_id'] = $financialTypes[$value];
735 if (array_key_exists('civicrm_contribution_honor_type_id', $row)) {
736 if ($value = $row['civicrm_contribution_honor_type_id']) {
737 $rows[$rowNum]['civicrm_contribution_honor_type_id'] = $honorTypes[$value];
742 if (array_key_exists('civicrm_contact_gender_id', $row)) {
743 if ($value = $row['civicrm_contact_gender_id']) {
744 $rows[$rowNum]['civicrm_contact_gender_id'] = $genders[$value];
749 // display birthday in the configured custom format
750 if (array_key_exists('civicrm_contact_birth_date', $row)) {
751 if ($value = $row['civicrm_contact_birth_date']) {
752 $rows[$rowNum]['civicrm_contact_birth_date'] = CRM_Utils_Date
::customFormat($row['civicrm_contact_birth_date'], '%Y%m%d');
757 // skip looking further in rows, if first row itself doesn't
758 // have the column we need