ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
5 include_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 $startfile;
53 
66  public function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id = "")
67  {
69  $lng = $this->lng;
70  $ilAccess = $this->access;
71 
72  if ($a_user_id == "") {
73  $a_user_id = $ilUser->getId();
74  }
75 
76  switch ($a_permission) {
77  case "read":
78 
79  if (ilObjFileBasedLMAccess::_determineStartUrl($a_obj_id) == "") {
80  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
81  return false;
82  }
83  break;
84  }
85  return true;
86  }
87 
100  public static function _getCommands()
101  {
102  $commands = array(
103  array("permission" => "read", "cmd" => "view", "lang_var" => "show",
104  "default" => true),
105  array("permission" => "write", "cmd" => "edit", "lang_var" => "edit_content"),
106  array("permission" => "write", "cmd" => "properties", "lang_var" => "settings")
107  );
108 
109  return $commands;
110  }
111 
112  //
113  // access relevant methods
114  //
115 
119  public static function _determineStartUrl($a_id)
120  {
121  global $DIC;
122 
123  $ilDB = $DIC->database();
124 
125  if (isset(self::$startfile[$a_id])) {
126  $start_file = self::$startfile[$a_id];
127  } else {
128  $q = "SELECT startfile FROM file_based_lm WHERE id = " . $ilDB->quote($a_id, "integer");
129  $set = $ilDB->query($q);
130  $rec = $ilDB->fetchAssoc($set);
131  $start_file = $rec["startfile"];
132  self::$startfile[$a_id] = $start_file . "";
133  }
134 
135  $dir = ilUtil::getWebspaceDir() . "/lm_data/lm_" . $a_id;
136 
137  if (($start_file != "") &&
138  (@is_file($dir . "/" . $start_file))) {
139  return "./" . $dir . "/" . $start_file;
140  } elseif (@is_file($dir . "/index.html")) {
141  return "./" . $dir . "/index.html";
142  } elseif (@is_file($dir . "/index.htm")) {
143  return "./" . $dir . "/index.htm";
144  }
145 
146  return "";
147  }
148 
152  public static function _checkGoto($a_target)
153  {
154  global $DIC;
155 
156  $ilAccess = $DIC->access();
157 
158  $t_arr = explode("_", $a_target);
159 
160  if ($t_arr[0] != "htlm" || ((int) $t_arr[1]) <= 0) {
161  return false;
162  }
163 
164  if ($ilAccess->checkAccess("visible", "", $t_arr[1]) ||
165  $ilAccess->checkAccess("read", "", $t_arr[1])) {
166  return true;
167  }
168  return false;
169  }
170 
176  public static function _lookupDiskUsage($a_id)
177  {
178  $lm_data_dir = ilUtil::getWebspaceDir('filesystem') . "/lm_data";
179  $lm_dir = $lm_data_dir . DIRECTORY_SEPARATOR . "lm_" . $a_id;
180 
181  return file_exists($lm_dir) ? ilUtil::dirsize($lm_dir) : 0;
182  }
183 
184 
190  public static function _preloadData($a_obj_ids, $a_ref_ids)
191  {
192  global $DIC;
193 
194  $ilDB = $DIC->database();
195 
196  $q = "SELECT id, startfile FROM file_based_lm WHERE " .
197  $ilDB->in("id", $a_obj_ids, false, "integer");
198 
199  $lm_set = $ilDB->query($q);
200  while ($rec = $ilDB->fetchAssoc($lm_set)) {
201  self::$startfile[$rec["id"]] = $rec["startfile"] . "";
202  }
203  }
204 }
static _lookupDiskUsage($a_id)
Returns the number of bytes used on the harddisk by the learning module with the specified object id...
global $DIC
Definition: saml.php:7
const IL_NO_OBJECT_ACCESS
_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.
user()
Definition: user.php:4
static _checkGoto($a_target)
check whether goto script will succeed
Class ilFileBasedLMAccess.
$ilUser
Definition: imgupload.php:18
static _determineStartUrl($a_id)
determine start url
static dirsize($directory)
get size of a directory or a file.
$lm_set
Class ilObjectAccess.
global $ilDB
static getWebspaceDir($mode="filesystem")
get webspace directory