ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilLuceneUserSearchGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
28 {
29  protected ilTabsGUI $tabs;
30  protected ilHelpGUI $help;
31 
35  public function __construct()
36  {
37  global $DIC;
38 
39  $this->tabs = $DIC->tabs();
40  $this->help = $DIC->help();
42  $this->initUserSearchCache();
43  }
44 
48  public function executeCommand(): void
49  {
50  $next_class = $this->ctrl->getNextClass($this);
51  $cmd = $this->ctrl->getCmd();
52 
53  $this->prepareOutput();
54  switch ($next_class) {
55  case "ilpublicuserprofilegui":
56 
57  $user_id = 0;
58  if ($this->http->wrapper()->query()->has('user_id')) {
59  $user_id = $this->http->wrapper()->query()->retrieve(
60  'user_id',
61  $this->refinery->kindlyTo()->int()
62  );
63  }
64  $profile = new ilPublicUserProfileGUI($user_id);
65  $profile->setBackUrl($this->ctrl->getLinkTarget($this, 'showSavedResults'));
66  $ret = $this->ctrl->forwardCommand($profile);
67  $this->tpl->setContent($ret);
68  break;
69 
70 
71  default:
73  if (!$cmd) {
74  $cmd = "showSavedResults";
75  }
76  $this->handleCommand($cmd);
77  break;
78  }
79  }
80 
81  public function prepareOutput(): void
82  {
83  parent::prepareOutput();
84  $this->getTabs();
85  }
86 
87 
88 
94  protected function getType(): int
95  {
96  return self::SEARCH_DETAILS;
97  }
98 
103  protected function getDetails(): array
104  {
105  return $this->search_cache->getItemFilter();
106  }
107 
108 
112  protected function remoteSearch(): void
113  {
114  $root_id = 0;
115  if ($this->http->wrapper()->post()->has('root_id')) {
116  $root_id = $this->http->wrapper()->post()->retrieve(
117  'root_id',
118  $this->refinery->kindlyTo()->int()
119  );
120  }
121  $queryString = '';
122  if ($this->http->wrapper()->post()->has('queryString')) {
123  $queryString = $this->http->wrapper()->post()->retrieve(
124  'queryString',
125  $this->refinery->kindlyTo()->string()
126  );
127  }
128  $this->search_cache->setRoot($root_id);
129  $this->search_cache->setQuery($queryString);
130  $this->search_cache->save();
131  $this->search();
132  }
133 
134  protected function showSavedResults(): void
135  {
136  if (strlen($this->search_cache->getQuery())) {
137  $this->performSearch();
138  return;
139  }
140 
141  $this->showSearchForm();
142  }
143 
147  protected function search(): void
148  {
149  if (!$this->form->checkInput()) {
150  $this->search_cache->deleteCachedEntries();
151  // Reset details
153  $this->showSearchForm();
154  return;
155  }
156  ilSession::clear('max_page');
157  $this->search_cache->deleteCachedEntries();
158 
159  // Reset details
161  $this->performSearch();
162  }
163 
167  protected function performSearch(): void
168  {
169  $qp = new ilLuceneQueryParser($this->search_cache->getQuery());
170  $qp->parse();
171  $searcher = ilLuceneSearcher::getInstance($qp);
172  $searcher->setType(ilLuceneSearcher::TYPE_USER);
173  $searcher->search();
174 
175  $this->showSearchForm();
176 
177  $user_table = new ilRepositoryUserResultTableGUI(
178  $this,
179  'performSearch',
180  false,
182  );
183  $user_table->setLuceneResult($searcher->getResult());
184  $user_table->parseUserIds($searcher->getResult()->getCandidates());
185 
186  $this->tpl->setVariable('SEARCH_RESULTS', $user_table->getHTML());
187  }
188 
192  protected function getTabs(): void
193  {
194  $this->help->setScreenIdComponent("src_luc");
195 
196  $this->tabs->addTarget('search', $this->ctrl->getLinkTargetByClass('illucenesearchgui'));
197 
198  if (ilSearchSettings::getInstance()->isLuceneUserSearchEnabled()) {
199  $this->tabs->addTarget('search_user', $this->ctrl->getLinkTargetByClass('illuceneusersearchgui'));
200  }
201 
202  $this->tabs->setTabActive('search_user');
203  }
204 
208  protected function initUserSearchCache(): void
209  {
210  $this->search_cache = ilUserSearchCache::_getInstance($this->user->getId());
211  $this->search_cache->switchSearchType(ilUserSearchCache::LUCENE_USER_SEARCH);
212  $page_number = $this->initPageNumberFromQuery();
213  if ($page_number) {
214  $this->search_cache->setResultPageNumber($page_number);
215  }
216 
217  if ($this->http->wrapper()->post()->has('term')) {
218  $query = $this->http->wrapper()->post()->retrieve(
219  'term',
220  $this->refinery->kindlyTo()->string()
221  );
222  $this->search_cache->setQuery($query);
223  $this->search_cache->setItemFilter(array());
224  $this->search_cache->setMimeFilter(array());
225  $this->search_cache->save();
226  }
227  }
228 
229 
230 
234  protected function showSearchForm()
235  {
236  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.lucene_usr_search.html', 'components/ILIAS/Search');
237  $this->renderSearch($this->search_cache->getQuery());
238 
239  return true;
240  }
241 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
parse()
parse query string
search()
Search (button pressed)
static _getInstance(int $a_usr_id)
Help GUI class.
static getInstance(ilLuceneQueryParser $qp)
Get singleton instance.
handleCommand(string $a_cmd)
static resetDetails()
As long as static::resetDetails is not possible this method is final.
initUserSearchCache()
Init user search cache.
GUI class for public user profile presentation.
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:26
renderSearch(string $term, int $root_node=0)
form( $class_path, string $cmd, string $submit_caption="")
remoteSearch()
Search from main menu.
initStandardSearchForm(int $a_mode)
__construct(Container $dic, ilPlugin $plugin)
static clear(string $a_var)
getType()
Get type of search (details | fast)
getDetails()
Needed for base class search form.