Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00033 include_once('Services/Utilities/interfaces/interface.ilSaxSubsetParser.php');
00034 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
00035 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValue.php');
00036
00037 class ilAdvancedMDValueParser implements ilSaxSubsetParser
00038 {
00039 protected $cdata = '';
00040 protected $obj_id;
00041 protected $values = array();
00042 protected $current_value = null;
00043
00051 public function __construct($a_new_obj_id = 0)
00052 {
00053 $this->obj_id = $a_new_obj_id;
00054 }
00055
00063 public function setObjId($a_obj_id)
00064 {
00065 $this->obj_id = $a_obj_id;
00066 }
00067
00073 public function save()
00074 {
00075 foreach($this->values as $value)
00076 {
00077 $value->setObjId($this->obj_id);
00078 $value->save();
00079 }
00080 return true;
00081 }
00082
00092 public function handlerBeginTag($a_xml_parser,$a_name,$a_attribs)
00093 {
00094 switch($a_name)
00095 {
00096 case 'AdvancedMetaData':
00097 $this->values = array();
00098 break;
00099
00100 case 'Value':
00101 $this->initValue($a_attribs['id']);
00102 break;
00103 }
00104
00105 }
00106
00115 public function handlerEndTag($a_xml_parser,$a_name)
00116 {
00117 switch($a_name)
00118 {
00119 case 'AdvancedMetaData':
00120 break;
00121
00122 case 'Value':
00123 if(is_object($this->current_value))
00124 {
00125 $this->current_value->setValue(trim($this->cdata));
00126 }
00127 break;
00128 }
00129 $this->cdata = '';
00130 }
00131
00139 public function handlerCharacterData($a_xml_parser,$a_data)
00140 {
00141 if($a_data != "\n")
00142 {
00143
00144 $a_data = preg_replace("/\t+/"," ",$a_data);
00145
00146 $this->cdata .= $a_data;
00147 }
00148 }
00149
00157 private function initValue($a_import_id)
00158 {
00159 if($field_id = ilAdvancedMDFieldDefinition::_lookupFieldId($a_import_id))
00160 {
00161 $this->current_value = new ilAdvancedMDValue($field_id,$this->obj_id);
00162 $this->values[] = $this->current_value;
00163 }
00164 else
00165 {
00166 $this->current_value = null;
00167 }
00168
00169 }
00170 }
00171
00172
00173 ?>