ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilContentPageDataSet.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
26  public static array $style_map = [];
27 
28  protected \ILIAS\Style\Content\DomainService $content_style_domain;
29 
30  public function __construct()
31  {
32  global $DIC;
33 
35 
36  $this->content_style_domain = $DIC
37  ->contentStyle()
38  ->domain();
39  }
40 
41  public function getSupportedVersions(): array
42  {
43  return [
44  '5.4.0', '9.0.0',
45  ];
46  }
47 
48  protected function getXmlNamespace(string $a_entity, string $a_schema_version): string
49  {
50  return 'http://www.ilias.de/xml/Modules/ContentPage/' . $a_entity;
51  }
52 
53  protected function getTypes(string $a_entity, string $a_version): array
54  {
55  return match ($a_entity) {
56  self::OBJ_TYPE => [
57  'id' => 'integer',
58  'title' => 'text',
59  'description' => 'text',
60  'info-tab' => 'integer'
61  ],
62  default => [],
63  };
64  }
65 
66  public function readData(string $a_entity, string $a_version, array $a_ids): void
67  {
68  $this->data = [];
69 
70  if (!is_array($a_ids)) {
71  $a_ids = [$a_ids];
72  }
73 
74  $this->readEntityData($a_entity, $a_ids);
75  }
76 
77 
81  protected function readEntityData(string $entity, array $ids): void
82  {
83  switch ($entity) {
84  case self::OBJ_TYPE:
85  foreach ($ids as $objId) {
86  if (ilObject::_lookupType((int) $objId) === self::OBJ_TYPE) {
88  $obj = ilObjectFactory::getInstanceByObjId((int) $objId);
89 
90  $this->data[] = [
91  'id' => $obj->getId(),
92  'title' => $obj->getTitle(),
93  'description' => $obj->getDescription(),
94  'info-tab' => (string) ((bool) ilContainer::_lookupContainerSetting(
95  $obj->getId(),
97  '1'
98  ))
99  ];
100  }
101  }
102  break;
103 
104  default:
105  break;
106  }
107  }
108 
109  public function importRecord(
110  string $a_entity,
111  array $a_types,
112  array $a_rec,
113  ilImportMapping $a_mapping,
114  string $a_schema_version
115  ): void {
116  switch ($a_entity) {
117  case self::OBJ_TYPE:
118  if ($newObjId = $a_mapping->getMapping('components/ILIAS/Container', 'objs', (string) $a_rec['id'])) {
119  $newObject = ilObjectFactory::getInstanceByObjId((int) $newObjId, false);
120  } else {
121  $newObject = new ilObjContentPage();
122  }
123 
124  $newObject->setTitle(ilUtil::stripSlashes($a_rec['title']));
125  $newObject->setDescription(ilUtil::stripSlashes($a_rec['description']));
126 
127  if (!$newObject->getId()) {
128  $newObject->create();
129  }
130 
131  if ($a_rec['Style'] ?? false) {
132  self::$style_map[(int) $a_rec['Style']][] = $newObject->getId();
133  }
134 
135  if ($a_rec['style-id'] ?? false) {
136  self::$style_map[(int) $a_rec['style-id']][] = $newObject->getId();
137  }
138 
140  $newObject->getId(),
142  (string) ((bool) $a_rec['info-tab'])
143  );
144 
145  $a_mapping->addMapping(
146  'components/ILIAS/ContentPage',
147  self::OBJ_TYPE,
148  (string) $a_rec['id'],
149  (string) $newObject->getId()
150  );
151  $a_mapping->addMapping(
152  'components/ILIAS/COPage',
153  'pg',
154  self::OBJ_TYPE . ':' . $a_rec['id'],
155  self::OBJ_TYPE . ':' . $newObject->getId()
156  );
157  $a_mapping->addMapping(
158  'components/ILIAS/MetaData',
159  'md',
160  $a_rec['id'] . ':0:' . self::OBJ_TYPE,
161  $newObject->getId() . ':0:' . self::OBJ_TYPE
162  );
163  break;
164  }
165  }
166 
167  public function getXmlRecord(
168  string $a_entity,
169  string $a_version,
170  array $a_set
171  ): array {
172  if ($a_entity === self::OBJ_TYPE) {
173  $style = $this->content_style_domain->styleForObjId((int) $a_set['id']);
174  $a_set['Style'] = $style->getStyleId();
175 
176  return $a_set;
177  }
178 
179  return parent::getXmlRecord($a_entity, $a_version, $a_set);
180  }
181 }
ILIAS Style Content DomainService $content_style_domain
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
$objId
Definition: xapitoken.php:57
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)
getTypes(string $a_entity, string $a_version)
getXmlNamespace(string $a_entity, string $a_schema_version)
readData(string $a_entity, string $a_version, array $a_ids)
getXmlRecord(string $a_entity, string $a_version, array $a_set)
importRecord(string $a_entity, array $a_types, array $a_rec, ilImportMapping $a_mapping, string $a_schema_version)
global $DIC
Definition: shib_login.php:26
static _writeContainerSetting(int $a_id, string $a_keyword, string $a_value)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
__construct(Container $dic, ilPlugin $plugin)
string $entity
static _lookupContainerSetting(int $a_id, string $a_keyword, ?string $a_default_value=null)
static _lookupType(int $id, bool $reference=false)