ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f87
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...
 

Data Fields

const MODE_UPDATE = 1
 
const MODE_INSERT = 2
 
const MODE_UPDATE_VALIDATION = 3
 
const MODE_INSERT_VALIDATION = 4
 

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

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()
 

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 57 of file class.ilAdvancedMDRecordParser.php.

58  {
59  parent::__construct($a_file,true);
60  }

Member Function Documentation

◆ appendErrorMessage()

ilAdvancedMDRecordParser::appendErrorMessage (   $a_msg)
private

private

Parameters

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

Referenced by handlerBeginTag().

342  {
343  $this->is_error = true;
344  $this->error_msg[] = $a_msg;
345  }
+ Here is the caller graph for this function:

◆ extractRecordId()

ilAdvancedMDRecordParser::extractRecordId (   $a_id_string)
private

Extract id.

private

Parameters

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

References ilAdvancedMDRecord\_lookupRecordIdByImportId().

Referenced by initRecordObject().

322  {
323  // first lookup import id
324  if($record_id = ilAdvancedMDRecord::_lookupRecordIdByImportId($a_id_string))
325  {
326  $this->record_exists = true;
327  return $record_id;
328  }
329  return 0;
330  }
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 309 of file class.ilAdvancedMDRecordParser.php.

Referenced by handlerBeginTag(), and handlerEndTag().

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

◆ getCurrentRecord()

ilAdvancedMDRecordParser::getCurrentRecord ( )
private

get current record

private

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

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

300  {
301  return $this->current_record;
302  }
+ Here is the caller graph for this function:

◆ getMode()

ilAdvancedMDRecordParser::getMode ( )

get mode

public

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

References $mode.

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

+ Here is the caller graph for this function:

◆ handlerBeginTag()

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

Handler for start tags.

protected

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

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

122  {
123  switch($a_name)
124  {
125  case 'AdvancedMetaDataRecords':
126  $this->is_error = false;
127  $this->error_msg = array();
128  // Nothing to do
129  break;
130 
131  case 'Record':
132  $this->fields = array();
133  $this->current_field = null;
134  $this->current_record = null;
135  if(!strlen($a_attribs['id']) or !isset($a_attribs['active']))
136  {
137  $this->appendErrorMessage('Missing XML attribute for element "Record".');
138  }
139  if(!$this->initRecordObject($a_attribs['id']))
140  {
141  $this->appendErrorMessage('Invalid attribute Id given for element "Record".');
142  }
143  $this->getCurrentRecord()->setActive($a_attribs['active']);
144  $this->getCurrentRecord()->setImportId($a_attribs['id']);
145  $this->getCurrentRecord()->setAssignedObjectTypes(array());
146  break;
147 
148  case 'Title':
149  break;
150 
151  case 'Field':
152  if(!strlen($a_attribs['id']) or !isset($a_attribs['searchable']) or !isset($a_attribs['fieldType']))
153  {
154  $this->appendErrorMessage('Missing XML attribute for element "Field".');
155  }
156  if(!$this->initFieldObject($a_attribs['id'], $a_attribs['fieldType']))
157  {
158  $this->appendErrorMessage('Invalid attribute Id given for element "Record".');
159  }
160  $this->getCurrentField()->setImportId($a_attribs['id']);
161  $this->getCurrentField()->setSearchable($a_attribs['searchable'] == 'Yes' ? true : false);
162  break;
163 
164  case 'FieldTitle':
165  case 'FieldDescription':
166  case 'FieldPosition':
167  case 'FieldValue':
168  $this->field_value_id = $a_attribs['id'];
169  break;
170  }
171  }
initFieldObject($a_id, $a_type)
Init field definition object.
$errors fields
Definition: imgupload.php:48
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 232 of file class.ilAdvancedMDRecordParser.php.

233  {
234  if($a_data != "\n")
235  {
236  // Replace multiple tabs with one space
237  $a_data = preg_replace("/\t+/"," ",$a_data);
238 
239  $this->cdata .= $a_data;
240  }
241  }

◆ handlerEndTag()

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

Handler for end tags.

protected

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

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

179  {
180  switch($a_name)
181  {
182  case 'AdvancedMetaDataRecords':
183  break;
184 
185  case 'Record':
186  $this->storeRecords();
187  break;
188 
189  case 'Title':
190  $this->getCurrentRecord()->setTitle(trim($this->cdata));
191  break;
192 
193  case 'Description':
194  $this->getCurrentRecord()->setDescription(trim($this->cdata));
195  break;
196 
197  case 'ObjectType':
198  // #12980
199  $parts = explode(":", trim($this->cdata));
200  $this->getCurrentRecord()->appendAssignedObjectType($parts[0], $parts[1]);
201  break;
202 
203  case 'Field':
204  break;
205 
206 
207  case 'FieldTitle':
208  $this->getCurrentField()->setTitle(trim($this->cdata));
209  break;
210 
211  case 'FieldDescription':
212  $this->getCurrentField()->setDescription(trim($this->cdata));
213  break;
214 
215  case 'FieldPosition':
216  $this->getCurrentField()->setPosition((int) trim($this->cdata));
217  break;
218 
219  case 'FieldValue':
220  $this->getCurrentField()->importXMLProperty($this->field_value_id, trim($this->cdata));
221  break;
222  }
223  $this->cdata = '';
224  }
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 273 of file class.ilAdvancedMDRecordParser.php.

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

Referenced by handlerBeginTag().

274  {
275  switch($this->getMode())
276  {
277  case self::MODE_INSERT:
278  case self::MODE_INSERT_VALIDATION:
279  $this->current_field = ilAdvancedMDFieldDefinition::getInstanceByTypeString($a_type);
280  $this->fields[] = $this->current_field;
281  return true;
282 
283  default:
284  // ??? nonsense
285  $this->current_field = ilAdvancedMDRecord::_getInstanceByFieldId($this->extractFieldId($a_id));
286  return true;
287  break;
288  }
289  }
$errors fields
Definition: imgupload.php:48
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 250 of file class.ilAdvancedMDRecordParser.php.

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

Referenced by handlerBeginTag().

251  {
252  switch($this->getMode())
253  {
254  case self::MODE_INSERT:
255  case self::MODE_INSERT_VALIDATION:
256  $this->current_record = new ilAdvancedMDRecord(0);
257  return true;
258 
259  default:
260  $this->current_record = ilAdvancedMDRecord::_getInstanceByRecordId($this->extractRecordId($a_id));
261  return true;
262  break;
263  }
264  }
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:

◆ setHandlers()

ilAdvancedMDRecordParser::setHandlers (   $a_xml_parser)

set event handlers

Parameters
resourcereference to the xml parser private

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

110  {
111  xml_set_object($a_xml_parser,$this);
112  xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
113  xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
114  }

◆ setMode()

ilAdvancedMDRecordParser::setMode (   $a_mode)

set parsing mode

public

Parameters
intMODE_VALIDATION, MODE_UPDATE or MODE_INSERT

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

Referenced by ilAdvancedMDSettingsGUI\importRecord().

70  {
71  $this->mode = $a_mode;
72  }
+ Here is the caller graph for this function:

◆ startParsing()

ilAdvancedMDRecordParser::startParsing ( )

stores xml data in array

Returns
bool success status private
Exceptions
ilSaxParserException

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

94  {
95  parent::startParsing();
96  if($this->is_error)
97  {
98  include_once('./Services/Xml/exceptions/class.ilSaxParserException.php');
99  throw new ilSaxParserException(implode('<br/>',$this->error_msg));
100  }
101  }
SaxParserException thrown by ilSaxParser if property throwException is set.

◆ storeRecords()

ilAdvancedMDRecordParser::storeRecords ( )
private

Store Record.

private

Parameters

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

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

Referenced by handlerEndTag().

355  {
356  switch($this->getMode())
357  {
358  case self::MODE_INSERT_VALIDATION:
359  case self::MODE_UPDATE_VALIDATION:
360  return true;
361 
362  case self::MODE_INSERT:
363  $this->getCurrentRecord()->save();
364  break;
365  }
366  foreach($this->fields as $field)
367  {
368  $field->setRecordId($this->getCurrentRecord()->getRecordId());
369  switch($this->getMode())
370  {
371  case self::MODE_INSERT:
372  $field->save();
373  break;
374  }
375 
376  }
377  }
$errors fields
Definition: imgupload.php:48
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

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

◆ $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: