ILIAS  release_8 Revision v8.23
trait.ilObjFileUsages.php
Go to the documentation of this file.
1 <?php
2 
23 trait ilObjFileUsages
24 {
30  // FSX
31  public static function _deleteAllUsages($a_type, $a_id, int $a_usage_hist_nr = 0, string $a_usage_lang = "-")
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 = array();
40  $set = $ilDB->query("SELECT id FROM file_usage" . " WHERE usage_type = "
41  . $ilDB->quote($a_type, "text") . " AND usage_id= "
42  . $ilDB->quote($a_id, "integer") . " AND usage_lang= "
43  . $ilDB->quote($a_usage_lang, "text") . $and_hist);
44  while ($row = $ilDB->fetchAssoc($set)) {
45  $file_ids[] = $row["id"];
46  }
47 
48  $ilDB->manipulate("DELETE FROM file_usage WHERE usage_type = "
49  . $ilDB->quote($a_type, "text") . " AND usage_id = "
50  . $ilDB->quote((int) $a_id, "integer") . " AND usage_lang= "
51  . $ilDB->quote($a_usage_lang, "text") . " AND usage_hist_nr = "
52  . $ilDB->quote($a_usage_hist_nr, "integer"));
53  }
54 
61  public static function _saveUsage($a_file_id, $a_type, $a_id, int $a_usage_hist_nr = 0, string $a_usage_lang = "-")
62  {
63  global $DIC;
64  $ilDB = $DIC['ilDB'];
65 
66  // check if file really exists
67  if (ilObject::_lookupType($a_file_id) != "file") {
68  return;
69  }
70  // #15143
71  $ilDB->replace("file_usage", array(
72  "id" => array("integer", (int) $a_file_id),
73  "usage_type" => array("text", (string) $a_type),
74  "usage_id" => array("integer", (int) $a_id),
75  "usage_hist_nr" => array("integer", $a_usage_hist_nr),
76  "usage_lang" => array("text", $a_usage_lang),
77  ), array());
78  }
79 
84  public function getUsages(): array
85  {
86  global $DIC;
87  $ilDB = $DIC['ilDB'];
88 
89  // get usages in learning modules
90  $q = "SELECT * FROM file_usage WHERE id = " . $ilDB->quote($this->getId(), "integer");
91  $us_set = $ilDB->query($q);
92  $ret = array();
93  while ($us_rec = $ilDB->fetchAssoc($us_set)) {
94  $ret[] = array(
95  "type" => $us_rec["usage_type"],
96  "id" => $us_rec["usage_id"],
97  "lang" => $us_rec["usage_lang"],
98  "hist_nr" => $us_rec["usage_hist_nr"],
99  );
100  }
101 
102  return $ret;
103  }
104 
108  public static function _getFilesOfObject(string $a_type, int $a_id, int $a_usage_hist_nr = 0, string $a_usage_lang = "-"): array
109  {
110  global $DIC;
111  $ilDB = $DIC['ilDB'];
112 
113  $lstr = "";
114  if ($a_usage_lang != "") {
115  $lstr = "usage_lang = " . $ilDB->quote($a_usage_lang, "text") . " AND ";
116  }
117 
118  // get usages in learning modules
119  $q = "SELECT * FROM file_usage WHERE " . "usage_id = " . $ilDB->quote($a_id, "integer")
120  . " AND " . "usage_type = " . $ilDB->quote($a_type, "text") . " AND " . $lstr
121  . "usage_hist_nr = " . $ilDB->quote($a_usage_hist_nr, "integer");
122  $file_set = $ilDB->query($q);
123  $ret = array();
124  while ($file_rec = $ilDB->fetchAssoc($file_set)) {
125  $ret[$file_rec["id"]] = $file_rec["id"];
126  }
127 
128  return $ret;
129  }
130 }
global $DIC
Definition: feed.php:28
static _lookupType(int $id, bool $reference=false)