ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilTranslationGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
14{
15
19 protected $ctrl;
23 public $tpl;
27 protected $ilAccess;
31 protected $lng;
40
41
42 public function __construct(ilObjOrgUnitGUI $ilObjOrgUnitGUI)
43 {
44 global $DIC;
45 $tpl = $DIC['tpl'];
46 $ilCtrl = $DIC['ilCtrl'];
47 $ilDB = $DIC['ilDB'];
48 $lng = $DIC['lng'];
49 $ilAccess = $DIC['ilAccess'];
55 $this->tpl = $tpl;
56 $this->ctrl = $ilCtrl;
57 $this->lng = $lng;
58 $this->ilObjOrgUnitGui = $ilObjOrgUnitGUI;
59 $this->ilObjectOrgUnit = $ilObjOrgUnitGUI->object;
60 $this->ilAccess = $ilAccess;
61
62 if (!$ilAccess->checkAccess('write', '', $this->ilObjectOrgUnit->getRefId())) {
63 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
64 $this->ctrl->redirect($this->parent_gui, "");
65 }
66 }
67
68
69 public function executeCommand()
70 {
71 $cmd = $this->ctrl->getCmd();
72 $this->$cmd();
73 }
74
75
76 public function editTranslations($a_get_post_values = false, $a_add = false)
77 {
78 $this->lng->loadLanguageModule($this->ilObjectOrgUnit->getType());
79
80 $table = new ilObjectTranslationTableGUI(
81 $this,
82 "editTranslations",
83 true,
84 "Translation"
85 );
86 if ($a_get_post_values) {
87 $vals = array();
88 foreach ($_POST["title"] as $k => $v) {
89 $vals[] = array(
90 "title" => $v,
91 "desc" => $_POST["desc"][$k],
92 "lang" => $_POST["lang"][$k],
93 "default" => ($_POST["default"] == $k),
94 );
95 }
96 $table->setData($vals);
97 } else {
98 $data = $this->ilObjectOrgUnit->getTranslations();
99 if ($a_add) {
100 $data[]["title"] = "";
101 }
102 $table->setData($data);
103 }
104 $this->tpl->setContent($table->getHTML());
105 }
106
107
111 public function saveTranslations()
112 {
113 // default language set?
114 if (!isset($_POST["default"])) {
115 ilUtil::sendFailure($this->lng->txt("msg_no_default_language"));
116
117 return $this->editTranslations(true);
118 }
119
120 // all languages set?
121 if (array_key_exists("", $_POST["lang"])) {
122 ilUtil::sendFailure($this->lng->txt("msg_no_language_selected"));
123
124 return $this->editTranslations(true);
125 }
126
127 // no single language is selected more than once?
128 if (count(array_unique($_POST["lang"])) < count($_POST["lang"])) {
129 ilUtil::sendFailure($this->lng->txt("msg_multi_language_selected"));
130
131 return $this->editTranslations(true);
132 }
133
134 // save the stuff
135 $this->ilObjectOrgUnit->removeTranslations();
136 foreach ($_POST["title"] as $k => $v) {
137
138
139 $translations = $this->ilObjectOrgUnit->getTranslations();
140
141 if(array_key_exists($_POST["lang"][$k], $translations)) {
142 $this->ilObjectOrgUnit->updateTranslation(
144 ilUtil::stripSlashes($_POST["desc"][$k]),
145 ilUtil::stripSlashes($_POST["lang"][$k]),
146 ($_POST["default"]==$k)?1:0
147 );
148 } else {
149 $this->ilObjectOrgUnit->addTranslation(
151 ilUtil::stripSlashes($_POST["desc"][$k]),
152 ilUtil::stripSlashes($_POST["lang"][$k]),
153 ($_POST["default"]==$k)?1:0
154 );
155 }
156 }
157
158 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
159 $this->ctrl->redirect($this, "editTranslations");
160 }
161
162
166 public function addTranslation()
167 {
168 if ($_POST["title"]) {
169 $k = max(array_keys($_POST["title"]));
170 $k++;
171 $_POST["title"][$k] = "";
172 $this->editTranslations(true);
173 } else {
174 $this->editTranslations(false, true);
175 }
176 }
177
178
182 public function deleteTranslations()
183 {
184 foreach ($_POST["title"] as $k => $v) {
185 if ($_POST["check"][$k]) {
186 // default translation cannot be deleted
187 if ($k != $_POST["default"]) {
188 unset($_POST["title"][$k]);
189 unset($_POST["desc"][$k]);
190 unset($_POST["lang"][$k]);
191 } else {
192 ilUtil::sendFailure($this->lng->txt("msg_no_default_language"));
193
194 return $this->editTranslations();
195 }
196 }
197 }
198 $this->saveTranslations();
199 }
200}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Class ilAccessHandler.
Class ilObjOrgUnit GUI class.
TableGUI class for title/description translations.
Class ilTranslationGUI.
editTranslations($a_get_post_values=false, $a_add=false)
addTranslation()
Add a translation.
deleteTranslations()
Remove translation.
saveTranslations()
Save title and translations.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $ilDB
$data
Definition: storeScorm.php:23