ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilAdvancedMDParser Class Reference

Adv MD XML Parser. More...

+ Inheritance diagram for ilAdvancedMDParser:
+ Collaboration diagram for ilAdvancedMDParser:

Public Member Functions

 __construct (string $a_obj_id, ilImportMapping $a_mapping)
 
 setHandlers ($a_xml_parser)
 
 createLocalRecord (int $a_old_id, string $a_xml, int $a_obj_id, ?string $a_sub_type=null)
 
 handlerBeginTag ($a_xml_parser, string $a_name, array $a_attribs)
 Start element handler. More...
 
 handlerEndTag ($a_xml_parser, string $a_name)
 End element handler. More...
 
 handlerCharacterData ($a_xml_parser, string $a_data)
 Character data handler. More...
 
 getRecordIds ()
 
- Public Member Functions inherited from ilSaxParser
 __construct (?string $path_to_file='', ?bool $throw_exception=false)
 
 setXMLContent (string $a_xml_content)
 
 getXMLContent ()
 
 getInputType ()
 
 startParsing ()
 stores xml data in array More...
 
 createParser ()
 
 setHandlers ($a_xml_parser)
 
 parse ($a_xml_parser, $a_fp=null)
 
 handlerBeginTag ($a_xml_parser, string $a_name, array $a_attribs)
 Start element handler. More...
 
 handlerEndTag ($a_xml_parser, string $a_name)
 End element handler. More...
 
 handlerCharacterData ($a_xml_parser, string $a_name)
 Character data handler. More...
 

Protected Member Functions

 initValue (string $a_import_id, string $a_sub_type="", int $a_sub_id=0, ?int $a_local_rec_id=null)
 
- Protected Member Functions inherited from ilSaxParser
 openXMLFile ()
 
 handleError (string $message)
 
 setThrowException (bool $throw_exception)
 

Protected Attributes

int $obj_id
 
int $rec_id = 0
 
ilImportMapping $mapping
 
string $cdata = ""
 
ilSaxController $sax_controller = null
 
array $value_records = []
 
ilAdvancedMDFieldDefinition $current_value = null
 
array $record_ids = []
 
array $local_record = null
 
array $local_rec_map = []
 
array $local_rec_fields_map = []
 
ilLogger $log
 
- Protected Attributes inherited from ilSaxParser
ilLanguage $lng = null
 

Additional Inherited Members

- Data Fields inherited from ilSaxParser
string $xml_file
 
bool $throw_exception = false
 

Detailed Description

Adv MD XML Parser.

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 25 of file class.ilAdvancedMDParser.php.

Constructor & Destructor Documentation

◆ __construct()

ilAdvancedMDParser::__construct ( string  $a_obj_id,
ilImportMapping  $a_mapping 
)

Definition at line 51 of file class.ilAdvancedMDParser.php.

52 {
54
55 $this->log = ilLoggerFactory::getLogger('amet');
56
57 $parts = explode(":", $a_obj_id);
58 $this->obj_id = (int) $parts[0];
59 $this->mapping = $a_mapping;
60 }
static getLogger(string $a_component_id)
Get component logger.
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:61
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References $parts, ILIAS\GlobalScreen\Provider\__construct(), ilLoggerFactory\getLogger(), and ILIAS\Repository\int().

+ Here is the call graph for this function:

Member Function Documentation

◆ createLocalRecord()

ilAdvancedMDParser::createLocalRecord ( int  $a_old_id,
string  $a_xml,
int  $a_obj_id,
?string  $a_sub_type = null 
)

Definition at line 69 of file class.ilAdvancedMDParser.php.

69 : void
70 {
71 $tmp_file = ilFileUtils::ilTempnam();
72 file_put_contents($tmp_file, $a_xml);
73
74 // see ilAdvancedMDSettingsGUI::importRecord()
75 $parser = null;
76 try {
77 // the (old) record parser does only support files
78 $parser = new ilAdvancedMDRecordParser($tmp_file);
79 $parser->setContext($a_obj_id, ilObject::_lookupType($a_obj_id), $a_sub_type);
81 $parser->startParsing();
83 $parser->startParsing();
84 } catch (ilSaxParserException $exc) {
85 $this->log->error('Parsing failed with message: ' . $exc->getMessage());
86 return;
87 } finally {
88 unlink($tmp_file);
89 }
90 $map = $parser->getRecordMap();
91 foreach ($map as $record_id => $fields) {
92 $this->local_rec_fields_map[$record_id] = $fields;
93
94 // needed for glossary field order
95 foreach ($fields as $import_id => $new_id) {
96 $import_ids = explode('_', $import_id);
97 $old_id = array_pop($import_ids);
98 $this->mapping->addMapping("components/ILIAS/AdvancedMetaData", "lfld", $old_id, (string) $new_id);
99 }
100 }
101 $map_keys = array_keys($map);
102 $new_id = array_shift($map_keys);
103 $this->local_rec_map[$a_old_id] = $new_id;
104 }
SAX based XML parser for record import files.
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
static _lookupType(int $id, bool $reference=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References ilObject\_lookupType(), ilFileUtils\ilTempnam(), ilAdvancedMDRecordParser\MODE_INSERT, and ilAdvancedMDRecordParser\MODE_INSERT_VALIDATION.

+ Here is the call graph for this function:

◆ getRecordIds()

ilAdvancedMDParser::getRecordIds ( )
Returns
int[]

Definition at line 279 of file class.ilAdvancedMDParser.php.

279 : array
280 {
281 return $this->record_ids;
282 }

◆ handlerBeginTag()

ilAdvancedMDParser::handlerBeginTag (   $a_xml_parser,
string  $a_name,
array  $a_attribs 
)

Start element handler.

Parameters
resource$a_xml_parserxml parser

Implements ilSaxSubsetParser.

Definition at line 106 of file class.ilAdvancedMDParser.php.

106 : void
107 {
108 switch ($a_name) {
109 case 'AdvancedMetaData':
110 break;
111
112 case 'Record':
113 $this->local_record = array('id' => $a_attribs['local_id']);
114 break;
115
116 case 'Value':
117 $this->initValue(
118 (string) $a_attribs['id'],
119 (string) $a_attribs['sub_type'],
120 (int) $a_attribs['sub_id'],
121 isset($a_attribs['local_rec_id']) ? (int) $a_attribs['local_rec_id'] : null
122 );
123 break;
124 }
125 }
initValue(string $a_import_id, string $a_sub_type="", int $a_sub_id=0, ?int $a_local_rec_id=null)

References initValue().

+ Here is the call graph for this function:

◆ handlerCharacterData()

ilAdvancedMDParser::handlerCharacterData (   $a_xml_parser,
string  $a_name 
)

Character data handler.

Parameters
resource$a_xml_parserxml parser

Implements ilSaxSubsetParser.

Definition at line 153 of file class.ilAdvancedMDParser.php.

153 : void
154 {
155 if ($a_data != "\n") {
156 // Replace multiple tabs with one space
157 $a_data = preg_replace("/\t+/", " ", $a_data);
158
159 $this->cdata .= $a_data;
160 }
161 }

◆ handlerEndTag()

ilAdvancedMDParser::handlerEndTag (   $a_xml_parser,
string  $a_name 
)

End element handler.

Parameters
resource$a_xml_parserxml parser

Implements ilSaxSubsetParser.

Definition at line 127 of file class.ilAdvancedMDParser.php.

127 : void
128 {
129 switch ($a_name) {
130 case 'AdvancedMetaData':
131 // we need to write all records that have been created (1 for each sub-item)
132 foreach ($this->value_records as $record) {
133 $record->write();
134 }
135 break;
136
137 case 'Record':
138 $this->local_record['xml'] = base64_decode(trim($this->cdata));
139 $this->log->debug("Local Record XML: " . $this->local_record['xml']);
140 break;
141
142 case 'Value':
143 $value = trim($this->cdata);
144 $this->log->debug("End Tag Value: -" . is_object($this->current_value) . "-" . $value);
145 if (is_object($this->current_value) && $value != "") {
146 $this->current_value->importValueFromXML($value);
147 }
148 break;
149 }
150 $this->cdata = '';
151 }

◆ initValue()

ilAdvancedMDParser::initValue ( string  $a_import_id,
string  $a_sub_type = "",
int  $a_sub_id = 0,
?int  $a_local_rec_id = null 
)
protected

Definition at line 163 of file class.ilAdvancedMDParser.php.

168 : void {
169 $this->current_value = null;
170
171 // get parent objects
172 $new_parent_id = (int) $this->mapping->getMapping("components/ILIAS/AdvancedMetaData", "parent", (string) $this->obj_id);
173 $this->log->notice('Found new parent id:' . $new_parent_id);
174 if (!$new_parent_id) {
175 return;
176 }
177 $new_sub_id = '';
178 if ($a_sub_type && strcmp($a_sub_type, '-') !== 0) {
179 $new_sub_id = $this->mapping->getMapping(
180 "components/ILIAS/AdvancedMetaData",
181 "advmd_sub_item",
182 "advmd:" . $a_sub_type . ":" . $a_sub_id
183 );
184 if (!$new_sub_id) {
185 return;
186 }
187 }
188
189 // init local record?
190 // done here because we need object context
191 if (is_array($this->local_record)) {
192 $this->createLocalRecord(
193 (int) $this->local_record['id'],
194 $this->local_record['xml'],
195 $new_parent_id,
196 $a_sub_type
197 );
198 $this->local_record = null;
199 }
200
201 $rec_id = null;
202
203 // find record via import id
204 if (!$a_local_rec_id) {
205 if ($field = ilAdvancedMDFieldDefinition::getInstanceByImportId($a_import_id)) {
206 $rec_id = $field->getRecordId();
207 }
208 } // (new) local record
209 else {
210 $rec_id = $this->local_rec_map[$a_local_rec_id];
211 }
212
213 if (!$rec_id) {
214 return;
215 }
216
217 // init record definitions
218 if ($a_sub_type) {
219 $rec_idx = $rec_id . ";" . $a_sub_type . ";" . $new_sub_id;
220 if (!array_key_exists($rec_idx, $this->value_records)) {
221 $this->value_records[$rec_idx] = new ilAdvancedMDValues(
222 $rec_id,
223 $new_parent_id,
224 $a_sub_type,
225 $new_sub_id
226 );
227 }
228 } else {
229 $rec_idx = $rec_id . ";;";
230 if (!array_key_exists($rec_idx, $this->value_records)) {
231 $this->value_records[$rec_idx] = new ilAdvancedMDValues($rec_id, $new_parent_id);
232 }
233 }
234
235 // init ADTGroup before definitions to bind definitions to group
236 $this->value_records[$rec_idx]->getADTGroup();
237
238 // find element with import id
239 $this->log->debug("Find element: " . $a_import_id . ", local rec_id: " . $a_local_rec_id);
240 if (!$a_local_rec_id) {
241 foreach ($this->value_records[$rec_idx]->getDefinitions() as $def) {
242 if ($a_import_id == $def->getImportId()) {
243 $this->current_value = $def;
244 break;
245 }
246 }
247 } else {
248 // find element in new local record
249 $field_id = $this->local_rec_fields_map[$rec_id][$a_import_id];
250 if ($field_id) {
251 $this->log->debug("- Field id: " . $field_id);
252 foreach ($this->value_records[$rec_idx]->getDefinitions() as $def) {
253 $this->log->debug("- Def field id: " . $def->getFieldId());
254 if ($field_id == $def->getFieldId()) {
255 $this->current_value = $def;
256 break;
257 }
258 }
259 } else {
260 $this->log->debug("- No Field id. local rec: " . $a_local_rec_id .
261 ", rec id:" . $rec_id . ", import id: " . $a_import_id . ", map: " . print_r(
262 $this->local_rec_fields_map,
263 true
264 ));
265 }
266 }
267
268 // record will be selected for parent
269 // see ilAdvancedMetaDataImporter
270 if ($this->current_value &&
271 !$a_local_rec_id) {
272 $this->record_ids[$new_parent_id][$a_sub_type][] = $rec_id;
273 }
274 }
static getInstanceByImportId(string $a_import_id)
createLocalRecord(int $a_old_id, string $a_xml, int $a_obj_id, ?string $a_sub_type=null)

Referenced by handlerBeginTag().

+ Here is the caller graph for this function:

◆ setHandlers()

ilAdvancedMDParser::setHandlers (   $a_xml_parser)
Parameters
XMLParser | resource$a_xml_parser
Returns
void

Reimplemented from ilSaxParser.

Definition at line 62 of file class.ilAdvancedMDParser.php.

62 : void
63 {
64 $this->sax_controller = new ilSaxController();
65 $this->sax_controller->setHandlers($a_xml_parser);
66 $this->sax_controller->setDefaultElementHandler($this);
67 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

Field Documentation

◆ $cdata

string ilAdvancedMDParser::$cdata = ""
protected

Definition at line 30 of file class.ilAdvancedMDParser.php.

◆ $current_value

ilAdvancedMDFieldDefinition ilAdvancedMDParser::$current_value = null
protected

Definition at line 38 of file class.ilAdvancedMDParser.php.

◆ $local_rec_fields_map

array ilAdvancedMDParser::$local_rec_fields_map = []
protected

Definition at line 44 of file class.ilAdvancedMDParser.php.

◆ $local_rec_map

array ilAdvancedMDParser::$local_rec_map = []
protected

Definition at line 43 of file class.ilAdvancedMDParser.php.

◆ $local_record

array ilAdvancedMDParser::$local_record = null
protected

Definition at line 42 of file class.ilAdvancedMDParser.php.

◆ $log

ilLogger ilAdvancedMDParser::$log
protected

Definition at line 49 of file class.ilAdvancedMDParser.php.

◆ $mapping

ilImportMapping ilAdvancedMDParser::$mapping
protected

Definition at line 29 of file class.ilAdvancedMDParser.php.

◆ $obj_id

int ilAdvancedMDParser::$obj_id
protected

Definition at line 27 of file class.ilAdvancedMDParser.php.

◆ $rec_id

int ilAdvancedMDParser::$rec_id = 0
protected

Definition at line 28 of file class.ilAdvancedMDParser.php.

◆ $record_ids

array ilAdvancedMDParser::$record_ids = []
protected

Definition at line 39 of file class.ilAdvancedMDParser.php.

◆ $sax_controller

ilSaxController ilAdvancedMDParser::$sax_controller = null
protected

Definition at line 31 of file class.ilAdvancedMDParser.php.

◆ $value_records

array ilAdvancedMDParser::$value_records = []
protected

Definition at line 36 of file class.ilAdvancedMDParser.php.


The documentation for this class was generated from the following file: