ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilStyleDataSet.php
Go to the documentation of this file.
1<?php
2
23
45{
48 protected ?ilObjStyleSheet $current_obj = null;
53 protected $log;
54
58 protected $rbacsystem;
59
63 protected $user;
64
65 public function __construct()
66 {
67 global $DIC;
68
69 $this->db = $DIC->database();
71 $this->log = ilLoggerFactory::getLogger('styl');
72 $this->log->debug("constructed");
73 $this->rbacsystem = $DIC->rbac()->system();
74 $this->user = $DIC->user();
75 $this->style_domain = $DIC->contentStyle()->internal()->domain();
76 $this->content_style_domain = $DIC->contentStyle()->domain();
77 $this->repo = $DIC->contentStyle()->internal()->repo();
78 }
79
80
85 public function getSupportedVersions(): array
86 {
87 return array("10.0", "8.0", "5.1.0");
88 }
89
95 public function getXmlNamespace(string $a_entity, string $a_schema_version): string
96 {
97 return "http://www.ilias.de/xml/Services/Style/" . $a_entity;
98 }
99
106 protected function getTypes(string $a_entity, string $a_version): array
107 {
108 if ($a_entity == "sty") {
109 switch ($a_version) {
110 case "5.1.0":
111 case "8.0":
112 return array(
113 "Id" => "integer",
114 "Title" => "text",
115 "Description" => "text",
116 "ImagesDir" => "directory"
117 );
118 case "10.0":
119 return array(
120 "Id" => "integer",
121 "Title" => "text",
122 "Description" => "text",
123 "StyleContainer" => "rscontainer"
124 );
125 }
126 }
127
128 if ($a_entity == "object_style") {
129 switch ($a_version) {
130 case "5.1.0":
131 case "8.0":
132 case "10.0":
133 return array(
134 "ObjectId" => "integer"
135 );
136 }
137 }
138
139 if ($a_entity == "sty_setting") {
140 switch ($a_version) {
141 case "5.1.0":
142 case "8.0":
143 case "10.0":
144 return array(
145 "StyleId" => "integer",
146 "Name" => "test",
147 "Value" => "text"
148 );
149 }
150 }
151
152 if ($a_entity == "sty_char") {
153 switch ($a_version) {
154 case "5.1.0":
155 return array(
156 "StyleId" => "integer",
157 "Type" => "text",
158 "Characteristic" => "text",
159 "Hide" => "integer"
160 );
161 case "8.0":
162 case "10.0":
163 return array(
164 "StyleId" => "integer",
165 "Type" => "text",
166 "Characteristic" => "text",
167 "Hide" => "integer",
168 "OrderNr" => "integer",
169 "Outdate" => "integer"
170 );
171 }
172 }
173
174 if ($a_entity == "sty_char_title") {
175 switch ($a_version) {
176 case "8.0":
177 case "10.0":
178 return array(
179 "StyleId" => "integer",
180 "Type" => "text",
181 "Characteristic" => "text",
182 "Lang" => "text",
183 "Title" => "text"
184 );
185 }
186 }
187
188 if ($a_entity == "sty_parameter") {
189 switch ($a_version) {
190 case "5.1.0":
191 case "8.0":
192 case "10.0":
193 return array(
194 "StyleId" => "integer",
195 "Tag" => "text",
196 "Class" => "text",
197 "Parameter" => "text",
198 "Value" => "text",
199 "Type" => "text",
200 "MqId" => "integer",
201 "Custom" => "integer"
202 );
203 }
204 }
205
206 if ($a_entity == "sty_color") {
207 switch ($a_version) {
208 case "5.1.0":
209 case "8.0":
210 case "10.0":
211 return array(
212 "StyleId" => "integer",
213 "ColorName" => "text",
214 "ColorCode" => "text"
215 );
216 }
217 }
218
219 if ($a_entity == "sty_media_query") {
220 switch ($a_version) {
221 case "5.1.0":
222 case "8.0":
223 case "10.0":
224 return array(
225 "Id" => "integer",
226 "StyleId" => "integer",
227 "OrderNr" => "integer",
228 "MQuery" => "text"
229 );
230 }
231 }
232
233 if ($a_entity == "sty_template") {
234 switch ($a_version) {
235 case "5.1.0":
236 case "8.0":
237 case "10.0":
238 return array(
239 "Id" => "integer",
240 "StyleId" => "integer",
241 "Name" => "text",
242 "Preview" => "text",
243 "TempType" => "text"
244 );
245 }
246 }
247
248 if ($a_entity == "sty_template_class") {
249 switch ($a_version) {
250 case "5.1.0":
251 case "8.0":
252 case "10.0":
253 return array(
254 "TemplateId" => "integer",
255 "ClassType" => "text",
256 "Class" => "text"
257 );
258 }
259 }
260
261 if ($a_entity == "sty_usage") {
262 switch ($a_version) {
263 case "5.1.0":
264 case "8.0":
265 case "10.0":
266 return array(
267 "ObjId" => "integer",
268 "StyleId" => "integer"
269 );
270 }
271 }
272 }
273
279 public function getXmlRecord(string $a_entity, string $a_version, array $a_set): array
280 {
281 if ($a_entity == "sty") {
282 $a_set["StyleContainer"] = serialize($this->style_domain->style((int) $a_set["Id"])->getResourceIdentification());
283 }
284
285 return $a_set;
286 }
287
293 public function readData(string $a_entity, string $a_version, array $a_ids): void
294 {
296
297 if (!is_array($a_ids)) {
298 $a_ids = array($a_ids);
299 }
300
301 if ($a_entity == "object_style") {
302 switch ($a_version) {
303 case "5.1.0":
304 case "8.0":
305 case "10.0":
306 foreach ($a_ids as $id) {
307 $this->data[] = array("ObjectId" => $id);
308 }
309 break;
310 }
311 }
312
313 if ($a_entity == "sty") {
314 switch ($a_version) {
315 case "5.1.0":
316 case "8.0":
317 case "10.0":
318 $this->getDirectDataFromQuery("SELECT o.title, o.description, o.obj_id id" .
319 " FROM object_data o " .
320 " WHERE " . $ilDB->in("o.obj_id", $a_ids, false, "integer"));
321 break;
322 }
323 }
324
325 if ($a_entity == "sty_setting") {
326 switch ($a_version) {
327 case "5.1.0":
328 case "8.0":
329 case "10.0":
330 $this->getDirectDataFromQuery("SELECT style_id, name, value" .
331 " FROM style_setting " .
332 " WHERE " . $ilDB->in("style_id", $a_ids, false, "integer"));
333 break;
334 }
335 }
336
337 if ($a_entity == "sty_char") {
338 switch ($a_version) {
339 case "5.1.0":
340 $this->getDirectDataFromQuery("SELECT style_id, type, characteristic, hide" .
341 " FROM style_char " .
342 " WHERE " . $ilDB->in("style_id", $a_ids, false, "integer"));
343 // no break
344 case "8.0":
345 case "10.0":
346 $this->getDirectDataFromQuery("SELECT style_id, type, characteristic, hide, order_nr, outdated" .
347 " FROM style_char " .
348 " WHERE " . $ilDB->in("style_id", $a_ids, false, "integer"));
349 break;
350 }
351 }
352
353 if ($a_entity == "sty_char_title") {
354 switch ($a_version) {
355 case "8.0":
356 case "10.0":
357 $this->getDirectDataFromQuery("SELECT style_id, type, characteristic, lang, title" .
358 " FROM style_char_title " .
359 " WHERE " . $ilDB->in("style_id", $a_ids, false, "integer"));
360 break;
361 }
362 }
363
364 if ($a_entity == "sty_parameter") {
365 switch ($a_version) {
366 case "5.1.0":
367 case "8.0":
368 case "10.0":
369 $this->getDirectDataFromQuery("SELECT style_id, tag, class, parameter, value, type, mq_id, custom" .
370 " FROM style_parameter " .
371 " WHERE " . $ilDB->in("style_id", $a_ids, false, "integer"));
372 break;
373 }
374 }
375
376 if ($a_entity == "sty_color") {
377 switch ($a_version) {
378 case "5.1.0":
379 case "8.0":
380 case "10.0":
381 $this->getDirectDataFromQuery("SELECT style_id, color_name, color_code" .
382 " FROM style_color " .
383 " WHERE " . $ilDB->in("style_id", $a_ids, false, "integer"));
384 break;
385 }
386 }
387
388 if ($a_entity == "sty_media_query") {
389 switch ($a_version) {
390 case "5.1.0":
391 case "8.0":
392 case "10.0":
393 $this->getDirectDataFromQuery("SELECT id, style_id, order_nr, mquery m_query" .
394 " FROM sty_media_query " .
395 " WHERE " . $ilDB->in("style_id", $a_ids, false, "integer"));
396 break;
397 }
398 }
399
400 if ($a_entity == "sty_template") {
401 switch ($a_version) {
402 case "5.1.0":
403 case "8.0":
404 case "10.0":
405 $this->getDirectDataFromQuery("SELECT id, style_id, name, preview, temp_type" .
406 " FROM style_template " .
407 " WHERE " . $ilDB->in("style_id", $a_ids, false, "integer"));
408 break;
409 }
410 }
411
412 if ($a_entity == "sty_template_class") {
413 switch ($a_version) {
414 case "5.1.0":
415 case "8.0":
416 case "10.0":
417 $this->getDirectDataFromQuery("SELECT template_id, class_type, class" .
418 " FROM style_template_class " .
419 " WHERE " . $ilDB->in("template_id", $a_ids, false, "integer"));
420 break;
421 }
422 }
423
424 if ($a_entity == "sty_usage") {
425 switch ($a_version) {
426 case "5.1.0":
427 case "8.0":
428 case "10.0":
429 $this->getDirectDataFromQuery("SELECT obj_id, style_id" .
430 " FROM style_usage " .
431 " WHERE " . $ilDB->in("style_id", $a_ids, false, "integer"));
432 break;
433 }
434 }
435 }
436
438 array $record,
439 string $entity,
440 string $schema_version,
441 string $field,
442 string $value
444 if ($entity === "sty" && $field === "StyleContainer") {
445 $rid = $this->style_domain->style((int) $record["Id"])->getResourceIdentification();
446 if ($rid) {
447 $container = $this->irss->manageContainer()->getResource($rid);
448 return
451 "images"
452 );
453 }
454 }
455 return null;
456 }
457
458
462 protected function getDependencies(
463 string $a_entity,
464 string $a_version,
465 ?array $a_rec = null,
466 ?array $a_ids = null
467 ): array {
468 $this->ds_log->debug("entity: " . $a_entity . ", rec: " . print_r($a_rec, true));
469 switch ($a_entity) {
470 case "object_style":
471 $this->ds_log->debug("object id: " . ($a_rec["ObjectId"] ?? null));
472 $style_id = $this->content_style_domain->styleForObjId($a_rec["ObjectId"] ?? 0)->getExportStyleId();
473 $this->ds_log->debug("style id: " . $style_id);
474 //if ($style_id > 0 && !ilObjStyleSheet::_lookupStandard($style_id))
475 if ($style_id > 0 && ilObject::_lookupType($style_id) == "sty") { // #0019337 always export style, if valid
476 return array(
477 "sty" => array("ids" => $style_id));
478 }
479 return array();
480 break;
481
482 case "sty":
483 return array(
484 "sty_setting" => array("ids" => $a_rec["Id"] ?? null),
485 "sty_media_query" => array("ids" => $a_rec["Id"] ?? null),
486 "sty_char" => array("ids" => $a_rec["Id"] ?? null),
487 "sty_char_title" => array("ids" => $a_rec["Id"] ?? null),
488 "sty_color" => array("ids" => $a_rec["Id"] ?? null),
489 "sty_parameter" => array("ids" => $a_rec["Id"] ?? null),
490 "sty_template" => array("ids" => $a_rec["Id"] ?? null),
491 "sty_usage" => array("ids" => $a_rec["Id"] ?? null)
492 );
493
494 case "sty_template":
495 return array(
496 "sty_template_class" => array("ids" => $a_rec["Id"] ?? null)
497 );
498 }
499
500 return [];
501 }
502
503
509 public function importRecord(string $a_entity, array $a_types, array $a_rec, ilImportMapping $a_mapping, string $a_schema_version): void
510 {
511 global $DIC;
512 $service = $DIC->contentStyle()->internal();
513 $access_manager = $service->domain()->access(
514 0,
515 $this->user->getId()
516 );
517 $access_manager->enableWrite(true);
518
519 $style_id = (isset($this->current_obj))
520 ? $this->current_obj->getId()
521 : 0;
522 $characteristic_manager = $service->domain()->characteristic(
523 $style_id,
524 $access_manager
525 );
526
527 $color_manager = $service->domain()->color(
528 $style_id,
529 $access_manager
530 );
531
532 $a_rec = $this->stripTags($a_rec);
533 switch ($a_entity) {
534 case "sty":
535 $this->log->debug("Entity: " . $a_entity);
536 if ($new_id = $a_mapping->getMapping('components/ILIAS/Container', 'objs', $a_rec['Id'])) {
537 $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
538 } else {
539 $newObj = new ilObjStyleSheet();
540 $newObj->create(0, true);
541 }
542
543 $newObj->setTitle($a_rec["Title"]);
544 $newObj->setDescription($a_rec["Description"]);
545 $newObj->update(true);
546
547 $this->current_obj = $newObj;
548 $a_mapping->addMapping("components/ILIAS/Style", "sty", $a_rec["Id"], $newObj->getId());
549 $a_mapping->addMapping("components/ILIAS/ILIASObject", "obj", $a_rec["Id"], $newObj->getId());
550 $this->log->debug("Added mapping Services/Style sty " . $a_rec["Id"] . " > " . $newObj->getId());
551
552 // up to 9
553 $dir = str_replace("..", "", $a_rec["ImagesDir"] ?? "");
554 if ($dir != "" && $this->getImportDirectory() != "") {
555 $source_dir = $this->getImportDirectory() . "/" . $dir;
556 $sm = $this->style_domain->style($newObj->getId());
557 $sm->createContainerFromLocalDir($source_dir, "images", false);
558 }
559
560 $dir = str_replace("..", "", ($a_rec["StyleContainer"] ?? ""));
561 if ($dir != "" && $this->getImportDirectory() != "") {
562 $source_dir = $this->getImportDirectory() . "/" . $dir;
563 if (is_dir($source_dir)) {
564 $sm = $this->style_domain->style($newObj->getId());
565 $sm->createContainerFromLocalDir($source_dir, "images", false);
566 }
567 }
568 break;
569
570 case "sty_setting":
571 $this->current_obj->writeStyleSetting($a_rec["Name"], $a_rec["Value"]);
572 break;
573
574 case "sty_char":
575 $this->current_obj->addCharacteristic($a_rec["Type"], $a_rec["Characteristic"], $a_rec["Hide"], (int) ($a_rec["OrderNr"] ?? 0), (bool) ($a_rec["Outdated"] ?? false));
576 break;
577
578 case "sty_char_title":
579 $char_repo = $this->repo->characteristic();
580 $char_repo->addTitle(
581 $this->current_obj->getId(),
582 $a_rec["Type"],
583 $a_rec["Characteristic"],
584 $a_rec["Lang"],
585 $a_rec["Title"],
586 );
587 break;
588
589 case "sty_parameter":
590 $mq_id = (int) $a_mapping->getMapping("components/ILIAS/Style", "media_query", $a_rec["MqId"]);
591 $characteristic_manager->replaceParameter($a_rec["Tag"], $a_rec["Class"], $a_rec["Parameter"], $a_rec["Value"], $a_rec["Type"], $mq_id, $a_rec["Custom"]);
592 break;
593
594 case "sty_color":
595 $color_manager->addColor($a_rec["ColorName"], $a_rec["ColorCode"]);
596 break;
597
598 case "sty_media_query":
599 $mq_id = $this->current_obj->addMediaQuery($a_rec["MQuery"], $a_rec["OrderNr"]);
600 $a_mapping->addMapping("components/ILIAS/Style", "media_query", $a_rec["Id"], $mq_id);
601 break;
602
603 case "sty_template":
604 $tid = $this->current_obj->addTemplate($a_rec["TempType"], $a_rec["Name"], array());
605 $a_mapping->addMapping("components/ILIAS/Style", "template", $a_rec["Id"], $tid);
606 break;
607
608 case "sty_template_class":
609 $tid = (int) $a_mapping->getMapping("components/ILIAS/Style", "template", $a_rec["TemplateId"]);
610 $this->current_obj->addTemplateClass($tid, $a_rec["ClassType"], $a_rec["Class"]);
611 break;
612
613 case "sty_usage":
614 $obj_id = (int) $a_mapping->getMapping("components/ILIAS/ILIASObject", "obj", $a_rec["ObjId"]);
615 $style_id = (int) $a_mapping->getMapping("components/ILIAS/Style", "sty", $a_rec["StyleId"]);
616 if ($obj_id > 0 && $style_id > 0) {
617 ilObjStyleSheet::writeStyleUsage($obj_id, $style_id);
618 ilObjStyleSheet::writeOwner($obj_id, $style_id);
619 }
620 break;
621 }
622 }
623}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Facade for consumer domain interface.
return true
A dataset contains in data in a common structure that can be shared and transformed for different pur...
getIRSSContainerExportConfig(StorableResource $source_container, string $source_path, string $target_path="")
getDirectDataFromQuery(string $a_query, bool $a_convert_to_leading_upper=true, bool $a_set=true)
Get data from query.This is a standard procedure, all db field names are directly mapped to abstract ...
ilDBInterface $db
string $schema_version
string $entity
addMapping(string $a_comp, string $a_entity, string $a_old_id, string $a_new_id)
getMapping(string $a_comp, string $a_entity, string $a_old_id)
static getLogger(string $a_component_id)
Get component logger.
Class ilObjStyleSheet.
static writeStyleUsage(int $a_obj_id, int $a_style_id)
Write style usage.
static writeOwner($obj_id, $style_id)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupType(int $id, bool $reference=false)
Style Data set class.
importRecord(string $a_entity, array $a_types, array $a_rec, ilImportMapping $a_mapping, string $a_schema_version)
Import record.
Content DomainService $content_style_domain
getXmlRecord(string $a_entity, string $a_version, array $a_set)
Get xml record.
getDependencies(string $a_entity, string $a_version, ?array $a_rec=null, ?array $a_ids=null)
Determine the dependent sets of data.
ilObjStyleSheet $current_obj
readData(string $a_entity, string $a_version, array $a_ids)
Read data.
getXmlNamespace(string $a_entity, string $a_schema_version)
Get xml namespace.
getSupportedVersions()
Get supported versions.
Content InternalDomainService $style_domain
Content InternalRepoService $repo
getContainerExportConfig(array $record, string $entity, string $schema_version, string $field, string $value)
getTypes(string $a_entity, string $a_version)
Get field types for entity.
$service
Definition: ltiresult.php:36
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26
$container
@noRector
Definition: wac.php:37