ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMainMenuSearchGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
33{
34 protected ?ilTemplate $tpl = null;
35 protected ilLanguage $lng;
36 protected ilTree $tree;
37 protected ilCtrl $ctrl;
38 protected ilObjUser $user;
39
42
43
44 private int $ref_id;
45 private bool $isContainer = true;
46
47 public function __construct()
48 {
49 global $DIC;
50
51 $this->lng = $DIC->language();
52 $this->lng->loadLanguageModule("search");
53 $this->tree = $DIC->repositoryTree();
54 $this->ctrl = $DIC->ctrl();
55 $this->user = $DIC->user();
56
57 $this->http = $DIC->http();
58 $this->refinery = $DIC->refinery();
59 $DIC->ui()->mainTemplate()->addJavascript('assets/js/SearchMainMenu.js');
60
61 $this->initRefIdFromQuery();
62 }
63
64 protected function initRefIdFromQuery(): void
65 {
66 $this->ref_id = ROOT_FOLDER_ID;
67 if ($this->http->wrapper()->query()->has('ref_id')) {
68 $this->ref_id = $this->http->wrapper()->query()->retrieve(
69 'ref_id',
70 $this->refinery->kindlyTo()->int()
71 );
72 }
73 }
74
75 public function getHTML(): string
76 {
79
80 $this->tpl = new ilTemplate('tpl.main_menu_search.html', true, true, 'components/ILIAS/Search');
81 if ($this->user->getId() != ANONYMOUS_USER_ID) {
82 $this->tpl->setVariable('LABEL_SEARCH_OPTIONS', $this->lng->txt("label_search_options"));
83 if (ilSearchSettings::getInstance()->isLuceneUserSearchEnabled() || ($this->ref_id != ROOT_FOLDER_ID)) {
84 $this->tpl->setCurrentBlock("position");
85 $this->tpl->setVariable('TXT_GLOBALLY', $this->lng->txt("search_globally"));
86 $this->tpl->setVariable('ROOT_ID', ROOT_FOLDER_ID);
87 $this->tpl->parseCurrentBlock();
88 } else {
89 $this->tpl->setCurrentBlock("position_hid");
90 $this->tpl->setVariable('ROOT_ID_HID', ROOT_FOLDER_ID);
91 $this->tpl->parseCurrentBlock();
92 }
93 if ($this->ref_id != ROOT_FOLDER_ID) {
94 $this->tpl->setCurrentBlock('position_rep');
95 $this->tpl->setVariable('TXT_CURRENT_POSITION', $this->lng->txt("search_at_current_position"));
96 $this->tpl->setVariable('REF_ID', $this->ref_id);
97 $this->tpl->parseCurrentBlock();
98 }
99 }
100
101 if ($this->user->getId() != ANONYMOUS_USER_ID && ilSearchSettings::getInstance()->isLuceneUserSearchEnabled()) {
102 $this->tpl->setCurrentBlock('usr_search');
103 $this->tpl->setVariable('TXT_USR_SEARCH', $this->lng->txt('search_users'));
104 $this->tpl->setVariable('USER_SEARCH_ID', ilSearchControllerGUI::TYPE_USER_SEARCH);
105 $this->tpl->parseCurrentBlock();
106 }
107 $this->tpl->setVariable(
108 'FORMACTION',
109 $this->buildSearchLink('remoteSearch', false)
110 );
111 $this->tpl->setVariable('BTN_SEARCH', $this->lng->txt('search'));
112 $this->tpl->setVariable('SEARCH_INPUT_LABEL', $this->lng->txt('search_field'));
113 $this->tpl->setVariable(
114 'AC_DATASOURCE',
115 $this->buildSearchLink('autoComplete', true)
116 );
117
118 $this->tpl->setVariable('IMG_MM_SEARCH', ilUtil::img(
119 ilUtil::getImagePath("standard/icon_seas.svg"),
120 $this->lng->txt("search")
121 ));
122
123 if ($this->user->getId() != ANONYMOUS_USER_ID) {
124 $this->tpl->setVariable(
125 'HREF_SEARCH_LINK',
126 $this->buildSearchLink('', false)
127 );
128 $this->tpl->setVariable('TXT_SEARCH_LINK', $this->lng->txt("last_search_result"));
129 }
130 $this->tpl->setVariable('TXT_SEARCH', $this->lng->txt("search"));
131
132 return $this->tpl->get();
133 }
134
135 protected function buildSearchLink(string $cmd, bool $async): string
136 {
137 if (ilSearchSettings::getInstance()->enabledLucene()) {
138 $default = strtolower(ilLuceneSearchGUI::class);
139 } else {
140 $default = strtolower(ilSearchGUI::class);
141 }
142
143 $root_id = 0;
144 if ($this->http->wrapper()->post()->has('root_id')) {
145 $root_id = $this->http->wrapper()->post()->retrieve(
146 'root_id',
147 $this->refinery->kindlyTo()->int()
148 );
149 }
151 $default = strtolower(ilLuceneUserSearchGUI::class);
152 }
153
154 return $this->ctrl->getLinkTargetByClass(
155 [strtolower(ilSearchControllerGUI::class), $default],
156 $cmd,
157 null,
158 $async
159 );
160 }
161}
Builds data types.
Definition: Factory.php:36
Class ilCtrl provides processing control methods.
language handling
Add a search box to main menu.
buildSearchLink(string $cmd, bool $async)
User class.
special template class to simplify handling of ITX/PEAR
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static img(string $a_src, ?string $a_alt=null, $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
static initjQueryUI(?ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery-UI JS-File to the global template (see included_components....
static initjQuery(?ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
const ANONYMOUS_USER_ID
Definition: constants.php:27
const ROOT_FOLDER_ID
Definition: constants.php:32
Interface GlobalHttpState.
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:26