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_Pledge_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 | /** | |
2e2605fe EM |
27 | * Class constructor. |
28 | * | |
29 | * @param object $controller | |
30 | * @param \const|int $action | |
95ea96be | 31 | */ |
acb1052e | 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_Pledge_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 | ||
50 | if ($result) { | |
51 | $this->_pages['CRM_Pledge_Form_Task_Result'] = NULL; | |
52 | } | |
53 | ||
54 | $this->addSequentialPages($this->_pages, $action); | |
55 | } | |
56 | ||
57 | /** | |
58 | * Determine the form name based on the action. This allows us | |
59 | * to avoid using conditional state machine, much more efficient | |
60 | * and simpler | |
61 | * | |
3a1617b6 TO |
62 | * @param CRM_Core_Controller $controller |
63 | * The controller object. | |
6a488035 | 64 | * |
77b97be7 EM |
65 | * @param string $formName |
66 | * | |
daa78a84 | 67 | * @return array |
a6c01b45 | 68 | * the name of the form that will handle the task |
6a488035 | 69 | */ |
00be9182 | 70 | public function taskName($controller, $formName = 'Search') { |
6a488035 | 71 | // total hack, check POST vars and then session to determine stuff |
9c1bc317 | 72 | $value = $_POST['task'] ?? NULL; |
6a488035 TO |
73 | if (!isset($value)) { |
74 | $value = $this->_controller->get('task'); | |
75 | } | |
76 | $this->_controller->set('task', $value); | |
77 | return CRM_Pledge_Task::getTask($value); | |
78 | } | |
79 | ||
80 | /** | |
fe482240 | 81 | * Return the form name of the task. |
6a488035 TO |
82 | * |
83 | * @return string | |
6a488035 | 84 | */ |
00be9182 | 85 | public function getTaskFormName() { |
6a488035 TO |
86 | return CRM_Utils_String::getClassName($this->_task); |
87 | } | |
88 | ||
89 | /** | |
90 | * Since this is a state machine for search and we want to come back to the same state | |
91 | * we dont want to issue a reset of the state session when we are done processing a task | |
6a488035 | 92 | */ |
00be9182 | 93 | public function shouldReset() { |
6a488035 TO |
94 | return FALSE; |
95 | } | |
96025800 | 96 | |
6a488035 | 97 | } |