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