Merge pull request #15982 from civicrm/5.20
[civicrm-core.git] / CRM / Event / StateMachine / Registration.php
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 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 * $Id$
17 *
18 */
19
20 /**
21 * State machine for managing different states of the EventWizard process.
22 *
23 */
24 class CRM_Event_StateMachine_Registration extends CRM_Core_StateMachine {
25
26 /**
27 * Class constructor.
28 *
29 * @param object $controller
30 * @param \const|int $action
31 *
32 * @return \CRM_Event_StateMachine_Registration CRM_Event_StateMachine
33 */
34 public function __construct($controller, $action = CRM_Core_Action::NONE) {
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');
38 $is_confirm_enabled = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $id, 'is_confirm_enabled');
39
40 $pages = ['CRM_Event_Form_Registration_Register' => NULL];
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
70 $additionalPages = [
71 'CRM_Event_Form_Registration_Confirm' => NULL,
72 'CRM_Event_Form_Registration_ThankYou' => NULL,
73 ];
74
75 $pages = array_merge($pages, $additionalPages);
76
77 // CRM-11182 - Optional confirmation screen
78 if (!$is_confirm_enabled && !$is_monetary) {
79 unset($pages['CRM_Event_Form_Registration_Confirm']);
80 }
81
82 $this->addSequentialPages($pages, $action);
83 }
84
85 }