ILIAS  release_7 Revision v7.30-3-g800a261c036
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 protected $fallback_lang_mode = true;
46
50 public function __construct($a_obj_gui)
51 {
52 global $DIC;
53
54 $this->toolbar = $DIC->toolbar();
55 $this->user = $DIC->user();
56 $lng = $DIC->language();
57 $ilCtrl = $DIC->ctrl();
58 $tpl = $DIC["tpl"];
59
60 $this->lng = $lng;
61 $this->ctrl = $ilCtrl;
62 $this->tpl = $tpl;
63 $this->obj_gui = $a_obj_gui;
64 $this->obj = $a_obj_gui->object;
65
66 include_once("./Services/Object/classes/class.ilObjectTranslation.php");
67 $this->obj_trans = ilObjectTranslation::getInstance($this->obj->getId());
68 }
69
75 public function setTitleDescrOnlyMode($a_val)
76 {
77 $this->title_descr_only = $a_val;
78 }
79
85 public function getTitleDescrOnlyMode()
86 {
88 }
89
94 public function setEnableFallbackLanguage($a_val)
95 {
96 $this->fallback_lang_mode = $a_val;
97 }
98
104 {
106 }
107
108
112 public function executeCommand()
113 {
114 $next_class = $this->ctrl->getNextClass($this);
115
116 switch ($next_class) {
117 default:
118 $cmd = $this->ctrl->getCmd("listTranslations");
119 if (in_array($cmd, array("listTranslations", "saveTranslations",
120 "addTranslation", "deleteTranslations", "activateContentMultilinguality",
121 "confirmRemoveLanguages", "removeLanguages", "confirmDeactivateContentMultiLang", "saveLanguages",
122 "saveContentTranslationActivation", "deactivateContentMultiLang", "addLanguages", "setFallback"))) {
123 $this->$cmd();
124 }
125 break;
126 }
127 }
128
132 public function listTranslations($a_get_post_values = false, $a_add = false)
133 {
134 $ilToolbar = $this->toolbar;
135
136 $this->lng->loadLanguageModule(ilObject::_lookupType($this->obj->getId()));
137
138
139 if ($this->getTitleDescrOnlyMode() || $this->obj_trans->getContentActivated()) {
140 $ilToolbar->addButton(
141 $this->lng->txt("obj_add_languages"),
142 $this->ctrl->getLinkTarget($this, "addLanguages")
143 );
144 }
145
146 if ($this->getTitleDescrOnlyMode()) {
147 if (!$this->obj_trans->getContentActivated()) {
148 ilUtil::sendInfo($this->lng->txt("obj_multilang_title_descr_only"));
149 $ilToolbar->addButton(
150 $this->lng->txt("obj_activate_content_lang"),
151 $this->ctrl->getLinkTarget($this, "activateContentMultilinguality")
152 );
153 } else {
154 $ilToolbar->addButton(
155 $this->lng->txt("obj_deactivate_content_lang"),
156 $this->ctrl->getLinkTarget($this, "confirmDeactivateContentMultiLang")
157 );
158 }
159 } else {
160 if ($this->obj_trans->getContentActivated()) {
161 $ilToolbar->addButton(
162 $this->lng->txt("obj_deactivate_multilang"),
163 $this->ctrl->getLinkTarget($this, "confirmDeactivateContentMultiLang")
164 );
165 } else {
166 $ilToolbar->addButton(
167 $this->lng->txt("obj_activate_multilang"),
168 $this->ctrl->getLinkTarget($this, "activateContentMultilinguality")
169 );
170 return;
171 }
172 }
173
174 include_once("./Services/Object/classes/class.ilObjectTranslation2TableGUI.php");
175 $table = new ilObjectTranslation2TableGUI(
176 $this,
177 "listTranslations",
178 true,
179 "Translation",
180 $this->obj_trans->getMasterLanguage(),
181 $this->fallback_lang_mode,
182 $this->obj_trans->getFallbackLanguage()
183 );
184 if ($a_get_post_values) {
185 $vals = array();
186 foreach ($_POST["title"] as $k => $v) {
187 $vals[] = array("title" => $v,
188 "desc" => $_POST["desc"][$k],
189 "lang" => $_POST["lang"][$k],
190 "default" => ($_POST["default"] == $k));
191 }
192 $table->setData($vals);
193 } else {
194 $data = $this->obj_trans->getLanguages();
195 foreach ($data as $k => $v) {
196 $data[$k]["default"] = $v["lang_default"];
197 $data[$k]["desc"] = $v["description"];
198 $data[$k]["lang"] = $v["lang_code"];
199 }
200 /* if($a_add)
201 {
202 $data["Fobject"][++$k]["title"] = "";
203 }*/
204 $table->setData($data);
205 }
206 $this->tpl->setContent($table->getHTML());
207 }
208
212 public function saveTranslations()
213 {
214 // default language set?
215 if (!isset($_POST["default"]) && $this->obj_trans->getMasterLanguage() == "") {
216 ilUtil::sendFailure($this->lng->txt("msg_no_default_language"));
217 $this->listTranslations(true);
218 return;
219 }
220
221 // all languages set?
222 if (array_key_exists("", $_POST["lang"])) {
223 ilUtil::sendFailure($this->lng->txt("msg_no_language_selected"));
224 $this->listTranslations(true);
225 return;
226 }
227
228 // no single language is selected more than once?
229 if (count(array_unique($_POST["lang"])) < count($_POST["lang"])) {
230 ilUtil::sendFailure($this->lng->txt("msg_multi_language_selected"));
231 $this->listTranslations(true);
232 return;
233 }
234
235 // save the stuff
236 $this->obj_trans->setLanguages(array());
237 if ($this->obj_trans->getFallbackLanguage() != "") {
238 $obj_store_lang = $this->obj_trans->getFallbackLanguage();
239 } else {
240 $obj_store_lang = $this->obj_trans->getMasterLanguage()
241 ?? $_POST["lang"][$_POST["default"]];
242 }
243
244 foreach ($_POST["title"] as $k => $v) {
245 // update object data if default
246 $is_default = ($_POST["default"] == $k);
247
248 // ensure master language is set as default
249 if ($this->obj_trans->getMasterLanguage() != "") {
250 $is_default = ($this->obj_trans->getMasterLanguage() == $_POST["lang"][$k]);
251 }
252 if ($_POST["lang"][$k] == $obj_store_lang) {
253 $this->obj->setTitle(ilUtil::stripSlashes($v));
254 $this->obj->setDescription(ilUtil::stripSlashes($_POST["desc"][$k]));
255 }
256
257 $this->obj_trans->addLanguage(
258 ilUtil::stripSlashes($_POST["lang"][$k]),
260 ilUtil::stripSlashes($_POST["desc"][$k]),
261 $is_default
262 );
263 }
264 $this->obj_trans->save();
265 if (method_exists($this->obj, "setObjectTranslation")) {
266 $this->obj->setObjectTranslation($this->obj_trans);
267 }
268 $this->obj->update();
269
270 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
271 $this->ctrl->redirect($this, "listTranslations");
272 }
273
277 public function deleteTranslations()
278 {
279 foreach ($_POST["title"] as $k => $v) {
280 if ($_POST["check"][$k]) {
281 // default translation cannot be deleted
282 if ($k != $_POST["default"]) {
283 unset($_POST["title"][$k]);
284 unset($_POST["desc"][$k]);
285 unset($_POST["lang"][$k]);
286 } else {
287 ilUtil::sendFailure($this->lng->txt("msg_no_default_language"));
288 $this->listTranslations();
289 return;
290 }
291 }
292 }
293 $this->saveTranslations();
294 }
295
299
304 {
307
308 ilUtil::sendInfo($lng->txt("obj_select_master_lang"));
309
310 $form = $this->getMultiLangForm();
311 $tpl->setContent($form->getHTML());
312 }
313
317 public function getMultiLangForm($a_add = false)
318 {
321 $ilCtrl = $this->ctrl;
323
324 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
325 $form = new ilPropertyFormGUI();
326
327 // master language
328 if (!$a_add) {
329 include_once("./Services/MetaData/classes/class.ilMDLanguageItem.php");
331 $si = new ilSelectInputGUI($lng->txt("obj_master_lang"), "master_lang");
332 $si->setOptions($options);
333 $si->setValue($ilUser->getLanguage());
334 $form->addItem($si);
335 }
336
337 // additional languages
338 if ($a_add) {
339 include_once("./Services/MetaData/classes/class.ilMDLanguageItem.php");
341 $options = array("" => $lng->txt("please_select")) + $options;
342 $si = new ilSelectInputGUI($lng->txt("obj_additional_langs"), "additional_langs");
343 $si->setOptions($options);
344 $si->setMulti(true);
345 $form->addItem($si);
346 }
347
348 if ($a_add) {
349 $form->setTitle($lng->txt("obj_add_languages"));
350 $form->addCommandButton("saveLanguages", $lng->txt("save"));
351 $form->addCommandButton("listTranslations", $lng->txt("cancel"));
352 } else {
353 if ($this->getTitleDescrOnlyMode()) {
354 $form->setTitle($lng->txt("obj_activate_content_lang"));
355 } else {
356 $form->setTitle($lng->txt("obj_activate_multilang"));
357 }
358 $form->addCommandButton("saveContentTranslationActivation", $lng->txt("save"));
359 $form->addCommandButton("listTranslations", $lng->txt("cancel"));
360 }
361 $form->setFormAction($ilCtrl->getFormAction($this));
362
363 return $form;
364 }
365
370 {
371 $ilCtrl = $this->ctrl;
372
373 // include_once("./Services/COPage/classes/class.ilPageMultiLang.php");
374
375 $form = $this->getMultiLangForm();
376 if ($form->checkInput()) {
377 $ml = $form->getInput("master_lang");
378 $this->obj_trans->setMasterLanguage($ml);
379 $this->obj_trans->addLanguage(
380 $ml,
381 $this->obj->getTitle(),
382 $this->obj->getDescription(),
383 true
384 );
385 $this->obj_trans->setDefaultTitle($this->obj->getTitle());
386 $this->obj_trans->setDefaultDescription($this->obj->getDescription());
387 $this->obj_trans->save();
388 }
389
390 $ilCtrl->redirect($this, "listTranslations");
391 }
392
397 {
398 $ilCtrl = $this->ctrl;
401
402 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
403 $cgui = new ilConfirmationGUI();
404 $cgui->setFormAction($ilCtrl->getFormAction($this));
405 if ($this->getTitleDescrOnlyMode()) {
406 $cgui->setHeaderText($lng->txt("obj_deactivate_content_transl_conf"));
407 } else {
408 $cgui->setHeaderText($lng->txt("obj_deactivate_multilang_conf"));
409 }
410
411 $cgui->setCancel($lng->txt("cancel"), "listTranslations");
412 $cgui->setConfirm($lng->txt("confirm"), "deactivateContentMultiLang");
413 $tpl->setContent($cgui->getHTML());
414 }
415
420 {
422 $ilCtrl = $this->ctrl;
423
424 if (!$this->getTitleDescrOnlyMode()) {
425 $this->obj_trans->setMasterLanguage("");
426 $this->obj_trans->setLanguages(array());
427 $this->obj_trans->save();
428 }
429 $this->obj_trans->deactivateContentTranslation();
430 if ($this->getTitleDescrOnlyMode()) {
431 ilUtil::sendSuccess($lng->txt("obj_cont_transl_deactivated"), true);
432 } else {
433 ilUtil::sendSuccess($lng->txt("obj_multilang_deactivated"), true);
434 }
435
436
437 $ilCtrl->redirect($this, "listTranslations");
438 }
439
443 public function addLanguages()
444 {
446
447 $form = $this->getMultiLangForm(true);
448 $tpl->setContent($form->getHTML());
449 }
450
454 public function saveLanguages()
455 {
456 $ilCtrl = $this->ctrl;
459
460 $form = $this->getMultiLangForm(true);
461 if ($form->checkInput()) {
462 $ad = $form->getInput("additional_langs");
463 if (is_array($ad)) {
464 $ml = $this->obj_trans->getMasterLanguage();
465 foreach ($ad as $l) {
466 if ($l != $ml && $l != "") {
467 $this->obj_trans->addLanguage($l, false, "", "");
468 }
469 }
470 }
471 $this->obj_trans->save();
472 ilUtil::sendInfo($lng->txt("msg_obj_modified"), true);
473 $ilCtrl->redirect($this, "listTranslations");
474 }
475
476 ilUtil::sendFailure($this->lng->txt('err_check_input'));
477 $form->setValuesByPost();
478 $tpl->setContent($form->getHTML());
479 }
480
484 public function confirmRemoveLanguages()
485 {
486 $ilCtrl = $this->ctrl;
489
490 $lng->loadLanguageModule("meta");
491
492 if (!is_array($_POST["lang"]) || count($_POST["lang"]) == 0) {
493 ilUtil::sendInfo($lng->txt("no_checkbox"), true);
494 $ilCtrl->redirect($this, "listTranslations");
495 } else {
496 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
497 $cgui = new ilConfirmationGUI();
498 $cgui->setFormAction($ilCtrl->getFormAction($this));
499 $cgui->setHeaderText($lng->txt("obj_conf_delete_lang"));
500 $cgui->setCancel($lng->txt("cancel"), "listTranslations");
501 $cgui->setConfirm($lng->txt("remove"), "removeLanguages");
502
503 foreach ($_POST["lang"] as $i) {
504 $cgui->addItem("lang[]", $i, $lng->txt("meta_l_" . $i));
505 }
506
507 $tpl->setContent($cgui->getHTML());
508 }
509 }
510
514 public function removeLanguages()
515 {
517 $ilCtrl = $this->ctrl;
518
519 if (is_array($_POST["lang"])) {
520 $langs = $this->obj_trans->getLanguages();
521 foreach ($langs as $k => $l) {
522 if (in_array($l, $_POST["lang"])) {
523 $this->obj_trans->removeLanguage($l);
524 }
525 }
526 $this->obj_trans->save();
527 ilUtil::sendInfo($lng->txt("msg_obj_modified"), true);
528 }
529 $ilCtrl->redirect($this, "listTranslations");
530 }
531
535 public function setFallback()
536 {
538 $ilCtrl = $this->ctrl;
539 // default language set?
540 if (!isset($_POST["check"]) || count($_POST["check"]) !== 1) {
541 ilUtil::sendFailure($this->lng->txt("obj_select_one_language"));
542 $this->listTranslations(true);
543 return;
544 }
545
546 $fallback_lang = $_POST["lang"][key($_POST["check"])];
547 if ($fallback_lang != $this->obj_trans->getFallbackLanguage()) {
548 $this->obj_trans->setFallbackLanguage($fallback_lang);
549 } else {
550 $this->obj_trans->setFallbackLanguage("");
551 }
552 $this->obj_trans->save();
553 ilUtil::sendInfo($lng->txt("msg_obj_modified"), true);
554 $ilCtrl->redirect($this, "listTranslations");
555 }
556}
user()
Definition: user.php:4
$_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.
setEnableFallbackLanguage($a_val)
Set enable fallback language.
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.
getEnableFallbackLanguage()
Get enable fallback language.
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.
global $DIC
Definition: goto.php:24
$ilUser
Definition: imgupload.php:18
$i
Definition: metadata.php:24
$data
Definition: storeScorm.php:23