XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
ActSearchAction.class.php
1<?php
12
13if (!defined('XOOPS_ROOT_PATH')) {
14 exit();
15}
16
17require_once XOOPS_LEGACY_PATH . '/admin/forms/ActionSearchForm.class.php';
18
20{
21 public $mKeywords;
22 public $mRecords;
23
24 public function __construct($words)
25 {
26 $this->setKeywords($words);
27 }
28
29 public function setKeywords($words)
30 {
31 foreach (explode(' ', $words) as $word) {
32 if ($word !== '') {
33 $this->mKeywords[] = $word;
34 }
35 }
36 }
37
38 public function getKeywords()
39 {
40 return $this->mKeywords;
41 }
42
43 public function addRecord($moduleName, $url, $title, $desc = null)
44 {
45 $this->mRecords[] =new Legacy_ActionSearchRecord($moduleName, $url, $title, $desc);
46 }
47
48 public function &getRecords()
49 {
50 return $this->mRecords;
51 }
52
56 public function hasRecord()
57 {
58 if(is_countable($this->mRecords)) {
59 return count($this->mRecords) > 0;
60 }
61 }
62
63}
64
71{
72 public $mModuleName;
73 public $mActionUrl;
74 public $mTitle;
75 public $mDescription;
76
77// TODO mDescription = $desc returns nothing !
78
79 public function __construct($moduleName, $url, $title, $desc)
80 {
81 $this->mModuleName = $moduleName;
82 $this->mActionUrl = $url;
83 $this->mTitle = $title;
84 $this->mDescription = $desc;
85 }
86}
87
88/***
89 * @internal
90 * Execute action search. Now,it returns the results of all modules that the current user can access.
91 *
92 * @todo We should return the result by the current user's permission.
93 */
94class Legacy_ActSearchAction extends Legacy_Action
95{
96 public $mModules = [];
97 public $mModuleRecords = null;
98 public $mRecords = null;
99 public $mActionForm = null;
100
101 public $mSearchAction = null;
102
103 public function __construct($flag)
104 {
105 parent::__construct($flag);
106
107 $this->mSearchAction =new XCube_Delegate();
108 $this->mSearchAction->add([&$this, 'defaultSearch']);
109 $this->mSearchAction->register('Legacy_ActSearchAction.SearchAction');
110 }
111
112 public function prepare(&$controller, &$xoopsUser)
113 {
114 parent::prepare($controller, $xoopsUser);
115
116 $db=&$controller->getDB();
117
118 $mod = $db->prefix('modules');
119 $perm = $db->prefix('group_permission');
120 $groups = implode(',', $xoopsUser->getGroups());
121
122 $sql = "SELECT DISTINCT {$mod}.weight, {$mod}.mid FROM {$mod},{$perm} " .
123 "WHERE {$mod}.isactive=1 AND {$mod}.mid={$perm}.gperm_itemid AND {$perm}.gperm_name='module_admin' AND {$perm}.gperm_groupid IN ({$groups}) " .
124 "ORDER BY {$mod}.weight, {$mod}.mid";
125
126 $result=$db->query($sql);
127
128 $handler =& xoops_gethandler('module');
129 while ($row = $db->fetchArray($result)) {
130 $module =& $handler->get($row['mid']);
131 $adapter =new Legacy_ModuleAdapter($module); // FIXMED
132
133 $this->mModules[] =& $adapter;
134
135 unset($module, $adapter);
136 }
137 }
138
139 public function hasPermission(&$controller, &$xoopsUser)
140 {
141 $permHandler =& xoops_gethandler('groupperm');
142 return $permHandler->checkRight('module_admin', -1, $xoopsUser->getGroups());
143 }
144
145 public function getDefaultView(&$controller, &$xoopsUser)
146 {
147 $this->_processActionForm();
148
149 $this->mActionForm->fetch();
150 $this->mActionForm->validate();
151
152 if ($this->mActionForm->hasError()) {
153 return LEGACY_FRAME_VIEW_INPUT;
154 }
155
156 $searchArgs =new Legacy_ActionSearchArgs($this->mActionForm->get('keywords'));
157 $this->mSearchAction->call(new XCube_Ref($searchArgs));
158
159 if ($searchArgs->hasRecord()) {
160 $this->mRecords =& $searchArgs->getRecords();
161 return LEGACY_FRAME_VIEW_SUCCESS;
162 }
163
164 return LEGACY_FRAME_VIEW_ERROR;
165 }
166
167 public function defaultSearch(&$searchArgs)
168 {
169 foreach (array_keys($this->mModules) as $key) {
170 $this->mModules[$key]->doActionSearch($searchArgs);
171 }
172 }
173
174 public function execute(&$controller, &$xoopsUser)
175 {
176 return $this->getDefaultView($controller, $xoopsUser);
177 }
178
179 public function _processActionForm()
180 {
181 $this->mActionForm =new Legacy_ActionSearchForm();
182 $this->mActionForm->prepare();
183 }
184
185 public function executeViewSuccess(&$controller, &$xoopsUser, &$render)
186 {
187 $render->setTemplateName('legacy_admin_actionsearch_success.html');
188 $render->setAttribute('records', $this->mRecords);
189 $render->setAttribute('actionForm', $this->mActionForm);
190 }
191
192 public function executeViewInput(&$controller, &$xoopsUser, &$render)
193 {
194 $render->setTemplateName('legacy_admin_actionsearch_input.html');
195 $render->setAttribute('actionForm', $this->mActionForm);
196 }
197
198 public function executeViewError(&$controller, &$xoopsUser, &$render)
199 {
200 $render->setTemplateName('legacy_admin_actionsearch_error.html');
201 $render->setAttribute('actionForm', $this->mActionForm);
202 }
203}
Used for adapting $xoopsModule to imitate XOOPS2 responses.
[Final] Used for the simple mechanism for common delegation in XCube.