ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilMultilingualismGUI.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 
15 {
19  protected $lng;
20 
24  protected $ctrl;
25 
29  protected $tpl;
30 
34  protected $toolbar;
35 
39  protected $user;
40 
41  protected $obj_trans;
42  protected $title_descr_only = true;
43  protected $start_title = "";
44  protected $start_description = "";
45 
51  public function __construct($a_obj_id, $a_type)
52  {
53  global $DIC;
54 
55  $this->toolbar = $DIC->toolbar();
56  $this->user = $DIC->user();
57  $lng = $DIC->language();
58  $ilCtrl = $DIC->ctrl();
59  $tpl = $DIC["tpl"];
60 
61  $this->lng = $lng;
62  $this->ctrl = $ilCtrl;
63  $this->tpl = $tpl;
64 
65  include_once("./Services/Multilingualism/classes/class.ilMultilingualism.php");
66  $this->obj_trans = ilMultilingualism::getInstance($a_obj_id, $a_type);
67  }
68 
74  public function setTitleDescrOnlyMode($a_val)
75  {
76  $this->title_descr_only = $a_val;
77  }
78 
84  public function getTitleDescrOnlyMode()
85  {
87  }
88 
92  public function executeCommand()
93  {
94  $next_class = $this->ctrl->getNextClass($this);
95 
96  switch ($next_class) {
97  default:
98  $cmd = $this->ctrl->getCmd("listTranslations");
99  if (in_array($cmd, array("listTranslations", "saveTranslations",
100  "addTranslation", "deleteTranslations", "activateContentMultilinguality",
101  "confirmRemoveLanguages", "removeLanguages", "confirmDeactivateContentMultiLang", "saveLanguages",
102  "saveContentTranslationActivation", "deactivateContentMultiLang", "addLanguages"))) {
103  $this->$cmd();
104  }
105  break;
106  }
107  }
108 
112  public function listTranslations($a_get_post_values = false, $a_add = false)
113  {
114  $this->lng->loadLanguageModule("translation");
115 
116 
117  $this->addToolbar();
118 
119  include_once("./Services/Multilingualism/classes/class.ilMultilingualismTableGUI.php");
121  $this,
122  "listTranslations",
123  true,
124  "Translation"
125  );
126  if ($a_get_post_values) {
127  $vals = array();
128  foreach ($_POST["title"] as $k => $v) {
129  $vals[] = array("title" => $v,
130  "desc" => $_POST["desc"][$k],
131  "lang" => $_POST["lang"][$k],
132  "default" => ($_POST["default"] == $k));
133  }
134  $table->setData($vals);
135  } else {
136  $data = $this->obj_trans->getLanguages();
137  foreach ($data as $k => $v) {
138  $data[$k]["default"] = $v["lang_default"];
139  $data[$k]["desc"] = $v["description"];
140  $data[$k]["lang"] = $v["lang_code"];
141  }
142  if ($a_add) {
143  $data["Fobject"][++$k]["title"] = "";
144  }
145  $table->setData($data);
146  }
147  $this->tpl->setContent($table->getHTML());
148  }
149 
150  public function addToolbar()
151  {
152  $ilToolbar = $this->toolbar;
153  if ($this->getTitleDescrOnlyMode()) {
154  $ilToolbar->addButton(
155  $this->lng->txt("obj_add_languages"),
156  $this->ctrl->getLinkTarget($this, "addLanguages")
157  );
158  }
159  }
160 
164  public function saveTranslations()
165  {
166  // default language set?
167  if (!isset($_POST["default"])) {
168  ilUtil::sendFailure($this->lng->txt("msg_no_default_language"));
169  $this->listTranslations(true);
170  return;
171  }
172 
173  // all languages set?
174  if (array_key_exists("", $_POST["lang"])) {
175  ilUtil::sendFailure($this->lng->txt("msg_no_language_selected"));
176  $this->listTranslations(true);
177  return;
178  }
179 
180  // no single language is selected more than once?
181  if (count(array_unique($_POST["lang"])) < count($_POST["lang"])) {
182  ilUtil::sendFailure($this->lng->txt("msg_multi_language_selected"));
183  $this->listTranslations(true);
184  return;
185  }
186 
187  // save the stuff
188  $this->obj_trans->setLanguages(array());
189 
190  foreach ($_POST["title"] as $k => $v) {
191  // update object data if default
192  $is_default = ($_POST["default"] == $k);
193 
194  $this->obj_trans->addLanguage(
195  ilUtil::stripSlashes($_POST["lang"][$k]),
197  ilUtil::stripSlashes($_POST["desc"][$k]),
198  $is_default
199  );
200  }
201  $this->obj_trans->save();
202 
203  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
204  $this->ctrl->redirect($this, "listTranslations");
205  }
206 
210  public function deleteTranslations()
211  {
212  foreach ($_POST["title"] as $k => $v) {
213  if ($_POST["check"][$k]) {
214  // default translation cannot be deleted
215  if ($k != $_POST["default"]) {
216  unset($_POST["title"][$k]);
217  unset($_POST["desc"][$k]);
218  unset($_POST["lang"][$k]);
219  } else {
220  ilUtil::sendFailure($this->lng->txt("msg_no_default_language"));
221  $this->listTranslations();
222  return;
223  }
224  }
225  }
226  $this->saveTranslations();
227  }
228 
232 
236  public function getMultiLangForm($a_add = false)
237  {
238  $tpl = $this->tpl;
239  $lng = $this->lng;
242 
243  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
244  $form = new ilPropertyFormGUI();
245 
246  // master language
247  if (!$a_add) {
248  include_once("./Services/MetaData/classes/class.ilMDLanguageItem.php");
250  $si = new ilSelectInputGUI($lng->txt("obj_master_lang"), "master_lang");
251  $si->setOptions($options);
252  $si->setValue($ilUser->getLanguage());
253  $form->addItem($si);
254  }
255 
256  // additional languages
257  if ($a_add) {
258  include_once("./Services/MetaData/classes/class.ilMDLanguageItem.php");
260  $options = array("" => $lng->txt("please_select")) + $options;
261  $si = new ilSelectInputGUI($lng->txt("obj_additional_langs"), "additional_langs");
262  $si->setOptions($options);
263  $si->setMulti(true);
264  $form->addItem($si);
265  }
266 
267  if ($a_add) {
268  $form->setTitle($lng->txt("obj_add_languages"));
269  $form->addCommandButton("saveLanguages", $lng->txt("save"));
270  $form->addCommandButton("listTranslations", $lng->txt("cancel"));
271  } else {
272  if ($this->getTitleDescrOnlyMode()) {
273  $form->setTitle($lng->txt("obj_activate_content_lang"));
274  } else {
275  $form->setTitle($lng->txt("obj_activate_multilang"));
276  }
277  $form->addCommandButton("saveContentTranslationActivation", $lng->txt("save"));
278  $form->addCommandButton("listTranslations", $lng->txt("cancel"));
279  }
280  $form->setFormAction($ilCtrl->getFormAction($this));
281 
282  return $form;
283  }
284 
289  {
291  $tpl = $this->tpl;
292  $lng = $this->lng;
293 
294  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
295  $cgui = new ilConfirmationGUI();
296  $cgui->setFormAction($ilCtrl->getFormAction($this));
297  if ($this->getTitleDescrOnlyMode()) {
298  $cgui->setHeaderText($lng->txt("obj_deactivate_content_transl_conf"));
299  } else {
300  $cgui->setHeaderText($lng->txt("obj_deactivate_multilang_conf"));
301  }
302 
303  $cgui->setCancel($lng->txt("cancel"), "listTranslations");
304  $cgui->setConfirm($lng->txt("confirm"), "deactivateContentMultiLang");
305  $tpl->setContent($cgui->getHTML());
306  }
307 
311  public function addLanguages(ilPropertyFormGUI $form = null)
312  {
313  $tpl = $this->tpl;
314 
315  if (!$form instanceof ilPropertyFormGUI) {
316  $form = $this->getMultiLangForm(true);
317  }
318  $tpl->setContent($form->getHTML());
319  }
320 
324  public function saveLanguages()
325  {
327  $lng = $this->lng;
328 
329  ilLoggerFactory::getLogger('otpl')->debug('Save languages');
330 
331  $form = $this->getMultiLangForm(true);
332  if ($form->checkInput()) {
333  $ad = $form->getInput("additional_langs");
334 
335  ilLoggerFactory::getLogger('otpl')->dump($ad);
336 
337  if (is_array($ad)) {
338  foreach ($ad as $l) {
339  if ($l != "") {
340  $std = false;
341 
342  //if no other language is set, set this one as standard
343  if (!count($this->obj_trans->getLanguages())) {
344  $std = true;
345  }
346 
347  $this->obj_trans->addLanguage($l, $this->start_title, $this->start_description, $std);
348  }
349  }
350  }
351  $this->obj_trans->save();
352  ilUtil::sendInfo($lng->txt("msg_obj_modified"), true);
353  $ilCtrl->redirect($this, "listTranslations");
354  } else {
355  $form->setValuesByPost();
356  ilUtil::sendFailure($lng->txt('err_check_input'));
357  $this->addLanguages($form);
358  }
359  }
360 
364  public function confirmRemoveLanguages()
365  {
367  $tpl = $this->tpl;
368  $lng = $this->lng;
369 
370  $lng->loadLanguageModule("meta");
371 
372  if (!is_array($_POST["lang"]) || count($_POST["lang"]) == 0) {
373  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
374  $ilCtrl->redirect($this, "listTranslations");
375  } else {
376  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
377  $cgui = new ilConfirmationGUI();
378  $cgui->setFormAction($ilCtrl->getFormAction($this));
379  $cgui->setHeaderText($lng->txt("obj_conf_delete_lang"));
380  $cgui->setCancel($lng->txt("cancel"), "listTranslations");
381  $cgui->setConfirm($lng->txt("remove"), "removeLanguages");
382 
383  foreach ($_POST["lang"] as $i) {
384  $cgui->addItem("lang[]", $i, $lng->txt("meta_l_" . $i));
385  }
386 
387  $tpl->setContent($cgui->getHTML());
388  }
389  }
390 
394  public function removeLanguages()
395  {
396  $lng = $this->lng;
398 
399  if (is_array($_POST["lang"])) {
400  $langs = $this->obj_trans->getLanguages();
401  foreach ($langs as $k => $l) {
402  if (in_array($l, $_POST["lang"])) {
403  $this->obj_trans->removeLanguage();
404  }
405  }
406  $this->obj_trans->save();
407  ilUtil::sendInfo($lng->txt("msg_obj_modified"), true);
408  }
409  $ilCtrl->redirect($this, "listTranslations");
410  }
411 
416  public function setStartValues($a_title, $a_description)
417  {
418  $this->start_title = $a_title;
419  $this->start_description = $a_description;
420  }
421 }
GUI class for object translation handling.
static getInstance($a_obj_id, $a_type)
Get instance.
saveTranslations()
Save translations.
This class represents a selection list property in a property form.
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
user()
Definition: user.php:4
getTitleDescrOnlyMode()
Get enable title/description only mode.
global $ilCtrl
Definition: ilias.php:18
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$a_type
Definition: workflow.php:92
if(isset($_POST['submit'])) $form
confirmDeactivateContentMultiLang()
Confirm page translation creation.
deleteTranslations()
Remove translation.
TableGUI class for title/description translations.
$ilUser
Definition: imgupload.php:18
setStartValues($a_title, $a_description)
listTranslations($a_get_post_values=false, $a_add=false)
List translations.
setTitleDescrOnlyMode($a_val)
Set enable title/description only mode.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
setOptions($a_options)
Set Options.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
addLanguages(ilPropertyFormGUI $form=null)
Add language.
removeLanguages()
Remove languages.
confirmRemoveLanguages()
Confirm remove languages.
getMultiLangForm($a_add=false)
Get multi language form.
global $l
Definition: afr.php:30
$i
Definition: disco.tpl.php:19
static getLogger($a_component_id)
Get component logger.
if(empty($password)) $table
Definition: pwgen.php:24
$_POST["username"]
__construct($a_obj_id, $a_type)
ilTranslationGUI constructor.
Confirmation screen class.
$data
Definition: bench.php:6