3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 |
9 +--------------------------------------------------------------------+
14 * @copyright CiviCRM LLC https://civicrm.org/licensing
18 * This class generates form components for processing Event.
20 class CRM_Event_Form_Registration
extends CRM_Core_Form
{
21 use CRM_Financial_Form_FrontEndPaymentFormTrait
;
24 * How many locationBlocks should we display?
29 const LOCATION_BLOCKS
= 1;
32 * The id of the event we are proceessing.
39 * The array of ids of all the participant we are proceessing.
43 protected $_participantIDS = NULL;
46 * The id of the participant we are proceessing.
50 protected $_participantId;
53 * Is participant able to walk registration wizard.
57 public $_allowConfirmation;
60 * Is participant requires approval.
64 public $_requireApproval;
67 * Is event configured for waitlist.
71 public $_allowWaitlist;
74 * Store additional participant ids.
75 * when there are pre-registered.
79 public $_additionalParticipantIds;
82 * The mode that we are in.
90 * The values for the contribution db object.
97 * The paymentProcessor attributes for this page.
101 public $_paymentProcessor;
104 * The params submitted by the form and computed by the app.
111 * The fields involved in this contribution page.
118 * The billing location id for this contribiution page.
125 * Price Set ID, if the new price set method is used
129 public $_priceSetId = NULL;
132 * Array of fields for the price set.
143 * Is event already full.
150 public $_isEventFull;
153 public $_lineItemParticipantsCount;
154 public $_availableRegistrations;
160 public $_isBillingAddressRequiredForPayLater;
163 * Is this a back office form
167 public $isBackOffice = FALSE;
170 * Payment instrument iD for the transaction.
172 * This will generally be drawn from the payment processor and is ignored for
177 public $paymentInstrumentID;
180 * Set variables up before form is built.
182 public function preProcess() {
183 $this->_eventId
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, TRUE);
184 $this->_action
= CRM_Utils_Request
::retrieve('action', 'Alphanumeric', $this, FALSE, CRM_Core_Action
::ADD
);
187 $this->_participantId
= CRM_Utils_Request
::retrieve('participantId', 'Positive', $this);
190 $this->_mode
= ($this->_action
== 1024) ?
'test' : 'live';
192 $this->_values
= $this->get('values');
193 $this->_fields
= $this->get('fields');
194 $this->_bltID
= $this->get('bltID');
195 $this->_paymentProcessor
= $this->get('paymentProcessor');
196 $this->_priceSetId
= $this->get('priceSetId');
197 $this->_priceSet
= $this->get('priceSet');
198 $this->_lineItem
= $this->get('lineItem');
199 $this->_isEventFull
= $this->get('isEventFull');
200 $this->_lineItemParticipantsCount
= $this->get('lineItemParticipants');
201 if (!is_array($this->_lineItem
)) {
202 $this->_lineItem
= array();
204 if (!is_array($this->_lineItemParticipantsCount
)) {
205 $this->_lineItemParticipantsCount
= array();
207 $this->_availableRegistrations
= $this->get('availableRegistrations');
208 $this->_participantIDS
= $this->get('participantIDs');
210 //check if participant allow to walk registration wizard.
211 $this->_allowConfirmation
= $this->get('allowConfirmation');
213 // check for Approval
214 $this->_requireApproval
= $this->get('requireApproval');
216 // check for waitlisting.
217 $this->_allowWaitlist
= $this->get('allowWaitlist');
219 //get the additional participant ids.
220 $this->_additionalParticipantIds
= $this->get('additionalParticipantIds');
221 $config = CRM_Core_Config
::singleton();
223 if (!$this->_values
) {
224 // create redirect URL to send folks back to event info page is registration not available
225 $infoUrl = CRM_Utils_System
::url('civicrm/event/info', "reset=1&id={$this->_eventId}",
226 FALSE, NULL, FALSE, TRUE
229 // this is the first time we are hitting this, so check for permissions here
230 if (!CRM_Core_Permission
::event(CRM_Core_Permission
::EDIT
, $this->_eventId
, 'register for events')) {
231 CRM_Core_Error
::statusBounce(ts('You do not have permission to register for this event'), $infoUrl);
234 // get all the values from the dao object
235 $this->_values
= $this->_fields
= array();
237 //retrieve event information
238 $params = array('id' => $this->_eventId
);
239 CRM_Event_BAO_Event
::retrieve($params, $this->_values
['event']);
240 // check for is_monetary status
241 $isMonetary = CRM_Utils_Array
::value('is_monetary', $this->_values
['event']);
242 // check for ability to add contributions of type
244 && CRM_Financial_BAO_FinancialType
::isACLFinancialTypeStatus()
245 && !CRM_Core_Permission
::check('add contributions of type ' . CRM_Contribute_PseudoConstant
::financialType($this->_values
['event']['financial_type_id']))
247 CRM_Core_Error
::fatal(ts('You do not have permission to access this page.'));
250 $this->checkValidEvent($infoUrl);
251 // get the participant values, CRM-4320
252 $this->_allowConfirmation
= FALSE;
253 if ($this->_participantId
) {
254 $this->processFirstParticipant($this->_participantId
);
256 //check for additional participants.
257 if ($this->_allowConfirmation
&& $this->_values
['event']['is_multiple_registrations']) {
258 $additionalParticipantIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_participantId
);
260 foreach ($additionalParticipantIds as $additionalParticipantId) {
261 $this->_additionalParticipantIds
[$cnt] = $additionalParticipantId;
264 $this->set('additionalParticipantIds', $this->_additionalParticipantIds
);
267 $eventFull = CRM_Event_BAO_Participant
::eventFull($this->_eventId
, FALSE,
268 CRM_Utils_Array
::value('has_waitlist', $this->_values
['event'])
271 $this->_allowWaitlist
= $this->_isEventFull
= FALSE;
272 if ($eventFull && !$this->_allowConfirmation
) {
273 $this->_isEventFull
= TRUE;
274 //lets redirecting to info only when to waiting list.
275 $this->_allowWaitlist
= CRM_Utils_Array
::value('has_waitlist', $this->_values
['event']);
276 if (!$this->_allowWaitlist
) {
277 CRM_Utils_System
::redirect($infoUrl);
280 $this->set('isEventFull', $this->_isEventFull
);
281 $this->set('allowWaitlist', $this->_allowWaitlist
);
283 //check for require requires approval.
284 $this->_requireApproval
= FALSE;
285 if (!empty($this->_values
['event']['requires_approval']) && !$this->_allowConfirmation
) {
286 $this->_requireApproval
= TRUE;
288 $this->set('requireApproval', $this->_requireApproval
);
290 if (isset($this->_values
['event']['default_role_id'])) {
291 $participant_role = CRM_Core_OptionGroup
::values('participant_role');
292 $this->_values
['event']['participant_role'] = $participant_role["{$this->_values['event']['default_role_id']}"];
294 $isPayLater = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $this->_eventId
, 'is_pay_later');
295 $this->setPayLaterLabel($isPayLater ?
$this->_values
['event']['pay_later_text'] : '');
296 //check for various combinations for paylater, payment
297 //process with paid event.
298 if ($isMonetary && (!$isPayLater ||
!empty($this->_values
['event']['payment_processor']))) {
299 $this->_paymentProcessorIDs
= explode(CRM_Core_DAO
::VALUE_SEPARATOR
, CRM_Utils_Array
::value('payment_processor',
300 $this->_values
['event']
302 $this->assignPaymentProcessor($isPayLater);
305 self
::initEventFee($this, $this->_eventId
);
307 // get the profile ids
308 $ufJoinParams = array(
309 'entity_table' => 'civicrm_event',
310 // CRM-4377:Â CiviEvent for the main participant, CiviEvent_Additional for additional participants
311 'module' => 'CiviEvent',
312 'entity_id' => $this->_eventId
,
314 list($this->_values
['custom_pre_id'],
315 $this->_values
['custom_post_id']
316 ) = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
318 // set profiles for additional participants
319 if ($this->_values
['event']['is_multiple_registrations']) {
320 // CRM-4377:Â CiviEvent for the main participant, CiviEvent_Additional for additional participants
321 $ufJoinParams['module'] = 'CiviEvent_Additional';
323 list($this->_values
['additional_custom_pre_id'],
324 $this->_values
['additional_custom_post_id'], $preActive, $postActive
325 ) = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
327 // CRM-4377:Â we need to maintain backward compatibility, hence if there is profile for main contact
328 // set same profile for additional contacts.
329 if ($this->_values
['custom_pre_id'] && !$this->_values
['additional_custom_pre_id']) {
330 $this->_values
['additional_custom_pre_id'] = $this->_values
['custom_pre_id'];
333 if ($this->_values
['custom_post_id'] && !$this->_values
['additional_custom_post_id']) {
334 $this->_values
['additional_custom_post_id'] = $this->_values
['custom_post_id'];
336 // now check for no profile condition, in that case is_active = 0
337 if (isset($preActive) && !$preActive) {
338 unset($this->_values
['additional_custom_pre_id']);
340 if (isset($postActive) && !$postActive) {
341 unset($this->_values
['additional_custom_post_id']);
345 $this->assignBillingType();
347 if ($this->_values
['event']['is_monetary']) {
348 CRM_Core_Payment_Form
::setPaymentFieldsByProcessor($this, $this->_paymentProcessor
);
350 $params = array('entity_id' => $this->_eventId
, 'entity_table' => 'civicrm_event');
351 $this->_values
['location'] = CRM_Core_BAO_Location
::getValues($params, TRUE);
353 $this->set('values', $this->_values
);
354 $this->set('fields', $this->_fields
);
356 $this->_availableRegistrations
357 = CRM_Event_BAO_Participant
::eventFull(
358 $this->_values
['event']['id'], TRUE,
359 CRM_Utils_Array
::value('has_waitlist', $this->_values
['event'])
361 $this->set('availableRegistrations', $this->_availableRegistrations
);
363 $this->assign_by_ref('paymentProcessor', $this->_paymentProcessor
);
365 // check if this is a paypal auto return and redirect accordingly
366 if (CRM_Core_Payment
::paypalRedirect($this->_paymentProcessor
)) {
367 $url = CRM_Utils_System
::url('civicrm/event/register',
368 "_qf_ThankYou_display=1&qfKey={$this->controller->_key}"
370 CRM_Utils_System
::redirect($url);
372 // The concept of contributeMode is deprecated.
373 $this->_contributeMode
= $this->get('contributeMode');
374 $this->assign('contributeMode', $this->_contributeMode
);
376 $this->setTitle($this->_values
['event']['title']);
378 $this->assign('paidEvent', $this->_values
['event']['is_monetary']);
380 // we do not want to display recently viewed items on Registration pages
381 $this->assign('displayRecent', FALSE);
383 $isShowLocation = CRM_Utils_Array
::value('is_show_location', $this->_values
['event']);
384 $this->assign('isShowLocation', $isShowLocation);
386 $pcpId = CRM_Utils_Request
::retrieve('pcpId', 'Positive', $this);
388 $pcp = CRM_PCP_BAO_PCP
::handlePcp($pcpId, 'event', $this->_values
['event']);
389 $this->_pcpId
= $pcp['pcpId'];
390 $this->_values
['event']['intro_text'] = CRM_Utils_Array
::value('intro_text', $pcp['pcpInfo']);
393 // assign all event properties so wizard templates can display event info.
394 $this->assign('event', $this->_values
['event']);
395 $this->assign('location', $this->_values
['location']);
396 $this->assign('bltID', $this->_bltID
);
397 $isShowLocation = CRM_Utils_Array
::value('is_show_location', $this->_values
['event']);
398 $this->assign('isShowLocation', $isShowLocation);
399 CRM_Contribute_BAO_Contribution_Utils
::overrideDefaultCurrency($this->_values
['event']);
401 //lets allow user to override campaign.
402 $campID = CRM_Utils_Request
::retrieve('campID', 'Positive', $this);
403 if ($campID && CRM_Core_DAO
::getFieldValue('CRM_Campaign_DAO_Campaign', $campID)) {
404 $this->_values
['event']['campaign_id'] = $campID;
407 // Set the same value for is_billing_required as contribution page so code can be shared.
408 $this->_values
['is_billing_required'] = CRM_Utils_Array
::value('is_billing_required', $this->_values
['event']);
409 // check if billing block is required for pay later
410 // note that I have started removing the use of isBillingAddressRequiredForPayLater in favour of letting
411 // the CRM_Core_Payment_Manual class handle it - but there are ~300 references to it in the code base so only
412 // removing in very limited cases.
413 if (CRM_Utils_Array
::value('is_pay_later', $this->_values
['event'])) {
414 $this->_isBillingAddressRequiredForPayLater
= CRM_Utils_Array
::value('is_billing_required', $this->_values
['event']);
415 $this->assign('isBillingAddressRequiredForPayLater', $this->_isBillingAddressRequiredForPayLater
);
420 * Assign the minimal set of variables to the template.
422 public function assignToTemplate() {
423 //process only primary participant params
424 $this->_params
= $this->get('params');
425 if (isset($this->_params
[0])) {
426 $params = $this->_params
[0];
429 if (!empty($params['billing_first_name'])) {
430 $name = $params['billing_first_name'];
433 if (!empty($params['billing_middle_name'])) {
434 $name .= " {$params['billing_middle_name']}";
437 if (!empty($params['billing_last_name'])) {
438 $name .= " {$params['billing_last_name']}";
440 $this->assign('billingName', $name);
441 $this->set('name', $name);
452 foreach ($vars as $v) {
453 if (!empty($params[$v])) {
454 if ($v == 'receive_date') {
455 $this->assign($v, CRM_Utils_Date
::mysqlToIso($params[$v]));
458 $this->assign($v, $params[$v]);
461 elseif (empty($params['amount'])) {
462 $this->assign($v, CRM_Utils_Array
::value($v, $params));
466 $this->assign('address', CRM_Utils_Address
::getFormattedBillingAddressFieldsFromParameters($params, $this->_bltID
));
468 // The concept of contributeMode is deprecated.
469 if ($this->_contributeMode
== 'direct' && empty($params['is_pay_later'])) {
470 $date = CRM_Utils_Date
::format(CRM_Utils_Array
::value('credit_card_exp_date', $params));
471 $date = CRM_Utils_Date
::mysqlToIso($date);
472 $this->assign('credit_card_exp_date', $date);
473 $this->assign('credit_card_number',
474 CRM_Utils_System
::mungeCreditCard(CRM_Utils_Array
::value('credit_card_number', $params))
478 // get the email that the confirmation would have been sent to
479 $session = CRM_Core_Session
::singleton();
481 // assign is_email_confirm to templates
482 if (isset($this->_values
['event']['is_email_confirm'])) {
483 $this->assign('is_email_confirm', $this->_values
['event']['is_email_confirm']);
486 // assign pay later stuff
487 $params['is_pay_later'] = CRM_Utils_Array
::value('is_pay_later', $params, FALSE);
488 $this->assign('is_pay_later', $params['is_pay_later']);
489 if ($params['is_pay_later']) {
490 $this->assign('pay_later_text', $this->getPayLaterLabel());
491 $this->assign('pay_later_receipt', $this->_values
['event']['pay_later_receipt']);
494 // also assign all participantIDs to the template
495 // useful in generating confirmation numbers if needed
496 $this->assign('participantIDs', $this->_participantIDS
);
500 * Add the custom fields.
503 * @param string $name
504 * @param bool $viewOnly
506 public function buildCustom($id, $name, $viewOnly = FALSE) {
508 $button = substr($this->controller
->getButtonName(), -4);
509 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
510 $session = CRM_Core_Session
::singleton();
511 $contactID = $session->get('userID');
513 // we don't allow conflicting fields to be
514 // configured via profile
515 $fieldsToIgnore = array(
516 'participant_fee_amount' => 1,
517 'participant_fee_level' => 1,
523 foreach ($id as $profileID) {
524 $field = CRM_Core_BAO_UFGroup
::getFields($profileID, FALSE, CRM_Core_Action
::ADD
,
525 NULL, NULL, FALSE, NULL,
526 FALSE, NULL, CRM_Core_Permission
::CREATE
,
529 $fields = array_merge($fields, $field);
533 if (CRM_Core_BAO_UFGroup
::filterUFGroups($id, $contactID)) {
534 $fields = CRM_Core_BAO_UFGroup
::getFields($id, FALSE, CRM_Core_Action
::ADD
,
535 NULL, NULL, FALSE, NULL,
536 FALSE, NULL, CRM_Core_Permission
::CREATE
,
543 $fields = CRM_Core_BAO_UFGroup
::getFields($id, FALSE, CRM_Core_Action
::ADD
,
544 NULL, NULL, FALSE, NULL,
545 FALSE, NULL, CRM_Core_Permission
::CREATE
,
550 if (array_intersect_key($fields, $fieldsToIgnore)) {
551 $fields = array_diff_key($fields, $fieldsToIgnore);
552 CRM_Core_Session
::setStatus(ts('Some of the profile fields cannot be configured for this page.'));
556 if (!empty($this->_fields
)) {
557 $fields = @array_diff_assoc
($fields, $this->_fields
);
560 if (empty($this->_params
[0]['additional_participants']) &&
563 CRM_Core_BAO_Address
::checkContactSharedAddressFields($fields, $contactID);
565 $this->assign($name, $fields);
566 if (is_array($fields)) {
567 foreach ($fields as $key => $field) {
569 isset($field['data_type']) &&
570 $field['data_type'] == 'File' ||
($viewOnly && $field['name'] == 'image_URL')
572 // ignore file upload fields
575 //make the field optional if primary participant
576 //have been skip the additional participant.
577 if ($button == 'skip') {
578 $field['is_required'] = FALSE;
580 // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
581 elseif ($field['add_captcha'] && !$contactID) {
582 // only add captcha for first page
585 list($prefixName, $index) = CRM_Utils_System
::explode('-', $key, 2);
586 CRM_Core_BAO_UFGroup
::buildProfile($this, $field, CRM_Profile_Form
::MODE_CREATE
, $contactID, TRUE);
588 $this->_fields
[$key] = $field;
592 if ($addCaptcha && !$viewOnly) {
593 CRM_Utils_ReCAPTCHA
::enableCaptchaOnForm($this);
599 * Initiate event fee.
601 * @param CRM_Core_Form $form
602 * @param int $eventID
606 public static function initEventFee(&$form, $eventID) {
609 // retrive all active price set fields.
610 $discountId = CRM_Core_BAO_Discount
::findSet($eventID, 'civicrm_event');
611 if (property_exists($form, '_discountId') && $form->_discountId
) {
612 $discountId = $form->_discountId
;
615 //CRM-16456 get all price field including expired one.
616 $getAllPriceField = TRUE;
617 $className = CRM_Utils_System
::getClassName($form);
618 if ($className == 'CRM_Event_Form_ParticipantFeeSelection' && $form->_action
== CRM_Core_Action
::UPDATE
) {
619 $getAllPriceField = FALSE;
623 $priceSetId = CRM_Core_DAO
::getFieldValue('CRM_Core_BAO_Discount', $discountId, 'price_set_id');
624 $price = CRM_Price_BAO_PriceSet
::initSet($form, $eventID, 'civicrm_event', $getAllPriceField, $priceSetId);
627 $price = CRM_Price_BAO_PriceSet
::initSet($form, $eventID, 'civicrm_event', $getAllPriceField);
630 if (property_exists($form, '_context') && ($form->_context
== 'standalone'
631 ||
$form->_context
== 'participant')
633 $discountedEvent = CRM_Core_BAO_Discount
::getOptionGroup($eventID, 'civicrm_event');
634 if (is_array($discountedEvent)) {
635 foreach ($discountedEvent as $key => $priceSetId) {
636 $priceSet = CRM_Price_BAO_PriceSet
::getSetDetail($priceSetId);
637 $priceSet = CRM_Utils_Array
::value($priceSetId, $priceSet);
638 $form->_values
['discount'][$key] = CRM_Utils_Array
::value('fields', $priceSet);
639 $fieldID = key($form->_values
['discount'][$key]);
640 $form->_values
['discount'][$key][$fieldID]['name'] = CRM_Core_DAO
::getFieldValue(
641 'CRM_Price_DAO_PriceSet',
648 $eventFee = CRM_Utils_Array
::value('fee', $form->_values
);
649 if (!is_array($eventFee) ||
empty($eventFee)) {
650 $form->_values
['fee'] = array();
653 //fix for non-upgraded price sets.CRM-4256.
654 if (isset($form->_isPaidEvent
)) {
655 $isPaidEvent = $form->_isPaidEvent
;
658 $isPaidEvent = CRM_Utils_Array
::value('is_monetary', $form->_values
['event']);
660 if (CRM_Financial_BAO_FinancialType
::isACLFinancialTypeStatus()
661 && !empty($form->_values
['fee'])
663 foreach ($form->_values
['fee'] as $k => $fees) {
664 foreach ($fees['options'] as $options) {
665 if (!CRM_Core_Permission
::check('add contributions of type ' . CRM_Contribute_PseudoConstant
::financialType($options['financial_type_id']))) {
666 unset($form->_values
['fee'][$k]);
671 if ($isPaidEvent && empty($form->_values
['fee'])) {
672 if (CRM_Utils_System
::getClassName($form) != 'CRM_Event_Form_Participant') {
673 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
))));
679 * Handle process after the confirmation of payment by User.
681 * @param int $contactID
682 * @param \CRM_Contribute_BAO_Contribution $contribution
684 * @throws \CiviCRM_API3_Exception
686 public function confirmPostProcess($contactID = NULL, $contribution = NULL) {
687 // add/update contact information
688 unset($this->_params
['note']);
690 //to avoid conflict overwrite $this->_params
691 $this->_params
= $this->get('value');
693 //get the amount of primary participant
694 if (!empty($this->_params
['is_primary'])) {
695 $this->_params
['fee_amount'] = $this->get('primaryParticipantAmount');
698 // add participant record
699 $participant = CRM_Event_Form_Registration
::addParticipant($this, $contactID);
700 $this->_participantIDS
[] = $participant->id
;
702 //setting register_by_id field and primaryContactId
703 if (!empty($this->_params
['is_primary'])) {
704 $this->set('registerByID', $participant->id
);
705 $this->set('primaryContactId', $contactID);
708 $this->processFirstParticipant($participant->id
);
710 $this->_params
['participantID'] = $participant->id
;
711 $this->set('primaryParticipant', $this->_params
);
713 CRM_Core_BAO_CustomValueTable
::postProcess($this->_params
,
714 'civicrm_participant',
719 $createPayment = (CRM_Utils_Array
::value('amount', $this->_params
, 0) != 0) ?
TRUE : FALSE;
721 // force to create zero amount payment, CRM-5095
722 // we know the amout is zero since createPayment is false
723 if (!$createPayment &&
724 (isset($contribution) && $contribution->id
) &&
725 $this->_priceSetId
&&
728 $createPayment = TRUE;
731 if ($createPayment && $this->_values
['event']['is_monetary'] && !empty($this->_params
['contributionID'])) {
733 'participant_id' => $participant->id
,
734 'contribution_id' => $contribution->id
,
736 civicrm_api3('ParticipantPayment', 'create', $paymentParams);
739 $this->assign('action', $this->_action
);
742 if (!empty($this->_params
['cms_create_account'])) {
743 $this->_params
['contactID'] = $contactID;
745 if (array_key_exists('email-5', $this->_params
)) {
749 foreach ($this->_params
as $name => $dontCare) {
750 if (substr($name, 0, 5) == 'email') {
757 // we should use primary email for
758 // 1. pay later participant.
759 // 2. waiting list participant.
760 // 3. require approval participant.
761 if (!empty($this->_params
['is_pay_later']) ||
762 $this->_allowWaitlist ||
$this->_requireApproval
764 $mail = 'email-Primary';
767 if (!CRM_Core_BAO_CMSUser
::create($this->_params
, $mail)) {
768 CRM_Core_Error
::statusBounce(ts('Your profile is not saved and Account is not created.'));
774 * Process the participant.
776 * @param CRM_Core_Form $form
777 * @param int $contactID
779 * @return \CRM_Event_BAO_Participant
780 * @throws \CiviCRM_API3_Exception
782 public static function addParticipant(&$form, $contactID) {
783 if (empty($form->_params
)) {
786 $params = $form->_params
;
787 $transaction = new CRM_Core_Transaction();
789 // handle register date CRM-4320
790 $registerDate = NULL;
791 if (!empty($form->_allowConfirmation
) && $form->_participantId
) {
792 $registerDate = $params['participant_register_date'];
794 elseif (!empty($params['participant_register_date']) &&
795 is_array($params['participant_register_date']) &&
796 !empty($params['participant_register_date'])
798 $registerDate = CRM_Utils_Date
::format($params['participant_register_date']);
801 $participantFields = CRM_Event_DAO_Participant
::fields();
802 $participantParams = array(
803 'id' => CRM_Utils_Array
::value('participant_id', $params),
804 'contact_id' => $contactID,
805 'event_id' => $form->_eventId ?
$form->_eventId
: $params['event_id'],
806 'status_id' => CRM_Utils_Array
::value('participant_status',
809 'role_id' => CRM_Utils_Array
::value('participant_role_id', $params) ?
: self
::getDefaultRoleID(),
810 'register_date' => ($registerDate) ?
$registerDate : date('YmdHis'),
811 'source' => CRM_Utils_String
::ellipsify(
812 isset($params['participant_source']) ? CRM_Utils_Array
::value('participant_source', $params) : CRM_Utils_Array
::value('description', $params),
813 $participantFields['participant_source']['maxlength']
815 'fee_level' => CRM_Utils_Array
::value('amount_level', $params),
816 'is_pay_later' => CRM_Utils_Array
::value('is_pay_later', $params, 0),
817 'fee_amount' => CRM_Utils_Array
::value('fee_amount', $params),
818 'registered_by_id' => CRM_Utils_Array
::value('registered_by_id', $params),
819 'discount_id' => CRM_Utils_Array
::value('discount_id', $params),
820 'fee_currency' => CRM_Utils_Array
::value('currencyID', $params),
821 'campaign_id' => CRM_Utils_Array
::value('campaign_id', $params),
824 if ($form->_action
& CRM_Core_Action
::PREVIEW || CRM_Utils_Array
::value('mode', $params) == 'test') {
825 $participantParams['is_test'] = 1;
828 $participantParams['is_test'] = 0;
831 if (!empty($form->_params
['note'])) {
832 $participantParams['note'] = $form->_params
['note'];
834 elseif (!empty($form->_params
['participant_note'])) {
835 $participantParams['note'] = $form->_params
['participant_note'];
838 // reuse id if one already exists for this one (can happen
839 // with back button being hit etc)
840 if (!$participantParams['id'] && !empty($params['contributionID'])) {
841 $pID = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
842 $params['contributionID'],
846 $participantParams['id'] = $pID;
848 $participantParams['discount_id'] = CRM_Core_BAO_Discount
::findSet($form->_eventId
, 'civicrm_event');
850 if (!$participantParams['discount_id']) {
851 $participantParams['discount_id'] = "null";
854 $participant = CRM_Event_BAO_Participant
::create($participantParams);
856 $transaction->commit();
862 * Get the ID of the default (first) participant role
865 * @throws \CiviCRM_API3_Exception
867 private static function getDefaultRoleID() {
868 return (int) civicrm_api3('OptionValue', 'getvalue', [
870 'option_group_id' => "participant_role",
872 'options' => ['limit' => 1, 'sort' => "is_default DESC"],
877 * Calculate the total participant count as per params.
879 * @param CRM_Core_Form $form
880 * @param array $params
882 * @param bool $skipCurrent
886 public static function getParticipantCount(&$form, $params, $skipCurrent = FALSE) {
888 if (!is_array($params) ||
empty($params)) {
892 $priceSetId = $form->get('priceSetId');
893 $addParticipantNum = substr($form->_name
, 12);
894 $priceSetFields = $priceSetDetails = array();
895 $hasPriceFieldsCount = FALSE;
897 $priceSetDetails = $form->get('priceSet');
898 if (isset($priceSetDetails['optionsCountTotal'])
899 && $priceSetDetails['optionsCountTotal']
901 $hasPriceFieldsCount = TRUE;
902 $priceSetFields = $priceSetDetails['optionsCountDetails']['fields'];
906 $singleFormParams = FALSE;
907 foreach ($params as $key => $val) {
908 if (!is_numeric($key)) {
909 $singleFormParams = TRUE;
914 //first format the params.
915 if ($singleFormParams) {
916 $params = self
::formatPriceSetParams($form, $params);
917 $params = array($params);
920 foreach ($params as $key => $values) {
921 if (!is_numeric($key) ||
923 ($skipCurrent && ($addParticipantNum == $key))
930 $cacheCount = CRM_Utils_Array
::value($key, $form->_lineItemParticipantsCount
);
931 if ($cacheCount && is_numeric($cacheCount)) {
932 $count = $cacheCount;
936 if (!$usedCache && $hasPriceFieldsCount) {
938 foreach ($values as $valKey => $value) {
939 if (strpos($valKey, 'price_') === FALSE) {
942 $priceFieldId = substr($valKey, 6);
943 if (!$priceFieldId ||
945 !array_key_exists($priceFieldId, $priceSetFields)
949 foreach ($value as $optId => $optVal) {
950 $currentCount = $priceSetFields[$priceFieldId]['options'][$optId] * $optVal;
952 $count +
= $currentCount;
960 $totalCount +
= $count;
970 * Format user submitted price set params.
972 * Convert price set each param as an array.
974 * @param CRM_Core_Form $form
975 * @param array $params
976 * An array of user submitted params.
979 * Formatted price set params.
981 public static function formatPriceSetParams(&$form, $params) {
982 if (!is_array($params) ||
empty($params)) {
986 $priceSetId = $form->get('priceSetId');
990 $priceSetDetails = $form->get('priceSet');
992 foreach ($params as $key => & $value) {
994 if (strpos($key, 'price_') !== FALSE) {
995 $fieldId = substr($key, 6);
996 if (!array_key_exists($fieldId, $priceSetDetails['fields']) ||
1002 $field = $priceSetDetails['fields'][$fieldId];
1003 if ($field['html_type'] == 'Text') {
1004 $fieldOption = current($field['options']);
1005 $value = array($fieldOption['id'] => $value);
1008 $value = array($value => TRUE);
1017 * Calculate total count for each price set options.
1019 * - currently selected by user.
1021 * @param CRM_Core_Form $form
1025 * array of each option w/ count total.
1027 public static function getPriceSetOptionCount(&$form) {
1028 $params = $form->get('params');
1029 $priceSet = $form->get('priceSet');
1030 $priceSetId = $form->get('priceSetId');
1032 $optionsCount = array();
1034 !is_array($priceSet) ||
1036 !is_array($params) ||
1039 return $optionsCount;
1042 $priceSetFields = $priceMaxFieldDetails = array();
1043 if (!empty($priceSet['optionsCountTotal'])) {
1044 $priceSetFields = $priceSet['optionsCountDetails']['fields'];
1047 if (!empty($priceSet['optionsMaxValueTotal'])) {
1048 $priceMaxFieldDetails = $priceSet['optionsMaxValueDetails']['fields'];
1051 $addParticipantNum = substr($form->_name
, 12);
1052 foreach ($params as $pCnt => $values) {
1053 if ($values == 'skip' ||
1054 $pCnt === $addParticipantNum
1059 foreach ($values as $valKey => $value) {
1060 if (strpos($valKey, 'price_') === FALSE) {
1064 $priceFieldId = substr($valKey, 6);
1065 if (!$priceFieldId ||
1066 !is_array($value) ||
1067 !(array_key_exists($priceFieldId, $priceSetFields) ||
array_key_exists($priceFieldId, $priceMaxFieldDetails))
1072 foreach ($value as $optId => $optVal) {
1073 if (CRM_Utils_Array
::value('html_type', $priceSet['fields'][$priceFieldId]) == 'Text') {
1074 $currentCount = $optVal;
1080 if (isset($priceSetFields[$priceFieldId]) && isset($priceSetFields[$priceFieldId]['options'][$optId])) {
1081 $currentCount = $priceSetFields[$priceFieldId]['options'][$optId] * $optVal;
1084 $optionsCount[$optId] = $currentCount + CRM_Utils_Array
::value($optId, $optionsCount, 0);
1089 return $optionsCount;
1093 * Check if template file exists.
1095 * @param string $suffix
1097 * @return null|string
1099 public function checkTemplateFileExists($suffix = '') {
1100 if ($this->_eventId
) {
1101 $templateName = $this->_name
;
1102 if (substr($templateName, 0, 12) == 'Participant_') {
1103 $templateName = 'AdditionalParticipant';
1106 $templateFile = "CRM/Event/Form/Registration/{$this->_eventId}/{$templateName}.{$suffix}tpl";
1107 $template = CRM_Core_Form
::getTemplate();
1108 if ($template->template_exists($templateFile)) {
1109 return $templateFile;
1116 * Get template file name.
1118 * @return null|string
1120 public function getTemplateFileName() {
1121 $fileName = $this->checkTemplateFileExists();
1122 return $fileName ?
$fileName : parent
::getTemplateFileName();
1126 * Override extra template name.
1128 * @return null|string
1130 public function overrideExtraTemplateFileName() {
1131 $fileName = $this->checkTemplateFileExists('extra.');
1132 return $fileName ?
$fileName : parent
::overrideExtraTemplateFileName();
1136 * Reset values for all options those are full.
1138 * @param array $optionFullIds
1139 * @param CRM_Core_Form $form
1141 public static function resetElementValue($optionFullIds = array(), &$form) {
1142 if (!is_array($optionFullIds) ||
1143 empty($optionFullIds) ||
1144 !$form->isSubmitted()
1149 foreach ($optionFullIds as $fldId => $optIds) {
1150 $name = "price_$fldId";
1151 if (!$form->elementExists($name)) {
1155 $element = $form->getElement($name);
1156 $eleType = $element->getType();
1158 $resetSubmitted = FALSE;
1161 if ($element->getValue() && $element->isFrozen()) {
1162 $label = "{$element->getLabel()}<tt>(x)</tt>";
1163 $element->setLabel($label);
1164 $element->setPersistantFreeze();
1165 $resetSubmitted = TRUE;
1170 if (is_array($element->_elements
)) {
1171 foreach ($element->_elements
as $child) {
1172 $childType = $child->getType();
1173 $methodName = 'getName';
1175 $methodName = 'getValue';
1177 if (in_array($child->{$methodName}(), $optIds) && $child->isFrozen()) {
1178 $resetSubmitted = TRUE;
1179 $child->setPersistantFreeze();
1186 $value = $element->getValue();
1187 if (in_array($value[0], $optIds)) {
1188 foreach ($element->_options
as $option) {
1189 if ($option['attr']['value'] === "crm_disabled_opt-{$value[0]}") {
1190 $placeholder = html_entity_decode($option['text'], ENT_QUOTES
, "UTF-8");
1191 $element->updateAttributes(array('placeholder' => $placeholder));
1195 $resetSubmitted = TRUE;
1200 //finally unset values from submitted.
1201 if ($resetSubmitted) {
1202 self
::resetSubmittedValue($name, $optIds, $form);
1208 * Reset submitted value.
1210 * @param string $elementName
1211 * @param array $optionIds
1212 * @param CRM_Core_Form $form
1214 public static function resetSubmittedValue($elementName, $optionIds = array(), &$form) {
1215 if (empty($elementName) ||
1216 !$form->elementExists($elementName) ||
1217 !$form->getSubmitValue($elementName)
1226 $values = $form->{"_$val"};
1227 if (!is_array($values) ||
empty($values)) {
1230 $eleVal = CRM_Utils_Array
::value($elementName, $values);
1231 if (empty($eleVal)) {
1234 if (is_array($eleVal)) {
1236 foreach ($eleVal as $keyId => $ignore) {
1237 if (in_array($keyId, $optionIds)) {
1239 unset($values[$elementName][$keyId]);
1242 if ($found && empty($values[$elementName][$keyId])) {
1243 $values[$elementName][$keyId] = NULL;
1247 if (!empty($keyId)) {
1248 $values[$elementName][$keyId] = NULL;
1255 * Validate price set submitted params for price option limit.
1257 * User should select at least one price field option.
1259 * @param CRM_Core_Form $form
1260 * @param array $params
1264 public static function validatePriceSet(&$form, $params) {
1266 $hasOptMaxValue = FALSE;
1267 if (!is_array($params) ||
empty($params)) {
1271 $currentParticipantNum = substr($form->_name
, 12);
1272 if (!$currentParticipantNum) {
1273 $currentParticipantNum = 0;
1276 $priceSetId = $form->get('priceSetId');
1277 $priceSetDetails = $form->get('priceSet');
1280 !is_array($priceSetDetails) ||
1281 empty($priceSetDetails)
1286 $optionsCountDetails = $optionsMaxValueDetails = array();
1288 isset($priceSetDetails['optionsMaxValueTotal'])
1289 && $priceSetDetails['optionsMaxValueTotal']
1291 $hasOptMaxValue = TRUE;
1292 $optionsMaxValueDetails = $priceSetDetails['optionsMaxValueDetails']['fields'];
1295 isset($priceSetDetails['optionsCountTotal'])
1296 && $priceSetDetails['optionsCountTotal']
1298 $hasOptCount = TRUE;
1299 $optionsCountDetails = $priceSetDetails['optionsCountDetails']['fields'];
1301 $feeBlock = $form->_feeBlock
;
1303 if (empty($feeBlock)) {
1304 $feeBlock = $priceSetDetails['fields'];
1307 $optionMaxValues = $fieldSelected = array();
1308 foreach ($params as $pNum => $values) {
1309 if (!is_array($values) ||
$values == 'skip') {
1313 foreach ($values as $valKey => $value) {
1314 if (strpos($valKey, 'price_') === FALSE) {
1317 $priceFieldId = substr($valKey, 6);
1318 $noneOptionValueSelected = FALSE;
1319 if (!$feeBlock[$priceFieldId]['is_required'] && $value == 0) {
1320 $noneOptionValueSelected = TRUE;
1325 (!$noneOptionValueSelected && !is_array($value))
1330 $fieldSelected[$pNum] = TRUE;
1332 if (!$hasOptMaxValue ||
!is_array($value)) {
1336 foreach ($value as $optId => $optVal) {
1337 if (CRM_Utils_Array
::value('html_type', $feeBlock[$priceFieldId]) == 'Text') {
1338 $currentMaxValue = $optVal;
1341 $currentMaxValue = 1;
1344 if (isset($optionsCountDetails[$priceFieldId]) && isset($optionsCountDetails[$priceFieldId]['options'][$optId])) {
1345 $currentMaxValue = $optionsCountDetails[$priceFieldId]['options'][$optId] * $optVal;
1347 if (empty($optionMaxValues)) {
1348 $optionMaxValues[$priceFieldId][$optId] = $currentMaxValue;
1351 $optionMaxValues[$priceFieldId][$optId]
1352 = $currentMaxValue + CRM_Utils_Array
::value($optId, CRM_Utils_Array
::value($priceFieldId, $optionMaxValues), 0);
1354 $soldOutPnum[$optId] = $pNum;
1358 //validate for price field selection.
1359 if (empty($fieldSelected[$pNum])) {
1360 $errors[$pNum]['_qf_default'] = ts('Select at least one option from Event Fee(s).');
1364 //validate for option max value.
1365 foreach ($optionMaxValues as $fieldId => $values) {
1366 $options = CRM_Utils_Array
::value('options', $feeBlock[$fieldId], array());
1367 foreach ($values as $optId => $total) {
1368 $optMax = $optionsMaxValueDetails[$fieldId]['options'][$optId];
1369 $opDbCount = CRM_Utils_Array
::value('db_total_count', $options[$optId], 0);
1370 $total +
= $opDbCount;
1371 if ($optMax && ($total > $optMax)) {
1372 if ($opDbCount && ($opDbCount >= $optMax)) {
1373 $errors[$soldOutPnum[$optId]]["price_{$fieldId}"]
1374 = ts('Sorry, this option is currently sold out.');
1376 elseif (($optMax - $opDbCount) == 1) {
1377 $errors[$soldOutPnum[$optId]]["price_{$fieldId}"]
1378 = ts('Sorry, currently only a single space is available for this option.', array(1 => ($optMax - $opDbCount)));
1381 $errors[$soldOutPnum[$optId]]["price_{$fieldId}"]
1382 = ts('Sorry, currently only %1 spaces are available for this option.', array(1 => ($optMax - $opDbCount)));
1391 * Set the first participant ID if not set.
1395 * @param int $participantID
1397 public function processFirstParticipant($participantID) {
1398 $this->_participantId
= $participantID;
1399 $this->set('participantId', $this->_participantId
);
1401 $ids = $participantValues = array();
1402 $participantParams = array('id' => $this->_participantId
);
1403 CRM_Event_BAO_Participant
::getValues($participantParams, $participantValues, $ids);
1404 $this->_values
['participant'] = $participantValues[$this->_participantId
];
1405 $this->set('values', $this->_values
);
1407 // also set the allow confirmation stuff
1408 if (array_key_exists(
1409 $this->_values
['participant']['status_id'],
1410 CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Pending'")
1412 $this->_allowConfirmation
= TRUE;
1413 $this->set('allowConfirmation', TRUE);
1418 * Check if event is valid.
1420 * @todo - combine this with CRM_Event_BAO_Event::validRegistrationRequest
1421 * (probably extract relevant values here & call that with them & handle bounces & redirects here -as
1422 * those belong in the form layer)
1424 * @param string $redirect
1426 public function checkValidEvent($redirect = NULL) {
1427 // is the event active (enabled)?
1428 if (!$this->_values
['event']['is_active']) {
1429 // form is inactive, die a fatal death
1430 CRM_Core_Error
::statusBounce(ts('The event you requested is currently unavailable (contact the site administrator for assistance).'));
1433 // is online registration is enabled?
1434 if (!$this->_values
['event']['is_online_registration']) {
1435 CRM_Core_Error
::statusBounce(ts('Online registration is not currently available for this event (contact the site administrator for assistance).'), $redirect);
1438 // is this an event template ?
1439 if (!empty($this->_values
['event']['is_template'])) {
1440 CRM_Core_Error
::statusBounce(ts('Event templates are not meant to be registered.'), $redirect);
1443 $now = date('YmdHis');
1444 $startDate = CRM_Utils_Date
::processDate(CRM_Utils_Array
::value('registration_start_date',
1445 $this->_values
['event']
1452 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'));
1455 $regEndDate = CRM_Utils_Date
::processDate(CRM_Utils_Array
::value('registration_end_date',
1456 $this->_values
['event']
1458 $eventEndDate = CRM_Utils_Date
::processDate(CRM_Utils_Array
::value('event_end_date', $this->_values
['event']));
1459 if (($regEndDate && ($regEndDate < $now)) ||
(empty($regEndDate) && !empty($eventEndDate) && ($eventEndDate < $now))) {
1460 $endDate = CRM_Utils_Date
::customFormat(CRM_Utils_Array
::value('registration_end_date', $this->_values
['event']));
1461 if (empty($regEndDate)) {
1462 $endDate = CRM_Utils_Date
::customFormat(CRM_Utils_Array
::value('event_end_date', $this->_values
['event']));
1464 CRM_Core_Error
::statusBounce(ts('Registration for this event ended on %1', array(1 => $endDate)), $redirect, ts('Sorry'));
1469 * Get the amount level for the event payment.
1471 * The amount level is the string stored on the contribution record that describes the purchase.
1473 * @param array $params
1474 * @param int|null $discountID
1478 protected function getAmountLevel($params, $discountID) {
1479 // @todo move handling of discount ID to the BAO function - preferably by converting it to a price_set with
1481 if (!empty($this->_values
['discount'][$discountID])) {
1482 return $this->_values
['discount'][$discountID][$params['amount']]['label'];
1484 if (empty($params['priceSetId'])) {
1485 // CRM-17509 An example of this is where the person is being waitlisted & there is no payment.
1486 // ideally we would have calculated amount first & only call this is there is an
1487 // amount but the flow needs more changes for that.
1490 return CRM_Price_BAO_PriceSet
::getAmountLevelText($params);
1494 * Process Registration of free event.
1496 * @param array $params
1498 * @param int $contactID
1500 * @throws \CiviCRM_API3_Exception
1502 public function processRegistration($params, $contactID = NULL) {
1503 $session = CRM_Core_Session
::singleton();
1504 $this->_participantInfo
= array();
1506 // CRM-4320, lets build array of cancelled additional participant ids
1507 // those are drop or skip by primary at the time of confirmation.
1508 // get all in and then unset those are confirmed.
1509 $cancelledIds = $this->_additionalParticipantIds
;
1511 $participantCount = array();
1512 foreach ($params as $participantNum => $record) {
1513 if ($record == 'skip') {
1514 $participantCount[$participantNum] = 'skip';
1516 elseif ($participantNum) {
1517 $participantCount[$participantNum] = 'participant';
1521 $registerByID = NULL;
1522 foreach ($params as $key => $value) {
1523 if ($value != 'skip') {
1526 // setting register by Id and unset contactId.
1527 if (empty($value['is_primary'])) {
1529 $registerByID = $this->get('registerByID');
1530 if ($registerByID) {
1531 $value['registered_by_id'] = $registerByID;
1533 // get an email if one exists for the participant
1534 $participantEmail = '';
1535 foreach (array_keys($value) as $valueName) {
1536 if (substr($valueName, 0, 6) == 'email-') {
1537 $participantEmail = $value[$valueName];
1540 if ($participantEmail) {
1541 $this->_participantInfo
[] = $participantEmail;
1544 $this->_participantInfo
[] = $value['first_name'] . ' ' . $value['last_name'];
1547 elseif (!empty($value['contact_id'])) {
1548 $contactID = $value['contact_id'];
1551 $contactID = $this->getContactID();
1554 CRM_Event_Form_Registration_Confirm
::fixLocationFields($value, $fields, $this);
1555 //for free event or additional participant, dont create billing email address.
1556 if (empty($value['is_primary']) ||
!$this->_values
['event']['is_monetary']) {
1557 unset($value["email-{$this->_bltID}"]);
1560 $contactID = CRM_Event_Form_Registration_Confirm
::updateContactFields($contactID, $value, $fields, $this);
1562 // lets store the contactID in the session
1563 // we dont store in userID in case the user is doing multiple
1565 // for things like tell a friend
1566 if (!$this->getContactID() && !empty($value['is_primary'])) {
1567 $session->set('transaction.userID', $contactID);
1570 //lets get the status if require approval or waiting.
1572 $waitingStatuses = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Waiting'");
1573 if ($this->_allowWaitlist
&& !$this->_allowConfirmation
) {
1574 $value['participant_status_id'] = $value['participant_status'] = array_search('On waitlist', $waitingStatuses);
1576 elseif ($this->_requireApproval
&& !$this->_allowConfirmation
) {
1577 $value['participant_status_id'] = $value['participant_status'] = array_search('Awaiting approval', $waitingStatuses);
1580 $this->set('value', $value);
1581 $this->confirmPostProcess($contactID, NULL);
1583 //lets get additional participant id to cancel.
1584 if ($this->_allowConfirmation
&& is_array($cancelledIds)) {
1585 $additonalId = CRM_Utils_Array
::value('participant_id', $value);
1586 if ($additonalId && $key = array_search($additonalId, $cancelledIds)) {
1587 unset($cancelledIds[$key]);
1593 // update status and send mail to cancelled additional participants, CRM-4320
1594 if ($this->_allowConfirmation
&& is_array($cancelledIds) && !empty($cancelledIds)) {
1595 $cancelledId = array_search('Cancelled',
1596 CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Negative'")
1598 CRM_Event_BAO_Participant
::transitionParticipants($cancelledIds, $cancelledId);
1601 //set information about additional participants if exists
1602 if (count($this->_participantInfo
)) {
1603 $this->set('participantInfo', $this->_participantInfo
);
1606 //send mail Confirmation/Receipt
1607 if ($this->_contributeMode
!= 'checkout' ||
1608 $this->_contributeMode
!= 'notify'
1610 $this->sendMails($params, $registerByID, $participantCount);
1615 * Send Mail to participants.
1618 * @param $registerByID
1619 * @param array $participantCount
1621 * @throws \CiviCRM_API3_Exception
1623 private function sendMails($params, $registerByID, array $participantCount) {
1625 if ($this->_action
& CRM_Core_Action
::PREVIEW
) {
1629 //handle if no additional participant.
1630 if (!$registerByID) {
1631 $registerByID = $this->get('registerByID');
1633 $primaryContactId = $this->get('primaryContactId');
1635 //build an array of custom profile and assigning it to template.
1636 $additionalIDs = CRM_Event_BAO_Event
::buildCustomProfile($registerByID, NULL,
1637 $primaryContactId, $isTest, TRUE
1640 //lets carry all participant params w/ values.
1641 foreach ($additionalIDs as $participantID => $contactId) {
1642 $participantNum = NULL;
1643 if ($participantID == $registerByID) {
1644 $participantNum = 0;
1647 if ($participantNum = array_search('participant', $participantCount)) {
1648 unset($participantCount[$participantNum]);
1652 if ($participantNum === NULL) {
1656 //carry the participant submitted values.
1657 $this->_values
['params'][$participantID] = $params[$participantNum];
1660 //lets send mails to all with meanigful text, CRM-4320.
1661 $this->assign('isOnWaitlist', $this->_allowWaitlist
);
1662 $this->assign('isRequireApproval', $this->_requireApproval
);
1664 foreach ($additionalIDs as $participantID => $contactId) {
1665 if ($participantID == $registerByID) {
1666 //set as Primary Participant
1667 $this->assign('isPrimary', 1);
1669 $customProfile = CRM_Event_BAO_Event
::buildCustomProfile($participantID, $this->_values
, NULL, $isTest);
1671 if (count($customProfile)) {
1672 $this->assign('customProfile', $customProfile);
1673 $this->set('customProfile', $customProfile);
1677 $this->assign('isPrimary', 0);
1678 $this->assign('customProfile', NULL);
1681 //send Confirmation mail to Primary & additional Participants if exists
1682 CRM_Event_BAO_Event
::sendMail($contactId, $this->_values
, $participantID, $isTest);