ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilLearningSequenceXMLWriter.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
9 {
10  public function __construct(
11  ilObjLearningSequence $ls_object,
12  ilSetting $il_settings,
13  ilLPObjSettings $lp_settings,
14  ilRbacReview $rbac_review
15  ) {
16  $this->ls_object = $ls_object;
17  $this->il_settings = $il_settings;
18  $this->settings = $ls_object->getLSSettings();
19  $this->lp_settings = $lp_settings;
20  $this->rbac_review = $rbac_review;
21  }
22 
23  public function getXml()
24  {
25  return $this->xmlDumpMem(false);
26  }
27 
28  public function start()
29  {
30  $this->writeHeader();
31  $this->writeLearningSequence();
32  $this->writeTitle();
33  $this->writeDescription();
34  $this->writeOwner();
35  $this->writeLSItems();
36  $this->writeSettings();
37  $this->writeLPSettings();
38  $this->writeFooter();
39  }
40 
41  protected function writeHeader()
42  {
43  $this->xmlSetDtdDef(
44  "<!DOCTYPE learning sequence PUBLIC \"-//ILIAS//DTD LearningSequence//EN\" \"" .
45  ILIAS_HTTP_PATH . "/xml/ilias_lso_5_4.dtd\">"
46  );
47 
48  $this->xmlSetGenCmt(
49  "Export of ILIAS LearningSequence " .
50  $this->ls_object->getId() .
51  " of installation " .
52  $this->il_settings->get("inst_id") .
53  "."
54  );
55  }
56 
57  protected function writeLearningSequence()
58  {
59  $att["ref_id"] = $this->ls_object->getRefId();
60 
61  $this->xmlStartTag("lso", $att);
62  }
63 
64  protected function writeTitle()
65  {
66  $this->xmlElement("title", null, $this->ls_object->getTitle());
67  }
68 
69  protected function writeDescription()
70  {
71  $this->xmlElement("description", null, $this->ls_object->getDescription());
72  }
73 
74  protected function writeOwner()
75  {
76  $att['id'] = 'il_' . $this->il_settings->get("inst_id") . '_usr_' . $this->ls_object->getOwner();
77  $this->xmlElement('owner', $att);
78  }
79 
80  protected function writeLSItems()
81  {
82  $ls_items = $this->ls_object->getLSItems();
83 
84  $this->xmlStartTag("ls_items");
85 
86  foreach ($ls_items as $ls_item) {
87  $post_condition = $ls_item->getPostCondition();
88  $att["id"] = $ls_item->getRefId();
89  $this->xmlStartTag("ls_item", $att);
90 
91  $this->xmlElement("ls_item_pc_ref_id", null, $post_condition->getRefId());
92  $this->xmlElement("ls_item_pc_condition_type", null, $post_condition->getConditionOperator());
93  $this->xmlElement("ls_item_pc_value", null, $post_condition->getValue());
94  $this->xmlElement("ls_item_type", null, $ls_item->getType());
95  $this->xmlElement("ls_item_title", null, $ls_item->getTitle());
96  $this->xmlElement("ls_item_description", null, $ls_item->getDescription());
97  $this->xmlElement("ls_item_icon_path", null, $ls_item->getIconPath());
98  $this->xmlElement("ls_item_is_online", null, (string) $ls_item->isOnline());
99  $this->xmlElement("ls_item_order_number", null, (string) $ls_item->getOrderNumber());
100 
101  $this->xmlEndTag("ls_item");
102  }
103 
104  $this->xmlEndTag("ls_items");
105  }
106 
107  protected function writeSettings()
108  {
109  $abstract_img = $this->settings->getAbstractImage();
110  $extro_img = $this->settings->getExtroImage();
111 
112  $this->xmlElement("abstract", null, base64_encode($this->settings->getAbstract()));
113  $this->xmlElement("extro", null, base64_encode($this->settings->getExtro()));
114  $this->xmlElement("members_gallery", null, $this->settings->getMembersGallery());
115  $this->xmlElement("abstract_img", null, $abstract_img);
116  $this->xmlElement("extro_img", null, $extro_img);
117  $this->xmlElement("abstract_img_data", null, $this->encodeImage($abstract_img));
118  $this->xmlElement("extro_img_data", null, $this->encodeImage($extro_img));
119  }
120 
121  protected function writeLPSettings()
122  {
123  if (!$this->il_settings->get("enable_tracking")) {
124  return;
125  }
126 
127  $collection = ilLPCollection::getInstanceByMode(
128  $this->ls_object->getId(),
129  (int) $this->lp_settings->getMode()
130  );
131 
132  if (!is_null($collection)) {
133  $items = $collection->getItems();
134 
135  foreach ($items as $item) {
136  $this->xmlElement("lp_item_ref_id", null, $item);
137  }
138  }
139 
140  $this->xmlElement("lp_type", null, $this->lp_settings->getObjType());
141  $this->xmlElement("lp_mode", null, $this->lp_settings->getMode());
142  }
143 
144  protected function encodeImage(string $path = null) : string
145  {
146  if (is_null($path) || $path == "") {
147  return "";
148  }
149 
150  return base64_encode(file_get_contents($path));
151  }
152 
153  protected function writeFooter()
154  {
155  $this->xmlEndTag('lso');
156  }
157 }
$path
Definition: aliased.php:25
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.
xmlSetGenCmt($genCmt)
Sets generated comment.
settings()
Definition: settings.php:2
xmlSetDtdDef($dtdDef)
Sets dtd definition.
Class ilObjLearningSequence.
xmlDumpMem($format=true)
Returns xml document from memory.
XML writer class.
static getInstanceByMode($a_obj_id, $a_mode)
xmlEndTag($tag)
Writes an endtag.
__construct(ilObjLearningSequence $ls_object, ilSetting $il_settings, ilLPObjSettings $lp_settings, ilRbacReview $rbac_review)
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
class ilRbacReview Contains Review functions of core Rbac.