copyright and version fixes
[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 CRM_Event_Controller
46 * @param int $action
47 *
48 * @return object CRM_Event_StateMachine
49 */
50 function __construct($controller, $action = CRM_Core_Action::NONE) {
51 parent::__construct($controller, $action);
52 $id = CRM_Utils_Request::retrieve('id', 'Positive', $controller, TRUE);
53 $is_monetary = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $id, 'is_monetary');
54
55 $pages = array('CRM_Event_Form_Registration_Register' => NULL);
56
57 //handle additional participant scenario, where we need to insert participant pages on runtime
58 $additionalParticipant = NULL;
59
60 // check that the controller has some data, hence we dont send the form name
61 // which results in an invalid argument error
62 $values = $controller->exportValues();
63 //first check POST value then QF
64 if (isset($_POST['additional_participants']) && CRM_Utils_Rule::positiveInteger($_POST['additional_participants'])) {
65 // we need to use $_POST since the QF framework has not yet been called
66 // and the additional participants page is the next one, so need to set this up
67 // now
68 $additionalParticipant = $_POST['additional_participants'];
69 }
70 elseif (isset($values['additional_participants']) && CRM_Utils_Rule::positiveInteger($values['additional_participants'])) {
71 $additionalParticipant = $values['additional_participants'];
72 }
73
74 if ($additionalParticipant) {
75 $additionalParticipant = CRM_Utils_Type::escape($additionalParticipant, 'Integer');
76 $controller->set('addParticipant', $additionalParticipant);
77 }
78
79 //to add instances of Additional Participant page, only if user has entered any additional participants
80 if ($additionalParticipant) {
81 $extraPages = CRM_Event_Form_Registration_AdditionalParticipant::getPages($additionalParticipant);
82 $pages = array_merge($pages, $extraPages);
83 }
84
85 $additionalPages = array(
86 'CRM_Event_Form_Registration_Confirm' => NULL,
87 'CRM_Event_Form_Registration_ThankYou' => NULL,
88 );
89
90 $pages = array_merge($pages, $additionalPages);
91
92 if (!$is_monetary) {
93 unset($pages['CRM_Event_Form_Registration_Confirm']);
94 }
95
96 $this->addSequentialPages($pages, $action);
97 }
98 }
99