ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilTranslationGUI Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilTranslationGUI:

Public Member Functions

 __construct (object $ilObjOrgUnitGUI)
 
 executeCommand ()
 
 editTranslations (bool $a_get_post_values=false, bool $a_add=false)
 
 saveTranslations ()
 Save title and translations. More...
 
 addTranslation ()
 Add a translation. More...
 
 deleteTranslations ()
 Remove translation. More...
 

Data Fields

ilGlobalTemplateInterface $tpl
 

Protected Attributes

ilCtrl $ctrl
 
ilAccessHandler $ilAccess
 
ilLanguage $lng
 
object $parent_gui
 
object $object
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Class ilTranslationGUI Based on methods of ilObjCategoryGUI

Author
Oskar Truffer ot@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch
Martin Studer ms@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch

Definition at line 26 of file class.ilTranslationGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilTranslationGUI::__construct ( object  $ilObjOrgUnitGUI)

Definition at line 35 of file class.ilTranslationGUI.php.

References $DIC, $ilAccess, ilRBACAccessHandler\checkAccess(), ILIAS\Repository\ctrl(), and ILIAS\Repository\lng().

36  {
37  global $DIC;
38  $main_tpl = $DIC->ui()->mainTemplate();
39 
40  $ilAccess = $DIC['ilAccess'];
41  $this->tpl = $DIC->ui()->mainTemplate();
42  $this->ctrl = $DIC->ctrl();
43  $this->lng = $DIC->language();
44  $this->parent_gui = $ilObjOrgUnitGUI;
45  $this->object = $ilObjOrgUnitGUI->getObject();
46  $this->ilAccess = $ilAccess;
47 
48  if (!$ilAccess->checkAccess('write', '', $this->object->getRefId())) {
49  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("permission_denied"), true);
50  $this->ctrl->redirect($this->parent_gui, "");
51  }
52  }
checkAccess(string $a_permission, string $a_cmd, int $a_ref_id, string $a_type="", ?int $a_obj_id=null, ?int $a_tree_id=null)
check access for an object (provide $a_type and $a_obj_id if available for better performance) ...
global $DIC
Definition: feed.php:28
ilAccessHandler $ilAccess
+ Here is the call graph for this function:

Member Function Documentation

◆ addTranslation()

ilTranslationGUI::addTranslation ( )

Add a translation.

Definition at line 144 of file class.ilTranslationGUI.php.

References editTranslations().

144  : void
145  {
146  if ($_POST["title"]) {
147  $k = max(array_keys($_POST["title"]));
148  $k++;
149  $_POST["title"][$k] = "";
150  $this->editTranslations(true);
151  } else {
152  $this->editTranslations(false, true);
153  }
154  }
editTranslations(bool $a_get_post_values=false, bool $a_add=false)
+ Here is the call graph for this function:

◆ deleteTranslations()

ilTranslationGUI::deleteTranslations ( )

Remove translation.

Definition at line 159 of file class.ilTranslationGUI.php.

References editTranslations(), ILIAS\Repository\lng(), and saveTranslations().

159  : void
160  {
161  foreach ($_POST["title"] as $k => $v) {
162  if ($_POST["check"][$k]) {
163  // default translation cannot be deleted
164  if ($k != $_POST["default"]) {
165  unset($_POST["title"][$k]);
166  unset($_POST["desc"][$k]);
167  unset($_POST["lang"][$k]);
168  } else {
169  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("msg_no_default_language"));
170 
171  $this->editTranslations();
172  }
173  }
174  }
175  $this->saveTranslations();
176  }
saveTranslations()
Save title and translations.
editTranslations(bool $a_get_post_values=false, bool $a_add=false)
+ Here is the call graph for this function:

◆ editTranslations()

ilTranslationGUI::editTranslations ( bool  $a_get_post_values = false,
bool  $a_add = false 
)

Definition at line 60 of file class.ilTranslationGUI.php.

References $data, ILIAS\Repository\lng(), and ILIAS\Repository\object().

Referenced by addTranslation(), deleteTranslations(), and saveTranslations().

60  : void
61  {
62  $this->lng->loadLanguageModule($this->object->getType());
63 
64  $table = new ilObjectTranslationTableGUI(
65  $this,
66  "editTranslations",
67  true,
68  "Translation"
69  );
70  if ($a_get_post_values) {
71  $vals = array();
72  foreach ($_POST["title"] as $k => $v) {
73  $vals[] = array(
74  "title" => $v,
75  "desc" => $_POST["desc"][$k],
76  "lang" => $_POST["lang"][$k],
77  "default" => ($_POST["default"] == $k),
78  );
79  }
80  $table->setData($vals);
81  } else {
82  $data = $this->object->getTranslations();
83  if ($a_add) {
84  $data[]["title"] = "";
85  }
86  $table->setData($data);
87  }
88  $this->tpl->setContent($table->getHTML());
89  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ executeCommand()

ilTranslationGUI::executeCommand ( )

Definition at line 54 of file class.ilTranslationGUI.php.

References ILIAS\Repository\ctrl().

54  : void
55  {
56  $cmd = $this->ctrl->getCmd();
57  $this->$cmd();
58  }
+ Here is the call graph for this function:

◆ saveTranslations()

ilTranslationGUI::saveTranslations ( )

Save title and translations.

Definition at line 94 of file class.ilTranslationGUI.php.

References ILIAS\Repository\ctrl(), editTranslations(), ILIAS\Repository\lng(), and ilUtil\stripSlashes().

Referenced by deleteTranslations().

94  : void
95  {
96  // default language set?
97  if (!isset($_POST["default"])) {
98  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("msg_no_default_language"));
99  $this->editTranslations(true);
100  }
101 
102  // all languages set?
103  if (array_key_exists("", $_POST["lang"])) {
104  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("msg_no_language_selected"));
105  $this->editTranslations(true);
106  }
107 
108  // no single language is selected more than once?
109  if (count(array_unique($_POST["lang"])) < count($_POST["lang"])) {
110  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("msg_multi_language_selected"));
111 
112  $this->editTranslations(true);
113  }
114 
115  // save the stuff
116  $this->object->removeTranslations();
117  foreach ($_POST["title"] as $k => $v) {
118  $translations = $this->object->getTranslations();
119 
120  if (array_key_exists($_POST["lang"][$k], $translations)) {
121  $this->object->updateTranslation(
123  ilUtil::stripSlashes($_POST["desc"][$k]),
124  ilUtil::stripSlashes($_POST["lang"][$k]),
125  ($_POST["default"] == $k) ? 1 : 0
126  );
127  } else {
128  $this->object->addTranslation(
130  ilUtil::stripSlashes($_POST["desc"][$k]),
131  ilUtil::stripSlashes($_POST["lang"][$k]),
132  ($_POST["default"] == $k) ? 1 : 0
133  );
134  }
135  }
136 
137  $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
138  $this->ctrl->redirect($this, "editTranslations");
139  }
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
editTranslations(bool $a_get_post_values=false, bool $a_add=false)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $ctrl

ilCtrl ilTranslationGUI::$ctrl
protected

Definition at line 28 of file class.ilTranslationGUI.php.

◆ $ilAccess

ilAccessHandler ilTranslationGUI::$ilAccess
protected

Definition at line 30 of file class.ilTranslationGUI.php.

Referenced by __construct().

◆ $lng

ilLanguage ilTranslationGUI::$lng
protected

Definition at line 31 of file class.ilTranslationGUI.php.

◆ $object

object ilTranslationGUI::$object
protected

Definition at line 33 of file class.ilTranslationGUI.php.

◆ $parent_gui

object ilTranslationGUI::$parent_gui
protected

Definition at line 32 of file class.ilTranslationGUI.php.

◆ $tpl

ilGlobalTemplateInterface ilTranslationGUI::$tpl

Definition at line 29 of file class.ilTranslationGUI.php.


The documentation for this class was generated from the following file: