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