ILIAS  release_8 Revision v8.23
class.ilAdvancedMDValueParser.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 /*
5  +-----------------------------------------------------------------------------+
6  | ILIAS open source |
7  +-----------------------------------------------------------------------------+
8  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
9  | |
10  | This program is free software; you can redistribute it and/or |
11  | modify it under the terms of the GNU General Public License |
12  | as published by the Free Software Foundation; either version 2 |
13  | of the License, or (at your option) any later version. |
14  | |
15  | This program is distributed in the hope that it will be useful, |
16  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
17  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18  | GNU General Public License for more details. |
19  | |
20  | You should have received a copy of the GNU General Public License |
21  | along with this program; if not, write to the Free Software |
22  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23  +-----------------------------------------------------------------------------+
24 */
25 
32 {
33  protected string $cdata = '';
34  protected int $obj_id;
35  protected array $values_records = array();
36  protected array $values = array();
38 
39  public function __construct(int $a_new_obj_id = 0)
40  {
41  $this->obj_id = $a_new_obj_id;
42  }
43 
47  public function setObjId(int $a_obj_id): void
48  {
49  $this->obj_id = $a_obj_id;
50  }
51 
56  public function save(): bool
57  {
58  foreach ($this->values_records as $values_record) {
59  $values_record->write();
60  }
61  return true;
62  }
63 
71  public function handlerBeginTag($a_xml_parser, string $a_name, array $a_attribs): void
72  {
73  switch ($a_name) {
74  case 'AdvancedMetaData':
75  $this->values_records = ilAdvancedMDValues::getInstancesForObjectId($this->obj_id);
76  foreach ($this->values_records as $values_record) {
77  // init ADTGroup before definitions to bind definitions to group
78  $values_record->getADTGroup();
79 
80  foreach ($values_record->getDefinitions() as $def) {
81  $this->values[$def->getImportId()] = $def;
82  }
83  }
84  break;
85 
86  case 'Value':
87  $this->initValue($a_attribs['id']);
88  break;
89  }
90  }
91 
98  public function handlerEndTag($a_xml_parser, string $a_name): void
99  {
100  switch ($a_name) {
101  case 'AdvancedMetaData':
102  break;
103 
104  case 'Value':
105  $value = trim($this->cdata);
106  if (is_object($this->current_value) && $value) {
107  $this->current_value->importValueFromXML($value);
108  }
109  break;
110  }
111  $this->cdata = '';
112  }
113 
120  public function handlerCharacterData($a_xml_parser, string $a_data): void
121  {
122  if ($a_data != "\n") {
123  // Replace multiple tabs with one space
124  $a_data = preg_replace("/\t+/", " ", $a_data);
125 
126  $this->cdata .= $a_data;
127  }
128  }
129 
133  private function initValue(string $a_import_id): void
134  {
135  if (isset($this->values[$a_import_id])) {
136  $this->current_value = $this->values[$a_import_id];
137  } else {
138  $this->current_value = null;
139  }
140  }
141 }
static getInstancesForObjectId(int $a_obj_id, ?string $a_obj_type=null, string $a_sub_type="-", int $a_sub_id=0)
initValue(string $a_import_id)
init new value object
handlerBeginTag($a_xml_parser, string $a_name, array $a_attribs)
Start element handler public.
setObjId(int $a_obj_id)
Set object id (id of new created object)
handlerCharacterData($a_xml_parser, string $a_data)
Character data handler public.
ilAdvancedMDFieldDefinition $current_value
handlerEndTag($a_xml_parser, string $a_name)
End element handler public.
Interface definition for sax subset parsers.