ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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{
16 protected $db;
17
18
19 protected $id;
20 protected $context_obj_id;
24 protected $type;
25 protected $title;
26
32 public function __construct($a_id = 0)
33 {
34 global $DIC;
35
36 $this->db = $DIC->database();
37 if ($a_id > 0) {
38 $this->setId($a_id);
39 $this->read();
40 }
41 }
42
48 public function setId($a_id)
49 {
50 $this->id = $a_id;
51 }
52
58 public function getId()
59 {
60 return $this->id;
61 }
62
68 public function setContextObjId($a_context_obj_id)
69 {
70 $this->context_obj_id = $a_context_obj_id;
71 }
72
78 public function getContextObjId()
79 {
80 return (int) $this->context_obj_id;
81 }
82
88 public function setContextObjType($a_context_obj_type)
89 {
90 $this->context_obj_type = $a_context_obj_type;
91 }
92
98 public function getContextObjType()
99 {
101 }
102
108 public function setContextSubObjId($a_context_sub_obj_id)
109 {
110 $this->context_sub_obj_id = $a_context_sub_obj_id;
111 }
112
118 public function getContextSubObjId()
119 {
120 return (int) $this->context_sub_obj_id;
121 }
122
128 public function setContextSubObjType($a_context_sub_obj_type)
129 {
130 $this->context_sub_obj_type = $a_context_sub_obj_type;
131 }
132
138 public function getContextSubObjType()
139 {
141 }
142
148 public function setType($a_type)
149 {
150 $this->type = $a_type;
151 }
152
158 public function getType()
159 {
160 return $this->type;
161 }
162
168 public function setTitle($a_title)
169 {
170 $this->title = $a_title;
171 }
172
178 public function getTitle()
179 {
180 return $this->title;
181 }
182
187 public function create()
188 {
190
191 $this->setId($ilDB->nextId("il_custom_block"));
192 $query = "INSERT INTO il_custom_block (" .
193 " id" .
194 ", context_obj_id" .
195 ", context_obj_type" .
196 ", context_sub_obj_id" .
197 ", context_sub_obj_type" .
198 ", type" .
199 ", title" .
200 " ) VALUES (" .
201 $ilDB->quote($this->getId(), "integer")
202 . "," . $ilDB->quote($this->getContextObjId(), "integer")
203 . "," . $ilDB->quote($this->getContextObjType(), "text")
204 . "," . $ilDB->quote($this->getContextSubObjId(), "integer")
205 . "," . $ilDB->quote($this->getContextSubObjType(), "text")
206 . "," . $ilDB->quote($this->getType(), "text")
207 . "," . $ilDB->quote($this->getTitle(), "text") . ")";
208 $ilDB->manipulate($query);
209 }
210
215 public function read()
216 {
218
219 $query = "SELECT * FROM il_custom_block WHERE id = " .
220 $ilDB->quote($this->getId(), "integer");
221 $set = $ilDB->query($query);
222 $rec = $ilDB->fetchAssoc($set);
223
224 $this->setContextObjId($rec["context_obj_id"]);
225 $this->setContextObjType($rec["context_obj_type"]);
226 $this->setContextSubObjId($rec["context_sub_obj_id"]);
227 $this->setContextSubObjType($rec["context_sub_obj_type"]);
228 $this->setType($rec["type"]);
229 $this->setTitle($rec["title"]);
230 }
231
236 public function update()
237 {
239
240 $query = "UPDATE il_custom_block SET " .
241 " context_obj_id = " . $ilDB->quote($this->getContextObjId(), "integer") .
242 ", context_obj_type = " . $ilDB->quote($this->getContextObjType(), "text") .
243 ", context_sub_obj_id = " . $ilDB->quote($this->getContextSubObjId(), "integer") .
244 ", context_sub_obj_type = " . $ilDB->quote($this->getContextSubObjType(), "text") .
245 ", type = " . $ilDB->quote($this->getType(), "text") .
246 ", title = " . $ilDB->quote($this->getTitle(), "text") .
247 " WHERE id = " . $ilDB->quote($this->getId(), "integer");
248
249 $ilDB->manipulate($query);
250 }
251
256 public function delete()
257 {
259
260 $query = "DELETE FROM il_custom_block" .
261 " WHERE id = " . $ilDB->quote($this->getId(), "integer");
262
263 $ilDB->manipulate($query);
264 }
265
270 public function querygetBlocksForContext()
271 {
273
274 $query = "SELECT id, context_obj_id, context_obj_type, context_sub_obj_id, context_sub_obj_type, type, title " .
275 "FROM il_custom_block " .
276 "WHERE " .
277 "context_obj_id = " . $ilDB->quote($this->getContextObjId(), "integer") .
278 " AND context_obj_type = " . $ilDB->quote($this->getContextObjType(), "text") .
279 " AND context_sub_obj_id = " . $ilDB->quote($this->getContextSubObjId(), "integer") .
280 " AND " . $ilDB->equals("context_sub_obj_type", $this->getContextSubObjType(), "text", true);
281 //" AND context_sub_obj_type = ".$ilDB->quote($this->getContextSubObjType(), "text")."";
282
283 $set = $ilDB->query($query);
284 $result = array();
285 while ($rec = $ilDB->fetchAssoc($set)) {
286 $result[] = $rec;
287 }
288
289 return $result;
290 }
291
296 public function queryBlocksForContext($a_include_sub_obj = true)
297 {
299
300 $query = "SELECT id, context_obj_id, context_obj_type, context_sub_obj_id, context_sub_obj_type, type, title " .
301 "FROM il_custom_block " .
302 "WHERE " .
303 "context_obj_id = " . $ilDB->quote($this->getContextObjId(), "integer") .
304 " AND context_obj_type = " . $ilDB->quote($this->getContextObjType(), "text");
305 if ($a_include_sub_obj_id) {
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 $result[] = $rec;
315 }
316
317 return $result;
318 }
319
324 public function queryTitleForId()
325 {
327 die("ilCustomBlock::queryTitleForId is deprecated");
328 /*
329 $query = "SELECT id ".
330 "FROM il_custom_block ".
331 "WHERE "."";
332
333 $set = $ilDB->query($query);
334 $result = array();
335 while($rec = $set->fetchRow(ilDBConstants::FETCHMODE_ASSOC))
336 {
337 $result[] = $rec;
338 }
339
340 return $result;
341 */
342 }
343
348 public function queryCntBlockForContext()
349 {
351
352 $query = "SELECT count(*) as cnt " .
353 "FROM il_custom_block " .
354 "WHERE " .
355 "context_obj_id = " . $ilDB->quote($this->getContextObjId(), "integer") .
356 " AND context_obj_type = " . $ilDB->quote($this->getContextObjType(), "text") .
357 " AND context_sub_obj_id = " . $ilDB->quote($this->getContextSubObjId(), "integer") .
358 " AND " . $ilDB->equals("context_sub_obj_type", $this->getContextSubObjType(), "text", true) .
359 " AND type = " . $ilDB->quote($this->getType(), "text") . "";
360
361 $set = $ilDB->query($query);
362 $result = array();
363 while ($rec = $ilDB->fetchAssoc($set)) {
364 $result[] = $rec;
365 }
366
367 return $result;
368 }
369
370 public static function multiBlockQuery($a_context_obj_type, array $a_context_obj_ids)
371 {
372 global $DIC;
373
374 $ilDB = $DIC->database();
375
376 $query = "SELECT id, context_obj_id, context_obj_type, context_sub_obj_id, context_sub_obj_type, type, title " .
377 "FROM il_custom_block " .
378 "WHERE " .
379 $ilDB->in("context_obj_id", $a_context_obj_ids, "", "integer") .
380 " AND context_obj_type = " . $ilDB->quote($a_context_obj_type, "text") .
381 " ORDER BY title";
382 $set = $ilDB->query($query);
383 $result = array();
384 while ($rec = $ilDB->fetchAssoc($set)) {
385 $result[] = $rec;
386 }
387
388 return $result;
389 }
390}
$result
An exception for terminatinating execution or to throw for unit testing.
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.
$query
global $ilDB
$a_type
Definition: workflow.php:92
$DIC
Definition: xapitoken.php:46