ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilAdvancedMDRecordParser Class Reference

SAX based XML parser for record import files. More...

+ Inheritance diagram for ilAdvancedMDRecordParser:
+ Collaboration diagram for ilAdvancedMDRecordParser:

Public Member Functions

 __construct (string $a_file)
 
 setMode (int $a_mode)
 
 getMode ()
 
 startParsing ()
 stores xml data in array More...
 
 setHandlers ($a_xml_parser)
 set event handlers More...
 
 setContext (int $a_obj_id, string $a_obj_type, ?string $a_sub_type=null)
 
 getRecordMap ()
 
- Public Member Functions inherited from ilSaxParser
 __construct (?string $path_to_file='', ?bool $throw_exception=false)
 
 setXMLContent (string $a_xml_content)
 
 getXMLContent ()
 
 getInputType ()
 
 startParsing ()
 stores xml data in array More...
 
 createParser ()
 
 setHandlers ($a_xml_parser)
 
 parse ($a_xml_parser, $a_fp=null)
 

Data Fields

const MODE_UNDEFINED = 0
 
const MODE_UPDATE = 1
 
const MODE_INSERT = 2
 
const MODE_UPDATE_VALIDATION = 3
 
const MODE_INSERT_VALIDATION = 4
 
- Data Fields inherited from ilSaxParser
string $xml_file
 
bool $throw_exception = false
 

Protected Member Functions

 handlerBeginTag ($a_xml_parser, $a_name, $a_attribs)
 Handler for start tags @access protected. More...
 
 handlerEndTag ($a_xml_parser, $a_name)
 Handler for end tags @access protected. More...
 
 handlerCharacterData ($a_xml_parser, string $a_data)
 handler for character data More...
 
- Protected Member Functions inherited from ilSaxParser
 openXMLFile ()
 
 handleError (string $message)
 
 setThrowException (bool $throw_exception)
 

Protected Attributes

array $context
 
array $scopes = []
 
array $translations = []
 
string $translation_language = ''
 
array $field_translations = []
 
string $field_translation_language = ''
 
ilAdvancedMDRecord $current_record = null
 
ilAdvancedMDFieldDefinition $current_field = null
 
string $cdata = ''
 
ilLogger $log
 
- Protected Attributes inherited from ilSaxParser
ilLanguage $lng = null
 

Private Member Functions

 initRecordObject (string $a_id)
 
 initFieldObject (int $a_id, string $a_type)
 Init field definition object. More...
 
 getCurrentRecord ()
 
 getCurrentField ()
 
 extractRecordId (string $a_id_string)
 
 appendErrorMessage (string $a_msg)
 
 storeRecords ()
 

Private Attributes

int $mode = self::MODE_UNDEFINED
 
array $fields = []
 
bool $is_error = false
 
array $error_msg = []
 
string $field_value_id = ''
 
array $rec_map
 

Detailed Description

SAX based XML parser for record import files.

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Todo:
remove update mode completely

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

Constructor & Destructor Documentation

◆ __construct()

ilAdvancedMDRecordParser::__construct ( string  $a_file)

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

61 {
62 parent::__construct($a_file, true);
63 $this->log = ilLoggerFactory::getLogger('amet');
64 }
static getLogger(string $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 ( string  $a_msg)
private

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

328 : void
329 {
330 $this->is_error = true;
331 $this->error_msg[] = $a_msg;
332 }

Referenced by handlerBeginTag().

+ Here is the caller graph for this function:

◆ extractRecordId()

ilAdvancedMDRecordParser::extractRecordId ( string  $a_id_string)
private

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

319 : int
320 {
321 // first lookup import id
322 if ($record_id = ilAdvancedMDRecord::_lookupRecordIdByImportId($a_id_string)) {
323 return $record_id;
324 }
325 return 0;
326 }
static _lookupRecordIdByImportId(string $a_ilias_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

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

315 {
317 }
ilAdvancedMDFieldDefinition $current_field

References $current_field.

Referenced by handlerBeginTag(), and handlerEndTag().

+ Here is the caller graph for this function:

◆ getCurrentRecord()

ilAdvancedMDRecordParser::getCurrentRecord ( )
private

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

References $current_record.

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

+ Here is the caller graph for this function:

◆ getMode()

ilAdvancedMDRecordParser::getMode ( )

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

71 : int
72 {
73 return $this->mode;
74 }

References $mode.

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

+ Here is the caller graph for this function:

◆ getRecordMap()

ilAdvancedMDRecordParser::getRecordMap ( )

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

417 : array
418 {
419 return $this->rec_map;
420 }

References $rec_map.

◆ handlerBeginTag()

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

Handler for start tags @access protected.

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

99 : void
100 {
101 switch ($a_name) {
102 case 'AdvancedMetaDataRecords':
103 $this->is_error = false;
104 $this->error_msg = array();
105 // Nothing to do
106 break;
107
108 case 'Scope':
109 $this->scopes = [];
110 break;
111
112 case 'ScopeEntry':
113 $parsed_id = ilUtil::parseImportId($a_attribs['id']);
114 if (
115 $parsed_id['inst_id'] == IL_INST_ID &&
116 ilObject::_exists($parsed_id['id'], true, $parsed_id['type'])
117 ) {
119 $scope->setRefId((int) $parsed_id['id']);
120 $this->scopes[] = $scope;
121 }
122 break;
123
124 case 'Record':
125 $this->fields = array();
126 $this->current_field = null;
127 $this->current_record = null;
128 if (!strlen($a_attribs['id']) or !isset($a_attribs['active'])) {
129 $this->appendErrorMessage('Missing XML attribute for element "Record".');
130 }
131 if (!$this->initRecordObject((string) $a_attribs['id'])) {
132 $this->appendErrorMessage('Invalid attribute Id given for element "Record".');
133 }
134 $this->getCurrentRecord()->setActive((bool) $a_attribs['active']);
135 $this->getCurrentRecord()->setImportId($a_attribs['id']);
136 $this->getCurrentRecord()->setAssignedObjectTypes(array());
137
138 if (isset($a_attribs['defaultLanguage'])) {
139 $language = (string) $a_attribs['defaultLanguage'];
140 if (ilLanguage::lookupId($language)) {
141 $this->getCurrentRecord()->setDefaultLanguage($language);
142 }
143 } else {
144 $this->getCurrentRecord()->setDefaultLanguage($this->lng->getDefaultLanguage());
145 }
146 break;
147
148 case 'RecordTranslations':
149 $this->translations = [];
150 $this->field_translations = [];
151 $this->getCurrentRecord()->setDefaultLanguage(
152 $a_attribs['defaultLanguage'] ?? $this->getCurrentRecord()->getDefaultLanguage()
153 );
154 break;
155
156 case 'RecordTranslation':
157 $this->translation_language = $a_attribs['language'] ?? $this->lng->getDefaultLanguage();
158 break;
159
160 case 'FieldTranslations':
161 $this->field_translations[$this->getCurrentField()->getImportId()] = [];
162 break;
163
164 case 'FieldTranslation':
165 $this->field_translation_language = $a_attribs['language'] ?? $this->lng->getDefaultLanguage();
166 break;
167
168 case 'Title':
169 break;
170
171 case 'Field':
172 if (!strlen($a_attribs['id']) or !isset($a_attribs['searchable']) or !isset($a_attribs['fieldType'])) {
173 $this->appendErrorMessage('Missing XML attribute for element "Field".');
174 }
175 if (!$this->initFieldObject((int) $a_attribs['id'], (string) $a_attribs['fieldType'])) {
176 $this->appendErrorMessage('Invalid attribute Id given for element "Record".');
177 }
178 $this->getCurrentField()->setImportId($a_attribs['id']);
179 $this->getCurrentField()->setSearchable($a_attribs['searchable'] == 'Yes');
180 break;
181
182 case 'FieldTitle':
183 case 'FieldDescription':
184 case 'FieldPosition':
185 case 'FieldValue':
186 $this->field_value_id = (string) ($a_attribs['id'] ?? "");
187 break;
188 }
189 }
initFieldObject(int $a_id, string $a_type)
Init field definition object.
Scope restrictions for advanced md records.
static lookupId(string $a_lang_key)
Lookup obj_id of language.
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
static parseImportId(string $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:40
$scope
Definition: ltiregstart.php:51

References $scope, ilObject\_exists(), appendErrorMessage(), getCurrentField(), getCurrentRecord(), IL_INST_ID, initFieldObject(), initRecordObject(), ILIAS\Repository\lng(), ilLanguage\lookupId(), and ilUtil\parseImportId().

Referenced by setHandlers().

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

◆ handlerCharacterData()

ilAdvancedMDRecordParser::handlerCharacterData (   $a_xml_parser,
string  $a_data 
)
protected

handler for character data

Parameters
resource$a_xml_parserxml parser
string$a_datacharacter data

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

266 : void
267 {
268 if ($a_data != "\n") {
269 // Replace multiple tabs with one space
270 $a_data = preg_replace("/\t+/", " ", $a_data);
271
272 $this->cdata .= $a_data;
273 }
274 }

Referenced by setHandlers().

+ Here is the caller graph for this function:

◆ handlerEndTag()

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

Handler for end tags @access protected.

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

195 : void
196 {
197 switch ($a_name) {
198 case 'AdvancedMetaDataRecords':
199 break;
200
201 case 'Record':
202 $this->storeRecords();
203 break;
204
205 case 'Scope':
206 $this->getCurrentRecord()->setScopes($this->scopes);
207 break;
208
209 case 'Title':
210 $this->getCurrentRecord()->setTitle(trim($this->cdata));
211 break;
212
213 case 'Description':
214 $this->getCurrentRecord()->setDescription(trim($this->cdata));
215 break;
216
217 case 'ObjectType':
218 // #12980
219 $parts = explode(":", trim($this->cdata));
220 $this->getCurrentRecord()->appendAssignedObjectType($parts[0], $parts[1]);
221 break;
222
223 case 'Field':
224 break;
225
226 case 'RecordTranslationTitle':
227 $this->translations[$this->translation_language]['title'] = trim($this->cdata);
228 break;
229
230 case 'RecordTranslationDescription':
231 $this->translations[$this->translation_language]['description'] = trim($this->cdata);
232 break;
233
234 case 'FieldTranslationTitle':
235 $this->field_translations[$this->getCurrentField()->getImportId()][$this->field_translation_language]['title'] = trim($this->cdata);
236 break;
237
238 case 'FieldTranslationDescription':
239 $this->field_translations[$this->getCurrentField()->getImportId()][$this->field_translation_language]['description'] = trim($this->cdata);
240 break;
241
242 case 'FieldTitle':
243 $this->getCurrentField()->setTitle(trim($this->cdata));
244 break;
245
246 case 'FieldDescription':
247 $this->getCurrentField()->setDescription(trim($this->cdata));
248 break;
249
250 case 'FieldPosition':
251 $this->getCurrentField()->setPosition((int) trim($this->cdata));
252 break;
253
254 case 'FieldValue':
255 $this->getCurrentField()->importXMLProperty($this->field_value_id, trim($this->cdata));
256 break;
257 }
258 $this->cdata = '';
259 }
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:61

References $field_translation_language, $parts, $translation_language, getCurrentField(), getCurrentRecord(), and storeRecords().

Referenced by setHandlers().

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

◆ initFieldObject()

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

Init field definition object.

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

294 {
295 switch ($this->getMode()) {
298 $this->current_field = ilAdvancedMDFieldDefinition::getInstanceByTypeString($a_type);
299 $this->fields[] = $this->current_field;
300 return true;
301
302 default:
303 throw new InvalidArgumentException(
304 'Current parsing mode is not supported. Mode: ' . $this->getMode()
305 );
306 }
307 }
static getInstanceByTypeString(string $a_type)
Get instance by type string (used by import)

References $current_field, 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 ( string  $a_id)
private

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

276 : bool
277 {
278 switch ($this->getMode()) {
281 $this->current_record = new ilAdvancedMDRecord(0);
282 return true;
283
284 default:
285 $this->current_record = ilAdvancedMDRecord::_getInstanceByRecordId($this->extractRecordId($a_id));
286 return true;
287 }
288 }
static _getInstanceByRecordId(int $a_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 ( int  $a_obj_id,
string  $a_obj_type,
?string  $a_sub_type = null 
)

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

404 : void
405 {
406 if (!$a_sub_type) {
407 $a_sub_type = "-";
408 }
409
410 $this->context = array(
411 "obj_id" => $a_obj_id,
412 "obj_type" => $a_obj_type,
413 "sub_type" => $a_sub_type
414 );
415 }

◆ setHandlers()

ilAdvancedMDRecordParser::setHandlers (   $a_xml_parser)

set event handlers

Parameters
resourcereference to the xml parser @access private

Reimplemented from ilSaxParser.

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

89 : void
90 {
91 xml_set_element_handler($a_xml_parser, $this->handlerBeginTag(...), $this->handlerEndTag(...));
92 xml_set_character_data_handler($a_xml_parser, $this->handlerCharacterData(...));
93 }
handlerCharacterData($a_xml_parser, string $a_data)
handler for character data
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
Handler for start tags @access protected.
handlerEndTag($a_xml_parser, $a_name)
Handler for end tags @access protected.

References handlerBeginTag(), handlerCharacterData(), and handlerEndTag().

+ Here is the call graph for this function:

◆ setMode()

ilAdvancedMDRecordParser::setMode ( int  $a_mode)

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

66 : void
67 {
68 $this->mode = $a_mode;
69 }

◆ startParsing()

ilAdvancedMDRecordParser::startParsing ( )

stores xml data in array

Exceptions
ilSaxParserException

Reimplemented from ilSaxParser.

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

76 : void
77 {
78 parent::startParsing();
79 if ($this->is_error) {
80 throw new ilSaxParserException(implode('<br/>', $this->error_msg));
81 }
82 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ storeRecords()

ilAdvancedMDRecordParser::storeRecords ( )
private

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

334 : void
335 {
336 switch ($this->getMode()) {
339 return;
340
342 // set local context
343 if (isset($this->context) && is_array($this->context)) {
344 $this->getCurrentRecord()->setParentObject($this->context["obj_id"]);
345 $this->getCurrentRecord()->setAssignedObjectTypes(array(
346 array(
347 "obj_type" => $this->context["obj_type"],
348 "sub_type" => $this->context["sub_type"],
349 "optional" => false
350 )
351 ));
352 }
353
354 $this->getCurrentRecord()->save();
355 break;
356 }
357 foreach ($this->fields as $field) {
358 $field->setRecordId($this->getCurrentRecord()->getRecordId());
359 switch ($this->getMode()) {
361 $field->save(false, true);
362 foreach ($this->field_translations as $field_id => $field_info) {
363 if (strcmp($field_id, $field->getImportId()) !== 0) {
364 continue;
365 }
366 foreach ((array) $field_info as $language => $field_translation) {
367 $translation = new ilAdvancedMDFieldTranslation(
368 (int) $field->getFieldId(),
369 (string) $field_translation['title'],
370 (string) $field_translation['description'],
371 (string) $language
372 );
373 $translation->insert();
374 }
375 }
376
377 // see getRecordMap()
378 $this->log->debug("add to record map, rec id: " . $this->getCurrentRecord()->getRecordId() .
379 ", import id: " . $field->getImportId() . ", field id:" . $field->getFieldId());
380 $this->rec_map[$this->getCurrentRecord()->getRecordId()][$field->getImportId()] = $field->getFieldId();
381 break;
382 }
383 }
385 $translations->addTranslationEntry($this->getCurrentRecord()->getDefaultLanguage(), true);
386 $translations->updateTranslations(
387 $this->getCurrentRecord()->getDefaultLanguage(),
388 $this->getCurrentRecord()->getTitle(),
389 $this->getCurrentRecord()->getDescription()
390 );
391
392 foreach ($this->translations as $lang_key => $translation_info) {
393 if (!$translations->isConfigured($lang_key)) {
394 $translations->addTranslationEntry($lang_key);
395 }
396 $translations->updateTranslations(
397 $lang_key,
398 (string) $translation_info['title'],
399 (string) $translation_info['description']
400 );
401 }
402 }
Class ilAdvancedMDFieldTranslation.

References $translations, getCurrentRecord(), ilAdvancedMDRecordTranslations\getInstanceByRecordId(), getMode(), ILIAS\GlobalScreen\Scope\Footer\Factory\getTitle(), 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

◆ $cdata

string ilAdvancedMDRecordParser::$cdata = ''
protected

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

◆ $context

array ilAdvancedMDRecordParser::$context
protected

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

◆ $current_field

ilAdvancedMDFieldDefinition ilAdvancedMDRecordParser::$current_field = null
protected

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

Referenced by getCurrentField(), and initFieldObject().

◆ $current_record

ilAdvancedMDRecord ilAdvancedMDRecordParser::$current_record = null
protected

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

Referenced by getCurrentRecord().

◆ $error_msg

array ilAdvancedMDRecordParser::$error_msg = []
private

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

◆ $field_translation_language

string ilAdvancedMDRecordParser::$field_translation_language = ''
protected

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

Referenced by handlerEndTag().

◆ $field_translations

array ilAdvancedMDRecordParser::$field_translations = []
protected

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

◆ $field_value_id

string ilAdvancedMDRecordParser::$field_value_id = ''
private

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

◆ $fields

array ilAdvancedMDRecordParser::$fields = []
private

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

◆ $is_error

bool ilAdvancedMDRecordParser::$is_error = false
private

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

◆ $log

ilLogger ilAdvancedMDRecordParser::$log
protected

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

◆ $mode

int ilAdvancedMDRecordParser::$mode = self::MODE_UNDEFINED
private

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

Referenced by getMode().

◆ $rec_map

array ilAdvancedMDRecordParser::$rec_map
private

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

Referenced by getRecordMap().

◆ $scopes

array ilAdvancedMDRecordParser::$scopes = []
protected

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

◆ $translation_language

string ilAdvancedMDRecordParser::$translation_language = ''
protected

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

Referenced by handlerEndTag().

◆ $translations

array ilAdvancedMDRecordParser::$translations = []
protected

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

Referenced by storeRecords().

◆ MODE_INSERT

◆ MODE_INSERT_VALIDATION

const ilAdvancedMDRecordParser::MODE_INSERT_VALIDATION = 4

◆ MODE_UNDEFINED

const ilAdvancedMDRecordParser::MODE_UNDEFINED = 0

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

◆ MODE_UPDATE

const ilAdvancedMDRecordParser::MODE_UPDATE = 1

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

◆ MODE_UPDATE_VALIDATION

const ilAdvancedMDRecordParser::MODE_UPDATE_VALIDATION = 3

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

Referenced by storeRecords().


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