ILIAS  release_8 Revision v8.24
class.ilBiblTranslationGUI.php
Go to the documentation of this file.
1<?php
2
19use ILIAS\Modules\OrgUnit\ARHelper\DIC;
20
28{
29 use DIC;
30 public const P_TRANSLATIONS = 'translations';
31 public const P_DELETE = 'delete';
32 public const CMD_ADD_LANGUAGE = "addLanguages";
33 public const CMD_SAVE_LANGUAGES = "saveLanguages";
34 public const CMD_SAVE_TRANSLATIONS = "saveTranslations";
35 public const CMD_DELETE_TRANSLATIONS = "deleteTranslations";
36 public const CMD_DEFAULT = 'index';
37 protected \ilBiblAdminFactoryFacadeInterface $facade;
38 protected \ilBiblFieldInterface $field;
39 private \ilGlobalTemplateInterface $main_tpl;
40
41
46 {
47 global $DIC;
48 $DIC->language()->loadLanguageModule('obj');
49 $this->main_tpl = $DIC->ui()->mainTemplate();
50 $this->facade = $facade;
51 $this->field = $field;
52 }
53
54
55 public function executeCommand(): void
56 {
57 $this->ctrl()->saveParameter($this, ilBiblAdminFieldGUI::FIELD_IDENTIFIER);
58 switch ($this->ctrl()->getNextClass()) {
59 default:
60 $cmd = $this->ctrl()->getCmd(self::CMD_DEFAULT);
61 $this->{$cmd}();
62 }
63 }
64
65
66 protected function index(): void
67 {
68 $this->initToolbar();
69
70 $table = new ilBiblTranslationTableGUI($this, $this->field, $this->facade->translationFactory());
71 $this->tpl()->setContent($table->getHTML());
72 }
73
74
75 protected function initToolbar(): void
76 {
77 $this->toolbar()->addButton($this->lng()->txt("obj_add_languages"), $this->ctrl()
78 ->getLinkTarget($this, self::CMD_ADD_LANGUAGE));
79 }
80
81
82 protected function saveTranslations(): void
83 {
84 $to_translate = (array) $this->http()->request()->getParsedBody()[self::P_TRANSLATIONS];
85 foreach ($to_translate as $id => $data) {
86 $translation = $this->facade->translationFactory()->findById($id);
87 $translation->setTranslation($data['translation']);
88 $translation->setDescription($data['description']);
89 $translation->store();
90 }
91 $this->main_tpl->setOnScreenMessage('info', $this->lng()->txt('bibl_msg_translations_saved'), true);
92 $this->cancel();
93 }
94
95
96 protected function deleteTranslations(): void
97 {
98 $to_delete = (array) $this->http()->request()->getParsedBody()[self::P_DELETE];
99 foreach ($to_delete as $id) {
100 $this->facade->translationFactory()->deleteById($id);
101 }
102 $this->main_tpl->setOnScreenMessage('info', $this->lng()->txt('bibl_msg_translations_deleted'), true);
103 $this->cancel();
104 }
105
106
107 protected function addLanguages(): void
108 {
109 $form = $this->getLanguagesForm();
110
111 $this->tpl()->setContent($form->getHTML());
112 }
113
114
115 protected function saveLanguages(): void
116 {
117 $form = $this->getLanguagesForm();
118 if ($form->checkInput()) {
119 $ad = $form->getInput("additional_langs");
120 if (is_array($ad)) {
121 foreach ($ad as $language_key) {
122 $this->facade->translationFactory()
123 ->findArCreateInstanceForFieldAndlanguage($this->field, $language_key);
124 }
125 }
126 $this->main_tpl->setOnScreenMessage('info', $this->lng()->txt("msg_obj_modified"), true);
127 $this->cancel();
128 }
129
130 $this->main_tpl->setOnScreenMessage('failure', $this->lng()->txt('err_check_input'));
131 $form->setValuesByPost();
132 $this->tpl()->setContent($form->getHTML());
133 }
134
135
136 protected function getLanguagesForm(): \ilPropertyFormGUI
137 {
138 $form = new ilPropertyFormGUI();
139 $form->setFormAction($this->ctrl()->getFormAction($this));
140
141 // master language
142 // $options = ilMDLanguageItem::_getLanguages();
143 // $si = new ilSelectInputGUI($this->lng()->txt("obj_master_lang"), "master_lang");
144 // $si->setOptions($options);
145 // $si->setValue($this->user()->getLanguage());
146 // $form->addItem($si);
147
148 // additional languages
150 $options = array("" => $this->lng()->txt("please_select")) + $options;
151 $si = new ilSelectInputGUI($this->lng()->txt("obj_additional_langs"), "additional_langs");
152 $si->setOptions($options);
153 $si->setMulti(true);
154 $form->addItem($si);
155
156 $form->setTitle($this->lng()->txt("obj_add_languages"));
157 $form->addCommandButton(self::CMD_SAVE_LANGUAGES, $this->lng()->txt("save"));
158 $form->addCommandButton(self::CMD_DEFAULT, $this->lng()->txt("cancel"));
159
160 return $form;
161 }
162
163
164 protected function cancel(): void
165 {
166 $this->ctrl()->redirect($this, self::CMD_DEFAULT);
167 }
168}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Class ilBiblTranslationGUI.
__construct(ilBiblAdminFactoryFacadeInterface $facade, \ilBiblFieldInterface $field)
ilBiblTranslationGUI constructor.
ilGlobalTemplateInterface $main_tpl
ilBiblAdminFactoryFacadeInterface $facade
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a property form user interface.
This class represents a selection list property in a property form.
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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.