ILIAS  release_7 Revision v7.30-3-g800a261c036
trait.ilObjFileUsages.php
Go to the documentation of this file.
1<?php
2
7trait ilObjFileUsages
8{
16 // FSX
17 public static function _deleteAllUsages($a_type, $a_id, $a_usage_hist_nr = 0, $a_usage_lang = "-")
18 {
19 global $DIC;
20 $ilDB = $DIC['ilDB'];
21
22 $and_hist = ($a_usage_hist_nr !== false) ? " AND usage_hist_nr = "
23 . $ilDB->quote($a_usage_hist_nr, "integer") : "";
24
25 $file_ids = array();
26 $set = $ilDB->query("SELECT id FROM file_usage" . " WHERE usage_type = "
27 . $ilDB->quote($a_type, "text") . " AND usage_id= "
28 . $ilDB->quote($a_id, "integer") . " AND usage_lang= "
29 . $ilDB->quote($a_usage_lang, "text") . $and_hist);
30 while ($row = $ilDB->fetchAssoc($set)) {
31 $file_ids[] = $row["id"];
32 }
33
34 $ilDB->manipulate("DELETE FROM file_usage WHERE usage_type = "
35 . $ilDB->quote($a_type, "text") . " AND usage_id = "
36 . $ilDB->quote((int) $a_id, "integer") . " AND usage_lang= "
37 . $ilDB->quote($a_usage_lang, "text") . " AND usage_hist_nr = "
38 . $ilDB->quote((int) $a_usage_hist_nr, "integer"));
39
40 }
41
50 public static function _saveUsage($a_file_id, $a_type, $a_id, $a_usage_hist_nr = 0, $a_usage_lang = "-")
51 {
52 global $DIC;
53 $ilDB = $DIC['ilDB'];
54
55 // check if file really exists
56 if (ilObject::_lookupType($a_file_id) != "file") {
57 return;
58 }
59 // #15143
60 $ilDB->replace("file_usage", array(
61 "id" => array("integer", (int) $a_file_id),
62 "usage_type" => array("text", (string) $a_type),
63 "usage_id" => array("integer", (int) $a_id),
64 "usage_hist_nr" => array("integer", (int) $a_usage_hist_nr),
65 "usage_lang" => array("text", $a_usage_lang),
66 ), array());
67 }
68
72 public function getUsages()
73 {
74 global $DIC;
75 $ilDB = $DIC['ilDB'];
76
77 // get usages in learning modules
78 $q = "SELECT * FROM file_usage WHERE id = " . $ilDB->quote($this->getId(), "integer");
79 $us_set = $ilDB->query($q);
80 $ret = array();
81 while ($us_rec = $ilDB->fetchAssoc($us_set)) {
82 $ret[] = array(
83 "type" => $us_rec["usage_type"],
84 "id" => $us_rec["usage_id"],
85 "lang" => $us_rec["usage_lang"],
86 "hist_nr" => $us_rec["usage_hist_nr"],
87 );
88 }
89
90 return $ret;
91 }
92
101 public static function _getFilesOfObject($a_type, $a_id, $a_usage_hist_nr = 0, $a_usage_lang = "-")
102 {
103 global $DIC;
104 $ilDB = $DIC['ilDB'];
105
106 $lstr = "";
107 if ($a_usage_lang != "") {
108 $lstr = "usage_lang = " . $ilDB->quote((string) $a_usage_lang, "text") . " AND ";
109 }
110
111 // get usages in learning modules
112 $q = "SELECT * FROM file_usage WHERE " . "usage_id = " . $ilDB->quote((int) $a_id, "integer")
113 . " AND " . "usage_type = " . $ilDB->quote((string) $a_type, "text") . " AND " . $lstr
114 . "usage_hist_nr = " . $ilDB->quote((int) $a_usage_hist_nr, "integer");
115 $file_set = $ilDB->query($q);
116 $ret = array();
117 while ($file_rec = $ilDB->fetchAssoc($file_set)) {
118 $ret[$file_rec["id"]] = $file_rec["id"];
119 }
120
121 return $ret;
122 }
123
124}
An exception for terminatinating execution or to throw for unit testing.
static _lookupType($a_id, $a_reference=false)
lookup object type
global $DIC
Definition: goto.php:24
$ret
Definition: parser.php:6
global $ilDB