Merge pull request #16785 from demeritcowboy/weird-casetype-check
[civicrm-core.git] / CRM / Event / StateMachine / Registration.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 * $Id$
17 *
18 */
19
20/**
21 * State machine for managing different states of the EventWizard process.
22 *
23 */
24class CRM_Event_StateMachine_Registration extends CRM_Core_StateMachine {
25
26 /**
fe482240 27 * Class constructor.
6a488035 28 *
77b97be7
EM
29 * @param object $controller
30 * @param \const|int $action
6a488035 31 *
77b97be7 32 * @return \CRM_Event_StateMachine_Registration CRM_Event_StateMachine
6a488035 33 */
00be9182 34 public function __construct($controller, $action = CRM_Core_Action::NONE) {
6a488035
TO
35 parent::__construct($controller, $action);
36 $id = CRM_Utils_Request::retrieve('id', 'Positive', $controller, TRUE);
37 $is_monetary = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $id, 'is_monetary');
1909126f 38 $is_confirm_enabled = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $id, 'is_confirm_enabled');
6a488035 39
be2fb01f 40 $pages = ['CRM_Event_Form_Registration_Register' => NULL];
6a488035
TO
41
42 //handle additional participant scenario, where we need to insert participant pages on runtime
43 $additionalParticipant = NULL;
44
45 // check that the controller has some data, hence we dont send the form name
46 // which results in an invalid argument error
47 $values = $controller->exportValues();
48 //first check POST value then QF
49 if (isset($_POST['additional_participants']) && CRM_Utils_Rule::positiveInteger($_POST['additional_participants'])) {
50 // we need to use $_POST since the QF framework has not yet been called
51 // and the additional participants page is the next one, so need to set this up
52 // now
53 $additionalParticipant = $_POST['additional_participants'];
54 }
55 elseif (isset($values['additional_participants']) && CRM_Utils_Rule::positiveInteger($values['additional_participants'])) {
56 $additionalParticipant = $values['additional_participants'];
57 }
58
59 if ($additionalParticipant) {
60 $additionalParticipant = CRM_Utils_Type::escape($additionalParticipant, 'Integer');
61 $controller->set('addParticipant', $additionalParticipant);
62 }
63
64 //to add instances of Additional Participant page, only if user has entered any additional participants
65 if ($additionalParticipant) {
66 $extraPages = CRM_Event_Form_Registration_AdditionalParticipant::getPages($additionalParticipant);
67 $pages = array_merge($pages, $extraPages);
68 }
69
be2fb01f 70 $additionalPages = [
6a488035
TO
71 'CRM_Event_Form_Registration_Confirm' => NULL,
72 'CRM_Event_Form_Registration_ThankYou' => NULL,
be2fb01f 73 ];
6a488035
TO
74
75 $pages = array_merge($pages, $additionalPages);
77b97be7 76
1909126f 77 // CRM-11182 - Optional confirmation screen
353ffa53 78 if (!$is_confirm_enabled && !$is_monetary) {
6a488035
TO
79 unset($pages['CRM_Event_Form_Registration_Confirm']);
80 }
81
82 $this->addSequentialPages($pages, $action);
83 }
96025800 84
6a488035 85}