ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilLuceneUserSearchGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once './Services/Search/classes/class.ilSearchSettings.php';
5 include_once './Services/Search/classes/class.ilSearchBaseGUI.php';
6 include_once './Services/Search/classes/Lucene/class.ilLuceneAdvancedSearchFields.php';
7 
8 
21 {
22  protected $ilTabs;
23 
27  public function __construct()
28  {
29  global $ilTabs;
30 
31  $this->tabs_gui = $ilTabs;
33  $this->initUserSearchCache();
34 
35  }
36 
40  public function executeCommand()
41  {
42  global $ilBench, $ilCtrl;
43 
44  $next_class = $this->ctrl->getNextClass($this);
45  $cmd = $this->ctrl->getCmd();
46 
47  $this->prepareOutput();
48  switch($next_class)
49  {
50  case "ilpublicuserprofilegui":
51  include_once('./Services/User/classes/class.ilPublicUserProfileGUI.php');
52  $profile = new ilPublicUserProfileGUI((int) $_REQUEST['user']);
53  $profile->setBackUrl($this->ctrl->getLinkTarget($this,'showSavedResults'));
54  $ret = $ilCtrl->forwardCommand($profile);
55  $GLOBALS['tpl']->setContent($ret);
56  break;
57 
58 
59  default:
61  if(!$cmd)
62  {
63  $cmd = "showSavedResults";
64  }
65  $this->handleCommand($cmd);
66  break;
67  }
68  return true;
69  }
70 
75  public function prepareOutput()
76  {
78  $this->getTabs();
79  return true;
80  }
81 
82 
83 
89  protected function getType()
90  {
91  if(count($this->search_cache))
92  {
94  }
96  }
97 
103  protected function getDetails()
104  {
105  return (array) $this->search_cache->getItemFilter();
106  }
107 
108 
112  protected function remoteSearch()
113  {
114  $_POST['query'] = $_POST['queryString'];
115  $this->search_cache->setRoot((int) $_POST['root_id']);
116  $this->search_cache->setQuery(ilUtil::stripSlashes($_POST['queryString']));
117  $this->search_cache->save();
118 
119  $this->search();
120  }
121 
126  protected function showSavedResults()
127  {
128  global $ilUser,$ilBench;
129 
130  if(strlen($this->search_cache->getQuery()))
131  {
132  return $this->performSearch();
133  }
134 
135  return $this->showSearchForm();
136  }
137 
142  protected function search()
143  {
144  if(!$this->form->checkInput())
145  {
146  $this->search_cache->deleteCachedEntries();
147  // Reset details
148  include_once './Services/Object/classes/class.ilSubItemListGUI.php';
150  $this->showSearchForm();
151  return false;
152  }
153 
154  unset($_SESSION['max_page']);
155  $this->search_cache->deleteCachedEntries();
156 
157  // Reset details
158  include_once './Services/Object/classes/class.ilSubItemListGUI.php';
160 
161  $this->performSearch();
162  }
163 
167  protected function performSearch()
168  {
169  include_once './Services/Search/classes/Lucene/class.ilLuceneSearcher.php';
170  include_once './Services/Search/classes/Lucene/class.ilLuceneQueryParser.php';
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  include_once './Services/Search/classes/class.ilRepositoryUserResultTableGUI.php';
180  $user_table = new ilRepositoryUserResultTableGUI(
181  $this,
182  'performSearch',
183  false,
185  );
186  $user_table->setLuceneResult($searcher->getResult());
187  $user_table->parseUserIds($searcher->getResult()->getCandidates());
188 
189  $GLOBALS['tpl']->setVariable('SEARCH_RESULTS',$user_table->getHTML());
190 
191  return true;
192  }
193 
197  protected function getTabs()
198  {
199  global $ilHelp;
200 
201  $ilHelp->setScreenIdComponent("src_luc");
202 
203  $this->tabs_gui->addTarget('search',$this->ctrl->getLinkTargetByClass('illucenesearchgui'));
204 
205  if(ilSearchSettings::getInstance()->isLuceneUserSearchEnabled())
206  {
207  $this->tabs_gui->addTarget('search_user',$this->ctrl->getLinkTargetByClass('illuceneusersearchgui'));
208  }
209 
211 
212  if(
213  !ilSearchSettings::getInstance()->getHideAdvancedSearch() and
214  $fields->getActiveFields())
215  {
216  $this->tabs_gui->addTarget('search_advanced',$this->ctrl->getLinkTargetByClass('illuceneadvancedsearchgui'));
217  }
218 
219  $this->tabs_gui->setTabActive('search_user');
220  }
221 
228  protected function initUserSearchCache()
229  {
230  global $ilUser;
231 
232  include_once('Services/Search/classes/class.ilUserSearchCache.php');
233  $this->search_cache = ilUserSearchCache::_getInstance($ilUser->getId());
234  $this->search_cache->switchSearchType(ilUserSearchCache::LUCENE_USER_SEARCH);
235  if((int) $_GET['page_number'])
236  {
237  $this->search_cache->setResultPageNumber((int) $_GET['page_number']);
238  }
239  if(isset($_POST['term']))
240  {
241  $this->search_cache->setQuery(ilUtil::stripSlashes($_POST['term']));
242  $this->search_cache->setItemFilter(array());
243  $this->search_cache->setMimeFilter(array());
244  $this->search_cache->save();
245  }
246  }
247 
248 
249 
254  protected function showSearchForm()
255  {
256  global $ilCtrl, $lng;
257 
258  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.lucene_usr_search.html','Services/Search');
259 
260  // include js needed
261  include_once("./Services/UIComponent/Overlay/classes/class.ilOverlayGUI.php");
263  $this->tpl->addJavascript("./Services/Search/js/Search.js");
264 
265  $this->tpl->setVariable('FORM_ACTION',$GLOBALS['ilCtrl']->getFormAction($this,'performSearch'));
266  $this->tpl->setVariable("TERM", ilUtil::prepareFormOutput($this->search_cache->getQuery()));
267  include_once("./Services/UIComponent/Button/classes/class.ilSubmitButton.php");
269  $btn->setCommand("performSearch");
270  $btn->setCaption("search");
271  $this->tpl->setVariable("SUBMIT_BTN",$btn->render());
272 
273  return true;
274  }
275 }
276 ?>