ILIAS  release_8 Revision v8.24
class.ilObjectDataSet.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
31{
32 public function getSupportedVersions(): array
33 {
34 return ['4.4.0', '5.1.0', '5.2.0', '5.4.0'];
35 }
36
37 protected function getXmlNamespace(string $entity, string $schema_version): string
38 {
39 return 'http://www.ilias.de/xml/Services/Object/' . $entity;
40 }
41
45 protected function getTypes(string $entity, string $version): array
46 {
47 if ($entity == 'transl_entry') {
48 switch ($version) {
49 case '4.4.0':
50 case '5.1.0':
51 case '5.2.0':
52 case '5.4.0':
53 return [
54 'ObjId' => 'integer',
55 'Title' => 'text',
56 'Description' => 'text',
57 'LangCode' => 'text',
58 'LangDefault' => 'integer'
59 ];
60 }
61 }
62 if ($entity == 'transl') {
63 switch ($version) {
64 case '4.4.0':
65 case '5.1.0':
66 case '5.2.0':
67 case '5.4.0':
68 return [
69 'ObjId' => 'integer',
70 'MasterLang' => 'text'
71 ];
72 }
73 }
74 if ($entity == 'service_settings') {
75 switch ($version) {
76 case '5.1.0':
77 case '5.2.0':
78 case '5.4.0':
79 return [
80 'ObjId' => 'integer',
81 'Setting' => 'text',
82 'Value' => 'text'
83 ];
84 }
85 }
86 if ($entity == 'common') {
87 if ($version == '5.4.0') {
88 return [
89 'ObjId' => 'integer'
90 ];
91 }
92 }
93 if ($entity == 'icon') {
94 if ($version == '5.4.0') {
95 return [
96 'ObjId' => 'integer',
97 'Filename' => 'text',
98 'Dir' => 'directory'
99 ];
100 }
101 }
102 if ($entity == 'tile') {
103 if ($version == '5.4.0') {
104 return [
105 'ObjId' => 'integer',
106 'Extension' => 'text',
107 'Dir' => 'directory'
108 ];
109 }
110 }
111 return [];
112 }
113
114 public function readData(string $entity, string $version, array $ids): void
115 {
116 global $DIC;
117
118 if ($entity == 'transl_entry') {
119 switch ($version) {
120 case '4.4.0':
121 case '5.1.0':
122 case '5.2.0':
123 case '5.4.0':
125 'SELECT obj_id, title, description, lang_code, lang_default' . PHP_EOL
126 . 'FROM object_translation' . PHP_EOL
127 . 'WHERE ' . $this->db->in('obj_id', $ids, false, 'integer') . PHP_EOL
128 );
129 break;
130 }
131 }
132
133 if ($entity == 'transl') {
134 switch ($version) {
135 case '4.4.0':
136 case '5.1.0':
137 case '5.2.0':
138 case '5.4.0':
140 'SELECT obj_id, master_lang' . PHP_EOL
141 . 'FROM obj_content_master_lng' . PHP_EOL
142 . 'WHERE ' . $this->db->in('obj_id', $ids, false, 'integer') . PHP_EOL
143 );
144 break;
145 }
146 }
147
148 if ($entity == 'service_settings') {
149 switch ($version) {
150 case '5.1.0':
151 case '5.2.0':
152 case '5.4.0':
153 $this->data = [];
154 foreach ($ids as $id) {
155 // info, news, custom metadata, tags, taxonomies, auto rating (all stored in container settings)
156 $settings = [
164 ];
165 if ($version == '5.2.0') {
167 }
168 foreach ($settings as $s) {
169 if (ilContainer::_hasContainerSetting((int) $id, $s)) {
171 $this->data[] = [
172 'ObjId' => $id,
173 'Setting' => $s,
174 'Value' => $val
175 ];
176 }
177 }
178 }
179 break;
180 }
181 }
182 // common
183 if ($entity == 'common') {
184 $this->data = [];
185 foreach ($ids as $id) {
186 $this->data[] = [
187 'ObjId' => $id
188 ];
189 }
190 }
191 // tile images
192 if ($entity == 'tile') {
193 $cs = $DIC->object()->commonSettings();
194 $this->data = [];
195 foreach ($ids as $id) {
196 $ti = $cs->tileImage()->getByObjId((int) $id);
197 if ($ti->exists()) {
198 $this->data[] = [
199 'ObjId' => $id,
200 'Extension' => $ti->getExtension(),
201 'Dir' => dirname($ti->getFullPath())
202 ];
203 }
204 }
205 }
206
207 // icons
208 if ($entity == 'icon') {
209 $customIconFactory = $DIC['object.customicons.factory'];
210 $this->data = [];
211 foreach ($ids as $id) {
213 $customIcon = $customIconFactory->getByObjId((int) $id, ilObject::_lookupType((int) $id));
214 if ($customIcon->exists()) {
215 $this->data[] = [
216 'ObjId' => $id,
217 'Filename' => pathinfo($customIcon->getFullPath(), PATHINFO_BASENAME),
218 'Dir' => dirname($customIcon->getFullPath())
219 ];
220 }
221 }
222 }
223 }
224
228 protected function getDependencies(
229 string $entity,
230 string $version,
231 ?array $rec = null,
232 ?array $ids = null
233 ): array {
234 $rec['ObjId'] = $rec['ObjId'] ?? null;
235 switch ($entity) {
236 case 'common':
237 return [
238 'transl' => ['ids' => $rec['ObjId']],
239 'transl_entry' => ['ids' => $rec['ObjId']],
240 'service_settings' => ['ids' => $rec['ObjId']],
241 'tile' => ['ids' => $rec['ObjId']],
242 'icon' => ['ids' => $rec['ObjId']]
243 ];
244 }
245
246 return [];
247 }
248
249 public function importRecord(
250 string $entity,
251 array $types,
252 array $rec,
253 ilImportMapping $mapping,
254 string $schema_version
255 ): void {
256 global $DIC;
257
258 switch ($entity) {
259 case 'transl_entry':
260 $new_id = $this->getNewObjId($mapping, $rec['ObjId']);
261 if ($new_id > 0) {
262 $transl = ilObjectTranslation::getInstance($new_id);
263 $transl->addLanguage(
264 $rec['LangCode'],
265 strip_tags(
266 $rec['Title'],
268 ),
269 strip_tags(
270 $rec['Description'],
272 ),
273 (bool) $rec['LangDefault'],
274 true
275 );
276 $transl->save();
277 }
278 break;
279
280 case 'transl':
281 $new_id = $this->getNewObjId($mapping, $rec['ObjId']);
282 if ($new_id > 0) {
283 $transl = ilObjectTranslation::getInstance($new_id);
284 $transl->setMasterLanguage($rec['MasterLang']);
285 $transl->save();
286 }
287 break;
288
289 case 'service_settings':
290 // info, news, custom metadata, tags, taxonomies, auto rating (all stored in container settings)
291 $settings = [
300 ];
301 $new_id = (int) $this->getNewObjId($mapping, $rec['ObjId']);
302 if ($new_id > 0) {
303 if (in_array($rec['Setting'], $settings)) {
304 ilContainer::_writeContainerSetting($new_id, $rec['Setting'], $rec['Value']);
305 }
306 }
307 break;
308
309 case 'icon':
310 $new_id = (int) $this->getNewObjId($mapping, $rec['ObjId']);
311 $dir = str_replace('..', '', $rec['Dir']);
312 if ($dir != '' && $this->getImportDirectory() != '') {
313 $source_dir = $this->getImportDirectory() . '/' . $dir;
314
316 $customIconFactory = $DIC['object.customicons.factory'];
317 $customIcon = $customIconFactory->getByObjId($new_id, ilObject::_lookupType($new_id));
318 $customIcon->createFromImportDir($source_dir);
319 }
320 break;
321
322 case 'tile':
323 $new_id = (int) $this->getNewObjId($mapping, $rec['ObjId']);
324 $dir = str_replace('..', '', $rec['Dir']);
325 if ($new_id > 0 && $dir != '' && $this->getImportDirectory() != '') {
326 $source_dir = $this->getImportDirectory() . '/' . $dir;
327 $cs = $DIC->object()->commonSettings();
328 $ti = $cs->tileImage()->getByObjId($new_id);
329 $ti->createFromImportDir($source_dir, $rec['Extension']);
330 }
331 break;
332 }
333 }
334
335 public function getNewObjId(ilImportMapping $mapping, string $old_id): int
336 {
337 global $DIC;
338
340 $objDefinition = $DIC['objDefinition'];
341
342 $new_id = $mapping->getMapping('Services/Container', 'objs', $old_id);
343 if (!$new_id) {
344 $new_id = $mapping->getMapping('Services/Object', 'objs', $old_id);
345 }
346 if (!$new_id) {
347 $new_id = $mapping->getMapping('Services/Object', 'obj', $old_id);
348 }
349 if (!$new_id) {
350 foreach ($mapping->getAllMappings() as $k => $m) {
351 if (substr($k, 0, 8) == 'Modules/') {
352 foreach ($m as $type => $map) {
353 if (!$new_id) {
354 if ($objDefinition->isRBACObject($type)) {
355 $new_id = $mapping->getMapping($k, $type, $old_id);
356 }
357 }
358 }
359 }
360 }
361 }
362 return (int) $new_id;
363 }
364}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static _writeContainerSetting(int $a_id, string $a_keyword, string $a_value)
static _lookupContainerSetting(int $a_id, string $a_keyword, string $a_default_value=null)
static _hasContainerSetting(int $a_id, string $a_keyword)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
readData(string $a_entity, string $a_version, array $a_ids)
Read data from DB.
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 ...
string $schema_version
string $version
string $entity
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getMapping(string $a_comp, string $a_entity, string $a_old_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getXmlNamespace(string $entity, string $schema_version)
getTypes(string $entity, string $version)
Get field types for entity.
getDependencies(string $entity, string $version, ?array $rec=null, ?array $ids=null)
Determine the dependent sets of data.
const ALLOWED_TAGS_IN_TITLE_AND_DESCRIPTION
static getInstance(int $obj_id)
static _lookupType(int $id, bool $reference=false)
global $DIC
Definition: feed.php:28
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
$type