Merge pull request #15314 from jitendrapurohit/dev-1255
[civicrm-core.git] / CRM / Contribute / 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_Contribute_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.
7a9ab499
EM
28 *
29 * @param object $controller
30 * @param \const|int $action
95ea96be 31 */
971d41b1 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_Contribute_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 if ($result) {
50 $this->_pages['CRM_Contribute_Form_Task_Result'] = NULL;
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 *
014c4014
TO
60 * @param CRM_Core_Controller $controller
61 * The controller object.
6a488035 62 *
6c8f6e67
EM
63 * @param string $formName
64 *
1330f57a
SL
65 * @return array
66 * [ 'class' => task classname, 'result' => TRUE ]
a6c01b45 67 * the name of the form that will handle the task
6a488035 68 */
00be9182 69 public function taskName($controller, $formName = 'Search') {
6a488035 70 // total hack, check POST vars and then session to determine stuff
e341bbee 71 $value = CRM_Utils_Array::value('task', $_POST);
6a488035
TO
72 if (!isset($value)) {
73 $value = $this->_controller->get('task');
74 }
75 $this->_controller->set('task', $value);
76 return CRM_Contribute_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 }
87
88 /**
89 * Since this is a state machine for search and we want to come back to the same state
90 * we dont want to issue a reset of the state session when we are done processing a task
6a488035 91 */
00be9182 92 public function shouldReset() {
6a488035
TO
93 return FALSE;
94 }
96025800 95
6a488035 96}