ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
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)
 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 362 of file class.ilAdvancedMDRecordParser.php.

Referenced by handlerBeginTag().

363  {
364  $this->is_error = true;
365  $this->error_msg[] = $a_msg;
366  }
+ Here is the caller graph for this function:

◆ extractRecordId()

ilAdvancedMDRecordParser::extractRecordId (   $a_id_string)
private

Extract id.

private

Parameters

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

References ilAdvancedMDRecord\_lookupRecordIdByImportId().

Referenced by initRecordObject().

343  {
344  // first lookup import id
345  if($record_id = ilAdvancedMDRecord::_lookupRecordIdByImportId($a_id_string))
346  {
347  $this->record_exists = true;
348  return $record_id;
349  }
350  return 0;
351  }
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 330 of file class.ilAdvancedMDRecordParser.php.

Referenced by handlerBeginTag(), and handlerEndTag().

331  {
332  return $this->current_field;
333  }
+ Here is the caller graph for this function:

◆ getCurrentRecord()

ilAdvancedMDRecordParser::getCurrentRecord ( )
private

get current record

private

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

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

321  {
322  return $this->current_record;
323  }
+ 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(), initRecordObject(), ilAdvancedMDFieldDefinition\TYPE_DATE, ilAdvancedMDFieldDefinition\TYPE_DATETIME, ilAdvancedMDFieldDefinition\TYPE_SELECT, and ilAdvancedMDFieldDefinition\TYPE_TEXT.

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']))
157  {
158  $this->appendErrorMessage('Invalid attribute Id given for element "Record".');
159  }
160  switch($a_attribs['fieldType'])
161  {
162  case 'Select':
164  break;
165 
166  case 'Date':
168  break;
169 
170  case 'DateTime':
172  break;
173 
174  case 'Text':
176  break;
177 
178  default:
179  $this->appendErrorMessage('Invalid attribute value given for element "Record::FieldType".');
180  break;
181 
182  }
183  $this->getCurrentField()->setImportId($a_attribs['id']);
184  $this->getCurrentField()->enableSearchable($a_attribs['searchable'] == 'Yes' ? true : false);
185  break;
186 
187  case 'FieldTitle':
188  case 'FieldDescription':
189  case 'FieldPosition':
190  case 'FieldValue':
191  break;
192  }
193  }
$errors fields
Definition: imgupload.php:47
initFieldObject($a_id)
Init field definition object.
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 254 of file class.ilAdvancedMDRecordParser.php.

255  {
256  if($a_data != "\n")
257  {
258  // Replace multiple tabs with one space
259  $a_data = preg_replace("/\t+/"," ",$a_data);
260 
261  $this->cdata .= $a_data;
262  }
263  }

◆ handlerEndTag()

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

Handler for end tags.

protected

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

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

201  {
202  switch($a_name)
203  {
204  case 'AdvancedMetaDataRecords':
205  break;
206 
207  case 'Record':
208  $this->storeRecords();
209  break;
210 
211  case 'Title':
212  $this->getCurrentRecord()->setTitle(trim($this->cdata));
213  break;
214 
215  case 'Description':
216  $this->getCurrentRecord()->setDescription(trim($this->cdata));
217  break;
218 
219  case 'ObjectType':
220  // #12980
221  $parts = explode(":", trim($this->cdata));
222  $this->getCurrentRecord()->appendAssignedObjectType($parts[0], $parts[1]);
223  break;
224 
225  case 'Field':
226  break;
227 
228 
229  case 'FieldTitle':
230  $this->getCurrentField()->setTitle(trim($this->cdata));
231  break;
232 
233  case 'FieldDescription':
234  $this->getCurrentField()->setDescription(trim($this->cdata));
235  break;
236 
237  case 'FieldPosition':
238  $this->getCurrentField()->setPosition((int) trim($this->cdata));
239  break;
240 
241  case 'FieldValue':
242  $this->getCurrentField()->appendFieldValue(trim($this->cdata));
243  break;
244  }
245  $this->cdata = '';
246  }
getCurrentField()
get current field definition private
+ Here is the call graph for this function:

◆ initFieldObject()

ilAdvancedMDRecordParser::initFieldObject (   $a_id)
private

Init field definition object.

private

Parameters
stringimport id

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

References fields, and getMode().

Referenced by handlerBeginTag().

296  {
297  switch($this->getMode())
298  {
299  case self::MODE_INSERT:
300  case self::MODE_INSERT_VALIDATION:
301  $this->current_field = new ilAdvancedMDFieldDefinition(0);
302  $this->fields[] = $this->current_field;
303  return true;
304 
305  default:
306  $this->current_field = ilAdvancedMDRecord::_getInstanceByFieldId($this->extractFieldId($a_id));
307  return true;
308  break;
309  }
310  }
$errors fields
Definition: imgupload.php:47
+ 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 272 of file class.ilAdvancedMDRecordParser.php.

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

Referenced by handlerBeginTag().

273  {
274  switch($this->getMode())
275  {
276  case self::MODE_INSERT:
277  case self::MODE_INSERT_VALIDATION:
278  $this->current_record = new ilAdvancedMDRecord(0);
279  return true;
280 
281  default:
282  $this->current_record = ilAdvancedMDRecord::_getInstanceByRecordId($this->extractRecordId($a_id));
283  return true;
284  break;
285  }
286  }
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 375 of file class.ilAdvancedMDRecordParser.php.

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

Referenced by handlerEndTag().

376  {
377  switch($this->getMode())
378  {
379  case self::MODE_INSERT_VALIDATION:
380  case self::MODE_UPDATE_VALIDATION:
381  return true;
382 
383  case self::MODE_INSERT:
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->add();
394  break;
395  }
396 
397  }
398  }
$errors fields
Definition: imgupload.php:47
+ 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: