ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilCustomBlock.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4
12{
13
14 protected $id;
15 protected $context_obj_id;
19 protected $type;
20 protected $title;
21
27 public function __construct($a_id = 0)
28 {
29 if ($a_id > 0)
30 {
31 $this->setId($a_id);
32 $this->read();
33 }
34
35 }
36
42 public function setId($a_id)
43 {
44 $this->id = $a_id;
45 }
46
52 public function getId()
53 {
54 return $this->id;
55 }
56
62 public function setContextObjId($a_context_obj_id)
63 {
64 $this->context_obj_id = $a_context_obj_id;
65 }
66
72 public function getContextObjId()
73 {
74 return (int) $this->context_obj_id;
75 }
76
82 public function setContextObjType($a_context_obj_type)
83 {
84 $this->context_obj_type = $a_context_obj_type;
85 }
86
92 public function getContextObjType()
93 {
95 }
96
102 public function setContextSubObjId($a_context_sub_obj_id)
103 {
104 $this->context_sub_obj_id = $a_context_sub_obj_id;
105 }
106
112 public function getContextSubObjId()
113 {
114 return (int) $this->context_sub_obj_id;
115 }
116
122 public function setContextSubObjType($a_context_sub_obj_type)
123 {
124 $this->context_sub_obj_type = $a_context_sub_obj_type;
125 }
126
132 public function getContextSubObjType()
133 {
135 }
136
142 public function setType($a_type)
143 {
144 $this->type = $a_type;
145 }
146
152 public function getType()
153 {
154 return $this->type;
155 }
156
162 public function setTitle($a_title)
163 {
164 $this->title = $a_title;
165 }
166
172 public function getTitle()
173 {
174 return $this->title;
175 }
176
181 public function create()
182 {
183 global $ilDB;
184
185 $this->setId($ilDB->nextId("il_custom_block"));
186 $query = "INSERT INTO il_custom_block (".
187 " id".
188 ", context_obj_id".
189 ", context_obj_type".
190 ", context_sub_obj_id".
191 ", context_sub_obj_type".
192 ", type".
193 ", title".
194 " ) VALUES (".
195 $ilDB->quote($this->getId(), "integer")
196 .",".$ilDB->quote($this->getContextObjId(), "integer")
197 .",".$ilDB->quote($this->getContextObjType(), "text")
198 .",".$ilDB->quote($this->getContextSubObjId(), "integer")
199 .",".$ilDB->quote($this->getContextSubObjType(), "text")
200 .",".$ilDB->quote($this->getType(), "text")
201 .",".$ilDB->quote($this->getTitle(), "text").")";
202 $ilDB->manipulate($query);
203 }
204
209 public function read()
210 {
211 global $ilDB;
212
213 $query = "SELECT * FROM il_custom_block WHERE id = ".
214 $ilDB->quote($this->getId(), "integer");
215 $set = $ilDB->query($query);
216 $rec = $ilDB->fetchAssoc($set);
217
218 $this->setContextObjId($rec["context_obj_id"]);
219 $this->setContextObjType($rec["context_obj_type"]);
220 $this->setContextSubObjId($rec["context_sub_obj_id"]);
221 $this->setContextSubObjType($rec["context_sub_obj_type"]);
222 $this->setType($rec["type"]);
223 $this->setTitle($rec["title"]);
224
225 }
226
231 public function update()
232 {
233 global $ilDB;
234
235 $query = "UPDATE il_custom_block SET ".
236 " context_obj_id = ".$ilDB->quote($this->getContextObjId(), "integer").
237 ", context_obj_type = ".$ilDB->quote($this->getContextObjType(), "text").
238 ", context_sub_obj_id = ".$ilDB->quote($this->getContextSubObjId(), "integer").
239 ", context_sub_obj_type = ".$ilDB->quote($this->getContextSubObjType(), "text").
240 ", type = ".$ilDB->quote($this->getType(), "text").
241 ", title = ".$ilDB->quote($this->getTitle(), "text").
242 " WHERE id = ".$ilDB->quote($this->getId(), "integer");
243
244 $ilDB->manipulate($query);
245
246 }
247
252 public function delete()
253 {
254 global $ilDB;
255
256 $query = "DELETE FROM il_custom_block".
257 " WHERE id = ".$ilDB->quote($this->getId(), "integer");
258
259 $ilDB->manipulate($query);
260
261 }
262
267 public function querygetBlocksForContext()
268 {
269 global $ilDB;
270
271 $query = "SELECT id, context_obj_id, context_obj_type, context_sub_obj_id, context_sub_obj_type, type, title ".
272 "FROM il_custom_block ".
273 "WHERE ".
274 "context_obj_id = ".$ilDB->quote($this->getContextObjId(), "integer").
275 " AND context_obj_type = ".$ilDB->quote($this->getContextObjType(), "text").
276 " AND context_sub_obj_id = ".$ilDB->quote($this->getContextSubObjId(), "integer").
277 " AND ".$ilDB->equals("context_sub_obj_type", $this->getContextSubObjType(), "text", true);
278 //" AND context_sub_obj_type = ".$ilDB->quote($this->getContextSubObjType(), "text")."";
279
280 $set = $ilDB->query($query);
281 $result = array();
282 while($rec = $ilDB->fetchAssoc($set))
283 {
284 $result[] = $rec;
285 }
286
287 return $result;
288
289 }
290
295 public function queryBlocksForContext($a_include_sub_obj = true)
296 {
297 global $ilDB;
298
299 $query = "SELECT id, context_obj_id, context_obj_type, context_sub_obj_id, context_sub_obj_type, type, title ".
300 "FROM il_custom_block ".
301 "WHERE ".
302 "context_obj_id = ".$ilDB->quote($this->getContextObjId(), "integer").
303 " AND context_obj_type = ".$ilDB->quote($this->getContextObjType(), "text");
304 if($a_include_sub_obj_id)
305 {
306 $query .= " AND context_sub_obj_id = ".$ilDB->quote($this->getContextSubObjId(), "integer").
307 " AND ".$ilDB->equals("context_sub_obj_type", $this->getContextSubObjType(), "text", true);
308 //" AND context_sub_obj_type = ".$ilDB->quote($this->getContextSubObjType(), "text")."";
309 }
310//echo "$query";
311 $set = $ilDB->query($query);
312 $result = array();
313 while($rec = $ilDB->fetchAssoc($set))
314 {
315 $result[] = $rec;
316 }
317
318 return $result;
319
320 }
321
326 public function queryTitleForId()
327 {
328 global $ilDB;
329die("ilCustomBlock::queryTitleForId is deprecated");
330/*
331 $query = "SELECT id ".
332 "FROM il_custom_block ".
333 "WHERE "."";
334
335 $set = $ilDB->query($query);
336 $result = array();
337 while($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
338 {
339 $result[] = $rec;
340 }
341
342 return $result;
343*/
344 }
345
350 public function queryCntBlockForContext()
351 {
352 global $ilDB;
353
354 $query = "SELECT count(*) as cnt ".
355 "FROM il_custom_block ".
356 "WHERE ".
357 "context_obj_id = ".$ilDB->quote($this->getContextObjId(), "integer").
358 " AND context_obj_type = ".$ilDB->quote($this->getContextObjType(), "text").
359 " AND context_sub_obj_id = ".$ilDB->quote($this->getContextSubObjId(), "integer").
360 " AND ".$ilDB->equals("context_sub_obj_type", $this->getContextSubObjType(), "text", true).
361 " AND type = ".$ilDB->quote($this->getType(), "text")."";
362
363 $set = $ilDB->query($query);
364 $result = array();
365 while($rec = $ilDB->fetchAssoc($set))
366 {
367 $result[] = $rec;
368 }
369
370 return $result;
371 }
372
373 public static function multiBlockQuery($a_context_obj_type, array $a_context_obj_ids)
374 {
375 global $ilDB;
376
377 $query = "SELECT id, context_obj_id, context_obj_type, context_sub_obj_id, context_sub_obj_type, type, title ".
378 "FROM il_custom_block ".
379 "WHERE ".
380 $ilDB->in("context_obj_id", $a_context_obj_ids, "", "integer").
381 " AND context_obj_type = ".$ilDB->quote($a_context_obj_type, "text").
382 " ORDER BY title";
383 $set = $ilDB->query($query);
384 $result = array();
385 while($rec = $ilDB->fetchAssoc($set))
386 {
387 $result[] = $rec;
388 }
389
390 return $result;
391 }
392
393
394}
395?>
$result
This is the super class of all custom blocks.
create()
Create new item.
queryCntBlockForContext()
Query CntBlockForContext.
setTitle($a_title)
Set Title.
setId($a_id)
Set Id.
queryTitleForId()
Query TitleForId.
getContextObjType()
Get ContextObjType.
setContextSubObjType($a_context_sub_obj_type)
Set ContextSubObjType.
querygetBlocksForContext()
Query getBlocksForContext.
queryBlocksForContext($a_include_sub_obj=true)
Query BlocksForContext.
update()
Update item in database.
static multiBlockQuery($a_context_obj_type, array $a_context_obj_ids)
setContextObjType($a_context_obj_type)
Set ContextObjType.
setContextObjId($a_context_obj_id)
Set ContextObjId.
getContextSubObjType()
Get ContextSubObjType.
__construct($a_id=0)
Constructor.
getContextObjId()
Get ContextObjId.
setType($a_type)
Set Type.
read()
Read item from database.
getContextSubObjId()
Get ContextSubObjId.
setContextSubObjId($a_context_sub_obj_id)
Set ContextSubObjId.
global $ilDB