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