ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilMultilingualismGUI Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilMultilingualismGUI:

Public Member Functions

 __construct (int $a_obj_id, string $a_type)
 
 setTitleDescrOnlyMode (bool $a_val)
 Set enable title/description only mode. More...
 
 getTitleDescrOnlyMode ()
 Get enable title/description only mode. More...
 
 executeCommand ()
 
 listTranslations (bool $a_get_post_values=false, bool $a_add=false)
 
 addToolbar ()
 
 saveTranslations (bool $delete_checked=false)
 
 deleteTranslations ()
 
 getMultiLangForm (bool $a_add=false)
 Get multi language form. More...
 
 confirmDeactivateContentMultiLang ()
 Confirm page translation creation. More...
 
 addLanguages (?ilPropertyFormGUI $form=null)
 Add language. More...
 
 saveLanguages ()
 
 confirmRemoveLanguages ()
 Confirm remove languages. More...
 
 removeLanguages ()
 Remove languages. More...
 
 setStartValues (string $a_title, string $a_description)
 

Protected Attributes

ILIAS DidacticTemplate Multilingualism StandardGUIRequest $request
 
ilLanguage $lng
 
ilCtrl $ctrl
 
ilGlobalTemplateInterface $tpl
 
ilToolbarGUI $toolbar
 
ilObjUser $user
 
LOMServices $lom_services
 
ilMultilingualism $obj_trans
 
bool $title_descr_only = true
 
string $start_title = ""
 
string $start_description = ""
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning GUI class for object translation handling.

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de @ilCtrl_IsCalledBy ilMultilingualismeGUI: ilDidacticTemplateSettingsGUI

Definition at line 26 of file class.ilMultilingualismGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilMultilingualismGUI::__construct ( int  $a_obj_id,
string  $a_type 
)

Definition at line 40 of file class.ilMultilingualismGUI.php.

43 {
44 global $DIC;
45
46 $this->toolbar = $DIC->toolbar();
47 $this->user = $DIC->user();
48 $this->lng = $DIC->language();
49 $this->lng->loadLanguageModule('obj');
50 $this->ctrl = $DIC->ctrl();
51 $this->tpl = $DIC->ui()->mainTemplate();
52 $this->lom_services = $DIC->learningObjectMetadata();
53
54 $this->obj_trans = ilMultilingualism::getInstance($a_obj_id, $a_type);
55 $this->request = new \ILIAS\Multilingualism\StandardGUIRequest(
56 $DIC->http(),
57 $DIC->refinery()
58 );
59 }
static getInstance(int $a_obj_id, string $a_type)
global $DIC
Definition: shib_login.php:26

References $DIC, ILIAS\Repository\ctrl(), ilMultilingualism\getInstance(), ILIAS\Repository\lng(), ILIAS\Repository\toolbar(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

Member Function Documentation

◆ addLanguages()

ilMultilingualismGUI::addLanguages ( ?ilPropertyFormGUI  $form = null)

Add language.

Definition at line 304 of file class.ilMultilingualismGUI.php.

304 : void
305 {
307
308 if (!$form instanceof ilPropertyFormGUI) {
309 $form = $this->getMultiLangForm(true);
310 }
311 $tpl->setContent($form->getHTML());
312 }
getMultiLangForm(bool $a_add=false)
Get multi language form.
ilGlobalTemplateInterface $tpl
This class represents a property form user interface.
setContent(string $a_html)
Sets content for standard template.

References ILIAS\UICore\GlobalTemplate\setContent().

+ Here is the call graph for this function:

◆ addToolbar()

ilMultilingualismGUI::addToolbar ( )

Definition at line 139 of file class.ilMultilingualismGUI.php.

139 : void
140 {
141 $ilToolbar = $this->toolbar;
142 if ($this->getTitleDescrOnlyMode()) {
143 $ilToolbar->addButton(
144 $this->lng->txt("obj_add_languages"),
145 $this->ctrl->getLinkTarget($this, "addLanguages")
146 );
147 }
148 }
getTitleDescrOnlyMode()
Get enable title/description only mode.
addButton(string $a_txt, string $a_cmd, string $a_target="", ?int $a_acc_key=null, string $a_additional_attrs='', string $a_id="", string $a_class='submit')

References ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ confirmDeactivateContentMultiLang()

ilMultilingualismGUI::confirmDeactivateContentMultiLang ( )

Confirm page translation creation.

Definition at line 282 of file class.ilMultilingualismGUI.php.

282 : void
283 {
284 $ilCtrl = $this->ctrl;
287
288 $cgui = new ilConfirmationGUI();
289 $cgui->setFormAction($ilCtrl->getFormAction($this));
290 if ($this->getTitleDescrOnlyMode()) {
291 $cgui->setHeaderText($lng->txt("obj_deactivate_content_transl_conf"));
292 } else {
293 $cgui->setHeaderText($lng->txt("obj_deactivate_multilang_conf"));
294 }
295
296 $cgui->setCancel($lng->txt("cancel"), "listTranslations");
297 $cgui->setConfirm($lng->txt("confirm"), "deactivateContentMultiLang");
298 $tpl->setContent($cgui->getHTML());
299 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...

References $lng, and ILIAS\UICore\GlobalTemplate\setContent().

+ Here is the call graph for this function:

◆ confirmRemoveLanguages()

ilMultilingualismGUI::confirmRemoveLanguages ( )

Confirm remove languages.

Definition at line 354 of file class.ilMultilingualismGUI.php.

354 : void
355 {
356 $ilCtrl = $this->ctrl;
359
360 $lng->loadLanguageModule("meta");
361 $langs = $this->request->getLanguages();
362
363 if (count($langs) === 0) {
364 $this->tpl->setOnScreenMessage('info', $lng->txt("no_checkbox"), true);
365 $ilCtrl->redirect($this, "listTranslations");
366 } else {
367 $cgui = new ilConfirmationGUI();
368 $cgui->setFormAction($ilCtrl->getFormAction($this));
369 $cgui->setHeaderText($lng->txt("obj_conf_delete_lang"));
370 $cgui->setCancel($lng->txt("cancel"), "listTranslations");
371 $cgui->setConfirm($lng->txt("remove"), "removeLanguages");
372
373 foreach ($langs as $i) {
374 $cgui->addItem("lang[]", $i, $lng->txt("meta_l_" . $i));
375 }
376
377 $tpl->setContent($cgui->getHTML());
378 }
379 }
loadLanguageModule(string $a_module)
Load language module.

References $lng, and ILIAS\UICore\GlobalTemplate\setContent().

+ Here is the call graph for this function:

◆ deleteTranslations()

ilMultilingualismGUI::deleteTranslations ( )

Definition at line 203 of file class.ilMultilingualismGUI.php.

203 : void
204 {
205 $default = $this->request->getDefault();
206 $langs = $this->request->getLanguages();
207 $titles = $this->request->getTitles();
208 $descs = $this->request->getDescriptions();
209 $check = $this->request->getCheck();
210 foreach ($titles as $k => $v) {
211 if ($check[$k] ?? false) {
212 // default translation cannot be deleted
213 if ($k != $default) {
214 unset($titles[$k], $descs[$k], $langs[$k]);
215 } else {
216 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("msg_no_default_language"));
217 $this->listTranslations();
218 return;
219 }
220 }
221 }
222 $this->saveTranslations(true);
223 }
$check
Definition: buildRTE.php:81
listTranslations(bool $a_get_post_values=false, bool $a_add=false)
saveTranslations(bool $delete_checked=false)

References $check, and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ executeCommand()

ilMultilingualismGUI::executeCommand ( )

Definition at line 77 of file class.ilMultilingualismGUI.php.

77 : void
78 {
79 $next_class = $this->ctrl->getNextClass($this);
80
81 switch ($next_class) {
82 default:
83 $cmd = $this->ctrl->getCmd("listTranslations");
84 if (in_array($cmd, array("listTranslations", "saveTranslations",
85 "addTranslation", "deleteTranslations", "activateContentMultilinguality",
86 "confirmRemoveLanguages", "removeLanguages", "confirmDeactivateContentMultiLang", "saveLanguages",
87 "saveContentTranslationActivation", "deactivateContentMultiLang", "addLanguages"))) {
88 $this->$cmd();
89 }
90 break;
91 }
92 }

References ILIAS\Repository\ctrl().

+ Here is the call graph for this function:

◆ getMultiLangForm()

ilMultilingualismGUI::getMultiLangForm ( bool  $a_add = false)

Get multi language form.

Definition at line 232 of file class.ilMultilingualismGUI.php.

233 {
235 $ilCtrl = $this->ctrl;
236 $ilUser = $this->user;
237
238 $form = new ilPropertyFormGUI();
239
240 $options = [];
241 foreach ($this->lom_services->dataHelper()->getAllLanguages() as $language) {
242 $options[$language->value()] = $language->presentableLabel();
243 }
244
245 // master language
246 if (!$a_add) {
247 $si = new ilSelectInputGUI($lng->txt("obj_base_lang"), "master_lang");
248 $si->setOptions($options);
249 $si->setValue($ilUser->getLanguage());
250 $form->addItem($si);
251 }
252
253 // additional languages
254 if ($a_add) {
255 $options = array("" => $lng->txt("please_select")) + $options;
256 $si = new ilSelectInputGUI($lng->txt("obj_additional_langs"), "additional_langs");
257 $si->setOptions($options);
258 $si->setMulti(true);
259 $form->addItem($si);
260 }
261
262 if ($a_add) {
263 $form->setTitle($lng->txt("obj_add_languages"));
264 $form->addCommandButton("saveLanguages", $lng->txt("save"));
265 } else {
266 if ($this->getTitleDescrOnlyMode()) {
267 $form->setTitle($lng->txt("obj_activate_content_lang"));
268 } else {
269 $form->setTitle($lng->txt("obj_activate_multilang"));
270 }
271 $form->addCommandButton("saveContentTranslationActivation", $lng->txt("save"));
272 }
273 $form->addCommandButton("listTranslations", $lng->txt("cancel"));
274 $form->setFormAction($ilCtrl->getFormAction($this));
275
276 return $form;
277 }
This class represents a selection list property in a property form.

References $lng.

◆ getTitleDescrOnlyMode()

ilMultilingualismGUI::getTitleDescrOnlyMode ( )

Get enable title/description only mode.

Definition at line 72 of file class.ilMultilingualismGUI.php.

72 : bool
73 {
75 }

References $title_descr_only.

◆ listTranslations()

ilMultilingualismGUI::listTranslations ( bool  $a_get_post_values = false,
bool  $a_add = false 
)

Definition at line 94 of file class.ilMultilingualismGUI.php.

97 : void {
98 $this->lng->loadLanguageModule("translation");
99
100
101 $this->addToolbar();
102
103 $titles = $this->request->getTitles();
104 $langs = $this->request->getLanguages();
105 $descs = $this->request->getDescriptions();
106 $default = $this->request->getDefault();
107
108 $table = new ilMultilingualismTableGUI(
109 $this,
110 "listTranslations",
111 true,
112 "Translation"
113 );
114 if ($a_get_post_values) {
115 $vals = array();
116 foreach ($titles as $k => $v) {
117 $vals[] = array("title" => $v,
118 "desc" => $descs[$k],
119 "lang" => $langs[$k],
120 "default" => ($default == $k));
121 }
122 $table->setData($vals);
123 } else {
124 $k = 0;
125 $data = $this->obj_trans->getLanguages();
126 foreach ($data as $k => $v) {
127 $data[$k]["default"] = $v["lang_default"];
128 $data[$k]["desc"] = $v["description"];
129 $data[$k]["lang"] = $v["lang_code"];
130 }
131 if ($a_add) {
132 $data["Fobject"][++$k]["title"] = "";
133 }
134 $table->setData($data);
135 }
136 $this->tpl->setContent($table->getHTML());
137 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ removeLanguages()

ilMultilingualismGUI::removeLanguages ( )

Remove languages.

Definition at line 384 of file class.ilMultilingualismGUI.php.

384 : void
385 {
387 $ilCtrl = $this->ctrl;
388
389 $post_langs = $this->request->getLanguages();
390
391 if (count($post_langs) > 0) {
392 $langs = $this->obj_trans->getLanguages();
393 foreach ($langs as $k => $l) {
394 if (in_array($l, $post_langs)) {
395 $this->obj_trans->removeLanguage($l);
396 }
397 }
398 $this->obj_trans->save();
399 $this->tpl->setOnScreenMessage('info', $lng->txt("msg_obj_modified"), true);
400 }
401 $ilCtrl->redirect($this, "listTranslations");
402 }
redirect(object $a_gui_obj, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false)
@inheritDoc

References $lng.

◆ saveLanguages()

ilMultilingualismGUI::saveLanguages ( )

Definition at line 314 of file class.ilMultilingualismGUI.php.

314 : void
315 {
316 $ilCtrl = $this->ctrl;
318
319 ilLoggerFactory::getLogger('otpl')->debug('Save languages');
320
321 $form = $this->getMultiLangForm(true);
322 if ($form->checkInput()) {
323 $ad = $form->getInput("additional_langs");
324
325 ilLoggerFactory::getLogger('otpl')->dump($ad);
326
327 if (is_array($ad)) {
328 foreach ($ad as $l) {
329 if ($l != "") {
330 $std = false;
331
332 //if no other language is set, set this one as standard
333 if (!count($this->obj_trans->getLanguages())) {
334 $std = true;
335 }
336
337 $this->obj_trans->addLanguage($l, $this->start_title, $this->start_description, $std);
338 }
339 }
340 }
341 $this->obj_trans->save();
342 $this->tpl->setOnScreenMessage('info', $lng->txt("msg_obj_modified"), true);
343 $ilCtrl->redirect($this, "listTranslations");
344 } else {
345 $form->setValuesByPost();
346 $this->tpl->setOnScreenMessage('failure', $lng->txt('err_check_input'));
347 $this->addLanguages($form);
348 }
349 }
static getLogger(string $a_component_id)
Get component logger.
addLanguages(?ilPropertyFormGUI $form=null)
Add language.

References $lng, and ilLoggerFactory\getLogger().

+ Here is the call graph for this function:

◆ saveTranslations()

ilMultilingualismGUI::saveTranslations ( bool  $delete_checked = false)

Definition at line 150 of file class.ilMultilingualismGUI.php.

150 : void
151 {
152 $default = $this->request->getDefault();
153 $langs = $this->request->getLanguages();
154 $titles = $this->request->getTitles();
155 $descs = $this->request->getDescriptions();
156
157 // default language set?
158 if ($default === "") {
159 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("msg_no_default_language"));
160 $this->listTranslations(true);
161 return;
162 }
163
164 // all languages set?
165 if (array_key_exists("", $langs)) {
166 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("msg_no_language_selected"));
167 $this->listTranslations(true);
168 return;
169 }
170
171 // no single language is selected more than once?
172 if (count(array_unique($langs)) < count($langs)) {
173 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("msg_multi_language_selected"));
174 $this->listTranslations(true);
175 return;
176 }
177
178 $check = $this->request->getCheck();
179
180 // save the stuff
181 $this->obj_trans->setLanguages(array());
182
183 foreach ($titles as $k => $v) {
184 // update object data if default
185 $is_default = ($default == $k);
186 if ($delete_checked && !$is_default && isset($check[$k])) {
187 continue;
188 }
189
190 $this->obj_trans->addLanguage(
191 $langs[$k],
192 $v,
193 $descs[$k],
194 $is_default
195 );
196 }
197 $this->obj_trans->save();
198
199 $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
200 $this->ctrl->redirect($this, "listTranslations");
201 }

References $check, ILIAS\Repository\ctrl(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ setStartValues()

ilMultilingualismGUI::setStartValues ( string  $a_title,
string  $a_description 
)

Definition at line 404 of file class.ilMultilingualismGUI.php.

407 : void {
408 $this->start_title = $a_title;
409 $this->start_description = $a_description;
410 }

◆ setTitleDescrOnlyMode()

ilMultilingualismGUI::setTitleDescrOnlyMode ( bool  $a_val)

Set enable title/description only mode.

Definition at line 64 of file class.ilMultilingualismGUI.php.

64 : void
65 {
66 $this->title_descr_only = $a_val;
67 }

Field Documentation

◆ $ctrl

ilCtrl ilMultilingualismGUI::$ctrl
protected

Definition at line 30 of file class.ilMultilingualismGUI.php.

◆ $lng

ilLanguage ilMultilingualismGUI::$lng
protected

Definition at line 29 of file class.ilMultilingualismGUI.php.

◆ $lom_services

LOMServices ilMultilingualismGUI::$lom_services
protected

Definition at line 34 of file class.ilMultilingualismGUI.php.

◆ $obj_trans

ilMultilingualism ilMultilingualismGUI::$obj_trans
protected

Definition at line 35 of file class.ilMultilingualismGUI.php.

◆ $request

ILIAS DidacticTemplate Multilingualism StandardGUIRequest ilMultilingualismGUI::$request
protected

Definition at line 28 of file class.ilMultilingualismGUI.php.

◆ $start_description

string ilMultilingualismGUI::$start_description = ""
protected

Definition at line 38 of file class.ilMultilingualismGUI.php.

◆ $start_title

string ilMultilingualismGUI::$start_title = ""
protected

Definition at line 37 of file class.ilMultilingualismGUI.php.

◆ $title_descr_only

bool ilMultilingualismGUI::$title_descr_only = true
protected

Definition at line 36 of file class.ilMultilingualismGUI.php.

Referenced by getTitleDescrOnlyMode().

◆ $toolbar

ilToolbarGUI ilMultilingualismGUI::$toolbar
protected

Definition at line 32 of file class.ilMultilingualismGUI.php.

◆ $tpl

ilGlobalTemplateInterface ilMultilingualismGUI::$tpl
protected

Definition at line 31 of file class.ilMultilingualismGUI.php.

◆ $user

ilObjUser ilMultilingualismGUI::$user
protected

Definition at line 33 of file class.ilMultilingualismGUI.php.


The documentation for this class was generated from the following file: