ILIAS  release_8 Revision v8.24
class.CharacteristicDBRepo.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
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("SELECT * FROM style_char " .
244 " WHERE style_id = %s ",
245 ["integer"],
246 [$from_style_id]
247 );
248 while ($rec = $this->db->fetchAssoc($set)) {
249 $this->db->insert("style_char", [
250 "style_id" => ["integer", $to_style_id],
251 "type" => ["text", $rec["type"]],
252 "characteristic" => ["text", $rec["characteristic"]],
253 "hide" => ["integer", (int) ($rec["hide"] ?? 0)],
254 "outdated" => ["integer", (int) ($rec["outdated"] ?? 0)],
255 "order_nr" => ["integer", (int) ($rec["order_nr"] ?? 0)]
256 ]);
257 }
258 $set = $this->db->queryF("SELECT * FROM style_char_title " .
259 " WHERE style_id = %s ",
260 ["integer"],
261 [$from_style_id]
262 );
263 while ($rec = $this->db->fetchAssoc($set)) {
264 $this->db->insert("style_char_title", [
265 "style_id" => ["integer", $to_style_id],
266 "type" => ["text", $rec["type"]],
267 "characteristic" => ["text", $rec["characteristic"]],
268 "lang" => ["text", $rec["lang"]],
269 "title" => ["text", $rec["title"]]
270 ]);
271 }
272 }
273
277 public function saveHidden(
278 int $style_id,
279 string $type,
280 string $characteristic,
281 bool $hide
282 ): void {
283 $db = $this->db;
284
285 $db->update(
286 "style_char",
287 [
288 "hide" => ["integer", $hide]
289 ],
290 [ // where
291 "style_id" => ["integer", $style_id],
292 "type" => ["text", $type],
293 "characteristic" => ["text", $characteristic]
294 ]
295 );
296 }
297
301 public function saveOutdated(
302 int $style_id,
303 string $type,
304 string $characteristic,
305 bool $outdated
306 ): void {
307 $db = $this->db;
308
309 $db->update(
310 "style_char",
311 [
312 "outdated" => ["integer", $outdated]
313 ],
314 [ // where
315 "style_id" => ["integer", $style_id],
316 "type" => ["text", $type],
317 "characteristic" => ["text", $characteristic]
318 ]
319 );
320 }
321
322 public function isOutdated(
323 int $style_id,
324 string $type,
325 string $characteristic
326 ): bool {
327 $db = $this->db;
328
329 $set = $db->queryF("SELECT outdated FROM style_char " .
330 " WHERE style_id = %s AND type = %s AND characteristic = %s",
331 ["integer", "text", "text"],
332 [$style_id, $type, $characteristic]
333 );
334 if ($rec = $db->fetchAssoc($set)) {
335 return (bool) $rec["outdated"];
336 }
337 return false;
338 }
339
340 public function saveOrderNr(
341 int $style_id,
342 string $type,
343 string $characteristic,
344 int $order_nr
345 ): void {
346 $db = $this->db;
347
348 $db->update(
349 "style_char",
350 [
351 "order_nr" => ["integer", $order_nr]
352 ],
353 [ // where
354 "style_id" => ["integer", $style_id],
355 "type" => ["text", $type],
356 "characteristic" => ["text", $characteristic]
357 ]
358 );
359 }
360
361 public function deleteCharacteristic(
362 int $style_id,
363 string $type,
364 string $tag,
365 string $class
366 ): void {
367 $db = $this->db;
368
369 // delete characteristic record
370 $db->manipulateF(
371 "DELETE FROM style_char WHERE style_id = %s AND type = %s AND characteristic = %s",
372 array("integer", "text", "text"),
373 array($style_id, $type, $class)
374 );
375
376 // delete parameter records
377 $db->manipulateF(
378 "DELETE FROM style_parameter WHERE style_id = %s AND tag = %s AND type = %s AND class = %s",
379 array("integer", "text", "text", "text"),
380 array($style_id, $tag, $type, $class)
381 );
382 }
383
384 //
385 // Parameter
386 //
387
388 public function replaceParameter(
389 int $style_id,
390 string $a_tag,
391 string $a_class,
392 string $a_par,
393 string $a_val,
394 string $a_type,
395 int $a_mq_id = 0,
396 bool $a_custom = false
397 ): void {
398 $db = $this->db;
399
400 $set = $db->queryF(
401 "SELECT * FROM style_parameter " .
402 " WHERE style_id = %s AND tag = %s AND class = %s AND mq_id = %s " .
403 " AND custom = %s AND type = %s AND parameter = %s ",
404 ["integer", "text", "text", "integer", "integer", "text", "text"],
405 [$style_id, $a_tag, $a_class, $a_mq_id, $a_custom, $a_type, $a_par]
406 );
407
408 if ($set->fetchRow()) {
409 $db->update(
410 "style_parameter",
411 [
412 "value" => ["text", $a_val]
413 ],
414 [ // where
415 "style_id" => ["integer", $style_id],
416 "tag" => ["text", $a_tag],
417 "class" => ["text", $a_class],
418 "mq_id" => ["integer", $a_mq_id],
419 "custom" => ["integer", $a_custom],
420 "type" => ["text", $a_type],
421 "parameter" => ["text", $a_par]
422 ]
423 );
424 } else {
425 $id = $db->nextId("style_parameter");
426 $db->insert("style_parameter", [
427 "id" => ["integer", $id],
428 "value" => ["text", $a_val],
429 "style_id" => ["integer", $style_id],
430 "tag" => ["text", $a_tag],
431 "class" => ["text", $a_class],
432 "type" => ["text", $a_type],
433 "parameter" => ["text", $a_par],
434 "mq_id" => ["integer", $a_mq_id],
435 "custom" => ["integer", $a_custom]
436 ]);
437 }
438 }
439
440 public function deleteParameter(
441 int $style_id,
442 string $tag,
443 string $class,
444 string $par,
445 string $type,
446 int $mq_id = 0,
447 bool $custom = false
448 ): void {
449 $db = $this->db;
450
451 $q = "DELETE FROM style_parameter WHERE " .
452 " style_id = " . $db->quote($style_id, "integer") . " AND " .
453 " tag = " . $db->quote($tag, "text") . " AND " .
454 " class = " . $db->quote($class, "text") . " AND " .
455 " mq_id = " . $db->quote($mq_id, "integer") . " AND " .
456 " custom = " . $db->quote($custom, "integer") . " AND " .
457 " " . $db->equals("type", $type, "text", true) . " AND " .
458 " parameter = " . $db->quote($par, "text");
459
460 $db->manipulate($q);
461 }
462
463 public function updateColorName(
464 int $style_id,
465 string $old_name,
466 string $new_name
467 ): void {
468 if ($old_name == $new_name) {
469 return;
470 }
471
472 $db = $this->db;
473
474 $color_attributes = [
475 "background-color",
476 "color",
477 "border-color",
478 "border-top-color",
479 "border-bottom-color",
480 "border-left-color",
481 "border-right-color",
482 ];
483
484 $set = $db->queryF(
485 "SELECT * FROM style_parameter " .
486 " WHERE style_id = %s AND " . $db->in("parameter", $color_attributes, false, "text"),
487 ["integer"],
488 [$style_id]
489 );
490 while ($rec = $db->fetchAssoc($set)) {
491 if ($rec["value"] == "!" . $old_name ||
492 is_int(strpos($rec["value"], "!" . $old_name . "("))) {
493 // parameter is based on color -> rename it
494 $this->replaceParameter(
495 $style_id,
496 $rec["tag"],
497 $rec["class"],
498 $rec["parameter"],
499 str_replace($old_name, $new_name, $rec["value"]),
500 $rec["type"],
501 $rec["mq_id"],
502 $rec["custom"]
503 );
504 }
505 }
506 }
507}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
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)
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
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="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$type
$lang
Definition: xapiexit.php:26