19 declare(strict_types=1);
36 private int $mode = self::MODE_UNDEFINED;
66 public function setMode(
int $a_mode): void
68 $this->mode = $a_mode;
78 parent::startParsing();
79 if ($this->is_error) {
102 case 'AdvancedMetaDataRecords':
103 $this->is_error =
false;
104 $this->error_msg = array();
119 $scope->setRefId((
int) $parsed_id[
'id']);
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'])) {
138 if (isset($a_attribs[
'defaultLanguage'])) {
139 $language = (string) $a_attribs[
'defaultLanguage'];
148 case 'RecordTranslations':
149 $this->translations = [];
150 $this->field_translations = [];
152 $a_attribs[
'defaultLanguage'] ?? $this->
getCurrentRecord()->getDefaultLanguage()
156 case 'RecordTranslation':
157 $this->translation_language = $a_attribs[
'language'] ?? $this->
lng->getDefaultLanguage();
160 case 'FieldTranslations':
161 $this->field_translations[$this->
getCurrentField()->getImportId()] = [];
164 case 'FieldTranslation':
165 $this->field_translation_language = $a_attribs[
'language'] ?? $this->
lng->getDefaultLanguage();
172 if (!strlen($a_attribs[
'id']) or !isset($a_attribs[
'searchable']) or !isset($a_attribs[
'fieldType'])) {
175 if (!$this->
initFieldObject((
int) $a_attribs[
'id'], (
string) $a_attribs[
'fieldType'])) {
179 $this->
getCurrentField()->setSearchable($a_attribs[
'searchable'] ==
'Yes');
183 case 'FieldDescription':
184 case 'FieldPosition':
186 $this->field_value_id = (string) ($a_attribs[
'id'] ??
"");
198 case 'AdvancedMetaDataRecords':
219 $parts = explode(
":", trim($this->cdata));
226 case 'RecordTranslationTitle':
230 case 'RecordTranslationDescription':
234 case 'FieldTranslationTitle':
238 case 'FieldTranslationDescription':
246 case 'FieldDescription':
250 case 'FieldPosition':
255 $this->
getCurrentField()->importXMLProperty($this->field_value_id, trim($this->cdata));
268 if ($a_data !=
"\n") {
270 $a_data = preg_replace(
"/\t+/",
" ", $a_data);
272 $this->cdata .= $a_data;
279 case self::MODE_INSERT:
280 case self::MODE_INSERT_VALIDATION:
296 case self::MODE_INSERT:
297 case self::MODE_INSERT_VALIDATION:
304 'Current parsing mode is not supported. Mode: ' . $this->
getMode()
330 $this->is_error =
true;
331 $this->error_msg[] = $a_msg;
337 case self::MODE_INSERT_VALIDATION:
338 case self::MODE_UPDATE_VALIDATION:
341 case self::MODE_INSERT:
343 if (isset($this->context) && is_array($this->context)) {
347 "obj_type" => $this->context[
"obj_type"],
348 "sub_type" => $this->context[
"sub_type"],
357 foreach ($this->fields as $field) {
360 case self::MODE_INSERT:
361 $field->save(
false,
true);
362 foreach ($this->field_translations as $field_id => $field_info) {
363 if (strcmp($field_id, $field->getImportId()) !== 0) {
366 foreach ((array) $field_info as $language => $field_translation) {
368 (
int) $field->getFieldId(),
369 (string) $field_translation[
'title'],
370 (
string) $field_translation[
'description'],
373 $translation->insert();
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();
385 $translations->addTranslationEntry($this->
getCurrentRecord()->getDefaultLanguage(),
true);
386 $translations->updateTranslations(
392 foreach ($this->translations as $lang_key => $translation_info) {
393 if (!$translations->isConfigured($lang_key)) {
394 $translations->addTranslationEntry($lang_key);
396 $translations->updateTranslations(
398 (
string) $translation_info[
'title'],
399 (
string) $translation_info[
'description']
404 public function setContext(
int $a_obj_id,
string $a_obj_type, ?
string $a_sub_type =
null): void
410 $this->context = array(
411 "obj_id" => $a_obj_id,
412 "obj_type" => $a_obj_type,
413 "sub_type" => $a_sub_type
Scope restrictions for advanced md records.
initFieldObject(int $a_id, string $a_type)
Init field definition object.
setHandlers($a_xml_parser)
set event handlers
initRecordObject(string $a_id)
ilAdvancedMDFieldDefinition $current_field
static getLogger(string $a_component_id)
Get component logger.
string $field_translation_language
ilAdvancedMDRecord $current_record
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
AMD field abstract base class.
__construct(string $a_file)
setContext(int $a_obj_id, string $a_obj_type, ?string $a_sub_type=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
handlerEndTag($a_xml_parser, $a_name)
Handler for end tags protected.
handlerCharacterData($a_xml_parser, string $a_data)
handler for character data
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static _getInstanceByRecordId(int $a_record_id)
static _lookupRecordIdByImportId(string $a_ilias_id)
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
array $field_translations
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
Handler for start tags protected.
static lookupId(string $a_lang_key)
Lookup obj_id of language.
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' ...
appendErrorMessage(string $a_msg)
__construct(Container $dic, ilPlugin $plugin)
SAX based XML parser for record import files.
const MODE_UPDATE_VALIDATION
string $translation_language
const MODE_INSERT_VALIDATION
extractRecordId(string $a_id_string)
static getInstanceByTypeString(string $a_type)
Get instance by type string (used by import)
Class ilAdvancedMDFieldTranslation.
static getInstanceByRecordId(int $record_id)