ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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{
18 function __construct($a_id = 0)
19 {
20 if ($a_id > 0)
21 {
22 $this->setId($a_id);
23 $this->read();
24 }
25 }
26
32 function setId($a_val)
33 {
34 $this->id = $a_val;
35 }
36
42 function getId()
43 {
44 return $this->id;
45 }
46
52 function setType($a_val)
53 {
54 $this->type = $a_val;
55 }
56
62 function getType()
63 {
64 return $this->type;
65 }
66
72 function setForeignId($a_val)
73 {
74 $this->foreign_id = $a_val;
75 }
76
82 function getForeignId()
83 {
84 return $this->foreign_id;
85 }
86
92 function setTitle($a_val)
93 {
94 $this->title = $a_val;
95 }
96
102 function getTitle()
103 {
104 return $this->title;
105 }
106
110 function create()
111 {
112 global $ilDB;
113
114 $nid = $ilDB->nextId("mep_item");
115 $ilDB->manipulate("INSERT INTO mep_item ".
116 "(obj_id, type, foreign_id, title) VALUES (".
117 $ilDB->quote($nid, "integer").",".
118 $ilDB->quote($this->getType(), "text").",".
119 $ilDB->quote($this->getForeignId(), "integer").",".
120 $ilDB->quote($this->getTitle(), "text").
121 ")");
122 $this->setId($nid);
123 }
124
128 function read()
129 {
130 global $ilDB;
131
132 $set = $ilDB->query("SELECT * FROM mep_item WHERE ".
133 "obj_id = ".$ilDB->quote($this->getId(), "integer")
134 );
135 if ($rec = $ilDB->fetchAssoc($set))
136 {
137 $this->setType($rec["type"]);
138 $this->setForeignId($rec["foreign_id"]);
139 $this->setTitle($rec["title"]);
140 }
141 }
142
149 function update()
150 {
151 global $ilDB;
152
153 $ilDB->manipulate("UPDATE mep_item SET ".
154 " type = ".$ilDB->quote($this->getType(), "text").",".
155 " foreign_id = ".$ilDB->quote($this->getForeignId(), "integer").",".
156 " title = ".$ilDB->quote($this->getTitle(), "text").
157 " WHERE obj_id = ".$ilDB->quote($this->getId(), "integer")
158 );
159 }
160
167 function delete()
168 {
169 global $ilDB;
170
171 $ilDB->manipulate("DELETE FROM mep_item WHERE "
172 ." obj_id = ".$ilDB->quote($this->getId(), "integer")
173 );
174 }
175
182 private static function lookup($a_id, $a_field)
183 {
184 global $ilDB;
185
186 $set = $ilDB->query("SELECT ".$a_field." FROM mep_item WHERE ".
187 " obj_id = ".$ilDB->quote($a_id, "integer"));
188 if ($rec = $ilDB->fetchAssoc($set))
189 {
190 return $rec[$a_field];
191 }
192 return false;
193 }
194
200 static function lookupForeignId($a_id)
201 {
202 return self::lookup($a_id, "foreign_id");
203 }
204
210 static function lookupType($a_id)
211 {
212 return self::lookup($a_id, "type");
213 }
214
220 static function lookupTitle($a_id)
221 {
222 return self::lookup($a_id, "title");
223 }
224
231 static function updateObjectTitle($a_obj)
232 {
233 global $ilDB;
234
235 if (ilObject::_lookupType($a_obj) == "mob")
236 {
237 $title = ilObject::_lookupTitle($a_obj);
238 $ilDB->manipulate("UPDATE mep_item SET ".
239 " title = ".$ilDB->quote($title, "text").
240 " WHERE foreign_id = ".$ilDB->quote($a_obj, "integer").
241 " AND type = ".$ilDB->quote("mob", "text")
242 );
243 }
244 }
245
249 static function getPoolForItemId($a_id)
250 {
251 global $ilDB;
252
253 $set = $ilDB->query("SELECT * FROM mep_tree ".
254 " WHERE child = ".$ilDB->quote($a_id, "integer")
255 );
256 $pool_ids = array();
257 while ($rec = $ilDB->fetchAssoc($set))
258 {
259 $pool_ids[] = $rec["mep_id"];
260 }
261 return $pool_ids; // currently this array should contain only one id
262 }
263
270 static function getIdsForType($a_id, $a_type)
271 {
272 global $ilDB;
273
274 $set = $ilDB->query("SELECT mep_tree.child as id".
275 " FROM mep_tree JOIN mep_item ON (mep_tree.child = mep_item.obj_id) WHERE ".
276 " mep_tree.mep_id = ".$ilDB->quote($a_id, "integer")." AND ".
277 " mep_item.type = ".$ilDB->quote($a_type, "text")
278 );
279
280 $ids = array();
281 while ($rec = $ilDB->fetchAssoc($set))
282 {
283 $ids[] = $rec["id"];
284 }
285 return $ids;
286 }
287
288}
289?>
static getPoolForItemId($a_id)
Get media pools for item id.
static lookupForeignId($a_id)
Lookup Foreign 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.
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
global $ilDB