ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.CharacteristicManager.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Style\Content;
22
24use ilObjUser;
26
32{
35 protected ilObjUser $user;
38 protected int $style_id;
39
40 public function __construct(
41 int $style_id,
43 CharacteristicDBRepo $char_repo,
44 CharacteristicCopyPasteSessionRepo $char_copy_paste_repo,
47 ) {
48 $this->user = $user;
49 $this->repo = $char_repo;
50 $this->color_repo = $color_repo;
51 $this->access_manager = $access_manager;
52 $this->session = $char_copy_paste_repo;
53 $this->style_id = $style_id;
54 }
55
56 public function addCharacteristic(
57 string $type,
58 string $char,
59 bool $hidden = false
60 ): void {
61 $this->repo->addCharacteristic(
62 $this->style_id,
63 $type,
64 $char,
65 $hidden
66 );
67
68 ilObjStyleSheet::_writeUpToDate($this->style_id, false);
69 }
70
74 public function exists(
75 string $type,
76 string $char
77 ): bool {
78 return $this->repo->exists(
79 $this->style_id,
80 $type,
81 $char
82 );
83 }
84
88 public function getByKey(
89 string $type,
90 string $characteristic
91 ): ?Characteristic {
92 return $this->repo->getByKey(
93 $this->style_id,
94 $type,
95 $characteristic
96 );
97 }
98
102 public function getByType(
103 string $type
104 ): array {
105 return $this->repo->getByType(
106 $this->style_id,
107 $type
108 );
109 }
110
114 public function getByTypes(
115 array $types,
116 bool $include_hidden = true,
117 bool $include_outdated = true
118 ): array {
119 return $this->repo->getByTypes(
120 $this->style_id,
121 $types,
122 $include_hidden,
123 $include_outdated
124 );
125 }
126
130 public function getBySuperType(
131 string $supertype
132 ): array {
133 return $this->repo->getBySuperType(
134 $this->style_id,
135 $supertype
136 );
137 }
138
142 public function getPresentationTitle(
143 string $type,
144 string $characteristic,
145 bool $fallback_to_characteristic = true
146 ): string {
147 $char = $this->repo->getByKey(
148 $this->style_id,
149 $type,
150 $characteristic
151 );
152
153 $titles = $char ? $char->getTitles() : [];
154
155 $lang = $this->user->getLanguage();
156
157 if (($titles[$lang] ?? "") != "") {
158 return $titles[$lang];
159 }
160 if ($fallback_to_characteristic) {
161 return $characteristic;
162 }
163 return "";
164 }
165
170 public function saveTitles(
171 string $type,
172 string $characteristic,
173 array $titles
174 ): void {
175 if (!$this->access_manager->checkWrite()) {
176 throw new ContentStyleNoPermissionException("No write permission for style.");
177 }
178 $this->repo->saveTitles(
179 $this->style_id,
180 $type,
181 $characteristic,
182 $titles
183 );
184 }
185
189 public function saveHidden(
190 string $type,
191 string $characteristic,
192 bool $hide
193 ): void {
194 if (!$this->access_manager->checkWrite()) {
195 throw new ContentStyleNoPermissionException("No write permission for style.");
196 }
197 $this->repo->saveHidden(
198 $this->style_id,
199 $type,
200 $characteristic,
201 $hide
202 );
203 }
204
208 public function saveOutdated(
209 string $type,
210 string $characteristic,
211 bool $outdated
212 ): void {
213 if (!$this->access_manager->checkWrite()) {
214 throw new ContentStyleNoPermissionException("No write permission for style.");
215 }
216 $this->repo->saveOutdated(
217 $this->style_id,
218 $type,
219 $characteristic,
220 $outdated
221 );
222 }
223
224 public function isOutdated(
225 string $type,
226 string $characteristic
227 ): bool {
228 return $this->repo->isOutdated(
229 $this->style_id,
230 $type,
231 $characteristic
232 );
233 }
234
239 public function saveOrderNrs(
240 string $type,
241 array $order_nrs
242 ): void {
243 if (!$this->access_manager->checkWrite()) {
244 throw new ContentStyleNoPermissionException("No write permission for style.");
245 }
246
247 asort($order_nrs, SORT_NUMERIC);
248
249 foreach ($order_nrs as $char => $nr) {
250 $this->repo->saveOrderNr(
251 $this->style_id,
252 $type,
253 $char,
254 (int) $nr
255 );
256 }
257 }
258
259
264 public function deleteCharacteristic(
265 string $type,
266 string $class
267 ): void {
268 if (!$this->access_manager->checkWrite()) {
269 throw new ContentStyleNoPermissionException("No write permission for style.");
270 }
271 $tag = ilObjStyleSheet::_determineTag($type);
272
273 // check, if characteristic is not a core style
274 $core_styles = ilObjStyleSheet::_getCoreStyles();
275 if (empty($core_styles[$type . "." . $tag . "." . $class])) {
276 $this->repo->deleteCharacteristic(
277 $this->style_id,
278 $type,
279 $tag,
280 $class
281 );
282 }
283
284 ilObjStyleSheet::_writeUpToDate($this->style_id, false);
285 }
286
287 public function setCopyCharacteristics(
288 string $style_type,
289 array $characteristics
290 ): void {
291 $this->session->set($this->style_id, $style_type, $characteristics);
292 }
293
297 public function hasCopiedCharacteristics(string $style_type): bool
298 {
299 return $this->session->hasEntries($style_type);
300 }
301
302 public function clearCopyCharacteristics(): void
303 {
304 $this->session->clear();
305 }
306
308 {
309 $data = $this->session->getData();
310 return (int) $data->style_id;
311 }
312
313 public function getCopyCharacteristicStyleType(): string
314 {
315 $data = $this->session->getData();
316 return $data->style_type;
317 }
318
319 public function getCopyCharacteristics(): array
320 {
321 $data = $this->session->getData();
322 return $data->characteristics;
323 }
324
330 int $source_style_id,
331 string $source_style_type,
332 string $source_char,
333 string $new_char,
334 array $new_titles
335 ): void {
336 if (!$this->access_manager->checkWrite()) {
337 throw new ContentStyleNoPermissionException("No write permission for style.");
338 }
339
340 if ($this->exists($source_style_type, $new_char)) {
341 $target_char = $this->getByKey($source_style_type, $new_char);
342 if (count($new_titles) == 0) {
343 $new_titles = $target_char->getTitles();
344 }
345 $this->deleteCharacteristic($source_style_type, $new_char);
346 }
347
348 $this->addCharacteristic($source_style_type, $new_char);
349 $this->saveTitles($source_style_type, $new_char, $new_titles);
350
351 $from_style = new ilObjStyleSheet($source_style_id);
352
353 // todo fix using mq_id
354 foreach (["", ":hover", ":before"] as $char_extension) {
355 $colors = array();
356 //foreach ($pars as $p => $v) {
357 foreach ($this->repo->getAllParametersOfCharacteristic(
358 $from_style->getId(),
359 $source_style_type,
360 $source_char . $char_extension
361 ) as $param) {
362 $p = $param["parameter"];
363 $v = $param["value"];
364 if (substr($v, 0, 1) == "!") {
365 $colors[] = substr($v, 1);
366 }
367 if ($param["mq_id"] > 0) {
368 continue;
369 }
370 $this->replaceParameter(
371 ilObjStyleSheet::_determineTag($source_style_type),
372 $new_char . $char_extension,
373 $p,
374 $v,
375 $source_style_type,
376 0,
377 (bool) $param["custom"]
378 );
379 }
380
381 // copy colors
382 foreach ($colors as $c) {
383 if (!$this->color_repo->colorExists($this->style_id, $c)) {
384 $this->color_repo->addColor(
385 $this->style_id,
386 $c,
387 $from_style->getColorCodeForName($c)
388 );
389 }
390 }
391 }
392 }
393
394 public function replaceParameter(
395 string $a_tag,
396 string $a_class,
397 string $a_par,
398 string $a_val,
399 string $a_type,
400 int $a_mq_id = 0,
401 bool $a_custom = false
402 ): void {
403 if ($a_val != "") {
404 $this->repo->replaceParameter(
405 $this->style_id,
406 $a_tag,
407 $a_class,
408 $a_par,
409 $a_val,
410 $a_type,
411 $a_mq_id,
412 $a_custom
413 );
414 } else {
415 $this->deleteParameter(
416 $a_tag,
417 $a_class,
418 $a_par,
419 $a_type,
420 $a_mq_id,
421 $a_custom
422 );
423 }
424 }
425
426 public function deleteParameter(
427 string $a_tag,
428 string $a_class,
429 string $a_par,
430 string $a_type,
431 int $a_mq_id = 0,
432 bool $a_custom = false
433 ): void {
434 $this->repo->deleteParameter(
435 $this->style_id,
436 $a_tag,
437 $a_class,
438 $a_par,
439 $a_type,
440 $a_mq_id,
441 $a_custom
442 );
443 }
444}
Manages access to content style editing.
Main business logic for characteristics.
exists(string $type, string $char)
Check if characteristic exists.
getByTypes(array $types, bool $include_hidden=true, bool $include_outdated=true)
Get characteristics by type.
isOutdated(string $type, string $characteristic)
__construct(int $style_id, Access\StyleAccessManager $access_manager, CharacteristicDBRepo $char_repo, CharacteristicCopyPasteSessionRepo $char_copy_paste_repo, ColorDBRepo $color_repo, ilObjUser $user)
addCharacteristic(string $type, string $char, bool $hidden=false)
deleteCharacteristic(string $type, string $class)
Delete Characteristic.
getByKey(string $type, string $characteristic)
Get characteristic by key.
hasCopiedCharacteristics(string $style_type)
Is in copy process?
getPresentationTitle(string $type, string $characteristic, bool $fallback_to_characteristic=true)
Get characteristic by key.
saveHidden(string $type, string $characteristic, bool $hide)
Save characteristic hidden status.
getByType(string $type)
Get characteristics by type.
setCopyCharacteristics(string $style_type, array $characteristics)
saveOutdated(string $type, string $characteristic, bool $outdated)
Save characteristic outdated status.
getBySuperType(string $supertype)
Get characteristics by supertype.
saveOrderNrs(string $type, array $order_nrs)
Save characteristics order.
saveTitles(string $type, string $characteristic, array $titles)
Save titles for characteristic.
copyCharacteristicFromSource(int $source_style_id, string $source_style_type, string $source_char, string $new_char, array $new_titles)
Copy characteristic.
deleteParameter(string $a_tag, string $a_class, string $a_par, string $a_type, int $a_mq_id=0, bool $a_custom=false)
replaceParameter(string $a_tag, string $a_class, string $a_par, string $a_val, string $a_type, int $a_mq_id=0, bool $a_custom=false)
Characteristic (Class) of style.
Class ilObjStyleSheet.
static _determineTag(string $a_type)
static _writeUpToDate(int $a_id, bool $a_up_to_date)
User class.
$c
Definition: deliver.php:25
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!file_exists('../ilias.ini.php'))
$lang
Definition: xapiexit.php:25
$param
Definition: xapitoken.php:46