ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilObjSearchSettingsFormGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26use ILIAS\Search\ObjGUI\Readme\Helper as ServerReadmeHelper;
27
32{
35 protected ilLanguage $lng;
37 protected Factory $factory;
39
41 protected ServerReadmeHelper $readme_helper;
42
43 public function __construct(
47 UIServices $ui,
49 ServerReadmeHelper $readme_helper
50 ) {
51 $this->http = $http;
52 $this->ctrl = $ctrl;
53 $this->lng = $lng;
54 $this->tpl = $ui->mainTemplate();
55 $this->factory = $ui->factory();
56 $this->renderer = $ui->renderer();
57 $this->coordinator = $coordinator;
58 $this->readme_helper = $readme_helper;
59 }
60
61 public function executeCommand(): void
62 {
63 $cmd = $this->ctrl->getCmd();
64
65 switch ($cmd) {
66 case 'readOnly':
67 $this->showForm(true);
68 break;
69
70 case 'edit':
71 $this->showForm(false);
72 break;
73
74 case 'permDenied':
75 $this->showPermissionDenied();
76 break;
77
78 case 'update':
79 $this->update();
80 break;
81
82 default:
84 'Invalid command for ilObjSearchSettingsFormGUI: ' . $cmd
85 );
86 }
87 }
88
89 protected function showForm(
90 bool $read_only,
91 bool $get_from_post = false,
92 string $error_message = ''
93 ): void {
94 $content = [];
95 if ($error_message !== '') {
96 $content[] = $this->readme_helper->getServerErrorMessageBox($error_message);
97 }
98
99 $form = $this->initForm($read_only);
100 if ($get_from_post) {
101 $form = $form->withRequest($this->http->request());
102 }
103 $content[] = $form;
104
105 $this->tpl->setContent($this->renderer->render($content));
106 }
107
108 protected function update(): void
109 {
110 $form = $this->initForm(false)
111 ->withRequest($this->http->request());
112
113 if (!$form->getData()) {
114 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_check_input'));
115 $this->showForm(false, true);
116 return;
117 }
118
119 $settings = $this->getSettings();
120
121 $main_data = $form->getData()['section'];
122 $filter_data = $form->getData()['filter_section'];
123 $user_data = $form->getData()['user_section'];
124
125 $settings->setMaxHits((int) $main_data['max_hits']);
126
127 switch ((int) $main_data['search_type']) {
129 $settings->enableLucene(false);
130 break;
132 $settings->enableLucene(true);
133 break;
134 }
135 $settings->setDefaultOperator((int) $main_data['operator']);
136 $settings->enableLuceneItemFilter(!is_null($filter_data['filter']));
137 if (!is_null($filter_data['filter'])) {
138 $settings->setLuceneItemFilter((array) $filter_data['filter']);
139 }
140 $settings->enableDateFilter((bool) $filter_data['cdate']);
141 $settings->setAutoCompleteLength((int) $user_data['auto_complete_length']);
142 $settings->showInactiveUser((bool) $user_data['inactive_user']);
143 $settings->showLimitedUser((bool) $user_data['limited_user']);
144 $settings->update();
145
146 // refresh lucene server
147 try {
148 if ($settings->enabledLucene()) {
149 $this->coordinator->refreshLuceneSettings();
150 }
151 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
152 $this->ctrl->redirect($this, 'edit');
153 } catch (Exception $exception) {
154 $this->showForm(false, false, $exception->getMessage());
155 }
156 }
157
158 protected function showPermissionDenied(): void
159 {
160 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
161 $this->ctrl->redirect($this, 'readOnly');
162 }
163
164 protected function initForm(bool $read_only): StandardForm
165 {
166 $settings = $this->getSettings();
167 $field_factory = $this->factory->input()->field();
168
169 // Max hits
170 $values = [];
171 for ($value = 5; $value <= 50; $value += 5) {
172 $values[$value] = $value;
173 }
174 $hits = $field_factory->select(
175 $this->lng->txt('seas_max_hits'),
176 $values,
177 $this->lng->txt('seas_max_hits_info')
178 )->withValue($settings->getMaxHits())
179 ->withRequired(true);
180
181 // Search type
182 $type = $field_factory->radio(
183 $this->lng->txt('seas_search_type')
184 )->withOption(
186 $this->lng->txt('search_direct'),
187 $this->lng->txt('search_like_info')
188 )->withOption(
190 $this->lng->txt('search_lucene'),
191 $this->lng->txt('java_server_info')
192 )->withRequired(true);
193
194 if ($settings->enabledLucene()) {
195 $type = $type->withValue((string) ilSearchSettings::LUCENE_SEARCH);
196 } else {
197 $type = $type->withValue((string) ilSearchSettings::LIKE_SEARCH);
198 }
199
200 // Default operator
201 $operator = $field_factory->radio(
202 $this->lng->txt('lucene_default_operator'),
203 $this->lng->txt('lucene_default_operator_info')
204 )->withOption(
206 $this->lng->txt('lucene_and')
207 )->withOption(
209 $this->lng->txt('lucene_or')
210 )->withRequired(true)
211 ->withValue((string) $settings->getDefaultOperator());
212
213 // Item filter
214 $filter = $settings->getLuceneItemFilter();
215 $checks = [];
216 foreach (ilSearchSettings::getLuceneItemFilterDefinitions() as $obj => $def) {
217 $checks[$obj] = $field_factory->checkbox(
218 $this->lng->txt($def['trans'])
219 )->withValue(isset($filter[$obj]) && $filter[$obj]);
220 }
221
222 $item_filter = $field_factory->optionalGroup(
223 $checks,
224 $this->lng->txt('search_item_filter_form'),
225 $this->lng->txt('search_item_filter_form_info')
226 );
227 if (!$settings->isLuceneItemFilterEnabled()) {
228 $item_filter = $item_filter->withValue(null);
229 }
230
231 // Filter by date
232 $cdate = $field_factory->checkbox(
233 $this->lng->txt('search_cdate_filter'),
234 $this->lng->txt('search_cdate_filter_info')
235 )->withValue($settings->isDateFilterEnabled());
236
237 // number of auto complete entries
238 $options = [
239 0 => 0,
240 5 => 5,
241 10 => 10,
242 20 => 20,
243 30 => 30
244 ];
245 $auto_complete = $field_factory->select(
246 $this->lng->txt('search_auto_complete_length'),
247 $options,
248 $this->lng->txt('search_auto_complete_length_info'),
249 )->withRequired(true)->withValue($settings->getAutoCompleteLength());
250
251 // Show inactive users
252 $inactive_user = $field_factory->checkbox(
253 $this->lng->txt('search_show_inactive_user'),
254 $this->lng->txt('search_show_inactive_user_info')
255 )->withValue($settings->isInactiveUserVisible());
256
257 // Show limited users
258 $limited_user = $field_factory->checkbox(
259 $this->lng->txt('search_show_limited_user'),
260 $this->lng->txt('search_show_limited_user_info')
261 )->withValue($settings->isLimitedUserVisible());
262
263 $section = $this->factory->input()->field()->section(
264 [
265 'search_type' => $type,
266 'max_hits' => $hits,
267 'operator' => $operator
268 ],
269 $this->lng->txt('seas_settings')
270 )->withDisabled($read_only);
271
272 $filter_section = $this->factory->input()->field()->section(
273 [
274 'filter' => $item_filter,
275 'cdate' => $cdate
276 ],
277 $this->lng->txt('search_filter_settings_section')
278 )->withDisabled($read_only);
279
280 $user_section = $this->factory->input()->field()->section(
281 [
282 'auto_complete_length' => $auto_complete,
283 'inactive_user' => $inactive_user,
284 'limited_user' => $limited_user
285 ],
286 $this->lng->txt('user_search_settings_section')
287 )->withDisabled($read_only);
288
289 if ($read_only) {
290 $action = $this->ctrl->getFormAction($this, 'permDenied');
291 } else {
292 $action = $this->ctrl->getFormAction($this, 'update');
293 }
294
295 return $this->factory->input()->container()->form()->standard(
296 $action,
297 [
298 'section' => $section,
299 'filter_section' => $filter_section,
300 'user_section' => $user_section
301 ]
302 );
303 }
304
305 protected function getSettings(): ilSearchSettings
306 {
308 }
309}
renderer()
factory()
Provides fluid interface to RBAC services.
Definition: UIServices.php:25
renderer()
Get a renderer for UI components.
Definition: UIServices.php:44
mainTemplate()
Get the ILIAS main template.
Definition: UIServices.php:54
factory()
Get the factory that crafts UI components.
Definition: UIServices.php:36
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
language handling
showForm(bool $read_only, bool $get_from_post=false, string $error_message='')
ilObjSearchRpcClientCoordinator $coordinator
__construct(GlobalHttpState $http, ilCtrlInterface $ctrl, ilLanguage $lng, UIServices $ui, ilObjSearchRpcClientCoordinator $coordinator, ServerReadmeHelper $readme_helper)
static getLuceneItemFilterDefinitions()
Get lucene item filter definitions.
Interface GlobalHttpState.
This describes a standard form.
Definition: Standard.php:30
This is how the factory for UI elements looks.
Definition: Factory.php:38
An entity that renders components to a string output.
Definition: Renderer.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.