ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 {
14  protected $obj_trans;
15  protected $title_descr_only = true;
16 
20  function __construct($a_obj_gui)
21  {
22  global $lng, $ilCtrl, $tpl;
23 
24  $this->lng = $lng;
25  $this->ctrl = $ilCtrl;
26  $this->tpl = $tpl;
27  $this->obj_gui = $a_obj_gui;
28  $this->obj = $a_obj_gui->object;
29 
30  include_once("./Services/Object/classes/class.ilObjectTranslation.php");
31  $this->obj_trans = ilObjectTranslation::getInstance($this->obj->getId());
32  }
33 
39  function setTitleDescrOnlyMode($a_val)
40  {
41  $this->title_descr_only = $a_val;
42  }
43 
50  {
52  }
53 
57  function executeCommand()
58  {
59  $next_class = $this->ctrl->getNextClass($this);
60 
61  switch ($next_class)
62  {
63  default:
64  $cmd = $this->ctrl->getCmd("listTranslations");
65  if (in_array($cmd, array("listTranslations", "saveTranslations",
66  "addTranslation", "deleteTranslations", "activateContentMultilinguality",
67  "confirmRemoveLanguages", "removeLanguages", "confirmDeactivateContentMultiLang", "saveLanguages",
68  "saveContentTranslationActivation", "deactivateContentMultiLang", "addLanguages")))
69  {
70  $this->$cmd();
71  }
72  break;
73  }
74  }
75 
79  function listTranslations($a_get_post_values = false, $a_add = false)
80  {
81  global $ilToolbar;
82 
83  $this->lng->loadLanguageModule(ilObject::_lookupType($this->obj->getId()));
84 
85 
86  if ($this->getTitleDescrOnlyMode() || $this->obj_trans->getContentActivated())
87  {
88  $ilToolbar->addButton($this->lng->txt("obj_add_languages"),
89  $this->ctrl->getLinkTarget($this, "addLanguages"));
90  }
91 
92  if ($this->getTitleDescrOnlyMode())
93  {
94  if (!$this->obj_trans->getContentActivated())
95  {
96  ilUtil::sendInfo($this->lng->txt("obj_multilang_title_descr_only"));
97  $ilToolbar->addButton($this->lng->txt("obj_activate_content_lang"),
98  $this->ctrl->getLinkTarget($this, "activateContentMultilinguality"));
99  }
100  else
101  {
102  $ilToolbar->addButton($this->lng->txt("obj_deactivate_content_lang"),
103  $this->ctrl->getLinkTarget($this, "confirmDeactivateContentMultiLang"));
104  }
105  }
106  else
107  {
108 
109  if ($this->obj_trans->getContentActivated())
110  {
111  $ilToolbar->addButton($this->lng->txt("obj_deactivate_multilang"),
112  $this->ctrl->getLinkTarget($this, "confirmDeactivateContentMultiLang"));
113  }
114  else
115  {
116  $ilToolbar->addButton($this->lng->txt("obj_activate_multilang"),
117  $this->ctrl->getLinkTarget($this, "activateContentMultilinguality"));
118  return;
119  }
120  }
121 
122  include_once("./Services/Object/classes/class.ilObjectTranslation2TableGUI.php");
123  $table = new ilObjectTranslation2TableGUI($this, "listTranslations", true,
124  "Translation", $this->obj_trans->getMasterLanguage());
125  if ($a_get_post_values)
126  {
127  $vals = array();
128  foreach($_POST["title"] as $k => $v)
129  {
130  $vals[] = array("title" => $v,
131  "desc" => $_POST["desc"][$k],
132  "lang" => $_POST["lang"][$k],
133  "default" => ($_POST["default"] == $k));
134  }
135  $table->setData($vals);
136  }
137  else
138  {
139  $data = $this->obj_trans->getLanguages();
140  foreach($data as $k => $v)
141  {
142  $data[$k]["default"] = $v["lang_default"];
143  $data[$k]["desc"] = $v["description"];
144  $data[$k]["lang"] = $v["lang_code"];
145  }
146 /* if($a_add)
147  {
148  $data["Fobject"][++$k]["title"] = "";
149  }*/
150  $table->setData($data);
151  }
152  $this->tpl->setContent($table->getHTML());
153 
154  }
155 
159  function saveTranslations()
160  {
161  // default language set?
162  if (!isset($_POST["default"]) && $this->obj_trans->getMasterLanguage() == "")
163  {
164  ilUtil::sendFailure($this->lng->txt("msg_no_default_language"));
165  $this->listTranslations(true);
166  return;
167  }
168 
169  // all languages set?
170  if (array_key_exists("",$_POST["lang"]))
171  {
172  ilUtil::sendFailure($this->lng->txt("msg_no_language_selected"));
173  $this->listTranslations(true);
174  return;
175  }
176 
177  // no single language is selected more than once?
178  if (count(array_unique($_POST["lang"])) < count($_POST["lang"]))
179  {
180  ilUtil::sendFailure($this->lng->txt("msg_multi_language_selected"));
181  $this->listTranslations(true);
182  return;
183  }
184 
185  // save the stuff
186  $this->obj_trans->setLanguages(array());
187 
188  foreach($_POST["title"] as $k => $v)
189  {
190  // update object data if default
191  $is_default = ($_POST["default"] == $k);
192 
193  // ensure master language is set as default
194  if ($this->obj_trans->getMasterLanguage() != "")
195  {
196  $is_default = ($this->obj_trans->getMasterLanguage() == $_POST["lang"][$k]);
197  }
198  if($is_default)
199  {
200  $this->obj->setTitle(ilUtil::stripSlashes($v));
201  $this->obj->setDescription(ilUtil::stripSlashes($_POST["desc"][$k]));
202  $this->obj->update();
203  }
204 
205  $this->obj_trans->addLanguage(ilUtil::stripSlashes($_POST["lang"][$k]),
207  ilUtil::stripSlashes($_POST["desc"][$k]),
208  $is_default
209  );
210  }
211  $this->obj_trans->save();
212 
213  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
214  $this->ctrl->redirect($this, "listTranslations");
215 
216  }
217 
222  {
223  foreach($_POST["title"] as $k => $v)
224  {
225  if ($_POST["check"][$k])
226  {
227  // default translation cannot be deleted
228  if($k != $_POST["default"])
229  {
230  unset($_POST["title"][$k]);
231  unset($_POST["desc"][$k]);
232  unset($_POST["lang"][$k]);
233  }
234  else
235  {
236  ilUtil::sendFailure($this->lng->txt("msg_no_default_language"));
237  $this->listTranslations();
238  return;
239  }
240  }
241  }
242  $this->saveTranslations();
243  }
244 
248 
253  {
254  global $tpl, $lng;
255 
256  ilUtil::sendInfo($lng->txt("obj_select_master_lang"));
257 
258  $form = $this->getMultiLangForm();
259  $tpl->setContent($form->getHTML());
260  }
261 
265  function getMultiLangForm($a_add = false)
266  {
267  global $tpl, $lng, $ilCtrl, $ilUser;
268 
269  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
270  $form = new ilPropertyFormGUI();
271 
272  // master language
273  if (!$a_add)
274  {
275  include_once("./Services/MetaData/classes/class.ilMDLanguageItem.php");
277  $si = new ilSelectInputGUI($lng->txt("obj_master_lang"), "master_lang");
278  $si->setOptions($options);
279  $si->setValue($ilUser->getLanguage());
280  $form->addItem($si);
281  }
282 
283  // additional languages
284  if ($a_add)
285  {
286  include_once("./Services/MetaData/classes/class.ilMDLanguageItem.php");
288  $options = array("" => $lng->txt("please_select")) + $options;
289  $si = new ilSelectInputGUI($lng->txt("obj_additional_langs"), "additional_langs");
290  $si->setOptions($options);
291  $si->setMulti(true);
292  $form->addItem($si);
293  }
294 
295  if ($a_add)
296  {
297  $form->setTitle($lng->txt("obj_add_languages"));
298  $form->addCommandButton("saveLanguages", $lng->txt("save"));
299  $form->addCommandButton("listTranslations", $lng->txt("cancel"));
300  }
301  else
302  {
303  if ($this->getTitleDescrOnlyMode())
304  {
305  $form->setTitle($lng->txt("obj_activate_content_lang"));
306  }
307  else
308  {
309  $form->setTitle($lng->txt("obj_activate_multilang"));
310  }
311  $form->addCommandButton("saveContentTranslationActivation", $lng->txt("save"));
312  $form->addCommandButton("listTranslations", $lng->txt("cancel"));
313  }
314  $form->setFormAction($ilCtrl->getFormAction($this));
315 
316  return $form;
317  }
318 
323  {
324  global $ilCtrl;
325 
326 // include_once("./Services/COPage/classes/class.ilPageMultiLang.php");
327 
328  $form = $this->getMultiLangForm();
329  if ($form->checkInput())
330  {
331  $ml = $form->getInput("master_lang");
332  $this->obj_trans->setMasterLanguage($ml);
333  $this->obj_trans->addLanguage($ml,
334  $this->obj->getTitle(),
335  $this->obj->getDescription(),
336  true
337  );
338  $this->obj_trans->setDefaultTitle($this->obj->getTitle());
339  $this->obj_trans->setDefaultDescription($this->obj->getDescription());
340  $this->obj_trans->save();
341  }
342 
343  $ilCtrl->redirect($this, "listTranslations");
344  }
345 
349 /*
350  function getMultiLangInfo($a_page_lang = "-")
351  {
352  global $lng;
353 
354  if ($a_page_lang == "")
355  {
356  $a_page_lang = "-";
357  }
358 
359  $lng->loadLanguageModule("meta");
360 
361  $tpl = new ilTemplate("tpl.page_multi_lang_info.html", true, true, "Services/COPage");
362  $tpl->setVariable("TXT_MASTER_LANG", $lng->txt("cont_master_lang"));
363  $tpl->setVariable("VAL_ML", $lng->txt("meta_l_".$this->ml->getMasterLanguage()));
364  $cl = ($a_page_lang == "-")
365  ? $this->ml->getMasterLanguage()
366  : $a_page_lang;
367  $tpl->setVariable("TXT_CURRENT_LANG", $lng->txt("cont_current_lang"));
368  $tpl->setVariable("VAL_CL", $lng->txt("meta_l_".$cl));
369  return $tpl->get();
370  }*/
371 
376  {
377  global $ilCtrl, $tpl, $lng;
378 
379  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
380  $cgui = new ilConfirmationGUI();
381  $cgui->setFormAction($ilCtrl->getFormAction($this));
382  if ($this->getTitleDescrOnlyMode())
383  {
384  $cgui->setHeaderText($lng->txt("obj_deactivate_content_transl_conf"));
385  }
386  else
387  {
388  $cgui->setHeaderText($lng->txt("obj_deactivate_multilang_conf"));
389  }
390 
391  $cgui->setCancel($lng->txt("cancel"), "listTranslations");
392  $cgui->setConfirm($lng->txt("confirm"), "deactivateContentMultiLang");
393  $tpl->setContent($cgui->getHTML());
394  }
395 
400  {
401  global $lng, $ilCtrl;
402 
403  if (!$this->getTitleDescrOnlyMode())
404  {
405  $this->obj_trans->setMasterLanguage("");
406  $this->obj_trans->setLanguages(array());
407  $this->obj_trans->save();
408  }
409  $this->obj_trans->deactivateContentTranslation();
410  if ($this->getTitleDescrOnlyMode())
411  {
412  ilUtil::sendSuccess($lng->txt("obj_cont_transl_deactivated"), true);
413  }
414  else
415  {
416  ilUtil::sendSuccess($lng->txt("obj_multilang_deactivated"), true);
417  }
418 
419 
420  $ilCtrl->redirect($this, "listTranslations");
421  }
422 
426  function addLanguages()
427  {
428  global $tpl;
429 
430  $form = $this->getMultiLangForm(true);
431  $tpl->setContent($form->getHTML());
432  }
433 
437  function saveLanguages()
438  {
439  global $ilCtrl, $lng;
440 
441  $form = $this->getMultiLangForm();
442  if ($form->checkInput())
443  {
444  $ad = $form->getInput("additional_langs");
445  if (is_array($ad))
446  {
447  $ml = $this->obj_trans->getMasterLanguage();
448  foreach ($ad as $l)
449  {
450  if ($l != $ml && $l != "")
451  {
452  $this->obj_trans->addLanguage($l, false, "", "");
453  }
454  }
455  }
456  }
457  $this->obj_trans->save();
458  ilUtil::sendInfo($lng->txt("msg_obj_modified"), true);
459  $ilCtrl->redirect($this, "listTranslations");
460  }
461 
466  {
467  global $ilCtrl, $tpl, $lng;
468 
469  $lng->loadLanguageModule("meta");
470 
471  if (!is_array($_POST["lang"]) || count($_POST["lang"]) == 0)
472  {
473  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
474  $ilCtrl->redirect($this, "listTranslations");
475  }
476  else
477  {
478  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
479  $cgui = new ilConfirmationGUI();
480  $cgui->setFormAction($ilCtrl->getFormAction($this));
481  $cgui->setHeaderText($lng->txt("obj_conf_delete_lang"));
482  $cgui->setCancel($lng->txt("cancel"), "listTranslations");
483  $cgui->setConfirm($lng->txt("remove"), "removeLanguages");
484 
485  foreach ($_POST["lang"] as $i)
486  {
487  $cgui->addItem("lang[]", $i, $lng->txt("meta_l_".$i));
488  }
489 
490  $tpl->setContent($cgui->getHTML());
491  }
492  }
493 
497  function removeLanguages()
498  {
499  global $lng, $ilCtrl;
500 
501  if (is_array($_POST["lang"]))
502  {
503  $langs = $this->obj_trans->getLanguages();
504  foreach ($langs as $k => $l)
505  {
506  if (in_array($l, $_POST["lang"]))
507  {
508  $this->obj_trans->removeLanguage();
509  }
510  }
511  $this->obj_trans->save();
512  ilUtil::sendInfo($lng->txt("msg_obj_modified"), true);
513  }
514  $ilCtrl->redirect($this, "listTranslations");
515  }
516 
517 
518 }
519 
520 ?>