ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilAdvancedMDTranslationGUI.php
Go to the documentation of this file.
1<?php
2
3use Psr\Http\Message\RequestInterface;
4
6{
10 protected const CMD_DEFAULT = 'translations';
11 protected const CMD_ADD_TRANSLATION = 'addTranslations';
12 protected const CMD_SAVE_ADDITIONAL_TRANSLATIONS = 'saveAdditionalTranslations';
13
14
18 protected $ctrl;
19
23 protected $tpl;
24
28 protected $toolbar;
29
33 protected $tabs;
34
38 protected $language;
39
43 protected $request;
44
48 protected $logger;
49
53 protected $record;
54
60 {
61 global $DIC;
62
63 $this->ctrl = $DIC->ctrl();
64 $this->tabs = $DIC->tabs();
65 $this->tpl = $DIC->ui()->mainTemplate();
66 $this->logger = $DIC->logger()->amet();
67 $this->toolbar = $DIC->toolbar();
68 $this->language = $DIC->language();
69 $this->language->loadLanguageModule('obj');
70 $this->request = $DIC->http()->request();
71 $this->record = $record;
72 }
73
77 public function executeCommand()
78 {
79 $this->ctrl->setParameterByClass(
80 strtolower(get_class($this)),
81 'record_id',
82 $this->record->getRecordId()
83 );
84
85 $next_class = $this->ctrl->getNextClass($this);
86 $cmd = $this->ctrl->getCmd(self::CMD_DEFAULT);
87 switch ($next_class) {
88 default:
89 $this->$cmd();
90 }
91 }
92
96 protected function setTabs(string $active_tab)
97 {
98 $this->tabs->activateTab($active_tab);
99 }
100
104 abstract protected function translations();
105
109 protected function addTranslations(ilPropertyFormGUI $form = null)
110 {
111 $this->tabs->activateTab(self::CMD_DEFAULT);
112 if (!$form instanceof ilPropertyFormGUI)
113 {
114 $form = $this->initCreateTranslationForm();
115 }
116 $this->tpl->setContent($form->getHTML());
117 }
118
122 protected function initCreateTranslationForm()
123 {
124 $form = new \ilPropertyFormGUI();
125 $form->setFormAction($this->ctrl->getFormAction($this));
126 $form->setTitle($this->language->txt('obj_add_languages'));
127
128 $language_options = $this->getAvailableLanguagesOptions();
129 $languages = new ilSelectInputGUI(
130 $this->language->txt('obj_additional_langs'),
131 'languages'
132 );
133 $languages->setOptions($language_options);
134 $languages->setMulti(true);
135 $languages->setRequired(true);
136 $form->addItem($languages);
137
138 $form->addCommandButton(
139 self::CMD_SAVE_ADDITIONAL_TRANSLATIONS,
140 $this->language->txt('save')
141 );
142 $form->addCommandButton(
143 self::CMD_DEFAULT,
144 $this->language->txt('cancel')
145 );
146
147 return $form;
148 }
149
150 protected function addToolbarLanguageCreation()
151 {
152 $button = ilLinkButton::getInstance();
153 $button->setCaption('obj_add_languages');
154 $button->setUrl(
155 $this->ctrl->getLinkTargetByClass(
156 strtolower(get_class($this)),
157 self::CMD_ADD_TRANSLATION
158 )
159 );
160 $this->toolbar->addButtonInstance($button);
161 }
162
167 protected function getAvailableLanguagesOptions()
168 {
169 $languages = ilAdvancedMDRecordTranslations::getInstanceByRecordId($this->record->getRecordId());
170
171 $this->language->loadLanguageModule('meta');
172 $installed_languages = ilLanguage::_getInstalledLanguages();
173 $options = [];
174 $options[''] = $this->language->txt('select_one');
175 foreach ($installed_languages as $key => $language) {
176
177 if ($languages->isConfigured($language)) {
178 continue;
179 }
180 $options[$language] = $this->language->txt('meta_l_' . $language);
181 }
182 return $options;
183 }
184
185 protected function saveAdditionalTranslations()
186 {
187 $form = $this->initCreateTranslationForm();
188 if (!$form->checkInput()) {
189 $form->setValuesByPost();
190 ilUtil::sendFailure($this->language->txt('err_check_input'));
191 return $this->addTranslations($form);
192 }
193 foreach (array_unique((array) $form->getInput('languages')) as $language_code) {
194
195 $languages = ilAdvancedMDRecordTranslations::getInstanceByRecordId($this->record->getRecordId());
196 $languages->addTranslationEntry($language_code);
197 }
198
199 ilUtil::sendSuccess($this->language->txt('settings_saved'), true);
200 $this->ctrl->redirect($this, self::CMD_DEFAULT);
201 }
202
203
204}
An exception for terminatinating execution or to throw for unit testing.
addTranslations(ilPropertyFormGUI $form=null)
show translation creation form
__construct(ilAdvancedMDRecord $record)
ilAdvancedMDTranslationGUI constructor.
executeCommand()
Execute command and save parameter record id.
static _getInstalledLanguages()
static getInstance()
Factory.
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.
global $DIC
Definition: goto.php:24
language()
Definition: language.php:2