Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
16654cd4 | 2 | |
6a488035 | 3 | /* |
16654cd4 | 4 | +--------------------------------------------------------------------+ |
06b69b18 | 5 | | CiviCRM version 4.5 | |
16654cd4 | 6 | +--------------------------------------------------------------------+ |
06b69b18 | 7 | | Copyright CiviCRM LLC (c) 2004-2014 | |
16654cd4 DL |
8 | +--------------------------------------------------------------------+ |
9 | | This file is a part of CiviCRM. | | |
10 | | | | |
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. | | |
14 | | | | |
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. | | |
19 | | | | |
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 | +--------------------------------------------------------------------+ | |
6a488035 TO |
27 | */ |
28 | ||
29 | /** | |
30 | * | |
31 | * @package CRM | |
06b69b18 | 32 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
33 | * $Id$ |
34 | * | |
35 | */ | |
36 | class CRM_Report_Form_Event_ParticipantListing extends CRM_Report_Form_Event { | |
37 | ||
38 | protected $_summary = NULL; | |
9b34c9e3 | 39 | |
e8e008f5 | 40 | protected $_contribField = FALSE; |
16654cd4 | 41 | protected $_lineitemField = FALSE; |
26dcc739 E |
42 | protected $_groupFilter = TRUE; |
43 | protected $_tagFilter = TRUE; | |
6a488035 | 44 | |
0f18adb9 | 45 | protected $_customGroupExtends = array('Participant', 'Contact', 'Individual', 'Event'); |
28ac0bbe | 46 | |
6a488035 TO |
47 | public $_drilldownReport = array('event/income' => 'Link to Detail Report'); |
48 | ||
f813f78e | 49 | function __construct() { |
28ac0bbe | 50 | $this->_autoIncludeIndexedFieldsAsOrderBys = 1; |
f813f78e | 51 | |
52 | // Check if CiviCampaign is a) enabled and b) has active campaigns | |
9b34c9e3 | 53 | $config = CRM_Core_Config::singleton(); |
4fabb77b CD |
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); | |
59 | } | |
f813f78e | 60 | |
6a488035 TO |
61 | $this->_columns = array( |
62 | 'civicrm_contact' => | |
63 | array( | |
64 | 'dao' => 'CRM_Contact_DAO_Contact', | |
65 | 'fields' => | |
66 | array( | |
67 | 'sort_name_linked' => | |
68 | array('title' => ts('Participant Name'), | |
69 | 'required' => TRUE, | |
70 | 'no_repeat' => TRUE, | |
71 | 'dbAlias' => 'contact_civireport.sort_name', | |
72 | ), | |
9b34c9e3 | 73 | 'first_name' => array('title' => ts('First Name'), |
6a488035 | 74 | ), |
9b34c9e3 | 75 | 'last_name' => array('title' => ts('Last Name'), |
6a488035 TO |
76 | ), |
77 | 'id' => | |
78 | array( | |
79 | 'no_display' => TRUE, | |
80 | 'required' => TRUE, | |
81 | ), | |
28ac0bbe DG |
82 | 'gender_id' => |
83 | array('title' => ts('Gender'), | |
84 | ), | |
439fc6fe DG |
85 | 'birth_date' => |
86 | array('title' => ts('Birth Date'), | |
87 | ), | |
28ac0bbe DG |
88 | 'age' => array( |
89 | 'title' => ts('Age'), | |
90 | 'dbAlias' => 'TIMESTAMPDIFF(YEAR, contact_civireport.birth_date, CURDATE())', | |
91 | ), | |
92 | 'age_at_event' => array( | |
93 | 'title' => ts('Age at Event'), | |
94 | 'dbAlias' => 'TIMESTAMPDIFF(YEAR, contact_civireport.birth_date, event_civireport.start_date)', | |
439fc6fe | 95 | ), |
6a488035 TO |
96 | 'employer_id' => |
97 | array('title' => ts('Organization'), | |
98 | ), | |
99 | ), | |
100 | 'grouping' => 'contact-fields', | |
4fabb77b | 101 | 'order_bys' => |
6a488035 TO |
102 | array( |
103 | 'sort_name' => | |
f813f78e | 104 | array('title' => ts('Last Name, First Name'), |
9b34c9e3 PJ |
105 | 'default' => '1', |
106 | 'default_weight' => '0', | |
107 | 'default_order' => 'ASC', | |
6a488035 | 108 | ), |
28ac0bbe DG |
109 | 'gender_id' => |
110 | array( | |
111 | 'name' => 'gender_id', | |
112 | 'title' => ts('Gender'), | |
113 | ), | |
114 | 'birth_date' => | |
115 | array( | |
116 | 'name' => 'birth_date', | |
117 | 'title' => ts('Birth Date'), | |
118 | ), | |
119 | 'age_at_event' => | |
120 | array( | |
121 | 'name' => 'age_at_event', | |
122 | 'title' => ts('Age at Event'), | |
123 | ), | |
6a488035 | 124 | ), |
4fabb77b | 125 | 'filters' => |
6a488035 TO |
126 | array( |
127 | 'sort_name' => | |
4fabb77b CD |
128 | array('title' => ts('Participant Name'), |
129 | 'operator' => 'like', | |
130 | ), | |
28ac0bbe DG |
131 | 'gender_id' => |
132 | array('title' => ts('Gender'), | |
133 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
134 | 'options' => CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'), | |
135 | ), | |
136 | 'birth_date' => array( | |
137 | 'title' => 'Birth Date', | |
138 | 'operatorType' => CRM_Report_Form::OP_DATE, | |
139 | 'type' => CRM_Utils_Type::T_DATE | |
140 | ), | |
6a488035 TO |
141 | ), |
142 | ), | |
143 | 'civicrm_email' => | |
144 | array( | |
145 | 'dao' => 'CRM_Core_DAO_Email', | |
146 | 'fields' => | |
147 | array( | |
148 | 'email' => | |
149 | array('title' => ts('Email'), | |
150 | 'no_repeat' => TRUE, | |
151 | ), | |
152 | ), | |
153 | 'grouping' => 'contact-fields', | |
154 | 'filters' => | |
155 | array( | |
156 | 'email' => | |
157 | array('title' => ts('Participant E-mail'), | |
158 | 'operator' => 'like', | |
159 | ), | |
160 | ), | |
161 | ), | |
162 | 'civicrm_address' => | |
163 | array( | |
164 | 'dao' => 'CRM_Core_DAO_Address', | |
165 | 'fields' => | |
166 | array( | |
167 | 'street_address' => NULL, | |
168 | 'city' => NULL, | |
169 | 'postal_code' => NULL, | |
170 | 'state_province_id' => | |
171 | array('title' => ts('State/Province'), | |
172 | ), | |
173 | 'country_id' => | |
174 | array('title' => ts('Country'), | |
175 | ), | |
176 | ), | |
177 | 'grouping' => 'contact-fields', | |
178 | ), | |
179 | 'civicrm_participant' => | |
180 | array( | |
181 | 'dao' => 'CRM_Event_DAO_Participant', | |
182 | 'fields' => | |
183 | array('participant_id' => array('title' => 'Participant ID'), | |
184 | 'participant_record' => array( | |
185 | 'name' => 'id', | |
186 | 'no_display' => TRUE, | |
187 | 'required' => TRUE, | |
188 | ), | |
189 | 'event_id' => array( | |
190 | 'default' => TRUE, | |
191 | 'type' => CRM_Utils_Type::T_STRING, | |
192 | ), | |
193 | 'status_id' => array('title' => ts('Status'), | |
16654cd4 | 194 | 'default' => TRUE, |
6a488035 TO |
195 | ), |
196 | 'role_id' => array('title' => ts('Role'), | |
16654cd4 | 197 | 'default' => TRUE, |
6a488035 | 198 | ), |
9bf1940a | 199 | 'fee_currency' => array( |
16654cd4 DL |
200 | 'required' => TRUE, |
201 | 'no_display' => TRUE, | |
9bf1940a | 202 | ), |
6a488035 TO |
203 | 'participant_fee_level' => NULL, |
204 | 'participant_fee_amount' => NULL, | |
205 | 'participant_register_date' => array('title' => ts('Registration Date')), | |
206 | ), | |
207 | 'grouping' => 'event-fields', | |
208 | 'filters' => | |
209 | array( | |
210 | 'event_id' => array('name' => 'event_id', | |
16654cd4 DL |
211 | 'title' => ts('Event'), |
212 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
213 | 'options' => $this->getEventFilterOptions(), | |
6a488035 TO |
214 | ), |
215 | 'sid' => array( | |
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'), | |
220 | ), | |
221 | 'rid' => array( | |
222 | 'name' => 'role_id', | |
223 | 'title' => ts('Participant Role'), | |
224 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
225 | 'options' => CRM_Event_PseudoConstant::participantRole(), | |
226 | ), | |
227 | 'participant_register_date' => array( | |
439fc6fe | 228 | 'title' => 'Registration Date', |
6a488035 TO |
229 | 'operatorType' => CRM_Report_Form::OP_DATE, |
230 | ), | |
9bf1940a | 231 | 'fee_currency' => |
9b34c9e3 | 232 | array('title' => ts('Fee Currency'), |
9bf1940a | 233 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, |
234 | 'options' => CRM_Core_OptionGroup::values('currencies_enabled'), | |
d1b0931b | 235 | 'default' => NULL, |
9bf1940a | 236 | 'type' => CRM_Utils_Type::T_STRING, |
237 | ), | |
238 | ||
6a488035 TO |
239 | ), |
240 | 'order_bys' => | |
241 | array( | |
08ef564e DG |
242 | 'participant_register_date' => |
243 | array('title' => ts('Registration Date'), | |
244 | 'default_weight' => '1', | |
245 | 'default_order' => 'ASC', | |
246 | ), | |
6a488035 TO |
247 | 'event_id' => |
248 | array('title' => ts('Event'), 'default_weight' => '1', 'default_order' => 'ASC'), | |
249 | ), | |
250 | ), | |
251 | 'civicrm_phone' => | |
252 | array( | |
253 | 'dao' => 'CRM_Core_DAO_Phone', | |
254 | 'fields' => | |
255 | array( | |
256 | 'phone' => | |
257 | array('title' => ts('Phone'), | |
258 | 'default' => TRUE, | |
259 | 'no_repeat' => TRUE, | |
260 | ), | |
261 | ), | |
262 | 'grouping' => 'contact-fields', | |
263 | ), | |
264 | 'civicrm_event' => | |
265 | array( | |
266 | 'dao' => 'CRM_Event_DAO_Event', | |
e1a1a24e | 267 | 'fields' => array( |
6a488035 | 268 | 'event_type_id' => array('title' => ts('Event Type')), |
e1a1a24e | 269 | 'event_start_date' => array('title' => ts('Event Start Date')), |
6a488035 TO |
270 | ), |
271 | 'grouping' => 'event-fields', | |
272 | 'filters' => | |
273 | array( | |
274 | 'eid' => array( | |
275 | 'name' => 'event_type_id', | |
276 | 'title' => ts('Event Type'), | |
277 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
278 | 'options' => CRM_Core_OptionGroup::values('event_type'), | |
279 | ), | |
e1a1a24e AH |
280 | 'event_start_date' => array( |
281 | 'title' => ts('Event Start Date'), | |
282 | 'operatorType' => CRM_Report_Form::OP_DATE, | |
283 | ), | |
6a488035 TO |
284 | ), |
285 | 'order_bys' => | |
286 | array( | |
287 | 'event_type_id' => | |
288 | array('title' => ts('Event Type'), 'default_weight' => '2', 'default_order' => 'ASC'), | |
289 | ), | |
290 | ), | |
42e9d54f AH |
291 | 'civicrm_contribution' => array( |
292 | 'dao' => 'CRM_Contribute_DAO_Contribution', | |
293 | 'fields' => array( | |
294 | 'contribution_id' => array( | |
295 | 'name' => 'id', | |
9b34c9e3 PJ |
296 | 'no_display' => TRUE, |
297 | 'required' => TRUE, | |
42e9d54f AH |
298 | 'csv_display' => TRUE, |
299 | 'title' => ts('Contribution ID'), | |
300 | ), | |
301 | 'financial_type_id' => array('title' => ts('Financial Type')), | |
302 | 'receive_date' => array('title' => ts('Payment Date')), | |
303 | 'contribution_status_id' => array('title' => ts('Contribution Status')), | |
304 | 'payment_instrument_id' => array('title' => ts('Payment Type')), | |
305 | 'contribution_source' => array( | |
306 | 'name' => 'source', | |
307 | 'title' => ts('Contribution Source'), | |
308 | ), | |
309 | 'currency' => array( | |
310 | 'required' => TRUE, | |
9b34c9e3 | 311 | 'no_display' => TRUE |
42e9d54f AH |
312 | ), |
313 | 'trxn_id' => NULL, | |
42e9d54f | 314 | 'fee_amount' => array('title' => ts('Transaction Fee')), |
9b34c9e3 PJ |
315 | 'net_amount' => NULL |
316 | ), | |
42e9d54f AH |
317 | 'grouping' => 'contrib-fields', |
318 | 'filters' => array( | |
319 | 'receive_date' => array( | |
320 | 'title' => 'Payment Date', | |
321 | 'operatorType' => CRM_Report_Form::OP_DATE, | |
322 | ), | |
d79a8b5c | 323 | 'financial_type_id' => array('title' => ts('Financial Type'), |
16654cd4 DL |
324 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, |
325 | 'options' => CRM_Contribute_PseudoConstant::financialType(), | |
d79a8b5c | 326 | ), |
9b34c9e3 | 327 | 'currency' => array('title' => ts('Contribution Currency'), |
16654cd4 DL |
328 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, |
329 | 'options' => CRM_Core_OptionGroup::values('currencies_enabled'), | |
330 | 'default' => NULL, | |
331 | 'type' => CRM_Utils_Type::T_STRING, | |
d79a8b5c AH |
332 | ), |
333 | 'payment_instrument_id' => array('title' => ts('Payment Type'), | |
16654cd4 DL |
334 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, |
335 | 'options' => CRM_Contribute_PseudoConstant::paymentInstrument(), | |
d79a8b5c AH |
336 | ), |
337 | 'contribution_status_id' => array('title' => ts('Contribution Status'), | |
16654cd4 DL |
338 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, |
339 | 'options' => CRM_Contribute_PseudoConstant::contributionStatus(), | |
340 | 'default' => NULL | |
341 | ), | |
342 | ), | |
343 | ), | |
344 | ||
345 | 'civicrm_line_item' => array( | |
346 | 'dao' => 'CRM_Price_DAO_LineItem', | |
347 | 'grouping' => 'priceset-fields', | |
348 | 'filters' => array( | |
349 | 'price_field_value_id' => array( | |
350 | 'name' => 'price_field_value_id', | |
351 | 'title' => ts('Fee Level'), | |
d79a8b5c | 352 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, |
16654cd4 | 353 | 'options' => $this->getPriceLevels(), |
d79a8b5c | 354 | ), |
42e9d54f AH |
355 | ), |
356 | ), | |
6a488035 | 357 | ); |
16654cd4 DL |
358 | |
359 | ||
360 | $this->_options = array( | |
361 | 'blank_column_begin' => array( | |
362 | 'title' => ts('Blank column at the Begining'), | |
6a488035 TO |
363 | 'type' => 'checkbox', |
364 | ), | |
16654cd4 DL |
365 | 'blank_column_end' => array( |
366 | 'title' => ts('Blank column at the End'), | |
6a488035 TO |
367 | 'type' => 'select', |
368 | 'options' => array( | |
369 | '' => '-select-', | |
370 | 1 => ts('One'), | |
371 | 2 => ts('Two'), | |
372 | 3 => ts('Three'), | |
373 | ), | |
374 | ), | |
375 | ); | |
f813f78e | 376 | |
4fabb77b CD |
377 | // If we have active campaigns add those elements to both the fields and filters |
378 | if ($campaignEnabled && !empty($this->activeCampaigns)) { | |
16654cd4 DL |
379 | $this->_columns['civicrm_participant']['fields']['campaign_id'] = |
380 | array( | |
381 | 'title' => ts('Campaign'), | |
382 | 'default' => 'false', | |
383 | ); | |
384 | $this->_columns['civicrm_participant']['filters']['campaign_id'] = | |
385 | array( | |
386 | 'title' => ts('Campaign'), | |
387 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
388 | 'options' => $this->activeCampaigns, | |
389 | ); | |
390 | $this->_columns['civicrm_participant']['order_bys']['campaign_id'] = | |
391 | array('title' => ts('Campaign')); | |
4fabb77b CD |
392 | |
393 | } | |
f813f78e | 394 | |
9bf1940a | 395 | $this->_currencyColumn = 'civicrm_participant_fee_currency'; |
6a488035 TO |
396 | parent::__construct(); |
397 | } | |
f813f78e | 398 | |
16654cd4 DL |
399 | function getPriceLevels() { |
400 | $query = " | |
401 | SELECT DISTINCT cv.label, cv.id | |
402 | FROM civicrm_price_field_value cv | |
403 | LEFT JOIN civicrm_price_field cf ON cv.price_field_id = cf.id | |
404 | LEFT JOIN civicrm_price_set_entity ce ON ce.price_set_id = cf.price_set_id | |
405 | WHERE ce.entity_table = 'civicrm_event' | |
406 | GROUP BY cv.label | |
407 | "; | |
408 | $dao = CRM_Core_DAO::executeQuery($query); | |
409 | $elements = array(); | |
410 | while ($dao->fetch()) { | |
411 | $elements[$dao->id] = "$dao->label\n"; | |
412 | } | |
413 | ||
414 | return $elements; | |
415 | } //searches database for priceset values | |
416 | ||
6a488035 TO |
417 | |
418 | function preProcess() { | |
419 | parent::preProcess(); | |
420 | } | |
421 | ||
422 | function select() { | |
423 | $select = array(); | |
424 | $this->_columnHeaders = array(); | |
425 | ||
426 | //add blank column at the Start | |
8cc574cf | 427 | if (array_key_exists('options', $this->_params) && !empty($this->_params['options']['blank_column_begin'])) { |
6a488035 TO |
428 | $select[] = " '' as blankColumnBegin"; |
429 | $this->_columnHeaders['blankColumnBegin']['title'] = '_ _ _ _'; | |
430 | } | |
431 | foreach ($this->_columns as $tableName => $table) { | |
16654cd4 DL |
432 | if ($tableName == 'civicrm_line_item'){ |
433 | $this->_lineitemField = TRUE; | |
434 | } | |
6a488035 TO |
435 | if (array_key_exists('fields', $table)) { |
436 | foreach ($table['fields'] as $fieldName => $field) { | |
8cc574cf | 437 | if (!empty($field['required']) || !empty($this->_params['fields'][$fieldName])) { |
e8e008f5 AH |
438 | if ($tableName == 'civicrm_contribution') { |
439 | $this->_contribField = TRUE; | |
440 | } | |
6a488035 TO |
441 | |
442 | $alias = "{$tableName}_{$fieldName}"; | |
443 | $select[] = "{$field['dbAlias']} as $alias"; | |
444 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field); | |
445 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['no_display'] = CRM_Utils_Array::value('no_display', $field); | |
446 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array::value('title', $field); | |
447 | $this->_selectAliases[] = $alias; | |
448 | } | |
449 | } | |
450 | } | |
451 | } | |
452 | //add blank column at the end | |
453 | if ($blankcols = CRM_Utils_Array::value('blank_column_end', $this->_params)) { | |
454 | for ($i = 1; $i <= $blankcols; $i++) { | |
455 | $select[] = " '' as blankColumnEnd_{$i}"; | |
456 | $this->_columnHeaders["blank_{$i}"]['title'] = "_ _ _ _"; | |
457 | } | |
458 | } | |
459 | ||
460 | $this->_select = "SELECT " . implode(', ', $select) . " "; | |
461 | } | |
462 | ||
463 | static function formRule($fields, $files, $self) { | |
464 | $errors = $grouping = array(); | |
465 | return $errors; | |
466 | } | |
467 | ||
468 | function from() { | |
469 | $this->_from = " | |
470 | FROM civicrm_participant {$this->_aliases['civicrm_participant']} | |
f813f78e | 471 | LEFT JOIN civicrm_event {$this->_aliases['civicrm_event']} |
472 | ON ({$this->_aliases['civicrm_event']}.id = {$this->_aliases['civicrm_participant']}.event_id ) AND | |
99f13d8d | 473 | {$this->_aliases['civicrm_event']}.is_template = 0 |
f813f78e | 474 | LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']} |
6a488035 TO |
475 | ON ({$this->_aliases['civicrm_participant']}.contact_id = {$this->_aliases['civicrm_contact']}.id ) |
476 | {$this->_aclFrom} | |
477 | LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']} | |
f813f78e | 478 | ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND |
479 | {$this->_aliases['civicrm_address']}.is_primary = 1 | |
480 | LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']} | |
6a488035 | 481 | ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND |
f813f78e | 482 | {$this->_aliases['civicrm_email']}.is_primary = 1) |
483 | LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']} | |
6a488035 | 484 | ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND |
f813f78e | 485 | {$this->_aliases['civicrm_phone']}.is_primary = 1 |
e8e008f5 AH |
486 | "; |
487 | if ($this->_contribField) { | |
488 | $this->_from .= " | |
42e9d54f | 489 | LEFT JOIN civicrm_participant_payment pp |
9b34c9e3 PJ |
490 | ON ({$this->_aliases['civicrm_participant']}.id = pp.participant_id) |
491 | LEFT JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']} | |
492 | ON (pp.contribution_id = {$this->_aliases['civicrm_contribution']}.id) | |
f813f78e | 493 | "; |
e8e008f5 | 494 | } |
16654cd4 DL |
495 | if ($this->_lineitemField){ |
496 | $this->_from .= " | |
497 | LEFT JOIN civicrm_line_item line_item_civireport | |
5fa8e57d | 498 | ON line_item_civireport.entity_table = 'civicrm_participant' AND |
499 | line_item_civireport.entity_id = {$this->_aliases['civicrm_participant']}.id | |
16654cd4 DL |
500 | "; |
501 | } | |
6a488035 TO |
502 | } |
503 | ||
504 | function where() { | |
505 | $clauses = array(); | |
506 | foreach ($this->_columns as $tableName => $table) { | |
507 | if (array_key_exists('filters', $table)) { | |
508 | foreach ($table['filters'] as $fieldName => $field) { | |
509 | $clause = NULL; | |
510 | ||
511 | if (CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE) { | |
512 | $relative = CRM_Utils_Array::value("{$fieldName}_relative", $this->_params); | |
513 | $from = CRM_Utils_Array::value("{$fieldName}_from", $this->_params); | |
514 | $to = CRM_Utils_Array::value("{$fieldName}_to", $this->_params); | |
515 | ||
516 | if ($relative || $from || $to) { | |
517 | $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']); | |
518 | } | |
519 | } | |
520 | else { | |
521 | $op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params); | |
522 | ||
523 | if ($fieldName == 'rid') { | |
524 | $value = CRM_Utils_Array::value("{$fieldName}_value", $this->_params); | |
525 | if (!empty($value)) { | |
526 | $clause = "( {$field['dbAlias']} REGEXP '[[:<:]]" . implode('[[:>:]]|[[:<:]]', $value) . "[[:>:]]' )"; | |
527 | } | |
528 | $op = NULL; | |
529 | } | |
530 | ||
531 | if ($op) { | |
532 | $clause = $this->whereClause($field, | |
16654cd4 DL |
533 | $op, |
534 | CRM_Utils_Array::value("{$fieldName}_value", $this->_params), | |
535 | CRM_Utils_Array::value("{$fieldName}_min", $this->_params), | |
536 | CRM_Utils_Array::value("{$fieldName}_max", $this->_params) | |
6a488035 TO |
537 | ); |
538 | } | |
539 | } | |
540 | ||
541 | if (!empty($clause)) { | |
542 | $clauses[] = $clause; | |
543 | } | |
544 | } | |
545 | } | |
546 | } | |
547 | if (empty($clauses)) { | |
548 | $this->_where = "WHERE {$this->_aliases['civicrm_participant']}.is_test = 0 "; | |
549 | } | |
550 | else { | |
551 | $this->_where = "WHERE {$this->_aliases['civicrm_participant']}.is_test = 0 AND " . implode(' AND ', $clauses); | |
552 | } | |
553 | if ($this->_aclWhere) { | |
554 | $this->_where .= " AND {$this->_aclWhere} "; | |
555 | } | |
556 | } | |
557 | ||
1bfb7a7e DS |
558 | function groupBy(){ |
559 | $this->_groupBy = "GROUP BY {$this->_aliases['civicrm_participant']}.id"; | |
560 | } | |
561 | ||
6a488035 TO |
562 | function postProcess() { |
563 | ||
564 | // get ready with post process params | |
565 | $this->beginPostProcess(); | |
566 | ||
567 | // get the acl clauses built before we assemble the query | |
568 | $this->buildACLClause($this->_aliases['civicrm_contact']); | |
569 | // build query | |
570 | $sql = $this->buildQuery(TRUE); | |
571 | ||
16654cd4 | 572 | |
6a488035 TO |
573 | // build array of result based on column headers. This method also allows |
574 | // modifying column headers before using it to build result set i.e $rows. | |
638e7498 | 575 | $rows = array(); |
6a488035 TO |
576 | $this->buildRows($sql, $rows); |
577 | ||
578 | // format result set. | |
579 | $this->formatDisplay($rows); | |
580 | ||
581 | // assign variables to templates | |
582 | $this->doTemplateAssignment($rows); | |
583 | ||
584 | // do print / pdf / instance stuff if needed | |
585 | $this->endPostProcess($rows); | |
586 | } | |
587 | ||
588 | function alterDisplay(&$rows) { | |
589 | // custom code to alter rows | |
590 | ||
591 | $entryFound = FALSE; | |
592 | $eventType = CRM_Core_OptionGroup::values('event_type'); | |
593 | ||
9b34c9e3 PJ |
594 | $financialTypes = CRM_Contribute_PseudoConstant::financialType(); |
595 | $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus(); | |
596 | $paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument(); | |
439fc6fe | 597 | $genders = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id', array('localize' => TRUE)); |
9b34c9e3 | 598 | |
6a488035 TO |
599 | foreach ($rows as $rowNum => $row) { |
600 | // make count columns point to detail report | |
601 | // convert display name to links | |
602 | if (array_key_exists('civicrm_participant_event_id', $row)) { | |
603 | if ($value = $row['civicrm_participant_event_id']) { | |
604 | $rows[$rowNum]['civicrm_participant_event_id'] = CRM_Event_PseudoConstant::event($value, FALSE); | |
9b34c9e3 | 605 | |
6a488035 | 606 | $url = CRM_Report_Utils_Report::getNextUrl('event/income', |
16654cd4 DL |
607 | 'reset=1&force=1&id_op=in&id_value=' . $value, |
608 | $this->_absoluteUrl, $this->_id, $this->_drilldownReport | |
6a488035 TO |
609 | ); |
610 | $rows[$rowNum]['civicrm_participant_event_id_link'] = $url; | |
611 | $rows[$rowNum]['civicrm_participant_event_id_hover'] = ts("View Event Income Details for this Event"); | |
612 | } | |
613 | $entryFound = TRUE; | |
614 | } | |
615 | ||
616 | // handle event type id | |
617 | if (array_key_exists('civicrm_event_event_type_id', $row)) { | |
618 | if ($value = $row['civicrm_event_event_type_id']) { | |
619 | $rows[$rowNum]['civicrm_event_event_type_id'] = $eventType[$value]; | |
620 | } | |
621 | $entryFound = TRUE; | |
622 | } | |
623 | ||
624 | // handle participant status id | |
625 | if (array_key_exists('civicrm_participant_status_id', $row)) { | |
626 | if ($value = $row['civicrm_participant_status_id']) { | |
627 | $rows[$rowNum]['civicrm_participant_status_id'] = CRM_Event_PseudoConstant::participantStatus($value, FALSE, 'label'); | |
628 | } | |
629 | $entryFound = TRUE; | |
630 | } | |
631 | ||
632 | // handle participant role id | |
633 | if (array_key_exists('civicrm_participant_role_id', $row)) { | |
634 | if ($value = $row['civicrm_participant_role_id']) { | |
635 | $roles = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value); | |
636 | $value = array(); | |
637 | foreach ($roles as $role) { | |
638 | $value[$role] = CRM_Event_PseudoConstant::participantRole($role, FALSE); | |
639 | } | |
640 | $rows[$rowNum]['civicrm_participant_role_id'] = implode(', ', $value); | |
641 | } | |
642 | $entryFound = TRUE; | |
643 | } | |
644 | ||
645 | // Handel value seperator in Fee Level | |
646 | if (array_key_exists('civicrm_participant_participant_fee_level', $row)) { | |
647 | if ($value = $row['civicrm_participant_participant_fee_level']) { | |
648 | CRM_Event_BAO_Participant::fixEventLevel($value); | |
649 | $rows[$rowNum]['civicrm_participant_participant_fee_level'] = $value; | |
650 | } | |
651 | $entryFound = TRUE; | |
652 | } | |
653 | ||
654 | // Convert display name to link | |
655 | if (($displayName = CRM_Utils_Array::value('civicrm_contact_sort_name_linked', $row)) && | |
656 | ($cid = CRM_Utils_Array::value('civicrm_contact_id', $row)) && | |
657 | ($id = CRM_Utils_Array::value('civicrm_participant_participant_record', $row)) | |
658 | ) { | |
659 | $url = CRM_Report_Utils_Report::getNextUrl('contact/detail', | |
16654cd4 DL |
660 | "reset=1&force=1&id_op=eq&id_value=$cid", |
661 | $this->_absoluteUrl, $this->_id, $this->_drilldownReport | |
6a488035 TO |
662 | ); |
663 | ||
664 | $viewUrl = CRM_Utils_System::url("civicrm/contact/view/participant", | |
16654cd4 | 665 | "reset=1&id=$id&cid=$cid&action=view&context=participant" |
6a488035 TO |
666 | ); |
667 | ||
668 | $contactTitle = ts('View Contact Details'); | |
669 | $participantTitle = ts('View Participant Record'); | |
670 | ||
671 | $rows[$rowNum]['civicrm_contact_sort_name_linked'] = "<a title='$contactTitle' href=$url>$displayName</a>"; | |
672 | if ($this->_outputMode !== 'csv') { | |
673 | $rows[$rowNum]['civicrm_contact_sort_name_linked'] .= "<span style='float: right;'><a title='$participantTitle' href=$viewUrl>" . ts('View') . "</a></span>"; | |
674 | } | |
675 | $entryFound = TRUE; | |
676 | } | |
677 | ||
678 | // Handle country id | |
679 | if (array_key_exists('civicrm_address_country_id', $row)) { | |
680 | if ($value = $row['civicrm_address_country_id']) { | |
681 | $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant::country($value, TRUE); | |
682 | } | |
683 | $entryFound = TRUE; | |
684 | } | |
685 | ||
686 | // Handle state/province id | |
687 | if (array_key_exists('civicrm_address_state_province_id', $row)) { | |
688 | if ($value = $row['civicrm_address_state_province_id']) { | |
689 | $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($value, TRUE); | |
690 | } | |
691 | $entryFound = TRUE; | |
692 | } | |
693 | ||
694 | // Handle employer id | |
695 | if (array_key_exists('civicrm_contact_employer_id', $row)) { | |
696 | if ($value = $row['civicrm_contact_employer_id']) { | |
697 | $rows[$rowNum]['civicrm_contact_employer_id'] = CRM_Contact_BAO_Contact::displayName($value); | |
698 | $url = CRM_Utils_System::url('civicrm/contact/view', | |
16654cd4 | 699 | 'reset=1&cid=' . $value, $this->_absoluteUrl |
6a488035 TO |
700 | ); |
701 | $rows[$rowNum]['civicrm_contact_employer_id_link'] = $url; | |
702 | $rows[$rowNum]['civicrm_contact_employer_id_hover'] = ts('View Contact Summary for this Contact.'); | |
703 | } | |
704 | } | |
705 | ||
4fabb77b CD |
706 | // Convert campaign_id to campaign title |
707 | if (array_key_exists('civicrm_participant_campaign_id', $row)) { | |
708 | if ($value = $row['civicrm_participant_campaign_id']) { | |
709 | $rows[$rowNum]['civicrm_participant_campaign_id'] = $this->activeCampaigns[$value]; | |
710 | $entryFound = TRUE; | |
711 | } | |
712 | } | |
713 | ||
9b34c9e3 PJ |
714 | // handle contribution status |
715 | if (array_key_exists('civicrm_contribution_contribution_status_id', $row)) { | |
716 | if ($value = $row['civicrm_contribution_contribution_status_id']) { | |
717 | $rows[$rowNum]['civicrm_contribution_contribution_status_id'] = $contributionStatus[$value]; | |
718 | } | |
719 | $entryFound = TRUE; | |
720 | } | |
721 | ||
722 | // handle payment instrument | |
723 | if (array_key_exists('civicrm_contribution_payment_instrument_id', $row)) { | |
724 | if ($value = $row['civicrm_contribution_payment_instrument_id']) { | |
725 | $rows[$rowNum]['civicrm_contribution_payment_instrument_id'] = $paymentInstruments[$value]; | |
726 | } | |
727 | $entryFound = TRUE; | |
728 | } | |
729 | ||
730 | // handle financial type | |
731 | if (array_key_exists('civicrm_contribution_financial_type_id', $row)) { | |
732 | if ($value = $row['civicrm_contribution_financial_type_id']) { | |
733 | $rows[$rowNum]['civicrm_contribution_financial_type_id'] = $financialTypes[$value]; | |
734 | } | |
735 | $entryFound = TRUE; | |
736 | } | |
737 | ||
439fc6fe DG |
738 | if (array_key_exists('civicrm_contact_gender_id', $row)) { |
739 | if ($value = $row['civicrm_contact_gender_id']) { | |
740 | $rows[$rowNum]['civicrm_contact_gender_id'] = $genders[$value]; | |
741 | } | |
742 | $entryFound = TRUE; | |
743 | } | |
9b34c9e3 | 744 | |
28ac0bbe DG |
745 | // display birthday in the configured custom format |
746 | if (array_key_exists('civicrm_contact_birth_date', $row)) { | |
747 | if ($value = $row['civicrm_contact_birth_date']) { | |
16654cd4 | 748 | $rows[$rowNum]['civicrm_contact_birth_date'] = CRM_Utils_Date::customFormat($row['civicrm_contact_birth_date'], '%Y%m%d'); |
28ac0bbe DG |
749 | } |
750 | $entryFound = TRUE; | |
751 | } | |
752 | ||
6a488035 TO |
753 | // skip looking further in rows, if first row itself doesn't |
754 | // have the column we need | |
755 | if (!$entryFound) { | |
756 | break; | |
757 | } | |
758 | } | |
759 | } | |
16654cd4 | 760 | } |