19 declare(strict_types=1);
70 $this->vocab_manager = $services->vocabularies()->manager();
72 $services->presentation()->elements(),
73 $services->presentation()->utilities(),
74 $services->vocabularies()->presentation(),
75 $services->vocabularies()->slotHandler(),
76 $services->structure()->structure(),
77 $services->paths()->navigatorFactory(),
78 $services->paths()->pathFactory()
81 $services->paths()->pathFactory(),
82 $this->vocab_manager->controlledVocabularyCreator(),
83 $services->vocabularies()->slotHandler()
86 $this->
ctrl = $DIC->ctrl();
87 $this->
http = $DIC->http();
88 $this->temp_files = $DIC->filesystem()->temp();
89 $this->
lng = $DIC->language();
90 $this->tpl = $DIC->ui()->mainTemplate();
91 $this->
toolbar = $DIC->toolbar();
92 $this->ui_factory = $DIC->ui()->factory();
93 $this->ui_renderer = $DIC->ui()->renderer();
98 $this->parent_obj_gui->getRefId(),
102 $this->
lng->loadLanguageModule(
"meta");
107 $next_class = $this->
ctrl->getNextClass($this);
108 $cmd = $this->
ctrl->getCmd();
111 !$this->access_service->hasCurrentUserVisibleAccess() ||
112 !$this->access_service->hasCurrentUserReadAccess()
117 switch ($next_class) {
118 case strtolower(ilMDVocabularyUploadHandlerGUI::class):
124 if (!$cmd || $cmd ===
'view') {
125 $cmd =
'showVocabularies';
137 if ($this->access_service->hasCurrentUserWriteAccess()) {
140 $content[] = $import_modal;
145 $this->tpl->setContent($this->ui_renderer->render($content));
155 ($action !==
'show_all' && !$this->access_service->hasCurrentUserWriteAccess())
157 $this->
ctrl->redirect($this,
'showVocabularies');
162 $this->confirmDeleteVocabulary($vocab_id);
173 case 'allow_custom_input':
177 case 'disallow_custom_input':
182 $this->showAllValuesModalForVocabulary($vocab_id);
186 $this->
ctrl->redirect($this,
'showVocabularies');
192 if (!$this->access_service->hasCurrentUserWriteAccess()) {
193 $this->
ctrl->redirect($this,
'showVocabularies');
196 $message_type =
'failure';
197 $message_text = $this->
lng->txt(
'md_vocab_import_upload_failed');
201 $upload_folder =
null;
203 $upload_folder = (string) (
$modal->getData()[
'file'][0] ??
null);
204 if (!$this->temp_files->hasDir($upload_folder)) {
205 $upload_folder =
null;
209 $file_content =
null;
210 if (!is_null($upload_folder)) {
211 $files = $files = $this->temp_files->listContents($upload_folder);
212 if (count($files) === 1 && ($files[0] ??
null)?->isFile()) {
213 $file_content = $this->temp_files->read($files[0]->getPath());
215 $this->temp_files->deleteDir($upload_folder);
218 if (!is_null($file_content)) {
219 $result = $this->importer->import($file_content);
221 if ($result->wasSuccessful()) {
222 $message_type =
'success';
223 $message_text = $this->
lng->txt(
'md_vocab_import_successful');
225 $message_type =
'failure';
226 $message_text = sprintf(
227 $this->
lng->txt(
'md_vocab_import_invalid'),
228 implode(
"<br/>", $result->getErrors())
233 $this->tpl->setOnScreenMessage($message_type, $message_text,
true);
234 $this->
ctrl->redirect($this,
'showVocabularies');
237 #[NoReturn] protected function confirmDeleteVocabulary(string $vocab_id): void 240 $key = $vocabs_id_token->getName();
242 $vocab = $this->vocab_manager->getVocabulary($vocab_id);
244 foreach ($this->presentation->makeValuesPresentable(
246 self::MAX_CONFIRMATION_VALUES
248 $value_items[] = $this->ui_factory->modal()->interruptiveItem()->standard(
254 $this->
ctrl->setParameter($this,
$key, $vocab_id);
255 $link = $this->
ctrl->getLinkTarget($this,
'deleteVocabulary');
256 $this->
ctrl->clearParameters($this);
258 $modal = $this->ui_factory->modal()->interruptive(
259 $this->presentation->txt(
'md_vocab_delete_confirmation_title'),
260 $this->presentation->txtFill(
261 'md_vocab_delete_confirmation_text',
262 $this->presentation->makeSlotPresentable(
$vocab->slot()),
267 echo $this->ui_renderer->renderAsync(
$modal);
274 if ($vocab_id !==
'') {
275 $this->vocab_manager->actions()->delete(
276 $this->vocab_manager->getVocabulary($vocab_id)
279 $this->tpl->setOnScreenMessage(
280 GlobalTemplate::MESSAGE_TYPE_SUCCESS,
281 $this->
lng->txt(
'md_vocab_deletion_successful'),
284 $this->
ctrl->redirect($this,
'showVocabularies');
289 $this->vocab_manager->actions()->activate(
290 $this->vocab_manager->getVocabulary($vocab_id)
292 $this->tpl->setOnScreenMessage(
293 GlobalTemplate::MESSAGE_TYPE_SUCCESS,
294 $this->
lng->txt(
'md_vocab_update_successful'),
297 $this->
ctrl->redirect($this,
'showVocabularies');
302 $this->vocab_manager->actions()->deactivate(
303 $this->vocab_manager->getVocabulary($vocab_id)
305 $this->tpl->setOnScreenMessage(
306 GlobalTemplate::MESSAGE_TYPE_SUCCESS,
307 $this->
lng->txt(
'md_vocab_update_successful'),
310 $this->
ctrl->redirect($this,
'showVocabularies');
315 $this->vocab_manager->actions()->allowCustomInput(
316 $this->vocab_manager->getVocabulary($vocab_id)
318 $this->tpl->setOnScreenMessage(
319 GlobalTemplate::MESSAGE_TYPE_SUCCESS,
320 $this->
lng->txt(
'md_vocab_update_successful'),
323 $this->
ctrl->redirect($this,
'showVocabularies');
328 $this->vocab_manager->actions()->disallowCustomInput(
329 $this->vocab_manager->getVocabulary($vocab_id)
331 $this->tpl->setOnScreenMessage(
332 GlobalTemplate::MESSAGE_TYPE_SUCCESS,
333 $this->
lng->txt(
'md_vocab_update_successful'),
336 $this->
ctrl->redirect($this,
'showVocabularies');
339 #[NoReturn] protected function showAllValuesModalForVocabulary(string $vocab_id): void 341 $vocab = $this->vocab_manager->getVocabulary($vocab_id);
342 $values = $this->ui_factory->listing()->unordered(
343 $this->presentation->makeValuesPresentable(
$vocab)
345 $modal = $this->ui_factory->modal()->roundtrip(
346 $this->presentation->txtFill(
347 'md_vocab_all_values_title',
348 $this->presentation->makeSlotPresentable(
$vocab->slot()),
353 echo $this->ui_renderer->renderAsync(
$modal);
359 $column_factory = $this->ui_factory->table()->column();
361 'element' => $column_factory->text($this->
lng->txt(
'md_vocab_element_column'))->withIsSortable(
false),
362 'type' => $column_factory->status($this->
lng->txt(
'md_vocab_type_column'))->withIsSortable(
false),
363 'source' => $column_factory->text($this->
lng->txt(
'md_vocab_source_column'))->withIsSortable(
false),
364 'preview' => $column_factory->text($this->
lng->txt(
'md_vocab_preview_column'))->withIsSortable(
false),
365 'active' => $column_factory->statusIcon($this->
lng->txt(
'md_vocab_active_column'))->withIsSortable(
false),
366 'custom_input' => $column_factory->statusIcon($this->
lng->txt(
'md_vocab_custom_input_column'))->withIsSortable(
false)
370 $actions_factory = $this->ui_factory->table()->action();
373 if ($this->access_service->hasCurrentUserWriteAccess()) {
374 $actions [
'delete'] = $actions_factory->single(
375 $this->
lng->txt(
'md_vocab_delete_action'),
376 $url_builder->withParameter($action_parameter_token,
'delete'),
379 $actions[
'activate'] = $actions_factory->single(
380 $this->
lng->txt(
'md_vocab_activate_action'),
381 $url_builder->withParameter($action_parameter_token,
'activate'),
384 $actions[
'deactivate'] = $actions_factory->single(
385 $this->
lng->txt(
'md_vocab_deactivate_action'),
386 $url_builder->withParameter($action_parameter_token,
'deactivate'),
389 $actions[
'allow_custom_input'] = $actions_factory->single(
390 $this->
lng->txt(
'md_vocab_allow_custom_input_action'),
391 $url_builder->withParameter($action_parameter_token,
'allow_custom_input'),
394 $actions[
'disallow_custom_input'] = $actions_factory->single(
395 $this->
lng->txt(
'md_vocab_disallow_custom_input_action'),
396 $url_builder->withParameter($action_parameter_token,
'disallow_custom_input'),
401 $actions[
'show_all'] = $actions_factory->single(
402 $this->
lng->txt(
'md_vocab_show_all_action'),
403 $url_builder->withParameter($action_parameter_token,
'show_all'),
407 return $this->ui_factory->table()->data(
409 $this->vocab_manager,
413 $this->
lng->txt(
'md_vocab_table_title'),
415 )->withActions($actions)->withRequest($this->
http->request());
420 $file_input = $this->ui_factory->input()->field()->file(
422 $this->
lng->txt(
'md_import_file_vocab')
423 )->withAcceptedMimeTypes([MimeType::TEXT__XML])->withMaxFiles(1);
425 return $this->ui_factory->modal()->roundtrip(
426 $this->
lng->txt(
'md_import_vocab_modal'),
428 [
'file' => $file_input],
429 $this->
ctrl->getLinkTarget($this,
'importVocabulary')
435 return $this->ui_factory->button()->standard(
436 $this->
lng->txt(
'md_import_vocab'),
444 $key = $action_parameter_token->getName();
445 if ($this->
http->wrapper()->query()->has(
$key)) {
446 return $this->
http->wrapper()->query()->retrieve(
457 $key = $vocabs_id_token->getName();
458 if ($this->
http->wrapper()->query()->has(
$key)) {
459 return $this->
http->wrapper()->query()->retrieve(
470 rtrim(ILIAS_HTTP_PATH,
'/') .
'/' . $this->
ctrl->getLinkTarget($this,
'tableAction')
472 return $url_builder->acquireParameters(
473 [
'metadata',
'vocab'],
ilMDVocabulariesGUI: ilMDVocabularyUploadHandlerGUI
__construct(ilObjMDSettingsGUI $parent_obj_gui)
const int MAX_CONFIRMATION_VALUES
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
allowCustomInputForVocabulary(string $vocab_id)
ilMDSettingsAccessService $access_service
deactivateVocabulary(string $vocab_id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
VocabManager $vocab_manager
ilGlobalTemplateInterface $tpl
static http()
Fetches the global http state from ILIAS.
activateVocabulary(string $vocab_id)
Presentation $presentation
ilObjMDSettingsGUI $parent_obj_gui
disallowCustomInputForVocabulary(string $vocab_id)
getImportButton(Signal $signal)
getTableURLBuilderAndParameters()