Merge pull request #4822 from kurund/indentation-fixes
[civicrm-core.git] / CRM / Activity / StateMachine / Search.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License along with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
25 */
26
27 /**
28 *
29 * @package CRM
30 * @copyright CiviCRM LLC (c) 2004-2014
31 * $Id$
32 *
33 */
34 class CRM_Activity_StateMachine_Search extends CRM_Core_StateMachine {
35
36 /**
37 * The task that the wizard is currently processing
38 *
39 * @var string
40 */
41 protected $_task;
42
43 /**
44 * Class constructor
45 */
46 public function __construct($controller, $action = CRM_Core_Action::NONE) {
47 parent::__construct($controller, $action);
48
49 $this->_pages = array();
50
51 $this->_pages['CRM_Activity_Form_Search'] = NULL;
52 list($task, $result) = $this->taskName($controller, 'Search');
53 $this->_task = $task;
54
55 if (is_array($task)) {
56 foreach ($task as $t) {
57 $this->_pages[$t] = NULL;
58 }
59 }
60 else {
61 $this->_pages[$task] = NULL;
62 }
63
64 $this->addSequentialPages($this->_pages, $action);
65 }
66
67 /**
68 * Determine the form name based on the action. This allows us
69 * to avoid using conditional state machine, much more efficient
70 * and simpler
71 *
72 * @param CRM_Core_Controller $controller the controller object
73 *
74 * @param string $formName
75 *
76 * @return string the name of the form that will handle the task
77 */
78 public function taskName($controller, $formName = 'Search') {
79 // total hack, check POST vars and then session to determine stuff
80 $value = CRM_Utils_Array::value('task', $_POST);
81 if (!isset($value)) {
82 $value = $this->_controller->get('task');
83 }
84 $this->_controller->set('task', $value);
85 return CRM_Activity_Task::getTask($value);
86 }
87
88 /**
89 * Return the form name of the task
90 *
91 * @return string
92 */
93 public function getTaskFormName() {
94 return CRM_Utils_String::getClassName($this->_task);
95 }
96
97 /**
98 * Should the controller reset the session
99 * In some cases, specifically search we want to remember
100 * state across various actions and want to go back to the
101 * beginning from the final state, but retain the same session
102 * values
103 *
104 * @return boolean
105 */
106 /**
107 * @return bool
108 */
109 public function shouldReset() {
110 return FALSE;
111 }
112 }