ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilObjectDataSet.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23use ILIAS\ResourceStorage\Services as ResourceStorage;
27
38{
39 private ResourceStorage $storage;
41 private TranslationsRepository $translations_repository;
42
43 public static ?string $base_lang = null;
44
45 public function __construct()
46 {
48 global $DIC;
49 $this->storage = $DIC->resourceStorage();
50
51 $object_dic = LocalDIC::dic();
52 $this->properties_aggregator = $object_dic['properties.aggregator'];
53 $this->translations_repository = $object_dic['properties.translations.repository'];
54
56 }
57 public function getSupportedVersions(): array
58 {
59 return ['4.4.0', '5.1.0', '5.2.0', '5.4.0'];
60 }
61
62 protected function getXmlNamespace(string $entity, string $schema_version): string
63 {
64 return 'http://www.ilias.de/xml/Services/Object/' . $entity;
65 }
66
70 protected function getTypes(string $entity, string $version): array
71 {
72 if ($entity == 'transl_entry') {
73 switch ($version) {
74 case '4.4.0':
75 case '5.1.0':
76 case '5.2.0':
77 case '5.4.0':
78 return [
79 'ObjId' => 'integer',
80 'Title' => 'text',
81 'Description' => 'text',
82 'LangCode' => 'text',
83 'LangDefault' => 'integer'
84 ];
85 }
86 }
87 if ($entity == 'transl') {
88 switch ($version) {
89 case '4.4.0':
90 case '5.1.0':
91 case '5.2.0':
92 case '5.4.0':
93 return [
94 'ObjId' => 'integer',
95 'MasterLang' => 'text'
96 ];
97 }
98 }
99 if ($entity == 'service_settings') {
100 switch ($version) {
101 case '5.1.0':
102 case '5.2.0':
103 case '5.4.0':
104 return [
105 'ObjId' => 'integer',
106 'Setting' => 'text',
107 'Value' => 'text'
108 ];
109 }
110 }
111 if ($entity == 'common') {
112 if ($version == '5.4.0') {
113 return [
114 'ObjId' => 'integer'
115 ];
116 }
117 }
118 if ($entity == 'icon') {
119 if ($version == '5.4.0') {
120 return [
121 'ObjId' => 'integer',
122 'Filename' => 'text',
123 'Dir' => 'directory'
124 ];
125 }
126 }
127 if ($entity == 'tile') {
128 if ($version == '5.4.0') {
129 return [
130 'ObjId' => 'integer',
131 'Dir' => 'directory'
132 ];
133 }
134 }
135 return [];
136 }
137
138 public function readData(string $entity, string $version, array $ids): void
139 {
141 global $DIC;
142
143 if ($entity == 'transl_entry') {
144 switch ($version) {
145 case '4.4.0':
146 case '5.1.0':
147 case '5.2.0':
148 case '5.4.0':
150 'SELECT obj_id, title, description, lang_code, lang_default' . PHP_EOL
151 . 'FROM object_translation' . PHP_EOL
152 . 'WHERE ' . $this->db->in('obj_id', $ids, false, 'integer') . PHP_EOL
153 );
154 break;
155 }
156 }
157
158 if ($entity == 'transl') {
159 switch ($version) {
160 case '4.4.0':
161 case '5.1.0':
162 case '5.2.0':
163 case '5.4.0':
165 'SELECT obj_id, lang_code' . PHP_EOL
166 . 'FROM object_translation' . PHP_EOL
167 . 'WHERE ' . $this->db->in('obj_id', $ids, false, 'integer') . PHP_EOL
168 . 'AND lang_base = 1'
169 );
170 break;
171 }
172 }
173
174 if ($entity == 'service_settings') {
175 switch ($version) {
176 case '5.1.0':
177 case '5.2.0':
178 case '5.4.0':
179 $this->data = [];
180 foreach ($ids as $id) {
181 // info, news, custom metadata, tags, taxonomies, auto rating (all stored in container settings)
182 $settings = [
190 ];
191 if ($version == '5.2.0') {
193 }
194 foreach ($settings as $s) {
195 if (ilContainer::_hasContainerSetting((int) $id, $s)) {
197 $this->data[] = [
198 'ObjId' => $id,
199 'Setting' => $s,
200 'Value' => $val
201 ];
202 }
203 }
204 }
205 break;
206 }
207 }
208 // common
209 if ($entity == 'common') {
210 $this->data = [];
211 foreach ($ids as $id) {
212 $this->data[] = [
213 'ObjId' => $id
214 ];
215 }
216 }
217 // tile images
218 if ($entity == "tile") {
219 $this->data = [];
220 foreach ($ids as $id) {
221 $rid_string = $this->properties_aggregator->getFor((int) $id)
222 ->getPropertyTileImage()->getTileImage()->getRid();
223 if ($rid_string === null
224 || ($rid = $this->storage->manage()->find($rid_string)) === null) {
225 continue;
226 }
227
228 ;
229 $temp_dir = $this->copyTileToTempFolderForExport($rid);
230
231 $this->data[] = [
232 "ObjId" => $id,
233 "Dir" => $temp_dir
234 ];
235 }
236 }
237
238 // icons
239 if ($entity == 'icon') {
240 $customIconFactory = $DIC['object.customicons.factory'];
241 $this->data = [];
242 foreach ($ids as $id) {
244 $customIcon = $customIconFactory->getByObjId((int) $id, ilObject::_lookupType((int) $id));
245 if ($customIcon->exists()) {
246 $this->data[] = [
247 'ObjId' => $id,
248 'Filename' => pathinfo($customIcon->getFullPath(), PATHINFO_BASENAME),
249 'Dir' => dirname($customIcon->getFullPath())
250 ];
251 }
252 }
253 }
254 }
255
257 {
258 $path_in_container = "/dsDir_{$this->dircnt}/"
259 . $this->storage->manage()->getResource($rid)
260 ->getCurrentRevision()->getTitle();
261 $path_in_container = $this->export->isContainerExport()
262 ? $this->export->getPathToComponentExpDirInContainerWithLeadingSetNumber()
263 . $path_in_container
264 : $this->export->getPathToComponentExpDirInContainer()
265 . $path_in_container;
266 $this->export->getExportWriter()->writeFilesByResourceId(
267 $rid->serialize(),
268 $path_in_container
269 );
270 return $path_in_container;
271 }
275 protected function getDependencies(
276 string $entity,
277 string $version,
278 ?array $rec = null,
279 ?array $ids = null
280 ): array {
281 $rec['ObjId'] = $rec['ObjId'] ?? null;
282 switch ($entity) {
283 case 'common':
284 return [
285 'transl' => ['ids' => $rec['ObjId']],
286 'transl_entry' => ['ids' => $rec['ObjId']],
287 'service_settings' => ['ids' => $rec['ObjId']],
288 'tile' => ['ids' => $rec['ObjId']],
289 'icon' => ['ids' => $rec['ObjId']]
290 ];
291 }
292
293 return [];
294 }
295
296 public function importRecord(
297 string $entity,
298 array $types,
299 array $rec,
300 ilImportMapping $mapping,
301 string $schema_version
302 ): void {
304 global $DIC;
305
306 switch ($entity) {
307 case 'transl_entry':
308 $new_id = $this->getNewObjId($mapping, $rec['ObjId']);
309 if ($new_id <= 0) {
310 break;
311 }
312
313 $is_base_lang = $rec['LangCode'] === self::$base_lang;
314
315 $transl = $this->translations_repository->getFor($new_id);
316 $this->translations_repository->store(
317 $transl->withLanguage(
318 new Language(
319 $rec['LangCode'],
320 $rec['Title'],
321 $rec['Description'],
322 (bool) $rec['LangDefault'],
323 $rec['LangCode'] === self::$base_lang
324 )
325 )
326 );
327 if ($is_base_lang) {
328 self::$base_lang = null;
329 }
330 break;
331
332 case 'transl':
333 $new_id = $this->getNewObjId($mapping, $rec['ObjId']);
334 if ($new_id <= 0) {
335 break;
336 }
337 $transl = $this->translations_repository->getFor($new_id);
338 $lang_code = $rec['LangCode'] ?? $rec['MasterLang'];
339 if ($transl->getLaguageForCode($lang_code) === null) {
340 self::$base_lang = $lang_code;
341 break;
342 }
343
344 $this->translations_repository->store(
345 $transl->withBaseLanguage($lang_code)
346 );
347 break;
348
349 case 'service_settings':
350 // info, news, custom metadata, tags, taxonomies, auto rating (all stored in container settings)
351 $settings = [
360 ];
361 $new_id = (int) $this->getNewObjId($mapping, $rec['ObjId']);
362 if ($new_id > 0) {
363 if (in_array($rec['Setting'], $settings)) {
364 ilContainer::_writeContainerSetting($new_id, $rec['Setting'], $rec['Value']);
365 }
366 }
367 break;
368
369 case 'icon':
370 $new_id = (int) $this->getNewObjId($mapping, $rec['ObjId']);
371 $dir = str_replace('..', '', $rec['Dir']);
372 if ($dir != '' && $this->getImportDirectory() != '') {
373 $source_dir = $this->getImportDirectory() . '/' . $dir;
374
375 $customIconFactory = $DIC['object.customicons.factory'];
376 $customIcon = $customIconFactory->getByObjId($new_id, ilObject::_lookupType($new_id));
377 $customIcon->createFromImportDir($source_dir);
378 }
379 break;
380
381 case 'tile':
382 $new_id = (int) $this->getNewObjId($mapping, $rec['ObjId']);
383 $dir = str_replace('..', '', $rec['Dir']);
384 if ($new_id > 0 && $dir != '' && $this->getImportDirectory() != '') {
385 $source_dir = $this->getImportDirectory() . '/' . $dir;
386 $object_properties = $this->properties_aggregator->getFor($new_id);
387 $ti = $object_properties->getPropertyTileImage()->getTileImage();
388 $ti->createFromImportDir($source_dir);
389 $object_properties->storePropertyTileImage(
390 $object_properties->getPropertyTileImage()->withTileImage($ti)
391 );
392 }
393 break;
394 }
395 }
396
397 public function getNewObjId(ilImportMapping $mapping, string $old_id): int
398 {
399 global $DIC;
400
402 $objDefinition = $DIC['objDefinition'];
403
404 $new_id = $mapping->getMapping('components/ILIAS/Container', 'objs', $old_id);
405 if (!$new_id) {
406 $new_id = $mapping->getMapping('components/ILIAS/ILIASObject', 'objs', $old_id);
407 }
408 if (!$new_id) {
409 $new_id = $mapping->getMapping('components/ILIAS/ILIASObject', 'obj', $old_id);
410 }
411 if (!$new_id) {
412 foreach ($mapping->getAllMappings() as $k => $m) {
413 if (substr($k, 0, 17) == 'components/ILIAS/') {
414 foreach ($m as $type => $map) {
415 if (!$new_id) {
416 if ($objDefinition->isRBACObject($type)) {
417 $new_id = $mapping->getMapping($k, $type, $old_id);
418 }
419 }
420 }
421 }
422 }
423 }
424 return (int) $new_id;
425 }
426}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static _writeContainerSetting(int $a_id, string $a_keyword, string $a_value)
static _hasContainerSetting(int $a_id, string $a_keyword)
static _lookupContainerSetting(int $a_id, string $a_keyword, ?string $a_default_value=null)
A dataset contains in data in a common structure that can be shared and transformed for different pur...
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
getMapping(string $a_comp, string $a_entity, string $a_old_id)
Object data set class.
Aggregator $properties_aggregator
static string $base_lang
getXmlNamespace(string $entity, string $schema_version)
ResourceStorage $storage
copyTileToTempFolderForExport(ResourceIdentification $rid)
getTypes(string $entity, string $version)
Get field types for entity.
TranslationsRepository $translations_repository
getDependencies(string $entity, string $version, ?array $rec=null, ?array $ids=null)
Determine the dependent sets of data.
static _lookupType(int $id, bool $reference=false)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26