ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAdvancedMDValueParser.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
33 include_once('Services/Utilities/interfaces/interface.ilSaxSubsetParser.php');
34 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
35 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValue.php');
36 
38 {
39  protected $cdata = '';
40  protected $obj_id;
41  protected $values = array();
42  protected $current_value = null;
43 
51  public function __construct($a_new_obj_id = 0)
52  {
53  $this->obj_id = $a_new_obj_id;
54  }
55 
63  public function setObjId($a_obj_id)
64  {
65  $this->obj_id = $a_obj_id;
66  }
67 
73  public function save()
74  {
75  foreach($this->values as $value)
76  {
77  $value->setObjId($this->obj_id);
78  $value->save();
79  }
80  return true;
81  }
82 
92  public function handlerBeginTag($a_xml_parser,$a_name,$a_attribs)
93  {
94  switch($a_name)
95  {
96  case 'AdvancedMetaData':
97  $this->values = array();
98  break;
99 
100  case 'Value':
101  $this->initValue($a_attribs['id']);
102  break;
103  }
104 
105  }
106 
115  public function handlerEndTag($a_xml_parser,$a_name)
116  {
117  switch($a_name)
118  {
119  case 'AdvancedMetaData':
120  break;
121 
122  case 'Value':
123  if(is_object($this->current_value))
124  {
125  $this->current_value->setValue(trim($this->cdata));
126  }
127  break;
128  }
129  $this->cdata = '';
130  }
131 
139  public function handlerCharacterData($a_xml_parser,$a_data)
140  {
141  if($a_data != "\n")
142  {
143  // Replace multiple tabs with one space
144  $a_data = preg_replace("/\t+/"," ",$a_data);
145 
146  $this->cdata .= $a_data;
147  }
148  }
149 
157  private function initValue($a_import_id)
158  {
159  if($field_id = ilAdvancedMDFieldDefinition::_lookupFieldId($a_import_id))
160  {
161  $this->current_value = new ilAdvancedMDValue($field_id,$this->obj_id);
162  $this->values[] = $this->current_value;
163  }
164  else
165  {
166  $this->current_value = null;
167  }
168 
169  }
170 }
171 
172 
173 ?>