ILIAS  trunk Revision v12.0_alpha-16-g3e876e53c80
XMLWriter.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ilCondition;
25use SimpleXMLElement;
26
28{
29 protected SimpleXMLElement $xml_root;
30 public function __construct()
31 {
32 $this->xml_root = new SimpleXMLElement('<Conditions></Conditions>');
33 }
34
35 public function write(
37 ): void {
38 $cond_xml = $this->xml_root->addChild('Condition');
39 $cond_xml->addAttribute('object_id', (string) $info->getObjectId());
40 $cond_xml->addAttribute('reference_id', (string) $info->getReferenceId());
41 $cond_xml->addAttribute('object_type', $info->getObjectType());
42 $cond_xml->addAttribute('hide_object_enabled', (string) ((int) $info->getConditionSet()->getHiddenStatus()));
43 $cond_xml->addAttribute('all_obligatory_enabled', (string) ((int) $info->getConditionSet()->getAllObligatory()));
44 $cond_xml->addAttribute('number_of_required_materials', (string) $info->getConditionSet()->getNumObligatory());
45 $p_conds_xml = $cond_xml->addChild('Preconditions');
46 foreach ($info->getConditionSet()->getConditions() as $precondition) {
47 $p_cond_xml = $p_conds_xml->addChild('Precondition');
48 $p_cond_xml->addAttribute('id', (string) $precondition->getId());
49 $p_cond_xml->addAttribute('is_obligatory', (string) ((int) $precondition->getObligatory()));
50 $p_cond_xml->addAttribute('operator', $precondition->getOperator());
51 $p_cond_xml->addAttribute('value', $precondition->getValue() ?? '');
52 $p_cond_trigger_xml = $p_cond_xml->addChild('Trigger');
53 $p_cond_trigger_xml->addAttribute('ref_id', (string) $precondition->getTrigger()->getRefId());
54 $p_cond_trigger_xml->addAttribute('obj_id', (string) $precondition->getTrigger()->getObjId());
55 $p_cond_trigger_xml->addAttribute('type', $precondition->getTrigger()->getType());
56 }
57 }
58
59 public function writeAll(
60 InfoCollection $infos
61 ): void {
62 foreach ($infos as $info) {
63 $this->write($info);
64 }
65 }
66
67 public function __toString(): string
68 {
69 return trim(str_replace('<?xml version="1.0"?>', '', $this->xml_root->asXML()));
70 }
71}
writeAll(InfoCollection $infos)
Definition: XMLWriter.php:59
Condition set Note: This object currently focuses on repository objects as targets.
Condition class.
$info
Definition: entry_point.php:21