ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
33include_once('Services/Utilities/interfaces/interface.ilSaxSubsetParser.php');
34include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
35include_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 $values_record->write();
78 }
79 return true;
80 }
81
91 public function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
92 {
93 switch ($a_name) {
94 case 'AdvancedMetaData':
95 $this->values_records = ilAdvancedMDValues::getInstancesForObjectId($this->obj_id);
96 foreach ($this->values_records as $values_record) {
97 // init ADTGroup before definitions to bind definitions to group
98 $values_record->getADTGroup();
99
100 foreach ($values_record->getDefinitions() as $def) {
101 $this->values[$def->getImportId()] = $def;
102 }
103 }
104 break;
105
106 case 'Value':
107 $this->initValue($a_attribs['id']);
108 break;
109 }
110 }
111
120 public function handlerEndTag($a_xml_parser, $a_name)
121 {
122 switch ($a_name) {
123 case 'AdvancedMetaData':
124 break;
125
126 case 'Value':
127 $value = trim($this->cdata);
128 if (is_object($this->current_value) && $value) {
129 $this->current_value->importValueFromXML($value);
130 }
131 break;
132 }
133 $this->cdata = '';
134 }
135
143 public function handlerCharacterData($a_xml_parser, $a_data)
144 {
145 if ($a_data != "\n") {
146 // Replace multiple tabs with one space
147 $a_data = preg_replace("/\t+/", " ", $a_data);
148
149 $this->cdata .= $a_data;
150 }
151 }
152
160 private function initValue($a_import_id)
161 {
162 if (isset($this->values[$a_import_id])) {
163 $this->current_value = $this->values[$a_import_id];
164 } else {
165 $this->current_value = null;
166 }
167 }
168}
An exception for terminatinating execution or to throw for unit testing.
handlerEndTag($a_xml_parser, $a_name)
End element handler.
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
Start element handler.
save()
Save values @access public.
__construct($a_new_obj_id=0)
Constructor.
handlerCharacterData($a_xml_parser, $a_data)
Character data handler.
setObjId($a_obj_id)
Set object id (id of new created object)
initValue($a_import_id)
init new value object
static getInstancesForObjectId($a_obj_id, $a_obj_type=null, $a_sub_type="-", $a_sub_id=0)
Get instances for given object id.
$def
Definition: croninfo.php:21
Interface definition for sax subset parsers.