ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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 @access private More...
 
 extractRecordId ($a_id_string)
 Extract id. More...
 
 appendErrorMessage ($a_msg)
 @access 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.

@access 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

@access private

Parameters

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

342 {
343 $this->is_error = true;
344 $this->error_msg[] = $a_msg;
345 }

Referenced by handlerBeginTag().

+ Here is the caller graph for this function:

◆ extractRecordId()

ilAdvancedMDRecordParser::extractRecordId (   $a_id_string)
private

Extract id.

@access private

Parameters

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

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.

References ilAdvancedMDRecord\_lookupRecordIdByImportId().

Referenced by initRecordObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCurrentField()

ilAdvancedMDRecordParser::getCurrentField ( )
private

get current field definition @access private

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

310 {
311 return $this->current_field;
312 }

Referenced by handlerBeginTag(), and handlerEndTag().

+ Here is the caller graph for this function:

◆ getCurrentRecord()

ilAdvancedMDRecordParser::getCurrentRecord ( )
private

get current record

@access private

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

300 {
301 return $this->current_record;
302 }

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

+ Here is the caller graph for this function:

◆ getMode()

ilAdvancedMDRecordParser::getMode ( )

get mode

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

@access protected

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

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 }
initRecordObject($a_id)
Init record object.
initFieldObject($a_id, $a_type)
Init field definition object.
getCurrentField()
get current field definition @access private
$errors fields
Definition: imgupload.php:48

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

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

@access protected

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

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 }

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

+ Here is the call graph for this function:

◆ initFieldObject()

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

Init field definition object.

@access private

Parameters
stringimport id

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

274 {
275 switch($this->getMode())
276 {
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 }
static getInstanceByTypeString($a_type)
Get instance by type string (used by import)

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

Referenced by handlerBeginTag().

+ 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 @access private

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

251 {
252 switch($this->getMode())
253 {
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 }
extractRecordId($a_id_string)
Extract id.
static _getInstanceByRecordId($a_record_id)
Get instance by record id.

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

Referenced by handlerBeginTag().

+ 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 @access 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

@access public

Parameters
intMODE_VALIDATION, MODE_UPDATE or MODE_INSERT

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

70 {
71 $this->mode = $a_mode;
72 }

◆ startParsing()

ilAdvancedMDRecordParser::startParsing ( )

stores xml data in array

Returns
bool success status @access 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.

@access private

Parameters

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

355 {
356 switch($this->getMode())
357 {
360 return true;
361
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 {
372 $field->save();
373 break;
374 }
375
376 }
377 }

References fields, getCurrentRecord(), getMode(), MODE_INSERT, MODE_INSERT_VALIDATION, and MODE_UPDATE_VALIDATION.

Referenced by handlerEndTag().

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

Referenced by storeRecords().


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