ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
trait.ilObjFileUsages.php
Go to the documentation of this file.
1<?php
2
23trait ilObjFileUsages
24{
30 // FSX
31 public static function _deleteAllUsages($a_type, $a_id, int $a_usage_hist_nr = 0, string $a_usage_lang = "-"): void
32 {
33 global $DIC;
34 $ilDB = $DIC['ilDB'];
35
36 $and_hist = ($a_usage_hist_nr !== false) ? " AND usage_hist_nr = "
37 . $ilDB->quote($a_usage_hist_nr, "integer") : "";
38
39 $file_ids = [];
40 $set = $ilDB->query(
41 'SELECT id FROM file_usage WHERE usage_type = '
42 . $ilDB->quote($a_type, "text") . " AND usage_id= "
43 . $ilDB->quote($a_id, "integer") . " AND usage_lang= "
44 . $ilDB->quote($a_usage_lang, "text") . $and_hist
45 );
46 while ($row = $ilDB->fetchAssoc($set)) {
47 $file_ids[] = $row["id"];
48 }
49
50 $ilDB->manipulate(
51 "DELETE FROM file_usage WHERE usage_type = "
52 . $ilDB->quote($a_type, "text") . " AND usage_id = "
53 . $ilDB->quote((int) $a_id, "integer") . " AND usage_lang= "
54 . $ilDB->quote($a_usage_lang, "text") . " AND usage_hist_nr = "
55 . $ilDB->quote($a_usage_hist_nr, "integer")
56 );
57 }
58
65 public static function _saveUsage(
66 $a_file_id,
67 $a_type,
68 $a_id,
69 int $a_usage_hist_nr = 0,
70 string $a_usage_lang = "-"
71 ): void {
72 global $DIC;
73 $ilDB = $DIC['ilDB'];
74
75 // check if file really exists
76 if (ilObject::_lookupType($a_file_id) !== "file") {
77 return;
78 }
79 // #15143
80 $ilDB->replace(
81 "file_usage",
82 [
83 "id" => ["integer", (int) $a_file_id],
84 "usage_type" => ["text", (string) $a_type],
85 "usage_id" => ["integer", (int) $a_id],
86 "usage_hist_nr" => ["integer", $a_usage_hist_nr],
87 "usage_lang" => ["text", $a_usage_lang]
88 ],
89 []
90 );
91 }
92
97 public function getUsages(): array
98 {
99 global $DIC;
100 $ilDB = $DIC['ilDB'];
101
102 // get usages in learning modules
103 $q = "SELECT * FROM file_usage WHERE id = " . $ilDB->quote($this->getId(), "integer");
104 $us_set = $ilDB->query($q);
105 $ret = [];
106 while ($us_rec = $ilDB->fetchAssoc($us_set)) {
107 $ret[] = [
108 "type" => $us_rec["usage_type"],
109 "id" => $us_rec["usage_id"],
110 "lang" => $us_rec["usage_lang"],
111 "hist_nr" => $us_rec["usage_hist_nr"]
112 ];
113 }
114
115 return $ret;
116 }
117
121 public static function _getFilesOfObject(
122 string $a_type,
123 int $a_id,
124 int $a_usage_hist_nr = 0,
125 string $a_usage_lang = "-"
126 ): array {
127 global $DIC;
128 $ilDB = $DIC['ilDB'];
129
130 $lstr = "";
131 if ($a_usage_lang !== "") {
132 $lstr = "usage_lang = " . $ilDB->quote($a_usage_lang, "text") . " AND ";
133 }
134
135 // get usages in learning modules
136 $q = 'SELECT * FROM file_usage WHERE usage_id = ' . $ilDB->quote($a_id, "integer")
137 . " AND " . "usage_type = " . $ilDB->quote($a_type, "text") . " AND " . $lstr
138 . "usage_hist_nr = " . $ilDB->quote($a_usage_hist_nr, "integer");
139 $file_set = $ilDB->query($q);
140 $ret = [];
141 while ($file_rec = $ilDB->fetchAssoc($file_set)) {
142 $ret[$file_rec["id"]] = $file_rec["id"];
143 }
144
145 return $ret;
146 }
147}
static _lookupType(int $id, bool $reference=false)
global $DIC
Definition: shib_login.php:26
$q
Definition: shib_logout.php:23