ILIAS  trunk Revision v11.0_alpha-1838-g59fc79e306b
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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  private \ilGlobalTemplateInterface $main_tpl;
41 
42 
46  public function __construct(protected \ilBiblAdminFactoryFacadeInterface $facade, protected \ilBiblFieldInterface $field)
47  {
48  global $DIC;
49  $DIC->language()->loadLanguageModule('obj');
50  $this->main_tpl = $DIC->ui()->mainTemplate();
51  $this->ctrl = $DIC['ilCtrl'];
52  $this->lom_services = $DIC->learningObjectMetadata();
53  }
54 
55 
56  public function executeCommand(): void
57  {
58  $cmd = $this->ctrl->getCmd(self::CMD_DEFAULT);
59  $this->{$cmd}();
60  }
61 
62 
63  protected function index(): void
64  {
65  $this->initToolbar();
66 
67  $table = new ilBiblTranslationTableGUI($this, $this->field, $this->facade->translationFactory());
68  $this->tpl()->setContent($table->getHTML());
69  }
70 
71 
72  protected function initToolbar(): void
73  {
74  $this->toolbar()->addButton($this->lng()->txt("obj_add_languages"), $this->ctrl
75  ->getLinkTarget($this, self::CMD_ADD_LANGUAGE));
76  }
77 
78 
79  protected function saveTranslations(): void
80  {
81  $to_translate = (array) $this->http()->request()->getParsedBody()[self::P_TRANSLATIONS];
82  foreach ($to_translate as $id => $data) {
83  $translation = $this->facade->translationFactory()->findById($id);
84  $translation->setTranslation($data['translation']);
85  $translation->setDescription($data['description']);
86  $translation->store();
87  }
88  $this->main_tpl->setOnScreenMessage('info', $this->lng()->txt('bibl_msg_translations_saved'), true);
89  $this->cancel();
90  }
91 
92 
93  protected function deleteTranslations(): void
94  {
95  $to_delete = (array) $this->http()->request()->getParsedBody()[self::P_DELETE];
96  foreach ($to_delete as $id) {
97  $this->facade->translationFactory()->deleteById($id);
98  }
99  $this->main_tpl->setOnScreenMessage('info', $this->lng()->txt('bibl_msg_translations_deleted'), true);
100  $this->cancel();
101  }
102 
103 
104  protected function addLanguages(): void
105  {
106  $form = $this->getLanguagesForm();
107 
108  $this->tpl()->setContent($form->getHTML());
109  }
110 
111 
112  protected function saveLanguages(): void
113  {
114  $form = $this->getLanguagesForm();
115  if ($form->checkInput()) {
116  $ad = $form->getInput("additional_langs");
117  if (is_array($ad)) {
118  foreach ($ad as $language_key) {
119  $this->facade->translationFactory()
120  ->findArCreateInstanceForFieldAndlanguage($this->field, $language_key);
121  }
122  }
123  $this->main_tpl->setOnScreenMessage('info', $this->lng()->txt("msg_obj_modified"), true);
124  $this->cancel();
125  }
126 
127  $this->main_tpl->setOnScreenMessage('failure', $this->lng()->txt('err_check_input'));
128  $form->setValuesByPost();
129  $this->tpl()->setContent($form->getHTML());
130  }
131 
132 
133  protected function getLanguagesForm(): \ilPropertyFormGUI
134  {
135  $form = new ilPropertyFormGUI();
136  $form->setFormAction($this->ctrl->getFormAction($this));
137 
138  // master language
139  // $options = ilMDLanguageItem::_getLanguages();
140  // $si = new ilSelectInputGUI($this->lng()->txt("obj_master_lang"), "master_lang");
141  // $si->setOptions($options);
142  // $si->setValue($this->user()->getLanguage());
143  // $form->addItem($si);
144 
145  // additional languages
146  $options = [];
147  foreach ($this->lom_services->dataHelper()->getAllLanguages() as $language) {
148  $options[$language->value()] = $language->presentableLabel();
149  }
150  $options = ["" => $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 }
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.
Class ilBiblTranslationTableGUI.
static http()
Fetches the global http state from ILIAS.
ilGlobalTemplateInterface $main_tpl
global $DIC
Definition: shib_login.php:22
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
__construct(protected \ilBiblAdminFactoryFacadeInterface $facade, protected \ilBiblFieldInterface $field)
ilBiblTranslationGUI constructor.