3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 * The basic state element. Each state element is linked to a form and
30 * represents the form in the transition diagram. We use the state to
31 * determine what action to take on various user input. Actions include
32 * things like going back / stepping forward / process etc
35 * @copyright CiviCRM LLC (c) 2004-2014
39 class CRM_Core_State
{
48 * this is a combination "OR" of the STATE_* constants defined below
54 * the state that precedes this state
60 * the state that succeeds this state
66 * The state machine that this state is part of
69 protected $_stateMachine;
72 * The different types of states. As we flush out the framework more
73 * we will introduce other conditional / looping states which will
74 * bring in more complexity to the framework. For now, lets keep it simple
77 CONST START
= 1, FINISH
= 2, SIMPLE
= 4;
86 * @param $stateMachine
88 * @internal param \the $string internal name of the state
89 * @internal param \the $int state type
90 * @internal param \the $object state that precedes this state
91 * @internal param \the $object state that follows this state
92 * @internal param \the $object statemachine that this states belongs to
94 * @return \CRM_Core_State
97 function __construct($name, $type, $back, $next, &$stateMachine) {
100 $this->_back
= $back;
101 $this->_next
= $next;
103 $this->_stateMachine
= &$stateMachine;
106 function debugPrint() {
107 CRM_Core_Error
::debug("{$this->_name}, {$this->_type}", "{$this->_back}, {$this->_next}");
111 * Given an CRM Form, jump to the previous page
113 * @param object the CRM_Core_Form element under consideration
115 * @return mixed does a jump to the back state
118 function handleBackState(&$page) {
119 if ($this->_type
& self
::START
) {
120 $page->handle('display');
123 $back = &$page->controller
->getPage($this->_back
);
124 return $back->handle('jump');
129 * Given an CRM Form, jump to the next page
131 * @param object the CRM_Core_Form element under consideration
133 * @return mixed does a jump to the nextstate
136 function handleNextState(&$page) {
137 if ($this->_type
& self
::FINISH
) {
138 $page->handle('process');
141 $next = &$page->controller
->getPage($this->_next
);
142 return $next->handle('jump');
147 * Determine the name of the next state. This is useful when we want
148 * to display the navigation labels or potential path
153 function getNextState() {
154 if ($this->_type
& self
::FINISH
) {
158 $next = &$page->controller
->getPage($this->_next
);
164 * Mark this page as valid for the QFC framework. This is needed as
165 * we build more advanced functionality into the StateMachine
167 * @param object the QFC data container
172 function validate(&$data) {
173 $data['valid'][$this->_name
] = TRUE;
177 * Mark this page as invalid for the QFC framework. This is needed as
178 * we build more advanced functionality into the StateMachine
180 * @param object the QFC data container
185 function invalidate(&$data) {
186 $data['valid'][$this->_name
] = NULL;
207 function setName($name) {
208 $this->_name
= $name;