ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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{
16 protected $obj_trans;
17 protected $title_descr_only = true;
18 protected $start_title = "";
19 protected $start_description = "";
20
26 function __construct($a_obj_id, $a_type)
27 {
28 global $lng, $ilCtrl, $tpl;
29
30 $this->lng = $lng;
31 $this->ctrl = $ilCtrl;
32 $this->tpl = $tpl;
33
34 include_once("./Services/Multilingualism/classes/class.ilMultilingualism.php");
35 $this->obj_trans = ilMultilingualism::getInstance($a_obj_id, $a_type);
36 }
37
43 function setTitleDescrOnlyMode($a_val)
44 {
45 $this->title_descr_only = $a_val;
46 }
47
54 {
56 }
57
61 function executeCommand()
62 {
63 $next_class = $this->ctrl->getNextClass($this);
64
65 switch ($next_class)
66 {
67 default:
68 $cmd = $this->ctrl->getCmd("listTranslations");
69 if (in_array($cmd, array("listTranslations", "saveTranslations",
70 "addTranslation", "deleteTranslations", "activateContentMultilinguality",
71 "confirmRemoveLanguages", "removeLanguages", "confirmDeactivateContentMultiLang", "saveLanguages",
72 "saveContentTranslationActivation", "deactivateContentMultiLang", "addLanguages")))
73 {
74 $this->$cmd();
75 }
76 break;
77 }
78 }
79
83 function listTranslations($a_get_post_values = false, $a_add = false)
84 {
85 $this->lng->loadLanguageModule("translation");
86
87
88 $this->addToolbar();
89
90 include_once("./Services/Multilingualism/classes/class.ilMultilingualismTableGUI.php");
91 $table = new ilMultilingualismTableGUI($this, "listTranslations", true,
92 "Translation");
93 if ($a_get_post_values)
94 {
95 $vals = array();
96 foreach($_POST["title"] as $k => $v)
97 {
98 $vals[] = array("title" => $v,
99 "desc" => $_POST["desc"][$k],
100 "lang" => $_POST["lang"][$k],
101 "default" => ($_POST["default"] == $k));
102 }
103 $table->setData($vals);
104 }
105 else
106 {
107 $data = $this->obj_trans->getLanguages();
108 foreach($data as $k => $v)
109 {
110 $data[$k]["default"] = $v["lang_default"];
111 $data[$k]["desc"] = $v["description"];
112 $data[$k]["lang"] = $v["lang_code"];
113 }
114 if($a_add)
115 {
116 $data["Fobject"][++$k]["title"] = "";
117 }
118 $table->setData($data);
119 }
120 $this->tpl->setContent($table->getHTML());
121
122 }
123
124 function addToolbar()
125 {
126 global $ilToolbar;
127 if ($this->getTitleDescrOnlyMode())
128 {
129 $ilToolbar->addButton($this->lng->txt("obj_add_languages"),
130 $this->ctrl->getLinkTarget($this, "addLanguages"));
131 }
132 }
133
138 {
139 // default language set?
140 if (!isset($_POST["default"]))
141 {
142 ilUtil::sendFailure($this->lng->txt("msg_no_default_language"));
143 $this->listTranslations(true);
144 return;
145 }
146
147 // all languages set?
148 if (array_key_exists("",$_POST["lang"]))
149 {
150 ilUtil::sendFailure($this->lng->txt("msg_no_language_selected"));
151 $this->listTranslations(true);
152 return;
153 }
154
155 // no single language is selected more than once?
156 if (count(array_unique($_POST["lang"])) < count($_POST["lang"]))
157 {
158 ilUtil::sendFailure($this->lng->txt("msg_multi_language_selected"));
159 $this->listTranslations(true);
160 return;
161 }
162
163 // save the stuff
164 $this->obj_trans->setLanguages(array());
165
166 foreach($_POST["title"] as $k => $v)
167 {
168 // update object data if default
169 $is_default = ($_POST["default"] == $k);
170
171 $this->obj_trans->addLanguage(ilUtil::stripSlashes($_POST["lang"][$k]),
173 ilUtil::stripSlashes($_POST["desc"][$k]),
174 $is_default
175 );
176 }
177 $this->obj_trans->save();
178
179 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
180 $this->ctrl->redirect($this, "listTranslations");
181
182 }
183
188 {
189 foreach($_POST["title"] as $k => $v)
190 {
191 if ($_POST["check"][$k])
192 {
193 // default translation cannot be deleted
194 if($k != $_POST["default"])
195 {
196 unset($_POST["title"][$k]);
197 unset($_POST["desc"][$k]);
198 unset($_POST["lang"][$k]);
199 }
200 else
201 {
202 ilUtil::sendFailure($this->lng->txt("msg_no_default_language"));
203 $this->listTranslations();
204 return;
205 }
206 }
207 }
208 $this->saveTranslations();
209 }
210
214
218 function getMultiLangForm($a_add = false)
219 {
220 global $tpl, $lng, $ilCtrl, $ilUser;
221
222 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
223 $form = new ilPropertyFormGUI();
224
225 // master language
226 if (!$a_add)
227 {
228 include_once("./Services/MetaData/classes/class.ilMDLanguageItem.php");
230 $si = new ilSelectInputGUI($lng->txt("obj_master_lang"), "master_lang");
231 $si->setOptions($options);
232 $si->setValue($ilUser->getLanguage());
233 $form->addItem($si);
234 }
235
236 // additional languages
237 if ($a_add)
238 {
239 include_once("./Services/MetaData/classes/class.ilMDLanguageItem.php");
241 $options = array("" => $lng->txt("please_select")) + $options;
242 $si = new ilSelectInputGUI($lng->txt("obj_additional_langs"), "additional_langs");
243 $si->setOptions($options);
244 $si->setMulti(true);
245 $form->addItem($si);
246 }
247
248 if ($a_add)
249 {
250 $form->setTitle($lng->txt("obj_add_languages"));
251 $form->addCommandButton("saveLanguages", $lng->txt("save"));
252 $form->addCommandButton("listTranslations", $lng->txt("cancel"));
253 }
254 else
255 {
256 if ($this->getTitleDescrOnlyMode())
257 {
258 $form->setTitle($lng->txt("obj_activate_content_lang"));
259 }
260 else
261 {
262 $form->setTitle($lng->txt("obj_activate_multilang"));
263 }
264 $form->addCommandButton("saveContentTranslationActivation", $lng->txt("save"));
265 $form->addCommandButton("listTranslations", $lng->txt("cancel"));
266 }
267 $form->setFormAction($ilCtrl->getFormAction($this));
268
269 return $form;
270 }
271
276 {
277 global $ilCtrl, $tpl, $lng;
278
279 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
280 $cgui = new ilConfirmationGUI();
281 $cgui->setFormAction($ilCtrl->getFormAction($this));
282 if ($this->getTitleDescrOnlyMode())
283 {
284 $cgui->setHeaderText($lng->txt("obj_deactivate_content_transl_conf"));
285 }
286 else
287 {
288 $cgui->setHeaderText($lng->txt("obj_deactivate_multilang_conf"));
289 }
290
291 $cgui->setCancel($lng->txt("cancel"), "listTranslations");
292 $cgui->setConfirm($lng->txt("confirm"), "deactivateContentMultiLang");
293 $tpl->setContent($cgui->getHTML());
294 }
295
299 function addLanguages(ilPropertyFormGUI $form = null)
300 {
301 global $tpl;
302
303 if(!$form instanceof ilPropertyFormGUI)
304 {
305 $form = $this->getMultiLangForm(true);
306 }
307 $tpl->setContent($form->getHTML());
308 }
309
313 function saveLanguages()
314 {
315 global $ilCtrl, $lng;
316
317 ilLoggerFactory::getLogger('otpl')->debug('Save languages');
318
319 $form = $this->getMultiLangForm(true);
320 if($form->checkInput())
321 {
322 $ad = $form->getInput("additional_langs");
323
324 ilLoggerFactory::getLogger('otpl')->dump($ad);
325
326 if (is_array($ad))
327 {
328
329 foreach ($ad as $l)
330 {
331 if ($l != "")
332 {
333 $std = false;
334
335 //if no other language is set, set this one as standard
336 if(!count($this->obj_trans->getLanguages()))
337 {
338 $std = true;
339 }
340
341 $this->obj_trans->addLanguage($l, $this->start_title, $this->start_description,$std);
342 }
343 }
344 }
345 $this->obj_trans->save();
346 ilUtil::sendInfo($lng->txt("msg_obj_modified"), true);
347 $ilCtrl->redirect($this, "listTranslations");
348 }
349 else
350 {
351 $form->setValuesByPost();
352 ilUtil::sendFailure($lng->txt('err_check_input'));
353 $this->addLanguages($form);
354 }
355
356 }
357
362 {
363 global $ilCtrl, $tpl, $lng;
364
365 $lng->loadLanguageModule("meta");
366
367 if (!is_array($_POST["lang"]) || count($_POST["lang"]) == 0)
368 {
369 ilUtil::sendInfo($lng->txt("no_checkbox"), true);
370 $ilCtrl->redirect($this, "listTranslations");
371 }
372 else
373 {
374 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
375 $cgui = new ilConfirmationGUI();
376 $cgui->setFormAction($ilCtrl->getFormAction($this));
377 $cgui->setHeaderText($lng->txt("obj_conf_delete_lang"));
378 $cgui->setCancel($lng->txt("cancel"), "listTranslations");
379 $cgui->setConfirm($lng->txt("remove"), "removeLanguages");
380
381 foreach ($_POST["lang"] as $i)
382 {
383 $cgui->addItem("lang[]", $i, $lng->txt("meta_l_".$i));
384 }
385
386 $tpl->setContent($cgui->getHTML());
387 }
388 }
389
394 {
395 global $lng, $ilCtrl;
396
397 if (is_array($_POST["lang"]))
398 {
399 $langs = $this->obj_trans->getLanguages();
400 foreach ($langs as $k => $l)
401 {
402 if (in_array($l, $_POST["lang"]))
403 {
404 $this->obj_trans->removeLanguage();
405 }
406 }
407 $this->obj_trans->save();
408 ilUtil::sendInfo($lng->txt("msg_obj_modified"), true);
409 }
410 $ilCtrl->redirect($this, "listTranslations");
411 }
412
417 public function setStartValues($a_title, $a_description)
418 {
419 $this->start_title = $a_title;
420 $this->start_description = $a_description;
421 }
422
423
424}
425
426?>
global $tpl
Definition: ilias.php:8
global $l
Definition: afr.php:30
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Confirmation screen class.
static getLogger($a_component_id)
Get component logger.
GUI class for object translation handling.
getMultiLangForm($a_add=false)
Get multi language form.
saveTranslations()
Save translations.
confirmDeactivateContentMultiLang()
Confirm page translation creation.
confirmRemoveLanguages()
Confirm remove languages.
__construct($a_obj_id, $a_type)
ilTranslationGUI constructor.
listTranslations($a_get_post_values=false, $a_add=false)
List translations.
deleteTranslations()
Remove translation.
addLanguages(ilPropertyFormGUI $form=null)
Add language.
getTitleDescrOnlyMode()
Get enable title/description only mode.
setStartValues($a_title, $a_description)
setTitleDescrOnlyMode($a_val)
Set enable title/description only mode.
TableGUI class for title/description translations.
static getInstance($a_obj_id, $a_type)
Get instance.
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.
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:17
$cmd
Definition: sahs_server.php:35
if(!is_array($argv)) $options
$ilUser
Definition: imgupload.php:18
$a_type
Definition: workflow.php:93