ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
All Data Structures Namespaces Files Functions Variables Typedefs Modules Pages
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)
 
 setHandlers ($a_xml_parser)
 
 createLocalRecord ($a_old_id, $a_xml, $a_obj_id, $a_sub_type=null)
 
 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_data)
 Character data handler. 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 ()
 
- Public Member Functions inherited from ilSaxParser
 __construct ($a_xml_file='', $throwException=false)
 Constructor setup ILIAS global object 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 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...
 

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_obj_id,
  $a_mapping 
)

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

References ilLoggerFactory\getLogger().

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.
+ 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.

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

Referenced by initValue().

59  {
60  $tmp_file = ilUtil::ilTempnam();
61  file_put_contents($tmp_file, $a_xml);
62 
63  // see ilAdvancedMDSettingsGUI::importRecord()
64  try
65  {
66  // the (old) record parser does only support files
67  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordParser.php');
68  $parser = new ilAdvancedMDRecordParser($tmp_file);
69  $parser->setContext($a_obj_id, ilObject::_lookupType($a_obj_id), $a_sub_type);
71  $parser->startParsing();
73  $parser->startParsing();
74  }
75  catch(ilSAXParserException $exc)
76  {
77 
78  }
79 
80  unlink($tmp_file);
81 
82  $map = $parser->getRecordMap();
83  foreach($map as $record_id => $fields)
84  {
85  $this->local_rec_fields_map[$record_id] = $fields;
86 
87  // needed for glossary field order
88  foreach($fields as $import_id => $new_id)
89  {
90  $old_id = array_pop(explode("_", $import_id));
91  $this->mapping->addMapping("Services/AdvancedMetaData", "lfld", $old_id, $new_id);
92  }
93  }
94 
95  $new_id = array_shift(array_keys($map));
96  $this->local_rec_map[$a_old_id] = $new_id;
97  }
static _lookupType($a_id, $a_reference=false)
lookup object type
static ilTempnam($a_temp_path=null)
Create a temporary file in an ILIAS writable directory.
$parser
Definition: BPMN2Parser.php:24
SAX based XML parser for record import files.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRecordIds()

ilAdvancedMDParser::getRecordIds ( )

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

References $record_ids.

272  {
273  return $this->record_ids;
274  }

◆ handlerBeginTag()

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

Start element handler.

public

Parameters
resource$a_xml_parserxml parser
string$a_nameelement name
array$a_attribselement attributes array

Implements ilSaxSubsetParser.

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

References array, and initValue().

100  {
101  switch($a_name)
102  {
103  case 'AdvancedMetaData':
104  break;
105 
106  case 'Record':
107  $this->local_record = array('id'=>$a_attribs['local_id']);
108  break;
109 
110  case 'Value':
111  $this->initValue($a_attribs['id'], $a_attribs['sub_type'], $a_attribs['sub_id'], $a_attribs['local_rec_id']);
112  break;
113  }
114  }
initValue($a_import_id, $a_sub_type="", $a_sub_id=0, $a_local_rec_id=null)
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ handlerCharacterData()

ilAdvancedMDParser::handlerCharacterData (   $a_xml_parser,
  $a_name 
)

Character data handler.

public

Parameters
resource$a_xml_parserxml parser
string$a_datacharacter data

Implements ilSaxSubsetParser.

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

146  {
147  if($a_data != "\n")
148  {
149  // Replace multiple tabs with one space
150  $a_data = preg_replace("/\t+/"," ",$a_data);
151 
152  $this->cdata .= $a_data;
153  }
154  }

◆ handlerEndTag()

ilAdvancedMDParser::handlerEndTag (   $a_xml_parser,
  $a_name 
)

End element handler.

public

Parameters
resource$a_xml_parserxml parser
string$a_nameelement name

Implements ilSaxSubsetParser.

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

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

◆ initValue()

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

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

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

Referenced by handlerBeginTag().

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

◆ setHandlers()

ilAdvancedMDParser::setHandlers (   $a_xml_parser)

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: