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