ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
4 include_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 
123  $ilDB = $this->db;
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) {
180  $val = ilContainer::_lookupContainerSetting($id, $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  "service_settings" => array("ids" => $a_rec["ObjId"]),
246  "tile" => array("ids" => $a_rec["ObjId"]),
247  "icon" => array("ids" => $a_rec["ObjId"])
248  );
249 
250  case "transl":
251  return array(
252  "transl_entry" => array("ids" => $a_rec["ObjId"])
253  );
254  }
255 
256  return false;
257  }
258 
259 
266  public function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
267  {
268  global $DIC;
269 
270  switch ($a_entity) {
271  case "transl_entry":
272  $new_id = $this->getNewObjId($a_mapping, $a_rec['ObjId']);
273  if ($new_id > 0) {
274  include_once("./Services/Object/classes/class.ilObjectTranslation.php");
275  $transl = ilObjectTranslation::getInstance($new_id);
276  $transl->addLanguage(
277  $a_rec["LangCode"],
278  $a_rec["Title"],
279  $a_rec["Description"],
280  $a_rec["LangDefault"],
281  true
282  );
283  $transl->save();
284  }
285  break;
286 
287  case "transl":
288  $new_id = $this->getNewObjId($a_mapping, $a_rec['ObjId']);
289  if ($new_id > 0) {
290  include_once("./Services/Object/classes/class.ilObjectTranslation.php");
291  $transl = ilObjectTranslation::getInstance($new_id);
292  $transl->setMasterLanguage($a_rec["MasterLang"]);
293  $transl->save();
294  }
295  break;
296 
297  case "service_settings":
298  include_once("./Services/Object/classes/class.ilObjectServiceSettingsGUI.php");
299  include_once("./Services/Container/classes/class.ilContainer.php");
300 
301  // info, news, custom metadata, tags, taxonomies, auto rating (all stored in container settings)
302  $settings = array(
311  );
312  $new_id = $this->getNewObjId($a_mapping, $a_rec['ObjId']);
313  if ($new_id > 0) {
314  if (in_array($a_rec["Setting"], $settings)) {
315  ilContainer::_writeContainerSetting($new_id, $a_rec["Setting"], $a_rec["Value"]);
316  }
317  }
318  break;
319 
320  case "icon":
321  $new_id = $this->getNewObjId($a_mapping, $a_rec['ObjId']);
322  $dir = str_replace("..", "", $a_rec["Dir"]);
323  if ($dir != "" && $this->getImportDirectory() != "") {
324  $source_dir = $this->getImportDirectory() . "/" . $dir;
325 
326  $customIconFactory = $DIC['object.customicons.factory'];
327  $customIcon = $customIconFactory->getByObjId($new_id, ilObject::_lookupType($new_id));
328  $customIcon->createFromImportDir($source_dir, $a_rec["Filename"]);
329  }
330  break;
331 
332  case "tile":
333  $new_id = $this->getNewObjId($a_mapping, $a_rec['ObjId']);
334  $dir = str_replace("..", "", $a_rec["Dir"]);
335  if ($new_id > 0 && $dir != "" && $this->getImportDirectory() != "") {
336  $source_dir = $this->getImportDirectory() . "/" . $dir;
337  $cs = $DIC->object()->commonSettings();
338  $ti = $cs->tileImage()->getByObjId($new_id);
339  $ti->createFromImportDir($source_dir, $a_rec["Extension"]);
340  }
341  break;
342  }
343  }
344 
352  public function getNewObjId($a_mapping, $old_id)
353  {
354  global $DIC;
355 
357  $objDefinition = $DIC["objDefinition"];
358 
359  $new_id = $a_mapping->getMapping('Services/Container', 'objs', $old_id);
360  if (!$new_id) {
361  $new_id = $a_mapping->getMapping('Services/Object', 'objs', $old_id);
362  }
363  if (!$new_id) {
364  $new_id = $a_mapping->getMapping('Services/Object', 'obj', $old_id);
365  }
366  if (!$new_id) {
367  foreach ($a_mapping->getAllMappings() as $k => $m) {
368  if (substr($k, 0, 8) == "Modules/") {
369  foreach ($m as $type => $map) {
370  if (!$new_id) {
371  if ($objDefinition->isRBACObject($type)) {
372  $new_id = $a_mapping->getMapping($k, $type, $old_id);
373  }
374  }
375  }
376  }
377  }
378  }
379  return $new_id;
380  }
381 }
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 ...
$type
global $DIC
Definition: saml.php:7
if(!array_key_exists('StateId', $_REQUEST)) $id
Object data set class.
$s
Definition: pwgen.php:45
getImportDirectory()
Get import directory.
readData($a_entity, $a_version, $a_ids)
Read data from DB.
static _lookupType($a_id, $a_reference=false)
lookup object type
getDependencies($a_entity, $a_version, $a_rec, $a_ids)
Determine the dependent sets of data.
importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
Import record.
getSupportedVersions()
Get supported versions.
$this data['403_header']
static getInstance($a_obj_id)
Get instance.
global $ilDB
static _writeContainerSetting($a_id, $a_keyword, $a_value)
getXmlNamespace($a_entity, $a_schema_version)
Get xml namespace.
A dataset contains in data in a common structure that can be shared and transformed for different pur...
getTypes($a_entity, $a_version)
Get field types for entity.
static _lookupContainerSetting($a_id, $a_keyword, $a_default_value=null)
Lookup a container setting.