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