ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilAdvancedMDParser Class Reference

Adv MD XML Parser. More...

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

Public Member Functions

 __construct ($a_obj_id, $a_mapping)
 Constructor setup ILIAS global object @access public. More...
 
 setHandlers ($a_xml_parser)
 set event handlers More...
 
 createLocalRecord ($a_old_id, $a_xml, $a_obj_id, $a_sub_type=null)
 
 handlerBeginTag ($a_xml_parser, $a_name, $a_attribs)
 handler for begin of element More...
 
 handlerEndTag ($a_xml_parser, $a_name)
 handler for end of element More...
 
 handlerCharacterData ($a_xml_parser, $a_data)
 handler for character data More...
 
 getRecordIds ()
 
- Public Member Functions inherited from ilMDSaxParser
 __construct ($a_xml_file='')
 Constructor. More...
 
 enableMDParsing ($a_status)
 
 getMDParsingStatus ()
 
 setMDObject (&$md)
 
getMDObject ()
 
 inMetaData ()
 
 setHandlers ($a_xml_parser)
 set event handlers More...
 
 handlerBeginTag ($a_xml_parser, $a_name, $a_attribs)
 handler for begin of element More...
 
 handlerEndTag ($a_xml_parser, $a_name)
 handler for end of element More...
 
 handlerCharacterData ($a_xml_parser, $a_data)
 handler for character data More...
 
 __getCharacterData ()
 
 __pushParent (&$md_obj)
 
 __popParent ()
 
 __getParent ()
 
 __construct ($a_xml_file='')
 Constructor. More...
 
 setMDObject (&$md)
 
 inMetaData ()
 
 handlerBeginTag ($a_xml_parser, $a_name, $a_attribs)
 handler for begin of element More...
 
 handlerEndTag ($a_xml_parser, $a_name)
 handler for end of element More...
 
 handlerCharacterData ($a_xml_parser, $a_data)
 handler for character data More...
 
 __getCharacterData ()
 
 __pushParent (&$md_obj)
 
__popParent ()
 
__getParent ()
 
 __construct ($a_xml_file='')
 Constructor. More...
 
 enableMDParsing ($a_status)
 
 getMDParsingStatus ()
 
 setMDObject (&$md)
 
getMDObject ()
 
 inMetaData ()
 
 setHandlers ($a_xml_parser)
 set event handlers More...
 
 handlerBeginTag ($a_xml_parser, $a_name, $a_attribs)
 handler for begin of element More...
 
 handlerEndTag ($a_xml_parser, $a_name)
 handler for end of element More...
 
 handlerCharacterData ($a_xml_parser, $a_data)
 handler for character data More...
 
 __getCharacterData ()
 
 __pushParent (&$md_obj)
 
__popParent ()
 
__getParent ()
 
- Public Member Functions inherited from ilSaxParser
 __construct ($a_xml_file='', $throwException=false)
 Constructor setup ILIAS global object @access public. More...
 
 setXMLContent ($a_xml_content)
 
 getXMLContent ()
 
 getInputType ()
 
 startParsing ()
 stores xml data in array More...
 
 createParser ()
 create parser More...
 
 setOptions ($a_xml_parser)
 set parser options More...
 
 setHandlers ($a_xml_parser)
 set event handler should be overwritten by inherited class @access private More...
 
 openXMLFile ()
 open xml file More...
 
 parse ($a_xml_parser, $a_fp=null)
 parse xml file More...
 
 freeParser ($a_xml_parser)
 free xml parser handle More...
 
 setThrowException ($throwException)
 set error handling More...
 
- Public Member Functions inherited from PEAR
 __construct ($error_class=null)
 Constructor. More...
 
 _PEAR ()
 Destructor (the emulated type of...). More...
 
 registerShutdownFunc ($func, $args=array())
 Use this function to register a shutdown method for static classes. More...
 
 isError ($data, $code=null)
 Tell whether a value is a PEAR error. More...
 
 expectError ($code=' *')
 This method is used to tell which errors you expect to get. More...
 
 popExpect ()
 This method pops one element off the expected error codes stack. More...
 
 _checkDelExpect ($error_code)
 This method checks unsets an error code if available. More...
 
 delExpect ($error_code)
 This method deletes all occurences of the specified element from the expected error codes stack. More...
 
raiseError ($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
 This method is a wrapper that returns an instance of the configured error class with this object's default error handling applied. More...
 
throwError ($message=null, $code=null, $userinfo=null)
 Simpler form of raiseError with fewer options. More...
 
 staticPushErrorHandling ($mode, $options=null)
 
 staticPopErrorHandling ()
 
 pushErrorHandling ($mode, $options=null)
 Push a new error handler on top of the error handler options stack. More...
 
 popErrorHandling ()
 Pop the last error handler used. More...
 
 loadExtension ($ext)
 OS independant PHP extension load. More...
 
 handlerBeginTag ($a_xml_parser, $a_name, $a_attribs)
 Start element handler. More...
 
 handlerEndTag ($a_xml_parser, $a_name)
 End element handler. More...
 
 handlerCharacterData ($a_xml_parser, $a_name)
 Character data handler. More...
 

Protected Member Functions

 initValue ($a_import_id, $a_sub_type="", $a_sub_id=0, $a_local_rec_id=null)
 
- Protected Member Functions inherited from ilSaxParser
 handleError ($message, $code)
 use given error handler to handle error message or internal ilias error message handle More...
 

Protected Attributes

 $obj_id
 
 $rec_id
 
 $mapping
 
 $cdata
 
 $value_records = array()
 
 $current_record
 
 $current_value
 
 $has_values
 
 $record_ids = array()
 
 $local_record
 
 $local_rec_map = array()
 
 $local_rec_fields_map = array()
 
 $log
 
- Protected Attributes inherited from ilMDSaxParser
 $meta_log
 

Additional Inherited Members

- Static Public Member Functions inherited from PEAR
static & getStaticProperty ($class, $var)
 If you have a class that's mostly/entirely static, and you need static properties, you can use this method to simulate them. More...
 
static setErrorHandling ($mode=null, $options=null)
 Sets how errors generated by this object should be handled. More...
 
- Data Fields inherited from ilMDSaxParser
 $md_in_md = false
 
 $md_chr_data = ''
 
 $md_cur_el = null
 
 $md_parsing_enabled = null
 
 $md = null
 
 $md_gen
 
- Data Fields inherited from ilSaxParser
 $input_type = null
 
 $xml_content = ''
 
 $ilias
 
 $lng
 
 $xml_file
 
 $throwException = false
 
- Data Fields inherited from PEAR
 $_debug = false
 
 $_default_error_mode = null
 
 $_default_error_options = null
 
 $_default_error_handler = ''
 
 $_error_class = 'PEAR_Error'
 
 $_expected_errors = array()
 

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
Version
Id
class.ilCourseXMLParser.php 53320 2014-09-12 11:33:49Z fwolf

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

Constructor & Destructor Documentation

◆ __construct()

ilAdvancedMDParser::__construct (   $a_xml_file,
  $throwException 
)

Constructor setup ILIAS global object @access public.

Reimplemented from ilSaxParser.

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

41 {
42 parent::__construct();
43
44 $this->log = ilLoggerFactory::getLogger('amet');
45
46 $parts = explode(":", $a_obj_id);
47 $this->obj_id = $parts[0];
48 $this->mapping = $a_mapping;
49 }
static getLogger($a_component_id)
Get component logger.

References ilLoggerFactory\getLogger().

+ Here is the call graph for this function:

Member Function Documentation

◆ createLocalRecord()

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

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

59 {
60 $tmp_file = ilUtil::ilTempnam();
61 file_put_contents($tmp_file, $a_xml);
62
63 // see ilAdvancedMDSettingsGUI::importRecord()
64 try {
65 // the (old) record parser does only support files
66 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordParser.php');
67 $parser = new ilAdvancedMDRecordParser($tmp_file);
68 $parser->setContext($a_obj_id, ilObject::_lookupType($a_obj_id), $a_sub_type);
70 $parser->startParsing();
72 $parser->startParsing();
73 } catch (ilSAXParserException $exc) {
74 }
75
76 unlink($tmp_file);
77
78 $map = $parser->getRecordMap();
79 foreach ($map as $record_id => $fields) {
80 $this->local_rec_fields_map[$record_id] = $fields;
81
82 // needed for glossary field order
83 foreach ($fields as $import_id => $new_id) {
84 $old_id = array_pop(explode("_", $import_id));
85 $this->mapping->addMapping("Services/AdvancedMetaData", "lfld", $old_id, $new_id);
86 }
87 }
88
89 $new_id = array_shift(array_keys($map));
90 $this->local_rec_map[$a_old_id] = $new_id;
91 }
$parser
Definition: BPMN2Parser.php:23
SAX based XML parser for record import files.
static _lookupType($a_id, $a_reference=false)
lookup object type
static ilTempnam($a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.

References $map, $parser, ilObject\_lookupType(), ilUtil\ilTempnam(), ilAdvancedMDRecordParser\MODE_INSERT, and ilAdvancedMDRecordParser\MODE_INSERT_VALIDATION.

Referenced by initValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRecordIds()

ilAdvancedMDParser::getRecordIds ( )

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

References $record_ids.

◆ handlerBeginTag()

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

handler for begin of element

Reimplemented from ilMDSaxParser.

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

94 {
95 switch ($a_name) {
96 case 'AdvancedMetaData':
97 break;
98
99 case 'Record':
100 $this->local_record = array('id' => $a_attribs['local_id']);
101 break;
102
103 case 'Value':
104 $this->initValue($a_attribs['id'], $a_attribs['sub_type'], $a_attribs['sub_id'], $a_attribs['local_rec_id']);
105 break;
106 }
107 }
initValue($a_import_id, $a_sub_type="", $a_sub_id=0, $a_local_rec_id=null)

References initValue().

+ Here is the call graph for this function:

◆ handlerCharacterData()

ilAdvancedMDParser::handlerCharacterData (   $a_xml_parser,
  $a_data 
)

handler for character data

Reimplemented from ilMDSaxParser.

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

136 {
137 if ($a_data != "\n") {
138 // Replace multiple tabs with one space
139 $a_data = preg_replace("/\t+/", " ", $a_data);
140
141 $this->cdata .= $a_data;
142 }
143 }

◆ handlerEndTag()

ilAdvancedMDParser::handlerEndTag (   $a_xml_parser,
  $a_name 
)

handler for end of element

Reimplemented from ilMDSaxParser.

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

110 {
111 switch ($a_name) {
112 case 'AdvancedMetaData':
113 // we need to write all records that have been created (1 for each sub-item)
114 foreach ($this->value_records as $record) {
115 $record->write();
116 }
117 break;
118
119 case 'Record':
120 $this->local_record['xml'] = base64_decode(trim($this->cdata));
121 $this->log->debug("Local Record XML: " . $this->local_record['xml']);
122 break;
123
124 case 'Value':
125 $value = trim($this->cdata);
126 $this->log->debug("End Tag Value: -" . is_object($this->current_value) . "-" . $value);
127 if (is_object($this->current_value) && $value != "") {
128 $this->current_value->importValueFromXML($value);
129 }
130 break;
131 }
132 $this->cdata = '';
133 }

◆ initValue()

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

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

146 {
147 $this->current_value = null;
148
149 // get parent objects
150 $new_parent_id = $this->mapping->getMapping("Services/AdvancedMetaData", "parent", $this->obj_id);
151 $this->log->notice('Found new parent id:' . $new_parent_id);
152 if (!$new_parent_id) {
153 return;
154 }
155 if (
156 $a_sub_type &&
157 strcmp($a_sub_type, '-') !== 0
158 ) {
159 $new_sub_id = $this->mapping->getMapping("Services/AdvancedMetaData", "advmd_sub_item", "advmd:" . $a_sub_type . ":" . $a_sub_id);
160 if (!$new_sub_id) {
161 return;
162 }
163 }
164
165 // init local record?
166 // done here because we need object context
167 if (is_array($this->local_record)) {
168 $this->createLocalRecord($this->local_record['id'], $this->local_record['xml'], $new_parent_id, $a_sub_type);
169 $this->local_record = null;
170 }
171
172 $rec_id = null;
173
174 // find record via import id
175 if (!$a_local_rec_id) {
176 if ($field = ilAdvancedMDFieldDefinition::getInstanceByImportId($a_import_id)) {
177 $rec_id = $field->getRecordId();
178 }
179 }
180 // (new) local record
181 else {
182 $rec_id = $this->local_rec_map[$a_local_rec_id];
183 }
184
185 if (!$rec_id) {
186 return;
187 }
188
189 // init record definitions
190 if ($a_sub_type) {
191 $rec_idx = $rec_id . ";" . $a_sub_type . ";" . $new_sub_id;
192 if (!array_key_exists($rec_idx, $this->value_records)) {
193 $this->value_records[$rec_idx] = new ilAdvancedMDValues($rec_id, $new_parent_id, $a_sub_type, $new_sub_id);
194 }
195 } else {
196 $rec_idx = $rec_id . ";;";
197 if (!array_key_exists($rec_idx, $this->value_records)) {
198 $this->value_records[$rec_idx] = new ilAdvancedMDValues($rec_id, $new_parent_id);
199 }
200 }
201
202 // init ADTGroup before definitions to bind definitions to group
203 $this->value_records[$rec_idx]->getADTGroup();
204
205 // find element with import id
206 $this->log->debug("Find element: " . $a_import_id . ", local rec_id: " . $a_local_rec_id);
207 if (!$a_local_rec_id) {
208 foreach ($this->value_records[$rec_idx]->getDefinitions() as $def) {
209 if ($a_import_id == $def->getImportId()) {
210 $this->current_value = $def;
211 break;
212 }
213 }
214 } else {
215 // find element in new local record
216 $field_id = $this->local_rec_fields_map[$rec_id][$a_import_id];
217 if ($field_id) {
218 $this->log->debug("- Field id: " . $field_id);
219 foreach ($this->value_records[$rec_idx]->getDefinitions() as $def) {
220 $this->log->debug("- Def field id: " . $def->getFieldId());
221 if ($field_id == $def->getFieldId()) {
222 $this->current_value = $def;
223 break;
224 }
225 }
226 } else {
227 $this->log->debug("- No Field id. local rec: " . $a_local_rec_id .
228 ", rec id:" . $rec_id . ", import id: " . $a_import_id . ", map: " . print_r($this->local_rec_fields_map, true));
229 }
230 }
231
232 // record will be selected for parent
233 // see ilAdvancedMetaDataImporter
234 if ($this->current_value &&
235 !$a_local_rec_id) {
236 $this->record_ids[$new_parent_id][$a_sub_type][] = $rec_id;
237 }
238 }
static getInstanceByImportId($a_import_id)
Get definition instance by import id.
createLocalRecord($a_old_id, $a_xml, $a_obj_id, $a_sub_type=null)
$def
Definition: croninfo.php:21

References $def, $rec_id, createLocalRecord(), and ilAdvancedMDFieldDefinition\getInstanceByImportId().

Referenced by handlerBeginTag().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setHandlers()

ilAdvancedMDParser::setHandlers (   $a_xml_parser)

set event handlers

Parameters
resourcereference to the xml parser @access private

Reimplemented from ilMDSaxParser.

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

52 {
53 $this->sax_controller = new ilSaxController();
54 $this->sax_controller->setHandlers($a_xml_parser);
55 $this->sax_controller->setDefaultElementHandler($this);
56 }
Controller class for sax element handlers.

Field Documentation

◆ $cdata

ilAdvancedMDParser::$cdata
protected

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

◆ $current_record

ilAdvancedMDParser::$current_record
protected

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

◆ $current_value

ilAdvancedMDParser::$current_value
protected

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

◆ $has_values

ilAdvancedMDParser::$has_values
protected

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

◆ $local_rec_fields_map

ilAdvancedMDParser::$local_rec_fields_map = array()
protected

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

◆ $local_rec_map

ilAdvancedMDParser::$local_rec_map = array()
protected

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

◆ $local_record

ilAdvancedMDParser::$local_record
protected

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

◆ $log

ilAdvancedMDParser::$log
protected

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

◆ $mapping

ilAdvancedMDParser::$mapping
protected

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

◆ $obj_id

ilAdvancedMDParser::$obj_id
protected

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

◆ $rec_id

ilAdvancedMDParser::$rec_id
protected

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

Referenced by initValue().

◆ $record_ids

ilAdvancedMDParser::$record_ids = array()
protected

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

Referenced by getRecordIds().

◆ $value_records

ilAdvancedMDParser::$value_records = array()
protected

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


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