ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSearchBaseGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once 'Services/Search/classes/class.ilSearchSettings.php';
5 include_once './Services/PersonalDesktop/interfaces/interface.ilDesktopItemHandling.php';
6 include_once './Services/Administration/interfaces/interface.ilAdministrationCommandHandling.php';
7 
23 {
24  const SEARCH_FAST = 1;
25  const SEARCH_DETAILS = 2;
26  const SEARCH_AND = 'and';
27  const SEARCH_OR = 'or';
28 
29  const SEARCH_FORM_LUCENE = 1;
31 
32  var $settings = null;
33 
34  protected $ctrl = null;
35  var $ilias = null;
36  var $lng = null;
37  var $tpl = null;
38 
43  function ilSearchBaseGUI()
44  {
45  global $ilCtrl,$ilias,$lng,$tpl,$ilMainMenu;
46 
47  $this->ilias =& $ilias;
48  $this->ctrl =& $ilCtrl;
49  $this->tpl =& $tpl;
50  $this->lng =& $lng;
51  $this->lng->loadLanguageModule('search');
52 
53  $ilMainMenu->setActive('search');
54  $this->settings =& new ilSearchSettings();
55  }
56 
57  function prepareOutput()
58  {
59  global $ilLocator, $lng;
60 
61  $this->tpl->getStandardTemplate();
62 
63 // $ilLocator->addItem($this->lng->txt('search'),$this->ctrl->getLinkTarget($this));
64 // $this->tpl->setLocator();
65 
66  //$this->tpl->setTitleIcon(ilUtil::getImagePath("icon_src_b.gif"),
67  // $lng->txt("search"));
68  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_src_b.png"),
69  "");
70  $this->tpl->setTitle($lng->txt("search"));
71 
73 
74  }
75 
79  public function initStandardSearchForm($a_mode)
80  {
81  global $lng, $ilCtrl;
82 
83  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
84  $this->form = new ilPropertyFormGUI();
85  $this->form->setOpenTag(false);
86  $this->form->setCloseTag(false);
87 
88  // term combination
89  $radg = new ilHiddenInputGUI('search_term_combination');
90  $radg->setValue(ilSearchSettings::getInstance()->getDefaultOperator());
91  $this->form->addItem($radg);
92 
103  // search area
104 /*
105  include_once("./Services/Form/classes/class.ilRepositorySelectorInputGUI.php");
106  $ti = new ilRepositorySelectorInputGUI($lng->txt("search_area"), "area");
107  $ti->setSelectText($lng->txt("search_select_search_area"));
108  $this->form->addItem($ti);
109  $ti->readFromSession();*/
110 
111  // alex, 15.8.2012: Added the following lines to get the value
112  // from the main menu top right input search form
113 /* if (isset($_POST["root_id"]))
114  {
115  $ti->setValue($_POST["root_id"]);
116  $ti->writeToSession();
117  }*/
118 
119 
120  if(ilSearchSettings::getInstance()->isLuceneItemFilterEnabled())
121  {
122  if($a_mode == self::SEARCH_FORM_STANDARD)
123  {
124  // search type
125  $radg = new ilRadioGroupInputGUI($lng->txt("search_type"), "type");
126  $radg->setValue(
127  $this->getType() ==
131  );
132  $op1 = new ilRadioOption($lng->txt("search_fast_info"), ilSearchBaseGUI::SEARCH_FAST);
133  $radg->addOption($op1);
134  $op2 = new ilRadioOption($lng->txt("search_details_info"), ilSearchBaseGUI::SEARCH_DETAILS);
135  }
136  else
137  {
138  $op2 = new ilCheckboxInputGUI($this->lng->txt('search_filter_by_type'),'item_filter_enabled');
139  $op2->setValue(1);
140 // $op2->setChecked($this->getType() == ilSearchBaseGUI::SEARCH_DETAILS);
141  }
142 
143 
144  $cbgr = new ilCheckboxGroupInputGUI('','filter_type');
145  $cbgr->setUseValuesAsKeys(true);
146  $details = $this->getDetails();
147  $det = false;
148  foreach(ilSearchSettings::getInstance()->getEnabledLuceneItemFilterDefinitions() as $type => $data)
149  {
150  $cb = new ilCheckboxOption($lng->txt($data['trans']), $type);
151  if ($details[$type])
152  {
153  $det = true;
154  }
155  $cbgr->addOption($cb);
156  }
157  $cbgr->setValue($details);
158  $op2->addSubItem($cbgr);
159 
160  if($a_mode != self::SEARCH_FORM_STANDARD && $det)
161  {
162  $op2->setChecked(true);
163  }
164 
166  {
167  $radg->addOption($op2);
168  $this->form->addItem($radg);
169  }
170  else
171  {
172  $this->form->addItem($op2);
173  }
174  }
175 
176  $this->form->setFormAction($ilCtrl->getFormAction($this,'performSearch'));
177  }
178 
182  public function getSearchAreaForm()
183  {
184  global $lng, $ilCtrl;
185 
186  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
187  $form = new ilPropertyFormGUI();
188  $form->setOpenTag(false);
189  $form->setCloseTag(false);
190 
191  // term combination
192  $radg = new ilHiddenInputGUI('search_term_combination');
193  $radg->setValue(ilSearchSettings::getInstance()->getDefaultOperator());
194  $form->addItem($radg);
195 
196  // search area
197  include_once("./Services/Form/classes/class.ilRepositorySelectorInputGUI.php");
198  $ti = new ilRepositorySelectorInputGUI($lng->txt("search_area"), "area");
199  $ti->setSelectText($lng->txt("search_select_search_area"));
200  $form->addItem($ti);
201  $ti->readFromSession();
202 
203  // alex, 15.8.2012: Added the following lines to get the value
204  // from the main menu top right input search form
205  if (isset($_POST["root_id"]))
206  {
207  $ti->setValue($_POST["root_id"]);
208  $ti->writeToSession();
209  }
210  $form->setFormAction($ilCtrl->getFormAction($this,'performSearch'));
211 
212  return $form;
213  }
214 
215 
216  public function handleCommand($a_cmd)
217  {
218  if(method_exists($this, $a_cmd))
219  {
220  $this->$a_cmd();
221  }
222  else
223  {
224  $a_cmd .= 'Object';
225  $this->$a_cmd();
226  }
227  }
228 
232  public function addToDeskObject()
233  {
234  include_once './Services/PersonalDesktop/classes/class.ilDesktopItemGUI.php';
236  $this->showSavedResults();
237  }
238 
242  public function removeFromDeskObject()
243  {
244  include_once './Services/PersonalDesktop/classes/class.ilDesktopItemGUI.php';
246  $this->showSavedResults();
247  }
248 
252  public function delete()
253  {
254  include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
255  $admin = new ilAdministrationCommandGUI($this);
256  $admin->delete();
257  }
258 
262  public function cancelDelete()
263  {
264  $this->showSavedResults();
265  }
266 
270  public function performDelete()
271  {
272  include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
273  $admin = new ilAdministrationCommandGUI($this);
274  $admin->performDelete();
275  }
276 
280  public function cut()
281  {
282 
283 
284  include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
285  $admin = new ilAdministrationCommandGUI($this);
286  $admin->cut();
287  }
288 
292  public function link()
293  {
294  include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
295  $admin = new ilAdministrationCommandGUI($this);
296  $admin->link();
297  }
298 
299  public function paste()
300  {
301  include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
302  $admin = new ilAdministrationCommandGUI($this);
303  $admin->paste();
304  }
305 
307  {
308  include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
309  $admin = new ilAdministrationCommandGUI($this);
310  $admin->showLinkIntoMultipleObjectsTree();
311  }
312 
313  public function showMoveIntoObjectTree()
314  {
315  include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
316  $admin = new ilAdministrationCommandGUI($this);
317  $admin->showMoveIntoObjectTree();
318  }
319 
321  {
322  include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
323  $admin = new ilAdministrationCommandGUI($this);
324  $admin->performPasteIntoMultipleObjects();
325  }
326 
327  public function clear()
328  {
329  unset($_SESSION['clipboard']);
330  $this->ctrl->redirect($this);
331  }
332 
333  public function enableAdministrationPanel()
334  {
335  $_SESSION["il_cont_admin_panel"] = true;
336  $this->ctrl->redirect($this);
337  }
338 
339  public function disableAdministrationPanel()
340  {
341  $_SESSION["il_cont_admin_panel"] = false;
342  $this->ctrl->redirect($this);
343  }
344 
345 
349  public function addLocator()
350  {
351  $ilLocator->addItem($this->lng->txt('search'),$this->ctrl->getLinkTarget($this));
352  $this->tpl->setLocator();
353  }
354 
362  protected function addPager($result,$a_session_key)
363  {
364  global $tpl;
365 
366  $_SESSION["$a_session_key"] = max($_SESSION["$a_session_key"],$this->search_cache->getResultPageNumber());
367 
368  if($_SESSION["$a_session_key"] == 1 and
369  (count($result->getResults()) < $result->getMaxHits()))
370  {
371  return true;
372  }
373 
374  if($this->search_cache->getResultPageNumber() > 1)
375  {
376  $this->ctrl->setParameter($this,'page_number',$this->search_cache->getResultPageNumber() - 1);
377 /* $this->tpl->setCurrentBlock('prev');
378  $this->tpl->setVariable('PREV_LINK',$this->ctrl->getLinkTarget($this,'performSearch'));
379  $this->tpl->setVariable('TXT_PREV',$this->lng->txt('search_page_prev'));
380  $this->tpl->parseCurrentBlock();
381 */
382  $this->prev_link = $this->ctrl->getLinkTarget($this,'performSearch');
383  }
384  for($i = 1;$i <= $_SESSION["$a_session_key"];$i++)
385  {
386  if($i == $this->search_cache->getResultPageNumber())
387  {
388 /* $this->tpl->setCurrentBlock('pages_link');
389  $this->tpl->setVariable('NUMBER',$i);
390  $this->tpl->parseCurrentBlock();
391 */
392  continue;
393  }
394 
395  $this->ctrl->setParameter($this,'page_number',$i);
396  $link = '<a href="'.$this->ctrl->getLinkTarget($this,'performSearch').'" /a>'.$i.'</a> ';
397 /* $this->tpl->setCurrentBlock('pages_link');
398  $this->tpl->setVariable('NUMBER',$link);
399  $this->tpl->parseCurrentBlock();
400 */
401  }
402 
403 
404  if(count($result->getResults()) >= $result->getMaxHits())
405  {
406  $this->ctrl->setParameter($this,'page_number',$this->search_cache->getResultPageNumber() + 1);
407 /* $this->tpl->setCurrentBlock('next');
408  $this->tpl->setVariable('NEXT_LINK',$this->ctrl->getLinkTarget($this,'performSearch'));
409  $this->tpl->setVariable('TXT_NEXT',$this->lng->txt('search_page_next'));
410  $this->tpl->parseCurrentBlock();
411 */
412 $this->next_link = $this->ctrl->getLinkTarget($this,'performSearch');
413  }
414 
415 /* $this->tpl->setCurrentBlock('prev_next');
416  $this->tpl->setVariable('SEARCH_PAGE',$this->lng->txt('search_page'));
417  $this->tpl->parseCurrentBlock();
418 */
419 
420  $this->ctrl->clearParameters($this);
421  }
422 
427  protected function buildSearchAreaPath($a_root_node)
428  {
429  global $tree;
430 
431  $path_arr = $tree->getPathFull($a_root_node,ROOT_FOLDER_ID);
432  $counter = 0;
433  foreach($path_arr as $data)
434  {
435  if($counter++)
436  {
437  $path .= " > ";
438  $path .= $data['title'];
439  }
440  else
441  {
442  $path .= $this->lng->txt('repository');
443  }
444 
445  }
446  return $path;
447  }
448 
452  function autoComplete()
453  {
454  $q = $_REQUEST["term"];
455  include_once("./Services/Search/classes/class.ilSearchAutoComplete.php");
456  $list = ilSearchAutoComplete::getList($q);
457  echo $list;
458  exit;
459  }
460 
461 }
462 ?>