ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 ()
 
- Public Member Functions inherited from ilSaxParser
 __construct ($a_xml_file='', $throwException=false)
 Constructor setup ILIAS global object @access public. More...
 
 setXMLContent ($a_xml_content)
 
 getXMLContent ()
 
 getInputType ()
 
 startParsing ()
 stores xml data in array More...
 
 createParser ()
 create parser More...
 
 setOptions ($a_xml_parser)
 set parser options More...
 
 setHandlers ($a_xml_parser)
 set event handler should be overwritten by inherited class @access private More...
 
 openXMLFile ()
 open xml file More...
 
 parse ($a_xml_parser, $a_fp=null)
 parse xml file More...
 
 freeParser ($a_xml_parser)
 free xml parser handle More...
 
 setThrowException ($throwException)
 set error handling More...
 
- Public Member Functions inherited from PEAR
 __construct ($error_class=null)
 Constructor. More...
 
 _PEAR ()
 Destructor (the emulated type of...). More...
 
 registerShutdownFunc ($func, $args=array())
 Use this function to register a shutdown method for static classes. More...
 
 isError ($data, $code=null)
 Tell whether a value is a PEAR error. More...
 
 expectError ($code=' *')
 This method is used to tell which errors you expect to get. More...
 
 popExpect ()
 This method pops one element off the expected error codes stack. More...
 
 _checkDelExpect ($error_code)
 This method checks unsets an error code if available. More...
 
 delExpect ($error_code)
 This method deletes all occurences of the specified element from the expected error codes stack. More...
 
raiseError ($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
 This method is a wrapper that returns an instance of the configured error class with this object's default error handling applied. More...
 
throwError ($message=null, $code=null, $userinfo=null)
 Simpler form of raiseError with fewer options. More...
 
 staticPushErrorHandling ($mode, $options=null)
 
 staticPopErrorHandling ()
 
 pushErrorHandling ($mode, $options=null)
 Push a new error handler on top of the error handler options stack. More...
 
 popErrorHandling ()
 Pop the last error handler used. More...
 
 loadExtension ($ext)
 OS independant PHP extension load. More...
 

Data Fields

const MODE_UPDATE = 1
 
const MODE_INSERT = 2
 
const MODE_UPDATE_VALIDATION = 3
 
const MODE_INSERT_VALIDATION = 4
 
- Data Fields inherited from ilSaxParser
 $input_type = null
 
 $xml_content = ''
 
 $ilias
 
 $lng
 
 $xml_file
 
 $throwException = false
 
- Data Fields inherited from PEAR
 $_debug = false
 
 $_default_error_mode = null
 
 $_default_error_options = null
 
 $_default_error_handler = ''
 
 $_error_class = 'PEAR_Error'
 
 $_expected_errors = array()
 

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 Member Functions inherited from ilSaxParser
 handleError ($message, $code)
 use given error handler to handle error message or internal ilias error message handle More...
 

Protected Attributes

 $context
 
 $scopes = []
 
 $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()
 

Additional Inherited Members

- Static Public Member Functions inherited from PEAR
static & getStaticProperty ($class, $var)
 If you have a class that's mostly/entirely static, and you need static properties, you can use this method to simulate them. More...
 
static setErrorHandling ($mode=null, $options=null)
 Sets how errors generated by this object should be handled. More...
 

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

Reimplemented from PEAR.

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

68 {
69 parent::__construct($a_file, true);
70 $this->log = ilLoggerFactory::getLogger('amet');
71 }
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 362 of file class.ilAdvancedMDRecordParser.php.

363 {
364 $this->is_error = true;
365 $this->error_msg[] = $a_msg;
366 }

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

344 {
345 // first lookup import id
346 if ($record_id = ilAdvancedMDRecord::_lookupRecordIdByImportId($a_id_string)) {
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.

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

332 {
333 return $this->current_field;
334 }

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

322 {
323 return $this->current_record;
324 }

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

+ Here is the caller graph for this function:

◆ getMode()

ilAdvancedMDRecordParser::getMode ( )

get mode

@access public

Definition at line 91 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 425 of file class.ilAdvancedMDRecordParser.php.

426 {
427 return $this->rec_map;
428 }

◆ handlerBeginTag()

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

Handler for start tags.

@access protected

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

132 {
133 switch ($a_name) {
134 case 'AdvancedMetaDataRecords':
135 $this->is_error = false;
136 $this->error_msg = array();
137 // Nothing to do
138 break;
139
140 case 'Scope':
141 $this->scopes = [];
142 break;
143
144 case 'ScopeEntry':
145 $parsed_id = ilUtil::parseImportId($a_attribs['id']);
146 if (
147 $parsed_id['inst_id'] == IL_INST_ID &&
148 ilObject::_exists($parsed_id['id'], true, $parsed_id['type'])
149 ) {
150 $scope = new ilAdvancedMDRecordScope();
151 $scope->setRefId($parsed_id['id']);
152 $this->scopes[] = $scope;
153 }
154 break;
155
156
157 case 'Record':
158 $this->fields = array();
159 $this->current_field = null;
160 $this->current_record = null;
161 if (!strlen($a_attribs['id']) or !isset($a_attribs['active'])) {
162 $this->appendErrorMessage('Missing XML attribute for element "Record".');
163 }
164 if (!$this->initRecordObject($a_attribs['id'])) {
165 $this->appendErrorMessage('Invalid attribute Id given for element "Record".');
166 }
167 $this->getCurrentRecord()->setActive($a_attribs['active']);
168 $this->getCurrentRecord()->setImportId($a_attribs['id']);
169 $this->getCurrentRecord()->setAssignedObjectTypes(array());
170 break;
171
172 case 'Title':
173 break;
174
175 case 'Field':
176 if (!strlen($a_attribs['id']) or !isset($a_attribs['searchable']) or !isset($a_attribs['fieldType'])) {
177 $this->appendErrorMessage('Missing XML attribute for element "Field".');
178 }
179 if (!$this->initFieldObject($a_attribs['id'], $a_attribs['fieldType'])) {
180 $this->appendErrorMessage('Invalid attribute Id given for element "Record".');
181 }
182 $this->getCurrentField()->setImportId($a_attribs['id']);
183 $this->getCurrentField()->setSearchable($a_attribs['searchable'] == 'Yes' ? true : false);
184 break;
185
186 case 'FieldTitle':
187 case 'FieldDescription':
188 case 'FieldPosition':
189 case 'FieldValue':
190 $this->field_value_id = $a_attribs['id'];
191 break;
192 }
193 }
initRecordObject($a_id)
Init record object.
initFieldObject($a_id, $a_type)
Init field definition object.
getCurrentField()
get current field definition @access private
Scope restrictions for advanced md records.
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data@access public
static parseImportId($a_import_id)
Parse an ilias import id Typically of type il_[IL_INST_ID]_[OBJ_TYPE]_[OBJ_ID] returns array( 'orig' ...
$errors fields
Definition: imgupload.php:51

References ilObject\_exists(), appendErrorMessage(), fields, getCurrentField(), getCurrentRecord(), initFieldObject(), initRecordObject(), and ilUtil\parseImportId().

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

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

◆ handlerEndTag()

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

Handler for end tags.

@access protected

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

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

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

297 {
298 switch ($this->getMode()) {
302 $this->fields[] = $this->current_field;
303 return true;
304
305 default:
306 // ??? nonsense
307 $this->current_field = ilAdvancedMDRecord::_getInstanceByFieldId($this->extractFieldId($a_id));
308 return true;
309 break;
310 }
311 }
static getInstanceByTypeString($a_type)
Get instance by type string (used by import)
$a_type
Definition: workflow.php:92

References $a_type, 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 274 of file class.ilAdvancedMDRecordParser.php.

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

413 {
414 if (!$a_sub_type) {
415 $a_sub_type = "-";
416 }
417
418 $this->context = array(
419 "obj_id" => $a_obj_id,
420 "obj_type" => $a_obj_type,
421 "sub_type" => $a_sub_type
422 );
423 }

◆ setHandlers()

ilAdvancedMDRecordParser::setHandlers (   $a_xml_parser)

set event handlers

Parameters
resourcereference to the xml parser @access private

Reimplemented from ilSaxParser.

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

120 {
121 xml_set_object($a_xml_parser, $this);
122 xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
123 xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
124 }

◆ setMode()

ilAdvancedMDRecordParser::setMode (   $a_mode)

set parsing mode

@access public

Parameters
intMODE_VALIDATION, MODE_UPDATE or MODE_INSERT

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

81 {
82 $this->mode = $a_mode;
83 }

◆ startParsing()

ilAdvancedMDRecordParser::startParsing ( )

stores xml data in array

Returns
bool success status @access private
Exceptions
ilSaxParserException

Reimplemented from ilSaxParser.

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

105 {
106 parent::startParsing();
107 if ($this->is_error) {
108 include_once('./Services/Xml/exceptions/class.ilSaxParserException.php');
109 throw new ilSaxParserException(implode('<br/>', $this->error_msg));
110 }
111 }
SaxParserException thrown by ilSaxParser if property throwException is set.

◆ storeRecords()

ilAdvancedMDRecordParser::storeRecords ( )
private

Store Record.

@access private

Parameters

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

376 {
377 switch ($this->getMode()) {
380 return true;
381
383 // set local context
384 if (is_array($this->context)) {
385 $this->getCurrentRecord()->setParentObject($this->context["obj_id"]);
386 $this->getCurrentRecord()->setAssignedObjectTypes(array(
387 array(
388 "obj_type" => $this->context["obj_type"],
389 "sub_type" => $this->context["sub_type"],
390 "optional" => false
391 )));
392 }
393
394 $this->getCurrentRecord()->save();
395 break;
396 }
397 foreach ($this->fields as $field) {
398 $field->setRecordId($this->getCurrentRecord()->getRecordId());
399 switch ($this->getMode()) {
401 $field->save();
402
403 // see getRecordMap()
404 $this->log->debug("add to record map, rec id: " . $this->getCurrentRecord()->getRecordId() .
405 ", import id: " . $field->getImportId() . ", field id:" . $field->getFieldId());
406 $this->rec_map[$this->getCurrentRecord()->getRecordId()][$field->getImportId()] = $field->getFieldId();
407 break;
408 }
409 }
410 }

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

◆ $mode

ilAdvancedMDRecordParser::$mode
private

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

Referenced by getMode().

◆ $scopes

ilAdvancedMDRecordParser::$scopes = []
protected

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

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