Replace CRM_Utils_Array::value with ?? in variable assignments
[civicrm-core.git] / CRM / Activity / StateMachine / Search.php
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_Activity_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_Activity_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 $this->addSequentialPages($this->_pages, $action);
51 }
52
53 /**
54 * Determine the form name based on the action. This allows us
55 * to avoid using conditional state machine, much more efficient
56 * and simpler
57 *
58 * @param CRM_Core_Controller $controller
59 * The controller object.
60 *
61 * @param string $formName
62 *
63 * @return array
64 * the name of the form that will handle the task
65 */
66 public function taskName($controller, $formName = 'Search') {
67 // total hack, check POST vars and then session to determine stuff
68 $value = $_POST['task'] ?? NULL;
69 if (!isset($value)) {
70 $value = $this->_controller->get('task');
71 }
72 $this->_controller->set('task', $value);
73 return CRM_Activity_Task::getTask($value);
74 }
75
76 /**
77 * Return the form name of the task.
78 *
79 * @return string
80 */
81 public function getTaskFormName() {
82 return CRM_Utils_String::getClassName($this->_task);
83 }
84
85 /**
86 * Should the controller reset the session.
87 * In some cases, specifically search we want to remember
88 * state across various actions and want to go back to the
89 * beginning from the final state, but retain the same session
90 * values
91 *
92 * @return bool
93 */
94 public function shouldReset() {
95 return FALSE;
96 }
97
98 }