Merge pull request #16584 from eileenmcnaughton/role
[civicrm-core.git] / CRM / Contact / StateMachine / Search.php
CommitLineData
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 */
17class 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 }
44 elseif ($action == CRM_Core_Action::COPY) {
45 $this->_pages['CRM_Contact_Form_Search_Custom'] = NULL;
46 list($task, $result) = $this->taskName($controller, 'Custom');
47 }
48 else {
49 $this->_pages['CRM_Contact_Form_Search_Basic'] = NULL;
50 list($task, $result) = $this->taskName($controller, 'Basic');
51 }
52 $this->_task = $task;
53 if (is_array($task)) {
54 foreach ($task as $t) {
55 $this->_pages[$t] = NULL;
56 }
57 }
58 else {
59 $this->_pages[$task] = NULL;
60 }
61
62 if ($result) {
63 $this->_pages['CRM_Contact_Form_Task_Result'] = NULL;
64 }
65
66 $this->addSequentialPages($this->_pages, $action);
67 }
68
69 /**
70 * Determine the form name based on the action. This allows us
71 * to avoid using conditional state machine, much more efficient
72 * and simpler
73 *
77c5b619
TO
74 * @param CRM_Core_Controller $controller
75 * The controller object.
6a488035 76 *
77b97be7
EM
77 * @param string $formName
78 *
daa78a84 79 * @return array
a6c01b45 80 * the name of the form that will handle the task
6a488035 81 */
00be9182 82 public function taskName($controller, $formName = 'Search') {
e341bbee 83 // total hack, check POST vars and then session to determine stuff
9c1bc317 84 $value = $_POST['task'] ?? NULL;
6a488035
TO
85 if (!isset($value)) {
86 $value = $this->_controller->get('task');
87 }
88 $this->_controller->set('task', $value);
89
a6c6c64f
JP
90 $componentMode = $this->_controller->get('component_mode');
91 $modeValue = CRM_Contact_Form_Search::getModeValue($componentMode);
92 $taskClassName = $modeValue['taskClassName'];
93 return $taskClassName::getTask($value);
6a488035
TO
94 }
95
96 /**
fe482240 97 * Return the form name of the task.
6a488035
TO
98 *
99 * @return string
6a488035 100 */
00be9182 101 public function getTaskFormName() {
6a488035
TO
102 if (is_array($this->_task)) {
103 // return first page
104 return CRM_Utils_String::getClassName($this->_task[0]);
105 }
106 else {
107 return CRM_Utils_String::getClassName($this->_task);
108 }
109 }
110
111 /**
112 * Since this is a state machine for search and we want to come back to the same state
113 * we dont want to issue a reset of the state session when we are done processing a task
6a488035 114 */
00be9182 115 public function shouldReset() {
6a488035
TO
116 return FALSE;
117 }
96025800 118
6a488035 119}