3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Contact_StateMachine_Search
extends CRM_Core_StateMachine
{
20 * The task that the wizard is currently processing
29 * @param object $controller
30 * @param \const|int $action
32 public function __construct($controller, $action = CRM_Core_Action
::NONE
) {
33 parent
::__construct($controller, $action);
36 if ($action == CRM_Core_Action
::ADVANCED
) {
37 $this->_pages
['CRM_Contact_Form_Search_Advanced'] = NULL;
38 list($task, $result) = $this->taskName($controller, 'Advanced');
40 elseif ($action == CRM_Core_Action
::PROFILE
) {
41 $this->_pages
['CRM_Contact_Form_Search_Builder'] = NULL;
42 list($task, $result) = $this->taskName($controller, 'Builder');
44 // @todo - this 'should' be removable but it's getting to this controller, for now
45 elseif ($action == CRM_Core_Action
::COPY
) {
46 $this->_pages
['CRM_Contact_Form_Search_Custom'] = NULL;
47 list($task, $result) = $this->taskName($controller, 'Custom');
50 $this->_pages
['CRM_Contact_Form_Search_Basic'] = NULL;
51 list($task, $result) = $this->taskName($controller, 'Basic');
54 if (is_array($task)) {
55 foreach ($task as $t) {
56 $this->_pages
[$t] = NULL;
60 $this->_pages
[$task] = NULL;
64 $this->_pages
['CRM_Contact_Form_Task_Result'] = NULL;
67 $this->addSequentialPages($this->_pages
, $action);
71 * Determine the form name based on the action. This allows us
72 * to avoid using conditional state machine, much more efficient
75 * @param CRM_Core_Controller $controller
76 * The controller object.
78 * @param string $formName
81 * the name of the form that will handle the task
83 public function taskName($controller, $formName = 'Search') {
84 // total hack, check POST vars and then session to determine stuff
85 $value = $_POST['task'] ??
NULL;
87 $value = $this->_controller
->get('task');
89 $this->_controller
->set('task', $value);
91 $componentMode = $this->_controller
->get('component_mode');
92 $modeValue = CRM_Contact_Form_Search
::getModeValue($componentMode);
93 $taskClassName = $modeValue['taskClassName'];
94 return $taskClassName::getTask($value);
98 * Return the form name of the task.
102 public function getTaskFormName() {
103 if (is_array($this->_task
)) {
105 return CRM_Utils_String
::getClassName($this->_task
[0]);
108 return CRM_Utils_String
::getClassName($this->_task
);
113 * Since this is a state machine for search and we want to come back to the same state
114 * we dont want to issue a reset of the state session when we are done processing a task
116 public function shouldReset() {