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_Campaign_StateMachine_Search extends CRM_Core_StateMachine { | |
18 | ||
19 | /** | |
fe482240 | 20 | * The task that the wizard is currently processing. |
6a488035 TO |
21 | * |
22 | * @var string | |
6a488035 TO |
23 | */ |
24 | protected $_task; | |
25 | ||
26 | /** | |
fe482240 | 27 | * Class constructor. |
cde2037d EM |
28 | * |
29 | * @param object $controller | |
30 | * @param \const|int $action | |
95ea96be | 31 | */ |
e7483cbe | 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 | |
37 | $this->_pages['CRM_Campaign_Form_Search'] = NULL; | |
38 | list($task, $result) = $this->taskName($controller, 'Search'); | |
39 | $this->_task = $task; | |
40 | if (is_array($task)) { | |
41 | foreach ($task as $t) { | |
42 | $this->_pages[$t] = NULL; | |
43 | } | |
44 | } | |
45 | else { | |
46 | $this->_pages[$task] = NULL; | |
47 | } | |
48 | if ($result) { | |
49 | $this->_pages['CRM_Campaign_Form_Task_Result'] = NULL; | |
50 | } | |
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 | * | |
7aaf6db0 TO |
60 | * @param CRM_Core_Controller $controller |
61 | * The controller object. | |
6a488035 | 62 | * |
77b97be7 EM |
63 | * @param string $formName |
64 | * | |
daa78a84 | 65 | * @return array |
a6c01b45 | 66 | * the name of the form that will handle the task |
6a488035 | 67 | */ |
00be9182 | 68 | public function taskName($controller, $formName = 'Search') { |
6a488035 | 69 | // total hack, check POST vars and then session to determine stuff |
9c1bc317 | 70 | $value = $_POST['task'] ?? NULL; |
6a488035 TO |
71 | if (!isset($value)) { |
72 | $value = $this->_controller->get('task'); | |
73 | } | |
74 | $this->_controller->set('task', $value); | |
75 | ||
76 | return CRM_Campaign_Task::getTask($value); | |
77 | } | |
78 | ||
79 | /** | |
fe482240 | 80 | * Return the form name of the task. |
6a488035 TO |
81 | * |
82 | * @return string | |
6a488035 | 83 | */ |
00be9182 | 84 | public function getTaskFormName() { |
6a488035 TO |
85 | return CRM_Utils_String::getClassName($this->_task); |
86 | } | |
96025800 | 87 | |
6a488035 | 88 | } |