ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.CharacteristicDBRepo.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Style\Content;
22
25
30{
31 protected ilDBInterface $db;
33
34 public function __construct(
37 ) {
38 $this->db = $db;
39 $this->factory = $factory;
40 }
41
42 public function addCharacteristic(
43 int $style_id,
44 string $type,
45 string $char,
46 bool $hidden = false,
47 int $order_nr = 0,
48 bool $outdated = false
49 ): void {
50 $db = $this->db;
51
52 $db->insert("style_char", [
53 "style_id" => ["integer", $style_id],
54 "type" => ["text", $type],
55 "characteristic" => ["text", $char],
56 "hide" => ["integer", $hidden],
57 "order_nr" => ["integer", $order_nr],
58 "outdated" => ["integer", $outdated]
59 ]);
60 }
61
62 public function exists(
63 int $style_id,
64 string $type,
65 string $char
66 ): bool {
67 $db = $this->db;
68
69 $set = $db->queryF(
70 "SELECT * FROM style_char " .
71 " WHERE style_id = %s AND type = %s AND characteristic = %s",
72 ["integer", "text", "text"],
73 [$style_id, $type, $char]
74 );
75 if ($db->fetchAssoc($set)) {
76 return true;
77 }
78 return false;
79 }
80
81 public function getByKey(
82 int $style_id,
83 string $type,
84 string $characteristic
85 ): ?Characteristic {
86 $db = $this->db;
87
88 $set = $db->queryF(
89 "SELECT * FROM style_char " .
90 " WHERE style_id = %s AND type = %s AND characteristic = %s ",
91 ["integer", "text", "text"],
92 [$style_id, $type, $characteristic]
93 );
94 if ($rec = $db->fetchAssoc($set)) {
95 $set2 = $db->queryF(
96 "SELECT * FROM style_char_title " .
97 " WHERE style_id = %s AND type = %s AND characteristic = %s ",
98 ["integer", "text", "text"],
99 [$style_id, $type, $characteristic]
100 );
101 $titles = [];
102 while ($rec2 = $db->fetchAssoc($set2)) {
103 $titles[$rec2["lang"]] = $rec2["title"];
104 }
105 return $this->factory->characteristic(
106 $type,
107 $characteristic,
108 (bool) $rec["hide"],
109 $titles,
110 $style_id,
111 (int) $rec["order_nr"],
112 (bool) $rec["outdated"]
113 );
114 }
115 return null;
116 }
117
118 public function getByType(
119 int $style_id,
120 string $type
121 ): array {
122 return $this->getByTypes(
123 $style_id,
124 [$type]
125 );
126 }
127
128 public function getByTypes(
129 int $style_id,
130 array $types,
131 bool $include_hidden = true,
132 bool $include_outdated = true
133 ): array {
134 $db = $this->db;
135
136 $set = $db->queryF(
137 "SELECT * FROM style_char " .
138 " WHERE style_id = %s AND " . $db->in("type", $types, false, "text") .
139 " ORDER BY order_nr, type, characteristic",
140 ["integer"],
141 [$style_id]
142 );
143 $chars = [];
144 while ($rec = $db->fetchAssoc($set)) {
145 if (($rec["hide"] && !$include_hidden) ||
146 ($rec["outdated"] && !$include_outdated)) {
147 continue;
148 }
149
150 $set2 = $db->queryF(
151 "SELECT * FROM style_char_title " .
152 " WHERE style_id = %s AND type = %s AND characteristic = %s ",
153 ["integer", "text", "text"],
154 [$style_id, $rec["type"], $rec["characteristic"]]
155 );
156 $titles = [];
157 while ($rec2 = $db->fetchAssoc($set2)) {
158 $titles[$rec2["lang"]] = $rec2["title"];
159 }
160 $chars[] = $this->factory->characteristic(
161 $rec["type"],
162 $rec["characteristic"],
163 (bool) $rec["hide"],
164 $titles,
165 $style_id,
166 (int) $rec["order_nr"],
167 (bool) $rec["outdated"]
168 );
169 }
170 return $chars;
171 }
172
177 public function getBySuperType(
178 int $style_id,
179 string $super_type
180 ): array {
181 $stypes = ilObjStyleSheet::_getStyleSuperTypes();
182 $types = $stypes[$super_type];
183
184 return $this->getByTypes(
185 $style_id,
186 $types
187 );
188 }
189
190
194 public function saveTitles(
195 int $style_id,
196 string $type,
197 string $characteristic,
198 array $titles
199 ): void {
200 $db = $this->db;
201
202 $db->manipulateF(
203 "DELETE FROM style_char_title " .
204 " WHERE style_id = %s AND type = %s AND characteristic = %s ",
205 ["integer", "text", "text"],
206 [$style_id, $type, $characteristic]
207 );
208
209 foreach ($titles as $l => $title) {
210 $this->addTitle(
211 $style_id,
212 $type,
213 $characteristic,
214 $l,
215 $title
216 );
217 }
218 }
219
220 public function addTitle(
221 int $style_id,
222 string $type,
223 string $characteristic,
224 string $lang,
225 string $title
226 ): void {
227 $db = $this->db;
228
229 $db->insert("style_char_title", [
230 "style_id" => ["integer", $style_id],
231 "type" => ["text", $type],
232 "characteristic" => ["text", $characteristic],
233 "lang" => ["text", $lang],
234 "title" => ["text", $title]
235 ]);
236 }
237
238
239 public function cloneAllFromStyle(
240 int $from_style_id,
241 int $to_style_id
242 ): void {
243 $set = $this->db->queryF(
244 "SELECT * FROM style_char " .
245 " WHERE style_id = %s ",
246 ["integer"],
247 [$from_style_id]
248 );
249 while ($rec = $this->db->fetchAssoc($set)) {
250 $this->db->insert("style_char", [
251 "style_id" => ["integer", $to_style_id],
252 "type" => ["text", $rec["type"]],
253 "characteristic" => ["text", $rec["characteristic"]],
254 "hide" => ["integer", (int) ($rec["hide"] ?? 0)],
255 "outdated" => ["integer", (int) ($rec["outdated"] ?? 0)],
256 "order_nr" => ["integer", (int) ($rec["order_nr"] ?? 0)]
257 ]);
258 }
259 $set = $this->db->queryF(
260 "SELECT * FROM style_char_title " .
261 " WHERE style_id = %s ",
262 ["integer"],
263 [$from_style_id]
264 );
265 while ($rec = $this->db->fetchAssoc($set)) {
266 $this->db->insert("style_char_title", [
267 "style_id" => ["integer", $to_style_id],
268 "type" => ["text", $rec["type"]],
269 "characteristic" => ["text", $rec["characteristic"]],
270 "lang" => ["text", $rec["lang"]],
271 "title" => ["text", $rec["title"]]
272 ]);
273 }
274 }
275
279 public function saveHidden(
280 int $style_id,
281 string $type,
282 string $characteristic,
283 bool $hide
284 ): void {
285 $db = $this->db;
286
287 $db->update(
288 "style_char",
289 [
290 "hide" => ["integer", $hide]
291 ],
292 [ // where
293 "style_id" => ["integer", $style_id],
294 "type" => ["text", $type],
295 "characteristic" => ["text", $characteristic]
296 ]
297 );
298 }
299
303 public function saveOutdated(
304 int $style_id,
305 string $type,
306 string $characteristic,
307 bool $outdated
308 ): void {
309 $db = $this->db;
310
311 $db->update(
312 "style_char",
313 [
314 "outdated" => ["integer", $outdated]
315 ],
316 [ // where
317 "style_id" => ["integer", $style_id],
318 "type" => ["text", $type],
319 "characteristic" => ["text", $characteristic]
320 ]
321 );
322 }
323
324 public function isOutdated(
325 int $style_id,
326 string $type,
327 string $characteristic
328 ): bool {
329 $db = $this->db;
330
331 $set = $db->queryF(
332 "SELECT outdated FROM style_char " .
333 " WHERE style_id = %s AND type = %s AND characteristic = %s",
334 ["integer", "text", "text"],
335 [$style_id, $type, $characteristic]
336 );
337 if ($rec = $db->fetchAssoc($set)) {
338 return (bool) $rec["outdated"];
339 }
340 return false;
341 }
342
343 public function saveOrderNr(
344 int $style_id,
345 string $type,
346 string $characteristic,
347 int $order_nr
348 ): void {
349 $db = $this->db;
350
351 $db->update(
352 "style_char",
353 [
354 "order_nr" => ["integer", $order_nr]
355 ],
356 [ // where
357 "style_id" => ["integer", $style_id],
358 "type" => ["text", $type],
359 "characteristic" => ["text", $characteristic]
360 ]
361 );
362 }
363
364 public function deleteCharacteristic(
365 int $style_id,
366 string $type,
367 string $tag,
368 string $class
369 ): void {
370 $db = $this->db;
371
372 // delete characteristic record
373 $db->manipulateF(
374 "DELETE FROM style_char WHERE style_id = %s AND type = %s AND characteristic = %s",
375 array("integer", "text", "text"),
376 array($style_id, $type, $class)
377 );
378
379 // delete parameter records
380 $db->manipulateF(
381 "DELETE FROM style_parameter WHERE style_id = %s AND tag = %s AND type = %s AND class = %s",
382 array("integer", "text", "text", "text"),
383 array($style_id, $tag, $type, $class)
384 );
385 }
386
387 //
388 // Parameter
389 //
390
391 public function replaceParameter(
392 int $style_id,
393 string $a_tag,
394 string $a_class,
395 string $a_par,
396 string $a_val,
397 string $a_type,
398 int $a_mq_id = 0,
399 bool $a_custom = false
400 ): void {
401 $db = $this->db;
402
403 $set = $db->queryF(
404 "SELECT * FROM style_parameter " .
405 " WHERE style_id = %s AND tag = %s AND class = %s AND mq_id = %s " .
406 " AND custom = %s AND type = %s AND parameter = %s ",
407 ["integer", "text", "text", "integer", "integer", "text", "text"],
408 [$style_id, $a_tag, $a_class, $a_mq_id, $a_custom, $a_type, $a_par]
409 );
410
411 if ($set->fetchRow()) {
412 $db->update(
413 "style_parameter",
414 [
415 "value" => ["text", $a_val]
416 ],
417 [ // where
418 "style_id" => ["integer", $style_id],
419 "tag" => ["text", $a_tag],
420 "class" => ["text", $a_class],
421 "mq_id" => ["integer", $a_mq_id],
422 "custom" => ["integer", $a_custom],
423 "type" => ["text", $a_type],
424 "parameter" => ["text", $a_par]
425 ]
426 );
427 } else {
428 $id = $db->nextId("style_parameter");
429 $db->insert("style_parameter", [
430 "id" => ["integer", $id],
431 "value" => ["text", $a_val],
432 "style_id" => ["integer", $style_id],
433 "tag" => ["text", $a_tag],
434 "class" => ["text", $a_class],
435 "type" => ["text", $a_type],
436 "parameter" => ["text", $a_par],
437 "mq_id" => ["integer", $a_mq_id],
438 "custom" => ["integer", $a_custom]
439 ]);
440 }
441 }
442
444 int $style_id,
445 string $type,
446 string $characteristic
447 ): array {
448 $set = $this->db->queryF(
449 "SELECT * FROM style_parameter " .
450 " WHERE style_id = %s AND class = %s AND type = %s",
451 ["integer", "string", "string"],
452 [$style_id, $characteristic, $type]
453 );
454 $data = [];
455 while ($rec = $this->db->fetchAssoc($set)) {
456 $data[] = $rec;
457 }
458 return $data;
459 }
460
461 public function deleteParameter(
462 int $style_id,
463 string $tag,
464 string $class,
465 string $par,
466 string $type,
467 int $mq_id = 0,
468 bool $custom = false
469 ): void {
470 $db = $this->db;
471
472 $q = "DELETE FROM style_parameter WHERE " .
473 " style_id = " . $db->quote($style_id, "integer") . " AND " .
474 " tag = " . $db->quote($tag, "text") . " AND " .
475 " class = " . $db->quote($class, "text") . " AND " .
476 " mq_id = " . $db->quote($mq_id, "integer") . " AND " .
477 " custom = " . $db->quote($custom, "integer") . " AND " .
478 " " . $db->equals("type", $type, "text", true) . " AND " .
479 " parameter = " . $db->quote($par, "text");
480
481 $db->manipulate($q);
482 }
483
484 public function updateColorName(
485 int $style_id,
486 string $old_name,
487 string $new_name
488 ): void {
489 if ($old_name == $new_name) {
490 return;
491 }
492
493 $db = $this->db;
494
495 $color_attributes = [
496 "background-color",
497 "color",
498 "border-color",
499 "border-top-color",
500 "border-bottom-color",
501 "border-left-color",
502 "border-right-color",
503 ];
504
505 $set = $db->queryF(
506 "SELECT * FROM style_parameter " .
507 " WHERE style_id = %s AND " . $db->in("parameter", $color_attributes, false, "text"),
508 ["integer"],
509 [$style_id]
510 );
511 while ($rec = $db->fetchAssoc($set)) {
512 if ($rec["value"] == "!" . $old_name ||
513 is_int(strpos($rec["value"], "!" . $old_name . "("))) {
514 // parameter is based on color -> rename it
515 $this->replaceParameter(
516 $style_id,
517 $rec["tag"],
518 $rec["class"],
519 $rec["parameter"],
520 str_replace($old_name, $new_name, $rec["value"]),
521 $rec["type"],
522 $rec["mq_id"],
523 (bool) $rec["custom"]
524 );
525 }
526 }
527 }
528}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
factory()
getByKey(int $style_id, string $type, string $characteristic)
saveOrderNr(int $style_id, string $type, string $characteristic, int $order_nr)
getBySuperType(int $style_id, string $super_type)
Get characteristics by supertype.
replaceParameter(int $style_id, string $a_tag, string $a_class, string $a_par, string $a_val, string $a_type, int $a_mq_id=0, bool $a_custom=false)
__construct(ilDBInterface $db, InternalDataService $factory)
saveTitles(int $style_id, string $type, string $characteristic, array $titles)
Save titles for characteristic.
cloneAllFromStyle(int $from_style_id, int $to_style_id)
getAllParametersOfCharacteristic(int $style_id, string $type, string $characteristic)
deleteCharacteristic(int $style_id, string $type, string $tag, string $class)
isOutdated(int $style_id, string $type, string $characteristic)
deleteParameter(int $style_id, string $tag, string $class, string $par, string $type, int $mq_id=0, bool $custom=false)
addTitle(int $style_id, string $type, string $characteristic, string $lang, string $title)
saveHidden(int $style_id, string $type, string $characteristic, bool $hide)
Save characteristic hidden status.
updateColorName(int $style_id, string $old_name, string $new_name)
getByTypes(int $style_id, array $types, bool $include_hidden=true, bool $include_outdated=true)
exists(int $style_id, string $type, string $char)
addCharacteristic(int $style_id, string $type, string $char, bool $hidden=false, int $order_nr=0, bool $outdated=false)
saveOutdated(int $style_id, string $type, string $characteristic, bool $outdated)
Save characteristic outdated status.
Characteristic (Class) of style.
Class ilObjStyleSheet.
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ilDBInterface.
update(string $table_name, array $values, array $where)
@description $where MUST contain existing columns only.
insert(string $table_name, array $values)
nextId(string $table_name)
equals(string $columns, $value, string $type, bool $emptyOrNull=false)
quote($value, string $type)
manipulate(string $query)
Run a (write) Query on the database.
manipulateF(string $query, array $types, array $values)
fetchAssoc(ilDBStatement $statement)
queryF(string $query, array $types, array $values)
in(string $field, array $values, bool $negate=false, string $type="")
if(!file_exists('../ilias.ini.php'))
$q
Definition: shib_logout.php:23
$lang
Definition: xapiexit.php:25