3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
32 * @copyright CiviCRM LLC (c) 2004-2014
38 * This class generates form components for processing Event
41 class CRM_Event_Form_Registration
extends CRM_Core_Form
{
44 * How many locationBlocks should we display?
49 const LOCATION_BLOCKS
= 1;
52 * The id of the event we are proceessing
59 * The array of ids of all the participant we are proceessing
63 protected $_participantIDS = NULL;
66 * The id of the participant we are proceessing
70 protected $_participantId;
73 * Is participant able to walk registration wizard.
77 public $_allowConfirmation;
80 * Is participant requires approval
84 public $_requireApproval;
87 * Is event configured for waitlist.
91 public $_allowWaitlist;
94 * Store additional participant ids
95 * when there are pre-registered.
99 public $_additionalParticipantIds;
102 * The mode that we are in
110 * The values for the contribution db object
117 * The paymentProcessor attributes for this page
121 public $_paymentProcessor;
124 * The params submitted by the form and computed by the app
131 * The fields involved in this contribution page
138 * The billing location id for this contribiution page
145 * Price Set ID, if the new price set method is used
149 public $_priceSetId = NULL;
152 * Array of fields for the price set
162 /* Is event already full.
167 public $_isEventFull;
170 public $_lineItemParticipantsCount;
171 public $_availableRegistrations;
173 public $_forcePayement;
175 public $_isBillingAddressRequiredForPayLater;
178 * 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', 'String', $this, FALSE);
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 $this->_forcePayement
= $this->get('forcePayement');
221 //get the additional participant ids.
222 $this->_additionalParticipantIds
= $this->get('additionalParticipantIds');
223 $config = CRM_Core_Config
::singleton();
225 if (!$this->_values
) {
226 // create redirect URL to send folks back to event info page is registration not available
227 $infoUrl = CRM_Utils_System
::url('civicrm/event/info', "reset=1&id={$this->_eventId}",
228 FALSE, NULL, FALSE, TRUE
231 // this is the first time we are hitting this, so check for permissions here
232 if (!CRM_Core_Permission
::event(CRM_Core_Permission
::EDIT
, $this->_eventId
, 'register for events')) {
233 CRM_Core_Error
::statusBounce(ts('You do not have permission to register for this event'), $infoUrl);
236 // get all the values from the dao object
237 $this->_values
= $this->_fields
= array();
238 $this->_forcePayement
= FALSE;
240 //retrieve event information
241 $params = array('id' => $this->_eventId
);
242 CRM_Event_BAO_Event
::retrieve($params, $this->_values
['event']);
244 $this->checkValidEvent($infoUrl);
245 // get the participant values, CRM-4320
246 $this->_allowConfirmation
= FALSE;
247 if ($this->_participantId
) {
248 $this->processFirstParticipant($this->_participantId
);
250 //check for additional participants.
251 if ($this->_allowConfirmation
&& $this->_values
['event']['is_multiple_registrations']) {
252 $additionalParticipantIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_participantId
);
254 foreach ($additionalParticipantIds as $additionalParticipantId) {
255 $this->_additionalParticipantIds
[$cnt] = $additionalParticipantId;
258 $this->set('additionalParticipantIds', $this->_additionalParticipantIds
);
261 $eventFull = CRM_Event_BAO_Participant
::eventFull($this->_eventId
, FALSE,
262 CRM_Utils_Array
::value('has_waitlist', $this->_values
['event'])
265 $this->_allowWaitlist
= $this->_isEventFull
= FALSE;
266 if ($eventFull && !$this->_allowConfirmation
) {
267 $this->_isEventFull
= TRUE;
268 //lets redirecting to info only when to waiting list.
269 $this->_allowWaitlist
= CRM_Utils_Array
::value('has_waitlist', $this->_values
['event']);
270 if (!$this->_allowWaitlist
) {
271 CRM_Utils_System
::redirect($infoUrl);
274 $this->set('isEventFull', $this->_isEventFull
);
275 $this->set('allowWaitlist', $this->_allowWaitlist
);
277 //check for require requires approval.
278 $this->_requireApproval
= FALSE;
279 if (!empty($this->_values
['event']['requires_approval']) && !$this->_allowConfirmation
) {
280 $this->_requireApproval
= TRUE;
282 $this->set('requireApproval', $this->_requireApproval
);
284 if (isset($this->_values
['event']['default_role_id'])) {
285 $participant_role = CRM_Core_OptionGroup
::values('participant_role');
286 $this->_values
['event']['participant_role'] = $participant_role["{$this->_values['event']['default_role_id']}"];
288 // check for is_monetary status
289 $isMonetary = CRM_Utils_Array
::value('is_monetary', $this->_values
['event']);
290 $isPayLater = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $this->_eventId
, 'is_pay_later');
291 //check for variour combination for paylater, payment
292 //process with paid event.
293 if ($isMonetary && (!$isPayLater ||
!empty($this->_values
['event']['payment_processor']))) {
294 $ppID = CRM_Utils_Array
::value('payment_processor',
295 $this->_values
['event']
298 CRM_Core_Error
::statusBounce(ts('A payment processor must be selected for this event registration page, or the event must be configured to give users the option to pay later (contact the site administrator for assistance).'), $infoUrl);
300 $ppIds = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $ppID);
301 $this->_paymentProcessors
= CRM_Financial_BAO_PaymentProcessor
::getPayments($ppIds,
304 $this->set('paymentProcessors', $this->_paymentProcessors
);
306 //set default payment processor
307 if (!empty($this->_paymentProcessors
) && empty($this->_paymentProcessor
)) {
308 foreach ($this->_paymentProcessors
as $ppId => $values) {
309 if ($values['is_default'] == 1 ||
(count($this->_paymentProcessors
) == 1)) {
310 $defaultProcessorId = $ppId;
316 if (isset($defaultProcessorId)) {
317 $this->_paymentProcessor
= CRM_Financial_BAO_PaymentProcessor
::getPayment($defaultProcessorId, $this->_mode
);
319 // make sure we have a valid payment class, else abort
320 if ($this->_values
['event']['is_monetary']) {
321 if (!CRM_Utils_System
::isNull($this->_paymentProcessors
)) {
322 foreach ($this->_paymentProcessors
as $eachPaymentProcessor) {
323 // check selected payment processor is active
324 if (!$eachPaymentProcessor) {
325 CRM_Core_Error
::fatal(ts('The site administrator must set a Payment Processor for this event in order to use online registration.'));
327 // ensure that processor has a valid config
328 $payment = CRM_Core_Payment
::singleton($this->_mode
, $eachPaymentProcessor, $this);
329 $error = $payment->checkConfig();
330 if (!empty($error)) {
331 CRM_Core_Error
::fatal($error);
338 self
::initEventFee($this, $this->_eventId
);
340 // get the profile ids
341 $ufJoinParams = array(
342 'entity_table' => 'civicrm_event',
343 // CRM-4377:Â CiviEvent for the main participant, CiviEvent_Additional for additional participants
344 'module' => 'CiviEvent',
345 'entity_id' => $this->_eventId
,
347 list($this->_values
['custom_pre_id'],
348 $this->_values
['custom_post_id']
349 ) = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
351 // set profiles for additional participants
352 if ($this->_values
['event']['is_multiple_registrations']) {
353 // CRM-4377:Â CiviEvent for the main participant, CiviEvent_Additional for additional participants
354 $ufJoinParams['module'] = 'CiviEvent_Additional';
356 list($this->_values
['additional_custom_pre_id'],
357 $this->_values
['additional_custom_post_id'], $preActive, $postActive
358 ) = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
360 // CRM-4377:Â we need to maintain backward compatibility, hence if there is profile for main contact
361 // set same profile for additional contacts.
362 if ($this->_values
['custom_pre_id'] && !$this->_values
['additional_custom_pre_id']) {
363 $this->_values
['additional_custom_pre_id'] = $this->_values
['custom_pre_id'];
366 if ($this->_values
['custom_post_id'] && !$this->_values
['additional_custom_post_id']) {
367 $this->_values
['additional_custom_post_id'] = $this->_values
['custom_post_id'];
369 // now check for no profile condition, in that case is_active = 0
370 if (isset($preActive) && !$preActive) {
371 unset($this->_values
['additional_custom_pre_id']);
373 if (isset($postActive) && !$postActive) {
374 unset($this->_values
['additional_custom_post_id']);
377 // get the billing location type
378 $locationTypes = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
379 // CRM-8108 remove ts from Billing as the location type can not be translated in CiviCRM!
380 //$this->_bltID = array_search( ts('Billing'), $locationTypes );
381 $this->_bltID
= array_search('Billing', $locationTypes);
382 if (!$this->_bltID
) {
383 CRM_Core_Error
::fatal(ts('Please set a location type of %1', array(1 => 'Billing')));
385 $this->set('bltID', $this->_bltID
);
387 if ($this->_values
['event']['is_monetary']) {
388 CRM_Core_Payment_Form
::setPaymentFieldsByProcessor($this, $this->_paymentProcessor
);
390 $params = array('entity_id' => $this->_eventId
, 'entity_table' => 'civicrm_event');
391 $this->_values
['location'] = CRM_Core_BAO_Location
::getValues($params, TRUE);
393 $this->set('values', $this->_values
);
394 $this->set('fields', $this->_fields
);
396 $this->_availableRegistrations
=
397 CRM_Event_BAO_Participant
::eventFull(
398 $this->_values
['event']['id'], TRUE,
399 CRM_Utils_Array
::value('has_waitlist', $this->_values
['event'])
401 $this->set('availableRegistrations', $this->_availableRegistrations
);
403 $this->assign_by_ref('paymentProcessor', $this->_paymentProcessor
);
405 // check if this is a paypal auto return and redirect accordingly
406 if (CRM_Core_Payment
::paypalRedirect($this->_paymentProcessor
)) {
407 $url = CRM_Utils_System
::url('civicrm/event/register',
408 "_qf_ThankYou_display=1&qfKey={$this->controller->_key}"
410 CRM_Utils_System
::redirect($url);
412 $this->_contributeMode
= $this->get('contributeMode');
413 $this->assign('contributeMode', $this->_contributeMode
);
415 // setting CMS page title
416 CRM_Utils_System
::setTitle($this->_values
['event']['title']);
417 $this->assign('title', $this->_values
['event']['title']);
419 $this->assign('paidEvent', $this->_values
['event']['is_monetary']);
421 // we do not want to display recently viewed items on Registration pages
422 $this->assign('displayRecent', FALSE);
423 // Registration page values are cleared from session, so can't use normal Printer Friendly view.
424 // Use Browser Print instead.
425 $this->assign('browserPrint', TRUE);
427 $isShowLocation = CRM_Utils_Array
::value('is_show_location', $this->_values
['event']);
428 $this->assign('isShowLocation', $isShowLocation);
430 $pcpId = CRM_Utils_Request
::retrieve('pcpId', 'Positive', $this);
432 $pcp = CRM_PCP_BAO_PCP
::handlePcp($pcpId, 'event', $this->_values
['event']);
433 $this->_pcpId
= $pcp['pcpId'];
434 $this->_values
['event']['intro_text'] = CRM_Utils_Array
::value('intro_text', $pcp['pcpInfo']);
437 // assign all event properties so wizard templates can display event info.
438 $this->assign('event', $this->_values
['event']);
439 $this->assign('location', $this->_values
['location']);
440 $this->assign('bltID', $this->_bltID
);
441 $isShowLocation = CRM_Utils_Array
::value('is_show_location', $this->_values
['event']);
442 $this->assign('isShowLocation', $isShowLocation);
444 $config->defaultCurrency
= CRM_Utils_Array
::value('currency', $this->_values
['event'],
445 $config->defaultCurrency
448 //lets allow user to override campaign.
449 $campID = CRM_Utils_Request
::retrieve('campID', 'Positive', $this);
450 if ($campID && CRM_Core_DAO
::getFieldValue('CRM_Campaign_DAO_Campaign', $campID)) {
451 $this->_values
['event']['campaign_id'] = $campID;
454 // check if billing block is required for pay later
455 if (CRM_Utils_Array
::value('is_pay_later', $this->_values
['event'])) {
456 $this->_isBillingAddressRequiredForPayLater
= CRM_Utils_Array
::value('is_billing_required', $this->_values
['event']);
457 $this->assign('isBillingAddressRequiredForPayLater', $this->_isBillingAddressRequiredForPayLater
);
462 * Assign the minimal set of variables to the template
466 public function assignToTemplate() {
467 //process only primary participant params
468 $this->_params
= $this->get('params');
469 if (isset($this->_params
[0])) {
470 $params = $this->_params
[0];
473 if (!empty($params['billing_first_name'])) {
474 $name = $params['billing_first_name'];
477 if (!empty($params['billing_middle_name'])) {
478 $name .= " {$params['billing_middle_name']}";
481 if (!empty($params['billing_last_name'])) {
482 $name .= " {$params['billing_last_name']}";
484 $this->assign('billingName', $name);
485 $this->set('name', $name);
488 'amount', 'currencyID', 'credit_card_type',
489 'trxn_id', 'amount_level', 'receive_date',
492 foreach ($vars as $v) {
493 if (!empty($params[$v])) {
494 if ($v == 'receive_date') {
495 $this->assign($v, CRM_Utils_Date
::mysqlToIso($params[$v]));
498 $this->assign($v, $params[$v]);
501 elseif (CRM_Utils_Array
::value('amount', $params) == 0) {
502 $this->assign($v, CRM_Utils_Array
::value($v, $params));
506 // assign the address formatted up for display
507 $addressParts = array(
508 "street_address-{$this->_bltID}",
509 "city-{$this->_bltID}",
510 "postal_code-{$this->_bltID}",
511 "state_province-{$this->_bltID}",
512 "country-{$this->_bltID}",
514 $addressFields = array();
515 foreach ($addressParts as $part) {
516 list($n, $id) = explode('-', $part);
517 if (isset($params['billing_' . $part])) {
518 $addressFields[$n] = CRM_Utils_Array
::value('billing_' . $part, $params);
522 $this->assign('address', CRM_Utils_Address
::format($addressFields));
524 if ($this->_contributeMode
== 'direct' && empty($params['is_pay_later'])) {
525 $date = CRM_Utils_Date
::format(CRM_Utils_Array
::value('credit_card_exp_date', $params));
526 $date = CRM_Utils_Date
::mysqlToIso($date);
527 $this->assign('credit_card_exp_date', $date);
528 $this->assign('credit_card_number',
529 CRM_Utils_System
::mungeCreditCard(CRM_Utils_Array
::value('credit_card_number', $params))
533 // get the email that the confirmation would have been sent to
534 $session = CRM_Core_Session
::singleton();
536 // assign is_email_confirm to templates
537 if (isset($this->_values
['event']['is_email_confirm'])) {
538 $this->assign('is_email_confirm', $this->_values
['event']['is_email_confirm']);
541 // assign pay later stuff
542 $params['is_pay_later'] = CRM_Utils_Array
::value('is_pay_later', $params, FALSE);
543 $this->assign('is_pay_later', $params['is_pay_later']);
544 if ($params['is_pay_later']) {
545 $this->assign('pay_later_text', $this->_values
['event']['pay_later_text']);
546 $this->assign('pay_later_receipt', $this->_values
['event']['pay_later_receipt']);
549 // also assign all participantIDs to the template
550 // useful in generating confirmation numbers if needed
551 $this->assign('participantIDs',
552 $this->_participantIDS
557 * Add the custom fields
560 * @param string $name
561 * @param bool $viewOnly
565 public function buildCustom($id, $name, $viewOnly = FALSE) {
567 $button = substr($this->controller
->getButtonName(), -4);
568 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
569 $session = CRM_Core_Session
::singleton();
570 $contactID = $session->get('userID');
572 // we don't allow conflicting fields to be
573 // configured via profile
574 $fieldsToIgnore = array(
575 'participant_fee_amount' => 1,
576 'participant_fee_level' => 1,
582 foreach ($id as $profileID) {
583 $field = CRM_Core_BAO_UFGroup
::getFields($profileID, FALSE, CRM_Core_Action
::ADD
,
584 NULL, NULL, FALSE, NULL,
585 FALSE, NULL, CRM_Core_Permission
::CREATE
,
588 $fields = array_merge($fields, $field);
592 if (CRM_Core_BAO_UFGroup
::filterUFGroups($id, $contactID)) {
593 $fields = CRM_Core_BAO_UFGroup
::getFields($id, FALSE, CRM_Core_Action
::ADD
,
594 NULL, NULL, FALSE, NULL,
595 FALSE, NULL, CRM_Core_Permission
::CREATE
,
602 $fields = CRM_Core_BAO_UFGroup
::getFields($id, FALSE, CRM_Core_Action
::ADD
,
603 NULL, NULL, FALSE, NULL,
604 FALSE, NULL, CRM_Core_Permission
::CREATE
,
609 if (array_intersect_key($fields, $fieldsToIgnore)) {
610 $fields = array_diff_key($fields, $fieldsToIgnore);
611 CRM_Core_Session
::setStatus(ts('Some of the profile fields cannot be configured for this page.'));
615 if (!empty($this->_fields
)) {
616 $fields = @array_diff_assoc
($fields, $this->_fields
);
619 if (empty($this->_params
[0]['additional_participants']) &&
622 CRM_Core_BAO_Address
::checkContactSharedAddressFields($fields, $contactID);
624 $this->assign($name, $fields);
625 if (is_array($fields)) {
626 foreach ($fields as $key => $field) {
628 isset($field['data_type']) &&
629 $field['data_type'] == 'File' ||
($viewOnly && $field['name'] == 'image_URL')
631 // ignore file upload fields
634 //make the field optional if primary participant
635 //have been skip the additional participant.
636 if ($button == 'skip') {
637 $field['is_required'] = FALSE;
639 // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
640 elseif ($field['add_captcha'] && !$contactID) {
641 // only add captcha for first page
644 list($prefixName, $index) = CRM_Utils_System
::explode('-', $key, 2);
645 CRM_Core_BAO_UFGroup
::buildProfile($this, $field, CRM_Profile_Form
::MODE_CREATE
, $contactID, TRUE);
647 $this->_fields
[$key] = $field;
651 if ($addCaptcha && !$viewOnly) {
652 $captcha = CRM_Utils_ReCAPTCHA
::singleton();
653 $captcha->add($this);
654 $this->assign('isCaptcha', TRUE);
660 * @param CRM_Core_Form $form
661 * @param int $eventID
665 public static function initEventFee(&$form, $eventID) {
668 // retrive all active price set fields.
669 $discountId = CRM_Core_BAO_Discount
::findSet($eventID, 'civicrm_event');
670 if (property_exists($form, '_discountId') && $form->_discountId
) {
671 $discountId = $form->_discountId
;
674 $priceSetId = CRM_Core_DAO
::getFieldValue('CRM_Core_BAO_Discount', $discountId, 'price_set_id');
675 $price = CRM_Price_BAO_PriceSet
::initSet($form, $eventID, 'civicrm_event', TRUE, $priceSetId);
678 $price = CRM_Price_BAO_PriceSet
::initSet($form, $eventID, 'civicrm_event', TRUE);
681 if (property_exists($form, '_context') && ($form->_context
== 'standalone'
682 ||
$form->_context
== 'participant')) {
683 $discountedEvent = CRM_Core_BAO_Discount
::getOptionGroup($eventID, 'civicrm_event');
684 if (is_array($discountedEvent)) {
685 foreach ($discountedEvent as $key => $priceSetId) {
686 $priceSet = CRM_Price_BAO_PriceSet
::getSetDetail($priceSetId);
687 $priceSet = CRM_Utils_Array
::value($priceSetId, $priceSet);
688 $form->_values
['discount'][$key] = CRM_Utils_Array
::value('fields', $priceSet);
689 $fieldID = key($form->_values
['discount'][$key]);
690 $form->_values
['discount'][$key][$fieldID]['name'] = CRM_Core_DAO
::getFieldValue(
691 'CRM_Price_DAO_PriceSet',
698 $eventFee = CRM_Utils_Array
::value('fee', $form->_values
);
699 if (!is_array($eventFee) ||
empty($eventFee)) {
700 $form->_values
['fee'] = array();
703 //fix for non-upgraded price sets.CRM-4256.
704 if (isset($form->_isPaidEvent
)) {
705 $isPaidEvent = $form->_isPaidEvent
;
708 $isPaidEvent = CRM_Utils_Array
::value('is_monetary', $form->_values
['event']);
710 if ($isPaidEvent && empty($form->_values
['fee'])) {
711 if (CRM_Utils_System
::getClassName($form) != 'CRM_Event_Form_Participant') {
712 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
))));
718 * Handle process after the confirmation of payment by User
720 * @param int $contactID
721 * @param null $contribution
722 * @param null $payment
726 public function confirmPostProcess($contactID = NULL, $contribution = NULL, $payment = NULL) {
727 // add/update contact information
729 unset($this->_params
['note']);
731 //to avoid conflict overwrite $this->_params
732 $this->_params
= $this->get('value');
734 //get the amount of primary participant
735 if (!empty($this->_params
['is_primary'])) {
736 $this->_params
['fee_amount'] = $this->get('primaryParticipantAmount');
739 // add participant record
740 $participant = CRM_Event_Form_Registration
::addParticipant($this, $contactID);
741 $this->_participantIDS
[] = $participant->id
;
743 //setting register_by_id field and primaryContactId
744 if (!empty($this->_params
['is_primary'])) {
745 $this->set('registerByID', $participant->id
);
746 $this->set('primaryContactId', $contactID);
749 $this->processFirstParticipant($participant->id
);
752 CRM_Core_BAO_CustomValueTable
::postProcess($this->_params
,
753 CRM_Core_DAO
::$_nullArray,
754 'civicrm_participant',
759 $createPayment = (CRM_Utils_Array
::value('amount', $this->_params
, 0) != 0) ?
TRUE : FALSE;
761 // force to create zero amount payment, CRM-5095
762 // we know the amout is zero since createPayment is false
763 if (!$createPayment &&
764 (isset($contribution) && $contribution->id
) &&
765 $this->_priceSetId
&&
768 $createPayment = TRUE;
771 if ($createPayment && $this->_values
['event']['is_monetary'] && !empty($this->_params
['contributionID'])) {
772 $paymentParams = array(
773 'participant_id' => $participant->id
,
774 'contribution_id' => $contribution->id
,
777 $paymentPartcipant = CRM_Event_BAO_ParticipantPayment
::create($paymentParams, $ids);
780 //set only primary participant's params for transfer checkout.
781 if (($this->_contributeMode
== 'checkout' ||
$this->_contributeMode
== 'notify') && !empty($this->_params
['is_primary'])) {
782 $this->_params
['participantID'] = $participant->id
;
783 $this->set('primaryParticipant', $this->_params
);
786 $this->assign('action', $this->_action
);
789 if (!empty($this->_params
['cms_create_account'])) {
790 $this->_params
['contactID'] = $contactID;
792 if (array_key_exists('email-5', $this->_params
)) {
796 foreach ($this->_params
as $name => $dontCare) {
797 if (substr($name, 0, 5) == 'email') {
804 // we should use primary email for
805 // 1. free event registration.
806 // 2. pay later participant.
807 // 3. waiting list participant.
808 // 4. require approval participant.
809 if (!empty($this->_params
['is_pay_later']) ||
810 $this->_allowWaitlist ||
$this->_requireApproval ||
empty($this->_values
['event']['is_monetary'])) {
811 $mail = 'email-Primary';
814 if (!CRM_Core_BAO_CMSUser
::create($this->_params
, $mail)) {
815 CRM_Core_Error
::statusBounce(ts('Your profile is not saved and Account is not created.'));
821 * Process the participant
823 * @param array $params
824 * @param int $contactID
828 public static function addParticipant(&$form, $contactID) {
829 if (empty($form->_params
)) {
832 $params = $form->_params
;
833 $transaction = new CRM_Core_Transaction();
835 $groupName = 'participant_role';
837 SELECT v.label as label ,v.value as value
838 FROM civicrm_option_value v,
839 civicrm_option_group g
840 WHERE v.option_group_id = g.id
845 $p = array(1 => array($groupName, 'String'));
847 $dao = CRM_Core_DAO
::executeQuery($query, $p);
849 $roleID = $dao->value
;
852 // handle register date CRM-4320
853 $registerDate = NULL;
854 if (!empty($form->_allowConfirmation
) && $form->_participantId
) {
855 $registerDate = $params['participant_register_date'];
857 elseif (!empty($params['participant_register_date']) &&
858 is_array($params['participant_register_date']) &&
859 !empty($params['participant_register_date'])
861 $registerDate = CRM_Utils_Date
::format($params['participant_register_date']);
864 $participantFields = CRM_Event_DAO_Participant
::fields();
865 $participantParams = array(
866 'id' => CRM_Utils_Array
::value('participant_id', $params),
867 'contact_id' => $contactID,
868 'event_id' => $form->_eventId ?
$form->_eventId
: $params['event_id'],
869 'status_id' => CRM_Utils_Array
::value('participant_status',
872 'role_id' => CRM_Utils_Array
::value('participant_role_id',
875 'register_date' => ($registerDate) ?
$registerDate : date('YmdHis'),
876 'source' => CRM_Utils_String
::ellipsify(
877 isset($params['participant_source']) ?
878 CRM_Utils_Array
::value('participant_source', $params) : CRM_Utils_Array
::value('description', $params),
879 $participantFields['participant_source']['maxlength']
881 'fee_level' => CRM_Utils_Array
::value('amount_level', $params),
882 'is_pay_later' => CRM_Utils_Array
::value('is_pay_later', $params, 0),
883 'fee_amount' => CRM_Utils_Array
::value('fee_amount', $params),
884 'registered_by_id' => CRM_Utils_Array
::value('registered_by_id', $params),
885 'discount_id' => CRM_Utils_Array
::value('discount_id', $params),
886 'fee_currency' => CRM_Utils_Array
::value('currencyID', $params),
887 'campaign_id' => CRM_Utils_Array
::value('campaign_id', $params),
890 if ($form->_action
& CRM_Core_Action
::PREVIEW || CRM_Utils_Array
::value('mode', $params) == 'test') {
891 $participantParams['is_test'] = 1;
894 $participantParams['is_test'] = 0;
897 if (!empty($form->_params
['note'])) {
898 $participantParams['note'] = $form->_params
['note'];
900 elseif (!empty($form->_params
['participant_note'])) {
901 $participantParams['note'] = $form->_params
['participant_note'];
904 // reuse id if one already exists for this one (can happen
905 // with back button being hit etc)
906 if (!$participantParams['id'] && !empty($params['contributionID'])) {
907 $pID = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
908 $params['contributionID'],
912 $participantParams['id'] = $pID;
914 $participantParams['discount_id'] = CRM_Core_BAO_Discount
::findSet($form->_eventId
, 'civicrm_event');
916 if (!$participantParams['discount_id']) {
917 $participantParams['discount_id'] = "null";
920 $participant = CRM_Event_BAO_Participant
::create($participantParams);
922 $transaction->commit();
927 /* Calculate the total participant count as per params.
929 * @param array $params
932 * @return $totalCount total participant count.
935 * @param CRM_Core_Form $form
936 * @param array $params
937 * @param bool $skipCurrent
941 public static function getParticipantCount(&$form, $params, $skipCurrent = FALSE) {
943 if (!is_array($params) ||
empty($params)) {
947 $priceSetId = $form->get('priceSetId');
948 $addParticipantNum = substr($form->_name
, 12);
949 $priceSetFields = $priceSetDetails = array();
950 $hasPriceFieldsCount = FALSE;
952 $priceSetDetails = $form->get('priceSet');
953 if (isset($priceSetDetails['optionsCountTotal'])
954 && $priceSetDetails['optionsCountTotal']
956 $hasPriceFieldsCount = TRUE;
957 $priceSetFields = $priceSetDetails['optionsCountDetails']['fields'];
961 $singleFormParams = FALSE;
962 foreach ($params as $key => $val) {
963 if (!is_numeric($key)) {
964 $singleFormParams = TRUE;
969 //first format the params.
970 if ($singleFormParams) {
971 $params = self
::formatPriceSetParams($form, $params);
972 $params = array($params);
975 foreach ($params as $key => $values) {
976 if (!is_numeric($key) ||
978 ($skipCurrent && ($addParticipantNum == $key))
985 $cacheCount = CRM_Utils_Array
::value($key, $form->_lineItemParticipantsCount
);
986 if ($cacheCount && is_numeric($cacheCount)) {
987 $count = $cacheCount;
991 if (!$usedCache && $hasPriceFieldsCount) {
993 foreach ($values as $valKey => $value) {
994 if (strpos($valKey, 'price_') === FALSE) {
997 $priceFieldId = substr($valKey, 6);
998 if (!$priceFieldId ||
1000 !array_key_exists($priceFieldId, $priceSetFields)
1004 foreach ($value as $optId => $optVal) {
1005 $currentCount = $priceSetFields[$priceFieldId]['options'][$optId] * $optVal;
1006 if ($currentCount) {
1007 $count +
= $currentCount;
1015 $totalCount +
= $count;
1024 /* Format user submitted price set params.
1025 * Convert price set each param as an array.
1027 * @param array $params
1028 * An array of user submitted params.
1032 * , formatted price set params.
1035 * @param CRM_Core_Form $form
1036 * @param array $params
1040 public static function formatPriceSetParams(&$form, $params) {
1041 if (!is_array($params) ||
empty($params)) {
1045 $priceSetId = $form->get('priceSetId');
1049 $priceSetDetails = $form->get('priceSet');
1051 foreach ($params as $key => & $value) {
1053 if (strpos($key, 'price_') !== FALSE) {
1054 $fieldId = substr($key, 6);
1055 if (!array_key_exists($fieldId, $priceSetDetails['fields']) ||
1061 $field = $priceSetDetails['fields'][$fieldId];
1062 if ($field['html_type'] == 'Text') {
1063 $fieldOption = current($field['options']);
1064 $value = array($fieldOption['id'] => $value);
1067 $value = array($value => TRUE);
1075 /* Calculate total count for each price set options.
1076 * those are currently selected by user.
1083 * , array of each option w/ count total.
1090 public static function getPriceSetOptionCount(&$form) {
1091 $params = $form->get('params');
1092 $priceSet = $form->get('priceSet');
1093 $priceSetId = $form->get('priceSetId');
1095 $optionsCount = array();
1097 !is_array($priceSet) ||
1099 !is_array($params) ||
1102 return $optionsCount;
1105 $priceSetFields = $priceMaxFieldDetails = array();
1106 if (!empty($priceSet['optionsCountTotal'])) {
1107 $priceSetFields = $priceSet['optionsCountDetails']['fields'];
1110 if (!empty($priceSet['optionsMaxValueTotal'])) {
1111 $priceMaxFieldDetails = $priceSet['optionsMaxValueDetails']['fields'];
1114 $addParticipantNum = substr($form->_name
, 12);
1115 foreach ($params as $pCnt => $values) {
1116 if ($values == 'skip' ||
1117 $pCnt === $addParticipantNum
1122 foreach ($values as $valKey => $value) {
1123 if (strpos($valKey, 'price_') === FALSE) {
1127 $priceFieldId = substr($valKey, 6);
1128 if (!$priceFieldId ||
1129 !is_array($value) ||
1130 !(array_key_exists($priceFieldId, $priceSetFields) ||
array_key_exists($priceFieldId, $priceMaxFieldDetails))
1135 foreach ($value as $optId => $optVal) {
1136 if (CRM_Utils_Array
::value('html_type', $priceSet['fields'][$priceFieldId]) == 'Text') {
1137 $currentCount = $optVal;
1143 if (isset($priceSetFields[$priceFieldId]) && isset($priceSetFields[$priceFieldId]['options'][$optId])) {
1144 $currentCount = $priceSetFields[$priceFieldId]['options'][$optId] * $optVal;
1147 $optionsCount[$optId] = $currentCount + CRM_Utils_Array
::value($optId, $optionsCount, 0);
1152 return $optionsCount;
1156 * @param string $suffix
1158 * @return null|string
1160 public function checkTemplateFileExists($suffix = '') {
1161 if ($this->_eventId
) {
1162 $templateName = $this->_name
;
1163 if (substr($templateName, 0, 12) == 'Participant_') {
1164 $templateName = 'AdditionalParticipant';
1167 $templateFile = "CRM/Event/Form/Registration/{$this->_eventId}/{$templateName}.{$suffix}tpl";
1168 $template = CRM_Core_Form
::getTemplate();
1169 if ($template->template_exists($templateFile)) {
1170 return $templateFile;
1177 * @return null|string
1179 public function getTemplateFileName() {
1180 $fileName = $this->checkTemplateFileExists();
1181 return $fileName ?
$fileName : parent
::getTemplateFileName();
1185 * @return null|string
1187 public function overrideExtraTemplateFileName() {
1188 $fileName = $this->checkTemplateFileExists('extra.');
1189 return $fileName ?
$fileName : parent
::overrideExtraTemplateFileName();
1193 * Validate price set submitted params for price option limit,
1194 * as well as user should select at least one price field option.
1195 * @param unknown_type $form
1196 * @param unknown_type $params
1197 * @return multitype:|Ambigous <multitype:, string, string>
1199 public static function validatePriceSet(&$form, $params) {
1201 $hasOptMaxValue = FALSE;
1202 if (!is_array($params) ||
empty($params)) {
1206 $currentParticipantNum = substr($form->_name
, 12);
1207 if (!$currentParticipantNum) {
1208 $currentParticipantNum = 0;
1211 $priceSetId = $form->get('priceSetId');
1212 $priceSetDetails = $form->get('priceSet');
1215 !is_array($priceSetDetails) ||
1216 empty($priceSetDetails)
1221 $optionsCountDetails = $optionsMaxValueDetails = array();
1223 isset($priceSetDetails['optionsMaxValueTotal'])
1224 && $priceSetDetails['optionsMaxValueTotal']
1226 $hasOptMaxValue = TRUE;
1227 $optionsMaxValueDetails = $priceSetDetails['optionsMaxValueDetails']['fields'];
1230 isset($priceSetDetails['optionsCountTotal'])
1231 && $priceSetDetails['optionsCountTotal']
1233 $hasOptCount = TRUE;
1234 $optionsCountDetails = $priceSetDetails['optionsCountDetails']['fields'];
1236 $feeBlock = $form->_feeBlock
;
1238 if (empty($feeBlock)) {
1239 $feeBlock = $priceSetDetails['fields'];
1242 $optionMaxValues = $fieldSelected = array();
1243 foreach ($params as $pNum => $values) {
1244 if (!is_array($values) ||
$values == 'skip') {
1248 foreach ($values as $valKey => $value) {
1249 if (strpos($valKey, 'price_') === FALSE) {
1252 $priceFieldId = substr($valKey, 6);
1253 $noneOptionValueSelected = FALSE;
1254 if (!$feeBlock[$priceFieldId]['is_required'] && $value == 0) {
1255 $noneOptionValueSelected = TRUE;
1260 (!$noneOptionValueSelected && !is_array($value))
1265 $fieldSelected[$pNum] = TRUE;
1267 if (!$hasOptMaxValue ||
!is_array($value)) {
1271 foreach ($value as $optId => $optVal) {
1272 if (CRM_Utils_Array
::value('html_type', $feeBlock[$priceFieldId]) == 'Text') {
1273 $currentMaxValue = $optVal;
1276 $currentMaxValue = 1;
1279 if (isset($optionsCountDetails[$priceFieldId]) && isset($optionsCountDetails[$priceFieldId]['options'][$optId])) {
1280 $currentMaxValue = $optionsCountDetails[$priceFieldId]['options'][$optId] * $optVal;
1282 if (empty($optionMaxValues)) {
1283 $optionMaxValues[$priceFieldId][$optId] = $currentMaxValue;
1286 $optionMaxValues[$priceFieldId][$optId] =
1287 $currentMaxValue + CRM_Utils_Array
::value($optId, CRM_Utils_Array
::value($priceFieldId, $optionMaxValues), 0);
1294 //validate for option max value.
1295 foreach ($optionMaxValues as $fieldId => $values) {
1296 $options = CRM_Utils_Array
::value('options', $feeBlock[$fieldId], array());
1297 foreach ($values as $optId => $total) {
1298 $optMax = $optionsMaxValueDetails[$fieldId]['options'][$optId];
1299 $opDbCount = CRM_Utils_Array
::value('db_total_count', $options[$optId], 0);
1300 $total +
= $opDbCount;
1301 if ($optMax && $total > $optMax) {
1302 $errors['soldOutOptions'][] = ts('Option %1 has sold out.', array(1 => $feeBlock[$fieldId]['options'][$optId]['label']));
1303 if ($opDbCount && ($opDbCount >= $optMax)) {
1304 $errors[$currentParticipantNum]["price_{$fieldId}"] =
1305 ts('Sorry, this option is currently sold out.');
1307 elseif (($optMax - $opDbCount) == 1) {
1308 $errors[$currentParticipantNum]["price_{$fieldId}"] =
1309 ts('Sorry, currently only a single seat is available for this option.', array(1 => ($optMax - $opDbCount)));
1312 $errors[$currentParticipantNum]["price_{$fieldId}"] =
1313 ts('Sorry, currently only %1 seats are available for this option.', array(1 => ($optMax - $opDbCount)));
1319 //validate for price field selection.
1320 foreach ($params as $pNum => $values) {
1321 if (!is_array($values) ||
$values == 'skip') {
1324 if (empty($fieldSelected[$pNum])) {
1325 $errors[$pNum]['_qf_default'] = ts('Select at least one option from Event Fee(s).');
1332 // set the first participant ID if not set, CRM-10032
1334 * @param int $participantID
1336 public function processFirstParticipant($participantID) {
1337 $this->_participantId
= $participantID;
1338 $this->set('participantId', $this->_participantId
);
1340 $ids = $participantValues = array();
1341 $participantParams = array('id' => $this->_participantId
);
1342 CRM_Event_BAO_Participant
::getValues($participantParams, $participantValues, $ids);
1343 $this->_values
['participant'] = $participantValues[$this->_participantId
];
1344 $this->set('values', $this->_values
);
1346 // also set the allow confirmation stuff
1347 if (array_key_exists(
1348 $this->_values
['participant']['status_id'],
1349 CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Pending'")
1351 $this->_allowConfirmation
= TRUE;
1352 $this->set('allowConfirmation', TRUE);
1357 * @todo - combine this with CRM_Event_BAO_Event::validRegistrationRequest
1358 * (probably extract relevant values here & call that with them & handle bounces & redirects here -as
1359 * those belong in the form layer)
1361 * @param string $redirect
1363 public function checkValidEvent($redirect = NULL) {
1364 // is the event active (enabled)?
1365 if (!$this->_values
['event']['is_active']) {
1366 // form is inactive, die a fatal death
1367 CRM_Core_Error
::statusBounce(ts('The event you requested is currently unavailable (contact the site administrator for assistance).'));
1370 // is online registration is enabled?
1371 if (!$this->_values
['event']['is_online_registration']) {
1372 CRM_Core_Error
::statusBounce(ts('Online registration is not currently available for this event (contact the site administrator for assistance).'), $redirect);
1375 // is this an event template ?
1376 if (!empty($this->_values
['event']['is_template'])) {
1377 CRM_Core_Error
::statusBounce(ts('Event templates are not meant to be registered.'), $redirect);
1380 $now = date('YmdHis');
1381 $startDate = CRM_Utils_Date
::processDate(CRM_Utils_Array
::value('registration_start_date',
1382 $this->_values
['event']
1389 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);
1392 $endDate = CRM_Utils_Date
::processDate(CRM_Utils_Array
::value('registration_end_date',
1393 $this->_values
['event']
1395 $eventEndDate = CRM_Utils_Date
::processDate(CRM_Utils_Array
::value('event_end_date', $this->_values
['event']));
1400 CRM_Core_Error
::statusBounce(ts('Registration for this event ended on %1', array(1 => CRM_Utils_Date
::customFormat(CRM_Utils_Array
::value('registration_end_date', $this->_values
['event'])))), $redirect);
1402 if (!empty($eventEndDate) && $eventEndDate < $now) {
1403 CRM_Core_Error
::statusBounce(ts('Event ended on %1', array(1 => CRM_Utils_Date
::customFormat(CRM_Utils_Array
::value('event_end_date', $this->_values
['event'])))), $redirect);