ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjLanguageAccess.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
34{
35 protected static bool $cached_check_translate;
36
46 public static function _checkTranslate(): bool
47 {
48 global $DIC;
49 $lng = $DIC->language();
50 $ilSetting = $DIC->settings();
51 $ilUser = $DIC->user();
52 $rbacsystem = $DIC->rbac()->system();
53
54 if (isset(self::$cached_check_translate)) {
56 }
57
58 if (!$ilSetting->get("lang_translate_" . $lng->getLangKey())) {
59 self::$cached_check_translate = false;
61 }
62
63 if ($ilUser->getId()) {
65 self::$cached_check_translate = $rbacsystem->checkAccess("read,write", $ref_id);
66 } else {
67 self::$cached_check_translate = false;
68 }
69
71 }
72
73
80 public static function _checkMaintenance(): bool
81 {
82 global $DIC;
83 $ilSetting = $DIC->settings();
84 $ilUser = $DIC->user();
85 $rbacsystem = $DIC->rbac()->system();
86
87 if ($ilUser->getId()) {
89 return $rbacsystem->checkAccess("read,write", $ref_id);
90 }
91 return false;
92 }
93
94
100 public static function _lookupLangFolderRefId(): int
101 {
102 global $DIC;
103 $ilDB = $DIC->database();
104
105 $q = "SELECT ref_id FROM object_reference r, object_data d" .
106 " WHERE r.obj_id = d.obj_id AND d.type = " . $ilDB->quote("lngf", "text");
107 $set = $ilDB->query($q);
108 $row = $ilDB->fetchAssoc($set);
109 return (int) $row["ref_id"];
110 }
111
112
119 public static function _lookupId(string $a_key): int
120 {
121 global $DIC;
122 $ilDB = $DIC->database();
123
124 $q = "SELECT obj_id FROM object_data " .
125 " WHERE type = " . $ilDB->quote("lng", "text") .
126 " AND title = " . $ilDB->quote($a_key, "text");
127 $set = $ilDB->query($q);
128 $row = $ilDB->fetchAssoc($set);
129 return (int) $row["obj_id"];
130 }
131
132
138 public static function _getTranslationLink(): string
139 {
140 // ref id must be given to prevent params being deleted by ilAdministrtionGUI
141 return "ilias.php"
142 . "?ref_id=" . self::_lookupLangFolderRefId()
143 . "&baseClass=ilAdministrationGUI"
144 . "&cmdClass=ilobjlanguageextgui"
145 . "&view_mode=translate"
146 . "&reset_offset=true";
147 }
148
159 public static function _isPageTranslation(): bool
160 {
161 global $DIC;
162 $cmdClass = "";
163 $view_mode_get = "";
164 if ($DIC->http()->wrapper()->query()->has("cmdClass")) {
165 $cmdClass = $DIC->http()->wrapper()->query()->retrieve(
166 "cmdClass",
167 $DIC->refinery()->kindlyTo()->string()
168 );
169 }
170 if ($DIC->http()->wrapper()->query()->has("view_mode")) {
171 $view_mode_get = $DIC->http()->wrapper()->query()->retrieve(
172 "view_mode",
173 $DIC->refinery()->kindlyTo()->string()
174 );
175 }
176 return (strtolower($cmdClass) === "ilobjlanguageextgui" && $view_mode_get === "translate");
177 }
178
183 public static function _saveUsages(): void
184 {
185 global $DIC;
186 $lng = $DIC->language();
187
188 if (self::_checkTranslate() and !self::_isPageTranslation()) {
189 ilSession::set("lang_ext_maintenance", array("used_modules" => array_keys($lng->getUsedModules())));
190 ilSession::set("lang_ext_maintenance", array("used_topics" => array_keys($lng->getUsedTopics())));
191 }
192 }
193
199 public static function _getSavedModules(): array
200 {
201 $saved = [];
202 $lang_ext_maintenance_from_session = ilSession::get("lang_ext_maintenance");
203 if (is_array($lang_ext_maintenance_from_session) && isset($lang_ext_maintenance_from_session["used_modules"])) {
204 $saved = $lang_ext_maintenance_from_session["used_modules"];
205 }
206 return $saved;
207 }
208
214 public static function _getSavedTopics(): array
215 {
216 $saved = [];
217 $lang_ext_maintenance_from_session = ilSession::get("lang_ext_maintenance");
218 if (is_array($lang_ext_maintenance_from_session) && isset($lang_ext_maintenance_from_session["used_topics"])) {
219 $saved = $lang_ext_maintenance_from_session["used_topics"];
220 }
221 return $saved;
222 }
223}
static _lookupId(string $a_key)
Lookup the object ID for a language key.
static _getSavedTopics()
Get the stored topics from the user session.
static _getSavedModules()
Get the stored modules from the user session.
static _saveUsages()
Store the collected language variable usages in the user session This should be called as late as pos...
static _checkMaintenance()
Permission check for language maintenance (import/export)
static _lookupLangFolderRefId()
Lookup the ref_id of the global language folder.
static _checkTranslate()
Permission check for translations.
static _isPageTranslation()
Check if the current request is a page translation.
static _getTranslationLink()
Get the link to translate the current page.
static get(string $a_var)
static set(string $a_var, $a_val)
Set a value.
$ref_id
Definition: ltiauth.php:66
global $lng
Definition: privfeed.php:31
global $ilSetting
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26
$q
Definition: shib_logout.php:23