4 include_once(
"Services/Xml/classes/class.ilSaxParser.php");
5 include_once(
"Services/Utilities/classes/class.ilSaxController.php");
6 include_once(
"Services/Utilities/interfaces/interface.ilSaxSubsetParser.php");
7 include_once(
"Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php");
8 include_once(
"Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php");
42 parent::__construct();
46 $parts = explode(
":", $a_obj_id);
47 $this->obj_id = $parts[0];
48 $this->mapping = $a_mapping;
54 $this->sax_controller->setHandlers($a_xml_parser);
55 $this->sax_controller->setDefaultElementHandler($this);
61 file_put_contents($tmp_file, $a_xml);
66 include_once(
'Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordParser.php');
73 }
catch (ilSAXParserException $exc) {
79 foreach ($map as $record_id => $fields) {
80 $this->local_rec_fields_map[$record_id] = $fields;
83 foreach ($fields as $import_id => $new_id) {
84 $old_id = array_pop(explode(
"_", $import_id));
85 $this->mapping->addMapping(
"Services/AdvancedMetaData",
"lfld", $old_id, $new_id);
89 $new_id = array_shift(array_keys($map));
90 $this->local_rec_map[$a_old_id] = $new_id;
96 case 'AdvancedMetaData':
100 $this->local_record =
array(
'id'=>$a_attribs[
'local_id']);
104 $this->
initValue($a_attribs[
'id'], $a_attribs[
'sub_type'], $a_attribs[
'sub_id'], $a_attribs[
'local_rec_id']);
112 case 'AdvancedMetaData':
114 foreach ($this->value_records as $record) {
120 $this->local_record[
'xml'] = base64_decode(trim($this->cdata));
121 $this->log->debug(
"Local Record XML: " . $this->local_record[
'xml']);
125 $value = trim($this->cdata);
126 $this->log->debug(
"End Tag Value: -" . is_object($this->current_value) .
"-" . $value);
127 if (is_object($this->current_value) && $value !=
"") {
128 $this->current_value->importValueFromXML($value);
137 if ($a_data !=
"\n") {
139 $a_data = preg_replace(
"/\t+/",
" ", $a_data);
141 $this->cdata .= $a_data;
145 protected function initValue($a_import_id, $a_sub_type =
"", $a_sub_id = 0, $a_local_rec_id = null)
147 $this->current_value = null;
150 $new_parent_id = $this->mapping->getMapping(
"Services/AdvancedMetaData",
"parent", $this->obj_id);
151 $this->log->notice(
'Found new parent id:' . $new_parent_id);
152 if (!$new_parent_id) {
157 strcmp($a_sub_type,
'-') !== 0
159 $new_sub_id = $this->mapping->getMapping(
"Services/AdvancedMetaData",
"advmd_sub_item",
"advmd:" . $a_sub_type .
":" . $a_sub_id);
167 if (is_array($this->local_record)) {
168 $this->
createLocalRecord($this->local_record[
'id'], $this->local_record[
'xml'], $new_parent_id, $a_sub_type);
169 $this->local_record = null;
175 if (!$a_local_rec_id) {
177 $rec_id = $field->getRecordId();
182 $rec_id = $this->local_rec_map[$a_local_rec_id];
191 $rec_idx =
$rec_id .
";" . $a_sub_type .
";" . $new_sub_id;
192 if (!array_key_exists($rec_idx, $this->value_records)) {
197 if (!array_key_exists($rec_idx, $this->value_records)) {
203 $this->value_records[$rec_idx]->getADTGroup();
206 $this->log->debug(
"Find element: " . $a_import_id .
", local rec_id: " . $a_local_rec_id);
207 if (!$a_local_rec_id) {
208 foreach ($this->value_records[$rec_idx]->getDefinitions() as
$def) {
209 if ($a_import_id == $def->getImportId()) {
210 $this->current_value =
$def;
216 $field_id = $this->local_rec_fields_map[
$rec_id][$a_import_id];
218 $this->log->debug(
"- Field id: " . $field_id);
219 foreach ($this->value_records[$rec_idx]->getDefinitions() as
$def) {
220 $this->log->debug(
"- Def field id: " . $def->getFieldId());
221 if ($field_id == $def->getFieldId()) {
222 $this->current_value =
$def;
227 $this->log->debug(
"- No Field id. local rec: " . $a_local_rec_id .
228 ", rec id:" .
$rec_id .
", import id: " . $a_import_id .
", map: " . print_r($this->local_rec_fields_map,
true));
234 if ($this->current_value &&
236 $this->record_ids[$new_parent_id][$a_sub_type][] =
$rec_id;
createLocalRecord($a_old_id, $a_xml, $a_obj_id, $a_sub_type=null)
initValue($a_import_id, $a_sub_type="", $a_sub_id=0, $a_local_rec_id=null)
static getInstanceByImportId($a_import_id)
Get definition instance by import id.
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
setHandlers($a_xml_parser)
handlerEndTag($a_xml_parser, $a_name)
End element handler.
__construct($a_obj_id, $a_mapping)
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
static ilTempnam($a_temp_path=null)
Create a temporary file in an ILIAS writable directory.
Interface definition for sax subset parsers.
Controller class for sax element handlers.
handlerCharacterData($a_xml_parser, $a_data)
Character data handler.
static getLogger($a_component_id)
Get component logger.
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
Start element handler.
SAX based XML parser for record import files.
const MODE_INSERT_VALIDATION