ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
ilAdvancedMDParser Class Reference

Adv MD XML Parser. More...

+ Inheritance diagram for ilAdvancedMDParser:
+ Collaboration diagram for ilAdvancedMDParser:

Public Member Functions

 __construct (string $a_obj_id, ilImportMapping $a_mapping)
 
 setHandlers ($a_xml_parser)
 Set event handlers. More...
 
 createLocalRecord (int $a_old_id, string $a_xml, int $a_obj_id, ?string $a_sub_type=null)
 
 handlerBeginTag ($a_xml_parser, string $a_name, array $a_attribs)
 
 handlerEndTag ($a_xml_parser, string $a_name)
 
 handlerCharacterData ($a_xml_parser, string $a_data)
 
 getRecordIds ()
 
- Public Member Functions inherited from ilMDSaxParser
 __construct (?string $a_xml_file='')
 
 enableMDParsing (bool $a_status)
 
 getMDParsingStatus ()
 
 setMDObject (ilMD $md)
 
 getMDObject ()
 
 inMetaData ()
 
 setHandlers ($a_xml_parser)
 Set event handlers. More...
 
 handlerBeginTag ($a_xml_parser, string $a_name, array $a_attribs)
 
 handlerEndTag ($a_xml_parser, string $a_name)
 
 handlerCharacterData ($a_xml_parser, string $a_data)
 
 __getCharacterData ()
 
 __pushParent (object $md_obj)
 
 __popParent ()
 
 __getParent ()
 
- 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)
 
 handlerBeginTag ($a_xml_parser, string $a_name, array $a_attribs)
 Start element handler. More...
 
 handlerEndTag ($a_xml_parser, string $a_name)
 End element handler. More...
 
 handlerCharacterData ($a_xml_parser, string $a_name)
 Character data handler. More...
 

Protected Member Functions

 initValue (string $a_import_id, string $a_sub_type="", int $a_sub_id=0, int $a_local_rec_id=null)
 
- Protected Member Functions inherited from ilMDSaxParser
 trimAndStripAttribs (array $attribs)
 
 trimAndStrip (string $input)
 
- Protected Member Functions inherited from ilSaxParser
 openXMLFile ()
 
 handleError (string $message)
 
 setThrowException (bool $throw_exception)
 

Protected Attributes

int $obj_id
 
int $rec_id = 0
 
ilImportMapping $mapping
 
string $cdata = ""
 
ilSaxController $sax_controller = null
 
array $value_records = []
 
ilAdvancedMDFieldDefinition $current_value = null
 
array $record_ids = []
 
array $local_record = null
 
array $local_rec_map = []
 
array $local_rec_fields_map = []
 
ilLogger $log
 
- Protected Attributes inherited from ilMDSaxParser
bool $md_in_md = false
 
string $md_chr_data = ''
 
ilMDIdentifier $md_ide = null
 
ilMDLanguage $md_lan = null
 
ilMDDescription $md_des = null
 
ilMDLifecycle $md_lif = null
 
ilMDContribute $md_con = null
 
ilMDEntity $md_ent = null
 
ilMDMetaMetadata $md_met = null
 
ilMDTechnical $md_tec = null
 
ilMDFormat $md_for = null
 
ilMDLocation $md_loc = null
 
ilMDRequirement $md_req = null
 
ilMDOrComposite $md_orc = null
 
ilMDEducational $md_edu = null
 
ilMDTypicalAgeRange $md_typ = null
 
ilMDRights $md_rig = null
 
ilMDRelation $md_rel = null
 
ilMDIdentifier_ $md_ide_ = null
 
ilMDAnnotation $md_ann = null
 
ilMDClassification $md_cla = null
 
ilMDTaxonPath $md_taxp = null
 
ilMDTaxon $md_tax = null
 
ilMDKeyword $md_key = null
 
array $md_parent = array()
 
ilMD $md = null
 
ilMDGeneral $md_gen = null
 
ilLogger $meta_log
 
- Protected Attributes inherited from ilSaxParser
ilLanguage $lng = null
 

Additional Inherited Members

- Data Fields inherited from ilSaxParser
string $xml_file
 
bool $throw_exception = false
 

Detailed Description

Adv MD XML Parser.

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 22 of file class.ilAdvancedMDParser.php.

Constructor & Destructor Documentation

◆ __construct()

ilAdvancedMDParser::__construct ( string  $a_obj_id,
ilImportMapping  $a_mapping 
)

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

49 {
51
52 $this->log = ilLoggerFactory::getLogger('amet');
53
54 $parts = explode(":", $a_obj_id);
55 $this->obj_id = (int) $parts[0];
56 $this->mapping = $a_mapping;
57 }
static getLogger(string $a_component_id)
Get component logger.
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:64
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References $parts, ILIAS\GlobalScreen\Provider\__construct(), ilLoggerFactory\getLogger(), and ILIAS\Repository\int().

+ Here is the call graph for this function:

Member Function Documentation

◆ createLocalRecord()

ilAdvancedMDParser::createLocalRecord ( int  $a_old_id,
string  $a_xml,
int  $a_obj_id,
?string  $a_sub_type = null 
)

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

66 : void
67 {
68 $tmp_file = ilFileUtils::ilTempnam();
69 file_put_contents($tmp_file, $a_xml);
70
71 // see ilAdvancedMDSettingsGUI::importRecord()
72 $parser = null;
73 try {
74 // the (old) record parser does only support files
75 $parser = new ilAdvancedMDRecordParser($tmp_file);
76 $parser->setContext($a_obj_id, ilObject::_lookupType($a_obj_id), $a_sub_type);
78 $parser->startParsing();
80 $parser->startParsing();
81 } catch (ilSaxParserException $exc) {
82 $this->log->error('Parsing failed with message: ' . $exc->getMessage());
83 return;
84 } finally {
85 unlink($tmp_file);
86 }
87 $map = $parser->getRecordMap();
88 foreach ($map as $record_id => $fields) {
89 $this->local_rec_fields_map[$record_id] = $fields;
90
91 // needed for glossary field order
92 foreach ($fields as $import_id => $new_id) {
93 $import_ids = explode('_', $import_id);
94 $old_id = array_pop($import_ids);
95 $this->mapping->addMapping("Services/AdvancedMetaData", "lfld", $old_id, (string) $new_id);
96 }
97 }
98 $map_keys = array_keys($map);
99 $new_id = array_shift($map_keys);
100 $this->local_rec_map[$a_old_id] = $new_id;
101 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
static _lookupType(int $id, bool $reference=false)
SaxParserException thrown by ilSaxParser if property throwException is set.

References ilObject\_lookupType(), ilFileUtils\ilTempnam(), ilAdvancedMDRecordParser\MODE_INSERT, and ilAdvancedMDRecordParser\MODE_INSERT_VALIDATION.

+ Here is the call graph for this function:

◆ getRecordIds()

ilAdvancedMDParser::getRecordIds ( )
Returns
int[]

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

276 : array
277 {
278 return $this->record_ids;
279 }

◆ handlerBeginTag()

ilAdvancedMDParser::handlerBeginTag (   $a_xml_parser,
string  $a_name,
array  $a_attribs 
)
Parameters
XMLParser | resource$a_xml_parser

Reimplemented from ilMDSaxParser.

Definition at line 103 of file class.ilAdvancedMDParser.php.

103 : void
104 {
105 switch ($a_name) {
106 case 'AdvancedMetaData':
107 break;
108
109 case 'Record':
110 $this->local_record = array('id' => $a_attribs['local_id']);
111 break;
112
113 case 'Value':
114 $this->initValue(
115 (string) $a_attribs['id'],
116 (string) $a_attribs['sub_type'],
117 (int) $a_attribs['sub_id'],
118 isset($a_attribs['local_rec_id']) ? (int) $a_attribs['local_rec_id'] : null
119 );
120 break;
121 }
122 }
initValue(string $a_import_id, string $a_sub_type="", int $a_sub_id=0, int $a_local_rec_id=null)

References initValue().

+ Here is the call graph for this function:

◆ handlerCharacterData()

ilAdvancedMDParser::handlerCharacterData (   $a_xml_parser,
string  $a_data 
)
Parameters
resource$a_xml_parser

Reimplemented from ilMDSaxParser.

Definition at line 150 of file class.ilAdvancedMDParser.php.

150 : void
151 {
152 if ($a_data != "\n") {
153 // Replace multiple tabs with one space
154 $a_data = preg_replace("/\t+/", " ", $a_data);
155
156 $this->cdata .= $a_data;
157 }
158 }

◆ handlerEndTag()

ilAdvancedMDParser::handlerEndTag (   $a_xml_parser,
string  $a_name 
)
Parameters
resource$a_xml_parser

Reimplemented from ilMDSaxParser.

Definition at line 124 of file class.ilAdvancedMDParser.php.

124 : void
125 {
126 switch ($a_name) {
127 case 'AdvancedMetaData':
128 // we need to write all records that have been created (1 for each sub-item)
129 foreach ($this->value_records as $record) {
130 $record->write();
131 }
132 break;
133
134 case 'Record':
135 $this->local_record['xml'] = base64_decode(trim($this->cdata));
136 $this->log->debug("Local Record XML: " . $this->local_record['xml']);
137 break;
138
139 case 'Value':
140 $value = trim($this->cdata);
141 $this->log->debug("End Tag Value: -" . is_object($this->current_value) . "-" . $value);
142 if (is_object($this->current_value) && $value != "") {
143 $this->current_value->importValueFromXML($value);
144 }
145 break;
146 }
147 $this->cdata = '';
148 }

◆ initValue()

ilAdvancedMDParser::initValue ( string  $a_import_id,
string  $a_sub_type = "",
int  $a_sub_id = 0,
int  $a_local_rec_id = null 
)
protected

Definition at line 160 of file class.ilAdvancedMDParser.php.

165 : void {
166 $this->current_value = null;
167
168 // get parent objects
169 $new_parent_id = (int) $this->mapping->getMapping("Services/AdvancedMetaData", "parent", (string) $this->obj_id);
170 $this->log->notice('Found new parent id:' . $new_parent_id);
171 if (!$new_parent_id) {
172 return;
173 }
174 $new_sub_id = '';
175 if ($a_sub_type && strcmp($a_sub_type, '-') !== 0) {
176 $new_sub_id = $this->mapping->getMapping(
177 "Services/AdvancedMetaData",
178 "advmd_sub_item",
179 "advmd:" . $a_sub_type . ":" . $a_sub_id
180 );
181 if (!$new_sub_id) {
182 return;
183 }
184 }
185
186 // init local record?
187 // done here because we need object context
188 if (is_array($this->local_record)) {
189 $this->createLocalRecord(
190 (int) $this->local_record['id'],
191 $this->local_record['xml'],
192 $new_parent_id,
193 $a_sub_type
194 );
195 $this->local_record = null;
196 }
197
198 $rec_id = null;
199
200 // find record via import id
201 if (!$a_local_rec_id) {
202 if ($field = ilAdvancedMDFieldDefinition::getInstanceByImportId($a_import_id)) {
203 $rec_id = $field->getRecordId();
204 }
205 } // (new) local record
206 else {
207 $rec_id = $this->local_rec_map[$a_local_rec_id];
208 }
209
210 if (!$rec_id) {
211 return;
212 }
213
214 // init record definitions
215 if ($a_sub_type) {
216 $rec_idx = $rec_id . ";" . $a_sub_type . ";" . $new_sub_id;
217 if (!array_key_exists($rec_idx, $this->value_records)) {
218 $this->value_records[$rec_idx] = new ilAdvancedMDValues(
219 $rec_id,
220 $new_parent_id,
221 $a_sub_type,
222 $new_sub_id
223 );
224 }
225 } else {
226 $rec_idx = $rec_id . ";;";
227 if (!array_key_exists($rec_idx, $this->value_records)) {
228 $this->value_records[$rec_idx] = new ilAdvancedMDValues($rec_id, $new_parent_id);
229 }
230 }
231
232 // init ADTGroup before definitions to bind definitions to group
233 $this->value_records[$rec_idx]->getADTGroup();
234
235 // find element with import id
236 $this->log->debug("Find element: " . $a_import_id . ", local rec_id: " . $a_local_rec_id);
237 if (!$a_local_rec_id) {
238 foreach ($this->value_records[$rec_idx]->getDefinitions() as $def) {
239 if ($a_import_id == $def->getImportId()) {
240 $this->current_value = $def;
241 break;
242 }
243 }
244 } else {
245 // find element in new local record
246 $field_id = $this->local_rec_fields_map[$rec_id][$a_import_id];
247 if ($field_id) {
248 $this->log->debug("- Field id: " . $field_id);
249 foreach ($this->value_records[$rec_idx]->getDefinitions() as $def) {
250 $this->log->debug("- Def field id: " . $def->getFieldId());
251 if ($field_id == $def->getFieldId()) {
252 $this->current_value = $def;
253 break;
254 }
255 }
256 } else {
257 $this->log->debug("- No Field id. local rec: " . $a_local_rec_id .
258 ", rec id:" . $rec_id . ", import id: " . $a_import_id . ", map: " . print_r(
259 $this->local_rec_fields_map,
260 true
261 ));
262 }
263 }
264
265 // record will be selected for parent
266 // see ilAdvancedMetaDataImporter
267 if ($this->current_value &&
268 !$a_local_rec_id) {
269 $this->record_ids[$new_parent_id][$a_sub_type][] = $rec_id;
270 }
271 }
static getInstanceByImportId(string $a_import_id)
createLocalRecord(int $a_old_id, string $a_xml, int $a_obj_id, ?string $a_sub_type=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

Referenced by handlerBeginTag().

+ Here is the caller graph for this function:

◆ setHandlers()

ilAdvancedMDParser::setHandlers (   $a_xml_parser)

Set event handlers.

Parameters
XMLParser|resourcereference to the xml parser

Reimplemented from ilMDSaxParser.

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

59 : void
60 {
61 $this->sax_controller = new ilSaxController();
62 $this->sax_controller->setHandlers($a_xml_parser);
63 $this->sax_controller->setDefaultElementHandler($this);
64 }
Controller class for sax element handlers.

Field Documentation

◆ $cdata

string ilAdvancedMDParser::$cdata = ""
protected

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

◆ $current_value

ilAdvancedMDFieldDefinition ilAdvancedMDParser::$current_value = null
protected

Definition at line 35 of file class.ilAdvancedMDParser.php.

◆ $local_rec_fields_map

array ilAdvancedMDParser::$local_rec_fields_map = []
protected

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

◆ $local_rec_map

array ilAdvancedMDParser::$local_rec_map = []
protected

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

◆ $local_record

array ilAdvancedMDParser::$local_record = null
protected

Definition at line 39 of file class.ilAdvancedMDParser.php.

◆ $log

ilLogger ilAdvancedMDParser::$log
protected

Definition at line 46 of file class.ilAdvancedMDParser.php.

◆ $mapping

ilImportMapping ilAdvancedMDParser::$mapping
protected

Definition at line 26 of file class.ilAdvancedMDParser.php.

◆ $obj_id

int ilAdvancedMDParser::$obj_id
protected

Definition at line 24 of file class.ilAdvancedMDParser.php.

◆ $rec_id

int ilAdvancedMDParser::$rec_id = 0
protected

Definition at line 25 of file class.ilAdvancedMDParser.php.

◆ $record_ids

array ilAdvancedMDParser::$record_ids = []
protected

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

◆ $sax_controller

ilSaxController ilAdvancedMDParser::$sax_controller = null
protected

Definition at line 28 of file class.ilAdvancedMDParser.php.

◆ $value_records

array ilAdvancedMDParser::$value_records = []
protected

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


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