ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
36  protected $settings = null;
37 
38  protected $ctrl = null;
39  var $ilias = null;
40  var $lng = null;
41  var $tpl = null;
42 
47  function __construct()
48  {
49  global $ilCtrl,$ilias,$lng,$tpl,$ilMainMenu;
50 
51  $this->ilias =& $ilias;
52  $this->ctrl =& $ilCtrl;
53  $this->tpl =& $tpl;
54  $this->lng =& $lng;
55  $this->lng->loadLanguageModule('search');
56 
57  $ilMainMenu->setActive('search');
58  $this->settings = new ilSearchSettings();
59  }
60 
61  function prepareOutput()
62  {
63  global $ilLocator, $lng;
64 
65  $this->tpl->getStandardTemplate();
66 
67 // $ilLocator->addItem($this->lng->txt('search'),$this->ctrl->getLinkTarget($this));
68 // $this->tpl->setLocator();
69 
70  //$this->tpl->setTitleIcon(ilUtil::getImagePath("icon_src_b.gif"),
71  // $lng->txt("search"));
72  $this->tpl->setTitleIcon(ilObject::_getIcon("","big", "src"),
73  "");
74  $this->tpl->setTitle($lng->txt("search"));
75 
77 
78  }
79 
83  public function initStandardSearchForm($a_mode)
84  {
85  global $lng, $ilCtrl;
86 
87  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
88  $this->form = new ilPropertyFormGUI();
89  $this->form->setOpenTag(false);
90  $this->form->setCloseTag(false);
91 
92  // term combination
93  $radg = new ilHiddenInputGUI('search_term_combination');
94  $radg->setValue(ilSearchSettings::getInstance()->getDefaultOperator());
95  $this->form->addItem($radg);
96 
97  if(ilSearchSettings::getInstance()->isLuceneItemFilterEnabled())
98  {
99  if($a_mode == self::SEARCH_FORM_STANDARD)
100  {
101  // search type
102  $radg = new ilRadioGroupInputGUI($lng->txt("search_type"), "type");
103  $radg->setValue(
104  $this->getType() ==
108  );
109  $op1 = new ilRadioOption($lng->txt("search_fast_info"), ilSearchBaseGUI::SEARCH_FAST);
110  $radg->addOption($op1);
111  $op2 = new ilRadioOption($lng->txt("search_details_info"), ilSearchBaseGUI::SEARCH_DETAILS);
112  }
113  else
114  {
115  $op2 = new ilCheckboxInputGUI($this->lng->txt('search_filter_by_type'),'item_filter_enabled');
116  $op2->setValue(1);
117 // $op2->setChecked($this->getType() == ilSearchBaseGUI::SEARCH_DETAILS);
118  }
119 
120 
121  $cbgr = new ilCheckboxGroupInputGUI('','filter_type');
122  $cbgr->setUseValuesAsKeys(true);
123  $details = $this->getDetails();
124  $det = false;
125  foreach(ilSearchSettings::getInstance()->getEnabledLuceneItemFilterDefinitions() as $type => $data)
126  {
127  $cb = new ilCheckboxOption($lng->txt($data['trans']), $type);
128  if ($details[$type])
129  {
130  $det = true;
131  }
132  $cbgr->addOption($cb);
133  }
134  if($a_mode == self::SEARCH_FORM_LUCENE)
135  {
136  if(ilSearchSettings::getInstance()->isLuceneMimeFilterEnabled())
137  {
138  $mimes = $this->getMimeDetails();
139  foreach(ilSearchSettings::getInstance()->getEnabledLuceneMimeFilterDefinitions() as $type => $data)
140  {
141  $op3 = new ilCheckboxOption($this->lng->txt($data['trans']),$type);
142  if($mimes[$type])
143  {
144  $det = true;
145  }
146  $cbgr->addOption($op3);
147  }
148  }
149  }
150 
151  $cbgr->setValue(array_merge((array) $details,(array) $mimes));
152  $op2->addSubItem($cbgr);
153 
154  if($a_mode != self::SEARCH_FORM_STANDARD && $det)
155  {
156  $op2->setChecked(true);
157  }
158 
160  {
161  $radg->addOption($op2);
162  $this->form->addItem($radg);
163  }
164  else
165  {
166  $this->form->addItem($op2);
167  }
168  }
169 
170  $this->form->setFormAction($ilCtrl->getFormAction($this,'performSearch'));
171  }
172 
176  public function getSearchAreaForm()
177  {
178  global $lng, $ilCtrl;
179 
180  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
181  $form = new ilPropertyFormGUI();
182  $form->setOpenTag(false);
183  $form->setCloseTag(false);
184 
185  // term combination
186  $radg = new ilHiddenInputGUI('search_term_combination');
187  $radg->setValue(ilSearchSettings::getInstance()->getDefaultOperator());
188  $form->addItem($radg);
189 
190  // search area
191  include_once("./Services/Form/classes/class.ilRepositorySelectorInputGUI.php");
192  $ti = new ilRepositorySelectorInputGUI($lng->txt("search_area"), "area");
193  $ti->setSelectText($lng->txt("search_select_search_area"));
194  $form->addItem($ti);
195  $ti->readFromSession();
196 
197  // alex, 15.8.2012: Added the following lines to get the value
198  // from the main menu top right input search form
199  if (isset($_POST["root_id"]))
200  {
201  $ti->setValue($_POST["root_id"]);
202  $ti->writeToSession();
203  }
204  $form->setFormAction($ilCtrl->getFormAction($this,'performSearch'));
205 
206  return $form;
207  }
208 
209 
214  public function handleCommand($a_cmd)
215  {
216  if(method_exists($this, $a_cmd))
217  {
218  $this->$a_cmd();
219  }
220  else
221  {
222  $a_cmd .= 'Object';
223  $this->$a_cmd();
224  }
225  }
226 
230  public function addToDeskObject()
231  {
232  include_once './Services/PersonalDesktop/classes/class.ilDesktopItemGUI.php';
234  $this->showSavedResults();
235  }
236 
240  public function removeFromDeskObject()
241  {
242  include_once './Services/PersonalDesktop/classes/class.ilDesktopItemGUI.php';
244  $this->showSavedResults();
245  }
246 
250  public function delete()
251  {
252  include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
253  $admin = new ilAdministrationCommandGUI($this);
254  $admin->delete();
255  }
256 
260  public function cancelDelete()
261  {
262  $this->showSavedResults();
263  }
264 
265  public function cancelMoveLinkObject()
266  {
267  $this->showSavedResults();
268  }
269 
273  public function performDelete()
274  {
275  include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
276  $admin = new ilAdministrationCommandGUI($this);
277  $admin->performDelete();
278  }
279 
283  public function cut()
284  {
285 
286 
287  include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
288  $admin = new ilAdministrationCommandGUI($this);
289  $admin->cut();
290  }
291 
295  public function link()
296  {
297  include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
298  $admin = new ilAdministrationCommandGUI($this);
299  $admin->link();
300  }
301 
302  public function paste()
303  {
304  include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
305  $admin = new ilAdministrationCommandGUI($this);
306  $admin->paste();
307  }
308 
310  {
311  include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
312  $admin = new ilAdministrationCommandGUI($this);
313  $admin->showLinkIntoMultipleObjectsTree();
314  }
315 
316  public function showMoveIntoObjectTree()
317  {
318  include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
319  $admin = new ilAdministrationCommandGUI($this);
320  $admin->showMoveIntoObjectTree();
321  }
322 
324  {
325  include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
326  $admin = new ilAdministrationCommandGUI($this);
327  $admin->performPasteIntoMultipleObjects();
328  }
329 
330  public function clear()
331  {
332  unset($_SESSION['clipboard']);
333  $this->ctrl->redirect($this);
334  }
335 
336  public function enableAdministrationPanel()
337  {
338  $_SESSION["il_cont_admin_panel"] = true;
339  $this->ctrl->redirect($this);
340  }
341 
342  public function disableAdministrationPanel()
343  {
344  $_SESSION["il_cont_admin_panel"] = false;
345  $this->ctrl->redirect($this);
346  }
347 
348 
352  public function addLocator()
353  {
354  $ilLocator->addItem($this->lng->txt('search'),$this->ctrl->getLinkTarget($this));
355  $this->tpl->setLocator();
356  }
357 
365  protected function addPager($result,$a_session_key)
366  {
367  global $tpl;
368 
369  $_SESSION["$a_session_key"] = max($_SESSION["$a_session_key"],$this->search_cache->getResultPageNumber());
370 
371  if($_SESSION["$a_session_key"] == 1 and
372  (count($result->getResults()) < $result->getMaxHits()))
373  {
374  return true;
375  }
376 
377  if($this->search_cache->getResultPageNumber() > 1)
378  {
379  $this->ctrl->setParameter($this,'page_number',$this->search_cache->getResultPageNumber() - 1);
380 /* $this->tpl->setCurrentBlock('prev');
381  $this->tpl->setVariable('PREV_LINK',$this->ctrl->getLinkTarget($this,'performSearch'));
382  $this->tpl->setVariable('TXT_PREV',$this->lng->txt('search_page_prev'));
383  $this->tpl->parseCurrentBlock();
384 */
385  $this->prev_link = $this->ctrl->getLinkTarget($this,'performSearch');
386  }
387  for($i = 1;$i <= $_SESSION["$a_session_key"];$i++)
388  {
389  if($i == $this->search_cache->getResultPageNumber())
390  {
391 /* $this->tpl->setCurrentBlock('pages_link');
392  $this->tpl->setVariable('NUMBER',$i);
393  $this->tpl->parseCurrentBlock();
394 */
395  continue;
396  }
397 
398  $this->ctrl->setParameter($this,'page_number',$i);
399  $link = '<a href="'.$this->ctrl->getLinkTarget($this,'performSearch').'" /a>'.$i.'</a> ';
400 /* $this->tpl->setCurrentBlock('pages_link');
401  $this->tpl->setVariable('NUMBER',$link);
402  $this->tpl->parseCurrentBlock();
403 */
404  }
405 
406 
407  if(count($result->getResults()) >= $result->getMaxHits())
408  {
409  $this->ctrl->setParameter($this,'page_number',$this->search_cache->getResultPageNumber() + 1);
410 /* $this->tpl->setCurrentBlock('next');
411  $this->tpl->setVariable('NEXT_LINK',$this->ctrl->getLinkTarget($this,'performSearch'));
412  $this->tpl->setVariable('TXT_NEXT',$this->lng->txt('search_page_next'));
413  $this->tpl->parseCurrentBlock();
414 */
415 $this->next_link = $this->ctrl->getLinkTarget($this,'performSearch');
416  }
417 
418 /* $this->tpl->setCurrentBlock('prev_next');
419  $this->tpl->setVariable('SEARCH_PAGE',$this->lng->txt('search_page'));
420  $this->tpl->parseCurrentBlock();
421 */
422 
423  $this->ctrl->clearParameters($this);
424  }
425 
430  protected function buildSearchAreaPath($a_root_node)
431  {
432  global $tree;
433 
434  $path_arr = $tree->getPathFull($a_root_node,ROOT_FOLDER_ID);
435  $counter = 0;
436  foreach($path_arr as $data)
437  {
438  if($counter++)
439  {
440  $path .= " > ";
441  $path .= $data['title'];
442  }
443  else
444  {
445  $path .= $this->lng->txt('repository');
446  }
447 
448  }
449  return $path;
450  }
451 
455  function autoComplete()
456  {
457  $q = $_REQUEST["term"];
458  include_once("./Services/Search/classes/class.ilSearchAutoComplete.php");
459  $list = ilSearchAutoComplete::getList($q);
460  echo $list;
461  exit;
462  }
463 
464  // begin-patch creation_date
465  protected function getCreationDateForm()
466  {
467  $options = $this->search_cache->getCreationFilter();
468 
469  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
470  $form = new ilPropertyFormGUI();
471  $form->setOpenTag(false);
472  $form->setCloseTag(false);
473 
474  $enabled = new ilCheckboxInputGUI($this->lng->txt('search_filter_cd'),'screation');
475  $enabled->setValue(1);
476  $enabled->setChecked((bool) $options['enabled']);
477  $form->addItem($enabled);
478 
479  #$group = new ilRadioGroupInputGUI('', 'screation_type');
480  #$group->setValue((int) $options['type']);
481  #$group->addOption($opt1 = new ilRadioOption($this->lng->txt('search_filter_date'), 1));
482 
483  $limit_sel = new ilSelectInputGUI('','screation_ontype');
484  $limit_sel->setValue($options['ontype']);
485  $limit_sel->setOptions(
486  array(
487  1 => $this->lng->txt('search_created_after'),
488  2 => $this->lng->txt('search_created_before'),
489  3 => $this->lng->txt('search_created_on')
490  )
491  );
492  $enabled->addSubItem($limit_sel);
493 
494 
495  if($options['date'])
496  {
497  $now = new ilDate($options['date'],IL_CAL_UNIX);
498  }
499  else
500  {
501  $now = new ilDate(time(),IL_CAL_UNIX);
502  }
503  $ds = new ilDateTimeInputGUI('','screation_date');
504  $ds->setRequired(true);
505  $ds->setDate($now);
506  $enabled->addSubItem($ds);
507 
508  #$group->addOption($opt2 = new ilRadioOption($this->lng->txt('search_filter_duration'), 2));
509 
510  #$duration = new ilDurationInputGUI($this->lng->txt('search_filter_duration'), 'screation_duration');
511  #$duration->setMonths((int) $options['duration']['MM']);
512  #$duration->setDays((int) $options['duration']['dd']);
513  #$duration->setShowMonths(true);
514  #$duration->setShowDays(true);
515  #$duration->setShowHours(false);
516  #$duration->setShowMinutes(false);
517  #$duration->setTitle($this->lng->txt('search_newer_than'));
518  #$opt2->addSubItem($duration);
519 
520  #$enabled->addSubItem($group);
521 
522  $form->setFormAction($GLOBALS['ilCtrl']->getFormAction($this,'performSearch'));
523 
524  return $form;
525 
526  }
527 
532  protected function getSearchCache()
533  {
534  return $this->search_cache;
535  }
536 
541  protected function loadCreationFilter()
542  {
543  if(!$this->settings->isDateFilterEnabled())
544  {
545  return array();
546  }
547 
548 
549  $form = $this->getCreationDateForm();
550  $options = array();
551  if($form->checkInput())
552  {
553  $options['enabled'] = $form->getInput('screation');
554  $options['type'] = $form->getInput('screation_type');
555  $options['ontype'] = $form->getInput('screation_ontype');
556  $options['date'] = $form->getItemByPostVar('screation_date')->getDate()->get(IL_CAL_UNIX);
557  $options['duration'] = $form->getInput('screation_duration');
558  }
559  return $options;
560  }
561 
562 
563 
564 }
565 ?>
This class represents an option in a radio group.
link()
Interface ilAdministrationCommandHandler.
static _getIcon($a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
$path
Definition: aliased.php:25
loadCreationFilter()
Load creation date filter.
cancelMoveLinkObject()
Cancel move/link.
removeFromDeskObject()
Remove from dektop.
getSearchAreaForm()
Init standard search form.
This class represents an option in a checkbox group.
$_SESSION["AccountId"]
This class represents a selection list property in a property form.
$result
showLinkIntoMultipleObjectsTree()
Target selection link.
This class represents a property form user interface.
Handles Administration commands (cut, delete paste)
performDelete()
Delete objects.
addToDeskObject()
Interface methods.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
static getList($a_str)
Get completion list.
This class represents a checkbox property in a property form.
const IL_CAL_UNIX
static addToDesktop()
Add desktop item public.
buildSearchAreaPath($a_root_node)
Build path for search area.
This class represents a date/time property in a property form.
global $ilCtrl
Definition: ilias.php:18
$counter
disableAdministrationPanel()
Disable administration panel.
This class represents a hidden form property in a property form.
This class represents a property in a property form.
setValue($a_value)
Set Value.
addPager($result, $a_session_key)
Add Pager.
Class for single dates.
if(!is_array($argv)) $options
cut()
Interface ilAdministrationCommandHandler.
autoComplete()
Data resource for autoComplete.
__construct()
Constructor public.
initStandardSearchForm($a_mode)
Init standard search form.
This class represents a repository selector in a property form.
setValue($a_value)
Set Value.
static infoPanel($a_keep=true)
cancelDelete()
Cancel delete.
redirection script todo: (a better solution should control the processing via a xml file) ...
performPasteIntoMultipleObjects()
Perform paste into multiple objects.
handleCommand($a_cmd)
Handle command.
This class represents a property in a property form.
Create styles array
The data for the language used.
showMoveIntoObjectTree()
Target selection cut.
static removeFromDesktop()
Remove item from personal desktop public.
settings()
Definition: settings.php:2
Interface for gui classes (e.g ilLuceneSearchGUI) that offer add/remove to/from desktop.
clear()
clear clipboard
addLocator()
Add Locator.
enableAdministrationPanel()
Enable administration panel.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
Interface for GUI classes (PDGUI, LuceneSearchGUI...) that have to handle administration commands (cu...
$_POST["username"]
getSearchCache()
Get user search cache.