ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $this->obj->update();
224 }
225
226 $this->obj_trans->addLanguage(
227 ilUtil::stripSlashes($_POST["lang"][$k]),
229 ilUtil::stripSlashes($_POST["desc"][$k]),
230 $is_default
231 );
232 }
233 $this->obj_trans->save();
234
235 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
236 $this->ctrl->redirect($this, "listTranslations");
237 }
238
242 public function deleteTranslations()
243 {
244 foreach ($_POST["title"] as $k => $v) {
245 if ($_POST["check"][$k]) {
246 // default translation cannot be deleted
247 if ($k != $_POST["default"]) {
248 unset($_POST["title"][$k]);
249 unset($_POST["desc"][$k]);
250 unset($_POST["lang"][$k]);
251 } else {
252 ilUtil::sendFailure($this->lng->txt("msg_no_default_language"));
253 $this->listTranslations();
254 return;
255 }
256 }
257 }
258 $this->saveTranslations();
259 }
260
264
269 {
272
273 ilUtil::sendInfo($lng->txt("obj_select_master_lang"));
274
275 $form = $this->getMultiLangForm();
276 $tpl->setContent($form->getHTML());
277 }
278
282 public function getMultiLangForm($a_add = false)
283 {
288
289 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
290 $form = new ilPropertyFormGUI();
291
292 // master language
293 if (!$a_add) {
294 include_once("./Services/MetaData/classes/class.ilMDLanguageItem.php");
296 $si = new ilSelectInputGUI($lng->txt("obj_master_lang"), "master_lang");
297 $si->setOptions($options);
298 $si->setValue($ilUser->getLanguage());
299 $form->addItem($si);
300 }
301
302 // additional languages
303 if ($a_add) {
304 include_once("./Services/MetaData/classes/class.ilMDLanguageItem.php");
306 $options = array("" => $lng->txt("please_select")) + $options;
307 $si = new ilSelectInputGUI($lng->txt("obj_additional_langs"), "additional_langs");
308 $si->setOptions($options);
309 $si->setMulti(true);
310 $form->addItem($si);
311 }
312
313 if ($a_add) {
314 $form->setTitle($lng->txt("obj_add_languages"));
315 $form->addCommandButton("saveLanguages", $lng->txt("save"));
316 $form->addCommandButton("listTranslations", $lng->txt("cancel"));
317 } else {
318 if ($this->getTitleDescrOnlyMode()) {
319 $form->setTitle($lng->txt("obj_activate_content_lang"));
320 } else {
321 $form->setTitle($lng->txt("obj_activate_multilang"));
322 }
323 $form->addCommandButton("saveContentTranslationActivation", $lng->txt("save"));
324 $form->addCommandButton("listTranslations", $lng->txt("cancel"));
325 }
326 $form->setFormAction($ilCtrl->getFormAction($this));
327
328 return $form;
329 }
330
335 {
337
338 // include_once("./Services/COPage/classes/class.ilPageMultiLang.php");
339
340 $form = $this->getMultiLangForm();
341 if ($form->checkInput()) {
342 $ml = $form->getInput("master_lang");
343 $this->obj_trans->setMasterLanguage($ml);
344 $this->obj_trans->addLanguage(
345 $ml,
346 $this->obj->getTitle(),
347 $this->obj->getDescription(),
348 true
349 );
350 $this->obj_trans->setDefaultTitle($this->obj->getTitle());
351 $this->obj_trans->setDefaultDescription($this->obj->getDescription());
352 $this->obj_trans->save();
353 }
354
355 $ilCtrl->redirect($this, "listTranslations");
356 }
357
361 /*
362 function getMultiLangInfo($a_page_lang = "-")
363 {
364 global $lng;
365
366 if ($a_page_lang == "")
367 {
368 $a_page_lang = "-";
369 }
370
371 $lng->loadLanguageModule("meta");
372
373 $tpl = new ilTemplate("tpl.page_multi_lang_info.html", true, true, "Services/COPage");
374 $tpl->setVariable("TXT_MASTER_LANG", $lng->txt("cont_master_lang"));
375 $tpl->setVariable("VAL_ML", $lng->txt("meta_l_".$this->ml->getMasterLanguage()));
376 $cl = ($a_page_lang == "-")
377 ? $this->ml->getMasterLanguage()
378 : $a_page_lang;
379 $tpl->setVariable("TXT_CURRENT_LANG", $lng->txt("cont_current_lang"));
380 $tpl->setVariable("VAL_CL", $lng->txt("meta_l_".$cl));
381 return $tpl->get();
382 }*/
383
388 {
392
393 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
394 $cgui = new ilConfirmationGUI();
395 $cgui->setFormAction($ilCtrl->getFormAction($this));
396 if ($this->getTitleDescrOnlyMode()) {
397 $cgui->setHeaderText($lng->txt("obj_deactivate_content_transl_conf"));
398 } else {
399 $cgui->setHeaderText($lng->txt("obj_deactivate_multilang_conf"));
400 }
401
402 $cgui->setCancel($lng->txt("cancel"), "listTranslations");
403 $cgui->setConfirm($lng->txt("confirm"), "deactivateContentMultiLang");
404 $tpl->setContent($cgui->getHTML());
405 }
406
411 {
414
415 if (!$this->getTitleDescrOnlyMode()) {
416 $this->obj_trans->setMasterLanguage("");
417 $this->obj_trans->setLanguages(array());
418 $this->obj_trans->save();
419 }
420 $this->obj_trans->deactivateContentTranslation();
421 if ($this->getTitleDescrOnlyMode()) {
422 ilUtil::sendSuccess($lng->txt("obj_cont_transl_deactivated"), true);
423 } else {
424 ilUtil::sendSuccess($lng->txt("obj_multilang_deactivated"), true);
425 }
426
427
428 $ilCtrl->redirect($this, "listTranslations");
429 }
430
434 public function addLanguages()
435 {
437
438 $form = $this->getMultiLangForm(true);
439 $tpl->setContent($form->getHTML());
440 }
441
445 public function saveLanguages()
446 {
450
451 $form = $this->getMultiLangForm(true);
452 if ($form->checkInput()) {
453 $ad = $form->getInput("additional_langs");
454 if (is_array($ad)) {
455 $ml = $this->obj_trans->getMasterLanguage();
456 foreach ($ad as $l) {
457 if ($l != $ml && $l != "") {
458 $this->obj_trans->addLanguage($l, false, "", "");
459 }
460 }
461 }
462 $this->obj_trans->save();
463 ilUtil::sendInfo($lng->txt("msg_obj_modified"), true);
464 $ilCtrl->redirect($this, "listTranslations");
465 }
466
467 ilUtil::sendFailure($this->lng->txt('err_check_input'));
468 $form->setValuesByPost();
469 $tpl->setContent($form->getHTML());
470 }
471
475 public function confirmRemoveLanguages()
476 {
480
481 $lng->loadLanguageModule("meta");
482
483 if (!is_array($_POST["lang"]) || count($_POST["lang"]) == 0) {
484 ilUtil::sendInfo($lng->txt("no_checkbox"), true);
485 $ilCtrl->redirect($this, "listTranslations");
486 } else {
487 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
488 $cgui = new ilConfirmationGUI();
489 $cgui->setFormAction($ilCtrl->getFormAction($this));
490 $cgui->setHeaderText($lng->txt("obj_conf_delete_lang"));
491 $cgui->setCancel($lng->txt("cancel"), "listTranslations");
492 $cgui->setConfirm($lng->txt("remove"), "removeLanguages");
493
494 foreach ($_POST["lang"] as $i) {
495 $cgui->addItem("lang[]", $i, $lng->txt("meta_l_" . $i));
496 }
497
498 $tpl->setContent($cgui->getHTML());
499 }
500 }
501
505 public function removeLanguages()
506 {
509
510 if (is_array($_POST["lang"])) {
511 $langs = $this->obj_trans->getLanguages();
512 foreach ($langs as $k => $l) {
513 if (in_array($l, $_POST["lang"])) {
514 $this->obj_trans->removeLanguage();
515 }
516 }
517 $this->obj_trans->save();
518 ilUtil::sendInfo($lng->txt("msg_obj_modified"), true);
519 }
520 $ilCtrl->redirect($this, "listTranslations");
521 }
522}
user()
Definition: user.php:4
global $l
Definition: afr.php:30
if(!isset( $_REQUEST[ 'ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
$_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()
Get multi lang info.
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 sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
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