ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilStyleDataSet.php
Go to the documentation of this file.
1 <?php
2 
21 
43 {
48  protected $log;
49 
53  protected $rbacsystem;
54 
58  protected $user;
59 
66  public function __construct()
67  {
68  global $DIC;
69 
70  $this->db = $DIC->database();
72  $this->log = ilLoggerFactory::getLogger('styl');
73  $this->log->debug("constructed");
74  $this->rbacsystem = $DIC->rbac()->system();
75  $this->user = $DIC->user();
76  $this->repo = $DIC->contentStyle()->internal()->repo();
77  }
78 
79 
84  public function getSupportedVersions(): array
85  {
86  return array("5.1.0", "8.0");
87  }
88 
94  public function getXmlNamespace(string $a_entity, string $a_schema_version): string
95  {
96  return "http://www.ilias.de/xml/Services/Style/" . $a_entity;
97  }
98 
105  protected function getTypes(string $a_entity, string $a_version): array
106  {
107  if ($a_entity == "sty") {
108  switch ($a_version) {
109  case "5.1.0":
110  case "8.0":
111  return array(
112  "Id" => "integer",
113  "Title" => "text",
114  "Description" => "text",
115  "ImagesDir" => "directory"
116  );
117  }
118  }
119 
120  if ($a_entity == "object_style") {
121  switch ($a_version) {
122  case "5.1.0":
123  case "8.0":
124  return array(
125  "ObjectId" => "integer"
126  );
127  }
128  }
129 
130  if ($a_entity == "sty_setting") {
131  switch ($a_version) {
132  case "5.1.0":
133  case "8.0":
134  return array(
135  "StyleId" => "integer",
136  "Name" => "test",
137  "Value" => "text"
138  );
139  }
140  }
141 
142  if ($a_entity == "sty_char") {
143  switch ($a_version) {
144  case "5.1.0":
145  return array(
146  "StyleId" => "integer",
147  "Type" => "text",
148  "Characteristic" => "text",
149  "Hide" => "integer"
150  );
151  case "8.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  return array(
167  "StyleId" => "integer",
168  "Type" => "text",
169  "Characteristic" => "text",
170  "Lang" => "text",
171  "Title" => "text"
172  );
173  }
174  }
175 
176  if ($a_entity == "sty_parameter") {
177  switch ($a_version) {
178  case "5.1.0":
179  case "8.0":
180  return array(
181  "StyleId" => "integer",
182  "Tag" => "text",
183  "Class" => "text",
184  "Parameter" => "text",
185  "Value" => "text",
186  "Type" => "text",
187  "MqId" => "integer",
188  "Custom" => "integer"
189  );
190  }
191  }
192 
193  if ($a_entity == "sty_color") {
194  switch ($a_version) {
195  case "5.1.0":
196  case "8.0":
197  return array(
198  "StyleId" => "integer",
199  "ColorName" => "text",
200  "ColorCode" => "text"
201  );
202  }
203  }
204 
205  if ($a_entity == "sty_media_query") {
206  switch ($a_version) {
207  case "5.1.0":
208  case "8.0":
209  return array(
210  "Id" => "integer",
211  "StyleId" => "integer",
212  "OrderNr" => "integer",
213  "MQuery" => "text"
214  );
215  }
216  }
217 
218  if ($a_entity == "sty_template") {
219  switch ($a_version) {
220  case "5.1.0":
221  case "8.0":
222  return array(
223  "Id" => "integer",
224  "StyleId" => "integer",
225  "Name" => "text",
226  "Preview" => "text",
227  "TempType" => "text"
228  );
229  }
230  }
231 
232  if ($a_entity == "sty_template_class") {
233  switch ($a_version) {
234  case "5.1.0":
235  case "8.0":
236  return array(
237  "TemplateId" => "integer",
238  "ClassType" => "text",
239  "Class" => "text"
240  );
241  }
242  }
243 
244  if ($a_entity == "sty_usage") {
245  switch ($a_version) {
246  case "5.1.0":
247  case "8.0":
248  return array(
249  "ObjId" => "integer",
250  "StyleId" => "integer"
251  );
252  }
253  }
254  }
255 
261  public function getXmlRecord(string $a_entity, string $a_version, array $a_set): array
262  {
263  if ($a_entity == "sty") {
264  $dir = ilObjStyleSheet::_getImagesDirectory($a_set["Id"]);
265  $a_set["ImagesDir"] = $dir;
266  }
267 
268  return $a_set;
269  }
270 
276  public function readData(string $a_entity, string $a_version, array $a_ids): void
277  {
278  $ilDB = $this->db;
279 
280  if (!is_array($a_ids)) {
281  $a_ids = array($a_ids);
282  }
283 
284  if ($a_entity == "object_style") {
285  switch ($a_version) {
286  case "5.1.0":
287  case "8.0":
288  foreach ($a_ids as $id) {
289  $this->data[] = array("ObjectId" => $id);
290  }
291  break;
292  }
293  }
294 
295  if ($a_entity == "sty") {
296  switch ($a_version) {
297  case "5.1.0":
298  case "8.0":
299  $this->getDirectDataFromQuery("SELECT o.title, o.description, o.obj_id id" .
300  " FROM object_data o " .
301  " WHERE " . $ilDB->in("o.obj_id", $a_ids, false, "integer"));
302  break;
303  }
304  }
305 
306  if ($a_entity == "sty_setting") {
307  switch ($a_version) {
308  case "5.1.0":
309  case "8.0":
310  $this->getDirectDataFromQuery("SELECT style_id, name, value" .
311  " FROM style_setting " .
312  " WHERE " . $ilDB->in("style_id", $a_ids, false, "integer"));
313  break;
314  }
315  }
316 
317  if ($a_entity == "sty_char") {
318  switch ($a_version) {
319  case "5.1.0":
320  case "8.0":
321  $this->getDirectDataFromQuery("SELECT style_id, type, characteristic, hide, order_nr, outdated" .
322  " FROM style_char " .
323  " WHERE " . $ilDB->in("style_id", $a_ids, false, "integer"));
324  break;
325  }
326  }
327 
328  if ($a_entity == "sty_char_title") {
329  switch ($a_version) {
330  case "8.0":
331  $this->getDirectDataFromQuery("SELECT style_id, type, characteristic, lang, title" .
332  " FROM style_char_title " .
333  " WHERE " . $ilDB->in("style_id", $a_ids, false, "integer"));
334  break;
335  }
336  }
337 
338  if ($a_entity == "sty_parameter") {
339  switch ($a_version) {
340  case "5.1.0":
341  case "8.0":
342  $this->getDirectDataFromQuery("SELECT style_id, tag, class, parameter, value, type, mq_id, custom" .
343  " FROM style_parameter " .
344  " WHERE " . $ilDB->in("style_id", $a_ids, false, "integer"));
345  break;
346  }
347  }
348 
349  if ($a_entity == "sty_color") {
350  switch ($a_version) {
351  case "5.1.0":
352  case "8.0":
353  $this->getDirectDataFromQuery("SELECT style_id, color_name, color_code" .
354  " FROM style_color " .
355  " WHERE " . $ilDB->in("style_id", $a_ids, false, "integer"));
356  break;
357  }
358  }
359 
360  if ($a_entity == "sty_media_query") {
361  switch ($a_version) {
362  case "5.1.0":
363  case "8.0":
364  $this->getDirectDataFromQuery("SELECT id, style_id, order_nr, mquery m_query" .
365  " FROM sty_media_query " .
366  " WHERE " . $ilDB->in("style_id", $a_ids, false, "integer"));
367  break;
368  }
369  }
370 
371  if ($a_entity == "sty_template") {
372  switch ($a_version) {
373  case "5.1.0":
374  case "8.0":
375  $this->getDirectDataFromQuery("SELECT id, style_id, name, preview, temp_type" .
376  " FROM style_template " .
377  " WHERE " . $ilDB->in("style_id", $a_ids, false, "integer"));
378  break;
379  }
380  }
381 
382  if ($a_entity == "sty_template_class") {
383  switch ($a_version) {
384  case "5.1.0":
385  case "8.0":
386  $this->getDirectDataFromQuery("SELECT template_id, class_type, class" .
387  " FROM style_template_class " .
388  " WHERE " . $ilDB->in("template_id", $a_ids, false, "integer"));
389  break;
390  }
391  }
392 
393  if ($a_entity == "sty_usage") {
394  switch ($a_version) {
395  case "5.1.0":
396  case "8.0":
397  $this->getDirectDataFromQuery("SELECT obj_id, style_id" .
398  " FROM style_usage " .
399  " WHERE " . $ilDB->in("style_id", $a_ids, false, "integer"));
400  break;
401  }
402  }
403  }
404 
408  protected function getDependencies(
409  string $a_entity,
410  string $a_version,
411  ?array $a_rec = null,
412  ?array $a_ids = null
413  ): array {
414  $this->ds_log->debug("entity: " . $a_entity . ", rec: " . print_r($a_rec, true));
415  switch ($a_entity) {
416  case "object_style":
417  $this->ds_log->debug("object id: " . ($a_rec["ObjectId"] ?? null));
418  $style_id = ilObjStyleSheet::lookupObjectStyle($a_rec["ObjectId"] ?? 0);
419  $this->ds_log->debug("style id: " . $style_id);
420  //if ($style_id > 0 && !ilObjStyleSheet::_lookupStandard($style_id))
421  if ($style_id > 0 && ilObject::_lookupType($style_id) == "sty") { // #0019337 always export style, if valid
422  return array(
423  "sty" => array("ids" => $style_id));
424  }
425  return array();
426  break;
427 
428  case "sty":
429  return array(
430  "sty_setting" => array("ids" => $a_rec["Id"] ?? null),
431  "sty_media_query" => array("ids" => $a_rec["Id"] ?? null),
432  "sty_char" => array("ids" => $a_rec["Id"] ?? null),
433  "sty_char_title" => array("ids" => $a_rec["Id"] ?? null),
434  "sty_color" => array("ids" => $a_rec["Id"] ?? null),
435  "sty_parameter" => array("ids" => $a_rec["Id"] ?? null),
436  "sty_template" => array("ids" => $a_rec["Id"] ?? null),
437  "sty_usage" => array("ids" => $a_rec["Id"] ?? null)
438  );
439 
440  case "sty_template":
441  return array(
442  "sty_template_class" => array("ids" => $a_rec["Id"] ?? null)
443  );
444  }
445 
446  return [];
447  }
448 
449 
455  public function importRecord(string $a_entity, array $a_types, array $a_rec, ilImportMapping $a_mapping, string $a_schema_version): void
456  {
457  global $DIC;
458  $service = $DIC->contentStyle()->internal();
459  $access_manager = $service->domain()->access(
460  0,
461  $this->user->getId()
462  );
463  $access_manager->enableWrite(true);
464 
465  $style_id = (isset($this->current_obj))
466  ? $this->current_obj->getId()
467  : 0;
468  $characteristic_manager = $service->domain()->characteristic(
469  $style_id,
470  $access_manager
471  );
472 
473  $color_manager = $service->domain()->color(
474  $style_id,
475  $access_manager
476  );
477 
478  $a_rec = $this->stripTags($a_rec);
479  switch ($a_entity) {
480  case "sty":
481  $this->log->debug("Entity: " . $a_entity);
482  if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['Id'])) {
483  $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
484  } else {
485  $newObj = new ilObjStyleSheet();
486  $newObj->create(0, true);
487  }
488 
489  $newObj->setTitle($a_rec["Title"]);
490  $newObj->setDescription($a_rec["Description"]);
491  $newObj->update(true);
492 
493  $this->current_obj = $newObj;
494  $a_mapping->addMapping("Services/Style", "sty", $a_rec["Id"], $newObj->getId());
495  $a_mapping->addMapping("Services/Object", "obj", $a_rec["Id"], $newObj->getId());
496  $this->log->debug("Added mapping Services/Style sty " . $a_rec["Id"] . " > " . $newObj->getId());
497 
498  $dir = str_replace("..", "", $a_rec["ImagesDir"]);
499  if ($dir != "" && $this->getImportDirectory() != "") {
500  $source_dir = $this->getImportDirectory() . "/" . $dir;
501  $target_dir = $dir = ilObjStyleSheet::_getImagesDirectory($newObj->getId());
502  ilFileUtils::rCopy($source_dir, $target_dir);
503  }
504  break;
505 
506  case "sty_setting":
507  $this->current_obj->writeStyleSetting($a_rec["Name"], $a_rec["Value"]);
508  break;
509 
510  case "sty_char":
511  $this->current_obj->addCharacteristic($a_rec["Type"], $a_rec["Characteristic"], $a_rec["Hide"], (int) ($a_rec["OrderNr"] ?? 0), (bool) ($a_rec["Outdated"] ?? false));
512  break;
513 
514  case "sty_char_title":
515  $char_repo = $this->repo->characteristic();
516  $char_repo->addTitle(
517  $this->current_obj->getId(),
518  $a_rec["Type"],
519  $a_rec["Characteristic"],
520  $a_rec["Lang"],
521  $a_rec["Title"],
522  );
523  break;
524 
525  case "sty_parameter":
526  $mq_id = (int) $a_mapping->getMapping("Services/Style", "media_query", $a_rec["MqId"]);
527  $characteristic_manager->replaceParameter($a_rec["Tag"], $a_rec["Class"], $a_rec["Parameter"], $a_rec["Value"], $a_rec["Type"], $mq_id, $a_rec["Custom"]);
528  break;
529 
530  case "sty_color":
531  $color_manager->addColor($a_rec["ColorName"], $a_rec["ColorCode"]);
532  break;
533 
534  case "sty_media_query":
535  $mq_id = $this->current_obj->addMediaQuery($a_rec["MQuery"], $a_rec["OrderNr"]);
536  $a_mapping->addMapping("Services/Style", "media_query", $a_rec["Id"], $mq_id);
537  break;
538 
539  case "sty_template":
540  $tid = $this->current_obj->addTemplate($a_rec["TempType"], $a_rec["Name"], array());
541  $a_mapping->addMapping("Services/Style", "template", $a_rec["Id"], $tid);
542  break;
543 
544  case "sty_template_class":
545  $tid = (int) $a_mapping->getMapping("Services/Style", "template", $a_rec["TemplateId"]);
546  $this->current_obj->addTemplateClass($tid, $a_rec["ClassType"], $a_rec["Class"]);
547  break;
548 
549  case "sty_usage":
550  $obj_id = (int) $a_mapping->getMapping("Services/Object", "obj", $a_rec["ObjId"]);
551  $style_id = (int) $a_mapping->getMapping("Services/Style", "sty", $a_rec["StyleId"]);
552  if ($obj_id > 0 && $style_id > 0) {
553  ilObjStyleSheet::writeStyleUsage($obj_id, $style_id);
554  ilObjStyleSheet::writeOwner($obj_id, $style_id);
555  }
556  break;
557  }
558  }
559 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getLogger(string $a_component_id)
Get component logger.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Content InternalRepoService $repo
static _getImagesDirectory(int $a_style_id)
__construct()
constructor
static rCopy(string $a_sdir, string $a_tdir, bool $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
getXmlRecord(string $a_entity, string $a_version, array $a_set)
Get xml record.
addMapping(string $a_comp, string $a_entity, string $a_old_id, string $a_new_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static writeOwner($obj_id, $style_id)
global $DIC
Definition: feed.php:28
getDependencies(string $a_entity, string $a_version, ?array $a_rec=null, ?array $a_ids=null)
Determine the dependent sets of data.
getMapping(string $a_comp, string $a_entity, string $a_old_id)
ilDBInterface $db
Content style internal repo service.
getSupportedVersions()
Get supported versions.
readData(string $a_entity, string $a_version, array $a_ids)
Read data.
getTypes(string $a_entity, string $a_version)
Get field types for entity.
getXmlNamespace(string $a_entity, string $a_schema_version)
Get xml namespace.
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 ...
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
Style Data set class.
static writeStyleUsage(int $a_obj_id, int $a_style_id)
Write style usage.
__construct(Container $dic, ilPlugin $plugin)
static lookupObjectStyle(int $a_obj_id)
Lookup object style.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
stripTags(array $rec, array $omit_keys=[])
static _lookupType(int $id, bool $reference=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$service
Definition: ltiservices.php:43
importRecord(string $a_entity, array $a_types, array $a_rec, ilImportMapping $a_mapping, string $a_schema_version)
Import record.