ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilBiblTranslationGUI.php
Go to the documentation of this file.
1 <?php
2 
4 
12 {
13  use DIC;
14  const P_TRANSLATIONS = 'translations';
15  const P_DELETE = 'delete';
16  const CMD_ADD_LANGUAGE = "addLanguages";
17  const CMD_SAVE_LANGUAGES = "saveLanguages";
18  const CMD_SAVE_TRANSLATIONS = "saveTranslations";
19  const CMD_DELETE_TRANSLATIONS = "deleteTranslations";
20  const CMD_DEFAULT = 'index';
24  protected $facade;
28  protected $field;
29 
30 
38  {
39  $this->facade = $facade;
40  $this->field = $field;
41  }
42 
43 
44  public function executeCommand()
45  {
46  $this->ctrl()->saveParameter($this, ilBiblAdminFieldGUI::FIELD_IDENTIFIER);
47  switch ($this->ctrl()->getNextClass()) {
48  default:
49  $cmd = $this->ctrl()->getCmd(self::CMD_DEFAULT);
50  $this->{$cmd}();
51  }
52  }
53 
54 
55  protected function index()
56  {
57  $this->initToolbar();
58 
59  $table = new ilBiblTranslationTableGUI($this, $this->field, $this->facade->translationFactory());
60  $this->tpl()->setContent($table->getHTML());
61  }
62 
63 
64  protected function initToolbar()
65  {
66  $this->toolbar()->addButton($this->lng()->txt("obj_add_languages"), $this->ctrl()
67  ->getLinkTarget($this, self::CMD_ADD_LANGUAGE));
68  }
69 
70 
71  protected function saveTranslations()
72  {
73  $to_translate = (array) $this->http()->request()->getParsedBody()[self::P_TRANSLATIONS];
74  foreach ($to_translate as $id => $data) {
75  $translation = $this->facade->translationFactory()->findById($id);
76  $translation->setTranslation($data['translation']);
77  $translation->setDescription($data['description']);
78  $translation->store();
79  }
80  ilUtil::sendInfo($this->lng()->txt('bibl_msg_translations_saved'), true);
81  $this->cancel();
82  }
83 
84 
85  protected function deleteTranslations()
86  {
87  $to_delete = (array) $this->http()->request()->getParsedBody()[self::P_DELETE];
88  foreach ($to_delete as $id) {
89  $this->facade->translationFactory()->deleteById($id);
90  }
91  ilUtil::sendInfo($this->lng()->txt('bibl_msg_translations_deleted'), true);
92  $this->cancel();
93  }
94 
95 
96  protected function addLanguages()
97  {
98  $form = $this->getLanguagesForm();
99 
100  $this->tpl()->setContent($form->getHTML());
101  }
102 
103 
104  protected function saveLanguages()
105  {
106  $form = $this->getLanguagesForm();
107  if ($form->checkInput()) {
108  $ad = $form->getInput("additional_langs");
109  if (is_array($ad)) {
110  foreach ($ad as $language_key) {
111  $this->facade->translationFactory()
112  ->findArCreateInstanceForFieldAndlanguage($this->field, $language_key);
113  }
114  }
115  ilUtil::sendInfo($this->lng()->txt("msg_obj_modified"), true);
116  $this->cancel();
117  }
118 
119  ilUtil::sendFailure($this->lng()->txt('err_check_input'));
120  $form->setValuesByPost();
121  $this->tpl()->setContent($form->getHTML());
122  }
123 
124 
128  protected function getLanguagesForm()
129  {
130  $form = new ilPropertyFormGUI();
131  $form->setFormAction($this->ctrl()->getFormAction($this));
132 
133  // master language
134  // $options = ilMDLanguageItem::_getLanguages();
135  // $si = new ilSelectInputGUI($this->lng()->txt("obj_master_lang"), "master_lang");
136  // $si->setOptions($options);
137  // $si->setValue($this->user()->getLanguage());
138  // $form->addItem($si);
139 
140  // additional languages
142  $options = array( "" => $this->lng()->txt("please_select") ) + $options;
143  $si = new ilSelectInputGUI($this->lng()->txt("obj_additional_langs"), "additional_langs");
144  $si->setOptions($options);
145  $si->setMulti(true);
146  $form->addItem($si);
147 
148  $form->setTitle($this->lng()->txt("obj_add_languages"));
149  $form->addCommandButton(self::CMD_SAVE_LANGUAGES, $this->lng()->txt("save"));
150  $form->addCommandButton(self::CMD_DEFAULT, $this->lng()->txt("cancel"));
151 
152  return $form;
153  }
154 
155 
156  protected function cancel()
157  {
158  $this->ctrl()->redirect($this, self::CMD_DEFAULT);
159  }
160 }
Interface ilBiblEntryInterface.
This class represents a selection list property in a property form.
This class represents a property form user interface.
if(!array_key_exists('StateId', $_REQUEST)) $id
Class ilBiblTranslationGUI.
Class ilBiblTranslationTableGUI.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static http()
Fetches the global http state from ILIAS.
if(isset($_POST['submit'])) $form
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
if(empty($password)) $table
Definition: pwgen.php:24
__construct(ilBiblAdminFactoryFacadeInterface $facade, \ilBiblFieldInterface $field)
ilBiblTranslationGUI constructor.
$data
Definition: bench.php:6