ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilAdvancedMetaDataExporter.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/Export/classes/class.ilXmlExporter.php");
5
14{
15 private $ds;
16
17 private static $local_recs_done = array();
18
22 public function init()
23 {
24 }
25
34 public function getXmlExportHeadDependencies($a_entity, $a_target_release, $a_ids)
35 {
36 return array();
37 }
38
39
48 public function getXmlExportTailDependencies($a_entity, $a_target_release, $a_ids)
49 {
50 return array();
51 }
52
61 public function getXmlRepresentation($a_entity, $a_schema_version, $a_id)
62 {
63 $parts = explode(":", $a_id);
64 if (sizeof($parts) != 2) {
65 return;
66 }
67 $obj_id = $parts[0];
68 $rec_id = $parts[1];
69
70 // any data for current record and object?
71 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
73 if (!$raw) {
74 return;
75 }
76
77 // gather sub-item data from value entries
78 $sub_items = array();
79 foreach ($raw as $item) {
80 $sub_items[$item["sub_type"]][] = $item["sub_id"];
81 }
82
83 // gather all relevant data
84 $items = array();
85 foreach ($sub_items as $sub_type => $sub_ids) {
86 foreach (array_unique($sub_ids) as $sub_id) {
87 $values_record = new ilAdvancedMDValues($rec_id, $obj_id, $sub_type, $sub_id);
88 $defs = $values_record->getDefinitions();
89 $values_record->read();
90 foreach ($values_record->getADTGroup()->getElements() as $element_id => $element) {
91 if (!$element->isNull()) {
92 $def = $defs[$element_id];
93 $items[$rec_id][] = array(
94 'id' => $def->generateImportId($def->getFieldId()),
95 'sub_type' => $sub_type,
96 'sub_id' => $sub_id,
97 'value' => $def->getValueForXML($element)
98 );
99 }
100 }
101 }
102 }
103
104 // #17066 - local advmd record
105 $local_recs = array();
106 $rec_obj = new ilAdvancedMDRecord($rec_id);
107 if ($rec_obj->getParentObject()) {
108 $xml = new ilXmlWriter;
109 $rec_obj->toXML($xml);
110 $xml = $xml->xmlDumpMem(false);
111
112 $local_recs[$rec_obj->getRecordId()] = base64_encode($xml);
113 }
114
115 // we only want non-empty fields
116 if (sizeof($items)) {
117 $xml = new ilXmlWriter;
118
119 foreach ($items as $record_id => $record_items) {
120 $xml->xmlStartTag('AdvancedMetaData');
121
122 $is_local = array_key_exists($record_id, $local_recs);
123
124 // add local record data?
125 if ($is_local) {
126 // we need to add this only once
127 if (!array_key_exists($record_id, self::$local_recs_done)) {
128 $xml->xmlElement(
129 'Record',
130 array('local_id' => $record_id),
131 $local_recs[$record_id]
132 );
133
134 self::$local_recs_done[] = $record_id;
135 }
136 }
137
138 foreach ($record_items as $item) {
139 $att = array(
140 'id' => $item['id'],
141 'sub_type' => $item['sub_type'],
142 'sub_id' => $item['sub_id']
143 );
144
145 if ($is_local) {
146 $att['local_rec_id'] = $record_id;
147 }
148
149 $xml->xmlElement(
150 'Value',
151 $att,
152 $item['value']
153 );
154 }
155
156 $xml->xmlEndTag('AdvancedMetaData');
157 }
158
159 return $xml->xmlDumpMem(false);
160 }
161 }
162
170 public function getValidSchemaVersions($a_entity)
171 {
172 return array(
173 "4.4.0" => array(
174 "namespace" => "http://www.ilias.de/Services/AdvancedMetaData/advmd/4_4",
175 "xsd_file" => "ilias_advmd_4_4.xsd",
176 "uses_dataset" => true,
177 "min" => "4.4.0",
178 "max" => "")
179 );
180 }
181}
An exception for terminatinating execution or to throw for unit testing.
static findByObjectId($a_obj_id)
Find all entries for object (regardless of sub-type/sub-id)
getXmlExportHeadDependencies($a_entity, $a_target_release, $a_ids)
Get head dependencies.
getValidSchemaVersions($a_entity)
Returns schema versions that the component can export to.
getXmlRepresentation($a_entity, $a_schema_version, $a_id)
Get xml representation.
getXmlExportTailDependencies($a_entity, $a_target_release, $a_ids)
Get tail dependencies.
Xml Exporter class.
XML writer class.
$def
Definition: croninfo.php:21