ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 ()
 

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

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

66 {
67 parent::__construct($a_file,true);
68 $this->log = ilLoggerFactory::getLogger('amet');
69 }
static getLogger($a_component_id)
Get component logger.

References ilLoggerFactory\getLogger().

+ Here is the call graph for this function:

Member Function Documentation

◆ appendErrorMessage()

ilAdvancedMDRecordParser::appendErrorMessage (   $a_msg)
private

@access private

Parameters

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

351 {
352 $this->is_error = true;
353 $this->error_msg[] = $a_msg;
354 }

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

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.

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

319 {
320 return $this->current_field;
321 }

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

309 {
310 return $this->current_record;
311 }

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

+ Here is the caller graph for this function:

◆ getMode()

ilAdvancedMDRecordParser::getMode ( )

get mode

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

@access protected

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

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

@access protected

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

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 }

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

283 {
284 switch($this->getMode())
285 {
288 $this->current_field = ilAdvancedMDFieldDefinition::getInstanceByTypeString($a_type);
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 }
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 259 of file class.ilAdvancedMDRecordParser.php.

260 {
261 switch($this->getMode())
262 {
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 }
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:

◆ setContext()

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

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

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 }

◆ setHandlers()

ilAdvancedMDRecordParser::setHandlers (   $a_xml_parser)

set event handlers

Parameters
resourcereference to the xml parser @access 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

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

@access private

Parameters

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

364 {
365 switch($this->getMode())
366 {
369 return true;
370
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 {
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 }

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

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

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