ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilMediaPoolItem.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
12{
16 protected $db;
17
18 protected $import_id;
19
25 public function __construct($a_id = 0)
26 {
27 global $DIC;
28
29 $this->db = $DIC->database();
30 if ($a_id > 0) {
31 $this->setId($a_id);
32 $this->read();
33 }
34 }
35
41 public function setId($a_val)
42 {
43 $this->id = $a_val;
44 }
45
51 public function getId()
52 {
53 return $this->id;
54 }
55
61 public function setType($a_val)
62 {
63 $this->type = $a_val;
64 }
65
71 public function getType()
72 {
73 return $this->type;
74 }
75
81 public function setForeignId($a_val)
82 {
83 $this->foreign_id = $a_val;
84 }
85
91 public function getForeignId()
92 {
93 return $this->foreign_id;
94 }
95
101 public function setImportId($a_val)
102 {
103 $this->import_id = $a_val;
104 }
105
111 public function getImportId()
112 {
113 return $this->import_id;
114 }
115
121 public function setTitle($a_val)
122 {
123 $this->title = $a_val;
124 }
125
131 public function getTitle()
132 {
133 return $this->title;
134 }
135
139 public function create()
140 {
142
143 $nid = $ilDB->nextId("mep_item");
144 $ilDB->manipulate("INSERT INTO mep_item " .
145 "(obj_id, type, foreign_id, title, import_id) VALUES (" .
146 $ilDB->quote($nid, "integer") . "," .
147 $ilDB->quote($this->getType(), "text") . "," .
148 $ilDB->quote($this->getForeignId(), "integer") . "," .
149 $ilDB->quote($this->getTitle(), "text") . "," .
150 $ilDB->quote($this->getImportId(), "text") .
151 ")");
152 $this->setId($nid);
153 }
154
158 public function read()
159 {
161
162 $set = $ilDB->query(
163 "SELECT * FROM mep_item WHERE " .
164 "obj_id = " . $ilDB->quote($this->getId(), "integer")
165 );
166 if ($rec = $ilDB->fetchAssoc($set)) {
167 $this->setType($rec["type"]);
168 $this->setForeignId($rec["foreign_id"]);
169 $this->setTitle($rec["title"]);
170 $this->setImportId($rec["import_id"]);
171 }
172 }
173
180 public function update()
181 {
183
184 $ilDB->manipulate(
185 "UPDATE mep_item SET " .
186 " type = " . $ilDB->quote($this->getType(), "text") . "," .
187 " foreign_id = " . $ilDB->quote($this->getForeignId(), "integer") . "," .
188 " title = " . $ilDB->quote($this->getTitle(), "text") . "," .
189 " import_id = " . $ilDB->quote($this->getImportId(), "text") .
190 " WHERE obj_id = " . $ilDB->quote($this->getId(), "integer")
191 );
192 }
193
200 public function delete()
201 {
203
204 $ilDB->manipulate(
205 "DELETE FROM mep_item WHERE "
206 . " obj_id = " . $ilDB->quote($this->getId(), "integer")
207 );
208 }
209
216 private static function lookup($a_id, $a_field)
217 {
218 global $DIC;
219
220 $ilDB = $DIC->database();
221
222 $set = $ilDB->query("SELECT " . $a_field . " FROM mep_item WHERE " .
223 " obj_id = " . $ilDB->quote($a_id, "integer"));
224 if ($rec = $ilDB->fetchAssoc($set)) {
225 return $rec[$a_field];
226 }
227 return false;
228 }
229
235 public static function lookupForeignId($a_id)
236 {
237 return self::lookup($a_id, "foreign_id");
238 }
239
245 public static function lookupType($a_id)
246 {
247 return self::lookup($a_id, "type");
248 }
249
255 public static function lookupTitle($a_id)
256 {
257 return self::lookup($a_id, "title");
258 }
259
266 public static function updateObjectTitle($a_obj)
267 {
268 global $DIC;
269
270 $ilDB = $DIC->database();
271
272 if (ilObject::_lookupType($a_obj) == "mob") {
273 $title = ilObject::_lookupTitle($a_obj);
274 $ilDB->manipulate(
275 "UPDATE mep_item SET " .
276 " title = " . $ilDB->quote($title, "text") .
277 " WHERE foreign_id = " . $ilDB->quote($a_obj, "integer") .
278 " AND type = " . $ilDB->quote("mob", "text")
279 );
280 }
281 }
282
286 public static function getPoolForItemId($a_id)
287 {
288 global $DIC;
289
290 $ilDB = $DIC->database();
291
292 $set = $ilDB->query(
293 "SELECT * FROM mep_tree " .
294 " WHERE child = " . $ilDB->quote($a_id, "integer")
295 );
296 $pool_ids = array();
297 while ($rec = $ilDB->fetchAssoc($set)) {
298 $pool_ids[] = $rec["mep_id"];
299 }
300 return $pool_ids; // currently this array should contain only one id
301 }
302
309 public static function getIdsForType($a_id, $a_type)
310 {
311 global $DIC;
312
313 $ilDB = $DIC->database();
314
315 $set = $ilDB->query(
316 "SELECT mep_tree.child as id" .
317 " FROM mep_tree JOIN mep_item ON (mep_tree.child = mep_item.obj_id) WHERE " .
318 " mep_tree.mep_id = " . $ilDB->quote($a_id, "integer") . " AND " .
319 " mep_item.type = " . $ilDB->quote($a_type, "text")
320 );
321
322 $ids = array();
323 while ($rec = $ilDB->fetchAssoc($set)) {
324 $ids[] = $rec["id"];
325 }
326 return $ids;
327 }
328}
An exception for terminatinating execution or to throw for unit testing.
static getPoolForItemId($a_id)
Get media pools for item id.
static lookupForeignId($a_id)
Lookup Foreign Id.
getImportId()
Get import id.
getForeignId()
Get foreign id.
static lookupType($a_id)
Lookup type.
setTitle($a_val)
Set title.
static getIdsForType($a_id, $a_type)
Get all ids for type.
static updateObjectTitle($a_obj)
Update object title.
setImportId($a_val)
Set import id.
setType($a_val)
Set type.
__construct($a_id=0)
Construtor.
setForeignId($a_val)
Set foreign id.
static lookupTitle($a_id)
Lookup title.
static lookup($a_id, $a_field)
Lookup.
static _lookupTitle($a_id)
lookup object title
static _lookupType($a_id, $a_reference=false)
lookup object type
$type
global $ilDB
$a_type
Definition: workflow.php:92
$DIC
Definition: xapitoken.php:46