ILIAS  release_8 Revision v8.24
class.ilAdvancedMDTranslationGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
5use Psr\Http\Message\RequestInterface;
6
8{
9 protected const CMD_DEFAULT = 'translations';
10 protected const CMD_ADD_TRANSLATION = 'addTranslations';
11 protected const CMD_SAVE_ADDITIONAL_TRANSLATIONS = 'saveAdditionalTranslations';
12
13 protected ilCtrl $ctrl;
16 protected ilTabsGUI $tabs;
18 protected RequestInterface $request;
19 protected ilLogger $logger;
21
23 {
24 global $DIC;
25
26 $this->ctrl = $DIC->ctrl();
27 $this->tpl = $DIC->ui()->mainTemplate();
28 $this->toolbar = $DIC->toolbar();
29 $this->tabs = $DIC->tabs();
30 $this->language = $DIC->language();
31 $this->language->loadLanguageModule('obj');
32 $this->request = $DIC->http()->request();
34 $this->logger = $DIC->logger()->amet();
35 $this->record = $record;
36 }
37
41 public function executeCommand()
42 {
43 $this->ctrl->setParameterByClass(
44 strtolower(get_class($this)),
45 'record_id',
46 $this->record->getRecordId()
47 );
48
49 $next_class = $this->ctrl->getNextClass($this);
50 $cmd = $this->ctrl->getCmd(self::CMD_DEFAULT);
51 switch ($next_class) {
52 default:
53 $this->$cmd();
54 }
55 }
56
57 protected function setTabs(string $active_tab)
58 {
59 $this->tabs->activateTab($active_tab);
60 }
61
65 abstract protected function translations(): void;
66
70 protected function addTranslations(ilPropertyFormGUI $form = null)
71 {
72 $this->tabs->activateTab(self::CMD_DEFAULT);
73 if (!$form instanceof ilPropertyFormGUI) {
74 $form = $this->initCreateTranslationForm();
75 }
76 $this->tpl->setContent($form->getHTML());
77 }
78
80 {
81 $form = new \ilPropertyFormGUI();
82 $form->setFormAction($this->ctrl->getFormAction($this));
83 $form->setTitle($this->language->txt('obj_add_languages'));
84
85 $language_options = $this->getAvailableLanguagesOptions();
86 $languages = new ilSelectInputGUI(
87 $this->language->txt('obj_additional_langs'),
88 'languages'
89 );
90 $languages->setOptions($language_options);
91 $languages->setMulti(true);
92 $languages->setRequired(true);
93 $form->addItem($languages);
94
95 $form->addCommandButton(
96 self::CMD_SAVE_ADDITIONAL_TRANSLATIONS,
97 $this->language->txt('save')
98 );
99 $form->addCommandButton(
100 self::CMD_DEFAULT,
101 $this->language->txt('cancel')
102 );
103 return $form;
104 }
105
106 protected function addToolbarLanguageCreation(): void
107 {
108 $button = ilLinkButton::getInstance();
109 $button->setCaption('obj_add_languages');
110 $button->setUrl(
111 $this->ctrl->getLinkTargetByClass(
112 strtolower(get_class($this)),
113 self::CMD_ADD_TRANSLATION
114 )
115 );
116 $this->toolbar->addButtonInstance($button);
117 }
118
123 protected function getAvailableLanguagesOptions(): array
124 {
125 $languages = ilAdvancedMDRecordTranslations::getInstanceByRecordId($this->record->getRecordId());
126
127 $this->language->loadLanguageModule('meta');
128 $installed_languages = ilLanguage::_getInstalledLanguages();
129 $options = [];
130 $options[''] = $this->language->txt('select_one');
131 foreach ($installed_languages as $key => $language) {
132 if ($languages->isConfigured($language)) {
133 continue;
134 }
135 $options[$language] = $this->language->txt('meta_l_' . $language);
136 }
137 return $options;
138 }
139
140 protected function saveAdditionalTranslations(): void
141 {
142 $form = $this->initCreateTranslationForm();
143 if (!$form->checkInput()) {
144 $form->setValuesByPost();
145 $this->tpl->setOnScreenMessage('failure', $this->language->txt('err_check_input'));
146 $this->addTranslations($form);
147 return;
148 }
149 foreach (array_unique((array) $form->getInput('languages')) as $language_code) {
150 $languages = ilAdvancedMDRecordTranslations::getInstanceByRecordId($this->record->getRecordId());
151 $languages->addTranslationEntry($language_code);
152 }
153
154 $this->tpl->setOnScreenMessage('success', $this->language->txt('settings_saved'), true);
155 $this->ctrl->redirect($this, self::CMD_DEFAULT);
156 }
157}
addTranslations(ilPropertyFormGUI $form=null)
show translation creation form
executeCommand()
Execute command and save parameter record id.
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: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
string $key
Consumer key/client ID value.
Definition: System.php:193