ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilAdvancedMDTranslationGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use Psr\Http\Message\RequestInterface;
22
24{
25 protected const CMD_DEFAULT = 'translations';
26 protected const CMD_ADD_TRANSLATION = 'addTranslations';
27 protected const CMD_SAVE_ADDITIONAL_TRANSLATIONS = 'saveAdditionalTranslations';
28
29 protected ilCtrl $ctrl;
32 protected ilTabsGUI $tabs;
34 protected RequestInterface $request;
35 protected ilLogger $logger;
37
39 {
40 global $DIC;
41
42 $this->ctrl = $DIC->ctrl();
43 $this->tpl = $DIC->ui()->mainTemplate();
44 $this->toolbar = $DIC->toolbar();
45 $this->tabs = $DIC->tabs();
46 $this->language = $DIC->language();
47 $this->language->loadLanguageModule('obj');
48 $this->request = $DIC->http()->request();
50 $this->logger = $DIC->logger()->amet();
51 $this->record = $record;
52 }
53
57 public function executeCommand()
58 {
59 $this->ctrl->setParameterByClass(
60 strtolower(get_class($this)),
61 'record_id',
62 $this->record->getRecordId()
63 );
64
65 $next_class = $this->ctrl->getNextClass($this);
66 $cmd = $this->ctrl->getCmd(self::CMD_DEFAULT);
67 switch ($next_class) {
68 default:
69 $this->$cmd();
70 }
71 }
72
73 protected function setTabs(string $active_tab)
74 {
75 $this->tabs->activateTab($active_tab);
76 }
77
81 abstract protected function translations(): void;
82
86 protected function addTranslations(?ilPropertyFormGUI $form = null)
87 {
88 $this->tabs->activateTab(self::CMD_DEFAULT);
89 if (!$form instanceof ilPropertyFormGUI) {
90 $form = $this->initCreateTranslationForm();
91 }
92 $this->tpl->setContent($form->getHTML());
93 }
94
96 {
97 $form = new \ilPropertyFormGUI();
98 $form->setFormAction($this->ctrl->getFormAction($this));
99 $form->setTitle($this->language->txt('obj_add_languages'));
100
101 $language_options = $this->getAvailableLanguagesOptions();
102 $languages = new ilSelectInputGUI(
103 $this->language->txt('obj_additional_langs'),
104 'languages'
105 );
106 $languages->setOptions($language_options);
107 $languages->setMulti(true);
108 $languages->setRequired(true);
109 $form->addItem($languages);
110
111 $form->addCommandButton(
112 self::CMD_SAVE_ADDITIONAL_TRANSLATIONS,
113 $this->language->txt('save')
114 );
115 $form->addCommandButton(
116 self::CMD_DEFAULT,
117 $this->language->txt('cancel')
118 );
119 return $form;
120 }
121
126 protected function getAvailableLanguagesOptions(): array
127 {
128 $languages = ilAdvancedMDRecordTranslations::getInstanceByRecordId($this->record->getRecordId());
129
130 $this->language->loadLanguageModule('meta');
131 $installed_languages = ilLanguage::_getInstalledLanguages();
132 $options = [];
133 $options[''] = $this->language->txt('select_one');
134 foreach ($installed_languages as $key => $language) {
135 if ($languages->isConfigured($language)) {
136 continue;
137 }
138 $options[$language] = $this->language->txt('meta_l_' . $language);
139 }
140 return $options;
141 }
142
143 protected function saveAdditionalTranslations(): void
144 {
145 $form = $this->initCreateTranslationForm();
146 if (!$form->checkInput()) {
147 $form->setValuesByPost();
148 $this->tpl->setOnScreenMessage('failure', $this->language->txt('err_check_input'));
149 $this->addTranslations($form);
150 return;
151 }
152 foreach (array_unique((array) $form->getInput('languages')) as $language_code) {
153 $languages = ilAdvancedMDRecordTranslations::getInstanceByRecordId($this->record->getRecordId());
154 $languages->addTranslationEntry($language_code);
155 }
156
157 $this->tpl->setOnScreenMessage('success', $this->language->txt('settings_saved'), true);
158 $this->ctrl->redirect($this, self::CMD_DEFAULT);
159 }
160}
executeCommand()
Execute command and save parameter record id.
addTranslations(?ilPropertyFormGUI $form=null)
show translation creation form
Class ilCtrl provides processing control methods.
language handling
static _getInstalledLanguages()
Get installed languages.
Component logger with individual log levels by component id.
This class represents a property form user interface.
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26