ILIAS  Release_5_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.ilAdvancedMDValues.php');
36 
38 {
39  protected $cdata = '';
40  protected $obj_id;
41  protected $values_records = array(); // [ilAdvancedMDValues]
42  protected $values = array(); // [ilAdvancedMDFieldDefinition]
43  protected $current_value = null;
44 
52  public function __construct($a_new_obj_id = 0)
53  {
54  $this->obj_id = $a_new_obj_id;
55  }
56 
64  public function setObjId($a_obj_id)
65  {
66  $this->obj_id = $a_obj_id;
67  }
68 
74  public function save()
75  {
76  foreach($this->values_records as $values_record)
77  {
78  $values_record->write();
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_records = ilAdvancedMDValues::getInstancesForObjectId($this->obj_id);
98  foreach($this->values_records as $values_record)
99  {
100  // init ADTGroup before definitions to bind definitions to group
101  $values_record->getADTGroup();
102 
103  foreach($values_record->getDefinitions() as $def)
104  {
105  $this->values[$def->getImportId()] = $def;
106  }
107  }
108  break;
109 
110  case 'Value':
111  $this->initValue($a_attribs['id']);
112  break;
113  }
114 
115  }
116 
125  public function handlerEndTag($a_xml_parser,$a_name)
126  {
127  switch($a_name)
128  {
129  case 'AdvancedMetaData':
130  break;
131 
132  case 'Value':
133  $value = trim($this->cdata);
134  if(is_object($this->current_value) && $value)
135  {
136  $this->current_value->importValueFromXML($value);
137  }
138  break;
139  }
140  $this->cdata = '';
141  }
142 
150  public function handlerCharacterData($a_xml_parser,$a_data)
151  {
152  if($a_data != "\n")
153  {
154  // Replace multiple tabs with one space
155  $a_data = preg_replace("/\t+/"," ",$a_data);
156 
157  $this->cdata .= $a_data;
158  }
159  }
160 
168  private function initValue($a_import_id)
169  {
170  if(isset($this->values[$a_import_id]))
171  {
172  $this->current_value = $this->values[$a_import_id];
173  }
174  else
175  {
176  $this->current_value = null;
177  }
178 
179  }
180 }
181 
182 
183 ?>