ILIAS  release_8 Revision v8.24
class.ilTranslationGUI.php
Go to the documentation of this file.
1<?php
18/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
19
27{
28 protected ilCtrl $ctrl;
31 protected ilLanguage $lng;
32 protected object $parent_gui;
33 protected object $object;
34
35 public function __construct(object $ilObjOrgUnitGUI)
36 {
37 global $DIC;
38 $main_tpl = $DIC->ui()->mainTemplate();
39
40 $ilAccess = $DIC['ilAccess'];
41 $this->tpl = $DIC->ui()->mainTemplate();
42 $this->ctrl = $DIC->ctrl();
43 $this->lng = $DIC->language();
44 $this->parent_gui = $ilObjOrgUnitGUI;
45 $this->object = $ilObjOrgUnitGUI->getObject();
46 $this->ilAccess = $ilAccess;
47
48 if (!$ilAccess->checkAccess('write', '', $this->object->getRefId())) {
49 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("permission_denied"), true);
50 $this->ctrl->redirect($this->parent_gui, "");
51 }
52 }
53
54 public function executeCommand(): void
55 {
56 $cmd = $this->ctrl->getCmd();
57 $this->$cmd();
58 }
59
60 public function editTranslations(bool $a_get_post_values = false, bool $a_add = false): void
61 {
62 $this->lng->loadLanguageModule($this->object->getType());
63
64 $table = new ilObjectTranslationTableGUI(
65 $this,
66 "editTranslations",
67 true,
68 "Translation"
69 );
70 if ($a_get_post_values) {
71 $vals = array();
72 foreach ($_POST["title"] as $k => $v) {
73 $vals[] = array(
74 "title" => $v,
75 "desc" => $_POST["desc"][$k],
76 "lang" => $_POST["lang"][$k],
77 "default" => ($_POST["default"] == $k),
78 );
79 }
80 $table->setData($vals);
81 } else {
82 $data = $this->object->getTranslations();
83 if ($a_add) {
84 $data[]["title"] = "";
85 }
86 $table->setData($data);
87 }
88 $this->tpl->setContent($table->getHTML());
89 }
90
94 public function saveTranslations(): void
95 {
96 // default language set?
97 if (!isset($_POST["default"])) {
98 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("msg_no_default_language"));
99 $this->editTranslations(true);
100 }
101
102 // all languages set?
103 if (array_key_exists("", $_POST["lang"])) {
104 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("msg_no_language_selected"));
105 $this->editTranslations(true);
106 }
107
108 // no single language is selected more than once?
109 if (count(array_unique($_POST["lang"])) < count($_POST["lang"])) {
110 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("msg_multi_language_selected"));
111
112 $this->editTranslations(true);
113 }
114
115 // save the stuff
116 $this->object->removeTranslations();
117 foreach ($_POST["title"] as $k => $v) {
118 $translations = $this->object->getTranslations();
119
120 if (array_key_exists($_POST["lang"][$k], $translations)) {
121 $this->object->updateTranslation(
123 ilUtil::stripSlashes($_POST["desc"][$k]),
124 ilUtil::stripSlashes($_POST["lang"][$k]),
125 ($_POST["default"] == $k) ? 1 : 0
126 );
127 } else {
128 $this->object->addTranslation(
130 ilUtil::stripSlashes($_POST["desc"][$k]),
131 ilUtil::stripSlashes($_POST["lang"][$k]),
132 ($_POST["default"] == $k) ? 1 : 0
133 );
134 }
135 }
136
137 $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
138 $this->ctrl->redirect($this, "editTranslations");
139 }
140
144 public function addTranslation(): void
145 {
146 if ($_POST["title"]) {
147 $k = max(array_keys($_POST["title"]));
148 $k++;
149 $_POST["title"][$k] = "";
150 $this->editTranslations(true);
151 } else {
152 $this->editTranslations(false, true);
153 }
154 }
155
159 public function deleteTranslations(): void
160 {
161 foreach ($_POST["title"] as $k => $v) {
162 if ($_POST["check"][$k]) {
163 // default translation cannot be deleted
164 if ($k != $_POST["default"]) {
165 unset($_POST["title"][$k]);
166 unset($_POST["desc"][$k]);
167 unset($_POST["lang"][$k]);
168 } else {
169 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("msg_no_default_language"));
170
171 $this->editTranslations();
172 }
173 }
174 }
175 $this->saveTranslations();
176 }
177}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
language handling
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...
ilGlobalTemplateInterface $tpl
addTranslation()
Add a translation.
ilAccessHandler $ilAccess
editTranslations(bool $a_get_post_values=false, bool $a_add=false)
deleteTranslations()
Remove translation.
saveTranslations()
Save title and translations.
__construct(object $ilObjOrgUnitGUI)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
global $DIC
Definition: feed.php:28
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...
checkAccess(string $a_permission, string $a_cmd, int $a_ref_id, string $a_type="", ?int $a_obj_id=null, ?int $a_tree_id=null)
check access for an object (provide $a_type and $a_obj_id if available for better performance)