ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  public $ilias = null;
40  public $lng = null;
41  public $tpl = null;
42 
47  public 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  public 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(
73  ilObject::_getIcon("", "big", "src"),
74  ""
75  );
76  $this->tpl->setTitle($lng->txt("search"));
77 
79  }
80 
84  public function initStandardSearchForm($a_mode)
85  {
86  global $lng, $ilCtrl;
87 
88  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
89  $this->form = new ilPropertyFormGUI();
90  $this->form->setOpenTag(false);
91  $this->form->setCloseTag(false);
92 
93  // term combination
94  $radg = new ilHiddenInputGUI('search_term_combination');
95  $radg->setValue(ilSearchSettings::getInstance()->getDefaultOperator());
96  $this->form->addItem($radg);
97 
98  if (ilSearchSettings::getInstance()->isLuceneItemFilterEnabled()) {
99  if ($a_mode == self::SEARCH_FORM_STANDARD) {
100  // search type
101  $radg = new ilRadioGroupInputGUI($lng->txt("search_type"), "type");
102  $radg->setValue(
103  $this->getType() ==
107  );
108  $op1 = new ilRadioOption($lng->txt("search_fast_info"), ilSearchBaseGUI::SEARCH_FAST);
109  $radg->addOption($op1);
110  $op2 = new ilRadioOption($lng->txt("search_details_info"), ilSearchBaseGUI::SEARCH_DETAILS);
111  } else {
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  $cb = new ilCheckboxOption($lng->txt($data['trans']), $type);
124  if ($details[$type]) {
125  $det = true;
126  }
127  $cbgr->addOption($cb);
128  }
129  if ($a_mode == self::SEARCH_FORM_LUCENE) {
130  if (ilSearchSettings::getInstance()->isLuceneMimeFilterEnabled()) {
131  $mimes = $this->getMimeDetails();
132  foreach (ilSearchSettings::getInstance()->getEnabledLuceneMimeFilterDefinitions() as $type => $data) {
133  $op3 = new ilCheckboxOption($this->lng->txt($data['trans']), $type);
134  if ($mimes[$type]) {
135  $det = true;
136  }
137  $cbgr->addOption($op3);
138  }
139  }
140  }
141 
142  $cbgr->setValue(array_merge((array) $details, (array) $mimes));
143  $op2->addSubItem($cbgr);
144 
145  if ($a_mode != self::SEARCH_FORM_STANDARD && $det) {
146  $op2->setChecked(true);
147  }
148 
149  if ($a_mode == ilSearchBaseGUI::SEARCH_FORM_STANDARD) {
150  $radg->addOption($op2);
151  $this->form->addItem($radg);
152  } else {
153  $this->form->addItem($op2);
154  }
155  }
156 
157  $this->form->setFormAction($ilCtrl->getFormAction($this, 'performSearch'));
158  }
159 
163  public function getSearchAreaForm()
164  {
165  global $lng, $ilCtrl;
166 
167  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
168  $form = new ilPropertyFormGUI();
169  $form->setOpenTag(false);
170  $form->setCloseTag(false);
171 
172  // term combination
173  $radg = new ilHiddenInputGUI('search_term_combination');
174  $radg->setValue(ilSearchSettings::getInstance()->getDefaultOperator());
175  $form->addItem($radg);
176 
177  // search area
178  include_once("./Services/Form/classes/class.ilRepositorySelectorInputGUI.php");
179  $ti = new ilRepositorySelectorInputGUI($lng->txt("search_area"), "area");
180  $ti->setSelectText($lng->txt("search_select_search_area"));
181  $form->addItem($ti);
182  $ti->readFromSession();
183 
184  // alex, 15.8.2012: Added the following lines to get the value
185  // from the main menu top right input search form
186  if (isset($_POST["root_id"])) {
187  $ti->setValue($_POST["root_id"]);
188  $ti->writeToSession();
189  }
190  $form->setFormAction($ilCtrl->getFormAction($this, 'performSearch'));
191 
192  return $form;
193  }
194 
195 
200  public function handleCommand($a_cmd)
201  {
202  if (method_exists($this, $a_cmd)) {
203  $this->$a_cmd();
204  } else {
205  $a_cmd .= 'Object';
206  $this->$a_cmd();
207  }
208  }
209 
213  public function addToDeskObject()
214  {
215  include_once './Services/PersonalDesktop/classes/class.ilDesktopItemGUI.php';
217  $this->showSavedResults();
218  }
219 
223  public function removeFromDeskObject()
224  {
225  include_once './Services/PersonalDesktop/classes/class.ilDesktopItemGUI.php';
227  $this->showSavedResults();
228  }
229 
233  public function delete()
234  {
235  include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
236  $admin = new ilAdministrationCommandGUI($this);
237  $admin->delete();
238  }
239 
243  public function cancelDelete()
244  {
245  $this->showSavedResults();
246  }
247 
248  public function cancelMoveLinkObject()
249  {
250  $this->showSavedResults();
251  }
252 
256  public function performDelete()
257  {
258  include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
259  $admin = new ilAdministrationCommandGUI($this);
260  $admin->performDelete();
261  }
262 
266  public function cut()
267  {
268  include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
269  $admin = new ilAdministrationCommandGUI($this);
270  $admin->cut();
271  }
272 
276  public function link()
277  {
278  include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
279  $admin = new ilAdministrationCommandGUI($this);
280  $admin->link();
281  }
282 
283  public function paste()
284  {
285  include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
286  $admin = new ilAdministrationCommandGUI($this);
287  $admin->paste();
288  }
289 
291  {
292  include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
293  $admin = new ilAdministrationCommandGUI($this);
294  $admin->showLinkIntoMultipleObjectsTree();
295  }
296 
297  public function showMoveIntoObjectTree()
298  {
299  include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
300  $admin = new ilAdministrationCommandGUI($this);
301  $admin->showMoveIntoObjectTree();
302  }
303 
305  {
306  include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
307  $admin = new ilAdministrationCommandGUI($this);
308  $admin->performPasteIntoMultipleObjects();
309  }
310 
311  public function clear()
312  {
313  unset($_SESSION['clipboard']);
314  $this->ctrl->redirect($this);
315  }
316 
317  public function enableAdministrationPanel()
318  {
319  $_SESSION["il_cont_admin_panel"] = true;
320  $this->ctrl->redirect($this);
321  }
322 
323  public function disableAdministrationPanel()
324  {
325  $_SESSION["il_cont_admin_panel"] = false;
326  $this->ctrl->redirect($this);
327  }
328 
333  {
334  $this->ctrl->redirect($this);
335  }
336 
337 
341  public function addLocator()
342  {
343  $ilLocator->addItem($this->lng->txt('search'), $this->ctrl->getLinkTarget($this));
344  $this->tpl->setLocator();
345  }
346 
354  protected function addPager($result, $a_session_key)
355  {
356  global $tpl;
357 
358  $_SESSION["$a_session_key"] = max($_SESSION["$a_session_key"], $this->search_cache->getResultPageNumber());
359 
360  if ($_SESSION["$a_session_key"] == 1 and
361  (count($result->getResults()) < $result->getMaxHits())) {
362  return true;
363  }
364 
365  if ($this->search_cache->getResultPageNumber() > 1) {
366  $this->ctrl->setParameter($this, 'page_number', $this->search_cache->getResultPageNumber() - 1);
367  /* $this->tpl->setCurrentBlock('prev');
368  $this->tpl->setVariable('PREV_LINK',$this->ctrl->getLinkTarget($this,'performSearch'));
369  $this->tpl->setVariable('TXT_PREV',$this->lng->txt('search_page_prev'));
370  $this->tpl->parseCurrentBlock();
371  */
372  $this->prev_link = $this->ctrl->getLinkTarget($this, 'performSearch');
373  }
374  for ($i = 1;$i <= $_SESSION["$a_session_key"];$i++) {
375  if ($i == $this->search_cache->getResultPageNumber()) {
376  /* $this->tpl->setCurrentBlock('pages_link');
377  $this->tpl->setVariable('NUMBER',$i);
378  $this->tpl->parseCurrentBlock();
379  */
380  continue;
381  }
382 
383  $this->ctrl->setParameter($this, 'page_number', $i);
384  $link = '<a href="' . $this->ctrl->getLinkTarget($this, 'performSearch') . '" /a>' . $i . '</a> ';
385  /* $this->tpl->setCurrentBlock('pages_link');
386  $this->tpl->setVariable('NUMBER',$link);
387  $this->tpl->parseCurrentBlock();
388  */
389  }
390 
391 
392  if (count($result->getResults()) >= $result->getMaxHits()) {
393  $this->ctrl->setParameter($this, 'page_number', $this->search_cache->getResultPageNumber() + 1);
394  /* $this->tpl->setCurrentBlock('next');
395  $this->tpl->setVariable('NEXT_LINK',$this->ctrl->getLinkTarget($this,'performSearch'));
396  $this->tpl->setVariable('TXT_NEXT',$this->lng->txt('search_page_next'));
397  $this->tpl->parseCurrentBlock();
398  */
399  $this->next_link = $this->ctrl->getLinkTarget($this, 'performSearch');
400  }
401 
402  /* $this->tpl->setCurrentBlock('prev_next');
403  $this->tpl->setVariable('SEARCH_PAGE',$this->lng->txt('search_page'));
404  $this->tpl->parseCurrentBlock();
405  */
406 
407  $this->ctrl->clearParameters($this);
408  }
409 
414  protected function buildSearchAreaPath($a_root_node)
415  {
416  global $tree;
417 
418  $path_arr = $tree->getPathFull($a_root_node, ROOT_FOLDER_ID);
419  $counter = 0;
420  foreach ($path_arr as $data) {
421  if ($counter++) {
422  $path .= " > ";
423  $path .= $data['title'];
424  } else {
425  $path .= $this->lng->txt('repository');
426  }
427  }
428  return $path;
429  }
430 
434  public function autoComplete()
435  {
436  $q = $_REQUEST["term"];
437  include_once("./Services/Search/classes/class.ilSearchAutoComplete.php");
439  echo $list;
440  exit;
441  }
442 
443  // begin-patch creation_date
444  protected function getCreationDateForm()
445  {
446  $options = $this->search_cache->getCreationFilter();
447 
448  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
449  $form = new ilPropertyFormGUI();
450  $form->setOpenTag(false);
451  $form->setCloseTag(false);
452 
453  $enabled = new ilCheckboxInputGUI($this->lng->txt('search_filter_cd'), 'screation');
454  $enabled->setValue(1);
455  $enabled->setChecked((bool) $options['enabled']);
456  $form->addItem($enabled);
457 
458  #$group = new ilRadioGroupInputGUI('', 'screation_type');
459  #$group->setValue((int) $options['type']);
460  #$group->addOption($opt1 = new ilRadioOption($this->lng->txt('search_filter_date'), 1));
461 
462  $limit_sel = new ilSelectInputGUI('', 'screation_ontype');
463  $limit_sel->setValue($options['ontype']);
464  $limit_sel->setOptions(
465  array(
466  1 => $this->lng->txt('search_created_after'),
467  2 => $this->lng->txt('search_created_before'),
468  3 => $this->lng->txt('search_created_on')
469  )
470  );
471  $enabled->addSubItem($limit_sel);
472 
473 
474  if ($options['date']) {
475  $now = new ilDate($options['date'], IL_CAL_UNIX);
476  } else {
477  $now = new ilDate(time(), IL_CAL_UNIX);
478  }
479  $ds = new ilDateTimeInputGUI('', 'screation_date');
480  $ds->setRequired(true);
481  $ds->setDate($now);
482  $enabled->addSubItem($ds);
483 
484  #$group->addOption($opt2 = new ilRadioOption($this->lng->txt('search_filter_duration'), 2));
485 
486  #$duration = new ilDurationInputGUI($this->lng->txt('search_filter_duration'), 'screation_duration');
487  #$duration->setMonths((int) $options['duration']['MM']);
488  #$duration->setDays((int) $options['duration']['dd']);
489  #$duration->setShowMonths(true);
490  #$duration->setShowDays(true);
491  #$duration->setShowHours(false);
492  #$duration->setShowMinutes(false);
493  #$duration->setTitle($this->lng->txt('search_newer_than'));
494  #$opt2->addSubItem($duration);
495 
496  #$enabled->addSubItem($group);
497 
498  $form->setFormAction($GLOBALS['ilCtrl']->getFormAction($this, 'performSearch'));
499 
500  return $form;
501  }
502 
507  protected function getSearchCache()
508  {
509  return $this->search_cache;
510  }
511 
516  protected function loadCreationFilter()
517  {
518  if (!$this->settings->isDateFilterEnabled()) {
519  return array();
520  }
521 
522 
523  $form = $this->getCreationDateForm();
524  $options = array();
525  if ($form->checkInput()) {
526  $options['enabled'] = $form->getInput('screation');
527  $options['type'] = $form->getInput('screation_type');
528  $options['ontype'] = $form->getInput('screation_ontype');
529  $options['date'] = $form->getItemByPostVar('screation_date')->getDate()->get(IL_CAL_UNIX);
530  $options['duration'] = $form->getInput('screation_duration');
531  }
532  return $options;
533  }
534 }
static _getIcon( $a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
This class represents an option in a radio group.
link()
Interface ilAdministrationCommandHandler.
loadCreationFilter()
Load creation date filter.
if(isset($_REQUEST['delete'])) $list
Definition: registry.php:41
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.
$type
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.
keepObjectsInClipboardObject()
cancel action but keep objects in clipboardvoid
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(isset($_POST['submit'])) $form
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.
$i
Definition: disco.tpl.php:19
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"]
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
getSearchCache()
Get user search cache.