ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLuceneUserSearchGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
30{
31 protected ilTabsGUI $tabs;
32 protected ilHelpGUI $help;
33
37 public function __construct()
38 {
39 global $DIC;
40
41 $this->tabs = $DIC->tabs();
42 $this->help = $DIC->help();
44 $this->initUserSearchCache();
45 }
46
50 public function executeCommand(): void
51 {
52 $next_class = $this->ctrl->getNextClass($this);
53 $cmd = $this->ctrl->getCmd();
54
55 $this->prepareOutput();
56 switch ($next_class) {
57 case strtolower(PublicProfileGUI::class):
58
59 $user_id = 0;
60 if ($this->http->wrapper()->query()->has('user_id')) {
61 $user_id = $this->http->wrapper()->query()->retrieve(
62 'user_id',
63 $this->refinery->kindlyTo()->int()
64 );
65 }
66 $profile = new PublicProfileGUI($user_id);
67 $profile->setBackUrl($this->ctrl->getLinkTarget($this, 'showSavedResults'));
68 $ret = $this->ctrl->forwardCommand($profile);
69 $this->tpl->setContent($ret);
70 break;
71
72
73 default:
75 if (!$cmd) {
76 $cmd = "showSavedResults";
77 }
78 $this->handleCommand($cmd);
79 break;
80 }
81 }
82
83 public function prepareOutput(): void
84 {
85 parent::prepareOutput();
86 $this->getTabs();
87 }
88
89
90
96 protected function getType(): int
97 {
99 }
100
105 protected function getDetails(): array
106 {
107 return $this->search_cache->getItemFilter();
108 }
109
110
114 protected function remoteSearch(): void
115 {
116 $root_id = 0;
117 if ($this->http->wrapper()->post()->has('root_id')) {
118 $root_id = $this->http->wrapper()->post()->retrieve(
119 'root_id',
120 $this->refinery->kindlyTo()->int()
121 );
122 }
123 $queryString = '';
124 if ($this->http->wrapper()->post()->has('queryString')) {
125 $queryString = $this->http->wrapper()->post()->retrieve(
126 'queryString',
127 $this->refinery->kindlyTo()->string()
128 );
129 }
130 $this->search_cache->setRoot($root_id);
131 $this->search_cache->setQuery($queryString);
132 $this->search_cache->save();
133 $this->search();
134 }
135
136 protected function showSavedResults(): void
137 {
138 if (strlen($this->search_cache->getQuery())) {
139 $this->performSearch();
140 return;
141 }
142
143 $this->showSearchForm();
144 }
145
149 protected function search(): void
150 {
151 if (!$this->form->checkInput()) {
152 $this->search_cache->deleteCachedEntries();
153 // Reset details
155 $this->showSearchForm();
156 return;
157 }
158 ilSession::clear('max_page');
159 $this->search_cache->deleteCachedEntries();
160
161 // Reset details
163 $this->performSearch();
164 }
165
169 protected function performSearch(): void
170 {
171 $qp = new ilLuceneQueryParser($this->search_cache->getQuery());
172 $qp->parse();
173 $searcher = ilLuceneSearcher::getInstance($qp);
174 $searcher->setType(ilLuceneSearcher::TYPE_USER);
175 $searcher->search();
176
177 $this->showSearchForm();
178
179 $user_table = new ilRepositoryUserResultTableGUI(
180 $this,
181 'performSearch',
182 false,
184 );
185 $user_table->setLuceneResult($searcher->getResult());
186 $user_table->parseUserIds($searcher->getResult()->getCandidates());
187
188 $this->tpl->setVariable('SEARCH_RESULTS', $user_table->getHTML());
189 }
190
194 protected function getTabs(): void
195 {
196 $this->help->setScreenIdComponent("src_luc");
197
198 $this->tabs->addTarget('search', $this->ctrl->getLinkTargetByClass('illucenesearchgui'));
199
200 if (ilSearchSettings::getInstance()->isLuceneUserSearchEnabled()) {
201 $this->tabs->addTarget('search_user', $this->ctrl->getLinkTargetByClass('illuceneusersearchgui'));
202 }
203
204 $this->tabs->setTabActive('search_user');
205 }
206
210 protected function initUserSearchCache(): void
211 {
212 $this->search_cache = ilUserSearchCache::_getInstance($this->user->getId());
213 $this->search_cache->switchSearchType(ilUserSearchCache::LUCENE_USER_SEARCH);
214 $page_number = $this->initPageNumberFromQuery();
215 if ($page_number) {
216 $this->search_cache->setResultPageNumber($page_number);
217 }
218
219 if ($this->http->wrapper()->post()->has('term')) {
220 $query = $this->http->wrapper()->post()->retrieve(
221 'term',
222 $this->refinery->kindlyTo()->string()
223 );
224 $this->search_cache->setQuery($query);
225 $this->search_cache->setItemFilter(array());
226 $this->search_cache->setMimeFilter(array());
227 $this->search_cache->save();
228 }
229 }
230
231
232
236 protected function showSearchForm()
237 {
238 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.lucene_usr_search.html', 'components/ILIAS/Search');
239 $this->renderSearch($this->search_cache->getQuery());
240
241 return true;
242 }
243}
GUI class for public user profile presentation.
Help GUI class.
static getInstance(ilLuceneQueryParser $qp)
Get singleton instance.
initUserSearchCache()
Init user search cache.
getType()
Get type of search (details | fast)
search()
Search (button pressed)
getDetails()
Needed for base class search form.
remoteSearch()
Search from main menu.
renderSearch(string $term, int $root_node=0)
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)
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
form( $class_path, string $cmd, string $submit_caption="")
global $DIC
Definition: shib_login.php:26