ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilLuceneUserSearchGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23use ILIAS\Refinery\Factory as Refinery;
24
32{
34
35 protected ilCtrl $ctrl;
36 protected ilLanguage $lng;
38 protected ilObjUser $user;
40 protected Refinery $refinery;
41 protected ilTabsGUI $tabs;
42 protected ilHelpGUI $help;
43
47 public function __construct()
48 {
49 global $DIC;
50
51 $this->tabs = $DIC->tabs();
52 $this->help = $DIC->help();
53 $this->ctrl = $DIC->ctrl();
54 $this->lng = $DIC->language();
55 $this->lng->loadLanguageModule('search');
56 $this->tpl = $DIC->ui()->mainTemplate();
57 $this->user = $DIC->user();
58 $this->http = $DIC->http();
59 $this->refinery = $DIC->refinery();
60 $this->initUserSearchCache();
61 }
62
66 public function executeCommand(): void
67 {
68 $next_class = $this->ctrl->getNextClass($this);
69 $cmd = $this->ctrl->getCmd();
70
71 $this->prepareOutput();
72 switch ($next_class) {
73 case strtolower(PublicProfileGUI::class):
74
75 $user_id = 0;
76 if ($this->http->wrapper()->query()->has('user_id')) {
77 $user_id = $this->http->wrapper()->query()->retrieve(
78 'user_id',
79 $this->refinery->kindlyTo()->int()
80 );
81 }
82 $profile = new PublicProfileGUI($user_id);
83 $profile->setBackUrl($this->ctrl->getLinkTarget($this, 'showSavedResults'));
84 $ret = $this->ctrl->forwardCommand($profile);
85 $this->tpl->setContent($ret);
86 break;
87
88
89 default:
90 if (!$cmd) {
91 $cmd = "showSavedResults";
92 }
93 $this->$cmd();
94 break;
95 }
96 }
97
98 protected function prepareOutput(): void
99 {
100 $this->tpl->loadStandardTemplate();
101
102 $this->tpl->setTitleIcon(
103 ilObject::_getIcon(0, "big", "src"),
104 ""
105 );
106 $this->tpl->setTitle($this->lng->txt("search"));
107
108 $this->getTabs();
109 }
110
111 protected function getTabs(): void
112 {
113 $this->help->setScreenIdComponent('src_luc');
114
115 $this->tabs->addTarget('search', $this->ctrl->getLinkTargetByClass(ilSearchGUI::class));
116
117 if (ilSearchSettings::getInstance()->isLuceneUserSearchEnabled()) {
118 $this->tabs->addTarget('search_user', $this->ctrl->getLinkTargetByClass(ilLuceneUserSearchGUI::class));
119 }
120
121 $this->tabs->setTabActive('search_user');
122 }
123
124
128 protected function remoteSearch(): void
129 {
130 $root_id = 0;
131 if ($this->http->wrapper()->post()->has('root_id')) {
132 $root_id = $this->http->wrapper()->post()->retrieve(
133 'root_id',
134 $this->refinery->kindlyTo()->int()
135 );
136 }
137 $queryString = '';
138 if ($this->http->wrapper()->post()->has('queryString')) {
139 $queryString = $this->http->wrapper()->post()->retrieve(
140 'queryString',
141 $this->refinery->kindlyTo()->string()
142 );
143 }
144 $this->search_cache->setRoot($root_id);
145 $this->search_cache->setQuery($queryString);
146 $this->search_cache->save();
147 $this->search();
148 }
149
150 protected function showSavedResults(): void
151 {
152 if (strlen($this->search_cache->getQuery())) {
153 $this->performSearch();
154 return;
155 }
156
157 $this->showSearchForm();
158 }
159
163 protected function search(): void
164 {
165 $this->search_cache->deleteCachedEntries();
166 $this->performSearch();
167 }
168
172 protected function performSearch(): void
173 {
174 $qp = new ilLuceneQueryParser($this->search_cache->getQuery());
175 $qp->parse();
176 $searcher = ilLuceneSearcher::getInstance($qp);
177 $searcher->setType(ilLuceneSearcher::TYPE_USER);
178 $searcher->search();
179
180 $this->showSearchForm();
181
182 $user_table = new ilRepositoryUserResultTableGUI(
183 $this,
184 'performSearch',
185 false,
187 );
188 $user_table->setLuceneResult($searcher->getResult());
189 $user_table->parseUserIds($searcher->getResult()->getCandidates());
190
191 $this->tpl->setVariable('SEARCH_RESULTS', $user_table->getHTML());
192 }
193
194 protected function initUserSearchCache(): void
195 {
196 $this->search_cache = ilUserSearchCache::_getInstance($this->user->getId());
197 $this->search_cache->switchSearchType(ilUserSearchCache::LUCENE_USER_SEARCH);
198
199 if ($this->http->wrapper()->post()->has('term')) {
200 $query = $this->http->wrapper()->post()->retrieve(
201 'term',
202 $this->refinery->kindlyTo()->string()
203 );
204 $this->search_cache->setQuery($query);
205 $this->search_cache->setItemFilter([]);
206 $this->search_cache->setMimeFilter([]);
207 $this->search_cache->save();
208 }
209 }
210
211 protected function showSearchForm()
212 {
213 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.lucene_usr_search.html', 'components/ILIAS/Search');
214 $this->tpl->addJavascript("assets/js/Search.js");
215
216 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "performSearch"));
217 $this->tpl->setVariable("TERM", ilLegacyFormElementsUtil::prepareFormOutput($this->search_cache->getQuery()));
218 $this->tpl->setVariable("SEARCH_LABEL", $this->lng->txt("search"));
220 $btn->setCommand("performSearch");
221 $btn->setCaption("search");
222 $this->tpl->setVariable("SUBMIT_BTN", $btn->render());
223 }
224}
Builds data types.
Definition: Factory.php:36
GUI class for public user profile presentation.
Class ilCtrl provides processing control methods.
Help GUI class.
language handling
static prepareFormOutput($a_str, bool $a_strip=false)
static getInstance(ilLuceneQueryParser $qp)
Get singleton instance.
ilGlobalTemplateInterface $tpl
search()
Search (button pressed)
remoteSearch()
Search from main menu.
User class.
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class for storing search result.
static _getInstance(int $a_usr_id)
Interface GlobalHttpState.
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:26