ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilObjectDataSet.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once("./Services/DataSet/classes/class.ilDataSet.php");
5
18{
25 public function getSupportedVersions()
26 {
27 return array("4.4.0", "5.1.0", "5.2.0", "5.4.0");
28 }
29
36 public function getXmlNamespace($a_entity, $a_schema_version)
37 {
38 return "http://www.ilias.de/xml/Services/Object/" . $a_entity;
39 }
40
47 protected function getTypes($a_entity, $a_version)
48 {
49 if ($a_entity == "transl_entry") {
50 switch ($a_version) {
51 case "4.4.0":
52 case "5.1.0":
53 case "5.2.0":
54 case "5.4.0":
55 return array(
56 "ObjId" => "integer",
57 "Title" => "text",
58 "Description" => "text",
59 "LangCode" => "text",
60 "LangDefault" => "integer");
61 }
62 }
63 if ($a_entity == "transl") {
64 switch ($a_version) {
65 case "4.4.0":
66 case "5.1.0":
67 case "5.2.0":
68 case "5.4.0":
69 return array(
70 "ObjId" => "integer",
71 "MasterLang" => "text");
72 }
73 }
74 if ($a_entity == "service_settings") {
75 switch ($a_version) {
76 case "5.1.0":
77 case "5.2.0":
78 case "5.4.0":
79 return array(
80 "ObjId" => "integer",
81 "Setting" => "text",
82 "Value" => "text");
83 }
84 }
85 if ($a_entity == "common") {
86 switch ($a_version) {
87 case "5.4.0":
88 return array(
89 "ObjId" => "integer"
90 );
91 }
92 }
93 if ($a_entity == "icon") {
94 switch ($a_version) {
95 case "5.4.0":
96 return array(
97 "ObjId" => "integer",
98 "Filename" => "text",
99 "Dir" => "directory");
100 }
101 }
102 if ($a_entity == "tile") {
103 switch ($a_version) {
104 case "5.4.0":
105 return array(
106 "ObjId" => "integer",
107 "Extension" => "text",
108 "Dir" => "directory");
109 }
110 }
111 }
112
119 public function readData($a_entity, $a_version, $a_ids, $a_field = "")
120 {
121 global $DIC;
122
124
125 if (!is_array($a_ids)) {
126 $a_ids = array($a_ids);
127 }
128
129 if ($a_entity == "transl_entry") {
130 switch ($a_version) {
131 case "4.4.0":
132 case "5.1.0":
133 case "5.2.0":
134 case "5.4.0":
135 $this->getDirectDataFromQuery("SELECT obj_id, title, description," .
136 " lang_code, lang_default" .
137 " FROM object_translation" .
138 " WHERE " . $ilDB->in("obj_id", $a_ids, false, "integer"));
139 break;
140 }
141 }
142
143 if ($a_entity == "transl") {
144 switch ($a_version) {
145 case "4.4.0":
146 case "5.1.0":
147 case "5.2.0":
148 case "5.4.0":
149 $this->getDirectDataFromQuery("SELECT obj_id, master_lang" .
150 " FROM obj_content_master_lng" .
151 " WHERE " . $ilDB->in("obj_id", $a_ids, false, "integer"));
152 break;
153 }
154 }
155
156 if ($a_entity == "service_settings") {
157 switch ($a_version) {
158 case "5.1.0":
159 case "5.2.0":
160 case "5.4.0":
161 include_once("./Services/Object/classes/class.ilObjectServiceSettingsGUI.php");
162 include_once("./Services/Container/classes/class.ilContainer.php");
163
164 $this->data = array();
165 foreach ($a_ids as $id) {
166 // info, news, custom metadata, tags, taxonomies, auto rating (all stored in container settings)
167 $settings = array(
175 );
176 if ($a_version == "5.2.0") {
178 }
179 foreach ($settings as $s) {
181 if ($val) {
182 $this->data[] = array(
183 "ObjId" => $id,
184 "Setting" => $s,
185 "Value" => $val
186 );
187 }
188 }
189 }
190 break;
191 }
192 }
193 // common
194 if ($a_entity == "common") {
195 $this->data = [];
196 foreach ($a_ids as $id) {
197 $this->data[] = [
198 "ObjId" => $id
199 ];
200 }
201 }
202 // tile images
203 if ($a_entity == "tile") {
204 $cs = $DIC->object()->commonSettings();
205 $this->data = [];
206 foreach ($a_ids as $id) {
207 $ti = $cs->tileImage()->getByObjId($id);
208 if ($ti->exists()) {
209 $this->data[] = [
210 "ObjId" => $id,
211 "Extension" => $ti->getExtension(),
212 "Dir" => dirname($ti->getFullPath())
213 ];
214 }
215 }
216 }
217
218 // icons
219 if ($a_entity == "icon") {
220 $customIconFactory = $DIC['object.customicons.factory'];
221 $this->data = [];
222 foreach ($a_ids as $id) {
224 $customIcon = $customIconFactory->getByObjId($id, ilObject::_lookupType($id));
225 if ($customIcon->exists()) {
226 $this->data[] = [
227 "ObjId" => $id,
228 "Filename" => pathinfo($customIcon->getFullPath(), PATHINFO_BASENAME),
229 "Dir" => dirname($customIcon->getFullPath())
230 ];
231 }
232 }
233 }
234 }
235
239 protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
240 {
241 switch ($a_entity) {
242 case "common":
243 return array(
244 "transl" => array("ids" => $a_rec["ObjId"]),
245 "transl_entry" => array("ids" => $a_rec["ObjId"]),
246 "service_settings" => array("ids" => $a_rec["ObjId"]),
247 "tile" => array("ids" => $a_rec["ObjId"]),
248 "icon" => array("ids" => $a_rec["ObjId"])
249 );
250 }
251
252 return false;
253 }
254
255
262 public function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
263 {
264 global $DIC;
265
266 switch ($a_entity) {
267 case "transl_entry":
268 $new_id = $this->getNewObjId($a_mapping, $a_rec['ObjId']);
269 if ($new_id > 0) {
270 include_once("./Services/Object/classes/class.ilObjectTranslation.php");
271 $transl = ilObjectTranslation::getInstance($new_id);
272 $transl->addLanguage(
273 $a_rec["LangCode"],
274 strip_tags(
275 $a_rec['Title'],
277 ),
278 strip_tags(
279 $a_rec['Description'],
281 ),
282 $a_rec["LangDefault"],
283 true
284 );
285 $transl->save();
286 }
287 break;
288
289 case "transl":
290 $new_id = $this->getNewObjId($a_mapping, $a_rec['ObjId']);
291 if ($new_id > 0) {
292 include_once("./Services/Object/classes/class.ilObjectTranslation.php");
293 $transl = ilObjectTranslation::getInstance($new_id);
294 $transl->setMasterLanguage($a_rec["MasterLang"]);
295 $transl->save();
296 }
297 break;
298
299 case "service_settings":
300 include_once("./Services/Object/classes/class.ilObjectServiceSettingsGUI.php");
301 include_once("./Services/Container/classes/class.ilContainer.php");
302
303 // info, news, custom metadata, tags, taxonomies, auto rating (all stored in container settings)
304 $settings = array(
313 );
314 $new_id = $this->getNewObjId($a_mapping, $a_rec['ObjId']);
315 if ($new_id > 0) {
316 if (in_array($a_rec["Setting"], $settings)) {
317 ilContainer::_writeContainerSetting($new_id, $a_rec["Setting"], $a_rec["Value"]);
318 }
319 }
320 break;
321
322 case "icon":
323 $new_id = $this->getNewObjId($a_mapping, $a_rec['ObjId']);
324 $dir = str_replace("..", "", $a_rec["Dir"]);
325 if ($dir != "" && $this->getImportDirectory() != "") {
326 $source_dir = $this->getImportDirectory() . "/" . $dir;
327
328 $customIconFactory = $DIC['object.customicons.factory'];
329 $customIcon = $customIconFactory->getByObjId($new_id, ilObject::_lookupType($new_id));
330 $customIcon->createFromImportDir($source_dir, $a_rec["Filename"]);
331 }
332 break;
333
334 case "tile":
335 $new_id = $this->getNewObjId($a_mapping, $a_rec['ObjId']);
336 $dir = str_replace("..", "", $a_rec["Dir"]);
337 if ($new_id > 0 && $dir != "" && $this->getImportDirectory() != "") {
338 $source_dir = $this->getImportDirectory() . "/" . $dir;
339 $cs = $DIC->object()->commonSettings();
340 $ti = $cs->tileImage()->getByObjId($new_id);
341 $ti->createFromImportDir($source_dir, $a_rec["Extension"]);
342 }
343 break;
344 }
345 }
346
354 public function getNewObjId($a_mapping, $old_id)
355 {
356 global $DIC;
357
359 $objDefinition = $DIC["objDefinition"];
360
361 $new_id = $a_mapping->getMapping('Services/Container', 'objs', $old_id);
362 if (!$new_id) {
363 $new_id = $a_mapping->getMapping('Services/Object', 'objs', $old_id);
364 }
365 if (!$new_id) {
366 $new_id = $a_mapping->getMapping('Services/Object', 'obj', $old_id);
367 }
368 if (!$new_id) {
369 foreach ($a_mapping->getAllMappings() as $k => $m) {
370 if (substr($k, 0, 8) == "Modules/") {
371 foreach ($m as $type => $map) {
372 if (!$new_id) {
373 if ($objDefinition->isRBACObject($type)) {
374 $new_id = $a_mapping->getMapping($k, $type, $old_id);
375 }
376 }
377 }
378 }
379 }
380 }
381 return $new_id;
382 }
383}
An exception for terminatinating execution or to throw for unit testing.
static _lookupContainerSetting($a_id, $a_keyword, $a_default_value=null)
Lookup a container setting.
static _writeContainerSetting($a_id, $a_keyword, $a_value)
A dataset contains in data in a common structure that can be shared and transformed for different pur...
getDirectDataFromQuery($a_query, $a_convert_to_leading_upper=true, $a_set=true)
Get data from query.This is a standard procedure, all db field names are directly mapped to abstract ...
getImportDirectory()
Get import directory.
readData($a_entity, $a_version, $a_ids)
Read data from DB.
Object data set class.
getSupportedVersions()
Get supported versions.
importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
Import record.
getTypes($a_entity, $a_version)
Get field types for entity.
getXmlNamespace($a_entity, $a_schema_version)
Get xml namespace.
getDependencies($a_entity, $a_version, $a_rec, $a_ids)
Determine the dependent sets of data.
const ALLOWED_TAGS_IN_TITLE_AND_DESCRIPTION
static getInstance($a_obj_id)
Get instance.
static _lookupType($a_id, $a_reference=false)
lookup object type
global $DIC
Definition: goto.php:24
$type
global $ilDB