ILIAS  release_8 Revision v8.24
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 Multilingualism StandardGUIRequest $request
 
ilLanguage $lng
 
ilCtrl $ctrl
 
ilGlobalTemplateInterface $tpl
 
ilToolbarGUI $toolbar
 
ilObjUser $user
 
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 24 of file class.ilMultilingualismGUI.php.

Constructor & Destructor Documentation

◆ __construct()

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

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

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

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 297 of file class.ilMultilingualismGUI.php.

297 : void
298 {
300
301 if (!$form instanceof ilPropertyFormGUI) {
302 $form = $this->getMultiLangForm(true);
303 }
304 $tpl->setContent($form->getHTML());
305 }
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 $tpl.

◆ addToolbar()

ilMultilingualismGUI::addToolbar ( )

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

135 : void
136 {
137 $ilToolbar = $this->toolbar;
138 if ($this->getTitleDescrOnlyMode()) {
139 $ilToolbar->addButton(
140 $this->lng->txt("obj_add_languages"),
141 $this->ctrl->getLinkTarget($this, "addLanguages")
142 );
143 }
144 }
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 275 of file class.ilMultilingualismGUI.php.

275 : void
276 {
277 $ilCtrl = $this->ctrl;
280
281 $cgui = new ilConfirmationGUI();
282 $cgui->setFormAction($ilCtrl->getFormAction($this));
283 if ($this->getTitleDescrOnlyMode()) {
284 $cgui->setHeaderText($lng->txt("obj_deactivate_content_transl_conf"));
285 } else {
286 $cgui->setHeaderText($lng->txt("obj_deactivate_multilang_conf"));
287 }
288
289 $cgui->setCancel($lng->txt("cancel"), "listTranslations");
290 $cgui->setConfirm($lng->txt("confirm"), "deactivateContentMultiLang");
291 $tpl->setContent($cgui->getHTML());
292 }
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 $tpl.

◆ confirmRemoveLanguages()

ilMultilingualismGUI::confirmRemoveLanguages ( )

Confirm remove languages.

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

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

References $i, $lng, and $tpl.

◆ deleteTranslations()

ilMultilingualismGUI::deleteTranslations ( )

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

199 : void
200 {
201 $default = $this->request->getDefault();
202 $langs = $this->request->getLanguages();
203 $titles = $this->request->getTitles();
204 $descs = $this->request->getDescriptions();
205 $check = $this->request->getCheck();
206 foreach ($titles as $k => $v) {
207 if ($check[$k] ?? false) {
208 // default translation cannot be deleted
209 if ($k != $default) {
210 unset($titles[$k], $descs[$k], $langs[$k]);
211 } else {
212 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("msg_no_default_language"));
213 $this->listTranslations();
214 return;
215 }
216 }
217 }
218 $this->saveTranslations(true);
219 }
$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 73 of file class.ilMultilingualismGUI.php.

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

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 228 of file class.ilMultilingualismGUI.php.

229 {
231 $ilCtrl = $this->ctrl;
233
234 $form = new ilPropertyFormGUI();
235
236 // master language
237 if (!$a_add) {
239 $si = new ilSelectInputGUI($lng->txt("obj_master_lang"), "master_lang");
240 $si->setOptions($options);
241 $si->setValue($ilUser->getLanguage());
242 $form->addItem($si);
243 }
244
245 // additional languages
246 if ($a_add) {
248 $options = array("" => $lng->txt("please_select")) + $options;
249 $si = new ilSelectInputGUI($lng->txt("obj_additional_langs"), "additional_langs");
250 $si->setOptions($options);
251 $si->setMulti(true);
252 $form->addItem($si);
253 }
254
255 if ($a_add) {
256 $form->setTitle($lng->txt("obj_add_languages"));
257 $form->addCommandButton("saveLanguages", $lng->txt("save"));
258 } else {
259 if ($this->getTitleDescrOnlyMode()) {
260 $form->setTitle($lng->txt("obj_activate_content_lang"));
261 } else {
262 $form->setTitle($lng->txt("obj_activate_multilang"));
263 }
264 $form->addCommandButton("saveContentTranslationActivation", $lng->txt("save"));
265 }
266 $form->addCommandButton("listTranslations", $lng->txt("cancel"));
267 $form->setFormAction($ilCtrl->getFormAction($this));
268
269 return $form;
270 }
This class represents a selection list property in a property form.
$ilUser
Definition: imgupload.php:34

References $ilUser, $lng, and ilMDLanguageItem\_getLanguages().

+ Here is the call graph for this function:

◆ getTitleDescrOnlyMode()

ilMultilingualismGUI::getTitleDescrOnlyMode ( )

Get enable title/description only mode.

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

68 : bool
69 {
71 }

References $title_descr_only.

◆ listTranslations()

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

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

93 : void {
94 $this->lng->loadLanguageModule("translation");
95
96
97 $this->addToolbar();
98
99 $titles = $this->request->getTitles();
100 $langs = $this->request->getLanguages();
101 $descs = $this->request->getDescriptions();
102 $default = $this->request->getDefault();
103
104 $table = new ilMultilingualismTableGUI(
105 $this,
106 "listTranslations",
107 true,
108 "Translation"
109 );
110 if ($a_get_post_values) {
111 $vals = array();
112 foreach ($titles as $k => $v) {
113 $vals[] = array("title" => $v,
114 "desc" => $descs[$k],
115 "lang" => $langs[$k],
116 "default" => ($default == $k));
117 }
118 $table->setData($vals);
119 } else {
120 $k = 0;
121 $data = $this->obj_trans->getLanguages();
122 foreach ($data as $k => $v) {
123 $data[$k]["default"] = $v["lang_default"];
124 $data[$k]["desc"] = $v["description"];
125 $data[$k]["lang"] = $v["lang_code"];
126 }
127 if ($a_add) {
128 $data["Fobject"][++$k]["title"] = "";
129 }
130 $table->setData($data);
131 }
132 $this->tpl->setContent($table->getHTML());
133 }
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 377 of file class.ilMultilingualismGUI.php.

377 : void
378 {
380 $ilCtrl = $this->ctrl;
381
382 $post_langs = $this->request->getLanguages();
383
384 if (count($post_langs) > 0) {
385 $langs = $this->obj_trans->getLanguages();
386 foreach ($langs as $k => $l) {
387 if (in_array($l, $post_langs)) {
388 $this->obj_trans->removeLanguage($l);
389 }
390 }
391 $this->obj_trans->save();
392 $this->tpl->setOnScreenMessage('info', $lng->txt("msg_obj_modified"), true);
393 }
394 $ilCtrl->redirect($this, "listTranslations");
395 }
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 307 of file class.ilMultilingualismGUI.php.

307 : void
308 {
309 $ilCtrl = $this->ctrl;
311
312 ilLoggerFactory::getLogger('otpl')->debug('Save languages');
313
314 $form = $this->getMultiLangForm(true);
315 if ($form->checkInput()) {
316 $ad = $form->getInput("additional_langs");
317
318 ilLoggerFactory::getLogger('otpl')->dump($ad);
319
320 if (is_array($ad)) {
321 foreach ($ad as $l) {
322 if ($l != "") {
323 $std = false;
324
325 //if no other language is set, set this one as standard
326 if (!count($this->obj_trans->getLanguages())) {
327 $std = true;
328 }
329
330 $this->obj_trans->addLanguage($l, $this->start_title, $this->start_description, $std);
331 }
332 }
333 }
334 $this->obj_trans->save();
335 $this->tpl->setOnScreenMessage('info', $lng->txt("msg_obj_modified"), true);
336 $ilCtrl->redirect($this, "listTranslations");
337 } else {
338 $form->setValuesByPost();
339 $this->tpl->setOnScreenMessage('failure', $lng->txt('err_check_input'));
340 $this->addLanguages($form);
341 }
342 }
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 146 of file class.ilMultilingualismGUI.php.

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

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 397 of file class.ilMultilingualismGUI.php.

400 : void {
401 $this->start_title = $a_title;
402 $this->start_description = $a_description;
403 }

◆ setTitleDescrOnlyMode()

ilMultilingualismGUI::setTitleDescrOnlyMode ( bool  $a_val)

Set enable title/description only mode.

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

60 : void
61 {
62 $this->title_descr_only = $a_val;
63 }

Field Documentation

◆ $ctrl

ilCtrl ilMultilingualismGUI::$ctrl
protected

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

◆ $lng

ilLanguage ilMultilingualismGUI::$lng
protected

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

◆ $obj_trans

ilMultilingualism ilMultilingualismGUI::$obj_trans
protected

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

◆ $request

ILIAS Multilingualism StandardGUIRequest ilMultilingualismGUI::$request
protected

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

◆ $start_description

string ilMultilingualismGUI::$start_description = ""
protected

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

◆ $start_title

string ilMultilingualismGUI::$start_title = ""
protected

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

◆ $title_descr_only

bool ilMultilingualismGUI::$title_descr_only = true
protected

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

Referenced by getTitleDescrOnlyMode().

◆ $toolbar

ilToolbarGUI ilMultilingualismGUI::$toolbar
protected

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

◆ $tpl

ilGlobalTemplateInterface ilMultilingualismGUI::$tpl
protected

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

◆ $user

ilObjUser ilMultilingualismGUI::$user
protected

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


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