| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | Copyright CiviCRM LLC. All rights reserved. | |
| 5 | | | |
| 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 | +--------------------------------------------------------------------+ |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * State machine for managing different states of the EventWizard process. |
| 14 | */ |
| 15 | class CRM_Event_StateMachine_Registration extends CRM_Core_StateMachine { |
| 16 | |
| 17 | /** |
| 18 | * Class constructor. |
| 19 | * |
| 20 | * @param object $controller |
| 21 | * @param int $action |
| 22 | * |
| 23 | * @throws \CRM_Core_Exception |
| 24 | */ |
| 25 | public function __construct($controller, $action = CRM_Core_Action::NONE) { |
| 26 | parent::__construct($controller, $action); |
| 27 | $id = CRM_Utils_Request::retrieve('id', 'Positive', $controller, TRUE); |
| 28 | $is_monetary = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $id, 'is_monetary'); |
| 29 | $is_confirm_enabled = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $id, 'is_confirm_enabled'); |
| 30 | |
| 31 | $pages = ['CRM_Event_Form_Registration_Register' => NULL]; |
| 32 | |
| 33 | //handle additional participant scenario, where we need to insert participant pages on runtime |
| 34 | $additionalParticipant = NULL; |
| 35 | |
| 36 | // check that the controller has some data, hence we dont send the form name |
| 37 | // which results in an invalid argument error |
| 38 | $values = $controller->exportValues(); |
| 39 | //first check POST value then QF |
| 40 | if (isset($_POST['additional_participants']) && CRM_Utils_Rule::positiveInteger($_POST['additional_participants'])) { |
| 41 | // we need to use $_POST since the QF framework has not yet been called |
| 42 | // and the additional participants page is the next one, so need to set this up |
| 43 | // now |
| 44 | $additionalParticipant = $_POST['additional_participants']; |
| 45 | } |
| 46 | elseif (isset($values['additional_participants']) && CRM_Utils_Rule::positiveInteger($values['additional_participants'])) { |
| 47 | $additionalParticipant = $values['additional_participants']; |
| 48 | } |
| 49 | |
| 50 | if ($additionalParticipant) { |
| 51 | $additionalParticipant = CRM_Utils_Type::escape($additionalParticipant, 'Integer'); |
| 52 | $controller->set('addParticipant', $additionalParticipant); |
| 53 | } |
| 54 | |
| 55 | //to add instances of Additional Participant page, only if user has entered any additional participants |
| 56 | if ($additionalParticipant) { |
| 57 | $extraPages = CRM_Event_Form_Registration_AdditionalParticipant::getPages($additionalParticipant); |
| 58 | $pages = array_merge($pages, $extraPages); |
| 59 | } |
| 60 | |
| 61 | $additionalPages = [ |
| 62 | 'CRM_Event_Form_Registration_Confirm' => NULL, |
| 63 | 'CRM_Event_Form_Registration_ThankYou' => NULL, |
| 64 | ]; |
| 65 | |
| 66 | $pages = array_merge($pages, $additionalPages); |
| 67 | |
| 68 | // CRM-11182 - Optional confirmation screen |
| 69 | if (!$is_confirm_enabled && !$is_monetary) { |
| 70 | unset($pages['CRM_Event_Form_Registration_Confirm']); |
| 71 | } |
| 72 | |
| 73 | $this->addSequentialPages($pages, $action); |
| 74 | } |
| 75 | |
| 76 | } |