| 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 | class CRM_Event_StateMachine_Search extends CRM_Core_StateMachine { |
| 20 | |
| 21 | /** |
| 22 | * The task that the wizard is currently processing. |
| 23 | * |
| 24 | * @var string |
| 25 | */ |
| 26 | protected $_task; |
| 27 | |
| 28 | /** |
| 29 | * Class constructor. |
| 30 | * |
| 31 | * @param object $controller |
| 32 | * @param int $action |
| 33 | */ |
| 34 | public function __construct($controller, $action = CRM_Core_Action::NONE) { |
| 35 | parent::__construct($controller, $action); |
| 36 | |
| 37 | $this->_pages = []; |
| 38 | |
| 39 | $this->_pages['CRM_Event_Form_Search'] = NULL; |
| 40 | list($task, $result) = $this->taskName($controller, 'Search'); |
| 41 | $this->_task = $task; |
| 42 | |
| 43 | if (is_array($task)) { |
| 44 | foreach ($task as $t) { |
| 45 | $this->_pages[$t] = NULL; |
| 46 | } |
| 47 | } |
| 48 | else { |
| 49 | $this->_pages[$task] = NULL; |
| 50 | } |
| 51 | |
| 52 | if ($result) { |
| 53 | $this->_pages['CRM_Event_Form_Task_Result'] = NULL; |
| 54 | } |
| 55 | |
| 56 | $this->addSequentialPages($this->_pages, $action); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Determine the form name based on the action. This allows us |
| 61 | * to avoid using conditional state machine, much more efficient |
| 62 | * and simpler |
| 63 | * |
| 64 | * @param CRM_Core_Controller $controller |
| 65 | * The controller object. |
| 66 | * |
| 67 | * @param string $formName |
| 68 | * |
| 69 | * @return array |
| 70 | * the name of the form that will handle the task |
| 71 | */ |
| 72 | public function taskName($controller, $formName = 'Search') { |
| 73 | // total hack, check POST vars and then session to determine stuff |
| 74 | $value = CRM_Utils_Array::value('task', $_POST); |
| 75 | if (!isset($value)) { |
| 76 | $value = $this->_controller->get('task'); |
| 77 | } |
| 78 | $this->_controller->set('task', $value); |
| 79 | return CRM_Event_Task::getTask($value); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Return the form name of the task. |
| 84 | * |
| 85 | * @return string |
| 86 | */ |
| 87 | public function getTaskFormName() { |
| 88 | return CRM_Utils_String::getClassName($this->_task); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Since this is a state machine for search and we want to come back to the same state |
| 93 | * we dont want to issue a reset of the state session when we are done processing a task |
| 94 | */ |
| 95 | public function shouldReset() { |
| 96 | return FALSE; |
| 97 | } |
| 98 | |
| 99 | } |