ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups 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.
 setMode ($a_mode)
 set parsing mode
 getMode ()
 get mode
 startParsing ()
 stores xml data in array
 setHandlers ($a_xml_parser)
 set event handlers

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

Private Member Functions

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

Private Attributes

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

Detailed Description

SAX based XML parser for record import files.

Author
Stefan Meyer smeye.nosp@m.r@da.nosp@m.tabay.nosp@m..de
Version
$Id$

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

Constructor & Destructor Documentation

ilAdvancedMDRecordParser::__construct (   $a_file)

Constructor.

public

Parameters
stringxml file

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

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

Member Function Documentation

ilAdvancedMDRecordParser::appendErrorMessage (   $a_msg)
private

private

Parameters

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

Referenced by handlerBeginTag().

{
$this->is_error = true;
$this->error_msg[] = $a_msg;
}

+ Here is the caller graph for this function:

ilAdvancedMDRecordParser::extractRecordId (   $a_id_string)
private

Extract id.

private

Parameters

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

References ilAdvancedMDRecord\_lookupRecordIdByImportId().

Referenced by initRecordObject().

{
// first lookup import id
if($record_id = ilAdvancedMDRecord::_lookupRecordIdByImportId($a_id_string))
{
$this->record_exists = true;
return $record_id;
}
return 0;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilAdvancedMDRecordParser::getCurrentField ( )
private

get current field definition private

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

Referenced by handlerBeginTag(), and handlerEndTag().

{
return $this->current_field;
}

+ Here is the caller graph for this function:

ilAdvancedMDRecordParser::getCurrentRecord ( )
private

get current record

private

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

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

{
return $this->current_record;
}

+ Here is the caller graph for this function:

ilAdvancedMDRecordParser::getMode ( )

get mode

public

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

References $mode.

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

{
return $this->mode;
}

+ Here is the caller graph for this function:

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(), getCurrentField(), getCurrentRecord(), initFieldObject(), initRecordObject(), ilAdvancedMDFieldDefinition\TYPE_DATE, ilAdvancedMDFieldDefinition\TYPE_DATETIME, ilAdvancedMDFieldDefinition\TYPE_SELECT, and ilAdvancedMDFieldDefinition\TYPE_TEXT.

{
switch($a_name)
{
case 'AdvancedMetaDataRecords':
$this->is_error = false;
$this->error_msg = array();
// Nothing to do
break;
case 'Record':
$this->fields = array();
$this->current_field = null;
$this->current_record = null;
if(!strlen($a_attribs['id']) or !isset($a_attribs['active']))
{
$this->appendErrorMessage('Missing XML attribute for element "Record".');
}
if(!$this->initRecordObject($a_attribs['id']))
{
$this->appendErrorMessage('Invalid attribute Id given for element "Record".');
}
$this->getCurrentRecord()->setActive($a_attribs['active']);
$this->getCurrentRecord()->setImportId($a_attribs['id']);
$this->getCurrentRecord()->setAssignedObjectTypes(array());
break;
case 'Title':
break;
case 'Field':
if(!strlen($a_attribs['id']) or !isset($a_attribs['searchable']) or !isset($a_attribs['fieldType']))
{
$this->appendErrorMessage('Missing XML attribute for element "Field".');
}
if(!$this->initFieldObject($a_attribs['id']))
{
$this->appendErrorMessage('Invalid attribute Id given for element "Record".');
}
switch($a_attribs['fieldType'])
{
case 'Select':
break;
case 'Date':
break;
case 'DateTime':
break;
case 'Text':
break;
default:
$this->appendErrorMessage('Invalid attribute value given for element "Record::FieldType".');
break;
}
$this->getCurrentField()->setImportId($a_attribs['id']);
$this->getCurrentField()->enableSearchable($a_attribs['searchable'] == 'Yes' ? true : false);
break;
case 'FieldTitle':
case 'FieldDescription':
case 'FieldPosition':
case 'FieldValue':
break;
}
}

+ Here is the call graph for this function:

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

{
if($a_data != "\n")
{
// Replace multiple tabs with one space
$a_data = preg_replace("/\t+/"," ",$a_data);
$this->cdata .= $a_data;
}
}
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().

{
switch($a_name)
{
case 'AdvancedMetaDataRecords':
break;
case 'Record':
$this->storeRecords();
break;
case 'Title':
$this->getCurrentRecord()->setTitle(trim($this->cdata));
break;
case 'Description':
$this->getCurrentRecord()->setDescription(trim($this->cdata));
break;
case 'ObjectType':
$this->getCurrentRecord()->appendAssignedObjectType(trim($this->cdata));
break;
case 'Field':
break;
case 'FieldTitle':
$this->getCurrentField()->setTitle(trim($this->cdata));
break;
case 'FieldDescription':
$this->getCurrentField()->setDescription(trim($this->cdata));
break;
case 'FieldPosition':
$this->getCurrentField()->setPosition((int) trim($this->cdata));
break;
case 'FieldValue':
$this->getCurrentField()->appendFieldValue(trim($this->cdata));
break;
}
$this->cdata = '';
}

+ Here is the call graph for this function:

ilAdvancedMDRecordParser::initFieldObject (   $a_id)
private

Init field definition object.

private

Parameters
stringimport id

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

References getMode().

Referenced by handlerBeginTag().

{
switch($this->getMode())
{
case self::MODE_INSERT:
case self::MODE_INSERT_VALIDATION:
$this->current_field = new ilAdvancedMDFieldDefinition(0);
$this->fields[] = $this->current_field;
return true;
default:
$this->current_field = ilAdvancedMDRecord::_getInstanceByFieldId($this->extractFieldId($a_id));
return true;
break;
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilAdvancedMDRecordParser::initRecordObject (   $a_id)
private

Init record object.

Parameters
stringimport id private

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

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

Referenced by handlerBeginTag().

{
switch($this->getMode())
{
case self::MODE_INSERT:
case self::MODE_INSERT_VALIDATION:
$this->current_record = new ilAdvancedMDRecord(0);
return true;
default:
$this->current_record = ilAdvancedMDRecord::_getInstanceByRecordId($this->extractRecordId($a_id));
return true;
break;
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilAdvancedMDRecordParser::setHandlers (   $a_xml_parser)

set event handlers

Parameters
resourcereference to the xml parser private

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

{
xml_set_object($a_xml_parser,$this);
xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
}
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().

{
$this->mode = $a_mode;
}

+ Here is the caller graph for this function:

ilAdvancedMDRecordParser::startParsing ( )

stores xml data in array

Returns
bool success status private
Exceptions
ilSaxParserException

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

{
if($this->is_error)
{
include_once('classes/class.ilSaxParserException.php');
throw new ilSaxParserException(implode('<br/>',$this->error_msg));
}
}
ilAdvancedMDRecordParser::storeRecords ( )
private

Store Record.

private

Parameters

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

References getCurrentRecord(), and getMode().

Referenced by handlerEndTag().

{
switch($this->getMode())
{
case self::MODE_INSERT_VALIDATION:
case self::MODE_UPDATE_VALIDATION:
return true;
case self::MODE_INSERT:
$this->getCurrentRecord()->save();
break;
}
foreach($this->fields as $field)
{
$field->setRecordId($this->getCurrentRecord()->getRecordId());
switch($this->getMode())
{
case self::MODE_INSERT:
$field->add();
break;
}
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

ilAdvancedMDRecordParser::$error_msg = array()
private

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

ilAdvancedMDRecordParser::$fields = array()
private

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

ilAdvancedMDRecordParser::$is_error = false
private

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

ilAdvancedMDRecordParser::$mode
private

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

Referenced by getMode().

const ilAdvancedMDRecordParser::MODE_INSERT = 2
const ilAdvancedMDRecordParser::MODE_INSERT_VALIDATION = 4
const ilAdvancedMDRecordParser::MODE_UPDATE = 1

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

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: