Merge pull request #16447 from samuelsov/lab#1319
[civicrm-core.git] / CRM / Grant / 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 * $Id$
17 *
18 */
19class CRM_Grant_StateMachine_Search extends CRM_Core_StateMachine {
20
21 /**
fe482240 22 * The task that the wizard is currently processing.
6a488035
TO
23 *
24 * @var string
6a488035
TO
25 */
26 protected $_task;
27
28 /**
fe482240 29 * Class constructor.
ca87146b
EM
30 *
31 * @param object $controller
32 * @param \const|int $action
95ea96be 33 */
bed98343 34 public function __construct($controller, $action = CRM_Core_Action::NONE) {
6a488035
TO
35 parent::__construct($controller, $action);
36
be2fb01f 37 $this->_pages = [];
6a488035
TO
38
39 $this->_pages['CRM_Grant_Form_Search'] = NULL;
40 list($task, $result) = $this->taskName($controller, 'Search');
41 $this->_task = $task;
42
43 if (is_array($task)) {
44 foreach ($task as $t) {
45 $this->_pages[$t] = NULL;
46 }
47 }
48 else {
49 $this->_pages[$task] = NULL;
50 }
51
52 if ($result) {
53 $this->_pages['CRM_Grant_Form_Task_Result'] = NULL;
54 }
55
56 $this->addSequentialPages($this->_pages, $action);
57 }
58
59 /**
60 * Determine the form name based on the action. This allows us
61 * to avoid using conditional state machine, much more efficient
62 * and simpler
63 *
85511635
TO
64 * @param CRM_Core_Controller $controller
65 * The controller object.
6a488035 66 *
77b97be7
EM
67 * @param string $formName
68 *
daa78a84 69 * @return array
a6c01b45 70 * the name of the form that will handle the task
6a488035 71 */
00be9182 72 public function taskName($controller, $formName = 'Search') {
6a488035 73 // total hack, check POST vars and then session to determine stuff
e341bbee 74 $value = CRM_Utils_Array::value('task', $_POST);
6a488035
TO
75 if (!isset($value)) {
76 $value = $this->_controller->get('task');
77 }
78 $this->_controller->set('task', $value);
79
80 return CRM_Grant_Task::getTask($value);
81 }
82
83 /**
fe482240 84 * Return the form name of the task.
6a488035
TO
85 *
86 * @return string
6a488035 87 */
00be9182 88 public function getTaskFormName() {
6a488035
TO
89 return CRM_Utils_String::getClassName($this->_task);
90 }
96025800 91
6a488035 92}