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_AdditionalParticipant
extends CRM_Event_Form_Registration
{
44 * The defaults involved in this page
47 public $_defaults = array();
50 * Pre-registered additional participant id.
53 public $additionalParticipantId = NULL;
56 * Set variables up before form is built
60 public function preProcess() {
63 $participantNo = substr($this->_name
, 12);
65 //lets process in-queue participants.
66 if ($this->_participantId
&& $this->_additionalParticipantIds
) {
67 $this->_additionalParticipantId
= CRM_Utils_Array
::value($participantNo, $this->_additionalParticipantIds
);
70 $participantCnt = $participantNo +
1;
71 $this->assign('formId', $participantNo);
72 $this->_params
= array();
73 $this->_params
= $this->get('params');
75 $participantTot = $this->_params
[0]['additional_participants'] +
1;
76 $skipCount = count(array_keys($this->_params
, "skip"));
78 $this->assign('skipCount', $skipCount);
80 CRM_Utils_System
::setTitle(ts('Register Participant %1 of %2', array(1 => $participantCnt, 2 => $participantTot)));
82 //CRM-4320, hack to check last participant.
83 $this->_lastParticipant
= FALSE;
84 if ($participantTot == $participantCnt) {
85 $this->_lastParticipant
= TRUE;
87 $this->assign('lastParticipant', $this->_lastParticipant
);
91 * Set default values for the form. For edit/view mode
92 * the default values are retrieved from the database
97 public function setDefaultValues() {
98 $defaults = $unsetSubmittedOptions = array();
100 //fix for CRM-3088, default value for discount set.
101 if (!empty($this->_values
['discount'])) {
102 $discountId = CRM_Core_BAO_Discount
::findSet($this->_eventId
, 'civicrm_event');
103 if ($discountId && !empty($this->_values
['event']['default_discount_fee_id'])) {
104 $discountKey = CRM_Core_DAO
::getFieldValue("CRM_Core_DAO_OptionValue", $this->_values
['event']['default_discount_fee_id']
107 $defaults['amount'] = key(array_slice($this->_values
['discount'][$discountId], $discountKey - 1, $discountKey, TRUE));
110 if ($this->_priceSetId
) {
111 foreach ($this->_feeBlock
as $key => $val) {
112 if (empty($val['options'])) {
116 $optionsFull = CRM_Utils_Array
::value('option_full_ids', $val, array());
117 foreach ($val['options'] as $keys => $values) {
118 if ($values['is_default'] && !in_array($keys, $optionsFull)) {
119 if ($val['html_type'] == 'CheckBox') {
120 $defaults["price_{$key}"][$keys] = 1;
123 $defaults["price_{$key}"] = $keys;
127 if (!empty($optionsFull)) {
128 $unsetSubmittedOptions[$val['id']] = $optionsFull;
133 //CRM-4320, setdefault additional participant values.
134 if ($this->_allowConfirmation
&& $this->_additionalParticipantId
) {
135 //hack to get set default from eventFees.php
136 $this->_discountId
= $discountId;
137 $this->_pId
= $this->_additionalParticipantId
;
138 $this->_contactId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_additionalParticipantId
, 'contact_id');
139 $participantDefaults = CRM_Event_Form_EventFees
::setDefaultValues($this);
140 $participantDefaults = array_merge($this->_defaults
, $participantDefaults);
141 // use primary email address if billing email address is empty
142 if (empty($this->_defaults
["email-{$this->_bltID}"]) &&
143 !empty($this->_defaults
["email-Primary"])
145 $participantDefaults["email-{$this->_bltID}"] = $this->_defaults
["email-Primary"];
147 $defaults = array_merge($defaults, $participantDefaults);
150 $defaults = array_merge($this->_defaults
, $defaults);
152 //reset values for all options those are full.
153 if (!empty($unsetSubmittedOptions) && empty($_POST)) {
154 $this->resetElementValue($unsetSubmittedOptions);
157 //load default campaign from page.
158 if (array_key_exists('participant_campaign_id', $this->_fields
)) {
159 $defaults['participant_campaign_id'] = CRM_Utils_Array
::value('campaign_id', $this->_values
['event']);
166 * Build the form object
170 public function buildQuickForm() {
171 $config = CRM_Core_Config
::singleton();
172 $button = substr($this->controller
->getButtonName(), -4);
174 $this->add('hidden', 'scriptFee', NULL);
175 $this->add('hidden', 'scriptArray', NULL);
177 if ($this->_values
['event']['is_monetary']) {
178 CRM_Event_Form_Registration_Register
::buildAmount($this);
180 $first_name = $last_name = NULL;
181 $pre = $post = array();
183 'pre', 'post') as $keys) {
184 if (isset($this->_values
['additional_custom_' . $keys . '_id'])) {
185 $this->buildCustom($this->_values
['additional_custom_' . $keys . '_id'], 'additionalCustom' . ucfirst($keys), TRUE);
186 $
$keys = CRM_Core_BAO_UFGroup
::getFields($this->_values
['additional_custom_' . $keys . '_id']);
189 'first_name', 'last_name') as $name) {
190 if (array_key_exists($name, $
$keys) &&
191 CRM_Utils_Array
::value('is_required', CRM_Utils_Array
::value($name, $
$keys))
198 $required = ($button == 'skip' ||
199 $this->_values
['event']['allow_same_participant_emails'] == 1 &&
200 ($first_name && $last_name)
205 if ($this->isLastParticipant(TRUE) && empty($this->_values
['event']['is_monetary'])) {
206 $js = array('onclick' => "return submitOnce(this,'" . $this->_name
. "','" . ts('Processing') . "');");
209 //handle case where user might sart with waiting by group
210 //registration and skip some people and now group fit to
211 //become registered so need to take payment from user.
212 //this case only occurs at dynamic waiting status, CRM-4320
213 $statusMessage = NULL;
214 $allowToProceed = TRUE;
215 $includeSkipButton = TRUE;
216 $this->_resetAllowWaitlist
= FALSE;
218 $pricesetFieldsCount = CRM_Price_BAO_PriceSet
::getPricesetCount($this->_priceSetId
);
220 if ($this->_lastParticipant ||
$pricesetFieldsCount) {
221 //get the participant total.
222 $processedCnt = self
::getParticipantCount($this, $this->_params
, TRUE);
225 if (!$this->_allowConfirmation
&& !empty($this->_params
[0]['bypass_payment']) &&
226 $this->_lastParticipant
229 //get the event spaces.
230 $spaces = $this->_availableRegistrations
;
232 $currentPageMaxCount = 1;
233 if ($pricesetFieldsCount) {
234 $currentPageMaxCount = $pricesetFieldsCount;
237 //we might did reset allow waiting in case of dynamic calculation
238 if (!empty($this->_params
[0]['bypass_payment']) &&
239 is_numeric($spaces) &&
240 $processedCnt > $spaces
242 $this->_allowWaitlist
= TRUE;
243 $this->set('allowWaitlist', TRUE);
246 //lets allow to become a part of runtime waiting list, if primary selected pay later.
247 $realPayLater = FALSE;
248 if (!empty($this->_values
['event']['is_monetary']) && !empty($this->_values
['event']['is_pay_later'])) {
249 $realPayLater = CRM_Utils_Array
::value('is_pay_later', $this->_params
[0]);
252 //truly spaces are greater than required.
253 if (is_numeric($spaces) && $spaces >= ($processedCnt +
$currentPageMaxCount)) {
254 if (CRM_Utils_Array
::value('amount', $this->_params
[0], 0) == 0 ||
$this->_requireApproval
) {
255 $this->_allowWaitlist
= FALSE;
256 $this->set('allowWaitlist', $this->_allowWaitlist
);
257 if ($this->_requireApproval
) {
258 $statusMessage = ts("It looks like you are now registering a group of %1 participants. The event has %2 available spaces (you will not be wait listed). Registration for this event requires approval. You will receive an email once your registration has been reviewed.", array(1 => ++
$processedCnt, 2 => $spaces));
261 $statusMessage = ts("It looks like you are now registering a group of %1 participants. The event has %2 available spaces (you will not be wait listed).", array(1 => ++
$processedCnt, 2 => $spaces));
265 $statusMessage = ts("It looks like you are now registering a group of %1 participants. The event has %2 available spaces (you will not be wait listed). Please go back to the main registration page and reduce the number of additional people. You will also need to complete payment information.", array(1 => ++
$processedCnt, 2 => $spaces));
266 $allowToProceed = FALSE;
268 CRM_Core_Session
::setStatus($statusMessage, ts('Registration Error'), 'error');
270 elseif ($processedCnt == $spaces) {
271 if (CRM_Utils_Array
::value('amount', $this->_params
[0], 0) == 0
272 ||
$realPayLater ||
$this->_requireApproval
274 $this->_resetAllowWaitlist
= TRUE;
275 if ($this->_requireApproval
) {
276 $statusMessage = ts("If you skip this participant there will be enough spaces in the event for your group (you will not be wait listed). Registration for this event requires approval. You will receive an email once your registration has been reviewed.");
279 $statusMessage = ts("If you skip this participant there will be enough spaces in the event for your group (you will not be wait listed).");
283 //hey there is enough space and we require payment.
284 $statusMessage = ts("If you skip this participant there will be enough spaces in the event for your group (you will not be wait listed). Please go back to the main registration page and reduce the number of additional people. You will also need to complete payment information.");
285 $includeSkipButton = FALSE;
290 // for priceset with count
291 if ($pricesetFieldsCount && !empty($this->_values
['event']['has_waitlist']) &&
292 !$this->_allowConfirmation
295 if ($this->_isEventFull
) {
296 $statusMessage = ts('This event is currently full. You are registering for the waiting list. You will be notified if spaces become available.');
298 elseif ($this->_allowWaitlist ||
299 (!$this->_allowWaitlist
&& ($processedCnt +
$pricesetFieldsCount) > $this->_availableRegistrations
)
302 $waitingMsg = ts('It looks like you are registering more participants then there are spaces available. All participants will be added to the waiting list. You will be notified if spaces become available.');
303 $confirmedMsg = ts('It looks like there are enough spaces in this event for your group (you will not be wait listed).');
304 if ($this->_requireApproval
) {
305 $waitingMsg = ts('It looks like you are now registering a group of %1 participants. The event has %2 available spaces (you will not be wait listed). Registration for this event requires approval. You will receive an email once your registration has been reviewed.');
306 $confirmedMsg = ts('It looks there are enough spaces in this event for your group (you will not be wait listed). Registration for this event requires approval. You will receive an email once your registration has been reviewed.');
309 $this->assign('waitingMsg', $waitingMsg);
310 $this->assign('confirmedMsg', $confirmedMsg);
312 $this->assign('availableRegistrations', $this->_availableRegistrations
);
313 $this->assign('currentParticipantCount', $processedCnt);
314 $this->assign('allowGroupOnWaitlist', TRUE);
316 $paymentBypassed = NULL;
317 if (!empty($this->_params
[0]['bypass_payment']) &&
318 !$this->_allowWaitlist
&&
320 !$this->_requireApproval
&&
321 !(CRM_Utils_Array
::value('amount', $this->_params
[0], 0) == 0)
323 $paymentBypassed = ts('Please go back to the main registration page, to complete payment information.');
325 $this->assign('paymentBypassed', $paymentBypassed);
329 $this->assign('statusMessage', $statusMessage);
332 array('type' => 'back',
333 'name' => ts('<< Go Back'),
334 'spacing' => '  ',
339 if ($allowToProceed) {
340 $buttons = array_merge($buttons, array(
341 array('type' => 'next',
342 'name' => ts('Continue >>'),
343 'spacing' => ' ',
349 if ($includeSkipButton) {
350 $buttons = array_merge($buttons, array(
351 array('type' => 'next',
352 'name' => ts('Skip Participant >>|'),
359 $this->addButtons($buttons);
360 $this->addFormRule(array('CRM_Event_Form_Registration_AdditionalParticipant', 'formRule'), $this);
366 * @param array $fields the input form values
367 * @param array $files the uploaded files if any
371 * @return true if no errors, else array of errors
374 public static function formRule($fields, $files, $self) {
376 //get the button name.
377 $button = substr($self->controller
->getButtonName(), -4);
379 $realPayLater = FALSE;
380 if (!empty($self->_values
['event']['is_monetary']) && !empty($self->_values
['event']['is_pay_later'])) {
381 $realPayLater = CRM_Utils_Array
::value('is_pay_later', $self->_params
[0]);
384 if ($button != 'skip') {
385 //Check that either an email or firstname+lastname is included in the form(CRM-9587)
386 CRM_Event_Form_Registration_Register
::checkProfileComplete($fields, $errors, $self->_eventId
);
388 //Additional Participant can also register for an event only once
389 $isRegistered = CRM_Event_Form_Registration_Register
::checkRegistration($fields, $self, TRUE);
391 if ($self->_values
['event']['allow_same_participant_emails']) {
392 $errors['_qf_default'] = ts('A person is already registered for this event.');
395 $errors["email-{$self->_bltID}"] = ts('A person with this email address is already registered for this event.');
399 //get the complete params.
400 $params = $self->get('params');
402 //take the participant instance.
403 $addParticipantNum = substr($self->_name
, 12);
405 if (is_array($params)) {
406 foreach ($params as $key => $value) {
407 if ($key != $addParticipantNum) {
408 if (!$self->_values
['event']['allow_same_participant_emails']) {
409 //collect all email fields
410 $existingEmails = array();
411 $additionalParticipantEmails = array();
412 if (is_array($value)) {
413 foreach ($value as $key => $val) {
414 if (substr($key, 0, 6) == 'email-' && $val) {
415 $existingEmails[] = $val;
419 foreach ($fields as $key => $val) {
420 if (substr($key, 0, 6) == 'email-' && $val) {
421 $additionalParticipantEmails[] = $val;
425 //check if any emails are common to both arrays
426 if (count(array_intersect($existingEmails, $additionalParticipantEmails))) {
427 $errors[$mailKey] = ts('The email address must be unique for each participant.');
432 // check with first_name and last_name for additional participants
433 if (!empty($value['first_name']) && ($value['first_name'] == CRM_Utils_Array
::value('first_name', $fields)) &&
434 (CRM_Utils_Array
::value('last_name',$value) == CRM_Utils_Array
::value('last_name', $fields))
436 $errors['first_name'] = ts('The first name and last name must be unique for each participant.');
444 //check for atleast one pricefields should be selected
445 if (!empty($fields['priceSetId'])) {
446 $allParticipantParams = $params;
448 //format current participant params.
449 $allParticipantParams[$addParticipantNum] = self
::formatPriceSetParams($self, $fields);
450 $totalParticipants = self
::getParticipantCount($self, $allParticipantParams);
452 //validate price field params.
453 $priceSetErrors = self
::validatePriceSet($self, $allParticipantParams);
454 $errors = array_merge($errors, CRM_Utils_Array
::value($addParticipantNum, $priceSetErrors, array()));
456 if (!$self->_allowConfirmation
&&
457 is_numeric($self->_availableRegistrations
)
459 if (!empty($self->_params
[0]['bypass_payment']) &&
460 !$self->_allowWaitlist
&&
462 !$self->_requireApproval
&&
463 !(CRM_Utils_Array
::value('amount', $self->_params
[0], 0) == 0) &&
464 $totalParticipants < $self->_availableRegistrations
466 $errors['_qf_default'] = ts("Your event registration will be confirmed. Please go back to the main registration page, to complete payment information.");
468 //check for availability of registrations.
469 if (!$self->_allowConfirmation
&& empty($self->_values
['event']['has_waitlist']) &&
470 $totalParticipants > $self->_availableRegistrations
472 $errors['_qf_default'] = ts('It looks like event has only %2 seats available and you are trying to register %1 participants, so could you please select price options accordingly.', array(1 => $totalParticipants, 2 => $self->_availableRegistrations
));
478 if ($button == 'skip' && $self->_lastParticipant
&& !empty($fields['priceSetId'])) {
479 $pricesetFieldsCount = CRM_Price_BAO_PriceSet
::getPricesetCount($fields['priceSetId']);
480 if (($pricesetFieldsCount < 1) ||
$self->_allowConfirmation
) {
484 if (!empty($self->_values
['event']['has_waitlist']) && !empty($self->_params
[0]['bypass_payment']) &&
485 !$self->_allowWaitlist
&&
487 !$self->_requireApproval
&&
488 !(CRM_Utils_Array
::value('amount', $self->_params
[0], 0) == 0)
490 $errors['_qf_default'] = ts("You are going to skip the last participant, your event registration will be confirmed. Please go back to the main registration page, to complete payment information.");
495 if ($button != 'skip' &&
496 $self->_values
['event']['is_monetary'] &&
497 !isset($errors['_qf_default']) &&
498 !$self->validatePaymentValues($self, $fields)
500 $errors['_qf_default'] = ts("Your payment information looks incomplete. Please go back to the main registration page, to complete payment information.");
501 $self->set('forcePayement', TRUE);
503 elseif ($button == 'skip') {
504 $self->set('forcePayement', TRUE);
516 public function validatePaymentValues($self, $fields) {
518 if (!empty($self->_params
[0]['bypass_payment']) ||
519 $self->_allowWaitlist ||
520 empty($self->_fields
) ||
521 CRM_Utils_Array
::value('amount', $self->_params
[0]) > 0
526 $validatePayement = FALSE;
527 if (!empty($fields['priceSetId'])) {
529 CRM_Price_BAO_PriceSet
::processAmount($self->_values
['fee'], $fields, $lineItem);
530 if ($fields['amount'] > 0) {
531 $validatePayement = TRUE;
532 // $self->_forcePayement = true;
536 elseif (!empty($fields['amount']) &&
537 (CRM_Utils_Array
::value('value', $self->_values
['fee'][$fields['amount']]) > 0)
539 $validatePayement = TRUE;
542 if (!$validatePayement) {
548 CRM_Core_Form
::validateMandatoryFields($self->_fields
, $fields, $errors);
550 // make sure that credit card number and cvv are valid
551 CRM_Core_Payment_Form
::validateCreditCard($self->_params
[0], $errors);
557 foreach (CRM_Contact_BAO_Contact
::$_greetingTypes as $greeting) {
558 if ($greetingType = CRM_Utils_Array
::value($greeting, $self->_params
[0])) {
559 $customizedValue = CRM_Core_OptionGroup
::getValue($greeting, 'Customized', 'name');
560 if ($customizedValue == $greetingType && empty($self->_params
[0][$greeting . '_custom'])) {
568 * Process the form submission
573 public function postProcess() {
574 //get the button name.
575 $button = substr($this->controller
->getButtonName(), -4);
577 //take the participant instance.
578 $addParticipantNum = substr($this->_name
, 12);
580 //user submitted params.
581 $params = $this->controller
->exportValues($this->_name
);
583 if (!$this->_allowConfirmation
) {
584 // check if the participant is already registered
585 $params['contact_id'] = CRM_Event_Form_Registration_Register
::checkRegistration($params, $this, TRUE, TRUE);
588 //carry campaign to partcipants.
589 if (array_key_exists('participant_campaign_id', $params)) {
590 $params['campaign_id'] = $params['participant_campaign_id'];
593 $params['campaign_id'] = CRM_Utils_Array
::value('campaign_id', $this->_values
['event']);
596 // if waiting is enabled
597 if (!$this->_allowConfirmation
&&
598 is_numeric($this->_availableRegistrations
)
600 $this->_allowWaitlist
= FALSE;
601 //get the current page count.
602 $currentCount = self
::getParticipantCount($this, $params);
603 if ($button == 'skip') {
604 $currentCount = 'skip';
607 //get the total count.
608 $previousCount = self
::getParticipantCount($this, $this->_params
, TRUE);
609 $totalParticipants = $previousCount;
610 if (is_numeric($currentCount)) {
611 $totalParticipants +
= $currentCount;
613 if (!empty($this->_values
['event']['has_waitlist']) &&
614 $totalParticipants > $this->_availableRegistrations
616 $this->_allowWaitlist
= TRUE;
618 $this->set('allowWaitlist', $this->_allowWaitlist
);
619 $this->_lineItemParticipantsCount
[$addParticipantNum] = $currentCount;
622 if ($button == 'skip') {
623 //hack for free/zero amount event.
624 if ($this->_resetAllowWaitlist
) {
625 $this->_allowWaitlist
= FALSE;
626 $this->set('allowWaitlist', FALSE);
627 if ($this->_requireApproval
) {
628 $status = ts("You have skipped last participant and which result into event having enough spaces, but your registration require approval, Once your registration has been reviewed, you will receive an email with a link to a web page where you can complete the registration process.");
631 $status = ts("You have skipped last participant and which result into event having enough spaces, hence your group become as register participants though you selected on wait list.");
633 CRM_Core_Session
::setStatus($status);
636 $this->_params
[$addParticipantNum] = 'skip';
637 if (isset($this->_lineItem
)) {
638 $this->_lineItem
[$addParticipantNum] = 'skip';
639 $this->_lineItemParticipantsCount
[$addParticipantNum] = 'skip';
644 $config = CRM_Core_Config
::singleton();
645 $params['currencyID'] = $config->defaultCurrency
;
647 if ($this->_values
['event']['is_monetary']) {
650 $discountId = CRM_Core_BAO_Discount
::findSet($this->_eventId
, 'civicrm_event');
652 if (!empty($this->_values
['discount'][$discountId])) {
653 $params['discount_id'] = $discountId;
654 $params['amount_level'] = $this->_values
['discount'][$discountId][$params['amount']]['label'];
655 $params['amount'] = $this->_values
['discount'][$discountId][$params['amount']]['value'];
657 elseif (empty($params['priceSetId'])) {
658 $params['amount_level'] = $this->_values
['fee'][$params['amount']]['label'];
659 $params['amount'] = $this->_values
['fee'][$params['amount']]['value'];
663 CRM_Price_BAO_PriceSet
::processAmount($this->_values
['fee'], $params, $lineItem);
665 //build the line item..
666 if (array_key_exists($addParticipantNum, $this->_lineItem
)) {
667 $this->_lineItem
[$addParticipantNum] = $lineItem;
670 $this->_lineItem
[] = $lineItem;
675 if (array_key_exists('participant_role', $params)) {
676 $params['participant_role_id'] = $params['participant_role'];
679 if (empty($params['participant_role_id']) && $this->_values
['event']['default_role_id']) {
680 $params['participant_role_id'] = $this->_values
['event']['default_role_id'];
683 if (!empty($this->_params
[0]['is_pay_later'])) {
684 $params['is_pay_later'] = 1;
687 //carry additional participant id, contact id if pre-registered.
688 if ($this->_allowConfirmation
&& $this->_additionalParticipantId
) {
689 $params['contact_id'] = $this->_contactId
;
690 $params['participant_id'] = $this->_additionalParticipantId
;
693 //build the params array.
694 if (array_key_exists($addParticipantNum, $this->_params
)) {
695 $this->_params
[$addParticipantNum] = $params;
698 $this->_params
[] = $params;
702 //finally set the params.
703 $this->set('params', $this->_params
);
705 if ($this->_lineItem
) {
706 $this->set('lineItem', $this->_lineItem
);
707 $this->set('lineItemParticipantsCount', $this->_lineItemParticipantsCount
);
710 $participantNo = count($this->_params
);
711 if ($button != 'skip') {
712 $statusMsg = ts('Registration information for participant %1 has been saved.', array(1 => $participantNo));
713 CRM_Core_Session
::setStatus($statusMsg, ts('Registration Saved'), 'success');
716 // Check whether to process the registration now, calling processRegistration()
718 !$this->_values
['event']['is_confirm_enabled'] // CRM-11182 - Optional confirmation screen
719 && !$this->_values
['event']['is_monetary']
720 && CRM_Utils_Array
::value('additional_participants', $this->_params
[0])
721 && $this->isLastParticipant()
723 CRM_Event_Form_Registration_Register
::processRegistration($this->_params
, NULL);
728 * @param $additionalParticipant
732 public static function &getPages($additionalParticipant) {
734 for ($i = 1; $i <= $additionalParticipant; $i++
) {
735 $details["Participant_{$i}"] = array(
736 'className' => 'CRM_Event_Form_Registration_AdditionalParticipant',
737 'title' => "Register Additional Participant {$i}",
744 * Check whether call current participant is last one
746 * @param bool $isButtonJs
748 * @return boolean ture on success.
750 public function isLastParticipant($isButtonJs = FALSE) {
751 $participant = $isButtonJs ?
$this->_params
[0]['additional_participants'] : $this->_params
[0]['additional_participants'] +
1;
752 if (count($this->_params
) == $participant) {
759 * Reset values for all options those are full.
762 public function resetElementValue($optionFullIds = array()) {
763 if (!is_array($optionFullIds) ||
764 empty($optionFullIds) ||
765 !$this->isSubmitted()
770 foreach ($optionFullIds as $fldId => $optIds) {
771 $name = "price_$fldId";
772 if (!$this->elementExists($name)) {
776 $element = $this->getElement($name);
777 $eleType = $element->getType();
779 $resetSubmitted = FALSE;
782 if ($element->isFrozen()) {
783 $element->setValue('');
784 $resetSubmitted = TRUE;
789 if (is_array($element->_elements
)) {
790 foreach ($element->_elements
as $child) {
791 $childType = $child->getType();
792 $methodName = 'getName';
794 $methodName = 'getValue';
796 if (in_array($child->{$methodName}(), $optIds) && $child->isFrozen()) {
797 $resetSubmitted = TRUE;
798 $child->updateAttributes(array('checked' => NULL));
805 $resetSubmitted = TRUE;
806 $element->_values
= array();
810 //finally unset values from submitted.
811 if ($resetSubmitted) {
812 $this->resetSubmittedValue($name, $optIds);
818 * @param string $elementName
819 * @param array $optionIds
821 public function resetSubmittedValue($elementName, $optionIds = array()) {
822 if (empty($elementName) ||
823 !$this->elementExists($elementName) ||
824 !$this->getSubmitValue($elementName)
829 'constantValues', 'submitValues', 'defaultValues') as $val) {
830 $values = &$this->{"_$val"};
831 if (!is_array($values) ||
empty($values)) {
834 $eleVal = CRM_Utils_Array
::value($elementName, $values);
835 if (empty($eleVal)) {
838 if (is_array($eleVal)) {
840 foreach ($eleVal as $keyId => $ignore) {
841 if (in_array($keyId, $optionIds)) {
843 unset($values[$elementName][$keyId]);
846 if ($found && empty($values[$elementName][$keyId])) {
847 $values[$elementName][$keyId] = NULL;
851 $values[$elementName][$keyId] = NULL;