ILIAS  Release_4_4_x_branch Revision 61816
 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  const SEARCH_FORM_USER = 3;
32 
33  var $settings = null;
34 
35  protected $ctrl = null;
36  var $ilias = null;
37  var $lng = null;
38  var $tpl = null;
39 
44  function ilSearchBaseGUI()
45  {
46  global $ilCtrl,$ilias,$lng,$tpl,$ilMainMenu;
47 
48  $this->ilias =& $ilias;
49  $this->ctrl =& $ilCtrl;
50  $this->tpl =& $tpl;
51  $this->lng =& $lng;
52  $this->lng->loadLanguageModule('search');
53 
54  $ilMainMenu->setActive('search');
55  $this->settings =& new ilSearchSettings();
56  }
57 
58  function prepareOutput()
59  {
60  global $ilLocator, $lng;
61 
62  $this->tpl->getStandardTemplate();
63 
64 // $ilLocator->addItem($this->lng->txt('search'),$this->ctrl->getLinkTarget($this));
65 // $this->tpl->setLocator();
66 
67  //$this->tpl->setTitleIcon(ilUtil::getImagePath("icon_src_b.gif"),
68  // $lng->txt("search"));
69  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_src_b.png"),
70  "");
71  $this->tpl->setTitle($lng->txt("search"));
72 
74 
75  }
76 
80  public function initStandardSearchForm($a_mode)
81  {
82  global $lng, $ilCtrl;
83 
84  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
85  $this->form = new ilPropertyFormGUI();
86  $this->form->setOpenTag(false);
87  $this->form->setCloseTag(false);
88 
89  // term combination
90  $radg = new ilHiddenInputGUI('search_term_combination');
91  $radg->setValue(ilSearchSettings::getInstance()->getDefaultOperator());
92  $this->form->addItem($radg);
93 
94  if(ilSearchSettings::getInstance()->isLuceneItemFilterEnabled())
95  {
96  if($a_mode == self::SEARCH_FORM_STANDARD)
97  {
98  // search type
99  $radg = new ilRadioGroupInputGUI($lng->txt("search_type"), "type");
100  $radg->setValue(
101  $this->getType() ==
105  );
106  $op1 = new ilRadioOption($lng->txt("search_fast_info"), ilSearchBaseGUI::SEARCH_FAST);
107  $radg->addOption($op1);
108  $op2 = new ilRadioOption($lng->txt("search_details_info"), ilSearchBaseGUI::SEARCH_DETAILS);
109  }
110  else
111  {
112  $op2 = new ilCheckboxInputGUI($this->lng->txt('search_filter_by_type'),'item_filter_enabled');
113  $op2->setValue(1);
114 // $op2->setChecked($this->getType() == ilSearchBaseGUI::SEARCH_DETAILS);
115  }
116 
117 
118  $cbgr = new ilCheckboxGroupInputGUI('','filter_type');
119  $cbgr->setUseValuesAsKeys(true);
120  $details = $this->getDetails();
121  $det = false;
122  foreach(ilSearchSettings::getInstance()->getEnabledLuceneItemFilterDefinitions() as $type => $data)
123  {
124  $cb = new ilCheckboxOption($lng->txt($data['trans']), $type);
125  if ($details[$type])
126  {
127  $det = true;
128  }
129  $cbgr->addOption($cb);
130  }
131  if($a_mode == self::SEARCH_FORM_LUCENE)
132  {
133  if(ilSearchSettings::getInstance()->isLuceneMimeFilterEnabled())
134  {
135  $mimes = $this->getMimeDetails();
136  foreach(ilSearchSettings::getInstance()->getEnabledLuceneMimeFilterDefinitions() as $type => $data)
137  {
138  $op3 = new ilCheckboxOption($this->lng->txt($data['trans']),$type);
139  if($mimes[$type])
140  {
141  $det = true;
142  }
143  $cbgr->addOption($op3);
144  }
145  }
146  }
147 
148  $cbgr->setValue(array_merge((array) $details,(array) $mimes));
149  $op2->addSubItem($cbgr);
150 
151  if($a_mode != self::SEARCH_FORM_STANDARD && $det)
152  {
153  $op2->setChecked(true);
154  }
155 
157  {
158  $radg->addOption($op2);
159  $this->form->addItem($radg);
160  }
161  else
162  {
163  $this->form->addItem($op2);
164  }
165  }
166 
167  $this->form->setFormAction($ilCtrl->getFormAction($this,'performSearch'));
168  }
169 
173  public function getSearchAreaForm()
174  {
175  global $lng, $ilCtrl;
176 
177  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
178  $form = new ilPropertyFormGUI();
179  $form->setOpenTag(false);
180  $form->setCloseTag(false);
181 
182  // term combination
183  $radg = new ilHiddenInputGUI('search_term_combination');
184  $radg->setValue(ilSearchSettings::getInstance()->getDefaultOperator());
185  $form->addItem($radg);
186 
187  // search area
188  include_once("./Services/Form/classes/class.ilRepositorySelectorInputGUI.php");
189  $ti = new ilRepositorySelectorInputGUI($lng->txt("search_area"), "area");
190  $ti->setSelectText($lng->txt("search_select_search_area"));
191  $form->addItem($ti);
192  $ti->readFromSession();
193 
194  // alex, 15.8.2012: Added the following lines to get the value
195  // from the main menu top right input search form
196  if (isset($_POST["root_id"]))
197  {
198  $ti->setValue($_POST["root_id"]);
199  $ti->writeToSession();
200  }
201  $form->setFormAction($ilCtrl->getFormAction($this,'performSearch'));
202 
203  return $form;
204  }
205 
206 
211  public function handleCommand($a_cmd)
212  {
213  if(method_exists($this, $a_cmd))
214  {
215  $this->$a_cmd();
216  }
217  else
218  {
219  $a_cmd .= 'Object';
220  $this->$a_cmd();
221  }
222  }
223 
227  public function addToDeskObject()
228  {
229  include_once './Services/PersonalDesktop/classes/class.ilDesktopItemGUI.php';
231  $this->showSavedResults();
232  }
233 
237  public function removeFromDeskObject()
238  {
239  include_once './Services/PersonalDesktop/classes/class.ilDesktopItemGUI.php';
241  $this->showSavedResults();
242  }
243 
247  public function delete()
248  {
249  include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
250  $admin = new ilAdministrationCommandGUI($this);
251  $admin->delete();
252  }
253 
257  public function cancelDelete()
258  {
259  $this->showSavedResults();
260  }
261 
265  public function performDelete()
266  {
267  include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
268  $admin = new ilAdministrationCommandGUI($this);
269  $admin->performDelete();
270  }
271 
275  public function cut()
276  {
277 
278 
279  include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
280  $admin = new ilAdministrationCommandGUI($this);
281  $admin->cut();
282  }
283 
287  public function link()
288  {
289  include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
290  $admin = new ilAdministrationCommandGUI($this);
291  $admin->link();
292  }
293 
294  public function paste()
295  {
296  include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
297  $admin = new ilAdministrationCommandGUI($this);
298  $admin->paste();
299  }
300 
302  {
303  include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
304  $admin = new ilAdministrationCommandGUI($this);
305  $admin->showLinkIntoMultipleObjectsTree();
306  }
307 
308  public function showMoveIntoObjectTree()
309  {
310  include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
311  $admin = new ilAdministrationCommandGUI($this);
312  $admin->showMoveIntoObjectTree();
313  }
314 
316  {
317  include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
318  $admin = new ilAdministrationCommandGUI($this);
319  $admin->performPasteIntoMultipleObjects();
320  }
321 
322  public function clear()
323  {
324  unset($_SESSION['clipboard']);
325  $this->ctrl->redirect($this);
326  }
327 
328  public function enableAdministrationPanel()
329  {
330  $_SESSION["il_cont_admin_panel"] = true;
331  $this->ctrl->redirect($this);
332  }
333 
334  public function disableAdministrationPanel()
335  {
336  $_SESSION["il_cont_admin_panel"] = false;
337  $this->ctrl->redirect($this);
338  }
339 
340 
344  public function addLocator()
345  {
346  $ilLocator->addItem($this->lng->txt('search'),$this->ctrl->getLinkTarget($this));
347  $this->tpl->setLocator();
348  }
349 
357  protected function addPager($result,$a_session_key)
358  {
359  global $tpl;
360 
361  $_SESSION["$a_session_key"] = max($_SESSION["$a_session_key"],$this->search_cache->getResultPageNumber());
362 
363  if($_SESSION["$a_session_key"] == 1 and
364  (count($result->getResults()) < $result->getMaxHits()))
365  {
366  return true;
367  }
368 
369  if($this->search_cache->getResultPageNumber() > 1)
370  {
371  $this->ctrl->setParameter($this,'page_number',$this->search_cache->getResultPageNumber() - 1);
372 /* $this->tpl->setCurrentBlock('prev');
373  $this->tpl->setVariable('PREV_LINK',$this->ctrl->getLinkTarget($this,'performSearch'));
374  $this->tpl->setVariable('TXT_PREV',$this->lng->txt('search_page_prev'));
375  $this->tpl->parseCurrentBlock();
376 */
377  $this->prev_link = $this->ctrl->getLinkTarget($this,'performSearch');
378  }
379  for($i = 1;$i <= $_SESSION["$a_session_key"];$i++)
380  {
381  if($i == $this->search_cache->getResultPageNumber())
382  {
383 /* $this->tpl->setCurrentBlock('pages_link');
384  $this->tpl->setVariable('NUMBER',$i);
385  $this->tpl->parseCurrentBlock();
386 */
387  continue;
388  }
389 
390  $this->ctrl->setParameter($this,'page_number',$i);
391  $link = '<a href="'.$this->ctrl->getLinkTarget($this,'performSearch').'" /a>'.$i.'</a> ';
392 /* $this->tpl->setCurrentBlock('pages_link');
393  $this->tpl->setVariable('NUMBER',$link);
394  $this->tpl->parseCurrentBlock();
395 */
396  }
397 
398 
399  if(count($result->getResults()) >= $result->getMaxHits())
400  {
401  $this->ctrl->setParameter($this,'page_number',$this->search_cache->getResultPageNumber() + 1);
402 /* $this->tpl->setCurrentBlock('next');
403  $this->tpl->setVariable('NEXT_LINK',$this->ctrl->getLinkTarget($this,'performSearch'));
404  $this->tpl->setVariable('TXT_NEXT',$this->lng->txt('search_page_next'));
405  $this->tpl->parseCurrentBlock();
406 */
407 $this->next_link = $this->ctrl->getLinkTarget($this,'performSearch');
408  }
409 
410 /* $this->tpl->setCurrentBlock('prev_next');
411  $this->tpl->setVariable('SEARCH_PAGE',$this->lng->txt('search_page'));
412  $this->tpl->parseCurrentBlock();
413 */
414 
415  $this->ctrl->clearParameters($this);
416  }
417 
422  protected function buildSearchAreaPath($a_root_node)
423  {
424  global $tree;
425 
426  $path_arr = $tree->getPathFull($a_root_node,ROOT_FOLDER_ID);
427  $counter = 0;
428  foreach($path_arr as $data)
429  {
430  if($counter++)
431  {
432  $path .= " > ";
433  $path .= $data['title'];
434  }
435  else
436  {
437  $path .= $this->lng->txt('repository');
438  }
439 
440  }
441  return $path;
442  }
443 
447  function autoComplete()
448  {
449  $q = $_REQUEST["term"];
450  include_once("./Services/Search/classes/class.ilSearchAutoComplete.php");
451  $list = ilSearchAutoComplete::getList($q);
452  echo $list;
453  exit;
454  }
455 
456 }
457 ?>