ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilDiskQuotaHandler Class Reference

Class ilDiskQuotaHandler. More...

+ Collaboration diagram for ilDiskQuotaHandler:

Static Public Member Functions

static handleUpdatedSourceObject ($a_src_obj_type, $a_src_obj_id, $a_src_filesize, $a_owner_obj_ids=null, $a_is_prtf=false)
 Find and update/create all related entries for source object. More...
 
static deleteByOwner ($a_owner_id)
 Delete all entries for owner. More...
 
static getFilesizeByOwner ($a_owner_id)
 Get current storage size for owner. More...
 
static getFilesizeByTypeAndOwner ($a_owner_id)
 Get current storage size for owner (grouped by type) More...
 
static isUploadPossible ($a_additional_size=null)
 
static getStatusLegend ()
 

Static Protected Member Functions

static deleteEntry ($a_owner_id, $a_src_obj_type, $a_src_obj_id)
 Delete entry for owner and source object. More...
 
static getOwnersBySourceObject ($a_src_obj_type, $a_src_obj_id)
 Get owner ids by source object. More...
 
static getSourceObjectsByOwner ($a_owner_id)
 Get all source objects for owner. More...
 
static handleEntry ($a_owner_id, $a_src_obj_type, $a_src_obj_id, $a_src_filesize)
 Update/create owner-related entry of source object. More...
 

Detailed Description

Class ilDiskQuotaHandler.

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
Id
class.ilObjFile.php 40384 2013-03-06 13:08:21Z sborn

Definition at line 12 of file class.ilDiskQuotaHandler.php.

Member Function Documentation

◆ deleteByOwner()

static ilDiskQuotaHandler::deleteByOwner (   $a_owner_id)
static

Delete all entries for owner.

Parameters
int$a_owner_id

Definition at line 99 of file class.ilDiskQuotaHandler.php.

References $ilDB.

Referenced by ilObjUser\delete().

100  {
101  global $ilDB;
102 
103  $ilDB->manipulate("DELETE FROM il_disk_quota" .
104  " WHERE owner_id = " . $ilDB->quote($a_owner_id, "integer"));
105  }
global $ilDB
+ Here is the caller graph for this function:

◆ deleteEntry()

static ilDiskQuotaHandler::deleteEntry (   $a_owner_id,
  $a_src_obj_type,
  $a_src_obj_id 
)
staticprotected

Delete entry for owner and source object.

Parameters
int$a_owner_id
string$a_src_obj_type
int$a_src_obj_id

Definition at line 84 of file class.ilDiskQuotaHandler.php.

References $ilDB.

85  {
86  global $ilDB;
87 
88  $ilDB->manipulate("DELETE FROM il_disk_quota" .
89  " WHERE owner_id = " . $ilDB->quote($a_owner_id, "integer") .
90  " AND src_type = " . $ilDB->quote($a_src_obj_type, "text") .
91  " AND src_obj_id = " . $ilDB->quote($a_src_obj_id, "integer"));
92  }
global $ilDB

◆ getFilesizeByOwner()

static ilDiskQuotaHandler::getFilesizeByOwner (   $a_owner_id)
static

Get current storage size for owner.

Parameters
int$a_owner_id
Returns
int

Definition at line 194 of file class.ilDiskQuotaHandler.php.

References $ilDB, and $row.

Referenced by getStatusLegend(), ilObjUserGUI\getValues(), and isUploadPossible().

195  {
196  global $ilDB;
197 
198  $set = $ilDB->query("SELECT sum(src_size) fsize" .
199  " FROM il_disk_quota" .
200  " WHERE owner_id = " . $ilDB->quote($a_owner_id, "integer"));
201  $row = $ilDB->fetchAssoc($set);
202  return (int) $row["fsize"];
203  }
global $ilDB
+ Here is the caller graph for this function:

◆ getFilesizeByTypeAndOwner()

static ilDiskQuotaHandler::getFilesizeByTypeAndOwner (   $a_owner_id)
static

Get current storage size for owner (grouped by type)

Parameters
int$a_owner_id
Returns
int

Definition at line 211 of file class.ilDiskQuotaHandler.php.

References $ilDB, $res, $row, and array.

Referenced by ilObjUserGUI\getValues().

212  {
213  global $ilDB;
214 
215  $res = array();
216 
217  $set = $ilDB->query("SELECT sum(src_size) filesize, src_type, COUNT(*) count" .
218  " FROM il_disk_quota" .
219  " WHERE owner_id = " . $ilDB->quote($a_owner_id, "integer") .
220  " GROUP BY src_type");
221  while ($row = $ilDB->fetchAssoc($set)) {
222  $res[] = $row;
223  }
224 
225  return $res;
226  }
foreach($_POST as $key=> $value) $res
Create styles array
The data for the language used.
global $ilDB
+ Here is the caller graph for this function:

◆ getOwnersBySourceObject()

static ilDiskQuotaHandler::getOwnersBySourceObject (   $a_src_obj_type,
  $a_src_obj_id 
)
staticprotected

Get owner ids by source object.

Parameters
string$a_src_obj_type
int$a_src_obj_id
Returns
array

Definition at line 114 of file class.ilDiskQuotaHandler.php.

References $ilDB, $res, $row, and array.

115  {
116  global $ilDB;
117 
118  $res = array();
119 
120  $set = $ilDB->query("SELECT owner_id" .
121  " FROM il_disk_quota" .
122  " WHERE src_type = " . $ilDB->quote($a_src_obj_type, "text") .
123  " AND src_obj_id = " . $ilDB->quote($a_src_obj_id, "integer"));
124  while ($row = $ilDB->fetchAssoc($set)) {
125  $res[] = $row["owner_id"];
126  }
127 
128  return $res;
129  }
foreach($_POST as $key=> $value) $res
Create styles array
The data for the language used.
global $ilDB

◆ getSourceObjectsByOwner()

static ilDiskQuotaHandler::getSourceObjectsByOwner (   $a_owner_id)
staticprotected

Get all source objects for owner.

Parameters
int$a_owner_id
Returns
array

Definition at line 137 of file class.ilDiskQuotaHandler.php.

References $ilDB, $res, $row, and array.

138  {
139  global $ilDB;
140 
141  $res = array();
142 
143  $set = $ilDB->query("SELECT src_type, src_obj_id" .
144  " FROM il_disk_quota" .
145  " WHERE owner_id = " . $ilDB->quote($a_owner_id, "integer"));
146  while ($row = $ilDB->fetchAssoc($set)) {
147  $res[$row["src_type"]][] = $row["src_obj_id"];
148  }
149 
150  return $res;
151  }
foreach($_POST as $key=> $value) $res
Create styles array
The data for the language used.
global $ilDB

◆ getStatusLegend()

static ilDiskQuotaHandler::getStatusLegend ( )
static

Definition at line 255 of file class.ilDiskQuotaHandler.php.

References $ilUser, $lng, ilDiskQuotaActivationChecker\_isPersonalWorkspaceActive(), ilDiskQuotaChecker\_lookupPersonalWorkspaceDiskQuota(), ilUtil\formatSize(), and getFilesizeByOwner().

Referenced by ilImageFileInputGUI\insert(), ilDragDropFileInputGUI\render(), ilFileInputGUI\render(), and ilPortfolioRepositoryGUI\show().

256  {
257  global $ilUser, $lng;
258 
259  include_once "Services/WebDAV/classes/class.ilDiskQuotaActivationChecker.php";
261  return;
262  }
263 
264  include_once "Services/DiskQuota/classes/class.ilDiskQuotaHandler.php";
265  $usage = ilDiskQuotaHandler::getFilesizeByOwner($ilUser->getId());
266 
267  include_once "Services/WebDAV/classes/class.ilDiskQuotaChecker.php";
269  $quota = $quota["disk_quota"];
270 
271  // administrator
272  if (is_infinite($quota) || !(int) $quota) {
273  return;
274  }
275 
276  $lng->loadLanguageModule("file");
277  return sprintf(
278  $lng->txt("personal_workspace_quota_status_legend"),
279  ilUtil::formatSize($usage),
280  ilUtil::formatSize($quota),
281  $quota ? round($usage/$quota*100) : 0
282  );
283  }
static _lookupPersonalWorkspaceDiskQuota($a_user_id)
$ilUser
Definition: imgupload.php:18
static getFilesizeByOwner($a_owner_id)
Get current storage size for owner.
global $lng
Definition: privfeed.php:17
static formatSize($size, $a_mode='short', $a_lng=null)
Returns the specified file size value in a human friendly form.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleEntry()

static ilDiskQuotaHandler::handleEntry (   $a_owner_id,
  $a_src_obj_type,
  $a_src_obj_id,
  $a_src_filesize 
)
staticprotected

Update/create owner-related entry of source object.

Parameters
int$a_owner_id
int$a_src_obj_type
int$a_src_obj_id
int$a_src_filesize

Definition at line 161 of file class.ilDiskQuotaHandler.php.

References $ilDB.

162  {
163  global $ilDB;
164 
165  $existing = self::getSourceObjectsByOwner($a_owner_id);
166 
167  // update
168  if ($existing &&
169  isset($existing[$a_src_obj_type]) &&
170  in_array($a_src_obj_id, $existing[$a_src_obj_type])) {
171  $ilDB->manipulate("UPDATE il_disk_quota" .
172  " SET src_size = " . $ilDB->quote($a_src_filesize, "integer") .
173  " WHERE owner_id = " . $ilDB->quote($a_owner_id, "integer") .
174  " AND src_type = " . $ilDB->quote($a_src_obj_type, "text") .
175  " AND src_obj_id = " . $ilDB->quote($a_src_obj_id, "integer"));
176  }
177  // insert
178  else {
179  $ilDB->manipulate("INSERT INTO il_disk_quota" .
180  " (owner_id, src_type, src_obj_id, src_size)" .
181  " VALUES (" . $ilDB->quote($a_owner_id, "integer") .
182  ", " . $ilDB->quote($a_src_obj_type, "text") .
183  ", " . $ilDB->quote($a_src_obj_id, "integer") .
184  ", " . $ilDB->quote($a_src_filesize, "integer") . ")");
185  }
186  }
global $ilDB

◆ handleUpdatedSourceObject()

static ilDiskQuotaHandler::handleUpdatedSourceObject (   $a_src_obj_type,
  $a_src_obj_id,
  $a_src_filesize,
  $a_owner_obj_ids = null,
  $a_is_prtf = false 
)
static

Find and update/create all related entries for source object.

Parameters
string$a_src_obj_type
int$a_src_obj_id
int$a_src_filesize
array$a_owner_obj_ids

Definition at line 22 of file class.ilDiskQuotaHandler.php.

References $ilDB, $row, and array.

Referenced by ilObjPortfolio\handleQuotaUpdate(), ilVerificationObject\handleQuotaUpdate(), ilObjMediaObject\handleQuotaUpdate(), ilObjBlog\handleQuotaUpdate(), and ilObjFile\handleQuotaUpdate().

23  {
24  global $ilDB;
25  $done = array();
26 
27  if (is_array($a_owner_obj_ids) && sizeof($a_owner_obj_ids) && (int) $a_src_filesize > 0) {
28  // we are (currently) only interested in personal workspace objects
29 
30  // problem: file in portfolio comes in with file and portfolio id, however $a_is_prtf is set to false
31  // so we do both for now
32 
33  // get all owners
34  $set = $ilDB->query("SELECT DISTINCT(od.owner)" .
35  " FROM object_data od" .
36  " JOIN object_reference_ws ref ON (ref.obj_id = od.obj_id)" .
37  " JOIN tree_workspace t ON (t.child = ref.wsp_id)" .
38  " WHERE " . $ilDB->in("od.obj_id", $a_owner_obj_ids, "", "integer") .
39  " AND t.tree = od.owner");
40  $owners = array();
41  while ($row = $ilDB->fetchAssoc($set)) {
42  if (!in_array($row["owner"], $owners)) {
43  $owners[] = $row["owner"];
44  }
45  }
46  $set = $ilDB->query("SELECT DISTINCT(od.owner)" .
47  " FROM object_data od" .
48  " JOIN usr_portfolio prtf ON (prtf.id = od.obj_id)" .
49  " WHERE " . $ilDB->in("od.obj_id", $a_owner_obj_ids, "", "integer"));
50  while ($row = $ilDB->fetchAssoc($set)) {
51  if (!in_array($row["owner"], $owners)) {
52  $owners[] = $row["owner"];
53  }
54  }
55  foreach ($owners as $owner) {
56  $done[] = $owner;
57 
58  self::handleEntry(
59  $owner,
60  $a_src_obj_type,
61  $a_src_obj_id,
62  (int) $a_src_filesize
63  );
64  }
65  }
66 
67  // delete obsolete entries
68  $existing = self::getOwnersBySourceObject($a_src_obj_type, $a_src_obj_id);
69  $existing = array_diff($existing, $done);
70  if (sizeof($existing)) {
71  foreach ($existing as $owner) {
72  self::deleteEntry($owner, $a_src_obj_type, $a_src_obj_id);
73  }
74  }
75  }
Create styles array
The data for the language used.
global $ilDB
+ Here is the caller graph for this function:

◆ isUploadPossible()

static ilDiskQuotaHandler::isUploadPossible (   $a_additional_size = null)
static

Definition at line 228 of file class.ilDiskQuotaHandler.php.

References $ilUser, ilDiskQuotaActivationChecker\_isPersonalWorkspaceActive(), ilDiskQuotaChecker\_lookupPersonalWorkspaceDiskQuota(), and getFilesizeByOwner().

Referenced by ilObjTestVerificationGUI\create(), ilObjCourseVerificationGUI\create(), ilObjExerciseVerificationGUI\create(), ilObjSCORMVerificationGUI\create(), ilObjPortfolioGUI\createPortfolioFromAssignment(), ilObjPortfolioGUI\initCreatePortfolioFromTemplateForm(), ilObjFileGUI\initCreationForms(), ilObjFileGUI\initPropertiesForm(), ilImageFileInputGUI\insert(), ilDragDropFileInputGUI\render(), and ilFileInputGUI\render().

229  {
230  global $ilUser;
231 
232  include_once "Services/WebDAV/classes/class.ilDiskQuotaActivationChecker.php";
234  return true;
235  }
236 
237  include_once "Services/DiskQuota/classes/class.ilDiskQuotaHandler.php";
238  $usage = ilDiskQuotaHandler::getFilesizeByOwner($ilUser->getId());
239  if ($a_additional_size) {
240  $usage += $a_additional_size;
241  }
242 
243  include_once "Services/WebDAV/classes/class.ilDiskQuotaChecker.php";
245  $quota = $quota["disk_quota"];
246 
247  // administrator
248  if (is_infinite($quota)) {
249  return true;
250  }
251 
252  return $usage < $quota;
253  }
static _lookupPersonalWorkspaceDiskQuota($a_user_id)
$ilUser
Definition: imgupload.php:18
static getFilesizeByOwner($a_owner_id)
Get current storage size for owner.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: