ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilDataCollectionExporter.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
24  protected ilDBInterface $db;
25 
26  public function init(): void
27  {
28  global $DIC;
29  $ilDB = $DIC['ilDB'];
30  $this->ds = new ilDataCollectionDataSet();
31  $this->ds->setDSPrefix('ds');
32  $this->db = $ilDB;
33  }
34 
39  public function getValidSchemaVersions(string $a_entity): array
40  {
41  return [
42  '4.5.0' => [
43  'namespace' => 'https://www.ilias.de/Modules/DataCollection/dcl/4_5',
44  'xsd_file" => "ilias_dcl_4_5.xsd',
45  'uses_dataset' => true,
46  'min' => '4.5.0',
47  'max' => '8.12',
48  ],
49  '8.13' => [
50  'namespace' => 'https://www.ilias.de/Modules/DataCollection/dcl/4_5',
51  'xsd_file" => "ilias_dcl_4_5.xsd',
52  'uses_dataset' => true,
53  'min' => '8.13',
54  'max' => '',
55  ],
56  ];
57  }
58 
59  public function getXmlRepresentation(string $a_entity, string $a_schema_version, string $a_id): string
60  {
62  $this->ds->setExportDirectories($this->dir_relative, $this->dir_absolute);
63 
64  return $this->ds->getXmlRepresentation($a_entity, $a_schema_version, [$a_id], '', true, true);
65  }
66 
75  public function getXmlExportHeadDependencies(string $a_entity, string $a_target_release, array $a_ids): array
76  {
77  $dependencies = [
79  'component' => 'Modules/File',
80  'entity' => 'file',
81  'ids' => [],
82  ],
84  'component' => 'Services/MediaObjects',
85  'entity' => 'mob',
86  'ids' => [],
87  ],
88  ];
89 
90  // Direct SQL query is faster than looping over objects
91  foreach ($a_ids as $dcl_obj_id) {
92  $sql = "SELECT stloc2.value AS ext_id, f." . $this->db->quoteIdentifier('datatype_id') . " FROM il_dcl_stloc2_value AS stloc2 "
93  . "INNER JOIN il_dcl_record_field AS rf ON (rf." . $this->db->quoteIdentifier('id') . " = stloc2." . $this->db->quoteIdentifier('record_field_id') . ") "
94  . "INNER JOIN il_dcl_field AS f ON (rf." . $this->db->quoteIdentifier('field_id') . " = f." . $this->db->quoteIdentifier('id') . ") " . "INNER JOIN il_dcl_table AS t ON (t."
95  . $this->db->quoteIdentifier('id') . " = f." . $this->db->quoteIdentifier('table_id') . ") "
96  . "WHERE t." . $this->db->quoteIdentifier('obj_id') . " = " . $this->db->quote(
97  $dcl_obj_id,
98  'integer'
99  ) . " " . "AND f.datatype_id IN ("
100  . implode(
101  ',',
102  array_keys($dependencies)
103  ) . ") AND stloc2." . $this->db->quoteIdentifier('value') . " IS NOT NULL";
104  $set = $this->db->query($sql);
105  while ($rec = $this->db->fetchObject($set)) {
106  $dependencies[$rec->datatype_id]['ids'][] = (int) $rec->ext_id;
107  }
108  }
109 
110  // Return external dependencies/IDs if there are any
111  $return = [];
112  if (count($dependencies[ilDclDatatype::INPUTFORMAT_FILEUPLOAD]['ids'])) {
113  $return[] = $dependencies[ilDclDatatype::INPUTFORMAT_FILEUPLOAD];
114  }
115  if (count($dependencies[ilDclDatatype::INPUTFORMAT_MOB]['ids'])) {
116  $return[] = $dependencies[ilDclDatatype::INPUTFORMAT_MOB];
117  }
118 
119  return $return;
120  }
121 
128  public function getXmlExportTailDependencies(string $a_entity, string $a_target_release, array $a_ids): array
129  {
130  $page_object_ids = [];
131  foreach ($a_ids as $dcl_obj_id) {
132  // If a DCL table has a detail view, we need to export the associated page objects!
133  $sql = "SELECT page_id FROM page_object "
134  . "WHERE parent_type = " . $this->db->quote(
135  'dclf',
136  'text'
137  ) . " AND parent_id = " . $this->db->quote($dcl_obj_id, 'integer');
138  $set = $this->db->query($sql);
139  while ($rec = $this->db->fetchObject($set)) {
140  $page_object_ids[] = "dclf:" . $rec->page_id;
141  }
142  }
143  if (count($page_object_ids)) {
144  return [
145  [
146  'component' => 'Services/COPage',
147  'entity' => 'pg',
148  'ids' => $page_object_ids,
149  ],
150  ];
151  }
152 
153  return [];
154  }
155 }
getXmlExportHeadDependencies(string $a_entity, string $a_target_release, array $a_ids)
MOB/File fieldtypes objects are head dependencies They must be exported and imported first...
getXmlExportTailDependencies(string $a_entity, string $a_target_release, array $a_ids)
getXmlRepresentation(string $a_entity, string $a_schema_version, string $a_id)
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28