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