ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilSearchBaseGUI.php
Go to the documentation of this file.
1<?php
2
20use ILIAS\Object\CreationCallbackTrait;
21
37{
38 use CreationCallbackTrait;
39
40 const SEARCH_FAST = 1;
41 const SEARCH_DETAILS = 2;
42 const SEARCH_AND = 'and';
43 const SEARCH_OR = 'or';
44
48
52 protected $settings = null;
53
54 protected $ctrl = null;
55 public $ilias = null;
56 public $lng = null;
57 public $tpl = null;
58
62 protected $favourites;
63
67 protected $user;
68
73 public function __construct()
74 {
75 global $DIC;
76
77 $ilCtrl = $DIC['ilCtrl'];
78 $ilias = $DIC['ilias'];
79 $lng = $DIC['lng'];
80 $tpl = $DIC['tpl'];
81 $ilMainMenu = $DIC['ilMainMenu'];
82
83 $this->ilias = &$ilias;
84 $this->ctrl = &$ilCtrl;
85 $this->tpl = &$tpl;
86 $this->lng = &$lng;
87 $this->lng->loadLanguageModule('search');
88
89 $ilMainMenu->setActive('search');
90 $this->settings = new ilSearchSettings();
91 $this->favourites = new ilFavouritesManager();
92 $this->user = $DIC->user();
93 }
94
95 public function prepareOutput()
96 {
97 global $DIC;
98
99 $ilLocator = $DIC['ilLocator'];
100 $lng = $DIC['lng'];
101
102 $this->tpl->loadStandardTemplate();
103
104 // $ilLocator->addItem($this->lng->txt('search'),$this->ctrl->getLinkTarget($this));
105 // $this->tpl->setLocator();
106
107 //$this->tpl->setTitleIcon(ilUtil::getImagePath("icon_src_b.gif"),
108 // $lng->txt("search"));
109 $this->tpl->setTitleIcon(
110 ilObject::_getIcon("", "big", "src"),
111 ""
112 );
113 $this->tpl->setTitle($lng->txt("search"));
114
116 }
117
121 public function initStandardSearchForm($a_mode)
122 {
123 global $DIC;
124
125 $lng = $DIC['lng'];
126 $ilCtrl = $DIC['ilCtrl'];
127
128 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
129 $this->form = new ilPropertyFormGUI();
130 $this->form->setOpenTag(false);
131 $this->form->setCloseTag(false);
132
133 // term combination
134 $radg = new ilHiddenInputGUI('search_term_combination');
135 $radg->setValue(ilSearchSettings::getInstance()->getDefaultOperator());
136 $this->form->addItem($radg);
137
138 if (ilSearchSettings::getInstance()->isLuceneItemFilterEnabled()) {
139 if ($a_mode == self::SEARCH_FORM_STANDARD) {
140 // search type
141 $radg = new ilRadioGroupInputGUI($lng->txt("search_type"), "type");
142 $radg->setValue(
143 $this->getType() ==
147 );
148 $op1 = new ilRadioOption($lng->txt("search_fast_info"), ilSearchBaseGUI::SEARCH_FAST);
149 $radg->addOption($op1);
150 $op2 = new ilRadioOption($lng->txt("search_details_info"), ilSearchBaseGUI::SEARCH_DETAILS);
151 } else {
152 $op2 = new ilCheckboxInputGUI($this->lng->txt('search_filter_by_type'), 'item_filter_enabled');
153 $op2->setValue(1);
154 // $op2->setChecked($this->getType() == ilSearchBaseGUI::SEARCH_DETAILS);
155 }
156
157
158 $cbgr = new ilCheckboxGroupInputGUI('', 'filter_type');
159 $cbgr->setUseValuesAsKeys(true);
160 $details = $this->getDetails();
161 $det = false;
162 foreach (ilSearchSettings::getInstance()->getEnabledLuceneItemFilterDefinitions() as $type => $data) {
163 $cb = new ilCheckboxOption($lng->txt($data['trans']), $type);
164 if ($details[$type]) {
165 $det = true;
166 }
167 $cbgr->addOption($cb);
168 }
169 if ($a_mode == self::SEARCH_FORM_LUCENE) {
170 if (ilSearchSettings::getInstance()->isLuceneMimeFilterEnabled()) {
171 $mimes = $this->getMimeDetails();
172 foreach (ilSearchSettings::getInstance()->getEnabledLuceneMimeFilterDefinitions() as $type => $data) {
173 $op3 = new ilCheckboxOption($this->lng->txt($data['trans']), $type);
174 if ($mimes[$type]) {
175 $det = true;
176 }
177 $cbgr->addOption($op3);
178 }
179 }
180 }
181
182 $cbgr->setValue(array_merge((array) $details, (array) $mimes));
183 $op2->addSubItem($cbgr);
184
185 if ($a_mode != self::SEARCH_FORM_STANDARD && $det) {
186 $op2->setChecked(true);
187 }
188
190 $radg->addOption($op2);
191 $this->form->addItem($radg);
192 } else {
193 $this->form->addItem($op2);
194 }
195 }
196
197 $this->form->setFormAction($ilCtrl->getFormAction($this, 'performSearch'));
198 }
199
203 public function getSearchAreaForm()
204 {
205 global $DIC;
206
207 $lng = $DIC['lng'];
208 $ilCtrl = $DIC['ilCtrl'];
209
210 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
211 $form = new ilPropertyFormGUI();
212 $form->setOpenTag(false);
213 $form->setCloseTag(false);
214
215 // term combination
216 $radg = new ilHiddenInputGUI('search_term_combination');
217 $radg->setValue(ilSearchSettings::getInstance()->getDefaultOperator());
218 $form->addItem($radg);
219
220 // search area
221 include_once("./Services/Form/classes/class.ilRepositorySelectorInputGUI.php");
222 $ti = new ilRepositorySelectorInputGUI($lng->txt("search_area"), "area");
223 $ti->setSelectText($lng->txt("search_select_search_area"));
224 $form->addItem($ti);
225 $ti->readFromSession();
226
227 // alex, 15.8.2012: Added the following lines to get the value
228 // from the main menu top right input search form
229 if (isset($_POST["root_id"])) {
230 $ti->setValue($_POST["root_id"]);
231 $ti->writeToSession();
232 }
233 $form->setFormAction($ilCtrl->getFormAction($this, 'performSearch'));
234
235 return $form;
236 }
237
238
243 public function handleCommand($a_cmd)
244 {
245 if (method_exists($this, $a_cmd)) {
246 $this->$a_cmd();
247 } else {
248 $a_cmd .= 'Object';
249 $this->$a_cmd();
250 }
251 }
252
256 public function addToDeskObject()
257 {
258 $this->favourites->add($this->user->getId(), (int) $_GET["item_ref_id"]);
259 $this->showSavedResults();
260 }
261
265 public function removeFromDeskObject()
266 {
267 $this->favourites->remove($this->user->getId(), (int) $_GET["item_ref_id"]);
268 $this->showSavedResults();
269 }
270
274 public function delete()
275 {
276 $admin = new ilAdministrationCommandGUI($this);
277 $admin->delete();
278 }
279
283 public function cancelDelete()
284 {
285 $this->showSavedResults();
286 }
287
288 public function cancelObject() : void
289 {
290 $this->showSavedResults();
291 }
292
293 public function cancelMoveLinkObject()
294 {
295 $this->showSavedResults();
296 }
297
301 public function performDelete()
302 {
303 include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
304 $admin = new ilAdministrationCommandGUI($this);
305 $admin->performDelete();
306 }
307
311 public function cut()
312 {
313 include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
314 $admin = new ilAdministrationCommandGUI($this);
315 $admin->cut();
316 }
317
321 public function link()
322 {
323 include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
324 $admin = new ilAdministrationCommandGUI($this);
325 $admin->link();
326 }
327
328 public function paste()
329 {
330 include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
331 $admin = new ilAdministrationCommandGUI($this);
332 $admin->paste();
333 }
334
336 {
337 include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
338 $admin = new ilAdministrationCommandGUI($this);
339 $admin->showLinkIntoMultipleObjectsTree();
340 }
341
342 public function showPasteTree()
343 {
344 include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
345 $admin = new ilAdministrationCommandGUI($this);
346 $admin->showPasteTree();
347 }
348
350 {
351 include_once './Services/Administration/classes/class.ilAdministrationCommandGUI.php';
352 $admin = new ilAdministrationCommandGUI($this);
353 $admin->performPasteIntoMultipleObjects();
354 }
355
356 public function clear()
357 {
358 unset($_SESSION['clipboard']);
359 $this->ctrl->redirect($this);
360 }
361
363 {
364 $_SESSION["il_cont_admin_panel"] = true;
365 $this->ctrl->redirect($this);
366 }
367
369 {
370 $_SESSION["il_cont_admin_panel"] = false;
371 $this->ctrl->redirect($this);
372 }
373
378 {
379 $this->ctrl->redirect($this);
380 }
381
382
386 public function addLocator()
387 {
388 $ilLocator->addItem($this->lng->txt('search'), $this->ctrl->getLinkTarget($this));
389 $this->tpl->setLocator();
390 }
391
399 protected function addPager($result, $a_session_key)
400 {
401 global $DIC;
402
403 $tpl = $DIC['tpl'];
404
405 $_SESSION["$a_session_key"] = max($_SESSION["$a_session_key"], $this->search_cache->getResultPageNumber());
406
407 if ($_SESSION["$a_session_key"] == 1 and
408 (count($result->getResults()) < $result->getMaxHits())) {
409 return true;
410 }
411
412 if ($this->search_cache->getResultPageNumber() > 1) {
413 $this->ctrl->setParameter($this, 'page_number', $this->search_cache->getResultPageNumber() - 1);
414 /* $this->tpl->setCurrentBlock('prev');
415 $this->tpl->setVariable('PREV_LINK',$this->ctrl->getLinkTarget($this,'performSearch'));
416 $this->tpl->setVariable('TXT_PREV',$this->lng->txt('search_page_prev'));
417 $this->tpl->parseCurrentBlock();
418 */
419 $this->prev_link = $this->ctrl->getLinkTarget($this, 'performSearch');
420 }
421 for ($i = 1;$i <= $_SESSION["$a_session_key"];$i++) {
422 if ($i == $this->search_cache->getResultPageNumber()) {
423 /* $this->tpl->setCurrentBlock('pages_link');
424 $this->tpl->setVariable('NUMBER',$i);
425 $this->tpl->parseCurrentBlock();
426 */
427 continue;
428 }
429
430 $this->ctrl->setParameter($this, 'page_number', $i);
431 $link = '<a href="' . $this->ctrl->getLinkTarget($this, 'performSearch') . '" /a>' . $i . '</a> ';
432 /* $this->tpl->setCurrentBlock('pages_link');
433 $this->tpl->setVariable('NUMBER',$link);
434 $this->tpl->parseCurrentBlock();
435 */
436 }
437
438
439 if (count($result->getResults()) >= $result->getMaxHits()) {
440 $this->ctrl->setParameter($this, 'page_number', $this->search_cache->getResultPageNumber() + 1);
441 /* $this->tpl->setCurrentBlock('next');
442 $this->tpl->setVariable('NEXT_LINK',$this->ctrl->getLinkTarget($this,'performSearch'));
443 $this->tpl->setVariable('TXT_NEXT',$this->lng->txt('search_page_next'));
444 $this->tpl->parseCurrentBlock();
445 */
446 $this->next_link = $this->ctrl->getLinkTarget($this, 'performSearch');
447 }
448
449 /* $this->tpl->setCurrentBlock('prev_next');
450 $this->tpl->setVariable('SEARCH_PAGE',$this->lng->txt('search_page'));
451 $this->tpl->parseCurrentBlock();
452 */
453
454 $this->ctrl->clearParameters($this);
455 }
456
461 protected function buildSearchAreaPath($a_root_node)
462 {
463 global $DIC;
464
465 $tree = $DIC['tree'];
466
467 $path_arr = $tree->getPathFull($a_root_node, ROOT_FOLDER_ID);
468 $counter = 0;
469 foreach ($path_arr as $data) {
470 if ($counter++) {
471 $path .= " > ";
472 $path .= $data['title'];
473 } else {
474 $path .= $this->lng->txt('repository');
475 }
476 }
477 return $path;
478 }
479
483 public function autoComplete()
484 {
485 $q = $_REQUEST["term"];
486 include_once("./Services/Search/classes/class.ilSearchAutoComplete.php");
488 echo $list;
489 exit;
490 }
491
492 // begin-patch creation_date
493 protected function getCreationDateForm()
494 {
495 $options = $this->search_cache->getCreationFilter();
496
497 include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
498 $form = new ilPropertyFormGUI();
499 $form->setOpenTag(false);
500 $form->setCloseTag(false);
501
502 $enabled = new ilCheckboxInputGUI($this->lng->txt('search_filter_cd'), 'screation');
503 $enabled->setValue(1);
504 $enabled->setChecked((bool) $options['enabled']);
505 $form->addItem($enabled);
506
507 #$group = new ilRadioGroupInputGUI('', 'screation_type');
508 #$group->setValue((int) $options['type']);
509 #$group->addOption($opt1 = new ilRadioOption($this->lng->txt('search_filter_date'), 1));
510
511 $limit_sel = new ilSelectInputGUI('', 'screation_ontype');
512 $limit_sel->setValue($options['ontype']);
513 $limit_sel->setOptions(
514 array(
515 1 => $this->lng->txt('search_created_after'),
516 2 => $this->lng->txt('search_created_before'),
517 3 => $this->lng->txt('search_created_on')
518 )
519 );
520 $enabled->addSubItem($limit_sel);
521
522
523 if ($options['date']) {
524 $now = new ilDate($options['date'], IL_CAL_UNIX);
525 } else {
526 $now = new ilDate(time(), IL_CAL_UNIX);
527 }
528 $ds = new ilDateTimeInputGUI('', 'screation_date');
529 $ds->setRequired(true);
530 $ds->setDate($now);
531 $enabled->addSubItem($ds);
532
533 #$group->addOption($opt2 = new ilRadioOption($this->lng->txt('search_filter_duration'), 2));
534
535 #$duration = new ilDurationInputGUI($this->lng->txt('search_filter_duration'), 'screation_duration');
536 #$duration->setMonths((int) $options['duration']['MM']);
537 #$duration->setDays((int) $options['duration']['dd']);
538 #$duration->setShowMonths(true);
539 #$duration->setShowDays(true);
540 #$duration->setShowHours(false);
541 #$duration->setShowMinutes(false);
542 #$duration->setTitle($this->lng->txt('search_newer_than'));
543 #$opt2->addSubItem($duration);
544
545 #$enabled->addSubItem($group);
546
547 $form->setFormAction($GLOBALS['DIC']['ilCtrl']->getFormAction($this, 'performSearch'));
548
549 return $form;
550 }
551
556 protected function getSearchCache()
557 {
558 return $this->search_cache;
559 }
560
565 protected function loadCreationFilter()
566 {
567 if (!$this->settings->isDateFilterEnabled()) {
568 return array();
569 }
570
571
572 $form = $this->getCreationDateForm();
573 $options = array();
574 if ($form->checkInput()) {
575 $options['enabled'] = $form->getInput('screation');
576 $options['type'] = $form->getInput('screation_type');
577 $options['ontype'] = $form->getInput('screation_ontype');
578 $options['date'] = $form->getItemByPostVar('screation_date')->getDate()->get(IL_CAL_UNIX);
579 $options['duration'] = $form->getInput('screation_duration');
580 }
581 return $options;
582 }
583}
$result
user()
Definition: user.php:4
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
Handles Administration commands (cut, delete paste)
This class represents a property in a property form.
This class represents a checkbox property in a property form.
This class represents an option in a checkbox group.
This class represents a date/time property in a property form.
Class for single dates.
Manages favourites, currently the interface for other components, needs discussion.
This class represents a hidden form property in a property form.
static _getIcon( $a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a repository selector in a property form.
static getList($a_str)
Get completion list.
__construct()
Constructor @access public.
initStandardSearchForm($a_mode)
Init standard search form.
disableAdministrationPanel()
Disable administration panel.
enableAdministrationPanel()
Enable administration panel.
addPager($result, $a_session_key)
Add Pager.
getSearchCache()
Get user search cache.
showPasteTree()
Target selection cut.
getSearchAreaForm()
Init standard search form.
cut()
Interface ilAdministrationCommandHandler.
performPasteIntoMultipleObjects()
Perform paste into multiple objects.
link()
Interface ilAdministrationCommandHandler.
cancelMoveLinkObject()
Cancel move/link.
showLinkIntoMultipleObjectsTree()
Target selection link.
loadCreationFilter()
Load creation date filter.
keepObjectsInClipboardObject()
cancel action but keep objects in clipboardvoid
autoComplete()
Data resource for autoComplete.
performDelete()
Delete objects.
addToDeskObject()
Interface methods.
cancelDelete()
Cancel delete.
removeFromDeskObject()
Remove from dektop.
buildSearchAreaPath($a_root_node)
Build path for search area.
clear()
clear clipboard
handleCommand($a_cmd)
Handle command.
This class represents a selection list property in a property form.
static infoPanel($a_keep=true)
const ROOT_FOLDER_ID
Definition: constants.php:30
global $DIC
Definition: goto.php:24
Interface for GUI classes (PDGUI, LuceneSearchGUI...) that have to handle administration commands (cu...
Interface for gui classes (e.g ilLuceneSearchGUI) that offer add/remove to/from desktop.
exit
Definition: login.php:29
$i
Definition: metadata.php:24
redirection script todo: (a better solution should control the processing via a xml file)
$type
settings()
Definition: settings.php:2
$data
Definition: storeScorm.php:23