ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilMMItemTranslationGUI.php
Go to the documentation of this file.
1<?php
2
3use ILIAS\Modules\OrgUnit\ARHelper\DIC;
4
11{
12 use DIC;
13 const P_TRANSLATIONS = 'translations';
14 const P_DELETE = 'delete';
15 const CMD_ADD_LANGUAGE = "addLanguages";
16 const CMD_SAVE_LANGUAGES = "saveLanguages";
17 const CMD_SAVE_TRANSLATIONS = "saveTranslations";
18 const CMD_DELETE_TRANSLATIONS = "deleteTranslations";
19 const CMD_DEFAULT = 'index';
20 const IDENTIFIER = 'identifier';
24 private $repository;
28 private $item_facade;
29
30
37 {
38 $this->item_facade = $item_facade;
39 $this->repository = $repository;
40 $this->lng()->loadLanguageModule("mme");
41 }
42
43
44 public function executeCommand()
45 {
46 $this->ctrl()->saveParameter($this, self::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 ilMMItemTranslationTableGUI($this, $this->item_facade);
60 $this->tpl()->setContent($table->getHTML());
61 }
62
63
64 protected function initToolbar()
65 {
66 $this->toolbar()->addButton(
67 $this->lng()->txt("add_languages"),
68 $this->ctrl()
69 ->getLinkTarget($this, self::CMD_ADD_LANGUAGE)
70 );
71 }
72
73
74 protected function saveTranslations()
75 {
76 $to_translate = (array) $this->http()->request()->getParsedBody()[self::P_TRANSLATIONS];
77 foreach ($to_translate as $id => $data) {
82 $translation->setTranslation($data['translation']);
83 $translation->update();
84 }
85 $this->repository->clearCache();
86 ilUtil::sendInfo($this->lng()->txt('msg_translations_saved'), true);
87 $this->cancel();
88 }
89
90
91 protected function deleteTranslations()
92 {
93 $to_delete = (array) $this->http()->request()->getParsedBody()[self::P_DELETE];
94 foreach ($to_delete as $id) {
96 }
97 $this->repository->updateItem($this->item_facade);
98 ilUtil::sendInfo($this->lng()->txt('msg_translations_deleted'), true);
99 $this->cancel();
100 }
101
102
103 protected function addLanguages()
104 {
105 $form = $this->getLanguagesForm();
106
107 $this->tpl()->setContent($form->getHTML());
108 }
109
110
111 protected function saveLanguages()
112 {
113 $form = $this->getLanguagesForm();
114 if ($form->checkInput()) {
115 $ad = $form->getInput("additional_langs");
116 if (is_array($ad)) {
117 foreach ($ad as $language_key) {
118 ilMMItemTranslationStorage::storeTranslation($this->item_facade->identification(), $language_key, "");
119 }
120 }
121 $this->repository->updateItem($this->item_facade);
122 ilUtil::sendInfo($this->lng()->txt("msg_languages_added"), true);
123 $this->cancel();
124 }
125
126 ilUtil::sendFailure($this->lng()->txt('err_check_input'));
127 $form->setValuesByPost();
128 $this->tpl()->setContent($form->getHTML());
129 }
130
131
136 protected function getLanguagesForm()
137 {
138 $form = new ilPropertyFormGUI();
139 $form->setFormAction($this->ctrl()->getFormAction($this));
140
141 // additional languages
143 $options = array("" => $this->lng()->txt("please_select")) + $options;
144 $si = new ilSelectInputGUI($this->lng()->txt("additional_langs"), "additional_langs");
145 $si->setOptions($options);
146 $si->setMulti(true);
147 $form->addItem($si);
148
149 $form->setTitle($this->lng()->txt("add_languages"));
150 $form->addCommandButton(self::CMD_SAVE_LANGUAGES, $this->lng()->txt("save"));
151 $form->addCommandButton(self::CMD_DEFAULT, $this->lng()->txt("cancel"));
152
153 return $form;
154 }
155
156
157 protected function cancel()
158 {
159 $this->ctrl()->redirect($this, self::CMD_DEFAULT);
160 }
161}
An exception for terminatinating execution or to throw for unit testing.
static find($primary_key, array $add_constructor_args=array())
@inheritDoc
Class ilMMItemRepository.
Class ilMMItemTranslationGUI.
__construct(ilMMItemFacadeInterface $item_facade, ilMMItemRepository $repository)
ilMMItemTranslationGUI constructor.
static storeTranslation(IdentificationInterface $identification, string $language_key, string $translation)
Class ilMMItemTranslationTableGUI.
This class represents a property form user interface.
This class represents a selection list property in a property form.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
if(!array_key_exists('StateId', $_REQUEST)) $id
Interface ilMMItemFacadeInterface.
static http()
Fetches the global http state from ILIAS.
if(empty($password)) $table
Definition: pwgen.php:24
if(isset($_POST['submit'])) $form
repository()
Definition: repository.php:5
$data
Definition: bench.php:6