ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 $user_data = $form->getData()['user_section'];
123
124 $settings->setMaxHits((int) $main_data['max_hits']);
125
126 switch ((int) $main_data['search_type']) {
128 $settings->enableLucene(false);
129 break;
131 $settings->enableLucene(true);
132 break;
133 }
134 $settings->setDefaultOperator((int) $main_data['operator']);
135 $settings->enableLuceneItemFilter(!is_null($main_data['filter']));
136 if (!is_null($main_data['filter'])) {
137 $settings->setLuceneItemFilter((array) $main_data['filter']);
138 }
139 $settings->enableDateFilter((bool) $main_data['cdate']);
140 $settings->setAutoCompleteLength((int) $user_data['auto_complete_length']);
141 $settings->showInactiveUser((bool) $user_data['inactive_user']);
142 $settings->showLimitedUser((bool) $user_data['limited_user']);
143 $settings->update();
144
145 // refresh lucene server
146 try {
147 if ($settings->enabledLucene()) {
148 $this->coordinator->refreshLuceneSettings();
149 }
150 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
151 $this->ctrl->redirect($this, 'edit');
152 } catch (Exception $exception) {
153 $this->showForm(false, false, $exception->getMessage());
154 }
155 }
156
157 protected function showPermissionDenied(): void
158 {
159 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
160 $this->ctrl->redirect($this, 'readOnly');
161 }
162
163 protected function initForm(bool $read_only): StandardForm
164 {
165 $settings = $this->getSettings();
166 $field_factory = $this->factory->input()->field();
167
168 // Max hits
169 $values = [];
170 for ($value = 5; $value <= 50; $value += 5) {
171 $values[$value] = $value;
172 }
173 $hits = $field_factory->select(
174 $this->lng->txt('seas_max_hits'),
175 $values,
176 $this->lng->txt('seas_max_hits_info')
177 )->withValue($settings->getMaxHits())
178 ->withRequired(true);
179
180 // Search type
181 $type = $field_factory->radio(
182 $this->lng->txt('seas_search_type')
183 )->withOption(
185 $this->lng->txt('search_direct'),
186 $this->lng->txt('search_like_info')
187 )->withOption(
189 $this->lng->txt('search_lucene'),
190 $this->lng->txt('java_server_info')
191 )->withRequired(true);
192
193 if ($settings->enabledLucene()) {
194 $type = $type->withValue((string) ilSearchSettings::LUCENE_SEARCH);
195 } else {
196 $type = $type->withValue((string) ilSearchSettings::LIKE_SEARCH);
197 }
198
199 // Default operator
200 $operator = $field_factory->radio(
201 $this->lng->txt('lucene_default_operator'),
202 $this->lng->txt('lucene_default_operator_info')
203 )->withOption(
205 $this->lng->txt('lucene_and')
206 )->withOption(
208 $this->lng->txt('lucene_or')
209 )->withRequired(true)
210 ->withValue((string) $settings->getDefaultOperator());
211
212 // Item filter
213 $filter = $settings->getLuceneItemFilter();
214 $checks = [];
215 foreach (ilSearchSettings::getLuceneItemFilterDefinitions() as $obj => $def) {
216 $checks[$obj] = $field_factory->checkbox(
217 $this->lng->txt($def['trans'])
218 )->withValue(isset($filter[$obj]) && $filter[$obj]);
219 }
220
221 $item_filter = $field_factory->optionalGroup(
222 $checks,
223 $this->lng->txt('search_item_filter_form'),
224 $this->lng->txt('search_item_filter_form_info')
225 );
226 if (!$settings->isLuceneItemFilterEnabled()) {
227 $item_filter = $item_filter->withValue(null);
228 }
229
230 // Filter by date
231 $cdate = $field_factory->checkbox(
232 $this->lng->txt('search_cdate_filter'),
233 $this->lng->txt('search_cdate_filter_info')
234 )->withValue($settings->isDateFilterEnabled());
235
236 // number of auto complete entries
237 $options = [
238 0 => 0,
239 5 => 5,
240 10 => 10,
241 20 => 20,
242 30 => 30
243 ];
244 $auto_complete = $field_factory->select(
245 $this->lng->txt('search_auto_complete_length'),
246 $options
247 )->withRequired(true)->withValue($settings->getAutoCompleteLength());
248
249 // Show inactive users
250 $inactive_user = $field_factory->checkbox(
251 $this->lng->txt('search_show_inactive_user'),
252 $this->lng->txt('search_show_inactive_user_info')
253 )->withValue($settings->isInactiveUserVisible());
254
255 // Show limited users
256 $limited_user = $field_factory->checkbox(
257 $this->lng->txt('search_show_limited_user'),
258 $this->lng->txt('search_show_limited_user_info')
259 )->withValue($settings->isLimitedUserVisible());
260
264 $section = $this->factory->input()->field()->section(
265 [
266 'max_hits' => $hits,
267 'search_type' => $type,
268 'operator' => $operator,
269 'filter' => $item_filter,
270 'cdate' => $cdate
271 ],
272 $this->lng->txt('seas_settings')
273 )->withDisabled($read_only);
274
275 $user_section = $this->factory->input()->field()->section(
276 [
277 'auto_complete_length' => $auto_complete,
278 'inactive_user' => $inactive_user,
279 'limited_user' => $limited_user
280 ],
281 $this->lng->txt('user_search_settings_section')
282 )->withDisabled($read_only);
283
284 if ($read_only) {
285 $action = $this->ctrl->getFormAction($this, 'permDenied');
286 } else {
287 $action = $this->ctrl->getFormAction($this, 'update');
288 }
289
290 return $this->factory->input()->container()->form()->standard(
291 $action,
292 [
293 'section' => $section,
294 'user_section' => $user_section,
295 ]
296 );
297 }
298
299 protected function getSettings(): ilSearchSettings
300 {
302 }
303}
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:29
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.