Merge pull request #3812 from totten/master-envtests
[civicrm-core.git] / CRM / Event / StateMachine / Registration.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2014
32 * $Id$
33 *
34 */
35
36 /**
37 * State machine for managing different states of the EventWizard process.
38 *
39 */
40 class CRM_Event_StateMachine_Registration extends CRM_Core_StateMachine {
41
42 /**
43 * class constructor
44 *
45 * @param object $controller
46 * @param \const|int $action
47 *
48 * @internal param \CRM_Event_Controller $object
49 * @return \CRM_Event_StateMachine_Registration CRM_Event_StateMachine
50 */
51 function __construct($controller, $action = CRM_Core_Action::NONE) {
52 parent::__construct($controller, $action);
53 $id = CRM_Utils_Request::retrieve('id', 'Positive', $controller, TRUE);
54 $is_monetary = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $id, 'is_monetary');
55 $is_confirm_enabled = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $id, 'is_confirm_enabled');
56
57 $pages = array('CRM_Event_Form_Registration_Register' => NULL);
58
59 //handle additional participant scenario, where we need to insert participant pages on runtime
60 $additionalParticipant = NULL;
61
62 // check that the controller has some data, hence we dont send the form name
63 // which results in an invalid argument error
64 $values = $controller->exportValues();
65 //first check POST value then QF
66 if (isset($_POST['additional_participants']) && CRM_Utils_Rule::positiveInteger($_POST['additional_participants'])) {
67 // we need to use $_POST since the QF framework has not yet been called
68 // and the additional participants page is the next one, so need to set this up
69 // now
70 $additionalParticipant = $_POST['additional_participants'];
71 }
72 elseif (isset($values['additional_participants']) && CRM_Utils_Rule::positiveInteger($values['additional_participants'])) {
73 $additionalParticipant = $values['additional_participants'];
74 }
75
76 if ($additionalParticipant) {
77 $additionalParticipant = CRM_Utils_Type::escape($additionalParticipant, 'Integer');
78 $controller->set('addParticipant', $additionalParticipant);
79 }
80
81 //to add instances of Additional Participant page, only if user has entered any additional participants
82 if ($additionalParticipant) {
83 $extraPages = CRM_Event_Form_Registration_AdditionalParticipant::getPages($additionalParticipant);
84 $pages = array_merge($pages, $extraPages);
85 }
86
87 $additionalPages = array(
88 'CRM_Event_Form_Registration_Confirm' => NULL,
89 'CRM_Event_Form_Registration_ThankYou' => NULL,
90 );
91
92 $pages = array_merge($pages, $additionalPages);
93
94 // CRM-11182 - Optional confirmation screen
95 if (!$is_confirm_enabled && !$is_monetary) {
96 unset($pages['CRM_Event_Form_Registration_Confirm']);
97 }
98
99 $this->addSequentialPages($pages, $action);
100 }
101 }
102