34include_once(
'Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
35include_once(
'Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
88 $this->mode = $a_mode;
112 parent::startParsing();
113 if ($this->is_error) {
114 include_once(
'./Services/Xml/exceptions/class.ilSaxParserException.php');
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');
140 case 'AdvancedMetaDataRecords':
141 $this->is_error =
false;
142 $this->error_msg = array();
157 $scope->setRefId($parsed_id[
'id']);
158 $this->scopes[] = $scope;
165 $this->current_field =
null;
166 $this->current_record =
null;
167 if (!strlen($a_attribs[
'id']) or !isset($a_attribs[
'active'])) {
177 if (isset($a_attribs[
'defaultLanguage'])) {
178 $language = (string) $a_attribs[
'defaultLanguage'];
183 $this->
getCurrentRecord()->setDefaultLanguage($this->lng->getDefaultLanguage());
187 case 'RecordTranslations':
188 $this->translations = [];
189 $this->field_translations = [];
191 $a_attribs[
'defaultLanguage'] ?? $this->
getCurrentRecord()->getDefaultLanguage()
195 case 'RecordTranslation':
196 $this->translation_language = $a_attribs[
'language'] ?? $this->lng->getDefaultLanguage();
199 case 'FieldTranslations':
200 $this->field_translations[$this->
getCurrentField()->getImportId()] = [];
203 case 'FieldTranslation':
204 $this->field_translation_language = $a_attribs[
'language'] ?? $this->lng->getDefaultLanguage();
211 if (!strlen($a_attribs[
'id']) or !isset($a_attribs[
'searchable']) or !isset($a_attribs[
'fieldType'])) {
214 if (!$this->
initFieldObject($a_attribs[
'id'], $a_attribs[
'fieldType'])) {
218 $this->
getCurrentField()->setSearchable($a_attribs[
'searchable'] ==
'Yes' ?
true :
false);
222 case 'FieldDescription':
223 case 'FieldPosition':
225 $this->field_value_id = $a_attribs[
'id'];
238 case 'AdvancedMetaDataRecords':
259 $parts = explode(
":", trim($this->cdata));
266 case 'RecordTranslationTitle':
270 case 'RecordTranslationDescription':
274 case 'FieldTranslationTitle':
278 case 'FieldTranslationDescription':
286 case 'FieldDescription':
290 case 'FieldPosition':
295 $this->
getCurrentField()->importXMLProperty($this->field_value_id, trim($this->cdata));
309 if ($a_data !=
"\n") {
311 $a_data = preg_replace(
"/\t+/",
" ", $a_data);
313 $this->cdata .= $a_data;
352 $this->
fields[] = $this->current_field;
357 $this->current_field = ilAdvancedMDRecord::_getInstanceByFieldId($this->extractFieldId($a_id));
368 return $this->current_record;
378 return $this->current_field;
392 $this->record_exists =
true;
409 $this->is_error =
true;
410 $this->error_msg[] = $a_msg;
429 if (is_array($this->context)) {
433 "obj_type" => $this->context[
"obj_type"],
434 "sub_type" => $this->context[
"sub_type"],
442 foreach ($this->
fields as $field) {
447 foreach ($this->field_translations as $field_id => $field_info) {
448 if (strcmp($field_id, $field->getImportId()) !== 0) {
451 foreach ((array) $field_info as $language => $field_translation) {
453 (
int) $field->getFieldId(),
454 (
string) $field_translation[
'title'],
455 (
string) $field_translation[
'description'],
458 $translation->insert();
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();
477 foreach ($this->translations as $lang_key => $translation_info) {
484 (
string) $translation_info[
'title'],
485 (
string) $translation_info[
'description']
491 public function setContext($a_obj_id, $a_obj_type, $a_sub_type =
null)
497 $this->context = array(
498 "obj_id" => $a_obj_id,
499 "obj_type" => $a_obj_type,
500 "sub_type" => $a_sub_type
506 return $this->rec_map;
An exception for terminatinating execution or to throw for unit testing.
static getInstanceByTypeString($a_type)
Get instance by type string (used by import)
Class ilAdvancedMDFieldTranslation.
SAX based XML parser for record import files.
initRecordObject($a_id)
Init record object.
$field_translation_language
setContext($a_obj_id, $a_obj_type, $a_sub_type=null)
setMode($a_mode)
set parsing mode
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
Handler for start tags.
initFieldObject($a_id, $a_type)
Init field definition object.
const MODE_UPDATE_VALIDATION
setHandlers($a_xml_parser)
set event handlers
startParsing()
stores xml data in array
handlerEndTag($a_xml_parser, $a_name)
Handler for end tags.
handlerCharacterData($a_xml_parser, $a_data)
handler for character data
extractRecordId($a_id_string)
Extract id.
const MODE_INSERT_VALIDATION
appendErrorMessage($a_msg)
@access private
getCurrentField()
get current field definition @access private
__construct($a_file)
Constructor.
storeRecords()
Store Record.
Scope restrictions for advanced md records.
static getInstanceByRecordId(int $record_id)
static _getInstanceByRecordId($a_record_id)
Get instance by record id.
static _lookupRecordIdByImportId($a_ilias_id)
Lookup record Id by import id.
static lookupId($a_lang_key)
Lookup obj_id of language @global ilDB $ilDB.
static getLogger($a_component_id)
Get component logger.
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data@access public
SaxParserException thrown by ilSaxParser if property throwException is set.
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
static parseImportId($a_import_id)
Parse an ilias import id Typically of type il_[IL_INST_ID]_[OBJ_TYPE]_[OBJ_ID] returns array( 'orig' ...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc