3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
30 * @copyright CiviCRM LLC (c) 2004-2019
34 * This class generates form components for processing Event.
36 class CRM_Event_Form_Registration
extends CRM_Core_Form
{
39 * How many locationBlocks should we display?
44 const LOCATION_BLOCKS
= 1;
47 * The id of the event we are proceessing.
54 * The array of ids of all the participant we are proceessing.
58 protected $_participantIDS = NULL;
61 * The id of the participant we are proceessing.
65 protected $_participantId;
68 * Is participant able to walk registration wizard.
72 public $_allowConfirmation;
75 * Is participant requires approval.
79 public $_requireApproval;
82 * Is event configured for waitlist.
86 public $_allowWaitlist;
89 * Store additional participant ids.
90 * when there are pre-registered.
94 public $_additionalParticipantIds;
97 * The mode that we are in.
105 * The values for the contribution db object.
112 * The paymentProcessor attributes for this page.
116 public $_paymentProcessor;
119 * The params submitted by the form and computed by the app.
126 * The fields involved in this contribution page.
133 * The billing location id for this contribiution page.
140 * Price Set ID, if the new price set method is used
144 public $_priceSetId = NULL;
147 * Array of fields for the price set.
158 * Is event already full.
165 public $_isEventFull;
168 public $_lineItemParticipantsCount;
169 public $_availableRegistrations;
175 public $_isBillingAddressRequiredForPayLater;
178 * Is this a back office form
182 public $isBackOffice = FALSE;
185 * Payment instrument iD for the transaction.
187 * This will generally be drawn from the payment processor and is ignored for
192 public $paymentInstrumentID;
195 * Set variables up before form is built.
197 public function preProcess() {
198 $this->_eventId
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, TRUE);
199 $this->_action
= CRM_Utils_Request
::retrieve('action', 'Alphanumeric', $this, FALSE, CRM_Core_Action
::ADD
);
202 $this->_participantId
= CRM_Utils_Request
::retrieve('participantId', 'Positive', $this);
205 $this->_mode
= ($this->_action
== 1024) ?
'test' : 'live';
207 $this->_values
= $this->get('values');
208 $this->_fields
= $this->get('fields');
209 $this->_bltID
= $this->get('bltID');
210 $this->_paymentProcessor
= $this->get('paymentProcessor');
211 $this->_priceSetId
= $this->get('priceSetId');
212 $this->_priceSet
= $this->get('priceSet');
213 $this->_lineItem
= $this->get('lineItem');
214 $this->_isEventFull
= $this->get('isEventFull');
215 $this->_lineItemParticipantsCount
= $this->get('lineItemParticipants');
216 if (!is_array($this->_lineItem
)) {
217 $this->_lineItem
= array();
219 if (!is_array($this->_lineItemParticipantsCount
)) {
220 $this->_lineItemParticipantsCount
= array();
222 $this->_availableRegistrations
= $this->get('availableRegistrations');
223 $this->_participantIDS
= $this->get('participantIDs');
225 //check if participant allow to walk registration wizard.
226 $this->_allowConfirmation
= $this->get('allowConfirmation');
228 // check for Approval
229 $this->_requireApproval
= $this->get('requireApproval');
231 // check for waitlisting.
232 $this->_allowWaitlist
= $this->get('allowWaitlist');
234 //get the additional participant ids.
235 $this->_additionalParticipantIds
= $this->get('additionalParticipantIds');
236 $config = CRM_Core_Config
::singleton();
238 if (!$this->_values
) {
239 // create redirect URL to send folks back to event info page is registration not available
240 $infoUrl = CRM_Utils_System
::url('civicrm/event/info', "reset=1&id={$this->_eventId}",
241 FALSE, NULL, FALSE, TRUE
244 // this is the first time we are hitting this, so check for permissions here
245 if (!CRM_Core_Permission
::event(CRM_Core_Permission
::EDIT
, $this->_eventId
, 'register for events')) {
246 CRM_Core_Error
::statusBounce(ts('You do not have permission to register for this event'), $infoUrl);
249 // get all the values from the dao object
250 $this->_values
= $this->_fields
= array();
252 //retrieve event information
253 $params = array('id' => $this->_eventId
);
254 CRM_Event_BAO_Event
::retrieve($params, $this->_values
['event']);
255 // check for is_monetary status
256 $isMonetary = CRM_Utils_Array
::value('is_monetary', $this->_values
['event']);
257 // check for ability to add contributions of type
259 && CRM_Financial_BAO_FinancialType
::isACLFinancialTypeStatus()
260 && !CRM_Core_Permission
::check('add contributions of type ' . CRM_Contribute_PseudoConstant
::financialType($this->_values
['event']['financial_type_id']))
262 CRM_Core_Error
::fatal(ts('You do not have permission to access this page.'));
265 $this->checkValidEvent($infoUrl);
266 // get the participant values, CRM-4320
267 $this->_allowConfirmation
= FALSE;
268 if ($this->_participantId
) {
269 $this->processFirstParticipant($this->_participantId
);
271 //check for additional participants.
272 if ($this->_allowConfirmation
&& $this->_values
['event']['is_multiple_registrations']) {
273 $additionalParticipantIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_participantId
);
275 foreach ($additionalParticipantIds as $additionalParticipantId) {
276 $this->_additionalParticipantIds
[$cnt] = $additionalParticipantId;
279 $this->set('additionalParticipantIds', $this->_additionalParticipantIds
);
282 $eventFull = CRM_Event_BAO_Participant
::eventFull($this->_eventId
, FALSE,
283 CRM_Utils_Array
::value('has_waitlist', $this->_values
['event'])
286 $this->_allowWaitlist
= $this->_isEventFull
= FALSE;
287 if ($eventFull && !$this->_allowConfirmation
) {
288 $this->_isEventFull
= TRUE;
289 //lets redirecting to info only when to waiting list.
290 $this->_allowWaitlist
= CRM_Utils_Array
::value('has_waitlist', $this->_values
['event']);
291 if (!$this->_allowWaitlist
) {
292 CRM_Utils_System
::redirect($infoUrl);
295 $this->set('isEventFull', $this->_isEventFull
);
296 $this->set('allowWaitlist', $this->_allowWaitlist
);
298 //check for require requires approval.
299 $this->_requireApproval
= FALSE;
300 if (!empty($this->_values
['event']['requires_approval']) && !$this->_allowConfirmation
) {
301 $this->_requireApproval
= TRUE;
303 $this->set('requireApproval', $this->_requireApproval
);
305 if (isset($this->_values
['event']['default_role_id'])) {
306 $participant_role = CRM_Core_OptionGroup
::values('participant_role');
307 $this->_values
['event']['participant_role'] = $participant_role["{$this->_values['event']['default_role_id']}"];
309 $isPayLater = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $this->_eventId
, 'is_pay_later');
310 //check for various combinations for paylater, payment
311 //process with paid event.
312 if ($isMonetary && (!$isPayLater ||
!empty($this->_values
['event']['payment_processor']))) {
313 $this->_paymentProcessorIDs
= explode(CRM_Core_DAO
::VALUE_SEPARATOR
, CRM_Utils_Array
::value('payment_processor',
314 $this->_values
['event']
316 $this->assignPaymentProcessor($isPayLater);
320 self
::initEventFee($this, $this->_eventId
);
322 // get the profile ids
323 $ufJoinParams = array(
324 'entity_table' => 'civicrm_event',
325 // CRM-4377:Â CiviEvent for the main participant, CiviEvent_Additional for additional participants
326 'module' => 'CiviEvent',
327 'entity_id' => $this->_eventId
,
329 list($this->_values
['custom_pre_id'],
330 $this->_values
['custom_post_id']
331 ) = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
333 // set profiles for additional participants
334 if ($this->_values
['event']['is_multiple_registrations']) {
335 // CRM-4377:Â CiviEvent for the main participant, CiviEvent_Additional for additional participants
336 $ufJoinParams['module'] = 'CiviEvent_Additional';
338 list($this->_values
['additional_custom_pre_id'],
339 $this->_values
['additional_custom_post_id'], $preActive, $postActive
340 ) = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
342 // CRM-4377:Â we need to maintain backward compatibility, hence if there is profile for main contact
343 // set same profile for additional contacts.
344 if ($this->_values
['custom_pre_id'] && !$this->_values
['additional_custom_pre_id']) {
345 $this->_values
['additional_custom_pre_id'] = $this->_values
['custom_pre_id'];
348 if ($this->_values
['custom_post_id'] && !$this->_values
['additional_custom_post_id']) {
349 $this->_values
['additional_custom_post_id'] = $this->_values
['custom_post_id'];
351 // now check for no profile condition, in that case is_active = 0
352 if (isset($preActive) && !$preActive) {
353 unset($this->_values
['additional_custom_pre_id']);
355 if (isset($postActive) && !$postActive) {
356 unset($this->_values
['additional_custom_post_id']);
360 $this->assignBillingType();
362 if ($this->_values
['event']['is_monetary']) {
363 CRM_Core_Payment_Form
::setPaymentFieldsByProcessor($this, $this->_paymentProcessor
);
365 $params = array('entity_id' => $this->_eventId
, 'entity_table' => 'civicrm_event');
366 $this->_values
['location'] = CRM_Core_BAO_Location
::getValues($params, TRUE);
368 $this->set('values', $this->_values
);
369 $this->set('fields', $this->_fields
);
371 $this->_availableRegistrations
372 = CRM_Event_BAO_Participant
::eventFull(
373 $this->_values
['event']['id'], TRUE,
374 CRM_Utils_Array
::value('has_waitlist', $this->_values
['event'])
376 $this->set('availableRegistrations', $this->_availableRegistrations
);
378 $this->assign_by_ref('paymentProcessor', $this->_paymentProcessor
);
380 // check if this is a paypal auto return and redirect accordingly
381 if (CRM_Core_Payment
::paypalRedirect($this->_paymentProcessor
)) {
382 $url = CRM_Utils_System
::url('civicrm/event/register',
383 "_qf_ThankYou_display=1&qfKey={$this->controller->_key}"
385 CRM_Utils_System
::redirect($url);
387 // The concept of contributeMode is deprecated.
388 $this->_contributeMode
= $this->get('contributeMode');
389 $this->assign('contributeMode', $this->_contributeMode
);
391 $this->setTitle($this->_values
['event']['title']);
393 $this->assign('paidEvent', $this->_values
['event']['is_monetary']);
395 // we do not want to display recently viewed items on Registration pages
396 $this->assign('displayRecent', FALSE);
397 // Registration page values are cleared from session, so can't use normal Printer Friendly view.
398 // Use Browser Print instead.
399 $this->assign('browserPrint', TRUE);
401 $isShowLocation = CRM_Utils_Array
::value('is_show_location', $this->_values
['event']);
402 $this->assign('isShowLocation', $isShowLocation);
404 $pcpId = CRM_Utils_Request
::retrieve('pcpId', 'Positive', $this);
406 $pcp = CRM_PCP_BAO_PCP
::handlePcp($pcpId, 'event', $this->_values
['event']);
407 $this->_pcpId
= $pcp['pcpId'];
408 $this->_values
['event']['intro_text'] = CRM_Utils_Array
::value('intro_text', $pcp['pcpInfo']);
411 // assign all event properties so wizard templates can display event info.
412 $this->assign('event', $this->_values
['event']);
413 $this->assign('location', $this->_values
['location']);
414 $this->assign('bltID', $this->_bltID
);
415 $isShowLocation = CRM_Utils_Array
::value('is_show_location', $this->_values
['event']);
416 $this->assign('isShowLocation', $isShowLocation);
417 CRM_Contribute_BAO_Contribution_Utils
::overrideDefaultCurrency($this->_values
['event']);
419 //lets allow user to override campaign.
420 $campID = CRM_Utils_Request
::retrieve('campID', 'Positive', $this);
421 if ($campID && CRM_Core_DAO
::getFieldValue('CRM_Campaign_DAO_Campaign', $campID)) {
422 $this->_values
['event']['campaign_id'] = $campID;
425 // Set the same value for is_billing_required as contribution page so code can be shared.
426 $this->_values
['is_billing_required'] = CRM_Utils_Array
::value('is_billing_required', $this->_values
['event']);
427 // check if billing block is required for pay later
428 // note that I have started removing the use of isBillingAddressRequiredForPayLater in favour of letting
429 // the CRM_Core_Payment_Manual class handle it - but there are ~300 references to it in the code base so only
430 // removing in very limited cases.
431 if (CRM_Utils_Array
::value('is_pay_later', $this->_values
['event'])) {
432 $this->_isBillingAddressRequiredForPayLater
= CRM_Utils_Array
::value('is_billing_required', $this->_values
['event']);
433 $this->assign('isBillingAddressRequiredForPayLater', $this->_isBillingAddressRequiredForPayLater
);
438 * Assign the minimal set of variables to the template.
440 public function assignToTemplate() {
441 //process only primary participant params
442 $this->_params
= $this->get('params');
443 if (isset($this->_params
[0])) {
444 $params = $this->_params
[0];
447 if (!empty($params['billing_first_name'])) {
448 $name = $params['billing_first_name'];
451 if (!empty($params['billing_middle_name'])) {
452 $name .= " {$params['billing_middle_name']}";
455 if (!empty($params['billing_last_name'])) {
456 $name .= " {$params['billing_last_name']}";
458 $this->assign('billingName', $name);
459 $this->set('name', $name);
470 foreach ($vars as $v) {
471 if (!empty($params[$v])) {
472 if ($v == 'receive_date') {
473 $this->assign($v, CRM_Utils_Date
::mysqlToIso($params[$v]));
476 $this->assign($v, $params[$v]);
479 elseif (empty($params['amount'])) {
480 $this->assign($v, CRM_Utils_Array
::value($v, $params));
484 $this->assign('address', CRM_Utils_Address
::getFormattedBillingAddressFieldsFromParameters($params, $this->_bltID
));
486 // The concept of contributeMode is deprecated.
487 if ($this->_contributeMode
== 'direct' && empty($params['is_pay_later'])) {
488 $date = CRM_Utils_Date
::format(CRM_Utils_Array
::value('credit_card_exp_date', $params));
489 $date = CRM_Utils_Date
::mysqlToIso($date);
490 $this->assign('credit_card_exp_date', $date);
491 $this->assign('credit_card_number',
492 CRM_Utils_System
::mungeCreditCard(CRM_Utils_Array
::value('credit_card_number', $params))
496 // get the email that the confirmation would have been sent to
497 $session = CRM_Core_Session
::singleton();
499 // assign is_email_confirm to templates
500 if (isset($this->_values
['event']['is_email_confirm'])) {
501 $this->assign('is_email_confirm', $this->_values
['event']['is_email_confirm']);
504 // assign pay later stuff
505 $params['is_pay_later'] = CRM_Utils_Array
::value('is_pay_later', $params, FALSE);
506 $this->assign('is_pay_later', $params['is_pay_later']);
507 if ($params['is_pay_later']) {
508 $this->assign('pay_later_text', $this->_values
['event']['pay_later_text']);
509 $this->assign('pay_later_receipt', $this->_values
['event']['pay_later_receipt']);
512 // also assign all participantIDs to the template
513 // useful in generating confirmation numbers if needed
514 $this->assign('participantIDs', $this->_participantIDS
);
518 * Add the custom fields.
521 * @param string $name
522 * @param bool $viewOnly
524 public function buildCustom($id, $name, $viewOnly = FALSE) {
526 $button = substr($this->controller
->getButtonName(), -4);
527 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
528 $session = CRM_Core_Session
::singleton();
529 $contactID = $session->get('userID');
531 // we don't allow conflicting fields to be
532 // configured via profile
533 $fieldsToIgnore = array(
534 'participant_fee_amount' => 1,
535 'participant_fee_level' => 1,
541 foreach ($id as $profileID) {
542 $field = CRM_Core_BAO_UFGroup
::getFields($profileID, FALSE, CRM_Core_Action
::ADD
,
543 NULL, NULL, FALSE, NULL,
544 FALSE, NULL, CRM_Core_Permission
::CREATE
,
547 $fields = array_merge($fields, $field);
551 if (CRM_Core_BAO_UFGroup
::filterUFGroups($id, $contactID)) {
552 $fields = CRM_Core_BAO_UFGroup
::getFields($id, FALSE, CRM_Core_Action
::ADD
,
553 NULL, NULL, FALSE, NULL,
554 FALSE, NULL, CRM_Core_Permission
::CREATE
,
561 $fields = CRM_Core_BAO_UFGroup
::getFields($id, FALSE, CRM_Core_Action
::ADD
,
562 NULL, NULL, FALSE, NULL,
563 FALSE, NULL, CRM_Core_Permission
::CREATE
,
568 if (array_intersect_key($fields, $fieldsToIgnore)) {
569 $fields = array_diff_key($fields, $fieldsToIgnore);
570 CRM_Core_Session
::setStatus(ts('Some of the profile fields cannot be configured for this page.'));
574 if (!empty($this->_fields
)) {
575 $fields = @array_diff_assoc
($fields, $this->_fields
);
578 if (empty($this->_params
[0]['additional_participants']) &&
581 CRM_Core_BAO_Address
::checkContactSharedAddressFields($fields, $contactID);
583 $this->assign($name, $fields);
584 if (is_array($fields)) {
585 foreach ($fields as $key => $field) {
587 isset($field['data_type']) &&
588 $field['data_type'] == 'File' ||
($viewOnly && $field['name'] == 'image_URL')
590 // ignore file upload fields
593 //make the field optional if primary participant
594 //have been skip the additional participant.
595 if ($button == 'skip') {
596 $field['is_required'] = FALSE;
598 // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
599 elseif ($field['add_captcha'] && !$contactID) {
600 // only add captcha for first page
603 list($prefixName, $index) = CRM_Utils_System
::explode('-', $key, 2);
604 CRM_Core_BAO_UFGroup
::buildProfile($this, $field, CRM_Profile_Form
::MODE_CREATE
, $contactID, TRUE);
606 $this->_fields
[$key] = $field;
610 if ($addCaptcha && !$viewOnly) {
611 CRM_Utils_ReCAPTCHA
::enableCaptchaOnForm($this);
617 * Initiate event fee.
619 * @param CRM_Core_Form $form
620 * @param int $eventID
624 public static function initEventFee(&$form, $eventID) {
627 // retrive all active price set fields.
628 $discountId = CRM_Core_BAO_Discount
::findSet($eventID, 'civicrm_event');
629 if (property_exists($form, '_discountId') && $form->_discountId
) {
630 $discountId = $form->_discountId
;
633 //CRM-16456 get all price field including expired one.
634 $getAllPriceField = TRUE;
635 $className = CRM_Utils_System
::getClassName($form);
636 if ($className == 'CRM_Event_Form_ParticipantFeeSelection' && $form->_action
== CRM_Core_Action
::UPDATE
) {
637 $getAllPriceField = FALSE;
641 $priceSetId = CRM_Core_DAO
::getFieldValue('CRM_Core_BAO_Discount', $discountId, 'price_set_id');
642 $price = CRM_Price_BAO_PriceSet
::initSet($form, $eventID, 'civicrm_event', $getAllPriceField, $priceSetId);
645 $price = CRM_Price_BAO_PriceSet
::initSet($form, $eventID, 'civicrm_event', $getAllPriceField);
648 if (property_exists($form, '_context') && ($form->_context
== 'standalone'
649 ||
$form->_context
== 'participant')
651 $discountedEvent = CRM_Core_BAO_Discount
::getOptionGroup($eventID, 'civicrm_event');
652 if (is_array($discountedEvent)) {
653 foreach ($discountedEvent as $key => $priceSetId) {
654 $priceSet = CRM_Price_BAO_PriceSet
::getSetDetail($priceSetId);
655 $priceSet = CRM_Utils_Array
::value($priceSetId, $priceSet);
656 $form->_values
['discount'][$key] = CRM_Utils_Array
::value('fields', $priceSet);
657 $fieldID = key($form->_values
['discount'][$key]);
658 $form->_values
['discount'][$key][$fieldID]['name'] = CRM_Core_DAO
::getFieldValue(
659 'CRM_Price_DAO_PriceSet',
666 $eventFee = CRM_Utils_Array
::value('fee', $form->_values
);
667 if (!is_array($eventFee) ||
empty($eventFee)) {
668 $form->_values
['fee'] = array();
671 //fix for non-upgraded price sets.CRM-4256.
672 if (isset($form->_isPaidEvent
)) {
673 $isPaidEvent = $form->_isPaidEvent
;
676 $isPaidEvent = CRM_Utils_Array
::value('is_monetary', $form->_values
['event']);
678 if (CRM_Financial_BAO_FinancialType
::isACLFinancialTypeStatus()
679 && !empty($form->_values
['fee'])
681 foreach ($form->_values
['fee'] as $k => $fees) {
682 foreach ($fees['options'] as $options) {
683 if (!CRM_Core_Permission
::check('add contributions of type ' . CRM_Contribute_PseudoConstant
::financialType($options['financial_type_id']))) {
684 unset($form->_values
['fee'][$k]);
689 if ($isPaidEvent && empty($form->_values
['fee'])) {
690 if (CRM_Utils_System
::getClassName($form) != 'CRM_Event_Form_Participant') {
691 CRM_Core_Error
::fatal(ts('No Fee Level(s) or Price Set is configured for this event.<br />Click <a href=\'%1\'>CiviEvent >> Manage Event >> Configure >> Event Fees</a> to configure the Fee Level(s) or Price Set for this event.', array(1 => CRM_Utils_System
::url('civicrm/event/manage/fee', 'reset=1&action=update&id=' . $form->_eventId
))));
697 * Handle process after the confirmation of payment by User.
699 * @param int $contactID
700 * @param null $contribution
701 * @param null $payment
703 public function confirmPostProcess($contactID = NULL, $contribution = NULL, $payment = NULL) {
704 // add/update contact information
706 unset($this->_params
['note']);
708 //to avoid conflict overwrite $this->_params
709 $this->_params
= $this->get('value');
711 //get the amount of primary participant
712 if (!empty($this->_params
['is_primary'])) {
713 $this->_params
['fee_amount'] = $this->get('primaryParticipantAmount');
716 // add participant record
717 $participant = CRM_Event_Form_Registration
::addParticipant($this, $contactID);
718 $this->_participantIDS
[] = $participant->id
;
720 //setting register_by_id field and primaryContactId
721 if (!empty($this->_params
['is_primary'])) {
722 $this->set('registerByID', $participant->id
);
723 $this->set('primaryContactId', $contactID);
726 $this->processFirstParticipant($participant->id
);
729 CRM_Core_BAO_CustomValueTable
::postProcess($this->_params
,
730 'civicrm_participant',
735 $createPayment = (CRM_Utils_Array
::value('amount', $this->_params
, 0) != 0) ?
TRUE : FALSE;
737 // force to create zero amount payment, CRM-5095
738 // we know the amout is zero since createPayment is false
739 if (!$createPayment &&
740 (isset($contribution) && $contribution->id
) &&
741 $this->_priceSetId
&&
744 $createPayment = TRUE;
747 if ($createPayment && $this->_values
['event']['is_monetary'] && !empty($this->_params
['contributionID'])) {
748 $paymentParams = array(
749 'participant_id' => $participant->id
,
750 'contribution_id' => $contribution->id
,
752 $paymentPartcipant = CRM_Event_BAO_ParticipantPayment
::create($paymentParams);
755 //set only primary participant's params for transfer checkout.
756 // The concept of contributeMode is deprecated.
757 if (($this->_contributeMode
== 'checkout' ||
$this->_contributeMode
== 'notify') && !empty($this->_params
['is_primary'])) {
758 $this->_params
['participantID'] = $participant->id
;
759 $this->set('primaryParticipant', $this->_params
);
762 $this->assign('action', $this->_action
);
765 if (!empty($this->_params
['cms_create_account'])) {
766 $this->_params
['contactID'] = $contactID;
768 if (array_key_exists('email-5', $this->_params
)) {
772 foreach ($this->_params
as $name => $dontCare) {
773 if (substr($name, 0, 5) == 'email') {
780 // we should use primary email for
781 // 1. pay later participant.
782 // 2. waiting list participant.
783 // 3. require approval participant.
784 if (!empty($this->_params
['is_pay_later']) ||
785 $this->_allowWaitlist ||
$this->_requireApproval
787 $mail = 'email-Primary';
790 if (!CRM_Core_BAO_CMSUser
::create($this->_params
, $mail)) {
791 CRM_Core_Error
::statusBounce(ts('Your profile is not saved and Account is not created.'));
797 * Process the participant.
799 * @param CRM_Core_Form $form
800 * @param int $contactID
802 * @return \CRM_Event_BAO_Participant
804 public static function addParticipant(&$form, $contactID) {
805 if (empty($form->_params
)) {
808 $params = $form->_params
;
809 $transaction = new CRM_Core_Transaction();
811 // handle register date CRM-4320
812 $registerDate = NULL;
813 if (!empty($form->_allowConfirmation
) && $form->_participantId
) {
814 $registerDate = $params['participant_register_date'];
816 elseif (!empty($params['participant_register_date']) &&
817 is_array($params['participant_register_date']) &&
818 !empty($params['participant_register_date'])
820 $registerDate = CRM_Utils_Date
::format($params['participant_register_date']);
823 $participantFields = CRM_Event_DAO_Participant
::fields();
824 $participantParams = array(
825 'id' => CRM_Utils_Array
::value('participant_id', $params),
826 'contact_id' => $contactID,
827 'event_id' => $form->_eventId ?
$form->_eventId
: $params['event_id'],
828 'status_id' => CRM_Utils_Array
::value('participant_status',
831 'role_id' => CRM_Utils_Array
::value('participant_role_id', $params) ?
: self
::getDefaultRoleID(),
832 'register_date' => ($registerDate) ?
$registerDate : date('YmdHis'),
833 'source' => CRM_Utils_String
::ellipsify(
834 isset($params['participant_source']) ? CRM_Utils_Array
::value('participant_source', $params) : CRM_Utils_Array
::value('description', $params),
835 $participantFields['participant_source']['maxlength']
837 'fee_level' => CRM_Utils_Array
::value('amount_level', $params),
838 'is_pay_later' => CRM_Utils_Array
::value('is_pay_later', $params, 0),
839 'fee_amount' => CRM_Utils_Array
::value('fee_amount', $params),
840 'registered_by_id' => CRM_Utils_Array
::value('registered_by_id', $params),
841 'discount_id' => CRM_Utils_Array
::value('discount_id', $params),
842 'fee_currency' => CRM_Utils_Array
::value('currencyID', $params),
843 'campaign_id' => CRM_Utils_Array
::value('campaign_id', $params),
846 if ($form->_action
& CRM_Core_Action
::PREVIEW || CRM_Utils_Array
::value('mode', $params) == 'test') {
847 $participantParams['is_test'] = 1;
850 $participantParams['is_test'] = 0;
853 if (!empty($form->_params
['note'])) {
854 $participantParams['note'] = $form->_params
['note'];
856 elseif (!empty($form->_params
['participant_note'])) {
857 $participantParams['note'] = $form->_params
['participant_note'];
860 // reuse id if one already exists for this one (can happen
861 // with back button being hit etc)
862 if (!$participantParams['id'] && !empty($params['contributionID'])) {
863 $pID = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
864 $params['contributionID'],
868 $participantParams['id'] = $pID;
870 $participantParams['discount_id'] = CRM_Core_BAO_Discount
::findSet($form->_eventId
, 'civicrm_event');
872 if (!$participantParams['discount_id']) {
873 $participantParams['discount_id'] = "null";
876 $participant = CRM_Event_BAO_Participant
::create($participantParams);
878 $transaction->commit();
884 * Get the ID of the default (first) participant role
887 * @throws \CiviCRM_API3_Exception
889 private static function getDefaultRoleID() {
890 return (int) civicrm_api3('OptionValue', 'getvalue', [
892 'option_group_id' => "participant_role",
894 'options' => ['limit' => 1, 'sort' => "is_default DESC"],
899 * Calculate the total participant count as per params.
901 * @param CRM_Core_Form $form
902 * @param array $params
904 * @param bool $skipCurrent
908 public static function getParticipantCount(&$form, $params, $skipCurrent = FALSE) {
910 if (!is_array($params) ||
empty($params)) {
914 $priceSetId = $form->get('priceSetId');
915 $addParticipantNum = substr($form->_name
, 12);
916 $priceSetFields = $priceSetDetails = array();
917 $hasPriceFieldsCount = FALSE;
919 $priceSetDetails = $form->get('priceSet');
920 if (isset($priceSetDetails['optionsCountTotal'])
921 && $priceSetDetails['optionsCountTotal']
923 $hasPriceFieldsCount = TRUE;
924 $priceSetFields = $priceSetDetails['optionsCountDetails']['fields'];
928 $singleFormParams = FALSE;
929 foreach ($params as $key => $val) {
930 if (!is_numeric($key)) {
931 $singleFormParams = TRUE;
936 //first format the params.
937 if ($singleFormParams) {
938 $params = self
::formatPriceSetParams($form, $params);
939 $params = array($params);
942 foreach ($params as $key => $values) {
943 if (!is_numeric($key) ||
945 ($skipCurrent && ($addParticipantNum == $key))
952 $cacheCount = CRM_Utils_Array
::value($key, $form->_lineItemParticipantsCount
);
953 if ($cacheCount && is_numeric($cacheCount)) {
954 $count = $cacheCount;
958 if (!$usedCache && $hasPriceFieldsCount) {
960 foreach ($values as $valKey => $value) {
961 if (strpos($valKey, 'price_') === FALSE) {
964 $priceFieldId = substr($valKey, 6);
965 if (!$priceFieldId ||
967 !array_key_exists($priceFieldId, $priceSetFields)
971 foreach ($value as $optId => $optVal) {
972 $currentCount = $priceSetFields[$priceFieldId]['options'][$optId] * $optVal;
974 $count +
= $currentCount;
982 $totalCount +
= $count;
992 * Format user submitted price set params.
994 * Convert price set each param as an array.
996 * @param CRM_Core_Form $form
997 * @param array $params
998 * An array of user submitted params.
1001 * Formatted price set params.
1003 public static function formatPriceSetParams(&$form, $params) {
1004 if (!is_array($params) ||
empty($params)) {
1008 $priceSetId = $form->get('priceSetId');
1012 $priceSetDetails = $form->get('priceSet');
1014 foreach ($params as $key => & $value) {
1016 if (strpos($key, 'price_') !== FALSE) {
1017 $fieldId = substr($key, 6);
1018 if (!array_key_exists($fieldId, $priceSetDetails['fields']) ||
1024 $field = $priceSetDetails['fields'][$fieldId];
1025 if ($field['html_type'] == 'Text') {
1026 $fieldOption = current($field['options']);
1027 $value = array($fieldOption['id'] => $value);
1030 $value = array($value => TRUE);
1039 * Calculate total count for each price set options.
1041 * - currently selected by user.
1043 * @param CRM_Core_Form $form
1047 * array of each option w/ count total.
1049 public static function getPriceSetOptionCount(&$form) {
1050 $params = $form->get('params');
1051 $priceSet = $form->get('priceSet');
1052 $priceSetId = $form->get('priceSetId');
1054 $optionsCount = array();
1056 !is_array($priceSet) ||
1058 !is_array($params) ||
1061 return $optionsCount;
1064 $priceSetFields = $priceMaxFieldDetails = array();
1065 if (!empty($priceSet['optionsCountTotal'])) {
1066 $priceSetFields = $priceSet['optionsCountDetails']['fields'];
1069 if (!empty($priceSet['optionsMaxValueTotal'])) {
1070 $priceMaxFieldDetails = $priceSet['optionsMaxValueDetails']['fields'];
1073 $addParticipantNum = substr($form->_name
, 12);
1074 foreach ($params as $pCnt => $values) {
1075 if ($values == 'skip' ||
1076 $pCnt === $addParticipantNum
1081 foreach ($values as $valKey => $value) {
1082 if (strpos($valKey, 'price_') === FALSE) {
1086 $priceFieldId = substr($valKey, 6);
1087 if (!$priceFieldId ||
1088 !is_array($value) ||
1089 !(array_key_exists($priceFieldId, $priceSetFields) ||
array_key_exists($priceFieldId, $priceMaxFieldDetails))
1094 foreach ($value as $optId => $optVal) {
1095 if (CRM_Utils_Array
::value('html_type', $priceSet['fields'][$priceFieldId]) == 'Text') {
1096 $currentCount = $optVal;
1102 if (isset($priceSetFields[$priceFieldId]) && isset($priceSetFields[$priceFieldId]['options'][$optId])) {
1103 $currentCount = $priceSetFields[$priceFieldId]['options'][$optId] * $optVal;
1106 $optionsCount[$optId] = $currentCount + CRM_Utils_Array
::value($optId, $optionsCount, 0);
1111 return $optionsCount;
1115 * Check if template file exists.
1117 * @param string $suffix
1119 * @return null|string
1121 public function checkTemplateFileExists($suffix = '') {
1122 if ($this->_eventId
) {
1123 $templateName = $this->_name
;
1124 if (substr($templateName, 0, 12) == 'Participant_') {
1125 $templateName = 'AdditionalParticipant';
1128 $templateFile = "CRM/Event/Form/Registration/{$this->_eventId}/{$templateName}.{$suffix}tpl";
1129 $template = CRM_Core_Form
::getTemplate();
1130 if ($template->template_exists($templateFile)) {
1131 return $templateFile;
1138 * Get template file name.
1140 * @return null|string
1142 public function getTemplateFileName() {
1143 $fileName = $this->checkTemplateFileExists();
1144 return $fileName ?
$fileName : parent
::getTemplateFileName();
1148 * Override extra template name.
1150 * @return null|string
1152 public function overrideExtraTemplateFileName() {
1153 $fileName = $this->checkTemplateFileExists('extra.');
1154 return $fileName ?
$fileName : parent
::overrideExtraTemplateFileName();
1158 * Reset values for all options those are full.
1160 * @param array $optionFullIds
1161 * @param CRM_Core_Form $form
1163 public static function resetElementValue($optionFullIds = array(), &$form) {
1164 if (!is_array($optionFullIds) ||
1165 empty($optionFullIds) ||
1166 !$form->isSubmitted()
1171 foreach ($optionFullIds as $fldId => $optIds) {
1172 $name = "price_$fldId";
1173 if (!$form->elementExists($name)) {
1177 $element = $form->getElement($name);
1178 $eleType = $element->getType();
1180 $resetSubmitted = FALSE;
1183 if ($element->getValue() && $element->isFrozen()) {
1184 $label = "{$element->getLabel()}<tt>(x)</tt>";
1185 $element->setLabel($label);
1186 $element->setPersistantFreeze();
1187 $resetSubmitted = TRUE;
1192 if (is_array($element->_elements
)) {
1193 foreach ($element->_elements
as $child) {
1194 $childType = $child->getType();
1195 $methodName = 'getName';
1197 $methodName = 'getValue';
1199 if (in_array($child->{$methodName}(), $optIds) && $child->isFrozen()) {
1200 $resetSubmitted = TRUE;
1201 $child->setPersistantFreeze();
1208 $value = $element->getValue();
1209 if (in_array($value[0], $optIds)) {
1210 foreach ($element->_options
as $option) {
1211 if ($option['attr']['value'] === "crm_disabled_opt-{$value[0]}") {
1212 $placeholder = html_entity_decode($option['text'], ENT_QUOTES
, "UTF-8");
1213 $element->updateAttributes(array('placeholder' => $placeholder));
1217 $resetSubmitted = TRUE;
1222 //finally unset values from submitted.
1223 if ($resetSubmitted) {
1224 self
::resetSubmittedValue($name, $optIds, $form);
1230 * Reset submitted value.
1232 * @param string $elementName
1233 * @param array $optionIds
1234 * @param CRM_Core_Form $form
1236 public static function resetSubmittedValue($elementName, $optionIds = array(), &$form) {
1237 if (empty($elementName) ||
1238 !$form->elementExists($elementName) ||
1239 !$form->getSubmitValue($elementName)
1248 $values = $form->{"_$val"};
1249 if (!is_array($values) ||
empty($values)) {
1252 $eleVal = CRM_Utils_Array
::value($elementName, $values);
1253 if (empty($eleVal)) {
1256 if (is_array($eleVal)) {
1258 foreach ($eleVal as $keyId => $ignore) {
1259 if (in_array($keyId, $optionIds)) {
1261 unset($values[$elementName][$keyId]);
1264 if ($found && empty($values[$elementName][$keyId])) {
1265 $values[$elementName][$keyId] = NULL;
1269 if (!empty($keyId)) {
1270 $values[$elementName][$keyId] = NULL;
1277 * Validate price set submitted params for price option limit.
1279 * User should select at least one price field option.
1281 * @param CRM_Core_Form $form
1282 * @param array $params
1286 public static function validatePriceSet(&$form, $params) {
1288 $hasOptMaxValue = FALSE;
1289 if (!is_array($params) ||
empty($params)) {
1293 $currentParticipantNum = substr($form->_name
, 12);
1294 if (!$currentParticipantNum) {
1295 $currentParticipantNum = 0;
1298 $priceSetId = $form->get('priceSetId');
1299 $priceSetDetails = $form->get('priceSet');
1302 !is_array($priceSetDetails) ||
1303 empty($priceSetDetails)
1308 $optionsCountDetails = $optionsMaxValueDetails = array();
1310 isset($priceSetDetails['optionsMaxValueTotal'])
1311 && $priceSetDetails['optionsMaxValueTotal']
1313 $hasOptMaxValue = TRUE;
1314 $optionsMaxValueDetails = $priceSetDetails['optionsMaxValueDetails']['fields'];
1317 isset($priceSetDetails['optionsCountTotal'])
1318 && $priceSetDetails['optionsCountTotal']
1320 $hasOptCount = TRUE;
1321 $optionsCountDetails = $priceSetDetails['optionsCountDetails']['fields'];
1323 $feeBlock = $form->_feeBlock
;
1325 if (empty($feeBlock)) {
1326 $feeBlock = $priceSetDetails['fields'];
1329 $optionMaxValues = $fieldSelected = array();
1330 foreach ($params as $pNum => $values) {
1331 if (!is_array($values) ||
$values == 'skip') {
1335 foreach ($values as $valKey => $value) {
1336 if (strpos($valKey, 'price_') === FALSE) {
1339 $priceFieldId = substr($valKey, 6);
1340 $noneOptionValueSelected = FALSE;
1341 if (!$feeBlock[$priceFieldId]['is_required'] && $value == 0) {
1342 $noneOptionValueSelected = TRUE;
1347 (!$noneOptionValueSelected && !is_array($value))
1352 $fieldSelected[$pNum] = TRUE;
1354 if (!$hasOptMaxValue ||
!is_array($value)) {
1358 foreach ($value as $optId => $optVal) {
1359 if (CRM_Utils_Array
::value('html_type', $feeBlock[$priceFieldId]) == 'Text') {
1360 $currentMaxValue = $optVal;
1363 $currentMaxValue = 1;
1366 if (isset($optionsCountDetails[$priceFieldId]) && isset($optionsCountDetails[$priceFieldId]['options'][$optId])) {
1367 $currentMaxValue = $optionsCountDetails[$priceFieldId]['options'][$optId] * $optVal;
1369 if (empty($optionMaxValues)) {
1370 $optionMaxValues[$priceFieldId][$optId] = $currentMaxValue;
1373 $optionMaxValues[$priceFieldId][$optId]
1374 = $currentMaxValue + CRM_Utils_Array
::value($optId, CRM_Utils_Array
::value($priceFieldId, $optionMaxValues), 0);
1376 $soldOutPnum[$optId] = $pNum;
1380 //validate for price field selection.
1381 if (empty($fieldSelected[$pNum])) {
1382 $errors[$pNum]['_qf_default'] = ts('Select at least one option from Event Fee(s).');
1386 //validate for option max value.
1387 foreach ($optionMaxValues as $fieldId => $values) {
1388 $options = CRM_Utils_Array
::value('options', $feeBlock[$fieldId], array());
1389 foreach ($values as $optId => $total) {
1390 $optMax = $optionsMaxValueDetails[$fieldId]['options'][$optId];
1391 $opDbCount = CRM_Utils_Array
::value('db_total_count', $options[$optId], 0);
1392 $total +
= $opDbCount;
1393 if ($optMax && ($total > $optMax)) {
1394 if ($opDbCount && ($opDbCount >= $optMax)) {
1395 $errors[$soldOutPnum[$optId]]["price_{$fieldId}"]
1396 = ts('Sorry, this option is currently sold out.');
1398 elseif (($optMax - $opDbCount) == 1) {
1399 $errors[$soldOutPnum[$optId]]["price_{$fieldId}"]
1400 = ts('Sorry, currently only a single space is available for this option.', array(1 => ($optMax - $opDbCount)));
1403 $errors[$soldOutPnum[$optId]]["price_{$fieldId}"]
1404 = ts('Sorry, currently only %1 spaces are available for this option.', array(1 => ($optMax - $opDbCount)));
1413 * Set the first participant ID if not set.
1417 * @param int $participantID
1419 public function processFirstParticipant($participantID) {
1420 $this->_participantId
= $participantID;
1421 $this->set('participantId', $this->_participantId
);
1423 $ids = $participantValues = array();
1424 $participantParams = array('id' => $this->_participantId
);
1425 CRM_Event_BAO_Participant
::getValues($participantParams, $participantValues, $ids);
1426 $this->_values
['participant'] = $participantValues[$this->_participantId
];
1427 $this->set('values', $this->_values
);
1429 // also set the allow confirmation stuff
1430 if (array_key_exists(
1431 $this->_values
['participant']['status_id'],
1432 CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Pending'")
1434 $this->_allowConfirmation
= TRUE;
1435 $this->set('allowConfirmation', TRUE);
1440 * Check if event is valid.
1442 * @todo - combine this with CRM_Event_BAO_Event::validRegistrationRequest
1443 * (probably extract relevant values here & call that with them & handle bounces & redirects here -as
1444 * those belong in the form layer)
1446 * @param string $redirect
1448 public function checkValidEvent($redirect = NULL) {
1449 // is the event active (enabled)?
1450 if (!$this->_values
['event']['is_active']) {
1451 // form is inactive, die a fatal death
1452 CRM_Core_Error
::statusBounce(ts('The event you requested is currently unavailable (contact the site administrator for assistance).'));
1455 // is online registration is enabled?
1456 if (!$this->_values
['event']['is_online_registration']) {
1457 CRM_Core_Error
::statusBounce(ts('Online registration is not currently available for this event (contact the site administrator for assistance).'), $redirect);
1460 // is this an event template ?
1461 if (!empty($this->_values
['event']['is_template'])) {
1462 CRM_Core_Error
::statusBounce(ts('Event templates are not meant to be registered.'), $redirect);
1465 $now = date('YmdHis');
1466 $startDate = CRM_Utils_Date
::processDate(CRM_Utils_Array
::value('registration_start_date',
1467 $this->_values
['event']
1474 CRM_Core_Error
::statusBounce(ts('Registration for this event begins on %1', array(1 => CRM_Utils_Date
::customFormat(CRM_Utils_Array
::value('registration_start_date', $this->_values
['event'])))), $redirect, ts('Sorry'));
1477 $regEndDate = CRM_Utils_Date
::processDate(CRM_Utils_Array
::value('registration_end_date',
1478 $this->_values
['event']
1480 $eventEndDate = CRM_Utils_Date
::processDate(CRM_Utils_Array
::value('event_end_date', $this->_values
['event']));
1481 if (($regEndDate && ($regEndDate < $now)) ||
(empty($regEndDate) && !empty($eventEndDate) && ($eventEndDate < $now))) {
1482 $endDate = CRM_Utils_Date
::customFormat(CRM_Utils_Array
::value('registration_end_date', $this->_values
['event']));
1483 if (empty($regEndDate)) {
1484 $endDate = CRM_Utils_Date
::customFormat(CRM_Utils_Array
::value('event_end_date', $this->_values
['event']));
1486 CRM_Core_Error
::statusBounce(ts('Registration for this event ended on %1', array(1 => $endDate)), $redirect, ts('Sorry'));
1491 * Get the amount level for the event payment.
1493 * The amount level is the string stored on the contribution record that describes the purchase.
1495 * @param array $params
1496 * @param int|null $discountID
1500 protected function getAmountLevel($params, $discountID) {
1501 // @todo move handling of discount ID to the BAO function - preferably by converting it to a price_set with
1503 if (!empty($this->_values
['discount'][$discountID])) {
1504 return $this->_values
['discount'][$discountID][$params['amount']]['label'];
1506 if (empty($params['priceSetId'])) {
1507 // CRM-17509 An example of this is where the person is being waitlisted & there is no payment.
1508 // ideally we would have calculated amount first & only call this is there is an
1509 // amount but the flow needs more changes for that.
1512 return CRM_Price_BAO_PriceSet
::getAmountLevelText($params);
1516 * Process Registration of free event.
1518 * @param array $params
1520 * @param int $contactID
1522 public function processRegistration($params, $contactID = NULL) {
1523 $session = CRM_Core_Session
::singleton();
1524 $this->_participantInfo
= array();
1526 // CRM-4320, lets build array of cancelled additional participant ids
1527 // those are drop or skip by primary at the time of confirmation.
1528 // get all in and then unset those are confirmed.
1529 $cancelledIds = $this->_additionalParticipantIds
;
1531 $participantCount = array();
1532 foreach ($params as $participantNum => $record) {
1533 if ($record == 'skip') {
1534 $participantCount[$participantNum] = 'skip';
1536 elseif ($participantNum) {
1537 $participantCount[$participantNum] = 'participant';
1541 $registerByID = NULL;
1542 foreach ($params as $key => $value) {
1543 if ($value != 'skip') {
1546 // setting register by Id and unset contactId.
1547 if (empty($value['is_primary'])) {
1549 $registerByID = $this->get('registerByID');
1550 if ($registerByID) {
1551 $value['registered_by_id'] = $registerByID;
1553 // get an email if one exists for the participant
1554 $participantEmail = '';
1555 foreach (array_keys($value) as $valueName) {
1556 if (substr($valueName, 0, 6) == 'email-') {
1557 $participantEmail = $value[$valueName];
1560 if ($participantEmail) {
1561 $this->_participantInfo
[] = $participantEmail;
1564 $this->_participantInfo
[] = $value['first_name'] . ' ' . $value['last_name'];
1567 elseif (!empty($value['contact_id'])) {
1568 $contactID = $value['contact_id'];
1571 $contactID = $this->getContactID();
1574 CRM_Event_Form_Registration_Confirm
::fixLocationFields($value, $fields, $this);
1575 //for free event or additional participant, dont create billing email address.
1576 if (empty($value['is_primary']) ||
!$this->_values
['event']['is_monetary']) {
1577 unset($value["email-{$this->_bltID}"]);
1580 $contactID = CRM_Event_Form_Registration_Confirm
::updateContactFields($contactID, $value, $fields, $this);
1582 // lets store the contactID in the session
1583 // we dont store in userID in case the user is doing multiple
1585 // for things like tell a friend
1586 if (!$this->getContactID() && !empty($value['is_primary'])) {
1587 $session->set('transaction.userID', $contactID);
1590 //lets get the status if require approval or waiting.
1592 $waitingStatuses = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Waiting'");
1593 if ($this->_allowWaitlist
&& !$this->_allowConfirmation
) {
1594 $value['participant_status_id'] = $value['participant_status'] = array_search('On waitlist', $waitingStatuses);
1596 elseif ($this->_requireApproval
&& !$this->_allowConfirmation
) {
1597 $value['participant_status_id'] = $value['participant_status'] = array_search('Awaiting approval', $waitingStatuses);
1600 $this->set('value', $value);
1601 $this->confirmPostProcess($contactID, NULL, NULL);
1603 //lets get additional participant id to cancel.
1604 if ($this->_allowConfirmation
&& is_array($cancelledIds)) {
1605 $additonalId = CRM_Utils_Array
::value('participant_id', $value);
1606 if ($additonalId && $key = array_search($additonalId, $cancelledIds)) {
1607 unset($cancelledIds[$key]);
1613 // update status and send mail to cancelled additional participants, CRM-4320
1614 if ($this->_allowConfirmation
&& is_array($cancelledIds) && !empty($cancelledIds)) {
1615 $cancelledId = array_search('Cancelled',
1616 CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Negative'")
1618 CRM_Event_BAO_Participant
::transitionParticipants($cancelledIds, $cancelledId);
1621 //set information about additional participants if exists
1622 if (count($this->_participantInfo
)) {
1623 $this->set('participantInfo', $this->_participantInfo
);
1626 //send mail Confirmation/Receipt
1627 if ($this->_contributeMode
!= 'checkout' ||
1628 $this->_contributeMode
!= 'notify'
1631 if ($this->_action
& CRM_Core_Action
::PREVIEW
) {
1635 //handle if no additional participant.
1636 if (!$registerByID) {
1637 $registerByID = $this->get('registerByID');
1639 $primaryContactId = $this->get('primaryContactId');
1641 //build an array of custom profile and assigning it to template.
1642 $additionalIDs = CRM_Event_BAO_Event
::buildCustomProfile($registerByID, NULL,
1643 $primaryContactId, $isTest, TRUE
1646 //lets carry all participant params w/ values.
1647 foreach ($additionalIDs as $participantID => $contactId) {
1648 $participantNum = NULL;
1649 if ($participantID == $registerByID) {
1650 $participantNum = 0;
1653 if ($participantNum = array_search('participant', $participantCount)) {
1654 unset($participantCount[$participantNum]);
1658 if ($participantNum === NULL) {
1662 //carry the participant submitted values.
1663 $this->_values
['params'][$participantID] = $params[$participantNum];
1666 //lets send mails to all with meanigful text, CRM-4320.
1667 $this->assign('isOnWaitlist', $this->_allowWaitlist
);
1668 $this->assign('isRequireApproval', $this->_requireApproval
);
1670 foreach ($additionalIDs as $participantID => $contactId) {
1671 if ($participantID == $registerByID) {
1672 //set as Primary Participant
1673 $this->assign('isPrimary', 1);
1675 $customProfile = CRM_Event_BAO_Event
::buildCustomProfile($participantID, $this->_values
, NULL, $isTest);
1677 if (count($customProfile)) {
1678 $this->assign('customProfile', $customProfile);
1679 $this->set('customProfile', $customProfile);
1683 $this->assign('isPrimary', 0);
1684 $this->assign('customProfile', NULL);
1687 //send Confirmation mail to Primary & additional Participants if exists
1688 CRM_Event_BAO_Event
::sendMail($contactId, $this->_values
, $participantID, $isTest);