ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilObjFileBasedLMAccess.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once("./Services/Object/classes/class.ilObjectAccess.php");
6
17{
21 protected $user;
22
26 protected $lng;
27
31 protected $rbacsystem;
32
36 protected $access;
37
38
42 public function __construct()
43 {
44 global $DIC;
45
46 $this->user = $DIC->user();
47 $this->lng = $DIC->language();
48 $this->rbacsystem = $DIC->rbac()->system();
49 $this->access = $DIC->access();
50 }
51
52 public static $online;
53 public static $startfile;
54
67 public function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id = "")
68 {
72 $ilAccess = $this->access;
73
74 if ($a_user_id == "") {
75 $a_user_id = $ilUser->getId();
76 }
77
78 switch ($a_permission) {
79 case "visible":
81 (!$rbacsystem->checkAccessOfUser($a_user_id, 'write', $a_ref_id))) {
82 $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
83 return false;
84 }
85 break;
86
87 case "read":
88
90 && !$rbacsystem->checkAccessOfUser($a_user_id, 'write', $a_ref_id)) ||
92 $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
93 return false;
94 }
95 break;
96 }
97
98
99 return true;
100 }
101
114 public static function _getCommands()
115 {
116 $commands = array(
117 array("permission" => "read", "cmd" => "view", "lang_var" => "show",
118 "default" => true),
119 array("permission" => "write", "cmd" => "edit", "lang_var" => "edit_content"),
120 array("permission" => "write", "cmd" => "properties", "lang_var" => "settings")
121 );
122
123 return $commands;
124 }
125
126 //
127 // access relevant methods
128 //
129
133 public static function _lookupOnline($a_id)
134 {
135 global $DIC;
136
137 $ilDB = $DIC->database();
138
139 if (isset(self::$online[$a_id])) {
140 return self::$online[$a_id];
141 }
142 $q = "SELECT is_online FROM file_based_lm WHERE id = " . $ilDB->quote($a_id, "integer");
143 $set = $ilDB->query($q);
144 $rec = $ilDB->fetchAssoc($set);
145
146 self::$online[$a_id] = ilUtil::yn2tf($rec["is_online"]);
147
148 return self::$online[$a_id];
149 }
150
154 public static function _determineStartUrl($a_id)
155 {
156 global $DIC;
157
158 $ilDB = $DIC->database();
159
160 if (isset(self::$startfile[$a_id])) {
161 $start_file = self::$startfile[$a_id];
162 } else {
163 $q = "SELECT startfile FROM file_based_lm WHERE id = " . $ilDB->quote($a_id, "integer");
164 $set = $ilDB->query($q);
165 $rec = $ilDB->fetchAssoc($set);
166 $start_file = $rec["startfile"];
167 self::$startfile[$a_id] = $start_file . "";
168 }
169
170 $dir = ilUtil::getWebspaceDir() . "/lm_data/lm_" . $a_id;
171
172 if (($start_file != "") &&
173 (@is_file($dir . "/" . $start_file))) {
174 return "./" . $dir . "/" . $start_file;
175 } elseif (@is_file($dir . "/index.html")) {
176 return "./" . $dir . "/index.html";
177 } elseif (@is_file($dir . "/index.htm")) {
178 return "./" . $dir . "/index.htm";
179 }
180
181 return "";
182 }
183
187 public static function _checkGoto($a_target)
188 {
189 global $DIC;
190
191 $ilAccess = $DIC->access();
192
193 $t_arr = explode("_", $a_target);
194
195 if ($t_arr[0] != "htlm" || ((int) $t_arr[1]) <= 0) {
196 return false;
197 }
198
199 if ($ilAccess->checkAccess("visible", "", $t_arr[1]) ||
200 $ilAccess->checkAccess("read", "", $t_arr[1])) {
201 return true;
202 }
203 return false;
204 }
205
211 public static function _lookupDiskUsage($a_id)
212 {
213 $lm_data_dir = ilUtil::getWebspaceDir('filesystem') . "/lm_data";
214 $lm_dir = $lm_data_dir . DIRECTORY_SEPARATOR . "lm_" . $a_id;
215
216 return file_exists($lm_dir) ? ilUtil::dirsize($lm_dir) : 0;
217 }
218
227 public static function _isOffline($a_obj_id)
228 {
229 return !self::_lookupOnline($a_obj_id);
230 }
231
237 public static function _preloadData($a_obj_ids, $a_ref_ids)
238 {
239 global $DIC;
240
241 $ilDB = $DIC->database();
242 $ilUser = $DIC->user();
243
244 $q = "SELECT id, is_online, startfile FROM file_based_lm WHERE " .
245 $ilDB->in("id", $a_obj_ids, false, "integer");
246
247 $lm_set = $ilDB->query($q);
248 while ($rec = $ilDB->fetchAssoc($lm_set)) {
249 self::$online[$rec["id"]] = ilUtil::yn2tf($rec["is_online"]);
250 self::$startfile[$rec["id"]] = $rec["startfile"] . "";
251 }
252 }
253}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
const IL_NO_OBJECT_ACCESS
Class ilFileBasedLMAccess.
static _isOffline($a_obj_id)
Type-specific implementation of general status.
static _lookupOnline($a_id)
check wether learning module is online
_checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id="")
checks wether a user may invoke a command or not (this method is called by ilAccessHandler::checkAcce...
static _preloadData($a_obj_ids, $a_ref_ids)
Preload data.
static _checkGoto($a_target)
check whether goto script will succeed
static _determineStartUrl($a_id)
check wether learning module is online
static _lookupDiskUsage($a_id)
Returns the number of bytes used on the harddisk by the learning module with the specified object id.
Class ilObjectAccess.
static getWebspaceDir($mode="filesystem")
get webspace directory
static yn2tf($a_yn)
convert "y"/"n" to true/false
static dirsize($directory)
get size of a directory or a file.
global $DIC
Definition: saml.php:7
global $ilDB
$lm_set
$ilUser
Definition: imgupload.php:18