ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLearningSequenceXMLWriter.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 public const TAG_LSO = 'LearningSequence';
24 public const TAG_LSITEMS = 'LSItems';
25 public const TAG_LSITEM = 'LSItem';
26 public const TAG_MEMBERSGALLERY = 'MembersGallery';
27 public const TAG_CONDITION = 'Condition';
28 public const TAG_LPSETTING = 'LPSetting';
29 public const TAG_LPREFID = 'LPRefId';
30 public const TAG_TITLE = 'title';
31 public const TAG_DESCRIPTION = 'description';
32 public const TAG_CONTAINERSETTING = 'ContainerSetting';
33
35
36 public function __construct(
37 protected ilObjLearningSequence $ls_object,
38 protected ilSetting $settings,
39 protected ilLPObjSettings $lp_settings
40 ) {
42 $this->ls_settings = $ls_object->getLSSettings();
43 }
44
45 public function getXml(): string
46 {
47 return $this->xmlDumpMem(false);
48 }
49
50 public function start(): void
51 {
52 $this->writeHeader();
53 $this->writeLearningSequence();
54 $this->writeLSItems();
55 $this->writeFooter();
56 }
57
58 protected function writeHeader(): void
59 {
60 $this->xmlSetDtdDef(
61 "<!DOCTYPE learning sequence PUBLIC \"-//ILIAS//DTD LearningSequence//EN\" \"" .
62 ILIAS_HTTP_PATH . "/xml/ilias_lso_9_0.dtd\">"
63 );
64
65 $this->xmlSetGenCmt(
66 "Export of ILIAS LearningSequence " .
67 $this->ls_object->getId() .
68 " of installation " .
69 $this->settings->get("inst_id") .
70 "."
71 );
72 }
73
74 protected function writeLearningSequence(): void
75 {
76 $attributes = [
77 'ref_id' => $this->ls_object->getRefId(),
78 'members_gallery' => $this->ls_settings->getMembersGallery() ? 'true' : 'false'
79 ];
80 $this->xmlStartTag(self::TAG_LSO, $attributes);
81
82 $this->xmlElement(self::TAG_TITLE, null, $this->ls_object->getTitle());
83 if ($desc = $this->ls_object->getDescription()) {
84 $this->xmlElement(self::TAG_DESCRIPTION, null, $desc);
85 }
86
87 $this->writeLPSettings();
88 \ilContainer::_exportContainerSettings($this, $this->ls_object->getId());
89 }
90
91 protected function writeLPSettings(): void
92 {
93 $type = $this->lp_settings->getObjType();
94 $mode = $this->lp_settings->getMode();
95 $this->xmlStartTag(
96 self::TAG_LPSETTING,
97 [
98 'type' => $type,
99 'mode' => $mode
100 ]
101 );
103 $this->ls_object->getId(),
104 $mode
105 );
106 if (!is_null($collection)) {
107 $items = $collection->getItems();
108 foreach ($items as $item) {
109 $this->xmlElement(self::TAG_LPREFID, null, $item);
110 }
111 }
112 $this->xmlEndTag(self::TAG_LPSETTING);
113 }
114
115 protected function writeLSItems(): void
116 {
117 $this->xmlStartTag(self::TAG_LSITEMS);
118
119 $ls_items = $this->ls_object->getLSItems();
120 foreach ($ls_items as $ls_item) {
121 $post_condition = $ls_item->getPostCondition();
122
123 $this->xmlStartTag(
124 self::TAG_LSITEM,
125 [
126 'obj_id' => \ilObject::_lookupObjectId($ls_item->getRefId()),
127 'ref_id' => $ls_item->getRefId()
128 ]
129 );
130
131 $this->xmlElement(
132 self::TAG_CONDITION,
133 ['type' => $post_condition->getConditionOperator()],
134 $post_condition->getValue()
135 );
136
137 $this->xmlEndTag(self::TAG_LSITEM);
138 }
139
140 $this->xmlEndTag(self::TAG_LSITEMS);
141 }
142
143 protected function writeFooter(): void
144 {
145 $this->xmlEndTag(self::TAG_LSO);
146 }
147}
static _exportContainerSettings(ilXmlWriter $a_xml, int $a_obj_id)
static getInstanceByMode(int $a_obj_id, int $a_mode)
Settings for an LSO (like abstract, extro)
__construct(protected ilObjLearningSequence $ls_object, protected ilSetting $settings, protected ilLPObjSettings $lp_settings)
static _lookupObjectId(int $ref_id)
ILIAS Setting Class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlSetGenCmt(string $genCmt)
Sets generated comment.
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
xmlEndTag(string $tag)
Writes an endtag.
xmlSetDtdDef(string $dtdDef)
Sets dtd definition.
xmlDumpMem(bool $format=true)
Returns xml document from memory.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc