[NFC] Remove some more of the old cvs blocks
[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 11
6a488035
TO
12/**
13 * State machine for managing different states of the EventWizard process.
6a488035
TO
14 */
15class CRM_Event_StateMachine_Registration extends CRM_Core_StateMachine {
16
17 /**
fe482240 18 * Class constructor.
6a488035 19 *
77b97be7 20 * @param object $controller
016d95d3 21 * @param int $action
6a488035 22 *
016d95d3 23 * @throws \CRM_Core_Exception
6a488035 24 */
00be9182 25 public function __construct($controller, $action = CRM_Core_Action::NONE) {
6a488035
TO
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');
1909126f 29 $is_confirm_enabled = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $id, 'is_confirm_enabled');
6a488035 30
be2fb01f 31 $pages = ['CRM_Event_Form_Registration_Register' => NULL];
6a488035
TO
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
be2fb01f 61 $additionalPages = [
6a488035
TO
62 'CRM_Event_Form_Registration_Confirm' => NULL,
63 'CRM_Event_Form_Registration_ThankYou' => NULL,
be2fb01f 64 ];
6a488035
TO
65
66 $pages = array_merge($pages, $additionalPages);
77b97be7 67
1909126f 68 // CRM-11182 - Optional confirmation screen
353ffa53 69 if (!$is_confirm_enabled && !$is_monetary) {
6a488035
TO
70 unset($pages['CRM_Event_Form_Registration_Confirm']);
71 }
72
73 $this->addSequentialPages($pages, $action);
74 }
96025800 75
6a488035 76}