ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilAdvancedMDRecordParser Class Reference

SAX based XML parser for record import files. More...

+ Inheritance diagram for ilAdvancedMDRecordParser:
+ Collaboration diagram for ilAdvancedMDRecordParser:

Public Member Functions

 __construct ($a_file)
 Constructor. More...
 
 setMode ($a_mode)
 set parsing mode More...
 
 getMode ()
 get mode More...
 
 startParsing ()
 stores xml data in array More...
 
 setHandlers ($a_xml_parser)
 set event handlers More...
 
 setContext ($a_obj_id, $a_obj_type, $a_sub_type=null)
 
 getRecordMap ()
 
- 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...
 

Data Fields

const MODE_UPDATE = 1
 
const MODE_INSERT = 2
 
const MODE_UPDATE_VALIDATION = 3
 
const MODE_INSERT_VALIDATION = 4
 
- 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()
 

Protected Member Functions

 handlerBeginTag ($a_xml_parser, $a_name, $a_attribs)
 Handler for start tags. More...
 
 handlerEndTag ($a_xml_parser, $a_name)
 Handler for end tags. More...
 
 handlerCharacterData ($a_xml_parser, $a_data)
 handler for character data More...
 
- 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

 $context
 
 $log
 

Private Member Functions

 initRecordObject ($a_id)
 Init record object. More...
 
 initFieldObject ($a_id, $a_type)
 Init field definition object. More...
 
 getCurrentRecord ()
 get current record More...
 
 getCurrentField ()
 get current field definition private More...
 
 extractRecordId ($a_id_string)
 Extract id. More...
 
 appendErrorMessage ($a_msg)
 private More...
 
 storeRecords ()
 Store Record. More...
 

Private Attributes

 $mode
 
 $fields = array()
 
 $is_error = false
 
 $error_msg = array()
 

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

Detailed Description

SAX based XML parser for record import files.

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

Definition at line 37 of file class.ilAdvancedMDRecordParser.php.

Constructor & Destructor Documentation

◆ __construct()

ilAdvancedMDRecordParser::__construct (   $a_file)

Constructor.

public

Parameters
stringxml file

Definition at line 65 of file class.ilAdvancedMDRecordParser.php.

References ilLoggerFactory\getLogger().

66  {
67  parent::__construct($a_file,true);
68  $this->log = ilLoggerFactory::getLogger('amet');
69  }
static getLogger($a_component_id)
Get component logger.
+ Here is the call graph for this function:

Member Function Documentation

◆ appendErrorMessage()

ilAdvancedMDRecordParser::appendErrorMessage (   $a_msg)
private

private

Parameters

Definition at line 350 of file class.ilAdvancedMDRecordParser.php.

Referenced by handlerBeginTag().

351  {
352  $this->is_error = true;
353  $this->error_msg[] = $a_msg;
354  }
+ Here is the caller graph for this function:

◆ extractRecordId()

ilAdvancedMDRecordParser::extractRecordId (   $a_id_string)
private

Extract id.

private

Parameters

Definition at line 330 of file class.ilAdvancedMDRecordParser.php.

References ilAdvancedMDRecord\_lookupRecordIdByImportId().

Referenced by initRecordObject().

331  {
332  // first lookup import id
333  if($record_id = ilAdvancedMDRecord::_lookupRecordIdByImportId($a_id_string))
334  {
335  $this->record_exists = true;
336  return $record_id;
337  }
338  return 0;
339  }
static _lookupRecordIdByImportId($a_ilias_id)
Lookup record Id by import id.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCurrentField()

ilAdvancedMDRecordParser::getCurrentField ( )
private

get current field definition private

Definition at line 318 of file class.ilAdvancedMDRecordParser.php.

Referenced by handlerBeginTag(), and handlerEndTag().

319  {
320  return $this->current_field;
321  }
+ Here is the caller graph for this function:

◆ getCurrentRecord()

ilAdvancedMDRecordParser::getCurrentRecord ( )
private

get current record

private

Definition at line 308 of file class.ilAdvancedMDRecordParser.php.

Referenced by handlerBeginTag(), handlerEndTag(), and storeRecords().

309  {
310  return $this->current_record;
311  }
+ Here is the caller graph for this function:

◆ getMode()

ilAdvancedMDRecordParser::getMode ( )

get mode

public

Definition at line 89 of file class.ilAdvancedMDRecordParser.php.

References $mode.

Referenced by initFieldObject(), initRecordObject(), and storeRecords().

+ Here is the caller graph for this function:

◆ getRecordMap()

ilAdvancedMDRecordParser::getRecordMap ( )

Definition at line 418 of file class.ilAdvancedMDRecordParser.php.

419  {
420  return $this->rec_map;
421  }

◆ handlerBeginTag()

ilAdvancedMDRecordParser::handlerBeginTag (   $a_xml_parser,
  $a_name,
  $a_attribs 
)
protected

Handler for start tags.

protected

Definition at line 130 of file class.ilAdvancedMDRecordParser.php.

References appendErrorMessage(), array, fields, getCurrentField(), getCurrentRecord(), initFieldObject(), and initRecordObject().

131  {
132  switch($a_name)
133  {
134  case 'AdvancedMetaDataRecords':
135  $this->is_error = false;
136  $this->error_msg = array();
137  // Nothing to do
138  break;
139 
140  case 'Record':
141  $this->fields = array();
142  $this->current_field = null;
143  $this->current_record = null;
144  if(!strlen($a_attribs['id']) or !isset($a_attribs['active']))
145  {
146  $this->appendErrorMessage('Missing XML attribute for element "Record".');
147  }
148  if(!$this->initRecordObject($a_attribs['id']))
149  {
150  $this->appendErrorMessage('Invalid attribute Id given for element "Record".');
151  }
152  $this->getCurrentRecord()->setActive($a_attribs['active']);
153  $this->getCurrentRecord()->setImportId($a_attribs['id']);
154  $this->getCurrentRecord()->setAssignedObjectTypes(array());
155  break;
156 
157  case 'Title':
158  break;
159 
160  case 'Field':
161  if(!strlen($a_attribs['id']) or !isset($a_attribs['searchable']) or !isset($a_attribs['fieldType']))
162  {
163  $this->appendErrorMessage('Missing XML attribute for element "Field".');
164  }
165  if(!$this->initFieldObject($a_attribs['id'], $a_attribs['fieldType']))
166  {
167  $this->appendErrorMessage('Invalid attribute Id given for element "Record".');
168  }
169  $this->getCurrentField()->setImportId($a_attribs['id']);
170  $this->getCurrentField()->setSearchable($a_attribs['searchable'] == 'Yes' ? true : false);
171  break;
172 
173  case 'FieldTitle':
174  case 'FieldDescription':
175  case 'FieldPosition':
176  case 'FieldValue':
177  $this->field_value_id = $a_attribs['id'];
178  break;
179  }
180  }
initFieldObject($a_id, $a_type)
Init field definition object.
$errors fields
Definition: imgupload.php:52
Create styles array
The data for the language used.
initRecordObject($a_id)
Init record object.
getCurrentField()
get current field definition private
+ Here is the call graph for this function:

◆ handlerCharacterData()

ilAdvancedMDRecordParser::handlerCharacterData (   $a_xml_parser,
  $a_data 
)
protected

handler for character data

Parameters
resource$a_xml_parserxml parser
string$a_datacharacter data

Definition at line 241 of file class.ilAdvancedMDRecordParser.php.

242  {
243  if($a_data != "\n")
244  {
245  // Replace multiple tabs with one space
246  $a_data = preg_replace("/\t+/"," ",$a_data);
247 
248  $this->cdata .= $a_data;
249  }
250  }

◆ handlerEndTag()

ilAdvancedMDRecordParser::handlerEndTag (   $a_xml_parser,
  $a_name 
)
protected

Handler for end tags.

protected

Definition at line 187 of file class.ilAdvancedMDRecordParser.php.

References getCurrentField(), getCurrentRecord(), and storeRecords().

188  {
189  switch($a_name)
190  {
191  case 'AdvancedMetaDataRecords':
192  break;
193 
194  case 'Record':
195  $this->storeRecords();
196  break;
197 
198  case 'Title':
199  $this->getCurrentRecord()->setTitle(trim($this->cdata));
200  break;
201 
202  case 'Description':
203  $this->getCurrentRecord()->setDescription(trim($this->cdata));
204  break;
205 
206  case 'ObjectType':
207  // #12980
208  $parts = explode(":", trim($this->cdata));
209  $this->getCurrentRecord()->appendAssignedObjectType($parts[0], $parts[1]);
210  break;
211 
212  case 'Field':
213  break;
214 
215 
216  case 'FieldTitle':
217  $this->getCurrentField()->setTitle(trim($this->cdata));
218  break;
219 
220  case 'FieldDescription':
221  $this->getCurrentField()->setDescription(trim($this->cdata));
222  break;
223 
224  case 'FieldPosition':
225  $this->getCurrentField()->setPosition((int) trim($this->cdata));
226  break;
227 
228  case 'FieldValue':
229  $this->getCurrentField()->importXMLProperty($this->field_value_id, trim($this->cdata));
230  break;
231  }
232  $this->cdata = '';
233  }
getCurrentField()
get current field definition private
+ Here is the call graph for this function:

◆ initFieldObject()

ilAdvancedMDRecordParser::initFieldObject (   $a_id,
  $a_type 
)
private

Init field definition object.

private

Parameters
stringimport id

Definition at line 282 of file class.ilAdvancedMDRecordParser.php.

References $a_type, fields, ilAdvancedMDFieldDefinition\getInstanceByTypeString(), and getMode().

Referenced by handlerBeginTag().

283  {
284  switch($this->getMode())
285  {
286  case self::MODE_INSERT:
287  case self::MODE_INSERT_VALIDATION:
289  $this->fields[] = $this->current_field;
290  return true;
291 
292  default:
293  // ??? nonsense
294  $this->current_field = ilAdvancedMDRecord::_getInstanceByFieldId($this->extractFieldId($a_id));
295  return true;
296  break;
297  }
298  }
$errors fields
Definition: imgupload.php:52
$a_type
Definition: workflow.php:93
static getInstanceByTypeString($a_type)
Get instance by type string (used by import)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initRecordObject()

ilAdvancedMDRecordParser::initRecordObject (   $a_id)
private

Init record object.

Parameters
stringimport id private

Definition at line 259 of file class.ilAdvancedMDRecordParser.php.

References ilAdvancedMDRecord\_getInstanceByRecordId(), extractRecordId(), and getMode().

Referenced by handlerBeginTag().

260  {
261  switch($this->getMode())
262  {
263  case self::MODE_INSERT:
264  case self::MODE_INSERT_VALIDATION:
265  $this->current_record = new ilAdvancedMDRecord(0);
266  return true;
267 
268  default:
269  $this->current_record = ilAdvancedMDRecord::_getInstanceByRecordId($this->extractRecordId($a_id));
270  return true;
271  break;
272  }
273  }
static _getInstanceByRecordId($a_record_id)
Get instance by record id.
extractRecordId($a_id_string)
Extract id.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setContext()

ilAdvancedMDRecordParser::setContext (   $a_obj_id,
  $a_obj_type,
  $a_sub_type = null 
)

Definition at line 404 of file class.ilAdvancedMDRecordParser.php.

References array.

405  {
406  if(!$a_sub_type)
407  {
408  $a_sub_type = "-";
409  }
410 
411  $this->context = array(
412  "obj_id" => $a_obj_id,
413  "obj_type" => $a_obj_type,
414  "sub_type" => $a_sub_type
415  );
416  }
Create styles array
The data for the language used.

◆ setHandlers()

ilAdvancedMDRecordParser::setHandlers (   $a_xml_parser)

set event handlers

Parameters
resourcereference to the xml parser private

Definition at line 118 of file class.ilAdvancedMDRecordParser.php.

119  {
120  xml_set_object($a_xml_parser,$this);
121  xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
122  xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
123  }

◆ setMode()

ilAdvancedMDRecordParser::setMode (   $a_mode)

set parsing mode

public

Parameters
intMODE_VALIDATION, MODE_UPDATE or MODE_INSERT

Definition at line 78 of file class.ilAdvancedMDRecordParser.php.

79  {
80  $this->mode = $a_mode;
81  }

◆ startParsing()

ilAdvancedMDRecordParser::startParsing ( )

stores xml data in array

Returns
bool success status private
Exceptions
ilSaxParserException

Definition at line 102 of file class.ilAdvancedMDRecordParser.php.

103  {
104  parent::startParsing();
105  if($this->is_error)
106  {
107  include_once('./Services/Xml/exceptions/class.ilSaxParserException.php');
108  throw new ilSaxParserException(implode('<br/>',$this->error_msg));
109  }
110  }
SaxParserException thrown by ilSaxParser if property throwException is set.

◆ storeRecords()

ilAdvancedMDRecordParser::storeRecords ( )
private

Store Record.

private

Parameters

Definition at line 363 of file class.ilAdvancedMDRecordParser.php.

References array, fields, getCurrentRecord(), and getMode().

Referenced by handlerEndTag().

364  {
365  switch($this->getMode())
366  {
367  case self::MODE_INSERT_VALIDATION:
368  case self::MODE_UPDATE_VALIDATION:
369  return true;
370 
371  case self::MODE_INSERT:
372  // set local context
373  if(is_array($this->context))
374  {
375  $this->getCurrentRecord()->setParentObject($this->context["obj_id"]);
376  $this->getCurrentRecord()->setAssignedObjectTypes(array(
377  array(
378  "obj_type" => $this->context["obj_type"],
379  "sub_type" => $this->context["sub_type"],
380  "optional" => false
381  )));
382  }
383 
384  $this->getCurrentRecord()->save();
385  break;
386  }
387  foreach($this->fields as $field)
388  {
389  $field->setRecordId($this->getCurrentRecord()->getRecordId());
390  switch($this->getMode())
391  {
392  case self::MODE_INSERT:
393  $field->save();
394 
395  // see getRecordMap()
396  $this->log->debug("add to record map, rec id: ".$this->getCurrentRecord()->getRecordId().
397  ", import id: ".$field->getImportId().", field id:".$field->getFieldId());
398  $this->rec_map[$this->getCurrentRecord()->getRecordId()][$field->getImportId()] = $field->getFieldId();
399  break;
400  }
401  }
402  }
$errors fields
Definition: imgupload.php:52
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $context

ilAdvancedMDRecordParser::$context
protected

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

◆ $error_msg

ilAdvancedMDRecordParser::$error_msg = array()
private

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

◆ $fields

ilAdvancedMDRecordParser::$fields = array()
private

Definition at line 46 of file class.ilAdvancedMDRecordParser.php.

◆ $is_error

ilAdvancedMDRecordParser::$is_error = false
private

Definition at line 48 of file class.ilAdvancedMDRecordParser.php.

◆ $log

ilAdvancedMDRecordParser::$log
protected

Definition at line 56 of file class.ilAdvancedMDRecordParser.php.

◆ $mode

ilAdvancedMDRecordParser::$mode
private

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

Referenced by getMode().

◆ MODE_INSERT

const ilAdvancedMDRecordParser::MODE_INSERT = 2

◆ MODE_INSERT_VALIDATION

const ilAdvancedMDRecordParser::MODE_INSERT_VALIDATION = 4

◆ MODE_UPDATE

const ilAdvancedMDRecordParser::MODE_UPDATE = 1

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

◆ MODE_UPDATE_VALIDATION

const ilAdvancedMDRecordParser::MODE_UPDATE_VALIDATION = 3

Definition at line 41 of file class.ilAdvancedMDRecordParser.php.


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