Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
939287ad | 13 | * Back office participant form. |
6a488035 TO |
14 | * |
15 | * @package CRM | |
ca5cec67 | 16 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
17 | */ |
18 | ||
19 | /** | |
939287ad | 20 | * Back office participant form. |
6a488035 | 21 | */ |
6bd6d108 | 22 | class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment { |
6a488035 | 23 | |
2ee9bfad | 24 | /** |
25 | * Participant ID - use getParticipantID. | |
26 | * | |
27 | * @var int | |
28 | */ | |
29 | public $_pId; | |
30 | ||
31 | /** | |
32 | * ID of discount record. | |
33 | * | |
34 | * @var int | |
35 | */ | |
36 | public $_discountId; | |
37 | ||
96f50de2 CW |
38 | public $useLivePageJS = TRUE; |
39 | ||
6a488035 | 40 | /** |
66f9e52b | 41 | * The values for the contribution db object. |
6a488035 TO |
42 | * |
43 | * @var array | |
6a488035 TO |
44 | */ |
45 | public $_values; | |
46 | ||
47 | /** | |
66f9e52b | 48 | * The values for the quickconfig for priceset. |
6a488035 | 49 | * |
d51c6add | 50 | * @var bool |
6a488035 TO |
51 | */ |
52 | public $_quickConfig = NULL; | |
53 | ||
54 | /** | |
55 | * Price Set ID, if the new price set method is used | |
56 | * | |
57 | * @var int | |
6a488035 TO |
58 | */ |
59 | public $_priceSetId; | |
60 | ||
61 | /** | |
66f9e52b | 62 | * Array of fields for the price set. |
6a488035 TO |
63 | * |
64 | * @var array | |
6a488035 TO |
65 | */ |
66 | public $_priceSet; | |
67 | ||
68 | /** | |
6452294d | 69 | * The id of the participation that we are processing. |
6a488035 TO |
70 | * |
71 | * @var int | |
6a488035 TO |
72 | */ |
73 | public $_id; | |
74 | ||
75 | /** | |
66f9e52b | 76 | * The id of the note. |
6a488035 TO |
77 | * |
78 | * @var int | |
6a488035 TO |
79 | */ |
80 | protected $_noteId = NULL; | |
81 | ||
82 | /** | |
0dc4ef42 | 83 | * |
84 | * Use parent $this->contactID | |
85 | * | |
66f9e52b | 86 | * The id of the contact associated with this participation. |
6a488035 TO |
87 | * |
88 | * @var int | |
90b461f1 | 89 | * @deprecated |
6a488035 TO |
90 | */ |
91 | public $_contactId; | |
92 | ||
93 | /** | |
66f9e52b | 94 | * Array of event values. |
6a488035 TO |
95 | * |
96 | * @var array | |
6a488035 TO |
97 | */ |
98 | protected $_event; | |
99 | ||
100 | /** | |
101 | * Are we operating in "single mode", i.e. adding / editing only | |
102 | * one participant record, or is this a batch add operation | |
103 | * | |
d51c6add | 104 | * @var bool |
6a488035 TO |
105 | */ |
106 | public $_single = FALSE; | |
107 | ||
108 | /** | |
66f9e52b | 109 | * If event is paid or unpaid. |
b2a8013e | 110 | * |
90b461f1 | 111 | * @var bool |
6a488035 TO |
112 | */ |
113 | public $_isPaidEvent; | |
114 | ||
115 | /** | |
66f9e52b | 116 | * Page action. |
b2a8013e | 117 | * |
90b461f1 | 118 | * @var int |
6a488035 TO |
119 | */ |
120 | public $_action; | |
121 | ||
6a488035 | 122 | /** |
66f9e52b | 123 | * Event Type Id. |
b2a8013e | 124 | * |
90b461f1 | 125 | * @var int |
6a488035 TO |
126 | */ |
127 | protected $_eventTypeId = NULL; | |
128 | ||
129 | /** | |
66f9e52b | 130 | * Participant status Id. |
b2a8013e | 131 | * |
90b461f1 | 132 | * @var int |
6a488035 TO |
133 | */ |
134 | protected $_statusId = NULL; | |
135 | ||
136 | /** | |
66f9e52b | 137 | * Cache all the participant statuses. |
b2a8013e | 138 | * |
90b461f1 | 139 | * @var array |
6a488035 TO |
140 | */ |
141 | protected $_participantStatuses; | |
142 | ||
143 | /** | |
66f9e52b | 144 | * Participant mode. |
b2a8013e | 145 | * |
90b461f1 | 146 | * @var string |
6a488035 TO |
147 | */ |
148 | public $_mode = NULL; | |
149 | ||
150 | /** | |
66f9e52b | 151 | * Event ID preselect. |
b2a8013e | 152 | * |
90b461f1 | 153 | * @var int |
6a488035 TO |
154 | */ |
155 | public $_eID = NULL; | |
156 | ||
c490a46a | 157 | /** |
66f9e52b | 158 | * Line Item for Price Set. |
b2a8013e | 159 | * |
90b461f1 | 160 | * @var array |
c490a46a | 161 | */ |
6a488035 | 162 | public $_lineItem = NULL; |
6a488035 | 163 | |
d424ffde | 164 | /** |
66f9e52b | 165 | * Contribution mode for event registration for offline mode. |
b2a8013e | 166 | * |
90b461f1 | 167 | * @var string |
0f2b049e | 168 | * @deprecated |
c490a46a | 169 | */ |
6a488035 TO |
170 | public $_contributeMode = 'direct'; |
171 | ||
172 | public $_online; | |
173 | ||
174 | /** | |
100fef9d | 175 | * Store id of role custom data type ( option value ) |
b2a8013e | 176 | * |
90b461f1 | 177 | * @var int |
6a488035 TO |
178 | */ |
179 | protected $_roleCustomDataTypeID; | |
180 | ||
181 | /** | |
100fef9d | 182 | * Store id of event Name custom data type ( option value) |
b2a8013e | 183 | * |
90b461f1 | 184 | * @var int |
6a488035 TO |
185 | */ |
186 | protected $_eventNameCustomDataTypeID; | |
187 | ||
188 | /** | |
66f9e52b | 189 | * Selected discount id. |
b2a8013e | 190 | * |
90b461f1 | 191 | * @var int |
6a488035 TO |
192 | */ |
193 | public $_originalDiscountId = NULL; | |
194 | ||
195 | /** | |
66f9e52b | 196 | * Event id. |
b2a8013e | 197 | * |
90b461f1 | 198 | * @var int |
6a488035 TO |
199 | */ |
200 | public $_eventId = NULL; | |
201 | ||
202 | /** | |
100fef9d | 203 | * Id of payment, if any |
b2a8013e | 204 | * |
90b461f1 | 205 | * @var int |
6a488035 TO |
206 | */ |
207 | public $_paymentId = NULL; | |
208 | ||
9a4df24c | 209 | /** |
9a4df24c | 210 | * @var null |
90b461f1 | 211 | * @todo add explanatory note about this |
9a4df24c EM |
212 | */ |
213 | public $_onlinePendingContributionId = NULL; | |
d5965a37 | 214 | |
a3aed42a | 215 | /** |
216 | * Stored participant record. | |
217 | * | |
218 | * @var array | |
219 | */ | |
220 | protected $participantRecord; | |
221 | ||
d3e6e9a4 | 222 | /** |
223 | * Params for creating a payment to add to the contribution. | |
224 | * | |
225 | * @var array | |
226 | */ | |
227 | protected $createPaymentParams = []; | |
228 | ||
229 | /** | |
230 | * Get params to create payments. | |
231 | * | |
232 | * @return array | |
233 | */ | |
234 | public function getCreatePaymentParams(): array { | |
235 | return $this->createPaymentParams; | |
236 | } | |
237 | ||
238 | /** | |
239 | * Set params to create payments. | |
240 | * | |
241 | * @param array $createPaymentParams | |
242 | */ | |
243 | public function setCreatePaymentParams(array $createPaymentParams) { | |
244 | $this->createPaymentParams = $createPaymentParams; | |
245 | } | |
246 | ||
6e62b28c TM |
247 | /** |
248 | * Explicitly declare the entity api name. | |
249 | */ | |
250 | public function getDefaultEntity() { | |
251 | return 'Participant'; | |
252 | } | |
9a4df24c | 253 | |
c1a6d6ac SL |
254 | /** |
255 | * Default form context used as part of addField() | |
256 | */ | |
257 | public function getDefaultContext() { | |
258 | return 'create'; | |
259 | } | |
260 | ||
6a488035 | 261 | /** |
66f9e52b | 262 | * Set variables up before form is built. |
6a488035 | 263 | * |
6ba1830e | 264 | * @throws \CRM_Core_Exception |
b28a34c3 | 265 | * @throws \CiviCRM_API3_Exception |
6a488035 TO |
266 | */ |
267 | public function preProcess() { | |
0dc4ef42 | 268 | parent::preProcess(); |
9c1bc317 | 269 | $this->_showFeeBlock = $_GET['eventId'] ?? NULL; |
6a488035 TO |
270 | $this->assign('showFeeBlock', FALSE); |
271 | $this->assign('feeBlockPaid', FALSE); | |
272 | ||
0dc4ef42 | 273 | // @todo eliminate this duplication. |
274 | $this->_contactId = $this->_contactID; | |
353ffa53 | 275 | $this->_eID = CRM_Utils_Request::retrieve('eid', 'Positive', $this); |
edc80cda | 276 | $this->_context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this); |
6a488035 TO |
277 | $this->assign('context', $this->_context); |
278 | ||
0dc4ef42 | 279 | if ($this->_contactID) { |
be2fb01f | 280 | $this->setPageTitle(ts('Event Registration for %1', [1 => $this->userDisplayName])); |
e2046b33 CW |
281 | } |
282 | else { | |
283 | $this->setPageTitle(ts('Event Registration')); | |
6a488035 TO |
284 | } |
285 | ||
286 | // check the current path, if search based, then dont get participantID | |
287 | // CRM-5792 | |
288 | $path = CRM_Utils_System::currentPath(); | |
0edbaec6 JM |
289 | if ( |
290 | strpos($path, 'civicrm/contact/search') === 0 || | |
291 | strpos($path, 'civicrm/group/search') === 0 | |
353ffa53 | 292 | ) { |
6a488035 TO |
293 | $this->_id = NULL; |
294 | } | |
295 | else { | |
675f074e | 296 | $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); |
6a488035 TO |
297 | } |
298 | ||
299 | if ($this->_id) { | |
29c61b58 | 300 | $this->assign('participantId', $this->_id); |
29c61b58 | 301 | |
6a488035 TO |
302 | $this->_paymentId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', |
303 | $this->_id, 'id', 'participant_id' | |
304 | ); | |
0b2b58ea PJ |
305 | |
306 | $this->assign('hasPayment', $this->_paymentId); | |
685dc433 PN |
307 | $this->assign('componentId', $this->_id); |
308 | $this->assign('component', 'event'); | |
0b2b58ea | 309 | |
a4e0d7b5 DG |
310 | // CRM-12615 - Get payment information from the primary registration |
311 | if ((!$this->_paymentId) && ($this->_action == CRM_Core_Action::UPDATE)) { | |
312 | $registered_by_id = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', | |
313 | $this->_id, 'registered_by_id', 'id' | |
314 | ); | |
315 | if ($registered_by_id) { | |
316 | $this->_paymentId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', | |
317 | $registered_by_id, 'id', 'participant_id' | |
318 | ); | |
319 | $this->assign('registeredByParticipantId', $registered_by_id); | |
320 | } | |
321 | } | |
6a488035 | 322 | } |
5fda4b16 | 323 | $this->setCustomDataTypes(); |
6a488035 TO |
324 | |
325 | if ($this->_mode) { | |
326 | $this->assign('participantMode', $this->_mode); | |
6a488035 TO |
327 | } |
328 | ||
329 | if ($this->_showFeeBlock) { | |
330 | $this->assign('showFeeBlock', TRUE); | |
331 | $isMonetary = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_showFeeBlock, 'is_monetary'); | |
332 | if ($isMonetary) { | |
333 | $this->assign('feeBlockPaid', TRUE); | |
334 | } | |
335 | return CRM_Event_Form_EventFees::preProcess($this); | |
336 | } | |
337 | ||
6a488035 TO |
338 | //check the mode when this form is called either single or as |
339 | //search task action | |
340 | if ($this->_id || $this->_contactId || $this->_context == 'standalone') { | |
341 | $this->_single = TRUE; | |
342 | $this->assign('urlPath', 'civicrm/contact/view/participant'); | |
343 | if (!$this->_id && !$this->_contactId) { | |
be2fb01f CW |
344 | $breadCrumbs = [ |
345 | [ | |
353ffa53 | 346 | 'title' => ts('CiviEvent Dashboard'), |
6a488035 | 347 | 'url' => CRM_Utils_System::url('civicrm/event', 'reset=1'), |
be2fb01f CW |
348 | ], |
349 | ]; | |
6a488035 TO |
350 | |
351 | CRM_Utils_System::appendBreadCrumb($breadCrumbs); | |
352 | } | |
353 | } | |
354 | else { | |
355 | //set the appropriate action | |
353ffa53 TO |
356 | $context = $this->get('context'); |
357 | $urlString = 'civicrm/contact/search'; | |
6a488035 TO |
358 | $this->_action = CRM_Core_Action::BASIC; |
359 | switch ($context) { | |
360 | case 'advanced': | |
361 | $urlString = 'civicrm/contact/search/advanced'; | |
362 | $this->_action = CRM_Core_Action::ADVANCED; | |
363 | break; | |
364 | ||
365 | case 'builder': | |
366 | $urlString = 'civicrm/contact/search/builder'; | |
367 | $this->_action = CRM_Core_Action::PROFILE; | |
368 | break; | |
369 | ||
370 | case 'basic': | |
371 | $urlString = 'civicrm/contact/search/basic'; | |
372 | $this->_action = CRM_Core_Action::BASIC; | |
373 | break; | |
374 | ||
375 | case 'custom': | |
376 | $urlString = 'civicrm/contact/search/custom'; | |
377 | $this->_action = CRM_Core_Action::COPY; | |
378 | break; | |
379 | } | |
42e8b05c | 380 | CRM_Contact_Form_Task::preProcessCommon($this); |
6a488035 TO |
381 | |
382 | $this->_single = FALSE; | |
383 | $this->_contactId = NULL; | |
384 | ||
385 | //set ajax path, this used for custom data building | |
386 | $this->assign('urlPath', $urlString); | |
387 | $this->assign('urlPathVar', "_qf_Participant_display=true&qfKey={$this->controller->_key}"); | |
388 | } | |
389 | ||
390 | $this->assign('single', $this->_single); | |
391 | ||
392 | if (!$this->_id) { | |
393 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add'); | |
394 | } | |
395 | $this->assign('action', $this->_action); | |
396 | ||
397 | // check for edit permission | |
398 | if (!CRM_Core_Permission::checkActionPermission('CiviEvent', $this->_action)) { | |
e22ec653 | 399 | CRM_Core_Error::statusBounce(ts('You do not have permission to access this page.')); |
6a488035 TO |
400 | } |
401 | ||
402 | if ($this->_action & CRM_Core_Action::DELETE) { | |
403 | // check delete permission for contribution | |
404 | if ($this->_id && $this->_paymentId && !CRM_Core_Permission::checkActionPermission('CiviContribute', $this->_action)) { | |
e22ec653 | 405 | CRM_Core_Error::statusBounce(ts("This Participant is linked to a contribution. You must have 'delete in CiviContribute' permission in order to delete this record.")); |
6a488035 TO |
406 | } |
407 | return; | |
408 | } | |
409 | ||
410 | if ($this->_id) { | |
411 | // assign participant id to the template | |
412 | $this->assign('participantId', $this->_id); | |
6a488035 TO |
413 | } |
414 | ||
415 | // when fee amount is included in form | |
8cc574cf | 416 | if (!empty($_POST['hidden_feeblock']) || !empty($_POST['send_receipt'])) { |
6a488035 | 417 | CRM_Event_Form_EventFees::preProcess($this); |
eeca0339 | 418 | $this->buildEventFeeForm($this); |
6a488035 TO |
419 | CRM_Event_Form_EventFees::setDefaultValues($this); |
420 | } | |
421 | ||
422 | // when custom data is included in this page | |
a7488080 | 423 | if (!empty($_POST['hidden_custom'])) { |
2975f0aa | 424 | $eventId = (int) ($_POST['event_id'] ?? 0); |
7df021e5 | 425 | // Custom data of type participant role |
426 | // Note: Some earlier commits imply $_POST['role_id'] could be a comma separated string, | |
427 | // not sure if that ever really happens | |
a7488080 | 428 | if (!empty($_POST['role_id'])) { |
7df021e5 | 429 | foreach ($_POST['role_id'] as $roleID) { |
430 | CRM_Custom_Form_CustomData::preProcess($this, $this->_roleCustomDataTypeID, $roleID, 1, 'Participant', $this->_id); | |
6a488035 TO |
431 | CRM_Custom_Form_CustomData::buildQuickForm($this); |
432 | CRM_Custom_Form_CustomData::setDefaultValues($this); | |
433 | } | |
434 | } | |
435 | ||
436 | //custom data of type participant event | |
6452294d | 437 | CRM_Custom_Form_CustomData::preProcess($this, $this->_eventNameCustomDataTypeID, $eventId, 1, 'Participant', $this->_id); |
6a488035 TO |
438 | CRM_Custom_Form_CustomData::buildQuickForm($this); |
439 | CRM_Custom_Form_CustomData::setDefaultValues($this); | |
440 | ||
441 | // custom data of type participant event type | |
442 | $eventTypeId = NULL; | |
6452294d | 443 | if ($eventId) { |
6a488035 TO |
444 | $eventTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventId, 'event_type_id', 'id'); |
445 | } | |
446 | CRM_Custom_Form_CustomData::preProcess($this, $this->_eventTypeCustomDataTypeID, $eventTypeId, | |
447 | 1, 'Participant', $this->_id | |
448 | ); | |
449 | CRM_Custom_Form_CustomData::buildQuickForm($this); | |
450 | CRM_Custom_Form_CustomData::setDefaultValues($this); | |
451 | ||
452 | //custom data of type participant, ( we 'null' to reset subType and subName) | |
453 | CRM_Custom_Form_CustomData::preProcess($this, 'null', 'null', 1, 'Participant', $this->_id); | |
454 | CRM_Custom_Form_CustomData::buildQuickForm($this); | |
455 | CRM_Custom_Form_CustomData::setDefaultValues($this); | |
456 | } | |
457 | ||
458 | // CRM-4395, get the online pending contribution id. | |
459 | $this->_onlinePendingContributionId = NULL; | |
460 | if (!$this->_mode && $this->_id && ($this->_action & CRM_Core_Action::UPDATE)) { | |
461 | $this->_onlinePendingContributionId = CRM_Contribute_BAO_Contribution::checkOnlinePendingContribution($this->_id, | |
462 | 'Event' | |
463 | ); | |
464 | } | |
465 | $this->set('onlinePendingContributionId', $this->_onlinePendingContributionId); | |
6a488035 TO |
466 | } |
467 | ||
468 | /** | |
469 | * This function sets the default values for the form in edit/view mode | |
470 | * the default values are retrieved from the database | |
471 | * | |
6ba1830e MWMC |
472 | * @return array |
473 | * @throws \CRM_Core_Exception | |
6a488035 TO |
474 | */ |
475 | public function setDefaultValues() { | |
476 | if ($this->_showFeeBlock) { | |
477 | return CRM_Event_Form_EventFees::setDefaultValues($this); | |
478 | } | |
479 | ||
be2fb01f | 480 | $defaults = []; |
6a488035 TO |
481 | |
482 | if ($this->_action & CRM_Core_Action::DELETE) { | |
483 | return $defaults; | |
484 | } | |
485 | ||
486 | if ($this->_id) { | |
be2fb01f CW |
487 | $ids = []; |
488 | $params = ['id' => $this->_id]; | |
6a488035 TO |
489 | |
490 | CRM_Event_BAO_Participant::getValues($params, $defaults, $ids); | |
491 | $sep = CRM_Core_DAO::VALUE_SEPARATOR; | |
492 | if ($defaults[$this->_id]['role_id']) { | |
bdc20176 | 493 | $roleIDs = explode($sep, $defaults[$this->_id]['role_id']); |
6a488035 TO |
494 | } |
495 | $this->_contactId = $defaults[$this->_id]['contact_id']; | |
496 | $this->_statusId = $defaults[$this->_id]['participant_status_id']; | |
497 | ||
498 | //set defaults for note | |
499 | $noteDetails = CRM_Core_BAO_Note::getNote($this->_id, 'civicrm_participant'); | |
500 | $defaults[$this->_id]['note'] = array_pop($noteDetails); | |
501 | ||
502 | // Check if this is a primaryParticipant (registered for others) and retrieve additional participants if true (CRM-4859) | |
503 | if (CRM_Event_BAO_Participant::isPrimaryParticipant($this->_id)) { | |
504 | $this->assign('additionalParticipants', CRM_Event_BAO_Participant::getAdditionalParticipants($this->_id)); | |
505 | } | |
506 | ||
507 | // Get registered_by contact ID and display_name if participant was registered by someone else (CRM-4859) | |
a7488080 | 508 | if (!empty($defaults[$this->_id]['participant_registered_by_id'])) { |
6a488035 TO |
509 | $registered_by_contact_id = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', |
510 | $defaults[$this->_id]['participant_registered_by_id'], | |
511 | 'contact_id', 'id' | |
512 | ); | |
513 | $this->assign('participant_registered_by_id', $defaults[$this->_id]['participant_registered_by_id']); | |
514 | $this->assign('registered_by_contact_id', $registered_by_contact_id); | |
515 | $this->assign('registered_by_display_name', CRM_Contact_BAO_Contact::displayName($registered_by_contact_id)); | |
516 | } | |
517 | } | |
2944baac | 518 | elseif ($this->_contactID) { |
519 | $defaults[$this->_id]['contact_id'] = $this->_contactID; | |
520 | } | |
6a488035 | 521 | |
6a488035 TO |
522 | //setting default register date |
523 | if ($this->_action == CRM_Core_Action::ADD) { | |
e4659866 | 524 | $statuses = array_flip(CRM_Event_PseudoConstant::participantStatus()); |
9c1bc317 | 525 | $defaults[$this->_id]['status_id'] = $statuses['Registered'] ?? NULL; |
a7488080 | 526 | if (!empty($defaults[$this->_id]['event_id'])) { |
6a488035 TO |
527 | $contributionTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', |
528 | $defaults[$this->_id]['event_id'], | |
bdc20176 | 529 | 'financial_type_id' |
d96cf288 | 530 | ); |
6a488035 | 531 | if ($contributionTypeId) { |
d96cf288 | 532 | $defaults[$this->_id]['financial_type_id'] = $contributionTypeId; |
6a488035 TO |
533 | } |
534 | } | |
535 | ||
536 | if ($this->_mode) { | |
537 | $fields["email-{$this->_bltID}"] = 1; | |
538 | $fields['email-Primary'] = 1; | |
539 | ||
540 | if ($this->_contactId) { | |
541 | CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactId, $fields, $defaults); | |
542 | } | |
543 | ||
544 | if (empty($defaults["email-{$this->_bltID}"]) && | |
545 | !empty($defaults['email-Primary']) | |
546 | ) { | |
547 | $defaults[$this->_id]["email-{$this->_bltID}"] = $defaults['email-Primary']; | |
548 | } | |
549 | } | |
550 | ||
551 | $submittedRole = $this->getElementValue('role_id'); | |
a7488080 | 552 | if (!empty($submittedRole[0])) { |
6a488035 TO |
553 | $roleID = $submittedRole[0]; |
554 | } | |
555 | $submittedEvent = $this->getElementValue('event_id'); | |
a4e49a48 | 556 | if (!empty($submittedEvent[0])) { |
6a488035 TO |
557 | $eventID = $submittedEvent[0]; |
558 | } | |
6ba1830e | 559 | $defaults[$this->_id]['register_date'] = date('Y-m-d H:i:s'); |
6a488035 TO |
560 | } |
561 | else { | |
562 | $defaults[$this->_id]['record_contribution'] = 0; | |
563 | ||
564 | if ($defaults[$this->_id]['participant_is_pay_later']) { | |
565 | $this->assign('participant_is_pay_later', TRUE); | |
566 | } | |
567 | ||
568 | $this->assign('participant_status_id', $defaults[$this->_id]['participant_status_id']); | |
6a488035 TO |
569 | $eventID = $defaults[$this->_id]['event_id']; |
570 | ||
571 | $this->_eventTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id'); | |
572 | ||
573 | $this->_discountId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'discount_id'); | |
574 | if ($this->_discountId) { | |
575 | $this->set('discountId', $this->_discountId); | |
576 | } | |
577 | } | |
578 | ||
6a488035 TO |
579 | //assign event and role id, this is needed for Custom data building |
580 | $sep = CRM_Core_DAO::VALUE_SEPARATOR; | |
a7488080 | 581 | if (!empty($defaults[$this->_id]['participant_role_id'])) { |
6a488035 TO |
582 | $roleIDs = explode($sep, $defaults[$this->_id]['participant_role_id']); |
583 | } | |
6a488035 TO |
584 | if (isset($_POST['event_id'])) { |
585 | $eventID = $_POST['event_id']; | |
bdc20176 PJ |
586 | } |
587 | ||
22e263ad | 588 | if ($this->_eID) { |
bdc20176 PJ |
589 | $eventID = $this->_eID; |
590 | //@todo - rationalise the $this->_eID with $POST['event_id'], $this->_eid is set when eid=x is in the url | |
591 | $roleID = CRM_Core_DAO::getFieldValue( | |
592 | 'CRM_Event_DAO_Event', | |
593 | $this->_eID, | |
594 | 'default_role_id' | |
595 | ); | |
22e263ad | 596 | if (empty($roleIDs)) { |
bdc20176 | 597 | $roleIDs = (array) $defaults[$this->_id]['participant_role_id'] = $roleID; |
6a488035 | 598 | } |
bdc20176 PJ |
599 | $defaults[$this->_id]['event_id'] = $eventID; |
600 | } | |
601 | if (!empty($eventID)) { | |
602 | $this->_eventTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id'); | |
603 | } | |
604 | //these should take precedence so we state them last | |
605 | $urlRoleIDS = CRM_Utils_Request::retrieve('roles', 'String'); | |
22e263ad | 606 | if ($urlRoleIDS) { |
bdc20176 PJ |
607 | $roleIDs = explode(',', $urlRoleIDS); |
608 | } | |
609 | if (isset($roleIDs)) { | |
cd120ea0 | 610 | $defaults[$this->_id]['role_id'] = implode(',', $roleIDs); |
6a488035 TO |
611 | } |
612 | ||
613 | if (isset($eventID)) { | |
614 | $this->assign('eventID', $eventID); | |
615 | $this->set('eventId', $eventID); | |
616 | } | |
617 | ||
618 | if (isset($this->_eventTypeId)) { | |
619 | $this->assign('eventTypeID', $this->_eventTypeId); | |
620 | } | |
621 | ||
622 | $this->assign('event_is_test', CRM_Utils_Array::value('event_is_test', $defaults[$this->_id])); | |
623 | return $defaults[$this->_id]; | |
624 | } | |
625 | ||
626 | /** | |
66f9e52b | 627 | * Build the form object. |
6a488035 | 628 | * |
355ba699 | 629 | * @return void |
6ba1830e MWMC |
630 | * @throws \CRM_Core_Exception |
631 | * @throws \CiviCRM_API3_Exception | |
6a488035 TO |
632 | */ |
633 | public function buildQuickForm() { | |
5774b54f | 634 | |
e8cf3013 PJ |
635 | $participantStatuses = CRM_Event_PseudoConstant::participantStatus(); |
636 | $partiallyPaidStatusId = array_search('Partially paid', $participantStatuses); | |
81f3d017 | 637 | $this->assign('partiallyPaidStatusId', $partiallyPaidStatusId); |
e8cf3013 | 638 | |
6a488035 | 639 | if ($this->_showFeeBlock) { |
eeca0339 | 640 | return $this->buildEventFeeForm($this); |
6a488035 TO |
641 | } |
642 | ||
6a488035 TO |
643 | //need to assign custom data type to the template |
644 | $this->assign('customDataType', 'Participant'); | |
645 | ||
646 | $this->applyFilter('__ALL__', 'trim'); | |
647 | ||
648 | if ($this->_action & CRM_Core_Action::DELETE) { | |
649 | if ($this->_single) { | |
650 | $additionalParticipant = count(CRM_Event_BAO_Event::buildCustomProfile($this->_id, | |
651 | NULL, | |
652 | $this->_contactId, | |
653 | FALSE, | |
654 | TRUE | |
655 | )) - 1; | |
656 | if ($additionalParticipant) { | |
be2fb01f | 657 | $deleteParticipants = [ |
353ffa53 | 658 | 1 => ts('Delete this participant record along with associated participant record(s).'), |
6a488035 | 659 | 2 => ts('Delete only this participant record.'), |
be2fb01f | 660 | ]; |
6a488035 | 661 | $this->addRadio('delete_participant', NULL, $deleteParticipants, NULL, '<br />'); |
be2fb01f | 662 | $this->setDefaults(['delete_participant' => 1]); |
6a488035 TO |
663 | $this->assign('additionalParticipant', $additionalParticipant); |
664 | } | |
665 | } | |
be2fb01f | 666 | $this->addButtons([ |
90b461f1 SL |
667 | [ |
668 | 'type' => 'next', | |
669 | 'name' => ts('Delete'), | |
670 | 'spacing' => ' ', | |
671 | 'isDefault' => TRUE, | |
672 | ], | |
673 | [ | |
674 | 'type' => 'cancel', | |
675 | 'name' => ts('Cancel'), | |
676 | ], | |
677 | ]); | |
6a488035 TO |
678 | return; |
679 | } | |
680 | ||
2944baac | 681 | if ($this->_single) { |
682 | $contactField = $this->addEntityRef('contact_id', ts('Participant'), ['create' => TRUE, 'api' => ['extra' => ['email']]], TRUE); | |
683 | if ($this->_context != 'standalone') { | |
684 | $contactField->freeze(); | |
685 | } | |
6a488035 | 686 | } |
6a488035 | 687 | |
be2fb01f | 688 | $eventFieldParams = [ |
af00ced5 | 689 | 'entity' => 'Event', |
be2fb01f CW |
690 | 'select' => ['minimumInputLength' => 0], |
691 | 'api' => [ | |
692 | 'extra' => ['campaign_id', 'default_role_id', 'event_type_id'], | |
693 | ], | |
694 | ]; | |
6a488035 TO |
695 | |
696 | if ($this->_mode) { | |
1beb268a CW |
697 | // exclude events which are not monetary when credit card registration is used |
698 | $eventFieldParams['api']['params']['is_monetary'] = 1; | |
6a488035 | 699 | } |
b15c60e1 | 700 | $this->addPaymentProcessorSelect(TRUE, FALSE, FALSE); |
6a488035 | 701 | |
1beb268a | 702 | $element = $this->addEntityRef('event_id', ts('Event'), $eventFieldParams, TRUE); |
6a488035 TO |
703 | |
704 | //frozen the field fix for CRM-4171 | |
705 | if ($this->_action & CRM_Core_Action::UPDATE && $this->_id) { | |
706 | if (CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', | |
353ffa53 TO |
707 | $this->_id, 'contribution_id', 'participant_id' |
708 | ) | |
709 | ) { | |
6a488035 TO |
710 | $element->freeze(); |
711 | } | |
712 | } | |
713 | ||
714 | //CRM-7362 --add campaigns. | |
715 | $campaignId = NULL; | |
716 | if ($this->_id) { | |
717 | $campaignId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'campaign_id'); | |
718 | } | |
719 | if (!$campaignId) { | |
720 | $eventId = CRM_Utils_Request::retrieve('eid', 'Positive', $this); | |
721 | if ($eventId) { | |
722 | $campaignId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventId, 'campaign_id'); | |
723 | } | |
724 | } | |
725 | CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId); | |
be2fb01f | 726 | $this->add('datepicker', 'register_date', ts('Registration Date'), [], TRUE, ['time' => TRUE]); |
6a488035 TO |
727 | |
728 | if ($this->_id) { | |
729 | $this->assign('entityID', $this->_id); | |
730 | } | |
731 | ||
be2fb01f | 732 | $this->addSelect('role_id', ['multiple' => TRUE, 'class' => 'huge'], TRUE); |
6a488035 TO |
733 | |
734 | // CRM-4395 | |
be2fb01f | 735 | $checkCancelledJs = ['onchange' => "return sendNotification( );"]; |
6a488035 TO |
736 | $confirmJS = NULL; |
737 | if ($this->_onlinePendingContributionId) { | |
738 | $cancelledparticipantStatusId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus()); | |
739 | $cancelledContributionStatusId = array_search('Cancelled', | |
740 | CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name') | |
741 | ); | |
be2fb01f | 742 | $checkCancelledJs = [ |
a130e045 | 743 | 'onchange' => "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});", |
be2fb01f | 744 | ]; |
6a488035 TO |
745 | |
746 | $participantStatusId = array_search('Pending from pay later', | |
747 | CRM_Event_PseudoConstant::participantStatus() | |
748 | ); | |
749 | $contributionStatusId = array_search('Completed', | |
750 | CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name') | |
751 | ); | |
be2fb01f | 752 | $confirmJS = ['onclick' => "return confirmStatus( {$participantStatusId}, {$contributionStatusId} );"]; |
6a488035 TO |
753 | } |
754 | ||
453ed6d1 KJ |
755 | // get the participant status names to build special status array which is used to show notification |
756 | // checkbox below participant status select | |
757 | $participantStatusName = CRM_Event_PseudoConstant::participantStatus(); | |
be2fb01f | 758 | $notificationStatuses = [ |
453ed6d1 KJ |
759 | 'Cancelled', |
760 | 'Pending from waitlist', | |
761 | 'Pending from approval', | |
762 | 'Expired', | |
be2fb01f | 763 | ]; |
453ed6d1 KJ |
764 | |
765 | // get the required status and then implode only ids | |
766 | $notificationStatusIds = implode(',', array_keys(array_intersect($participantStatusName, $notificationStatuses))); | |
767 | $this->assign('notificationStatusIds', $notificationStatusIds); | |
768 | ||
f76b27fe | 769 | $this->_participantStatuses = $statusOptions = CRM_Event_BAO_Participant::buildOptions('status_id', 'create'); |
f6bae84f | 770 | |
f76b27fe CW |
771 | // Only show refund status when editing |
772 | if ($this->_action & CRM_Core_Action::ADD) { | |
773 | $pendingRefundStatusId = array_search('Pending refund', $participantStatusName); | |
774 | if ($pendingRefundStatusId) { | |
775 | unset($statusOptions[$pendingRefundStatusId]); | |
776 | } | |
777 | } | |
778 | ||
be2fb01f | 779 | $this->addSelect('status_id', $checkCancelledJs + [ |
90b461f1 SL |
780 | 'options' => $statusOptions, |
781 | 'option_url' => 'civicrm/admin/participant_status', | |
782 | ], TRUE); | |
6a488035 TO |
783 | |
784 | $this->addElement('checkbox', 'is_notify', ts('Send Notification'), NULL); | |
785 | ||
be2fb01f | 786 | $this->addField('source', ['entity' => 'Participant', 'name' => 'source']); |
6a488035 TO |
787 | $noteAttributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Note'); |
788 | $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']); | |
789 | ||
be2fb01f | 790 | $buttons[] = [ |
6a488035 TO |
791 | 'type' => 'upload', |
792 | 'name' => ts('Save'), | |
793 | 'isDefault' => TRUE, | |
794 | 'js' => $confirmJS, | |
be2fb01f | 795 | ]; |
6a488035 TO |
796 | |
797 | $path = CRM_Utils_System::currentPath(); | |
be2fb01f | 798 | $excludeForPaths = [ |
239a5027 | 799 | 'civicrm/contact/search', |
21dfd5f5 | 800 | 'civicrm/group/search', |
be2fb01f | 801 | ]; |
239a5027 | 802 | if (!in_array($path, $excludeForPaths)) { |
be2fb01f | 803 | $buttons[] = [ |
6a488035 TO |
804 | 'type' => 'upload', |
805 | 'name' => ts('Save and New'), | |
806 | 'subName' => 'new', | |
807 | 'js' => $confirmJS, | |
be2fb01f | 808 | ]; |
6a488035 | 809 | } |
239a5027 | 810 | |
be2fb01f | 811 | $buttons[] = [ |
6a488035 TO |
812 | 'type' => 'cancel', |
813 | 'name' => ts('Cancel'), | |
be2fb01f | 814 | ]; |
6a488035 TO |
815 | |
816 | $this->addButtons($buttons); | |
817 | if ($this->_action == CRM_Core_Action::VIEW) { | |
818 | $this->freeze(); | |
819 | } | |
820 | } | |
821 | ||
822 | /** | |
66f9e52b | 823 | * Add local and global form rules. |
6a488035 | 824 | * |
6a488035 TO |
825 | * @return void |
826 | */ | |
00be9182 | 827 | public function addRules() { |
be2fb01f | 828 | $this->addFormRule(['CRM_Event_Form_Participant', 'formRule'], $this); |
6a488035 TO |
829 | } |
830 | ||
831 | /** | |
66f9e52b | 832 | * Global validation rules for the form. |
6a488035 | 833 | * |
d4dd1e85 TO |
834 | * @param array $values |
835 | * Posted values of the form. | |
2a6da8d7 EM |
836 | * @param $files |
837 | * @param $self | |
838 | * | |
a6c01b45 CW |
839 | * @return array |
840 | * list of errors to be posted back to the form | |
6a488035 | 841 | */ |
00be9182 | 842 | public static function formRule($values, $files, $self) { |
6a488035 TO |
843 | // If $values['_qf_Participant_next'] is Delete or |
844 | // $values['event_id'] is empty, then return | |
845 | // instead of proceeding further. | |
846 | ||
847 | if ((CRM_Utils_Array::value('_qf_Participant_next', $values) == 'Delete') || | |
848 | (!$values['event_id']) | |
849 | ) { | |
850 | return TRUE; | |
851 | } | |
852 | ||
be2fb01f | 853 | $errorMsg = []; |
6a488035 | 854 | |
a7488080 | 855 | if (!empty($values['payment_processor_id'])) { |
a479fe60 | 856 | // make sure that payment instrument values (e.g. credit card number and cvv) are valid |
f48e6cf7 | 857 | CRM_Core_Payment_Form::validatePaymentInstrument($values['payment_processor_id'], $values, $errorMsg, NULL); |
6a488035 TO |
858 | } |
859 | ||
a7488080 CW |
860 | if (!empty($values['record_contribution'])) { |
861 | if (empty($values['financial_type_id'])) { | |
d96cf288 DG |
862 | $errorMsg['financial_type_id'] = ts('Please enter the associated Financial Type'); |
863 | } | |
a7488080 | 864 | if (empty($values['payment_instrument_id'])) { |
4db803dd | 865 | $errorMsg['payment_instrument_id'] = ts('Payment Method is a required field.'); |
d96cf288 | 866 | } |
610d2dac JP |
867 | if (!empty($values['priceSetId'])) { |
868 | CRM_Price_BAO_PriceField::priceSetValidation($values['priceSetId'], $values, $errorMsg); | |
869 | } | |
6a488035 TO |
870 | } |
871 | ||
872 | // validate contribution status for 'Failed'. | |
8cc574cf | 873 | if ($self->_onlinePendingContributionId && !empty($values['record_contribution']) && |
6a488035 TO |
874 | (CRM_Utils_Array::value('contribution_status_id', $values) == |
875 | array_search('Failed', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name')) | |
876 | ) | |
877 | ) { | |
878 | $errorMsg['contribution_status_id'] = ts('Please select a valid payment status before updating.'); | |
879 | } | |
880 | ||
881 | // do the amount validations. | |
882 | //skip for update mode since amount is freeze, CRM-6052 | |
8cc574cf | 883 | if ((!$self->_id && empty($values['total_amount']) && |
6a488035 TO |
884 | empty($self->_values['line_items']) |
885 | ) || | |
886 | ($self->_id && !$self->_paymentId && isset($self->_values['line_items']) && is_array($self->_values['line_items'])) | |
887 | ) { | |
888 | if ($priceSetId = CRM_Utils_Array::value('priceSetId', $values)) { | |
9da8dc8c | 889 | CRM_Price_BAO_PriceField::priceSetValidation($priceSetId, $values, $errorMsg, TRUE); |
6a488035 TO |
890 | } |
891 | } | |
4d3f1e42 | 892 | // For single additions - show validation error if the contact has already been registered |
c0558721 | 893 | // for this event. |
22e263ad | 894 | if ($self->_single && ($self->_action & CRM_Core_Action::ADD)) { |
c0558721 | 895 | if ($self->_context == 'standalone') { |
9c1bc317 | 896 | $contactId = $values['contact_id'] ?? NULL; |
c0558721 TS |
897 | } |
898 | else { | |
899 | $contactId = $self->_contactId; | |
900 | } | |
901 | ||
9c1bc317 | 902 | $eventId = $values['event_id'] ?? NULL; |
7a6b2b25 ML |
903 | |
904 | $event = new CRM_Event_DAO_Event(); | |
905 | $event->id = $eventId; | |
906 | $event->find(TRUE); | |
907 | ||
908 | if (!$event->allow_same_participant_emails && !empty($contactId) && !empty($eventId)) { | |
81767ac6 | 909 | $cancelledStatusID = CRM_Core_PseudoConstant::getKey('CRM_Event_BAO_Participant', 'status_id', 'Cancelled'); |
a130e045 | 910 | $dupeCheck = new CRM_Event_BAO_Participant(); |
4d3f1e42 JM |
911 | $dupeCheck->contact_id = $contactId; |
912 | $dupeCheck->event_id = $eventId; | |
81767ac6 | 913 | $dupeCheck->whereAdd("status_id != {$cancelledStatusID} "); |
4d3f1e42 | 914 | $dupeCheck->find(TRUE); |
22e263ad | 915 | if (!empty($dupeCheck->id)) { |
4d3f1e42 JM |
916 | $errorMsg['event_id'] = ts("This contact has already been assigned to this event."); |
917 | } | |
918 | } | |
919 | } | |
6a488035 TO |
920 | return CRM_Utils_Array::crmIsEmptyArray($errorMsg) ? TRUE : $errorMsg; |
921 | } | |
922 | ||
923 | /** | |
66f9e52b | 924 | * Process the form submission. |
6a488035 TO |
925 | */ |
926 | public function postProcess() { | |
927 | // get the submitted form values. | |
928 | $params = $this->controller->exportValues($this->_name); | |
929 | ||
930 | if ($this->_action & CRM_Core_Action::DELETE) { | |
931 | if (CRM_Utils_Array::value('delete_participant', $params) == 2) { | |
932 | $additionalId = (CRM_Event_BAO_Participant::getAdditionalParticipantIds($this->_id)); | |
933 | $participantLinks = (CRM_Event_BAO_Participant::getAdditionalParticipantUrl($additionalId)); | |
934 | } | |
935 | if (CRM_Utils_Array::value('delete_participant', $params) == 1) { | |
936 | $additionalIds = CRM_Event_BAO_Participant::getAdditionalParticipantIds($this->_id); | |
937 | foreach ($additionalIds as $value) { | |
938 | CRM_Event_BAO_Participant::deleteParticipant($value); | |
939 | } | |
940 | } | |
941 | CRM_Event_BAO_Participant::deleteParticipant($this->_id); | |
942 | CRM_Core_Session::setStatus(ts('Selected participant was deleted successfully.'), ts('Record Deleted'), 'success'); | |
943 | if (!empty($participantLinks)) { | |
d3e86119 | 944 | $status = ts('The following participants no longer have an event fee recorded. You can edit their registration and record a replacement contribution by clicking the links below:') . '<br/>' . $participantLinks; |
6a488035 TO |
945 | CRM_Core_Session::setStatus($status, ts('Group Payment Deleted')); |
946 | } | |
947 | return; | |
948 | } | |
4d3f1e42 JM |
949 | // When adding a single contact, the formRule prevents you from adding duplicates |
950 | // (See above in formRule()). When adding more than one contact, the duplicates are | |
951 | // removed automatically and the user receives one notification. | |
952 | if ($this->_action & CRM_Core_Action::ADD) { | |
aae2f9e6 | 953 | $event_id = $this->_eventId; |
22e263ad | 954 | if (empty($event_id) && !empty($params['event_id'])) { |
aae2f9e6 JM |
955 | $event_id = $params['event_id']; |
956 | } | |
22e263ad | 957 | if (!$this->_single && !empty($event_id)) { |
4d3f1e42 | 958 | $duplicateContacts = 0; |
5cda87ee | 959 | foreach ($this->_contactIds as $k => $dupeCheckContactId) { |
4d3f1e42 | 960 | // Eliminate contacts that have already been assigned to this event. |
a130e045 | 961 | $dupeCheck = new CRM_Event_BAO_Participant(); |
4d3f1e42 | 962 | $dupeCheck->contact_id = $dupeCheckContactId; |
aae2f9e6 | 963 | $dupeCheck->event_id = $event_id; |
4d3f1e42 | 964 | $dupeCheck->find(TRUE); |
22e263ad | 965 | if (!empty($dupeCheck->id)) { |
4d3f1e42 JM |
966 | $duplicateContacts++; |
967 | unset($this->_contactIds[$k]); | |
968 | } | |
969 | } | |
22e263ad | 970 | if ($duplicateContacts > 0) { |
4d3f1e42 JM |
971 | $msg = ts( |
972 | "%1 contacts have already been assigned to this event. They were not added a second time.", | |
be2fb01f | 973 | [1 => $duplicateContacts] |
4d3f1e42 JM |
974 | ); |
975 | CRM_Core_Session::setStatus($msg); | |
976 | } | |
22e263ad | 977 | if (count($this->_contactIds) == 0) { |
4d3f1e42 JM |
978 | CRM_Core_Session::setStatus(ts("No participants were added.")); |
979 | return; | |
980 | } | |
aef8149f JM |
981 | // We have to re-key $this->_contactIds so each contact has the same |
982 | // key as their corresponding record in the $participants array that | |
983 | // will be created below. | |
984 | $this->_contactIds = array_values($this->_contactIds); | |
4d3f1e42 JM |
985 | } |
986 | } | |
987 | ||
5fda4b16 | 988 | $statusMsg = $this->submit($params); |
989 | CRM_Core_Session::setStatus($statusMsg, ts('Saved'), 'success'); | |
990 | $session = CRM_Core_Session::singleton(); | |
991 | $buttonName = $this->controller->getButtonName(); | |
992 | if ($this->_context == 'standalone') { | |
993 | if ($buttonName == $this->getButtonName('upload', 'new')) { | |
994 | $urlParams = 'reset=1&action=add&context=standalone'; | |
995 | if ($this->_mode) { | |
996 | $urlParams .= '&mode=' . $this->_mode; | |
997 | } | |
998 | if ($this->_eID) { | |
999 | $urlParams .= '&eid=' . $this->_eID; | |
1000 | } | |
1001 | $session->replaceUserContext(CRM_Utils_System::url('civicrm/participant/add', $urlParams)); | |
1002 | } | |
1003 | else { | |
1004 | $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', | |
1005 | "reset=1&cid={$this->_contactId}&selectedChild=participant" | |
1006 | )); | |
1007 | } | |
1008 | } | |
1009 | elseif ($buttonName == $this->getButtonName('upload', 'new')) { | |
1010 | $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view/participant', | |
1011 | "reset=1&action=add&context={$this->_context}&cid={$this->_contactId}" | |
1012 | )); | |
1013 | } | |
1014 | } | |
1015 | ||
1016 | /** | |
1017 | * Submit form. | |
1018 | * | |
1019 | * @param array $params | |
1020 | * | |
6ba1830e MWMC |
1021 | * @return string |
1022 | * @throws \CRM_Core_Exception | |
1023 | * @throws \CiviCRM_API3_Exception | |
5fda4b16 | 1024 | */ |
1025 | public function submit($params) { | |
8b652293 | 1026 | if ($this->_mode && !$this->_isPaidEvent) { |
1027 | CRM_Core_Error::statusBounce(ts('Selected Event is not Paid Event ')); | |
1028 | } | |
aac57c29 | 1029 | $participantStatus = CRM_Event_PseudoConstant::participantStatus(); |
6a488035 | 1030 | // set the contact, when contact is selected |
479696ed | 1031 | if (!empty($params['contact_id'])) { |
0dc4ef42 | 1032 | $this->_contactID = $this->_contactId = $params['contact_id']; |
6a488035 | 1033 | } |
89b6b472 | 1034 | if (!$this->_priceSetId && $this->_isPaidEvent) { |
b28a34c3 | 1035 | CRM_Core_Error::deprecatedFunctionWarning('this should never be true, handling to be removed'); |
1036 | } | |
9da8dc8c | 1037 | if ($this->_priceSetId && $isQuickConfig = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) { |
6a488035 TO |
1038 | $this->_quickConfig = $isQuickConfig; |
1039 | } | |
1040 | ||
1041 | if ($this->_id) { | |
1042 | $params['id'] = $this->_id; | |
1043 | } | |
1044 | ||
1045 | $config = CRM_Core_Config::singleton(); | |
1675ba6d PN |
1046 | if (isset($params['total_amount'])) { |
1047 | $params['total_amount'] = CRM_Utils_Rule::cleanMoney($params['total_amount']); | |
1048 | } | |
6a488035 | 1049 | if ($this->_isPaidEvent) { |
f2525f80 | 1050 | list($contributionParams, $lineItem, $additionalParticipantDetails, $params) = $this->preparePaidEventProcessing($params); |
6a488035 TO |
1051 | } |
1052 | ||
1053 | $this->_params = $params; | |
5d3a2b9f | 1054 | parent::beginPostProcess(); |
fbc54416 PJ |
1055 | $amountOwed = NULL; |
1056 | if (isset($params['amount'])) { | |
1057 | $amountOwed = $params['amount']; | |
1058 | unset($params['amount']); | |
1059 | } | |
6a488035 TO |
1060 | $params['contact_id'] = $this->_contactId; |
1061 | ||
1062 | // overwrite actual payment amount if entered | |
a7488080 | 1063 | if (!empty($params['total_amount'])) { |
9c1bc317 | 1064 | $contributionParams['total_amount'] = $params['total_amount'] ?? NULL; |
6a488035 TO |
1065 | } |
1066 | ||
6a488035 | 1067 | // Retrieve the name and email of the current user - this will be the FROM for the receipt email |
46929486 | 1068 | $userName = CRM_Core_Session::singleton()->getLoggedInContactDisplayName(); |
6a488035 TO |
1069 | |
1070 | if ($this->_contactId) { | |
1071 | list($this->_contributorDisplayName, $this->_contributorEmail, $this->_toDoNotEmail) = CRM_Contact_BAO_Contact::getContactDetails($this->_contactId); | |
1072 | } | |
1073 | ||
7df021e5 | 1074 | //modify params according to parameter used in create |
1075 | //participant method (addParticipant) | |
1076 | $this->_params['participant_status_id'] = $params['status_id']; | |
1077 | $this->_params['participant_role_id'] = is_array($params['role_id']) ? $params['role_id'] : explode(',', $params['role_id']); | |
7df021e5 | 1078 | $roleIdWithSeparator = implode(CRM_Core_DAO::VALUE_SEPARATOR, $this->_params['participant_role_id']); |
1079 | ||
6ba1830e MWMC |
1080 | $now = date('YmdHis'); |
1081 | ||
6a488035 | 1082 | if ($this->_mode) { |
6a488035 TO |
1083 | // set source if not set |
1084 | if (empty($params['source'])) { | |
be2fb01f | 1085 | $this->_params['participant_source'] = ts('Offline Registration for Event: %2 by: %1', [ |
90b461f1 | 1086 | 1 => $userName, |
ef45ad8c | 1087 | 2 => $this->getEventValue('title'), |
90b461f1 | 1088 | ]); |
6a488035 TO |
1089 | } |
1090 | else { | |
03e04002 | 1091 | $this->_params['participant_source'] = $params['source']; |
6a488035 TO |
1092 | } |
1093 | $this->_params['description'] = $this->_params['participant_source']; | |
1094 | ||
1095 | $this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($this->_params['payment_processor_id'], | |
1096 | $this->_mode | |
1097 | ); | |
be2fb01f | 1098 | $fields = []; |
6a488035 TO |
1099 | |
1100 | // set email for primary location. | |
1101 | $fields['email-Primary'] = 1; | |
1102 | $params['email-Primary'] = $params["email-{$this->_bltID}"] = $this->_contributorEmail; | |
1103 | ||
6a488035 TO |
1104 | // now set the values for the billing location. |
1105 | foreach ($this->_fields as $name => $dontCare) { | |
1106 | $fields[$name] = 1; | |
1107 | } | |
1108 | ||
1109 | // also add location name to the array | |
a130e045 DG |
1110 | $params["address_name-{$this->_bltID}"] |
1111 | = CRM_Utils_Array::value('billing_first_name', $params) . ' ' . | |
6a488035 TO |
1112 | CRM_Utils_Array::value('billing_middle_name', $params) . ' ' . |
1113 | CRM_Utils_Array::value('billing_last_name', $params); | |
1114 | ||
1115 | $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]); | |
1116 | $fields["address_name-{$this->_bltID}"] = 1; | |
1117 | $fields["email-{$this->_bltID}"] = 1; | |
1118 | $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'contact_type'); | |
1119 | ||
be2fb01f | 1120 | $nameFields = ['first_name', 'middle_name', 'last_name']; |
6a488035 TO |
1121 | |
1122 | foreach ($nameFields as $name) { | |
1123 | $fields[$name] = 1; | |
1124 | if (array_key_exists("billing_$name", $params)) { | |
1125 | $params[$name] = $params["billing_{$name}"]; | |
1126 | $params['preserveDBName'] = TRUE; | |
1127 | } | |
1128 | } | |
1129 | $contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $this->_contactId, NULL, NULL, $ctype); | |
1130 | } | |
1131 | ||
e03317f1 | 1132 | if (!empty($this->_params['participant_role_id'])) { |
be2fb01f | 1133 | $customFieldsRole = []; |
7df021e5 | 1134 | foreach ($this->_params['participant_role_id'] as $roleKey) { |
1135 | $customFieldsRole = CRM_Utils_Array::crmArrayMerge(CRM_Core_BAO_CustomField::getFields('Participant', | |
1136 | FALSE, FALSE, $roleKey, $this->_roleCustomDataTypeID), $customFieldsRole); | |
6a488035 | 1137 | } |
7df021e5 | 1138 | $customFieldsEvent = CRM_Core_BAO_CustomField::getFields('Participant', |
1139 | FALSE, | |
1140 | FALSE, | |
1141 | CRM_Utils_Array::value('event_id', $params), | |
1142 | $this->_eventNameCustomDataTypeID | |
1143 | ); | |
1144 | $customFieldsEventType = CRM_Core_BAO_CustomField::getFields('Participant', | |
1145 | FALSE, | |
1146 | FALSE, | |
1147 | $this->_eventTypeId, | |
1148 | $this->_eventTypeCustomDataTypeID | |
1149 | ); | |
1150 | $customFields = CRM_Utils_Array::crmArrayMerge($customFieldsRole, | |
1151 | CRM_Core_BAO_CustomField::getFields('Participant', FALSE, FALSE, NULL, NULL, TRUE) | |
1152 | ); | |
1153 | $customFields = CRM_Utils_Array::crmArrayMerge($customFieldsEvent, $customFields); | |
1154 | $customFields = CRM_Utils_Array::crmArrayMerge($customFieldsEventType, $customFields); | |
6452294d MW |
1155 | |
1156 | $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $this->_id, $this->getDefaultEntity()); | |
6a488035 TO |
1157 | } |
1158 | ||
1159 | //do cleanup line items if participant edit the Event Fee. | |
0479b4c8 | 1160 | if (($this->_lineItem || !isset($params['proceSetId'])) && !$this->_paymentId && $this->_id) { |
6a488035 TO |
1161 | CRM_Price_BAO_LineItem::deleteLineItems($this->_id, 'civicrm_participant'); |
1162 | } | |
03e04002 | 1163 | |
6a488035 | 1164 | if ($this->_mode) { |
dc8cdf3a | 1165 | // add all the additional payment params we need |
b1b7f4e3 | 1166 | $this->_params = $this->prepareParamsForPaymentProcessor($this->_params); |
6a488035 TO |
1167 | $this->_params['amount'] = $params['fee_amount']; |
1168 | $this->_params['amount_level'] = $params['amount_level']; | |
1169 | $this->_params['currencyID'] = $config->defaultCurrency; | |
6a488035 TO |
1170 | $this->_params['invoiceID'] = md5(uniqid(rand(), TRUE)); |
1171 | ||
1172 | // at this point we've created a contact and stored its address etc | |
1173 | // all the payment processors expect the name and address to be in the | |
1174 | // so we copy stuff over to first_name etc. | |
1175 | $paymentParams = $this->_params; | |
a7488080 | 1176 | if (!empty($this->_params['send_receipt'])) { |
6a488035 TO |
1177 | $paymentParams['email'] = $this->_contributorEmail; |
1178 | } | |
e7309307 EM |
1179 | |
1180 | // The only reason for merging in the 'contact_id' rather than ensuring it is set | |
1181 | // is that this patch is being done around the time of the stable release | |
1182 | // so more conservative approach is called for. | |
1183 | // In fact the use of $params and $this->_params & $this->_contactId vs $contactID | |
1184 | // needs rationalising. | |
be2fb01f | 1185 | $mapParams = array_merge(['contact_id' => $contactID], $this->_params); |
e7309307 | 1186 | CRM_Core_Payment_Form::mapParams($this->_bltID, $mapParams, $paymentParams, TRUE); |
6a488035 | 1187 | |
077017db | 1188 | $payment = $this->_paymentProcessor['object']; |
6a488035 | 1189 | |
9b7e7d4c PH |
1190 | // CRM-15622: fix for incorrect contribution.fee_amount |
1191 | $paymentParams['fee_amount'] = NULL; | |
46366f16 SL |
1192 | try { |
1193 | $result = $payment->doPayment($paymentParams); | |
1194 | } | |
1195 | catch (\Civi\Payment\Exception\PaymentProcessorException $e) { | |
1196 | // @todo un comment the following line out when we are creating a contribution before we get to this point | |
1197 | // see dev/financial#53 about ensuring we create a pending contribution before we try processing payment | |
1198 | // CRM_Contribute_BAO_Contribution::failPayment($contributionID); | |
1199 | CRM_Core_Session::singleton()->setStatus($e->getMessage()); | |
6a488035 | 1200 | CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view/participant', |
353ffa53 TO |
1201 | "reset=1&action=add&cid={$this->_contactId}&context=participant&mode={$this->_mode}" |
1202 | )); | |
6a488035 TO |
1203 | } |
1204 | ||
1205 | if ($result) { | |
1206 | $this->_params = array_merge($this->_params, $result); | |
1207 | } | |
1208 | ||
1209 | $this->_params['receive_date'] = $now; | |
1210 | ||
a7488080 | 1211 | if (!empty($this->_params['send_receipt'])) { |
6a488035 TO |
1212 | $this->_params['receipt_date'] = $now; |
1213 | } | |
1214 | else { | |
1215 | $this->_params['receipt_date'] = NULL; | |
1216 | } | |
1217 | ||
1218 | $this->set('params', $this->_params); | |
1219 | $this->assign('trxn_id', $result['trxn_id']); | |
6ba1830e | 1220 | $this->assign('receive_date', $this->_params['receive_date']); |
6a488035 TO |
1221 | |
1222 | //add contribution record | |
a130e045 DG |
1223 | $this->_params['financial_type_id'] |
1224 | = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'financial_type_id'); | |
6a488035 TO |
1225 | $this->_params['mode'] = $this->_mode; |
1226 | ||
431c430b | 1227 | //add contribution record |
44237a29 | 1228 | $contributions[] = $contribution = $this->processContribution( |
faf44167 | 1229 | $this, $this->_params, |
1230 | $result, $contactID, | |
7a0f6c65 | 1231 | FALSE, |
faf44167 | 1232 | $this->_paymentProcessor |
1233 | ); | |
6a488035 TO |
1234 | |
1235 | // add participant record | |
be2fb01f | 1236 | $participants = []; |
dc8cdf3a K |
1237 | if (!empty($this->_params['role_id']) && is_array($this->_params['role_id'])) { |
1238 | $this->_params['role_id'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, | |
1239 | $this->_params['role_id'] | |
6a488035 TO |
1240 | ); |
1241 | } | |
0e81467c | 1242 | |
5c320924 | 1243 | //CRM-15372 patch to fix fee amount replacing amount |
0479b4c8 | 1244 | $this->_params['fee_amount'] = $this->_params['amount']; |
5c320924 | 1245 | |
35f86af2 | 1246 | $participants[] = $this->addParticipant($this, $this->_params, $contactID); |
6a488035 TO |
1247 | |
1248 | //add custom data for participant | |
1249 | CRM_Core_BAO_CustomValueTable::postProcess($this->_params, | |
6a488035 TO |
1250 | 'civicrm_participant', |
1251 | $participants[0]->id, | |
1252 | 'Participant' | |
1253 | ); | |
f55a8ac8 MWMC |
1254 | |
1255 | // Add participant payment | |
1256 | $participantPaymentParams = [ | |
6a488035 TO |
1257 | 'participant_id' => $participants[0]->id, |
1258 | 'contribution_id' => $contribution->id, | |
be2fb01f | 1259 | ]; |
f55a8ac8 | 1260 | civicrm_api3('ParticipantPayment', 'create', $participantPaymentParams); |
6a488035 | 1261 | |
6a488035 TO |
1262 | $this->_contactIds[] = $this->_contactId; |
1263 | } | |
1264 | else { | |
6a488035 TO |
1265 | if ($this->_single) { |
1266 | $this->_contactIds[] = $this->_contactId; | |
1267 | } | |
d6921a22 | 1268 | $participants = []; |
1269 | foreach ($this->_contactIds as $contactID) { | |
1270 | $commonParams = $params; | |
1271 | $commonParams['contact_id'] = $contactID; | |
1272 | $participants[] = CRM_Event_BAO_Participant::create($commonParams); | |
1273 | } | |
6a488035 | 1274 | |
be2fb01f | 1275 | $contributions = []; |
a7488080 CW |
1276 | if (!empty($params['record_contribution'])) { |
1277 | if (!empty($params['id'])) { | |
6a488035 | 1278 | if ($this->_onlinePendingContributionId) { |
70d43afb | 1279 | $contributionParams['id'] = $this->_onlinePendingContributionId; |
6a488035 TO |
1280 | } |
1281 | else { | |
70d43afb | 1282 | $contributionParams['id'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', |
6a488035 TO |
1283 | $params['id'], |
1284 | 'contribution_id', | |
1285 | 'participant_id' | |
1286 | ); | |
1287 | } | |
1288 | } | |
1289 | unset($params['note']); | |
1290 | ||
1291 | //build contribution params | |
1292 | if (!$this->_onlinePendingContributionId) { | |
0e81467c | 1293 | if (empty($params['source'])) { |
be2fb01f | 1294 | $contributionParams['source'] = ts('%1 : Offline registration (by %2)', [ |
ef45ad8c | 1295 | 1 => $this->getEventValue('title'), |
90b461f1 SL |
1296 | 2 => $userName, |
1297 | ]); | |
0e81467c EM |
1298 | } |
1299 | else { | |
1300 | $contributionParams['source'] = $params['source']; | |
1301 | } | |
1302 | } | |
6a488035 TO |
1303 | |
1304 | $contributionParams['currency'] = $config->defaultCurrency; | |
1305 | $contributionParams['non_deductible_amount'] = 'null'; | |
0d8afee2 | 1306 | $contributionParams['receipt_date'] = !empty($params['send_receipt']) ? CRM_Utils_Array::value('receive_date', $params) : 'null'; |
0dc4ef42 | 1307 | $contributionParams['contact_id'] = $this->_contactID; |
6ba1830e | 1308 | $contributionParams['receive_date'] = CRM_Utils_Array::value('receive_date', $params, 'null'); |
6a488035 | 1309 | |
be2fb01f | 1310 | $recordContribution = [ |
353ffa53 TO |
1311 | 'financial_type_id', |
1312 | 'payment_instrument_id', | |
1313 | 'trxn_id', | |
1314 | 'contribution_status_id', | |
353ffa53 TO |
1315 | 'check_number', |
1316 | 'campaign_id', | |
0dc4ef42 | 1317 | 'pan_truncation', |
5d3a2b9f | 1318 | 'card_type_id', |
be2fb01f | 1319 | ]; |
6a488035 TO |
1320 | |
1321 | foreach ($recordContribution as $f) { | |
9c1bc317 | 1322 | $contributionParams[$f] = $this->_params[$f] ?? NULL; |
6a488035 TO |
1323 | if ($f == 'trxn_id') { |
1324 | $this->assign('trxn_id', $contributionParams[$f]); | |
1325 | } | |
1326 | } | |
1327 | ||
1328 | //insert financial type name in receipt. | |
b956b310 | 1329 | $this->assign('financialTypeName', CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', |
1330 | $contributionParams['financial_type_id'])); | |
1331 | // legacy support | |
6a488035 TO |
1332 | $this->assign('contributionTypeName', CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $contributionParams['financial_type_id'])); |
1333 | $contributionParams['skipLineItem'] = 1; | |
7030a002 PN |
1334 | if ($this->_id) { |
1335 | $contributionParams['contribution_mode'] = 'participant'; | |
1336 | $contributionParams['participant_id'] = $this->_id; | |
1337 | } | |
6a488035 | 1338 | // Set is_pay_later flag for back-office offline Pending status contributions |
2f48e713 | 1339 | if ($contributionParams['contribution_status_id'] == CRM_Core_PseudoConstant::getKey('CRM_Contribute_DAO_Contribution', 'contribution_status_id', 'Pending')) { |
6a488035 TO |
1340 | $contributionParams['is_pay_later'] = 1; |
1341 | } | |
2f48e713 | 1342 | elseif ($contributionParams['contribution_status_id'] == CRM_Core_PseudoConstant::getKey('CRM_Contribute_DAO_Contribution', 'contribution_status_id', 'Completed')) { |
d75f2f47 EM |
1343 | $contributionParams['is_pay_later'] = 0; |
1344 | } | |
f8325309 | 1345 | |
aac57c29 | 1346 | if ($params['status_id'] == array_search('Partially paid', $participantStatus)) { |
5e494d5c PJ |
1347 | if (!$amountOwed && $this->_action & CRM_Core_Action::UPDATE) { |
1348 | $amountOwed = $params['fee_amount']; | |
1349 | } | |
1350 | ||
356579e9 | 1351 | // if multiple participants are link, consider contribution total amount as the amount Owed |
ea707c1b | 1352 | if ($this->_id && CRM_Event_BAO_Participant::isPrimaryParticipant($this->_id)) { |
356579e9 | 1353 | $amountOwed = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', |
70d43afb | 1354 | $contributionParams['id'], |
356579e9 PJ |
1355 | 'total_amount' |
1356 | ); | |
1357 | } | |
1358 | ||
aac57c29 PJ |
1359 | // CRM-13964 partial_payment_total |
1360 | if ($amountOwed > $params['total_amount']) { | |
1361 | // the owed amount | |
d3e6e9a4 | 1362 | $contributionParams['total_amount'] = $amountOwed; |
1363 | $contributionParams['contribution_status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending'); | |
1364 | $this->assign('balanceAmount', $amountOwed - $params['total_amount']); | |
1365 | $this->storePaymentCreateParams($params); | |
aac57c29 | 1366 | } |
f8325309 | 1367 | } |
372ad74d | 1368 | |
f3acfdd9 | 1369 | if (!empty($this->_params['tax_amount'])) { |
d91b8b33 | 1370 | $contributionParams['tax_amount'] = $this->_params['tax_amount']; |
1371 | } | |
1372 | ||
6a488035 | 1373 | if ($this->_single) { |
70d43afb | 1374 | $contributions[] = CRM_Contribute_BAO_Contribution::create($contributionParams); |
6a488035 TO |
1375 | } |
1376 | else { | |
6a488035 TO |
1377 | foreach ($this->_contactIds as $contactID) { |
1378 | $contributionParams['contact_id'] = $contactID; | |
70d43afb | 1379 | $contributions[] = CRM_Contribute_BAO_Contribution::create($contributionParams); |
6a488035 TO |
1380 | } |
1381 | } | |
1382 | ||
f55a8ac8 | 1383 | // Insert payment record for this participant |
70d43afb | 1384 | if (empty($contributionParams['id'])) { |
6a488035 | 1385 | foreach ($this->_contactIds as $num => $contactID) { |
f55a8ac8 MWMC |
1386 | $participantPaymentParams = [ |
1387 | 'participant_id' => $participants[$num]->id, | |
1388 | 'contribution_id' => $contributions[$num]->id, | |
1389 | ]; | |
1390 | civicrm_api3('ParticipantPayment', 'create', $participantPaymentParams); | |
6a488035 TO |
1391 | } |
1392 | } | |
6a488035 TO |
1393 | |
1394 | // CRM-11124 | |
362bd1b7 | 1395 | if ($this->_params['discount_id']) { |
1396 | CRM_Event_BAO_Participant::createDiscountTrxn( | |
1397 | $this->_eventId, | |
1398 | $contributionParams, | |
1399 | NULL, | |
1400 | CRM_Price_BAO_PriceSet::parseFirstPriceSetValueIDFromParams($this->_params) | |
1401 | ); | |
6a488035 | 1402 | } |
6a488035 TO |
1403 | } |
1404 | } | |
1405 | ||
1406 | // also store lineitem stuff here | |
1407 | if ((($this->_lineItem & $this->_action & CRM_Core_Action::ADD) || | |
1408 | ($this->_lineItem && CRM_Core_Action::UPDATE && !$this->_paymentId)) | |
1409 | ) { | |
1410 | foreach ($this->_contactIds as $num => $contactID) { | |
1411 | foreach ($this->_lineItem as $key => $value) { | |
1412 | if (is_array($value) && $value != 'skip') { | |
1413 | foreach ($value as $lineKey => $line) { | |
aac57c29 | 1414 | //10117 update the line items for participants if contribution amount is recorded |
f6bae84f | 1415 | if ($this->_quickConfig && !empty($params['total_amount']) && |
372ad74d | 1416 | ($params['status_id'] != array_search('Partially paid', $participantStatus)) |
aac57c29 PJ |
1417 | ) { |
1418 | $line['unit_price'] = $line['line_total'] = $params['total_amount']; | |
d91b8b33 | 1419 | if (!empty($params['tax_amount'])) { |
1420 | $line['unit_price'] = $line['unit_price'] - $params['tax_amount']; | |
ff9b6b50 | 1421 | $line['line_total'] = $line['line_total'] - $params['tax_amount']; |
d91b8b33 | 1422 | } |
aac57c29 | 1423 | } |
6a488035 TO |
1424 | $lineItem[$this->_priceSetId][$lineKey] = $line; |
1425 | } | |
1426 | CRM_Price_BAO_LineItem::processPriceSet($participants[$num]->id, $lineItem, CRM_Utils_Array::value($num, $contributions, NULL), 'civicrm_participant'); | |
1427 | } | |
1428 | } | |
1429 | } | |
0623f992 | 1430 | foreach ($contributions as $contribution) { |
d3e6e9a4 | 1431 | if (!empty($this->getCreatePaymentParams())) { |
1432 | civicrm_api3('Payment', 'create', array_merge(['contribution_id' => $contribution->id], $this->getCreatePaymentParams())); | |
0623f992 | 1433 | } |
1434 | } | |
6a488035 TO |
1435 | } |
1436 | ||
1437 | $updateStatusMsg = NULL; | |
1438 | //send mail when participant status changed, CRM-4326 | |
1439 | if ($this->_id && $this->_statusId && | |
353ffa53 TO |
1440 | $this->_statusId != CRM_Utils_Array::value('status_id', $params) && !empty($params['is_notify']) |
1441 | ) { | |
6a488035 TO |
1442 | |
1443 | $updateStatusMsg = CRM_Event_BAO_Participant::updateStatusMessage($this->_id, | |
1444 | $params['status_id'], | |
1445 | $this->_statusId | |
1446 | ); | |
1447 | } | |
1448 | ||
be2fb01f CW |
1449 | $sent = []; |
1450 | $notSent = []; | |
a7488080 | 1451 | if (!empty($params['send_receipt'])) { |
6a488035 TO |
1452 | |
1453 | $this->assign('module', 'Event Registration'); | |
e0dbddb4 | 1454 | $this->assignEventDetailsToTpl($params['event_id'], CRM_Utils_Array::value('role_id', $params), CRM_Utils_Array::value('receipt_text', $params), $this->_isPaidEvent); |
6a488035 | 1455 | $this->assign('isAmountzero', 1); |
6a488035 | 1456 | |
6a488035 TO |
1457 | if ($this->_isPaidEvent) { |
1458 | $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument(); | |
1459 | if (!$this->_mode) { | |
1460 | if (isset($params['payment_instrument_id'])) { | |
1461 | $this->assign('paidBy', | |
1462 | CRM_Utils_Array::value($params['payment_instrument_id'], | |
1463 | $paymentInstrument | |
1464 | ) | |
1465 | ); | |
1466 | } | |
1467 | } | |
1468 | ||
d3e6e9a4 | 1469 | $this->assign('totalAmount', $params['total_amount'] ?? $contributionParams['total_amount']); |
6a488035 TO |
1470 | $this->assign('isPrimary', 1); |
1471 | $this->assign('checkNumber', CRM_Utils_Array::value('check_number', $params)); | |
1472 | } | |
1473 | if ($this->_mode) { | |
0b50eca0 | 1474 | $this->assignBillingName($params); |
1475 | $this->assign('address', CRM_Utils_Address::getFormattedBillingAddressFieldsFromParameters( | |
1476 | $this->_params, | |
1477 | $this->_bltID | |
1478 | )); | |
6a488035 | 1479 | |
2e09448c MW |
1480 | $valuesForForm = CRM_Contribute_Form_AbstractEditPayment::formatCreditCardDetails($params); |
1481 | $this->assignVariables($valuesForForm, ['credit_card_exp_date', 'credit_card_type', 'credit_card_number']); | |
1482 | ||
0f2b049e | 1483 | // The concept of contributeMode is deprecated. |
6a488035 TO |
1484 | $this->assign('contributeMode', 'direct'); |
1485 | $this->assign('isAmountzero', 0); | |
1486 | $this->assign('is_pay_later', 0); | |
1487 | $this->assign('isPrimary', 1); | |
1488 | } | |
1489 | ||
1490 | $this->assign('register_date', $params['register_date']); | |
6ba1830e | 1491 | if (isset($params['receive_date'])) { |
6a488035 TO |
1492 | $this->assign('receive_date', $params['receive_date']); |
1493 | } | |
1494 | ||
be2fb01f | 1495 | $customGroup = []; |
6a488035 TO |
1496 | //format submitted data |
1497 | foreach ($params['custom'] as $fieldID => $values) { | |
1498 | foreach ($values as $fieldValue) { | |
af6de2f1 JP |
1499 | $isPublic = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $fieldValue['custom_group_id'], 'is_public'); |
1500 | if ($isPublic) { | |
1501 | $customFields[$fieldID]['id'] = $fieldID; | |
1502 | $formattedValue = CRM_Core_BAO_CustomField::displayValue($fieldValue['value'], $fieldID, $participants[0]->id); | |
1503 | $customGroup[$customFields[$fieldID]['groupTitle']][$customFields[$fieldID]['label']] = str_replace(' ', '', $formattedValue); | |
1504 | } | |
6a488035 TO |
1505 | } |
1506 | } | |
1507 | ||
1508 | foreach ($this->_contactIds as $num => $contactID) { | |
1509 | // Retrieve the name and email of the contact - this will be the TO for receipt email | |
1510 | list($this->_contributorDisplayName, $this->_contributorEmail, $this->_toDoNotEmail) = CRM_Contact_BAO_Contact::getContactDetails($contactID); | |
1511 | ||
1512 | $this->_contributorDisplayName = ($this->_contributorDisplayName == ' ') ? $this->_contributorEmail : $this->_contributorDisplayName; | |
1513 | ||
1514 | $waitStatus = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Waiting'"); | |
1515 | if ($waitingStatus = CRM_Utils_Array::value($params['status_id'], $waitStatus)) { | |
1516 | $this->assign('isOnWaitlist', TRUE); | |
1517 | } | |
1518 | ||
1519 | $this->assign('customGroup', $customGroup); | |
1520 | $this->assign('contactID', $contactID); | |
1521 | $this->assign('participantID', $participants[$num]->id); | |
1522 | ||
1523 | $this->_id = $participants[$num]->id; | |
1524 | ||
1525 | if ($this->_isPaidEvent) { | |
1526 | // fix amount for each of participants ( for bulk mode ) | |
be2fb01f | 1527 | $eventAmount = []; |
aaffa79f | 1528 | $invoiceSettings = Civi::settings()->get('contribution_invoice_settings'); |
9c1bc317 | 1529 | $invoicing = $invoiceSettings['invoicing'] ?? NULL; |
79d001a2 | 1530 | $totalTaxAmount = 0; |
0e81467c | 1531 | |
03b412ae | 1532 | //add dataArray in the receipts in ADD and UPDATE condition |
be2fb01f | 1533 | $dataArray = []; |
79d001a2 | 1534 | if ($this->_action & CRM_Core_Action::ADD) { |
2e1f50d6 | 1535 | $line = $lineItem[0] ?? []; |
79d001a2 PB |
1536 | } |
1537 | elseif ($this->_action & CRM_Core_Action::UPDATE) { | |
1538 | $line = $this->_values['line_items']; | |
1539 | } | |
03b412ae PB |
1540 | if ($invoicing) { |
1541 | foreach ($line as $key => $value) { | |
1542 | if (isset($value['tax_amount'])) { | |
1543 | $totalTaxAmount += $value['tax_amount']; | |
288ec043 PB |
1544 | if (isset($dataArray[(string) $value['tax_rate']])) { |
1545 | $dataArray[(string) $value['tax_rate']] = $dataArray[(string) $value['tax_rate']] + CRM_Utils_Array::value('tax_amount', $value); | |
03b412ae PB |
1546 | } |
1547 | else { | |
9c1bc317 | 1548 | $dataArray[(string) $value['tax_rate']] = $value['tax_amount'] ?? NULL; |
03b412ae | 1549 | } |
79d001a2 PB |
1550 | } |
1551 | } | |
03b412ae | 1552 | $this->assign('totalTaxAmount', $totalTaxAmount); |
a6e29c95 | 1553 | $this->assign('taxTerm', $this->getSalesTaxTerm()); |
03b412ae | 1554 | $this->assign('dataArray', $dataArray); |
79d001a2 | 1555 | } |
6a488035 TO |
1556 | if (!empty($additionalParticipantDetails)) { |
1557 | $params['amount_level'] = preg_replace('/\ 1/', '', $params['amount_level']) . ' - ' . $this->_contributorDisplayName; | |
1558 | } | |
1559 | ||
be2fb01f | 1560 | $eventAmount[$num] = [ |
6a488035 TO |
1561 | 'label' => preg_replace('/\ 1/', '', $params['amount_level']), |
1562 | 'amount' => $params['fee_amount'], | |
be2fb01f | 1563 | ]; |
6a488035 TO |
1564 | //as we are using same template for online & offline registration. |
1565 | //So we have to build amount as array. | |
1566 | $eventAmount = array_merge($eventAmount, $additionalParticipantDetails); | |
1567 | $this->assign('amount', $eventAmount); | |
1568 | } | |
1569 | ||
be2fb01f | 1570 | $sendTemplateParams = [ |
6a488035 TO |
1571 | 'groupName' => 'msg_tpl_workflow_event', |
1572 | 'valueName' => 'event_offline_receipt', | |
1573 | 'contactId' => $contactID, | |
52f3b44b | 1574 | 'isTest' => !empty($this->_defaultValues['is_test']), |
92fcb95f | 1575 | 'PDFFilename' => ts('confirmation') . '.pdf', |
be2fb01f | 1576 | ]; |
6a488035 TO |
1577 | |
1578 | // try to send emails only if email id is present | |
1579 | // and the do-not-email option is not checked for that contact | |
1580 | if ($this->_contributorEmail and !$this->_toDoNotEmail) { | |
b28a34c3 | 1581 | if (array_key_exists($params['from_email_address'], $this->_fromEmails['from_email_id'])) { |
1582 | $receiptFrom = $params['from_email_address']; | |
1583 | } | |
6a488035 TO |
1584 | $sendTemplateParams['from'] = $receiptFrom; |
1585 | $sendTemplateParams['toName'] = $this->_contributorDisplayName; | |
1586 | $sendTemplateParams['toEmail'] = $this->_contributorEmail; | |
9c1bc317 CW |
1587 | $sendTemplateParams['cc'] = $this->_fromEmails['cc'] ?? NULL; |
1588 | $sendTemplateParams['bcc'] = $this->_fromEmails['bcc'] ?? NULL; | |
6a488035 TO |
1589 | } |
1590 | ||
9161952c | 1591 | //send email with pdf invoice |
481a74f4 | 1592 | $template = CRM_Core_Smarty::singleton(); |
9161952c PD |
1593 | $taxAmt = $template->get_template_vars('dataArray'); |
1594 | $contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', | |
353ffa53 TO |
1595 | $this->_id, 'contribution_id', 'participant_id' |
1596 | ); | |
aaffa79f | 1597 | $prefixValue = Civi::settings()->get('contribution_invoice_settings'); |
9c1bc317 | 1598 | $invoicing = $prefixValue['invoicing'] ?? NULL; |
10a35967 | 1599 | if (!empty($taxAmt) && (isset($invoicing) && isset($prefixValue['is_email_pdf']))) { |
0479b4c8 | 1600 | $sendTemplateParams['isEmailPdf'] = TRUE; |
0e81467c | 1601 | $sendTemplateParams['contributionId'] = $contributionId; |
9161952c | 1602 | } |
c6327d7d | 1603 | list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams); |
6a488035 TO |
1604 | if ($mailSent) { |
1605 | $sent[] = $contactID; | |
1606 | foreach ($participants as $ids => $values) { | |
1607 | if ($values->contact_id == $contactID) { | |
9c1bc317 | 1608 | $values->details = $params['receipt_text'] ?? NULL; |
6a488035 TO |
1609 | CRM_Activity_BAO_Activity::addActivity($values, 'Email'); |
1610 | break; | |
1611 | } | |
1612 | } | |
1613 | } | |
1614 | else { | |
1615 | $notSent[] = $contactID; | |
1616 | } | |
1617 | } | |
1618 | } | |
1619 | ||
1620 | // set the participant id if it is not set | |
1621 | if (!$this->_id) { | |
1622 | $this->_id = $participants[0]->id; | |
1623 | } | |
1624 | ||
5fda4b16 | 1625 | return $this->getStatusMsg($params, $sent, $updateStatusMsg, $notSent); |
1626 | } | |
1627 | ||
1628 | /** | |
1629 | * Set the various IDs relating to custom data types. | |
1630 | */ | |
1631 | public function setCustomDataTypes() { | |
1632 | $customDataType = CRM_Core_OptionGroup::values('custom_data_type', FALSE, FALSE, FALSE, NULL, 'name'); | |
1633 | $this->_roleCustomDataTypeID = array_search('ParticipantRole', $customDataType); | |
1634 | $this->_eventNameCustomDataTypeID = array_search('ParticipantEventName', $customDataType); | |
1635 | $this->_eventTypeCustomDataTypeID = array_search('ParticipantEventType', $customDataType); | |
1636 | $this->assign('roleCustomDataTypeID', $this->_roleCustomDataTypeID); | |
1637 | $this->assign('eventNameCustomDataTypeID', $this->_eventNameCustomDataTypeID); | |
1638 | $this->assign('eventTypeCustomDataTypeID', $this->_eventTypeCustomDataTypeID); | |
1639 | } | |
1640 | ||
1641 | /** | |
1642 | * Get status message | |
1643 | * | |
1644 | * @param array $params | |
1645 | * @param int $sent | |
1646 | * @param string $updateStatusMsg | |
1647 | * @param int $notSent | |
1648 | * | |
1649 | * @return string | |
1650 | */ | |
1651 | protected function getStatusMsg($params, $sent, $updateStatusMsg, $notSent) { | |
1652 | $statusMsg = ''; | |
6a488035 | 1653 | if (($this->_action & CRM_Core_Action::UPDATE)) { |
be2fb01f | 1654 | $statusMsg = ts('Event registration information for %1 has been updated.', [1 => $this->_contributorDisplayName]); |
a7488080 | 1655 | if (!empty($params['send_receipt']) && count($sent)) { |
be2fb01f | 1656 | $statusMsg .= ' ' . ts('A confirmation email has been sent to %1', [1 => $this->_contributorEmail]); |
6a488035 TO |
1657 | } |
1658 | ||
1659 | if ($updateStatusMsg) { | |
1660 | $statusMsg = "{$statusMsg} {$updateStatusMsg}"; | |
1661 | } | |
1662 | } | |
1663 | elseif ($this->_action & CRM_Core_Action::ADD) { | |
1664 | if ($this->_single) { | |
be2fb01f | 1665 | $statusMsg = ts('Event registration for %1 has been added.', [1 => $this->_contributorDisplayName]); |
a7488080 | 1666 | if (!empty($params['send_receipt']) && count($sent)) { |
be2fb01f | 1667 | $statusMsg .= ' ' . ts('A confirmation email has been sent to %1.', [1 => $this->_contributorEmail]); |
6a488035 TO |
1668 | } |
1669 | } | |
1670 | else { | |
be2fb01f | 1671 | $statusMsg = ts('Total Participant(s) added to event: %1.', [1 => count($this->_contactIds)]); |
6a488035 | 1672 | if (count($notSent) > 0) { |
be2fb01f | 1673 | $statusMsg .= ' ' . ts('Email has NOT been sent to %1 contact(s) - communication preferences specify DO NOT EMAIL OR valid Email is NOT present. ', [1 => count($notSent)]); |
6a488035 TO |
1674 | } |
1675 | elseif (isset($params['send_receipt'])) { | |
1676 | $statusMsg .= ' ' . ts('A confirmation email has been sent to ALL participants'); | |
1677 | } | |
1678 | } | |
1679 | } | |
5fda4b16 | 1680 | return $statusMsg; |
6a488035 | 1681 | } |
96025800 | 1682 | |
775a355c | 1683 | /** |
1684 | * Build the form object. | |
1685 | * | |
eeca0339 | 1686 | * @param \CRM_Event_Form_Participant $form |
775a355c | 1687 | * |
1688 | * @return bool | |
1689 | * @throws \CRM_Core_Exception | |
1690 | * @throws \Exception | |
1691 | */ | |
eeca0339 | 1692 | public function buildEventFeeForm($form) { |
775a355c | 1693 | if ($form->_eventId) { |
1694 | $form->_isPaidEvent = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $form->_eventId, 'is_monetary'); | |
1695 | if ($form->_isPaidEvent) { | |
1696 | $form->addElement('hidden', 'hidden_feeblock', 1); | |
1697 | } | |
1698 | ||
2ee9bfad | 1699 | $eventfullMsg = CRM_Event_BAO_Participant::eventFullMessage($form->_eventId, $this->getParticipantID()); |
eeca0339 | 1700 | $form->addElement('hidden', 'hidden_eventFullMsg', $eventfullMsg, ['id' => 'hidden_eventFullMsg']); |
775a355c | 1701 | } |
1702 | ||
775a355c | 1703 | if ($form->_isPaidEvent) { |
1704 | $params = ['id' => $form->_eventId]; | |
1705 | CRM_Event_BAO_Event::retrieve($params, $event); | |
1706 | ||
1707 | //retrieve custom information | |
1708 | $form->_values = []; | |
1709 | CRM_Event_Form_Registration::initEventFee($form, $event['id']); | |
1710 | CRM_Event_Form_Registration_Register::buildAmount($form, TRUE, $form->_discountId); | |
1711 | $lineItem = []; | |
1712 | $invoiceSettings = Civi::settings()->get('contribution_invoice_settings'); | |
9c1bc317 | 1713 | $invoicing = $invoiceSettings['invoicing'] ?? NULL; |
775a355c | 1714 | $totalTaxAmount = 0; |
1715 | if (!CRM_Utils_System::isNull(CRM_Utils_Array::value('line_items', $form->_values))) { | |
1716 | $lineItem[] = $form->_values['line_items']; | |
1717 | foreach ($form->_values['line_items'] as $key => $value) { | |
1718 | $totalTaxAmount = $value['tax_amount'] + $totalTaxAmount; | |
1719 | } | |
1720 | } | |
1721 | if ($invoicing) { | |
1722 | $form->assign('totalTaxAmount', $totalTaxAmount); | |
1723 | } | |
1724 | $form->assign('lineItem', empty($lineItem) ? FALSE : $lineItem); | |
1725 | $discounts = []; | |
1726 | if (!empty($form->_values['discount'])) { | |
1727 | foreach ($form->_values['discount'] as $key => $value) { | |
1728 | $value = current($value); | |
1729 | $discounts[$key] = $value['name']; | |
1730 | } | |
1731 | ||
1732 | $element = $form->add('select', 'discount_id', | |
1733 | ts('Discount Set'), | |
1734 | [ | |
1735 | 0 => ts('- select -'), | |
1736 | ] + $discounts, | |
1737 | FALSE, | |
1738 | ['class' => "crm-select2"] | |
1739 | ); | |
775a355c | 1740 | } |
1741 | if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() | |
b99f3e96 | 1742 | && empty($form->_values['fee']) |
775a355c | 1743 | && CRM_Utils_Array::value('snippet', $_REQUEST) == CRM_Core_Smarty::PRINT_NOFORM |
1744 | ) { | |
1745 | CRM_Core_Session::setStatus(ts('You do not have all the permissions needed for this page.'), 'Permission Denied', 'error'); | |
1746 | return FALSE; | |
1747 | } | |
1748 | ||
1749 | CRM_Core_Payment_Form::buildPaymentForm($form, $form->_paymentProcessor, FALSE, TRUE, self::getDefaultPaymentInstrumentId()); | |
1750 | if (!$form->_mode) { | |
1751 | $form->addElement('checkbox', 'record_contribution', ts('Record Payment?'), NULL, | |
1752 | ['onclick' => "return showHideByValue('record_contribution','','payment_information','table-row','radio',false);"] | |
1753 | ); | |
1754 | // Check permissions for financial type first | |
1755 | if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) { | |
1756 | CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, $form->_action); | |
1757 | } | |
1758 | else { | |
1759 | $financialTypes = CRM_Contribute_PseudoConstant::financialType(); | |
1760 | } | |
1761 | ||
1762 | $form->add('select', 'financial_type_id', | |
1763 | ts('Financial Type'), | |
1764 | ['' => ts('- select -')] + $financialTypes | |
1765 | ); | |
1766 | ||
1767 | $form->add('datepicker', 'receive_date', ts('Received'), [], FALSE, ['time' => TRUE]); | |
1768 | ||
1769 | $form->add('select', 'payment_instrument_id', | |
1770 | ts('Payment Method'), | |
1771 | ['' => ts('- select -')] + CRM_Contribute_PseudoConstant::paymentInstrument(), | |
1772 | FALSE, ['onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);"] | |
1773 | ); | |
1774 | // don't show transaction id in batch update mode | |
1775 | $path = CRM_Utils_System::currentPath(); | |
1776 | $form->assign('showTransactionId', FALSE); | |
1777 | if ($path != 'civicrm/contact/search/basic') { | |
1778 | $form->add('text', 'trxn_id', ts('Transaction ID')); | |
1779 | $form->addRule('trxn_id', ts('Transaction ID already exists in Database.'), | |
1780 | 'objectExists', ['CRM_Contribute_DAO_Contribution', $form->_eventId, 'trxn_id'] | |
1781 | ); | |
1782 | $form->assign('showTransactionId', TRUE); | |
1783 | } | |
1784 | ||
1785 | $form->add('select', 'contribution_status_id', | |
1786 | ts('Payment Status'), CRM_Contribute_BAO_Contribution_Utils::getContributionStatuses('participant') | |
1787 | ); | |
1788 | ||
1789 | $form->add('text', 'check_number', ts('Check Number'), | |
1790 | CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'check_number') | |
1791 | ); | |
1792 | ||
1793 | $form->add('text', 'total_amount', ts('Amount'), | |
1794 | CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'total_amount') | |
1795 | ); | |
1796 | } | |
1797 | } | |
1798 | else { | |
1799 | $form->add('text', 'amount', ts('Event Fee(s)')); | |
1800 | } | |
1801 | $form->assign('onlinePendingContributionId', $form->get('onlinePendingContributionId')); | |
1802 | ||
1803 | $form->assign('paid', $form->_isPaidEvent); | |
1804 | ||
1805 | $form->addElement('checkbox', | |
1806 | 'send_receipt', | |
1807 | ts('Send Confirmation?'), NULL, | |
1808 | ['onclick' => "showHideByValue('send_receipt','','notice','table-row','radio',false); showHideByValue('send_receipt','','from-email','table-row','radio',false);"] | |
1809 | ); | |
1810 | ||
1811 | $form->add('select', 'from_email_address', ts('Receipt From'), $form->_fromEmails['from_email_id']); | |
1812 | ||
1813 | $form->add('textarea', 'receipt_text', ts('Confirmation Message')); | |
1814 | ||
1815 | // Retrieve the name and email of the contact - form will be the TO for receipt email ( only if context is not standalone) | |
1816 | if ($form->_context != 'standalone') { | |
1817 | if ($form->_contactId) { | |
1818 | list($form->_contributorDisplayName, | |
1819 | $form->_contributorEmail | |
1820 | ) = CRM_Contact_BAO_Contact_Location::getEmailDetails($form->_contactId); | |
1821 | $form->assign('email', $form->_contributorEmail); | |
1822 | } | |
1823 | else { | |
1824 | //show email block for batch update for event | |
1825 | $form->assign('batchEmail', TRUE); | |
1826 | } | |
1827 | } | |
1828 | ||
1829 | $mailingInfo = Civi::settings()->get('mailing_backend'); | |
1830 | $form->assign('outBound_option', $mailingInfo['outBound_option']); | |
1831 | $form->assign('hasPayment', $form->_paymentId); | |
1832 | } | |
1833 | ||
f2525f80 | 1834 | /** |
1835 | * Extracted code relating to paid events. | |
1836 | * | |
1837 | * @param $params | |
1838 | * | |
1839 | * @return array | |
f84f92f2 | 1840 | * |
f84f92f2 | 1841 | * @throws \CiviCRM_API3_Exception |
f2525f80 | 1842 | */ |
1843 | protected function preparePaidEventProcessing($params): array { | |
1844 | $participantStatus = CRM_Event_PseudoConstant::participantStatus(); | |
939287ad | 1845 | $contributionParams = [ |
1846 | 'skipCleanMoney' => TRUE, | |
1847 | 'revenue_recognition_date' => $this->getRevenueRecognitionDate(), | |
1848 | ]; | |
f2525f80 | 1849 | $lineItem = []; |
1850 | $additionalParticipantDetails = []; | |
939287ad | 1851 | |
3293fb2d | 1852 | if ($this->isPaymentOnExistingContribution()) { |
a3aed42a | 1853 | $contributionParams['total_amount'] = $this->getParticipantValue('fee_amount'); |
f2525f80 | 1854 | |
1855 | $params['discount_id'] = NULL; | |
1856 | //re-enter the values for UPDATE mode | |
a3aed42a | 1857 | $params['fee_level'] = $params['amount_level'] = $this->getParticipantValue('fee_level'); |
1858 | $params['fee_amount'] = $this->getParticipantValue('fee_amount'); | |
f2525f80 | 1859 | if (isset($params['priceSetId'])) { |
32b59dd0 | 1860 | CRM_Core_Error::deprecatedFunctionWarning('It seems this line is never hit & can go.'); |
f2525f80 | 1861 | $lineItem[0] = CRM_Price_BAO_LineItem::getLineItems($this->_id); |
1862 | } | |
1863 | //also add additional participant's fee level/priceset | |
1864 | if (CRM_Event_BAO_Participant::isPrimaryParticipant($this->_id)) { | |
1865 | $additionalIds = CRM_Event_BAO_Participant::getAdditionalParticipantIds($this->_id); | |
1866 | $hasLineItems = CRM_Utils_Array::value('priceSetId', $params, FALSE); | |
2f5a251a | 1867 | $additionalParticipantDetails = $this->getFeeDetails($additionalIds, $hasLineItems); |
f2525f80 | 1868 | } |
1869 | } | |
1870 | else { | |
1871 | ||
1872 | // check that discount_id is set | |
1873 | if (empty($params['discount_id'])) { | |
1874 | $params['discount_id'] = 'null'; | |
1875 | } | |
1876 | ||
1877 | //lets carry currency, CRM-4453 | |
1878 | $params['fee_currency'] = CRM_Core_Config::singleton()->defaultCurrency; | |
1879 | if (!isset($lineItem[0])) { | |
1880 | $lineItem[0] = []; | |
1881 | } | |
1882 | CRM_Price_BAO_PriceSet::processAmount($this->_values['fee'], | |
1883 | $params, $lineItem[0] | |
1884 | ); | |
1885 | //CRM-11529 for quick config backoffice transactions | |
1886 | //when financial_type_id is passed in form, update the | |
1887 | //lineitems with the financial type selected in form | |
9c1bc317 CW |
1888 | $submittedFinancialType = $params['financial_type_id'] ?? NULL; |
1889 | $isPaymentRecorded = $params['record_contribution'] ?? NULL; | |
f2525f80 | 1890 | if ($isPaymentRecorded && $this->_quickConfig && $submittedFinancialType) { |
1891 | foreach ($lineItem[0] as &$values) { | |
1892 | $values['financial_type_id'] = $submittedFinancialType; | |
1893 | } | |
1894 | } | |
1895 | ||
1896 | $params['fee_level'] = $params['amount_level']; | |
1897 | $contributionParams['total_amount'] = $params['amount']; | |
1898 | if ($this->_quickConfig && !empty($params['total_amount']) && | |
1899 | $params['status_id'] != array_search('Partially paid', $participantStatus) | |
1900 | ) { | |
1901 | $params['fee_amount'] = $params['total_amount']; | |
1902 | } | |
1903 | else { | |
1904 | //fix for CRM-3086 | |
1905 | $params['fee_amount'] = $params['amount']; | |
1906 | } | |
1907 | } | |
1908 | ||
1909 | if (isset($params['priceSetId'])) { | |
1910 | if (!empty($lineItem[0])) { | |
1911 | $this->set('lineItem', $lineItem); | |
1912 | ||
1913 | $this->_lineItem = $lineItem; | |
1914 | $lineItem = array_merge($lineItem, $additionalParticipantDetails); | |
1915 | ||
1916 | $participantCount = []; | |
1917 | foreach ($lineItem as $k) { | |
1918 | foreach ($k as $v) { | |
1919 | if (CRM_Utils_Array::value('participant_count', $v) > 0) { | |
1920 | $participantCount[] = $v['participant_count']; | |
1921 | } | |
1922 | } | |
1923 | } | |
1924 | } | |
1925 | if (isset($participantCount)) { | |
1926 | $this->assign('pricesetFieldsCount', $participantCount); | |
1927 | } | |
1928 | $this->assign('lineItem', empty($lineItem[0]) || $this->_quickConfig ? FALSE : $lineItem); | |
1929 | } | |
1930 | else { | |
1931 | $this->assign('amount_level', $params['amount_level']); | |
1932 | } | |
1933 | return [$contributionParams, $lineItem, $additionalParticipantDetails, $params]; | |
1934 | } | |
1935 | ||
e0dbddb4 | 1936 | /** |
1937 | * @param $eventID | |
1938 | * @param $participantRoles | |
1939 | * @param $receiptText | |
1940 | * @param $isPaidEvent | |
1941 | * | |
1942 | * @return void | |
1943 | */ | |
1944 | protected function assignEventDetailsToTpl($eventID, $participantRoles, $receiptText, $isPaidEvent) { | |
1945 | //use of the message template below requires variables in different format | |
1946 | $events = []; | |
1947 | $returnProperties = ['event_type_id', 'fee_label', 'start_date', 'end_date', 'is_show_location', 'title']; | |
1948 | ||
1949 | //get all event details. | |
1950 | CRM_Core_DAO::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $eventID, $events, $returnProperties); | |
1951 | $event = $events[$eventID]; | |
1952 | unset($event['start_date']); | |
1953 | unset($event['end_date']); | |
1954 | ||
1955 | $role = CRM_Event_PseudoConstant::participantRole(); | |
1956 | ||
1957 | if (is_array($participantRoles)) { | |
1958 | $selectedRoles = []; | |
1959 | foreach ($participantRoles as $roleId) { | |
1960 | $selectedRoles[] = $role[$roleId]; | |
1961 | } | |
1962 | $event['participant_role'] = implode(', ', $selectedRoles); | |
1963 | } | |
1964 | else { | |
9c1bc317 | 1965 | $event['participant_role'] = $role[$participantRoles] ?? NULL; |
e0dbddb4 | 1966 | } |
1967 | $event['is_monetary'] = $isPaidEvent; | |
1968 | ||
1969 | if ($receiptText) { | |
1970 | $event['confirm_email_text'] = $receiptText; | |
1971 | } | |
1972 | $this->assign('event', $event); | |
1973 | $this->assign('isShowLocation', $event['is_show_location']); | |
1974 | if (CRM_Utils_Array::value('is_show_location', $event) == 1) { | |
1975 | $locationParams = [ | |
1976 | 'entity_id' => $eventID, | |
1977 | 'entity_table' => 'civicrm_event', | |
1978 | ]; | |
1979 | $location = CRM_Core_BAO_Location::getValues($locationParams, TRUE); | |
1980 | $this->assign('location', $location); | |
1981 | } | |
1982 | } | |
1983 | ||
44237a29 | 1984 | /** |
1985 | * Process the contribution. | |
1986 | * | |
1987 | * @param CRM_Core_Form $form | |
1988 | * @param array $params | |
1989 | * @param array $result | |
1990 | * @param int $contactID | |
1991 | * @param bool $pending | |
1992 | * @param array $paymentProcessor | |
1993 | * | |
1994 | * @return \CRM_Contribute_BAO_Contribution | |
1995 | * | |
1996 | * @throws \CRM_Core_Exception | |
1997 | * @throws \CiviCRM_API3_Exception | |
1998 | */ | |
1999 | public function processContribution( | |
2000 | &$form, $params, $result, $contactID, | |
2001 | $pending = FALSE, | |
2002 | $paymentProcessor = NULL | |
2003 | ) { | |
2004 | $transaction = new CRM_Core_Transaction(); | |
2005 | ||
2006 | $now = date('YmdHis'); | |
2007 | $receiptDate = NULL; | |
2008 | ||
2009 | if (!empty($form->_values['event']['is_email_confirm'])) { | |
2010 | $receiptDate = $now; | |
2011 | } | |
2012 | ||
2013 | // CRM-20264: fetch CC type ID and number (last 4 digit) and assign it back to $params | |
2014 | CRM_Contribute_Form_AbstractEditPayment::formatCreditCardDetails($params); | |
2015 | ||
2016 | $contribParams = [ | |
2017 | 'contact_id' => $contactID, | |
2018 | 'financial_type_id' => !empty($form->_values['event']['financial_type_id']) ? $form->_values['event']['financial_type_id'] : $params['financial_type_id'], | |
2019 | 'receive_date' => $now, | |
2020 | 'total_amount' => $params['amount'], | |
2021 | 'tax_amount' => $params['tax_amount'], | |
2022 | 'amount_level' => $params['amount_level'], | |
2023 | 'invoice_id' => $params['invoiceID'], | |
2024 | 'currency' => $params['currencyID'], | |
2025 | 'source' => !empty($params['participant_source']) ? $params['participant_source'] : $params['description'], | |
2026 | 'is_pay_later' => CRM_Utils_Array::value('is_pay_later', $params, 0), | |
6b409353 CW |
2027 | 'campaign_id' => $params['campaign_id'] ?? NULL, |
2028 | 'card_type_id' => $params['card_type_id'] ?? NULL, | |
2029 | 'pan_truncation' => $params['pan_truncation'] ?? NULL, | |
44237a29 | 2030 | ]; |
2031 | ||
2032 | if ($paymentProcessor) { | |
2033 | $contribParams['payment_instrument_id'] = $paymentProcessor['payment_instrument_id']; | |
2034 | $contribParams['payment_processor'] = $paymentProcessor['id']; | |
2035 | } | |
2036 | ||
2037 | if (!$pending && $result) { | |
2038 | $contribParams += [ | |
6b409353 | 2039 | 'fee_amount' => $result['fee_amount'] ?? NULL, |
44237a29 | 2040 | 'trxn_id' => $result['trxn_id'], |
2041 | 'receipt_date' => $receiptDate, | |
2042 | ]; | |
2043 | } | |
2044 | ||
2045 | $allStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); | |
2046 | $contribParams['contribution_status_id'] = array_search('Completed', $allStatuses); | |
2047 | if ($pending) { | |
2048 | $contribParams['contribution_status_id'] = array_search('Pending', $allStatuses); | |
2049 | } | |
2050 | ||
2051 | $contribParams['is_test'] = 0; | |
2052 | if ($form->_action & CRM_Core_Action::PREVIEW || CRM_Utils_Array::value('mode', $params) == 'test') { | |
2053 | $contribParams['is_test'] = 1; | |
2054 | } | |
2055 | ||
2056 | if (!empty($contribParams['invoice_id'])) { | |
2057 | $contribParams['id'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', | |
2058 | $contribParams['invoice_id'], | |
2059 | 'id', | |
2060 | 'invoice_id' | |
2061 | ); | |
2062 | } | |
939287ad | 2063 | $contribParams['revenue_recognition_date'] = $this->getRevenueRecognitionDate(); |
44237a29 | 2064 | |
44237a29 | 2065 | //create an contribution address |
2066 | // The concept of contributeMode is deprecated. Elsewhere we use the function processBillingAddress() - although | |
2067 | // currently that is only inherited by back-office forms. | |
2068 | if ($form->_contributeMode != 'notify' && empty($params['is_pay_later'])) { | |
2069 | $contribParams['address_id'] = CRM_Contribute_BAO_Contribution::createAddress($params, $form->_bltID); | |
2070 | } | |
2071 | ||
2072 | $contribParams['skipLineItem'] = 1; | |
2073 | $contribParams['skipCleanMoney'] = 1; | |
2074 | // create contribution record | |
2075 | $contribution = CRM_Contribute_BAO_Contribution::add($contribParams); | |
2076 | // CRM-11124 | |
2077 | CRM_Event_BAO_Participant::createDiscountTrxn($form->_eventId, $contribParams, NULL, CRM_Price_BAO_PriceSet::parseFirstPriceSetValueIDFromParams($params)); | |
2078 | ||
2079 | // process soft credit / pcp pages | |
2080 | if (!empty($params['pcp_made_through_id'])) { | |
2081 | CRM_Contribute_BAO_ContributionSoft::formatSoftCreditParams($params, $form); | |
2082 | CRM_Contribute_BAO_ContributionSoft::processSoftContribution($params, $contribution); | |
2083 | } | |
2084 | ||
2085 | $transaction->commit(); | |
2086 | ||
2087 | return $contribution; | |
2088 | } | |
2089 | ||
2090 | /** | |
2091 | * Process the participant. | |
2092 | * | |
2093 | * @param CRM_Core_Form $form | |
b2a8013e | 2094 | * @param array $params |
44237a29 | 2095 | * @param int $contactID |
2096 | * | |
2097 | * @return \CRM_Event_BAO_Participant | |
b2a8013e | 2098 | * @throws \CRM_Core_Exception |
fc076fe3 | 2099 | * @throws \CiviCRM_API3_Exception |
44237a29 | 2100 | */ |
35f86af2 | 2101 | protected function addParticipant(&$form, $params, $contactID) { |
44237a29 | 2102 | $transaction = new CRM_Core_Transaction(); |
2103 | ||
44237a29 | 2104 | $participantFields = CRM_Event_DAO_Participant::fields(); |
b2a8013e | 2105 | $participantParams = [ |
6b409353 | 2106 | 'id' => $params['participant_id'] ?? NULL, |
44237a29 | 2107 | 'contact_id' => $contactID, |
2108 | 'event_id' => $form->_eventId ? $form->_eventId : $params['event_id'], | |
2109 | 'status_id' => CRM_Utils_Array::value('participant_status', | |
2110 | $params, 1 | |
2111 | ), | |
fc076fe3 | 2112 | 'role_id' => CRM_Utils_Array::value('participant_role_id', $params) ?: CRM_Event_BAO_Participant::getDefaultRoleID(), |
51c6ef2b | 2113 | 'register_date' => $params['register_date'], |
44237a29 | 2114 | 'source' => CRM_Utils_String::ellipsify( |
2115 | isset($params['participant_source']) ? CRM_Utils_Array::value('participant_source', $params) : CRM_Utils_Array::value('description', $params), | |
2116 | $participantFields['participant_source']['maxlength'] | |
2117 | ), | |
6b409353 | 2118 | 'fee_level' => $params['amount_level'] ?? NULL, |
44237a29 | 2119 | 'is_pay_later' => CRM_Utils_Array::value('is_pay_later', $params, 0), |
6b409353 CW |
2120 | 'fee_amount' => $params['fee_amount'] ?? NULL, |
2121 | 'registered_by_id' => $params['registered_by_id'] ?? NULL, | |
2122 | 'discount_id' => $params['discount_id'] ?? NULL, | |
2123 | 'fee_currency' => $params['currencyID'] ?? NULL, | |
2124 | 'campaign_id' => $params['campaign_id'] ?? NULL, | |
b2a8013e | 2125 | ]; |
44237a29 | 2126 | |
2127 | if ($form->_action & CRM_Core_Action::PREVIEW || CRM_Utils_Array::value('mode', $params) == 'test') { | |
2128 | $participantParams['is_test'] = 1; | |
2129 | } | |
2130 | else { | |
2131 | $participantParams['is_test'] = 0; | |
2132 | } | |
2133 | ||
2134 | if (!empty($form->_params['note'])) { | |
2135 | $participantParams['note'] = $form->_params['note']; | |
2136 | } | |
2137 | elseif (!empty($form->_params['participant_note'])) { | |
2138 | $participantParams['note'] = $form->_params['participant_note']; | |
2139 | } | |
2140 | ||
2141 | // reuse id if one already exists for this one (can happen | |
2142 | // with back button being hit etc) | |
2143 | if (!$participantParams['id'] && !empty($params['contributionID'])) { | |
2144 | $pID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', | |
2145 | $params['contributionID'], | |
2146 | 'participant_id', | |
2147 | 'contribution_id' | |
2148 | ); | |
2149 | $participantParams['id'] = $pID; | |
2150 | } | |
2151 | $participantParams['discount_id'] = CRM_Core_BAO_Discount::findSet($form->_eventId, 'civicrm_event'); | |
2152 | ||
2153 | if (!$participantParams['discount_id']) { | |
2154 | $participantParams['discount_id'] = "null"; | |
2155 | } | |
2156 | ||
2157 | $participant = CRM_Event_BAO_Participant::create($participantParams); | |
2158 | ||
2159 | $transaction->commit(); | |
2160 | ||
2161 | return $participant; | |
2162 | } | |
2163 | ||
3293fb2d | 2164 | /** |
2165 | * Is a payment being made on an existing contribution. | |
2166 | * | |
2167 | * Note | |
2168 | * 1) ideally we should not permit this on this form! Perhaps we don't & this is just cruft. | |
2169 | * 2) _paymentID is the contribution id. | |
2170 | * | |
2171 | * @return bool | |
2172 | */ | |
2173 | protected function isPaymentOnExistingContribution(): bool { | |
a3aed42a | 2174 | return ($this->getParticipantID() && $this->_action & CRM_Core_Action::UPDATE) && $this->_paymentId; |
3293fb2d | 2175 | } |
2176 | ||
f84f92f2 | 2177 | /** |
2178 | * Get the value for a field relating to the event. | |
2179 | * | |
2180 | * @param string $fieldName | |
2181 | * | |
2182 | * @return mixed | |
2183 | * @throws \CiviCRM_API3_Exception | |
2184 | */ | |
2185 | protected function getEventValue(string $fieldName) { | |
2186 | if (!isset($this->_event)) { | |
2187 | $this->_event = civicrm_api3('Event', 'getsingle', ['id' => $this->_eventId]); | |
2188 | } | |
2189 | return $this->_event[$fieldName]; | |
2190 | } | |
2191 | ||
a3aed42a | 2192 | /** |
2193 | * Get a value from the existing participant record (applies to edits). | |
2194 | * | |
2195 | * @param string $fieldName | |
2196 | * | |
2197 | * @return array | |
2198 | * @throws \CiviCRM_API3_Exception | |
2199 | */ | |
2200 | protected function getParticipantValue($fieldName) { | |
2201 | if (!$this->participantRecord) { | |
182df232 | 2202 | $this->participantRecord = civicrm_api3('Participant', 'getsingle', ['id' => $this->_id]); |
a3aed42a | 2203 | } |
182df232 | 2204 | return $this->participantRecord[$fieldName] ?? $this->participantRecord['participant_' . $fieldName]; |
a3aed42a | 2205 | } |
2206 | ||
2207 | /** | |
2208 | * Get id of participant being edited. | |
2209 | * | |
2210 | * @return int|null | |
2211 | */ | |
2212 | protected function getParticipantID() { | |
2ee9bfad | 2213 | return $this->_id ?? $this->_pId; |
a3aed42a | 2214 | } |
2215 | ||
939287ad | 2216 | /** |
2217 | * Get the value for the revenue recognition date field. | |
2218 | * | |
2219 | * @return string | |
2220 | * | |
2221 | * @throws \CiviCRM_API3_Exception | |
2222 | */ | |
2223 | protected function getRevenueRecognitionDate() { | |
2224 | if (Civi::settings()->get('deferred_revenue_enabled')) { | |
2225 | $eventStartDate = $this->getEventValue('start_date'); | |
2226 | if (strtotime($eventStartDate) > strtotime(date('Ymt'))) { | |
2227 | return date('Ymd', strtotime($eventStartDate)); | |
2228 | } | |
2229 | } | |
2230 | return ''; | |
2231 | } | |
2232 | ||
d3e6e9a4 | 2233 | /** |
2234 | * Store the parameters to create a payment, if approprite, on the form. | |
2235 | * | |
2236 | * @param array $params | |
2237 | * Params as submitted. | |
2238 | */ | |
2239 | protected function storePaymentCreateParams($params) { | |
2240 | if ('Completed' === CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $params['contribution_status_id'])) { | |
2241 | $this->setCreatePaymentParams([ | |
2242 | 'total_amount' => $params['total_amount'], | |
2243 | 'is_send_contribution_notification' => FALSE, | |
2244 | 'payment_instrument_id' => $params['payment_instrument_id'], | |
2245 | 'trxn_date' => $params['receive_date'] ?? date('Y-m-d'), | |
2246 | 'trxn_id' => $params['trxn_id'], | |
2247 | 'pan_truncation' => $params['pan_truncation'] ?? '', | |
2248 | 'card_type_id' => $params['card_type_id'] ?? '', | |
2249 | 'check_number' => $params['check_number'] ?? '', | |
2250 | 'skipCleanMoney' => TRUE, | |
2251 | ]); | |
2252 | } | |
2253 | } | |
2254 | ||
2f5a251a | 2255 | /** |
2256 | * Get the event fee info for given participant ids | |
2257 | * either from line item table / participant table. | |
2258 | * | |
2259 | * @param array $participantIds | |
2260 | * Participant ids. | |
2261 | * @param bool $hasLineItems | |
2262 | * Do fetch from line items. | |
2263 | * | |
2264 | * @return array | |
2265 | */ | |
2266 | public function getFeeDetails($participantIds, $hasLineItems = FALSE) { | |
2267 | $feeDetails = []; | |
2268 | if (!is_array($participantIds) || empty($participantIds)) { | |
2269 | return $feeDetails; | |
2270 | } | |
2271 | ||
2272 | $select = ' | |
2273 | SELECT participant.id as id, | |
2274 | participant.fee_level as fee_level, | |
2275 | participant.fee_amount as fee_amount'; | |
2276 | $from = 'FROM civicrm_participant participant'; | |
2277 | if ($hasLineItems) { | |
2278 | $select .= ' , | |
2279 | lineItem.id as lineId, | |
2280 | lineItem.label as label, | |
2281 | lineItem.qty as qty, | |
2282 | lineItem.unit_price as unit_price, | |
2283 | lineItem.line_total as line_total, | |
2284 | field.label as field_title, | |
2285 | field.html_type as html_type, | |
2286 | field.id as price_field_id, | |
2287 | value.id as price_field_value_id, | |
2288 | value.description as description, | |
2289 | IF( value.count, value.count, 0 ) as participant_count'; | |
2290 | $from .= " | |
2291 | INNER JOIN civicrm_line_item lineItem ON ( lineItem.entity_table = 'civicrm_participant' | |
2292 | AND lineItem.entity_id = participant.id ) | |
2293 | INNER JOIN civicrm_price_field field ON ( field.id = lineItem.price_field_id ) | |
2294 | INNER JOIN civicrm_price_field_value value ON ( value.id = lineItem.price_field_value_id ) | |
2295 | "; | |
2296 | } | |
2297 | $where = 'WHERE participant.id IN ( ' . implode(', ', $participantIds) . ' )'; | |
2298 | $query = "$select $from $where"; | |
2299 | ||
2300 | $feeInfo = CRM_Core_DAO::executeQuery($query); | |
2301 | $feeProperties = ['fee_level', 'fee_amount']; | |
2302 | $lineProperties = [ | |
2303 | 'lineId', | |
2304 | 'label', | |
2305 | 'qty', | |
2306 | 'unit_price', | |
2307 | 'line_total', | |
2308 | 'field_title', | |
2309 | 'html_type', | |
2310 | 'price_field_id', | |
2311 | 'participant_count', | |
2312 | 'price_field_value_id', | |
2313 | 'description', | |
2314 | ]; | |
2315 | while ($feeInfo->fetch()) { | |
2316 | if ($hasLineItems) { | |
2317 | foreach ($lineProperties as $property) { | |
2318 | $feeDetails[$feeInfo->id][$feeInfo->lineId][$property] = $feeInfo->$property; | |
2319 | } | |
2320 | } | |
2321 | else { | |
2322 | foreach ($feeProperties as $property) { | |
2323 | $feeDetails[$feeInfo->id][$property] = $feeInfo->$property; | |
2324 | } | |
2325 | } | |
2326 | } | |
2327 | ||
2328 | return $feeDetails; | |
2329 | } | |
2330 | ||
6a488035 | 2331 | } |