ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilObjectXMLParser Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Inheritance diagram for ilObjectXMLParser:
+ Collaboration diagram for ilObjectXMLParser:

Public Member Functions

 __construct (string $a_xml_data='', ?bool $throw_exception=false)
 
 getObjectData ()
 
 setHandlers ($a_xml_parser)
 
 handlerBeginTag ($a_xml_parser, string $a_name, array $a_attribs)
 
 handlerEndTag ($a_xml_parser, string $a_name)
 
 handlerCharacterData ($a_xml_parser, string $a_data)
 
- Public Member Functions inherited from ilSaxParser
 __construct (?string $path_to_file='', ?bool $throw_exception=false)
 
 setXMLContent (string $a_xml_content)
 
 getXMLContent ()
 
 getInputType ()
 
 startParsing ()
 stores xml data in array More...
 
 createParser ()
 
 setHandlers ($a_xml_parser)
 
 parse ($a_xml_parser, $a_fp=null)
 

Data Fields

array $object_data = []
 
- Data Fields inherited from ilSaxParser
string $xml_file
 
bool $throw_exception = false
 

Private Member Functions

 addProperty (string $a_name, $a_value)
 
 addReference (int $a_ref_id, int $a_parent_id, array $a_time_target)
 

Private Attributes

int $ref_id = 0
 
int $parent_id = 0
 
int $curr_obj = 0
 
array $time_target = []
 
string $cdata = ''
 

Additional Inherited Members

- Protected Member Functions inherited from ilSaxParser
 openXMLFile ()
 
 handleError (string $message)
 
 setThrowException (bool $throw_exception)
 
- Protected Attributes inherited from ilSaxParser
ilLanguage $lng = null
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning

Definition at line 20 of file class.ilObjectXMLParser.php.

Constructor & Destructor Documentation

◆ __construct()

ilObjectXMLParser::__construct ( string  $a_xml_data = '',
?bool  $throw_exception = false 
)

Definition at line 30 of file class.ilObjectXMLParser.php.

References ilSaxParser\$throw_exception, ILIAS\MetaData\Repository\Validation\Data\__construct(), and ilSaxParser\setXMLContent().

31  {
33  $this->setXMLContent($a_xml_data);
34  }
__construct(VocabulariesInterface $vocabularies)
setXMLContent(string $a_xml_content)
+ Here is the call graph for this function:

Member Function Documentation

◆ addProperty()

ilObjectXMLParser::addProperty ( string  $a_name,
  $a_value 
)
private
Parameters
string$a_name
string  |  int$a_value
Returns
void

Definition at line 198 of file class.ilObjectXMLParser.php.

References $curr_obj.

Referenced by handlerBeginTag(), and handlerEndTag().

198  : void
199  {
200  $this->object_data[$this->curr_obj][$a_name] = $a_value;
201  }
+ Here is the caller graph for this function:

◆ addReference()

ilObjectXMLParser::addReference ( int  $a_ref_id,
int  $a_parent_id,
array  $a_time_target 
)
private

Definition at line 203 of file class.ilObjectXMLParser.php.

References $curr_obj.

Referenced by handlerEndTag().

203  : void
204  {
205  $reference['ref_id'] = $a_ref_id;
206  $reference['parent_id'] = $a_parent_id;
207  $reference['time_target'] = $a_time_target;
208 
209  if (isset($reference['time_target']['changeable']) && $reference['time_target']['changeable'] &&
210  !isset($reference['time_target']['suggestion_start'], $reference['time_target']['suggestion_end'])) {
211  throw new ilObjectXMLException(
212  'Missing attributes: "starting_time" and "ending_time" required for attribute "changeable"'
213  );
214  }
215 
216  $this->object_data[$this->curr_obj]['references'][] = $reference;
217  }
Exception class for ObjectXMLWriter and ObjectXMLParser.
+ Here is the caller graph for this function:

◆ getObjectData()

ilObjectXMLParser::getObjectData ( )

Definition at line 36 of file class.ilObjectXMLParser.php.

References $object_data.

36  : array
37  {
38  return $this->object_data;
39  }

◆ handlerBeginTag()

ilObjectXMLParser::handlerBeginTag (   $a_xml_parser,
string  $a_name,
array  $a_attribs 
)
Parameters
XMLParser | resource$a_xml_parser

Definition at line 55 of file class.ilObjectXMLParser.php.

References $curr_obj, ilUtil\__extractId(), addProperty(), and IL_INST_ID.

55  : void
56  {
57  switch ($a_name) {
58  case 'Objects':
59  $this->curr_obj = -1;
60  break;
61 
62  case 'Object':
64 
65  $this->addProperty('type', (string) $a_attribs['type']);
66  if (array_key_exists('obj_id', $a_attribs)) {
67  $this->addProperty(
68  'obj_id',
69  is_numeric($a_attribs['obj_id']) ? (int) $a_attribs["obj_id"] : ilUtil::__extractId(
70  $a_attribs["obj_id"] ?? '',
72  )
73  );
74  }
75  if (isset($a_attribs['offline'])) {
76  $this->addProperty('offline', $a_attribs['offline']);
77  }
78 
79 
80 
81  break;
82 
83  case 'ImportId':
84  case 'LastUpdate':
85  case 'CreateDate':
86  case 'Owner':
87  case 'Description':
88  case 'Title':
89  break;
90 
91  case 'References':
92  $this->time_target = [];
93  $this->ref_id = $a_attribs["ref_id"] ?? 0;
94  $this->parent_id = $a_attribs['parent_id'] ?? 0;
95  break;
96 
97  case 'TimeTarget':
98  $this->time_target['timing_type'] = $a_attribs['type'];
99  break;
100 
101  case 'Timing':
102  if (isset($a_attribs['visibility'])) {
103  $this->time_target['timing_visibility'] = $a_attribs['visibility'];
104  }
105  if (isset($a_attribs['starting_time'])) {
106  $this->time_target['starting_time'] = $a_attribs['starting_time'];
107  }
108  if (isset($a_attribs['ending_time'])) {
109  $this->time_target['ending_time'] = $a_attribs['ending_time'];
110  }
111  if (isset($a_attribs['ending_time']) && isset($a_attribs['starting_time'])) {
112  // Validate timing if both times are present
113  if ($a_attribs['ending_time'] < $a_attribs['starting_time']) {
114  throw new ilObjectXMLException('Starting time must be earlier than ending time.');
115  }
116  }
117  break;
118 
119  case 'Suggestion':
120  $this->time_target['changeable'] = $a_attribs['changeable'] ?? false;
121 
122  if (isset($a_attribs['starting_time'])) {
123  $this->time_target['suggestion_start'] = $a_attribs['starting_time'];
124  }
125  if (isset($a_attribs['ending_time'])) {
126  $this->time_target['suggestion_end'] = $a_attribs['ending_time'];
127  }
128  break;
129  }
130  }
const IL_INST_ID
Definition: constants.php:40
Exception class for ObjectXMLWriter and ObjectXMLParser.
addProperty(string $a_name, $a_value)
static __extractId(string $ilias_id, int $inst_id)
extract ref id from role title, e.g.
+ Here is the call graph for this function:

◆ handlerCharacterData()

ilObjectXMLParser::handlerCharacterData (   $a_xml_parser,
string  $a_data 
)
Parameters
XMLParser | resource$a_xml_parser
string$a_data
Returns
void

Definition at line 183 of file class.ilObjectXMLParser.php.

183  : void
184  {
185  if ($a_data !== "\n") {
186  // Replace multiple tabs with one space
187  $a_data = preg_replace("/\t+/", " ", $a_data);
188 
189  $this->cdata .= $a_data;
190  }
191  }

◆ handlerEndTag()

ilObjectXMLParser::handlerEndTag (   $a_xml_parser,
string  $a_name 
)
Parameters
XMLParser | resource$a_xml_parser
string$a_name
Returns
void

Definition at line 137 of file class.ilObjectXMLParser.php.

References addProperty(), and addReference().

137  : void
138  {
139  switch ($a_name) {
140  case 'Object':
141  case 'Objects':
142  break;
143 
144  case 'Title':
145  $this->addProperty('title', trim($this->cdata));
146  break;
147 
148  case 'Description':
149  $this->addProperty('description', trim($this->cdata));
150  break;
151 
152  case 'Owner':
153  $this->addProperty('owner', trim($this->cdata));
154  break;
155 
156  case 'CreateDate':
157  $this->addProperty('create_date', trim($this->cdata));
158  break;
159 
160  case 'LastUpdate':
161  $this->addProperty('last_update', trim($this->cdata));
162  break;
163 
164  case 'ImportId':
165  $this->addProperty('import_id', trim($this->cdata));
166  break;
167 
168  case 'References':
169  if ($this->ref_id !== 0 && $this->parent_id !== 0) {
170  $this->addReference($this->ref_id, $this->parent_id, $this->time_target);
171  }
172  break;
173  }
174 
175  $this->cdata = '';
176  }
addReference(int $a_ref_id, int $a_parent_id, array $a_time_target)
addProperty(string $a_name, $a_value)
+ Here is the call graph for this function:

◆ setHandlers()

ilObjectXMLParser::setHandlers (   $a_xml_parser)
Parameters
XMLParser | resource$a_xml_parser
Returns
void

Definition at line 45 of file class.ilObjectXMLParser.php.

45  : void
46  {
47  xml_set_object($a_xml_parser, $this);
48  xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
49  xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
50  }

Field Documentation

◆ $cdata

string ilObjectXMLParser::$cdata = ''
private

Definition at line 28 of file class.ilObjectXMLParser.php.

◆ $curr_obj

int ilObjectXMLParser::$curr_obj = 0
private

Definition at line 26 of file class.ilObjectXMLParser.php.

Referenced by addProperty(), addReference(), and handlerBeginTag().

◆ $object_data

array ilObjectXMLParser::$object_data = []

Definition at line 22 of file class.ilObjectXMLParser.php.

Referenced by getObjectData().

◆ $parent_id

int ilObjectXMLParser::$parent_id = 0
private

Definition at line 25 of file class.ilObjectXMLParser.php.

◆ $ref_id

int ilObjectXMLParser::$ref_id = 0
private

Definition at line 24 of file class.ilObjectXMLParser.php.

◆ $time_target

array ilObjectXMLParser::$time_target = []
private

Definition at line 27 of file class.ilObjectXMLParser.php.


The documentation for this class was generated from the following file: