ILIAS  release_8 Revision v8.24
class.ilObjLanguageAccess.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
35{
36 protected static bool $cached_check_translate;
37
47 public static function _checkTranslate(): bool
48 {
49 global $DIC;
50 $lng = $DIC->language();
51 $ilSetting = $DIC->settings();
52 $ilUser = $DIC->user();
53 $rbacsystem = $DIC->rbac()->system();
54
55 if (isset(self::$cached_check_translate)) {
57 }
58
59 if (!$ilSetting->get("lang_translate_" . $lng->getLangKey())) {
60 self::$cached_check_translate = false;
62 }
63
64 if ($ilUser->getId()) {
66 self::$cached_check_translate = $rbacsystem->checkAccess("read,write", $ref_id);
67 } else {
68 self::$cached_check_translate = false;
69 }
70
72 }
73
74
81 public static function _checkMaintenance(): bool
82 {
83 global $DIC;
84 $ilSetting = $DIC->settings();
85 $ilUser = $DIC->user();
86 $rbacsystem = $DIC->rbac()->system();
87
88 if ($ilUser->getId()) {
90 return $rbacsystem->checkAccess("read,write", $ref_id);
91 }
92 return false;
93 }
94
95
101 public static function _lookupLangFolderRefId(): int
102 {
103 global $DIC;
104 $ilDB = $DIC->database();
105
106 $q = "SELECT ref_id FROM object_reference r, object_data d" .
107 " WHERE r.obj_id = d.obj_id AND d.type = " . $ilDB->quote("lngf", "text");
108 $set = $ilDB->query($q);
109 $row = $ilDB->fetchAssoc($set);
110 return (int) $row["ref_id"];
111 }
112
113
120 public static function _lookupId(string $a_key): int
121 {
122 global $DIC;
123 $ilDB = $DIC->database();
124
125 $q = "SELECT obj_id FROM object_data " .
126 " WHERE type = " . $ilDB->quote("lng", "text") .
127 " AND title = " . $ilDB->quote($a_key, "text");
128 $set = $ilDB->query($q);
129 $row = $ilDB->fetchAssoc($set);
130 return (int) $row["obj_id"];
131 }
132
133
139 public static function _getTranslationLink(): string
140 {
141 // ref id must be given to prevent params being deleted by ilAdministrtionGUI
142 return "ilias.php"
143 . "?ref_id=" . self::_lookupLangFolderRefId()
144 . "&baseClass=ilAdministrationGUI"
145 . "&cmdClass=ilobjlanguageextgui"
146 . "&view_mode=translate"
147 . "&reset_offset=true";
148 }
149
160 public static function _isPageTranslation(): bool
161 {
162 global $DIC;
163 $cmdClass = "";
164 $view_mode_get = "";
165 if ($DIC->http()->wrapper()->query()->has("cmdClass")) {
166 $cmdClass = $DIC->http()->wrapper()->query()->retrieve(
167 "cmdClass",
168 $DIC->refinery()->kindlyTo()->string()
169 );
170 }
171 if ($DIC->http()->wrapper()->query()->has("view_mode")) {
172 $view_mode_get = $DIC->http()->wrapper()->query()->retrieve(
173 "view_mode",
174 $DIC->refinery()->kindlyTo()->string()
175 );
176 }
177 return (strtolower($cmdClass) === "ilobjlanguageextgui" && $view_mode_get === "translate");
178 }
179
184 public static function _saveUsages(): void
185 {
186 global $DIC;
187 $lng = $DIC->language();
188
189 if (self::_checkTranslate() and !self::_isPageTranslation()) {
190 ilSession::set("lang_ext_maintenance", array("used_modules" => array_keys($lng->getUsedModules())));
191 ilSession::set("lang_ext_maintenance", array("used_topics" => array_keys($lng->getUsedTopics())));
192 }
193 }
194
200 public static function _getSavedModules(): array
201 {
202 $saved = [];
203 $lang_ext_maintenance_from_session = ilSession::get("lang_ext_maintenance");
204 if (is_array($lang_ext_maintenance_from_session) && isset($lang_ext_maintenance_from_session["used_modules"])) {
205 $saved = $lang_ext_maintenance_from_session["used_modules"];
206 }
207 return $saved;
208 }
209
215 public static function _getSavedTopics(): array
216 {
217 $saved = [];
218 $lang_ext_maintenance_from_session = ilSession::get("lang_ext_maintenance");
219 if (is_array($lang_ext_maintenance_from_session) && isset($lang_ext_maintenance_from_session["used_topics"])) {
220 $saved = $lang_ext_maintenance_from_session["used_topics"];
221 }
222 return $saved;
223 }
224}
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.
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
$ref_id
Definition: ltiauth.php:67
global $ilSetting
Definition: privfeed.php:17
$lng