ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilAdvancedMDValueParser.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
26 {
27  protected string $cdata = '';
28  protected int $obj_id;
29  protected array $values_records = array();
30  protected array $values = array();
32 
33  public function __construct(int $a_new_obj_id = 0)
34  {
35  $this->obj_id = $a_new_obj_id;
36  }
37 
41  public function setObjId(int $a_obj_id): void
42  {
43  $this->obj_id = $a_obj_id;
44  }
45 
50  public function save(): bool
51  {
52  foreach ($this->values_records as $values_record) {
53  $values_record->write();
54  }
55  return true;
56  }
57 
65  public function handlerBeginTag($a_xml_parser, string $a_name, array $a_attribs): void
66  {
67  switch ($a_name) {
68  case 'AdvancedMetaData':
69  $this->values_records = ilAdvancedMDValues::getInstancesForObjectId($this->obj_id);
70  foreach ($this->values_records as $values_record) {
71  // init ADTGroup before definitions to bind definitions to group
72  $values_record->getADTGroup();
73 
74  foreach ($values_record->getDefinitions() as $def) {
75  $this->values[$def->getImportId()] = $def;
76  }
77  }
78  break;
79 
80  case 'Value':
81  $this->initValue($a_attribs['id']);
82  break;
83  }
84  }
85 
92  public function handlerEndTag($a_xml_parser, string $a_name): void
93  {
94  switch ($a_name) {
95  case 'AdvancedMetaData':
96  break;
97 
98  case 'Value':
99  $value = trim($this->cdata);
100  if (is_object($this->current_value) && $value) {
101  $this->current_value->importValueFromXML($value);
102  }
103  break;
104  }
105  $this->cdata = '';
106  }
107 
114  public function handlerCharacterData($a_xml_parser, string $a_data): void
115  {
116  if ($a_data != "\n") {
117  // Replace multiple tabs with one space
118  $a_data = preg_replace("/\t+/", " ", $a_data);
119 
120  $this->cdata .= $a_data;
121  }
122  }
123 
127  private function initValue(string $a_import_id): void
128  {
129  if (isset($this->values[$a_import_id])) {
130  $this->current_value = $this->values[$a_import_id];
131  } else {
132  $this->current_value = null;
133  }
134  }
135 }
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.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...