ILIAS  release_7 Revision v7.30-3-g800a261c036
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 = []
 
 $translations = []
 
 $translation_language = ''
 
 $field_translations = []
 
 $field_translation_language = ''
 
 $log
 

Private Member Functions

 initRecordObject ($a_id)
 Init record object. More...
 
 initFieldObject ($a_id, $a_type)
 Init field definition object. More...
 
 getCurrentRecord ()
 
 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 73 of file class.ilAdvancedMDRecordParser.php.

74 {
75 parent::__construct($a_file, true);
76 $this->log = ilLoggerFactory::getLogger('amet');
77 }
static getLogger($a_component_id)
Get component logger.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References ILIAS\GlobalScreen\Provider\__construct(), and 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 407 of file class.ilAdvancedMDRecordParser.php.

408 {
409 $this->is_error = true;
410 $this->error_msg[] = $a_msg;
411 }

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

389 {
390 // first lookup import id
391 if ($record_id = ilAdvancedMDRecord::_lookupRecordIdByImportId($a_id_string)) {
392 $this->record_exists = true;
393 return $record_id;
394 }
395 return 0;
396 }
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 376 of file class.ilAdvancedMDRecordParser.php.

377 {
378 return $this->current_field;
379 }

Referenced by handlerBeginTag(), and handlerEndTag().

+ Here is the caller graph for this function:

◆ getCurrentRecord()

ilAdvancedMDRecordParser::getCurrentRecord ( )
private
Returns
ilAdvancedMDRecord

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

367 {
368 return $this->current_record;
369 }

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

+ Here is the caller graph for this function:

◆ getMode()

ilAdvancedMDRecordParser::getMode ( )

get mode

@access public

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

505 {
506 return $this->rec_map;
507 }

◆ handlerBeginTag()

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

Handler for start tags.

@access protected

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

138 {
139 switch ($a_name) {
140 case 'AdvancedMetaDataRecords':
141 $this->is_error = false;
142 $this->error_msg = array();
143 // Nothing to do
144 break;
145
146 case 'Scope':
147 $this->scopes = [];
148 break;
149
150 case 'ScopeEntry':
151 $parsed_id = ilUtil::parseImportId($a_attribs['id']);
152 if (
153 $parsed_id['inst_id'] == IL_INST_ID &&
154 ilObject::_exists($parsed_id['id'], true, $parsed_id['type'])
155 ) {
156 $scope = new ilAdvancedMDRecordScope();
157 $scope->setRefId($parsed_id['id']);
158 $this->scopes[] = $scope;
159 }
160 break;
161
162
163 case 'Record':
164 $this->fields = array();
165 $this->current_field = null;
166 $this->current_record = null;
167 if (!strlen($a_attribs['id']) or !isset($a_attribs['active'])) {
168 $this->appendErrorMessage('Missing XML attribute for element "Record".');
169 }
170 if (!$this->initRecordObject($a_attribs['id'])) {
171 $this->appendErrorMessage('Invalid attribute Id given for element "Record".');
172 }
173 $this->getCurrentRecord()->setActive($a_attribs['active']);
174 $this->getCurrentRecord()->setImportId($a_attribs['id']);
175 $this->getCurrentRecord()->setAssignedObjectTypes(array());
176
177 if (isset($a_attribs['defaultLanguage'])) {
178 $language = (string) $a_attribs['defaultLanguage'];
179 if (ilLanguage::lookupId($language)) {
180 $this->getCurrentRecord()->setDefaultLanguage($language);
181 }
182 } else {
183 $this->getCurrentRecord()->setDefaultLanguage($this->lng->getDefaultLanguage());
184 }
185 break;
186
187 case 'RecordTranslations':
188 $this->translations = [];
189 $this->field_translations = [];
190 $this->getCurrentRecord()->setDefaultLanguage(
191 $a_attribs['defaultLanguage'] ?? $this->getCurrentRecord()->getDefaultLanguage()
192 );
193 break;
194
195 case 'RecordTranslation':
196 $this->translation_language = $a_attribs['language'] ?? $this->lng->getDefaultLanguage();
197 break;
198
199 case 'FieldTranslations':
200 $this->field_translations[$this->getCurrentField()->getImportId()] = [];
201 break;
202
203 case 'FieldTranslation':
204 $this->field_translation_language = $a_attribs['language'] ?? $this->lng->getDefaultLanguage();
205 break;
206
207 case 'Title':
208 break;
209
210 case 'Field':
211 if (!strlen($a_attribs['id']) or !isset($a_attribs['searchable']) or !isset($a_attribs['fieldType'])) {
212 $this->appendErrorMessage('Missing XML attribute for element "Field".');
213 }
214 if (!$this->initFieldObject($a_attribs['id'], $a_attribs['fieldType'])) {
215 $this->appendErrorMessage('Invalid attribute Id given for element "Record".');
216 }
217 $this->getCurrentField()->setImportId($a_attribs['id']);
218 $this->getCurrentField()->setSearchable($a_attribs['searchable'] == 'Yes' ? true : false);
219 break;
220
221 case 'FieldTitle':
222 case 'FieldDescription':
223 case 'FieldPosition':
224 case 'FieldValue':
225 $this->field_value_id = $a_attribs['id'];
226 break;
227 }
228 }
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 lookupId($a_lang_key)
Lookup obj_id of language @global ilDB $ilDB.
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' ...
const IL_INST_ID
Definition: constants.php:38
$errors fields
Definition: imgupload.php:51

References ilObject\_exists(), appendErrorMessage(), fields, getCurrentField(), getCurrentRecord(), IL_INST_ID, initFieldObject(), initRecordObject(), ilLanguage\lookupId(), 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 307 of file class.ilAdvancedMDRecordParser.php.

308 {
309 if ($a_data != "\n") {
310 // Replace multiple tabs with one space
311 $a_data = preg_replace("/\t+/", " ", $a_data);
312
313 $this->cdata .= $a_data;
314 }
315 }

◆ handlerEndTag()

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

Handler for end tags.

@access protected

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

236 {
237 switch ($a_name) {
238 case 'AdvancedMetaDataRecords':
239 break;
240
241 case 'Record':
242 $this->storeRecords();
243 break;
244
245 case 'Scope':
246 $this->getCurrentRecord()->setScopes($this->scopes);
247 break;
248
249 case 'Title':
250 $this->getCurrentRecord()->setTitle(trim($this->cdata));
251 break;
252
253 case 'Description':
254 $this->getCurrentRecord()->setDescription(trim($this->cdata));
255 break;
256
257 case 'ObjectType':
258 // #12980
259 $parts = explode(":", trim($this->cdata));
260 $this->getCurrentRecord()->appendAssignedObjectType($parts[0], $parts[1]);
261 break;
262
263 case 'Field':
264 break;
265
266 case 'RecordTranslationTitle':
267 $this->translations[$this->translation_language]['title'] = trim($this->cdata);
268 break;
269
270 case 'RecordTranslationDescription':
271 $this->translations[$this->translation_language]['description'] = trim($this->cdata);
272 break;
273
274 case 'FieldTranslationTitle':
275 $this->field_translations[$this->getCurrentField()->getImportId()][$this->field_translation_language]['title'] = trim($this->cdata);
276 break;
277
278 case 'FieldTranslationDescription':
279 $this->field_translations[$this->getCurrentField()->getImportId()][$this->field_translation_language]['description'] = trim($this->cdata);
280 break;
281
282 case 'FieldTitle':
283 $this->getCurrentField()->setTitle(trim($this->cdata));
284 break;
285
286 case 'FieldDescription':
287 $this->getCurrentField()->setDescription(trim($this->cdata));
288 break;
289
290 case 'FieldPosition':
291 $this->getCurrentField()->setPosition((int) trim($this->cdata));
292 break;
293
294 case 'FieldValue':
295 $this->getCurrentField()->importXMLProperty($this->field_value_id, trim($this->cdata));
296 break;
297 }
298 $this->cdata = '';
299 }

References $field_translation_language, $translation_language, 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 346 of file class.ilAdvancedMDRecordParser.php.

347 {
348 switch ($this->getMode()) {
351 $this->current_field = ilAdvancedMDFieldDefinition::getInstanceByTypeString($a_type);
352 $this->fields[] = $this->current_field;
353 return true;
354
355 default:
356 // ??? nonsense
357 $this->current_field = ilAdvancedMDRecord::_getInstanceByFieldId($this->extractFieldId($a_id));
358 return true;
359 break;
360 }
361 }
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 324 of file class.ilAdvancedMDRecordParser.php.

325 {
326 switch ($this->getMode()) {
329 $this->current_record = new ilAdvancedMDRecord(0);
330 return true;
331
332 default:
333 $this->current_record = ilAdvancedMDRecord::_getInstanceByRecordId($this->extractRecordId($a_id));
334 return true;
335 break;
336 }
337 }
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 491 of file class.ilAdvancedMDRecordParser.php.

492 {
493 if (!$a_sub_type) {
494 $a_sub_type = "-";
495 }
496
497 $this->context = array(
498 "obj_id" => $a_obj_id,
499 "obj_type" => $a_obj_type,
500 "sub_type" => $a_sub_type
501 );
502 }

◆ setHandlers()

ilAdvancedMDRecordParser::setHandlers (   $a_xml_parser)

set event handlers

Parameters
resourcereference to the xml parser @access private

Reimplemented from ilSaxParser.

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

126 {
127 xml_set_object($a_xml_parser, $this);
128 xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
129 xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
130 }

◆ setMode()

ilAdvancedMDRecordParser::setMode (   $a_mode)

set parsing mode

@access public

Parameters
intMODE_VALIDATION, MODE_UPDATE or MODE_INSERT

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

87 {
88 $this->mode = $a_mode;
89 }

◆ startParsing()

ilAdvancedMDRecordParser::startParsing ( )

stores xml data in array

Returns
bool success status @access private
Exceptions
ilSaxParserException

Reimplemented from ilSaxParser.

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

111 {
112 parent::startParsing();
113 if ($this->is_error) {
114 include_once('./Services/Xml/exceptions/class.ilSaxParserException.php');
115 throw new ilSaxParserException(implode('<br/>', $this->error_msg));
116 }
117 }
SaxParserException thrown by ilSaxParser if property throwException is set.

◆ storeRecords()

ilAdvancedMDRecordParser::storeRecords ( )
private

Store Record.

@access private

Parameters

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

421 {
422 switch ($this->getMode()) {
425 return true;
426
428 // set local context
429 if (is_array($this->context)) {
430 $this->getCurrentRecord()->setParentObject($this->context["obj_id"]);
431 $this->getCurrentRecord()->setAssignedObjectTypes(array(
432 array(
433 "obj_type" => $this->context["obj_type"],
434 "sub_type" => $this->context["sub_type"],
435 "optional" => false
436 )));
437 }
438
439 $this->getCurrentRecord()->save();
440 break;
441 }
442 foreach ($this->fields as $field) {
443 $field->setRecordId($this->getCurrentRecord()->getRecordId());
444 switch ($this->getMode()) {
446 $field->save();
447 foreach ($this->field_translations as $field_id => $field_info) {
448 if (strcmp($field_id, $field->getImportId()) !== 0) {
449 continue;
450 }
451 foreach ((array) $field_info as $language => $field_translation) {
452 $translation = new ilAdvancedMDFieldTranslation(
453 (int) $field->getFieldId(),
454 (string) $field_translation['title'],
455 (string) $field_translation['description'],
456 (string) $language
457 );
458 $translation->insert();
459 }
460 }
461
462 // see getRecordMap()
463 $this->log->debug("add to record map, rec id: " . $this->getCurrentRecord()->getRecordId() .
464 ", import id: " . $field->getImportId() . ", field id:" . $field->getFieldId());
465 $this->rec_map[$this->getCurrentRecord()->getRecordId()][$field->getImportId()] = $field->getFieldId();
466 break;
467 }
468 }
470 $translations->addTranslationEntry($this->getCurrentRecord()->getDefaultLanguage(), true);
471 $translations->updateTranslations(
472 $this->getCurrentRecord()->getDefaultLanguage(),
473 (string) $this->getCurrentRecord()->getTitle(),
474 (string) $this->getCurrentRecord()->getDescription()
475 );
476
477 foreach ($this->translations as $lang_key => $translation_info) {
478 ilLoggerFactory::getLogger('root')->dump($translation_info, ilLogLevel::ERROR);
479 if (!$translations->isConfigured($lang_key)) {
480 $translations->addTranslationEntry($lang_key);
481 }
482 $translations->updateTranslations(
483 $lang_key,
484 (string) $translation_info['title'],
485 (string) $translation_info['description']
486 );
487 }
488
489 }
Class ilAdvancedMDFieldTranslation.

References $translations, ilLogLevel\ERROR, fields, getCurrentRecord(), ilAdvancedMDRecordTranslations\getInstanceByRecordId(), ilLoggerFactory\getLogger(), 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.

◆ $field_translation_language

ilAdvancedMDRecordParser::$field_translation_language = ''
protected

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

Referenced by handlerEndTag().

◆ $field_translations

ilAdvancedMDRecordParser::$field_translations = []
protected

Definition at line 58 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 64 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.

◆ $translation_language

ilAdvancedMDRecordParser::$translation_language = ''
protected

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

Referenced by handlerEndTag().

◆ $translations

ilAdvancedMDRecordParser::$translations = []
protected

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

Referenced by storeRecords().

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