ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilObjectTranslationGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2014 ILIAS open source, Extended GPL, see docs/LICENSE */
4
13{
17 protected $lng;
18
22 protected $ctrl;
23
27 protected $tpl;
28
32 protected $toolbar;
33
37 protected $user;
38
39 protected $obj_trans;
40 protected $title_descr_only = true;
41
45 public function __construct($a_obj_gui)
46 {
47 global $DIC;
48
49 $this->toolbar = $DIC->toolbar();
50 $this->user = $DIC->user();
51 $lng = $DIC->language();
52 $ilCtrl = $DIC->ctrl();
53 $tpl = $DIC["tpl"];
54
55 $this->lng = $lng;
56 $this->ctrl = $ilCtrl;
57 $this->tpl = $tpl;
58 $this->obj_gui = $a_obj_gui;
59 $this->obj = $a_obj_gui->object;
60
61 include_once("./Services/Object/classes/class.ilObjectTranslation.php");
62 $this->obj_trans = ilObjectTranslation::getInstance($this->obj->getId());
63 }
64
70 public function setTitleDescrOnlyMode($a_val)
71 {
72 $this->title_descr_only = $a_val;
73 }
74
80 public function getTitleDescrOnlyMode()
81 {
83 }
84
88 public function executeCommand()
89 {
90 $next_class = $this->ctrl->getNextClass($this);
91
92 switch ($next_class) {
93 default:
94 $cmd = $this->ctrl->getCmd("listTranslations");
95 if (in_array($cmd, array("listTranslations", "saveTranslations",
96 "addTranslation", "deleteTranslations", "activateContentMultilinguality",
97 "confirmRemoveLanguages", "removeLanguages", "confirmDeactivateContentMultiLang", "saveLanguages",
98 "saveContentTranslationActivation", "deactivateContentMultiLang", "addLanguages"))) {
99 $this->$cmd();
100 }
101 break;
102 }
103 }
104
108 public function listTranslations($a_get_post_values = false, $a_add = false)
109 {
110 $ilToolbar = $this->toolbar;
111
112 $this->lng->loadLanguageModule(ilObject::_lookupType($this->obj->getId()));
113
114
115 if ($this->getTitleDescrOnlyMode() || $this->obj_trans->getContentActivated()) {
116 $ilToolbar->addButton(
117 $this->lng->txt("obj_add_languages"),
118 $this->ctrl->getLinkTarget($this, "addLanguages")
119 );
120 }
121
122 if ($this->getTitleDescrOnlyMode()) {
123 if (!$this->obj_trans->getContentActivated()) {
124 ilUtil::sendInfo($this->lng->txt("obj_multilang_title_descr_only"));
125 $ilToolbar->addButton(
126 $this->lng->txt("obj_activate_content_lang"),
127 $this->ctrl->getLinkTarget($this, "activateContentMultilinguality")
128 );
129 } else {
130 $ilToolbar->addButton(
131 $this->lng->txt("obj_deactivate_content_lang"),
132 $this->ctrl->getLinkTarget($this, "confirmDeactivateContentMultiLang")
133 );
134 }
135 } else {
136 if ($this->obj_trans->getContentActivated()) {
137 $ilToolbar->addButton(
138 $this->lng->txt("obj_deactivate_multilang"),
139 $this->ctrl->getLinkTarget($this, "confirmDeactivateContentMultiLang")
140 );
141 } else {
142 $ilToolbar->addButton(
143 $this->lng->txt("obj_activate_multilang"),
144 $this->ctrl->getLinkTarget($this, "activateContentMultilinguality")
145 );
146 return;
147 }
148 }
149
150 include_once("./Services/Object/classes/class.ilObjectTranslation2TableGUI.php");
152 $this,
153 "listTranslations",
154 true,
155 "Translation",
156 $this->obj_trans->getMasterLanguage()
157 );
158 if ($a_get_post_values) {
159 $vals = array();
160 foreach ($_POST["title"] as $k => $v) {
161 $vals[] = array("title" => $v,
162 "desc" => $_POST["desc"][$k],
163 "lang" => $_POST["lang"][$k],
164 "default" => ($_POST["default"] == $k));
165 }
166 $table->setData($vals);
167 } else {
168 $data = $this->obj_trans->getLanguages();
169 foreach ($data as $k => $v) {
170 $data[$k]["default"] = $v["lang_default"];
171 $data[$k]["desc"] = $v["description"];
172 $data[$k]["lang"] = $v["lang_code"];
173 }
174 /* if($a_add)
175 {
176 $data["Fobject"][++$k]["title"] = "";
177 }*/
178 $table->setData($data);
179 }
180 $this->tpl->setContent($table->getHTML());
181 }
182
186 public function saveTranslations()
187 {
188 // default language set?
189 if (!isset($_POST["default"]) && $this->obj_trans->getMasterLanguage() == "") {
190 ilUtil::sendFailure($this->lng->txt("msg_no_default_language"));
191 $this->listTranslations(true);
192 return;
193 }
194
195 // all languages set?
196 if (array_key_exists("", $_POST["lang"])) {
197 ilUtil::sendFailure($this->lng->txt("msg_no_language_selected"));
198 $this->listTranslations(true);
199 return;
200 }
201
202 // no single language is selected more than once?
203 if (count(array_unique($_POST["lang"])) < count($_POST["lang"])) {
204 ilUtil::sendFailure($this->lng->txt("msg_multi_language_selected"));
205 $this->listTranslations(true);
206 return;
207 }
208
209 // save the stuff
210 $this->obj_trans->setLanguages(array());
211
212 foreach ($_POST["title"] as $k => $v) {
213 // update object data if default
214 $is_default = ($_POST["default"] == $k);
215
216 // ensure master language is set as default
217 if ($this->obj_trans->getMasterLanguage() != "") {
218 $is_default = ($this->obj_trans->getMasterLanguage() == $_POST["lang"][$k]);
219 }
220 if ($is_default) {
221 $this->obj->setTitle(ilUtil::stripSlashes($v));
222 $this->obj->setDescription(ilUtil::stripSlashes($_POST["desc"][$k]));
223 }
224
225 $this->obj_trans->addLanguage(
226 ilUtil::stripSlashes($_POST["lang"][$k]),
228 ilUtil::stripSlashes($_POST["desc"][$k]),
229 $is_default
230 );
231 }
232 $this->obj_trans->save();
233 if (method_exists($this->obj, "setObjectTranslation")) {
234 $this->obj->setObjectTranslation($this->obj_trans);
235 }
236 $this->obj->update();
237
238 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
239 $this->ctrl->redirect($this, "listTranslations");
240 }
241
245 public function deleteTranslations()
246 {
247 foreach ($_POST["title"] as $k => $v) {
248 if ($_POST["check"][$k]) {
249 // default translation cannot be deleted
250 if ($k != $_POST["default"]) {
251 unset($_POST["title"][$k]);
252 unset($_POST["desc"][$k]);
253 unset($_POST["lang"][$k]);
254 } else {
255 ilUtil::sendFailure($this->lng->txt("msg_no_default_language"));
256 $this->listTranslations();
257 return;
258 }
259 }
260 }
261 $this->saveTranslations();
262 }
263
267
272 {
275
276 ilUtil::sendInfo($lng->txt("obj_select_master_lang"));
277
278 $form = $this->getMultiLangForm();
279 $tpl->setContent($form->getHTML());
280 }
281
285 public function getMultiLangForm($a_add = false)
286 {
291
292 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
293 $form = new ilPropertyFormGUI();
294
295 // master language
296 if (!$a_add) {
297 include_once("./Services/MetaData/classes/class.ilMDLanguageItem.php");
299 $si = new ilSelectInputGUI($lng->txt("obj_master_lang"), "master_lang");
300 $si->setOptions($options);
301 $si->setValue($ilUser->getLanguage());
302 $form->addItem($si);
303 }
304
305 // additional languages
306 if ($a_add) {
307 include_once("./Services/MetaData/classes/class.ilMDLanguageItem.php");
309 $options = array("" => $lng->txt("please_select")) + $options;
310 $si = new ilSelectInputGUI($lng->txt("obj_additional_langs"), "additional_langs");
311 $si->setOptions($options);
312 $si->setMulti(true);
313 $form->addItem($si);
314 }
315
316 if ($a_add) {
317 $form->setTitle($lng->txt("obj_add_languages"));
318 $form->addCommandButton("saveLanguages", $lng->txt("save"));
319 $form->addCommandButton("listTranslations", $lng->txt("cancel"));
320 } else {
321 if ($this->getTitleDescrOnlyMode()) {
322 $form->setTitle($lng->txt("obj_activate_content_lang"));
323 } else {
324 $form->setTitle($lng->txt("obj_activate_multilang"));
325 }
326 $form->addCommandButton("saveContentTranslationActivation", $lng->txt("save"));
327 $form->addCommandButton("listTranslations", $lng->txt("cancel"));
328 }
329 $form->setFormAction($ilCtrl->getFormAction($this));
330
331 return $form;
332 }
333
338 {
340
341 // include_once("./Services/COPage/classes/class.ilPageMultiLang.php");
342
343 $form = $this->getMultiLangForm();
344 if ($form->checkInput()) {
345 $ml = $form->getInput("master_lang");
346 $this->obj_trans->setMasterLanguage($ml);
347 $this->obj_trans->addLanguage(
348 $ml,
349 $this->obj->getTitle(),
350 $this->obj->getDescription(),
351 true
352 );
353 $this->obj_trans->setDefaultTitle($this->obj->getTitle());
354 $this->obj_trans->setDefaultDescription($this->obj->getDescription());
355 $this->obj_trans->save();
356 }
357
358 $ilCtrl->redirect($this, "listTranslations");
359 }
360
365 {
369
370 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
371 $cgui = new ilConfirmationGUI();
372 $cgui->setFormAction($ilCtrl->getFormAction($this));
373 if ($this->getTitleDescrOnlyMode()) {
374 $cgui->setHeaderText($lng->txt("obj_deactivate_content_transl_conf"));
375 } else {
376 $cgui->setHeaderText($lng->txt("obj_deactivate_multilang_conf"));
377 }
378
379 $cgui->setCancel($lng->txt("cancel"), "listTranslations");
380 $cgui->setConfirm($lng->txt("confirm"), "deactivateContentMultiLang");
381 $tpl->setContent($cgui->getHTML());
382 }
383
388 {
391
392 if (!$this->getTitleDescrOnlyMode()) {
393 $this->obj_trans->setMasterLanguage("");
394 $this->obj_trans->setLanguages(array());
395 $this->obj_trans->save();
396 }
397 $this->obj_trans->deactivateContentTranslation();
398 if ($this->getTitleDescrOnlyMode()) {
399 ilUtil::sendSuccess($lng->txt("obj_cont_transl_deactivated"), true);
400 } else {
401 ilUtil::sendSuccess($lng->txt("obj_multilang_deactivated"), true);
402 }
403
404
405 $ilCtrl->redirect($this, "listTranslations");
406 }
407
411 public function addLanguages()
412 {
414
415 $form = $this->getMultiLangForm(true);
416 $tpl->setContent($form->getHTML());
417 }
418
422 public function saveLanguages()
423 {
427
428 $form = $this->getMultiLangForm(true);
429 if ($form->checkInput()) {
430 $ad = $form->getInput("additional_langs");
431 if (is_array($ad)) {
432 $ml = $this->obj_trans->getMasterLanguage();
433 foreach ($ad as $l) {
434 if ($l != $ml && $l != "") {
435 $this->obj_trans->addLanguage($l, false, "", "");
436 }
437 }
438 }
439 $this->obj_trans->save();
440 ilUtil::sendInfo($lng->txt("msg_obj_modified"), true);
441 $ilCtrl->redirect($this, "listTranslations");
442 }
443
444 ilUtil::sendFailure($this->lng->txt('err_check_input'));
445 $form->setValuesByPost();
446 $tpl->setContent($form->getHTML());
447 }
448
452 public function confirmRemoveLanguages()
453 {
457
458 $lng->loadLanguageModule("meta");
459
460 if (!is_array($_POST["lang"]) || count($_POST["lang"]) == 0) {
461 ilUtil::sendInfo($lng->txt("no_checkbox"), true);
462 $ilCtrl->redirect($this, "listTranslations");
463 } else {
464 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
465 $cgui = new ilConfirmationGUI();
466 $cgui->setFormAction($ilCtrl->getFormAction($this));
467 $cgui->setHeaderText($lng->txt("obj_conf_delete_lang"));
468 $cgui->setCancel($lng->txt("cancel"), "listTranslations");
469 $cgui->setConfirm($lng->txt("remove"), "removeLanguages");
470
471 foreach ($_POST["lang"] as $i) {
472 $cgui->addItem("lang[]", $i, $lng->txt("meta_l_" . $i));
473 }
474
475 $tpl->setContent($cgui->getHTML());
476 }
477 }
478
482 public function removeLanguages()
483 {
486
487 if (is_array($_POST["lang"])) {
488 $langs = $this->obj_trans->getLanguages();
489 foreach ($langs as $k => $l) {
490 if (in_array($l, $_POST["lang"])) {
491 $this->obj_trans->removeLanguage();
492 }
493 }
494 $this->obj_trans->save();
495 ilUtil::sendInfo($lng->txt("msg_obj_modified"), true);
496 }
497 $ilCtrl->redirect($this, "listTranslations");
498 }
499}
user()
Definition: user.php:4
global $l
Definition: afr.php:30
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Confirmation screen class.
TableGUI class for title/description translations.
GUI class for object translation handling.
listTranslations($a_get_post_values=false, $a_add=false)
List translations.
activateContentMultilinguality()
Activate multi language (-> master language selection)
__construct($a_obj_gui)
Constructor.
deactivateContentMultiLang()
Deactivate multilanguage.
confirmDeactivateContentMultiLang()
Confirm page translation creation.
confirmRemoveLanguages()
Confirm remove languages.
getMultiLangForm($a_add=false)
Get multi language form.
saveContentTranslationActivation()
Save content translation activation.
getTitleDescrOnlyMode()
Get enable title/description only mode.
setTitleDescrOnlyMode($a_val)
Set enable title/description only mode.
static getInstance($a_obj_id)
Get instance.
static _lookupType($a_id, $a_reference=false)
lookup object type
This class represents a property form user interface.
This class represents a selection list property in a property form.
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
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$i
Definition: disco.tpl.php:19
global $ilCtrl
Definition: ilias.php:18
if(empty($password)) $table
Definition: pwgen.php:24
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7
$ilUser
Definition: imgupload.php:18
$data
Definition: bench.php:6