24 public $mActionForm =
null;
25 public $mSearchResults = [];
26 public $mModules = [];
30 public function prepare(&$controller, &$xoopsUser)
32 $root =& $controller->mRoot;
33 $root->mLanguageManager->loadPageTypeMessageCatalog(
'search');
34 $root->mLanguageManager->loadModuleMessageCatalog(
'legacy');
36 $handler =& xoops_gethandler(
'config');
37 $this->mConfig =& $handler->getConfigsByCat(XOOPS_CONF_SEARCH);
39 $this->_setupActionForm();
42 public function _setupActionForm()
45 $this->mActionForm->prepare();
48 public function hasPermission(&$controller, &$xoopsUser)
51 if (1 != $this->mConfig[
'enable_search']) {
52 $controller->executeRedirect(XOOPS_URL .
'/', 3, _MD_LEGACY_ERROR_SEARCH_NOT_ENABLED);
58 public function _getMaxHit()
60 return LEGACY_SEARCH_RESULT_MAXHIT;
63 public function getDefaultView(&$controller, &$xoopsUser)
66 $root =& $controller->mRoot;
67 $service =& $root->mServiceManager->getService(
'LegacySearch');
69 if (is_object($service)) {
70 $client =& $root->mServiceManager->createClient($service);
71 $this->mModules = $client->call(
'getActiveModules', []);
74 $this->mActionForm->fetch();
75 $this->mActionForm->validate();
77 if ($this->mActionForm->hasError()) {
78 return LEGACY_FRAME_VIEW_INDEX;
84 if (is_object($service)) {
85 $this->mActionForm->update($params);
87 $handler =& xoops_gethandler(
'module');
88 foreach ($this->_getSelectedMids() as $mid) {
89 $t_module =& $handler->get($mid);
90 if (is_object($t_module)) {
93 $module[
'mid'] = $mid;
94 $module[
'name'] = $t_module->get(
'name');
96 $params[
'mid'] = $mid;
97 $module[
'results'] = $this->_doSearch($client, $xoopsUser, $params);
99 if ((is_countable($module[
'results']) ? count($module[
'results']) : 0) > 0) {
101 $module[
'has_more'] = (is_countable($module[
'results']) ? count($module[
'results']) : 0) >= $this->_getMaxHit();
102 $this->mSearchResults[] = $module;
107 return LEGACY_FRAME_VIEW_ERROR;
110 return LEGACY_FRAME_VIEW_INDEX;
113 public function _doSearch(&$client, &$xoopsUser, &$params)
115 $root =& XCube_Root::getSingleton();
116 $timezone = $root->mContext->getXoopsConfig(
'server_TZ') * 3600;
118 $results = $client->call(
'searchItems', $params);
123 public function execute(&$controller, &$xoopsUser)
125 return $this->getDefaultView($controller, $xoopsUser);
128 public function executeViewIndex(&$controller, &$xoopsUser, &$render)
130 $render->setTemplateName($this->_getTemplateName());
132 $render->setAttribute(
'actionForm', $this->mActionForm);
134 $render->setAttribute(
'searchResults', $this->mSearchResults);
135 $render->setAttribute(
'moduleArr', $this->mModules);
141 $render->setAttribute(
'selectedMidArr', $this->_getSelectedMids());
142 $render->setAttribute(
'searchRuleMessage', @sprintf(_SR_KEYTOOSHORT, $this->mConfig[
'keyword_min']));
145 public function _getTemplateName()
147 return 'legacy_search_results.html';
150 public function _getSelectedMids()
152 $ret = $this->mActionForm->get(
'mids');
153 if (!(is_countable($ret) ? count($ret) : 0)) {
154 foreach ($this->mModules as $module) {
155 $ret[] = $module[
'mid'];
162 public function executeViewError(&$controller, &$xoopsUser, &$render)
164 $controller->executeForward(XOOPS_URL .
'/');