ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilMediaPoolItem.php
Go to the documentation of this file.
1 <?php
2 
24 {
25  protected string $title = "";
26  protected int $foreign_id = 0;
27  protected string $type = "";
28  protected int $id = 0;
29  protected ilDBInterface $db;
30  protected string $import_id = "";
31 
35  public function __construct(
36  int $a_id = 0
37  ) {
38  global $DIC;
39 
40  $this->db = $DIC->database();
41  if ($a_id > 0) {
42  $this->setId($a_id);
43  $this->read();
44  }
45  }
46 
47  public function setId(int $a_val): void
48  {
49  $this->id = $a_val;
50  }
51 
52  public function getId(): int
53  {
54  return $this->id;
55  }
56 
57  public function setType(string $a_val): void
58  {
59  $this->type = $a_val;
60  }
61 
62  public function getType(): string
63  {
64  return $this->type;
65  }
66 
71  public function setForeignId(int $a_val): void
72  {
73  $this->foreign_id = $a_val;
74  }
75 
76  public function getForeignId(): int
77  {
78  return $this->foreign_id;
79  }
80 
81  public function setImportId(string $a_val): void
82  {
83  $this->import_id = $a_val;
84  }
85 
86  public function getImportId(): string
87  {
88  return $this->import_id;
89  }
90 
91  public function setTitle(string $a_val): void
92  {
93  $this->title = $a_val;
94  }
95 
96  public function getTitle(): string
97  {
98  return $this->title;
99  }
100 
101  public function create(): void
102  {
103  $ilDB = $this->db;
104 
105  $nid = $ilDB->nextId("mep_item");
106  $ilDB->manipulate("INSERT INTO mep_item " .
107  "(obj_id, type, foreign_id, title, import_id) VALUES (" .
108  $ilDB->quote($nid, "integer") . "," .
109  $ilDB->quote($this->getType(), "text") . "," .
110  $ilDB->quote($this->getForeignId(), "integer") . "," .
111  $ilDB->quote($this->getTitle(), "text") . "," .
112  $ilDB->quote($this->getImportId(), "text") .
113  ")");
114  $this->setId($nid);
115  }
116 
117  public function read(): void
118  {
119  $ilDB = $this->db;
120 
121  $set = $ilDB->query(
122  "SELECT * FROM mep_item WHERE " .
123  "obj_id = " . $ilDB->quote($this->getId(), "integer")
124  );
125  if ($rec = $ilDB->fetchAssoc($set)) {
126  $this->setType($rec["type"]);
127  $this->setForeignId((int) $rec["foreign_id"]);
128  $this->setTitle($rec["title"]);
129  $this->setImportId((string) $rec["import_id"]);
130  }
131  }
132 
133  public function update(): void
134  {
135  $ilDB = $this->db;
136 
137  $ilDB->manipulate(
138  "UPDATE mep_item SET " .
139  " type = " . $ilDB->quote($this->getType(), "text") . "," .
140  " foreign_id = " . $ilDB->quote($this->getForeignId(), "integer") . "," .
141  " title = " . $ilDB->quote($this->getTitle(), "text") . "," .
142  " import_id = " . $ilDB->quote($this->getImportId(), "text") .
143  " WHERE obj_id = " . $ilDB->quote($this->getId(), "integer")
144  );
145  }
146 
147  public function delete(): void
148  {
149  $ilDB = $this->db;
150 
151  $ilDB->manipulate(
152  "DELETE FROM mep_item WHERE "
153  . " obj_id = " . $ilDB->quote($this->getId(), "integer")
154  );
155  }
156 
157  private static function lookup(
158  int $a_id,
159  string $a_field
160  ): ?string {
161  global $DIC;
162 
163  $ilDB = $DIC->database();
164 
165  $set = $ilDB->query("SELECT " . $a_field . " FROM mep_item WHERE " .
166  " obj_id = " . $ilDB->quote($a_id, "integer"));
167  if ($rec = $ilDB->fetchAssoc($set)) {
168  return $rec[$a_field];
169  }
170  return null;
171  }
172 
173  public static function lookupForeignId(int $a_id): int
174  {
175  return (int) self::lookup($a_id, "foreign_id");
176  }
177 
178  public static function lookupType(int $a_id): string
179  {
180  return (string) self::lookup($a_id, "type");
181  }
182 
183  public static function lookupTitle(int $a_id): string
184  {
185  return (string) self::lookup($a_id, "title");
186  }
187 
188  // synch media item title for media objects
189  public static function updateObjectTitle(int $a_obj): void
190  {
191  global $DIC;
192 
193  $ilDB = $DIC->database();
194 
195  if (ilObject::_lookupType($a_obj) === "mob") {
196  $title = ilObject::_lookupTitle($a_obj);
197  $ilDB->manipulate(
198  "UPDATE mep_item SET " .
199  " title = " . $ilDB->quote($title, "text") .
200  " WHERE foreign_id = " . $ilDB->quote($a_obj, "integer") .
201  " AND type = " . $ilDB->quote("mob", "text")
202  );
203  }
204  }
205 
209  public static function getPoolForItemId(int $a_id): array
210  {
211  global $DIC;
212 
213  $ilDB = $DIC->database();
214 
215  $set = $ilDB->query(
216  "SELECT * FROM mep_tree " .
217  " WHERE child = " . $ilDB->quote($a_id, "integer")
218  );
219  $pool_ids = array();
220  while ($rec = $ilDB->fetchAssoc($set)) {
221  $pool_ids[] = (int) $rec["mep_id"];
222  }
223  return $pool_ids;
224  }
225 
232  public static function getIdsForType(
233  int $a_id,
234  string $a_type
235  ): array {
236  global $DIC;
237 
238  $ilDB = $DIC->database();
239 
240  $set = $ilDB->query(
241  "SELECT mep_tree.child as id" .
242  " FROM mep_tree JOIN mep_item ON (mep_tree.child = mep_item.obj_id) WHERE " .
243  " mep_tree.mep_id = " . $ilDB->quote($a_id, "integer") . " AND " .
244  " mep_item.type = " . $ilDB->quote($a_type, "text")
245  );
246 
247  $ids = array();
248  while ($rec = $ilDB->fetchAssoc($set)) {
249  $ids[] = (int) $rec["id"];
250  }
251  return $ids;
252  }
253 }
setTitle(string $a_val)
static getPoolForItemId(int $a_id)
static lookupForeignId(int $a_id)
setImportId(string $a_val)
static lookup(int $a_id, string $a_field)
static lookupTitle(int $a_id)
setType(string $a_val)
global $DIC
Definition: feed.php:28
static _lookupTitle(int $obj_id)
static updateObjectTitle(int $a_obj)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static lookupType(int $a_id)
static _lookupType(int $id, bool $reference=false)
static getIdsForType(int $a_id, string $a_type)
Get all ids for type.
setForeignId(int $a_val)
Set foreign id (mob id)