ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilLearningSequenceXMLWriter.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 {
24  protected ilSetting $settings;
28 
29  public function __construct(
30  ilObjLearningSequence $ls_object,
31  ilSetting $settings,
32  ilLPObjSettings $lp_settings,
33  ilRbacReview $rbac_review
34  ) {
36  $this->ls_object = $ls_object;
37  $this->settings = $settings;
38  $this->lp_settings = $lp_settings;
39  $this->rbac_review = $rbac_review;
40  $this->ls_settings = $ls_object->getLSSettings();
41  }
42 
43  public function getXml(): string
44  {
45  return $this->xmlDumpMem(false);
46  }
47 
48  public function start(): void
49  {
50  $this->writeHeader();
51  $this->writeLearningSequence();
52  $this->writeTitle();
53  $this->writeDescription();
54  $this->writeOwner();
55  $this->writeLSItems();
56  $this->writeSettings();
57  $this->writeLPSettings();
58  $this->writeFooter();
59  }
60 
61  protected function writeHeader(): void
62  {
63  $this->xmlSetDtdDef(
64  "<!DOCTYPE learning sequence PUBLIC \"-//ILIAS//DTD LearningSequence//EN\" \"" .
65  ILIAS_HTTP_PATH . "/xml/ilias_lso_5_4.dtd\">"
66  );
67 
68  $this->xmlSetGenCmt(
69  "Export of ILIAS LearningSequence " .
70  $this->ls_object->getId() .
71  " of installation " .
72  $this->settings->get("inst_id") .
73  "."
74  );
75  }
76 
77  protected function writeLearningSequence(): void
78  {
79  $att["ref_id"] = $this->ls_object->getRefId();
80 
81  $this->xmlStartTag("lso", $att);
82  }
83 
84  protected function writeTitle(): void
85  {
86  $this->xmlElement("title", null, $this->ls_object->getTitle());
87  }
88 
89  protected function writeDescription(): void
90  {
91  $this->xmlElement("description", null, $this->ls_object->getDescription());
92  }
93 
94  protected function writeOwner(): void
95  {
96  $att['id'] = 'il_' . $this->settings->get("inst_id") . '_usr_' . $this->ls_object->getOwner();
97  $this->xmlElement('owner', $att);
98  }
99 
100  protected function writeLSItems(): void
101  {
102  $ls_items = $this->ls_object->getLSItems();
103 
104  $this->xmlStartTag("ls_items");
105 
106  foreach ($ls_items as $ls_item) {
107  $post_condition = $ls_item->getPostCondition();
108  $att["id"] = $ls_item->getRefId();
109  $this->xmlStartTag("ls_item", $att);
110 
111  $this->xmlElement("ls_item_pc_ref_id", null, $post_condition->getRefId());
112  $this->xmlElement("ls_item_pc_condition_type", null, $post_condition->getConditionOperator());
113  $this->xmlElement("ls_item_pc_value", null, $post_condition->getValue());
114  $this->xmlElement("ls_item_type", null, $ls_item->getType());
115  $this->xmlElement("ls_item_title", null, $ls_item->getTitle());
116  $this->xmlElement("ls_item_description", null, $ls_item->getDescription());
117  $this->xmlElement("ls_item_icon_path", null, $ls_item->getIconPath());
118  $this->xmlElement("ls_item_is_online", null, (string) $ls_item->isOnline());
119  $this->xmlElement("ls_item_order_number", null, (string) $ls_item->getOrderNumber());
120 
121  $this->xmlEndTag("ls_item");
122  }
123 
124  $this->xmlEndTag("ls_items");
125  }
126 
127  protected function writeSettings(): void
128  {
129  $abstract_img = $this->ls_settings->getAbstractImage();
130  $extro_img = $this->ls_settings->getExtroImage();
131 
132  $this->xmlElement("abstract", null, base64_encode($this->ls_settings->getAbstract()));
133  $this->xmlElement("extro", null, base64_encode($this->ls_settings->getExtro()));
134  $this->xmlElement("members_gallery", null, $this->ls_settings->getMembersGallery());
135  $this->xmlElement("abstract_img", null, $abstract_img);
136  $this->xmlElement("extro_img", null, $extro_img);
137  $this->xmlElement("abstract_img_data", null, $this->encodeImage($abstract_img));
138  $this->xmlElement("extro_img_data", null, $this->encodeImage($extro_img));
139  }
140 
141  protected function writeLPSettings(): void
142  {
143  if (!$this->settings->get("enable_tracking")) {
144  return;
145  }
146 
147  $collection = ilLPCollection::getInstanceByMode(
148  $this->ls_object->getId(),
149  $this->lp_settings->getMode()
150  );
151 
152  if (!is_null($collection)) {
153  $items = $collection->getItems();
154 
155  foreach ($items as $item) {
156  $this->xmlElement("lp_item_ref_id", null, $item);
157  }
158  }
159 
160  $this->xmlElement("lp_type", null, $this->lp_settings->getObjType());
161  $this->xmlElement("lp_mode", null, $this->lp_settings->getMode());
162  }
163 
164  protected function encodeImage(string $path = null): string
165  {
166  if ($path == "") {
167  return "";
168  }
169 
170  return base64_encode(file_get_contents($path));
171  }
172 
173  protected function writeFooter(): void
174  {
175  $this->xmlEndTag('lso');
176  }
177 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlSetGenCmt(string $genCmt)
Sets generated comment.
$path
Definition: ltiservices.php:32
xmlEndTag(string $tag)
Writes an endtag.
static getInstanceByMode(int $a_obj_id, int $a_mode)
xmlSetDtdDef(string $dtdDef)
Sets dtd definition.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
xmlDumpMem(bool $format=true)
Returns xml document from memory.
__construct(ilObjLearningSequence $ls_object, ilSetting $settings, ilLPObjSettings $lp_settings, ilRbacReview $rbac_review)