ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 function init()
23 {
24
25 }
26
35 function getXmlExportHeadDependencies($a_entity, $a_target_release, $a_ids)
36 {
37 return array();
38 }
39
40
49 function getXmlExportTailDependencies($a_entity, $a_target_release, $a_ids)
50 {
51 return array();
52 }
53
62 public function getXmlRepresentation($a_entity, $a_schema_version, $a_id)
63 {
64 $parts = explode(":", $a_id);
65 if(sizeof($parts) != 2)
66 {
67 return;
68 }
69 $obj_id = $parts[0];
70 $rec_id = $parts[1];
71
72 // any data for current record and object?
73 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
75 if(!$raw)
76 {
77 return;
78 }
79
80 // gather sub-item data from value entries
81 $sub_items = array();
82 foreach($raw as $item)
83 {
84 $sub_items[$item["sub_type"]][] = $item["sub_id"];
85 }
86
87 // gather all relevant data
88 $items = array();
89 foreach($sub_items as $sub_type => $sub_ids)
90 {
91 foreach(array_unique($sub_ids) as $sub_id)
92 {
93 $values_record = new ilAdvancedMDValues($rec_id, $obj_id, $sub_type, $sub_id);
94 $defs = $values_record->getDefinitions();
95 $values_record->read();
96 foreach($values_record->getADTGroup()->getElements() as $element_id => $element)
97 {
98 if(!$element->isNull())
99 {
100 $def = $defs[$element_id];
101 $items[$rec_id][] =array(
102 'id' => $def->generateImportId($def->getFieldId()),
103 'sub_type' => $sub_type,
104 'sub_id' => $sub_id,
105 'value' => $def->getValueForXML($element)
106 );
107 }
108 }
109 }
110 }
111
112 // #17066 - local advmd record
113 $local_recs = array();
114 $rec_obj = new ilAdvancedMDRecord($rec_id);
115 if($rec_obj->getParentObject())
116 {
117 $xml = new ilXmlWriter;
118 $rec_obj->toXML($xml);
119 $xml = $xml->xmlDumpMem(false);
120
121 $local_recs[$rec_obj->getRecordId()] = base64_encode($xml);
122 }
123
124 // we only want non-empty fields
125 if(sizeof($items))
126 {
127 $xml = new ilXmlWriter;
128
129 foreach($items as $record_id => $record_items)
130 {
131 $xml->xmlStartTag('AdvancedMetaData');
132
133 $is_local = array_key_exists($record_id, $local_recs);
134
135 // add local record data?
136 if($is_local)
137 {
138 // we need to add this only once
139 if(!array_key_exists($record_id, self::$local_recs_done))
140 {
141 $xml->xmlElement(
142 'Record',
143 array('local_id' => $record_id),
144 $local_recs[$record_id]
145 );
146
147 self::$local_recs_done[] = $record_id;
148 }
149 }
150
151 foreach($record_items as $item)
152 {
153 $att = array(
154 'id' => $item['id'],
155 'sub_type' => $item['sub_type'],
156 'sub_id' => $item['sub_id']
157 );
158
159 if($is_local)
160 {
161 $att['local_rec_id'] = $record_id;
162 }
163
164 $xml->xmlElement(
165 'Value',
166 $att,
167 $item['value']
168 );
169 }
170
171 $xml->xmlEndTag('AdvancedMetaData');
172 }
173
174 return $xml->xmlDumpMem(false);
175 }
176 }
177
185 function getValidSchemaVersions($a_entity)
186 {
187 return array (
188 "4.4.0" => array(
189 "namespace" => "http://www.ilias.de/Services/AdvancedMetaData/advmd/4_4",
190 "xsd_file" => "ilias_advmd_4_4.xsd",
191 "uses_dataset" => true,
192 "min" => "4.4.0",
193 "max" => "")
194 );
195 }
196
197}
198
199?>
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.
xmlDumpMem($format=TRUE)
Returns xml document from memory.
xmlStartTag($tag, $attrs=NULL, $empty=FALSE, $encode=TRUE, $escape=TRUE)
Writes a starttag.