ILIAS  release_8 Revision v8.24
class.ilLuceneUserSearchGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
5
6
7
19{
20 protected ilTabsGUI $tabs;
21 protected ilHelpGUI $help;
22
26 public function __construct()
27 {
28 global $DIC;
29
30 $this->tabs = $DIC->tabs();
31 $this->help = $DIC->help();
33 $this->initUserSearchCache();
34 }
35
39 public function executeCommand(): void
40 {
41 $next_class = $this->ctrl->getNextClass($this);
42 $cmd = $this->ctrl->getCmd();
43
44 $this->prepareOutput();
45 switch ($next_class) {
46 case "ilpublicuserprofilegui":
47
48 $user_id = 0;
49 if ($this->http->wrapper()->query()->has('user_id')) {
50 $user_id = $this->http->wrapper()->query()->retrieve(
51 'user_id',
52 $this->refinery->kindlyTo()->int()
53 );
54 }
55 $profile = new ilPublicUserProfileGUI($user_id);
56 $profile->setBackUrl($this->ctrl->getLinkTarget($this, 'showSavedResults'));
57 $ret = $this->ctrl->forwardCommand($profile);
58 $this->tpl->setContent($ret);
59 break;
60
61
62 default:
64 if (!$cmd) {
65 $cmd = "showSavedResults";
66 }
67 $this->handleCommand($cmd);
68 break;
69 }
70 }
71
72 public function prepareOutput(): void
73 {
74 parent::prepareOutput();
75 $this->getTabs();
76 }
77
78
79
85 protected function getType(): int
86 {
88 }
89
94 protected function getDetails(): array
95 {
96 return $this->search_cache->getItemFilter();
97 }
98
99
103 protected function remoteSearch(): void
104 {
105 $root_id = 0;
106 if ($this->http->wrapper()->post()->has('root_id')) {
107 $root_id = $this->http->wrapper()->post()->retrieve(
108 'root_id',
109 $this->refinery->kindlyTo()->int()
110 );
111 }
112 $queryString = '';
113 if ($this->http->wrapper()->post()->has('queryString')) {
114 $queryString = $this->http->wrapper()->post()->retrieve(
115 'queryString',
116 $this->refinery->kindlyTo()->string()
117 );
118 }
119 $this->search_cache->setRoot($root_id);
120 $this->search_cache->setQuery($queryString);
121 $this->search_cache->save();
122 $this->search();
123 }
124
129 protected function showSavedResults(): void
130 {
131 if (strlen($this->search_cache->getQuery())) {
132 $this->performSearch();
133 return;
134 }
135
136 $this->showSearchForm();
137 }
138
143 protected function search(): void
144 {
145 if (!$this->form->checkInput()) {
146 $this->search_cache->deleteCachedEntries();
147 // Reset details
149 $this->showSearchForm();
150 return;
151 }
152 ilSession::clear('max_page');
153 $this->search_cache->deleteCachedEntries();
154
155 // Reset details
157 $this->performSearch();
158 }
159
163 protected function performSearch(): void
164 {
165 $qp = new ilLuceneQueryParser($this->search_cache->getQuery());
166 $qp->parse();
167 $searcher = ilLuceneSearcher::getInstance($qp);
168 $searcher->setType(ilLuceneSearcher::TYPE_USER);
169 $searcher->search();
170
171 $this->showSearchForm();
172
173 $user_table = new ilRepositoryUserResultTableGUI(
174 $this,
175 'performSearch',
176 false,
178 );
179 $user_table->setLuceneResult($searcher->getResult());
180 $user_table->parseUserIds($searcher->getResult()->getCandidates());
181
182 $this->tpl->setVariable('SEARCH_RESULTS', $user_table->getHTML());
183 }
184
188 protected function getTabs(): void
189 {
190 $this->help->setScreenIdComponent("src_luc");
191
192 $this->tabs->addTarget('search', $this->ctrl->getLinkTargetByClass('illucenesearchgui'));
193
194 if (ilSearchSettings::getInstance()->isLuceneUserSearchEnabled()) {
195 $this->tabs->addTarget('search_user', $this->ctrl->getLinkTargetByClass('illuceneusersearchgui'));
196 }
197
199
200 if (
201 !ilSearchSettings::getInstance()->getHideAdvancedSearch() and
202 $fields->getActiveFields()) {
203 $this->tabs->addTarget('search_advanced', $this->ctrl->getLinkTargetByClass('illuceneadvancedsearchgui'));
204 }
205
206 $this->tabs->setTabActive('search_user');
207 }
208
212 protected function initUserSearchCache(): void
213 {
214 $this->search_cache = ilUserSearchCache::_getInstance($this->user->getId());
215 $this->search_cache->switchSearchType(ilUserSearchCache::LUCENE_USER_SEARCH);
216 $page_number = $this->initPageNumberFromQuery();
217 if ($page_number) {
218 $this->search_cache->setResultPageNumber($page_number);
219 }
220
221 if ($this->http->wrapper()->post()->has('term')) {
222 $query = $this->http->wrapper()->post()->retrieve(
223 'term',
224 $this->refinery->kindlyTo()->string()
225 );
226 $this->search_cache->setQuery($query);
227 $this->search_cache->setItemFilter(array());
228 $this->search_cache->setMimeFilter(array());
229 $this->search_cache->save();
230 }
231 }
232
233
234
239 protected function showSearchForm()
240 {
241 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.lucene_usr_search.html', 'Services/Search');
242
243 ilOverlayGUI::initJavascript();
244 $this->tpl->addJavascript("./Services/Search/js/Search.js");
245
246 $this->tpl->setVariable('FORM_ACTION', $this->ctrl->getFormAction($this, 'performSearch'));
247 $this->tpl->setVariable("TERM", ilLegacyFormElementsUtil::prepareFormOutput($this->search_cache->getQuery()));
248 $this->tpl->setVariable("SEARCH_LABEL", $this->lng->txt("search"));
250 $btn->setCommand("performSearch");
251 $btn->setCaption("search");
252 $this->tpl->setVariable("SUBMIT_BTN", $btn->render());
253
254 return true;
255 }
256}
Help GUI class.
static prepareFormOutput($a_str, bool $a_strip=false)
static getInstance(ilLuceneQueryParser $qp)
Get singleton instance.
@classDescription GUI for Lucene user search
initUserSearchCache()
Init user search cache.
getType()
Get type of search (details | fast)
showSavedResults()
Show saved results.
search()
Search (button pressed)
getDetails()
Needed for base class search form.
remoteSearch()
Search from main menu.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
initStandardSearchForm(int $a_mode)
handleCommand(string $a_cmd)
static clear(string $a_var)
static resetDetails()
As long as static::resetDetails is not possible this method is final.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getInstance(int $a_usr_id)
global $DIC
Definition: feed.php:28
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
form( $class_path, string $cmd)
$query