ILIAS  release_8 Revision v8.24
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 $ilDB = $DIC->database();
79
80 if (isset(self::$startfile[$a_id])) {
81 $start_file = self::$startfile[$a_id];
82 } else {
83 $q = "SELECT startfile FROM file_based_lm WHERE id = " . $ilDB->quote($a_id, "integer");
84 $set = $ilDB->query($q);
85 $rec = $ilDB->fetchAssoc($set);
86 $start_file = $rec["startfile"];
87 self::$startfile[$a_id] = $start_file . "";
88 }
89
90 $dir = ilFileUtils::getWebspaceDir() . "/lm_data/lm_" . $a_id;
91
92 if (($start_file !== "") &&
93 (is_file($dir . "/" . $start_file))) {
94 return "./" . $dir . "/" . $start_file;
95 } elseif (is_file($dir . "/index.html")) {
96 return "./" . $dir . "/index.html";
97 } elseif (is_file($dir . "/index.htm")) {
98 return "./" . $dir . "/index.htm";
99 }
100
101 return "";
102 }
103
104 public static function _checkGoto(string $target): bool
105 {
106 global $DIC;
107
108 $ilAccess = $DIC->access();
109
110 $t_arr = explode("_", $target);
111
112 if ($t_arr[0] !== "htlm" || ((int) $t_arr[1]) <= 0) {
113 return false;
114 }
115
116 if ($ilAccess->checkAccess("visible", "", $t_arr[1]) ||
117 $ilAccess->checkAccess("read", "", $t_arr[1])) {
118 return true;
119 }
120 return false;
121 }
122
127 public static function _lookupDiskUsage(int $a_id): int
128 {
129 $lm_data_dir = ilFileUtils::getWebspaceDir('filesystem') . "/lm_data";
130 $lm_dir = $lm_data_dir . DIRECTORY_SEPARATOR . "lm_" . $a_id;
131
132 return file_exists($lm_dir) ? ilFileUtils::dirsize($lm_dir) : 0;
133 }
134
135 public static function _preloadData(array $obj_ids, array $ref_ids): void
136 {
137 global $DIC;
138
139 $ilDB = $DIC->database();
140
141 $q = "SELECT id, startfile FROM file_based_lm WHERE " .
142 $ilDB->in("id", $obj_ids, false, "integer");
143
144 $lm_set = $ilDB->query($q);
145 while ($rec = $ilDB->fetchAssoc($lm_set)) {
146 self::$startfile[$rec["id"]] = $rec["startfile"] . "";
147 }
148 }
149
150 public static function isInfoEnabled(int $obj_id): bool
151 {
153 $obj_id,
155 true
156 );
157 }
158}
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addInfoItem(string $a_type, string $a_text, string $a_data="")
add an info item to current info object
$ref_id
Definition: ltiauth.php:67
$lm_set