ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjFileBasedLMAccess.php
Go to the documentation of this file.
1<?php
2
23{
24 protected ilObjUser $user;
25 protected ilLanguage $lng;
29 public static array $startfile = [];
30
31 public function __construct()
32 {
33 global $DIC;
34
35 $this->user = $DIC->user();
36 $this->lng = $DIC->language();
37 $this->rbacsystem = $DIC->rbac()->system();
38 $this->access = $DIC->access();
39 }
40
41 public function _checkAccess(string $cmd, string $permission, int $ref_id, int $obj_id, ?int $user_id = null): bool
42 {
44 $ilAccess = $this->access;
45
46 switch ($permission) {
47 case "read":
48
49 if (self::_determineStartUrl($obj_id) === "") {
51 return false;
52 }
53 break;
54 }
55 return true;
56 }
57
58 public static function _getCommands(): array
59 {
60 return [
61 [
62 "permission" => "read", "cmd" => "view", "lang_var" => "show",
63 "default" => true
64 ],
65 ["permission" => "write", "cmd" => "edit", "lang_var" => "edit_content"],
66 ["permission" => "write", "cmd" => "properties", "lang_var" => "settings"]
67 ];
68 }
69
70 //
71 // access relevant methods
72 //
73
74 public static function _determineStartUrl(int $a_id): string
75 {
76 global $DIC;
77
78 static $startfile = [];
79 if (isset($startfile[$a_id])) {
80 return $startfile[$a_id];
81 }
82
83 $ilDB = $DIC->database();
84
85 $q = "SELECT startfile, rid FROM file_based_lm WHERE id = " . $ilDB->quote($a_id, "integer");
86 $set = $ilDB->query($q);
87 $rec = $ilDB->fetchAssoc($set);
88 $start_file = $rec["startfile"] ?? '';
89
90 // Migrated learning module
91 if (!empty($rec['rid'])) {
92 // check if the file is available in the container
93 $rid = $DIC->resourceStorage()->manageContainer()->find($rec['rid']);
94 if (!$rid) {
95 return $startfile[$a_id] = "";
96 }
97 $zip = $DIC->resourceStorage()->consume()->containerZIP($rid)->getZIP();
98 foreach ($zip->getFiles() as $file) {
99 if ($file === $start_file) {
100 return $startfile[$a_id] = $start_file;
101 }
102 }
103 return $startfile[$a_id] = "";
104 }
105
106 // Old learning module
107 $dir = realpath(__DIR__ . '/../../../../public/' . ilFileUtils::getWebspaceDir() . "/lm_data/lm_" . $a_id);
108
109 if (($start_file !== "") && (is_file($dir . "/" . $start_file))) {
110 return $startfile[$a_id] = str_replace(
111 realpath(__DIR__ . '/../../../../public/'),
112 "",
113 $dir . "/" . $start_file
114 );
115 }
116
117 if (is_file($dir . "/index.html")) {
118 return $startfile[$a_id] = str_replace(
119 realpath(__DIR__ . '/../../../../public/'),
120 "",
121 $dir . "/index.html"
122 );
123 }
124
125 if (is_file($dir . "/index.htm")) {
126 return $startfile[$a_id] = str_replace(realpath(__DIR__ . '/../../../../public/'), "", $dir . "/index.htm");
127 }
128
129 return $startfile[$a_id] = "";
130 }
131
132 public static function _checkGoto(string $target): bool
133 {
134 global $DIC;
135
136 $ilAccess = $DIC->access();
137
138 $t_arr = explode("_", $target);
139
140 if ($t_arr[0] !== "htlm" || ((int) $t_arr[1]) <= 0) {
141 return false;
142 }
143
144 if ($ilAccess->checkAccess("visible", "", $t_arr[1]) ||
145 $ilAccess->checkAccess("read", "", $t_arr[1])) {
146 return true;
147 }
148 return false;
149 }
150
155 public static function _lookupDiskUsage(int $a_id): int
156 {
157 $lm_data_dir = ilFileUtils::getWebspaceDir('filesystem') . "/lm_data";
158 $lm_dir = $lm_data_dir . DIRECTORY_SEPARATOR . "lm_" . $a_id;
159
160 return file_exists($lm_dir) ? ilFileUtils::dirsize($lm_dir) : 0;
161 }
162
163 public static function _preloadData(array $obj_ids, array $ref_ids): void
164 {
165 global $DIC;
166
167 $ilDB = $DIC->database();
168
169 $q = "SELECT id, startfile FROM file_based_lm WHERE " .
170 $ilDB->in("id", $obj_ids, false, "integer");
171
172 $lm_set = $ilDB->query($q);
173 while ($rec = $ilDB->fetchAssoc($lm_set)) {
174 self::$startfile[$rec["id"]] = $rec["startfile"] . "";
175 }
176 }
177
178 public static function isInfoEnabled(int $obj_id): bool
179 {
181 $obj_id,
183 true
184 );
185 }
186}
return true
static _lookupContainerSetting(int $a_id, string $a_keyword, ?string $a_default_value=null)
static getWebspaceDir(string $mode="filesystem")
get webspace directory
static dirsize(string $directory)
get size of a directory or a file.
language handling
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _checkGoto(string $target)
check whether goto script will succeed
_checkAccess(string $cmd, string $permission, int $ref_id, int $obj_id, ?int $user_id=null)
Checks whether a user may invoke a command or not (this method is called by ilAccessHandler::checkAcc...
static _preloadData(array $obj_ids, array $ref_ids)
Preload data.
static _lookupDiskUsage(int $a_id)
Returns the number of bytes used on the harddisk by the learning module with the specified object id.
User class.
Class ilObjectAccess.
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
addInfoItem(string $a_type, string $a_text, string $a_data="")
add an info item to current info object
$ref_id
Definition: ltiauth.php:66
global $DIC
Definition: shib_login.php:26
$q
Definition: shib_logout.php:23
$lm_set