ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
class.ilAdvancedMDParser.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once("Services/Xml/classes/class.ilSaxParser.php");
5include_once("Services/Utilities/classes/class.ilSaxController.php");
6include_once("Services/Utilities/interfaces/interface.ilSaxSubsetParser.php");
7include_once("Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php");
8include_once("Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php");
9
19{
20 protected $obj_id; // [int]
21 protected $rec_id; // [int]
22 protected $mapping; // [object]
23 protected $cdata; // [string]
24 protected $value_records = array(); // [array]
25 protected $current_record; // [ilAdvancedMDValues]
26 protected $current_value; // [ilAdvancedMDFieldDefinition]
27 protected $has_values; // [bool]
28 protected $record_ids = array(); // [array]
29
30 function __construct($a_obj_id, $a_mapping)
31 {
32 parent::__construct();
33
34 $parts = explode(":", $a_obj_id);
35 $this->obj_id = $parts[0];
36 $this->mapping = $a_mapping;
37 }
38
39 function setHandlers($a_xml_parser)
40 {
41 $this->sax_controller = new ilSaxController();
42 $this->sax_controller->setHandlers($a_xml_parser);
43 $this->sax_controller->setDefaultElementHandler($this);
44 }
45
46 function handlerBeginTag($a_xml_parser,$a_name,$a_attribs)
47 {
48 switch($a_name)
49 {
50 case 'AdvancedMetaData':
51
52
53 break;
54
55 case 'Value':
56 $this->initValue($a_attribs['id'], $a_attribs['sub_type'], $a_attribs['sub_id']);
57 break;
58 }
59 }
60
61 function handlerEndTag($a_xml_parser,$a_name)
62 {
63 switch($a_name)
64 {
65 case 'AdvancedMetaData':
66 // we need to write all records that have been created (1 for each sub-item)
67 foreach($this->value_records as $record)
68 {
69 $record->write();
70 }
71 break;
72
73 case 'Value':
74 $value = trim($this->cdata);
75 if(is_object($this->current_value) && $value != "")
76 {
77 $this->current_value->importValueFromXML($value);
78 }
79 break;
80 }
81 $this->cdata = '';
82 }
83
84 function handlerCharacterData($a_xml_parser,$a_data)
85 {
86 if($a_data != "\n")
87 {
88 // Replace multiple tabs with one space
89 $a_data = preg_replace("/\t+/"," ",$a_data);
90
91 $this->cdata .= $a_data;
92 }
93 }
94
95 protected function initValue($a_import_id, $a_sub_type = "", $a_sub_id = 0)
96 {
97 $this->current_value = null;
98
100 {
101 $rec_id = $field->getRecordId();
102
103 $new_parent_id = $this->mapping->getMapping("Services/AdvancedMetaData", "parent", $this->obj_id);
104 if(!$new_parent_id)
105 {
106 return;
107 }
108
109 if($a_sub_type)
110 {
111 $new_sub_id = $this->mapping->getMapping("Services/AdvancedMetaData", "advmd_sub_item", "advmd:".$a_sub_type.":".$a_sub_id);
112 if(!$new_sub_id)
113 {
114 return;
115 }
116
117 $rec_idx = $rec_id.";".$a_sub_type.";".$new_sub_id;
118 if(!array_key_exists($rec_idx, $this->value_records))
119 {
120 $this->value_records[$rec_idx] = new ilAdvancedMDValues($rec_id, $new_parent_id, $a_sub_type, $new_sub_id);
121 }
122 }
123 else
124 {
125 $rec_idx = $rec_id.";;";
126 if(!array_key_exists($rec_idx, $this->value_records))
127 {
128 $this->value_records[$rec_idx] = new ilAdvancedMDValues($rec_id, $new_parent_id);
129 }
130 }
131
132 // init ADTGroup before definitions to bind definitions to group
133 $this->value_records[$rec_idx]->getADTGroup();
134
135 foreach($this->value_records[$rec_idx]->getDefinitions() as $def)
136 {
137 if($a_import_id == $def->getImportId())
138 {
139 $this->current_value = $def;
140 break;
141 }
142 }
143
144 // valid field found, record will be imported
145 if($this->current_value)
146 {
147 $this->record_ids[$new_parent_id][$a_sub_type][] = $rec_id;
148 }
149 }
150 }
151
152 public function getRecordIds()
153 {
154 return $this->record_ids;
155 }
156}
static getInstanceByImportId($a_import_id)
Get definition instance by import id.
handlerCharacterData($a_xml_parser, $a_data)
handler for character data
setHandlers($a_xml_parser)
set event handlers
__construct($a_obj_id, $a_mapping)
handlerEndTag($a_xml_parser, $a_name)
handler for end of element
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element
initValue($a_import_id, $a_sub_type="", $a_sub_id=0)
Controller class for sax element handlers.
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
Interface definition for sax subset parsers.