ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCustomBlock.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26{
27 protected ilDBInterface $db;
28 protected int $id = 0;
29 protected int $context_obj_id = 0;
30 protected string $context_obj_type = "";
31 protected int $context_sub_obj_id = 0;
32 protected string $context_sub_obj_type = "";
33 protected string $type = "";
34 protected string $title = "";
35
36 public function __construct(
37 int $a_id = 0
38 ) {
39 global $DIC;
40
41 $this->db = $DIC->database();
42 if ($a_id > 0) {
43 $this->setId($a_id);
44 $this->read();
45 }
46 }
47
48 public function setId(int $a_id): void
49 {
50 $this->id = $a_id;
51 }
52
53 public function getId(): int
54 {
55 return $this->id;
56 }
57
58 public function setContextObjId(int $a_context_obj_id): void
59 {
60 $this->context_obj_id = $a_context_obj_id;
61 }
62
63 public function getContextObjId(): int
64 {
66 }
67
68 public function setContextObjType(string $a_context_obj_type): void
69 {
70 $this->context_obj_type = $a_context_obj_type;
71 }
72
73 public function getContextObjType(): string
74 {
76 }
77
78 public function setContextSubObjId(int $a_context_sub_obj_id): void
79 {
80 $this->context_sub_obj_id = $a_context_sub_obj_id;
81 }
82
83 public function getContextSubObjId(): int
84 {
86 }
87
88 public function setContextSubObjType(string $a_context_sub_obj_type): void
89 {
90 $this->context_sub_obj_type = $a_context_sub_obj_type;
91 }
92
93 public function getContextSubObjType(): string
94 {
96 }
97
101 public function setType(string $a_type): void
102 {
103 $this->type = $a_type;
104 }
105
106 public function getType(): string
107 {
108 return $this->type;
109 }
110
111 public function setTitle(string $a_title): void
112 {
113 $this->title = $a_title;
114 }
115
116 public function getTitle(): string
117 {
118 return $this->title;
119 }
120
121 public function create(): void
122 {
124
125 $this->setId($ilDB->nextId("il_custom_block"));
126 $query = "INSERT INTO il_custom_block (" .
127 " id" .
128 ", context_obj_id" .
129 ", context_obj_type" .
130 ", context_sub_obj_id" .
131 ", context_sub_obj_type" .
132 ", type" .
133 ", title" .
134 " ) VALUES (" .
135 $ilDB->quote($this->getId(), "integer")
136 . "," . $ilDB->quote($this->getContextObjId(), "integer")
137 . "," . $ilDB->quote($this->getContextObjType(), "text")
138 . "," . $ilDB->quote($this->getContextSubObjId(), "integer")
139 . "," . $ilDB->quote($this->getContextSubObjType(), "text")
140 . "," . $ilDB->quote($this->getType(), "text")
141 . "," . $ilDB->quote($this->getTitle(), "text") . ")";
142 $ilDB->manipulate($query);
143 }
144
145 public function read(): void
146 {
148
149 $query = "SELECT * FROM il_custom_block WHERE id = " .
150 $ilDB->quote($this->getId(), "integer");
151 $set = $ilDB->query($query);
152 $rec = $ilDB->fetchAssoc($set);
153
154 $this->setContextObjId((int) $rec["context_obj_id"]);
155 $this->setContextObjType($rec["context_obj_type"]);
156 $this->setContextSubObjId((int) $rec["context_sub_obj_id"]);
157 $this->setContextSubObjType((string) $rec["context_sub_obj_type"]);
158 $this->setType($rec["type"]);
159 $this->setTitle((string) $rec["title"]);
160 }
161
162 public function update(): void
163 {
165
166 $query = "UPDATE il_custom_block SET " .
167 " context_obj_id = " . $ilDB->quote($this->getContextObjId(), "integer") .
168 ", context_obj_type = " . $ilDB->quote($this->getContextObjType(), "text") .
169 ", context_sub_obj_id = " . $ilDB->quote($this->getContextSubObjId(), "integer") .
170 ", context_sub_obj_type = " . $ilDB->quote($this->getContextSubObjType(), "text") .
171 ", type = " . $ilDB->quote($this->getType(), "text") .
172 ", title = " . $ilDB->quote($this->getTitle(), "text") .
173 " WHERE id = " . $ilDB->quote($this->getId(), "integer");
174
175 $ilDB->manipulate($query);
176 }
177
178 public function delete(): void
179 {
181
182 $query = "DELETE FROM il_custom_block" .
183 " WHERE id = " . $ilDB->quote($this->getId(), "integer");
184
185 $ilDB->manipulate($query);
186 }
187
191 public function queryBlocksForContext(
192 bool $a_include_sub_obj = true
193 ): array {
194 $ilDB = $this->db;
195
196 $query = "SELECT id, context_obj_id, context_obj_type, context_sub_obj_id, context_sub_obj_type, type, title " .
197 "FROM il_custom_block " .
198 "WHERE " .
199 "context_obj_id = " . $ilDB->quote($this->getContextObjId(), "integer") .
200 " AND context_obj_type = " . $ilDB->quote($this->getContextObjType(), "text");
201 if ($a_include_sub_obj) {
202 $query .= " AND context_sub_obj_id = " . $ilDB->quote($this->getContextSubObjId(), "integer") .
203 " AND " . $ilDB->equals("context_sub_obj_type", $this->getContextSubObjType(), "text", true);
204 //" AND context_sub_obj_type = ".$ilDB->quote($this->getContextSubObjType(), "text")."";
205 }
206 //echo "$query";
207 $set = $ilDB->query($query);
208 $result = array();
209 while ($rec = $ilDB->fetchAssoc($set)) {
210 $result[] = $rec;
211 }
212
213 return $result;
214 }
215
216 public function queryCntBlockForContext(): array
217 {
218 $ilDB = $this->db;
219
220 $query = "SELECT count(*) as cnt " .
221 "FROM il_custom_block " .
222 "WHERE " .
223 "context_obj_id = " . $ilDB->quote($this->getContextObjId(), "integer") .
224 " AND context_obj_type = " . $ilDB->quote($this->getContextObjType(), "text") .
225 " AND context_sub_obj_id = " . $ilDB->quote($this->getContextSubObjId(), "integer") .
226 " AND " . $ilDB->equals("context_sub_obj_type", $this->getContextSubObjType(), "text", true) .
227 " AND type = " . $ilDB->quote($this->getType(), "text");
228
229 $set = $ilDB->query($query);
230 $result = array();
231 while ($rec = $ilDB->fetchAssoc($set)) {
232 $result[] = $rec;
233 }
234
235 return $result;
236 }
237
238 public static function multiBlockQuery(
239 string $a_context_obj_type,
240 array $a_context_obj_ids
241 ): array {
242 global $DIC;
243
244 $ilDB = $DIC->database();
245
246 $query = "SELECT id, context_obj_id, context_obj_type, context_sub_obj_id, context_sub_obj_type, type, title " .
247 "FROM il_custom_block " .
248 "WHERE " .
249 $ilDB->in("context_obj_id", $a_context_obj_ids, false, "integer") .
250 " AND context_obj_type = " . $ilDB->quote($a_context_obj_type, "text") .
251 " ORDER BY title";
252 $set = $ilDB->query($query);
253 $result = array();
254 while ($rec = $ilDB->fetchAssoc($set)) {
255 $result[] = $rec;
256 }
257
258 return $result;
259 }
260}
This is the super class of all custom blocks.
setType(string $a_type)
ilDBInterface $db
queryBlocksForContext(bool $a_include_sub_obj=true)
Query BlocksForContext.
__construct(int $a_id=0)
setTitle(string $a_title)
setContextSubObjType(string $a_context_sub_obj_type)
setContextObjType(string $a_context_obj_type)
static multiBlockQuery(string $a_context_obj_type, array $a_context_obj_ids)
setContextSubObjId(int $a_context_sub_obj_id)
setContextObjId(int $a_context_obj_id)
Interface ilDBInterface.
global $DIC
Definition: shib_login.php:26