Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | class CRM_Contact_StateMachine_Search extends CRM_Core_StateMachine { | |
18 | ||
19 | /** | |
20 | * The task that the wizard is currently processing | |
21 | * | |
22 | * @var string | |
6a488035 TO |
23 | */ |
24 | protected $_task; | |
25 | ||
26 | /** | |
fe482240 | 27 | * Class constructor. |
0e2e76cf EM |
28 | * |
29 | * @param object $controller | |
30 | * @param \const|int $action | |
95ea96be | 31 | */ |
608e6658 | 32 | public function __construct($controller, $action = CRM_Core_Action::NONE) { |
6a488035 TO |
33 | parent::__construct($controller, $action); |
34 | ||
be2fb01f | 35 | $this->_pages = []; |
6a488035 TO |
36 | if ($action == CRM_Core_Action::ADVANCED) { |
37 | $this->_pages['CRM_Contact_Form_Search_Advanced'] = NULL; | |
38 | list($task, $result) = $this->taskName($controller, 'Advanced'); | |
39 | } | |
40 | elseif ($action == CRM_Core_Action::PROFILE) { | |
41 | $this->_pages['CRM_Contact_Form_Search_Builder'] = NULL; | |
42 | list($task, $result) = $this->taskName($controller, 'Builder'); | |
43 | } | |
191b5c81 | 44 | // @todo - this 'should' be removable but it's getting to this controller, for now |
6a488035 TO |
45 | elseif ($action == CRM_Core_Action::COPY) { |
46 | $this->_pages['CRM_Contact_Form_Search_Custom'] = NULL; | |
47 | list($task, $result) = $this->taskName($controller, 'Custom'); | |
48 | } | |
49 | else { | |
50 | $this->_pages['CRM_Contact_Form_Search_Basic'] = NULL; | |
51 | list($task, $result) = $this->taskName($controller, 'Basic'); | |
52 | } | |
53 | $this->_task = $task; | |
54 | if (is_array($task)) { | |
55 | foreach ($task as $t) { | |
56 | $this->_pages[$t] = NULL; | |
57 | } | |
58 | } | |
59 | else { | |
60 | $this->_pages[$task] = NULL; | |
61 | } | |
62 | ||
63 | if ($result) { | |
64 | $this->_pages['CRM_Contact_Form_Task_Result'] = NULL; | |
65 | } | |
66 | ||
67 | $this->addSequentialPages($this->_pages, $action); | |
68 | } | |
69 | ||
70 | /** | |
71 | * Determine the form name based on the action. This allows us | |
72 | * to avoid using conditional state machine, much more efficient | |
73 | * and simpler | |
74 | * | |
77c5b619 TO |
75 | * @param CRM_Core_Controller $controller |
76 | * The controller object. | |
6a488035 | 77 | * |
77b97be7 EM |
78 | * @param string $formName |
79 | * | |
daa78a84 | 80 | * @return array |
a6c01b45 | 81 | * the name of the form that will handle the task |
6a488035 | 82 | */ |
00be9182 | 83 | public function taskName($controller, $formName = 'Search') { |
e341bbee | 84 | // total hack, check POST vars and then session to determine stuff |
9c1bc317 | 85 | $value = $_POST['task'] ?? NULL; |
6a488035 TO |
86 | if (!isset($value)) { |
87 | $value = $this->_controller->get('task'); | |
88 | } | |
89 | $this->_controller->set('task', $value); | |
90 | ||
a6c6c64f JP |
91 | $componentMode = $this->_controller->get('component_mode'); |
92 | $modeValue = CRM_Contact_Form_Search::getModeValue($componentMode); | |
93 | $taskClassName = $modeValue['taskClassName']; | |
94 | return $taskClassName::getTask($value); | |
6a488035 TO |
95 | } |
96 | ||
97 | /** | |
fe482240 | 98 | * Return the form name of the task. |
6a488035 TO |
99 | * |
100 | * @return string | |
6a488035 | 101 | */ |
00be9182 | 102 | public function getTaskFormName() { |
6a488035 TO |
103 | if (is_array($this->_task)) { |
104 | // return first page | |
105 | return CRM_Utils_String::getClassName($this->_task[0]); | |
106 | } | |
107 | else { | |
108 | return CRM_Utils_String::getClassName($this->_task); | |
109 | } | |
110 | } | |
111 | ||
112 | /** | |
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 | |
6a488035 | 115 | */ |
00be9182 | 116 | public function shouldReset() { |
6a488035 TO |
117 | return FALSE; |
118 | } | |
96025800 | 119 | |
6a488035 | 120 | } |