ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilPCLearningHistory.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5
14{
18 protected $user;
19
20 public $dom;
21
25 public function init()
26 {
27 global $DIC;
28
29 $this->user = $DIC->user();
30 $this->setType("lhist");
31 }
32
36 public function setNode($a_node)
37 {
38 parent::setNode($a_node); // this is the PageContent node
39 $this->lhist_node = $a_node->first_child(); // this is the skill node
40 }
41
49 public function create(ilPageObject $a_pg_obj, string $a_hier_id, $a_pc_id = "")
50 {
51 $this->node = $this->createPageContentNode();
52 $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
53 $this->lhist_node = $this->dom->create_element("LearningHistory");
54 $this->lhist_node = $this->node->append_child($this->lhist_node);
55 }
56
62 public function setFrom($a_val)
63 {
64 $this->lhist_node->set_attribute("From", $a_val);
65 }
66
72 public function getFrom()
73 {
74 return $this->lhist_node->get_attribute("From");
75 }
76
82 public function setTo($a_val)
83 {
84 $this->lhist_node->set_attribute("To", $a_val);
85 }
86
92 public function getTo()
93 {
94 return $this->lhist_node->get_attribute("To");
95 }
96
102 public function setClasses($a_val)
103 {
104 // delete properties
105 $children = $this->lhist_node->child_nodes();
106 for ($i = 0; $i < count($children); $i++) {
107 $this->lhist_node->remove_child($children[$i]);
108 }
109 // set classes
110 foreach ($a_val as $key => $class) {
111 $prop_node = $this->dom->create_element("LearningHistoryProvider");
112 $prop_node = $this->lhist_node->append_child($prop_node);
113 $prop_node->set_attribute("Name", $class);
114 }
115 }
116
122 public function getClasses()
123 {
124 $classes = [];
125 // delete properties
126 $children = $this->lhist_node->child_nodes();
127 for ($i = 0; $i < count($children); $i++) {
128 $classes[] = $children[$i]->get_attribute("Name");
129 }
130 return $classes;
131 }
132
133
142 public static function afterPageUpdate($a_page, DOMDocument $a_domdoc, $a_xml, $a_creation)
143 {
144 }
145
151 public static function beforePageDelete($a_page)
152 {
153 }
154
163 public static function afterPageHistoryEntry($a_page, DOMDocument $a_old_domdoc, $a_old_xml, $a_old_nr)
164 {
165 }
166
171 public static function getLangVars()
172 {
173 return array("ed_insert_learning_history", "pc_learning_history");
174 }
175
179 public function modifyPageContentPostXsl($a_html, $a_mode, $a_abstract_only = false)
180 {
182 $ilPluginAdmin = $this->plugin_admin;
183
184 $start = strpos($a_html, "{{{{{LearningHistory");
185 if (is_int($start)) {
186 $end = strpos($a_html, "}}}}}", $start);
187 }
188
189 while ($end > 0) {
190 $param = substr($a_html, $start + 5, $end - $start - 5);
191 $param = str_replace(' xmlns:xhtml="http://www.w3.org/1999/xhtml"', "", $param);
192 $param = explode("#", $param);
193 $from = $param[1];
194 $to = $param[2];
195 $classes = explode(";", $param[3]);
196 $classes = array_map(function ($i) {
197 return trim($i);
198 }, $classes);
199
200
201 $a_html = substr($a_html, 0, $start) .
202 $this->getPresentation($from, $to, $classes, $a_mode) .
203 substr($a_html, $end + 5);
204
205 if (strlen($a_html) > $start + 5) {
206 $start = strpos($a_html, "{{{{{LearningHistory", $start + 5);
207 } else {
208 $start = false;
209 }
210 $end = 0;
211 if (is_int($start)) {
212 $end = strpos($a_html, "}}}}}", $start);
213 }
214 }
215
216 return $a_html;
217 }
218
229 protected function getPresentation($from, $to, $classes, $a_mode) : string
230 {
231 if ($a_mode == "preview" || $a_mode == "presentation" || $a_mode == "print") {
232 if ($this->getPage()->getParentType() == "prtf") {
233 $user_id = ilObject::_lookupOwner($this->getPage()->getPortfolioId());
234 }
235 }
236 if ($user_id > 0) {
237 $tpl = new ilTemplate("tpl.pc_lhist.html", true, true, "Services/LearningHistory");
238 $hist_gui = new ilLearningHistoryGUI();
239 $hist_gui->setUserId($user_id);
240 $from_unix = ($from != "")
241 ? (new ilDateTime($from . " 00:00:00", IL_CAL_DATETIME))->get(IL_CAL_UNIX)
242 : null;
243 $to_unix = ($to != "")
244 ? (new ilDateTime($to . " 23:59:59", IL_CAL_DATETIME))->get(IL_CAL_UNIX)
245 : null;
246 $classes = (is_array($classes))
247 ? array_filter($classes, function ($i) {
248 return ($i != "");
249 })
250 : null;
251 if (count($classes) == 0) {
252 $classes = null;
253 }
254 $tpl->setVariable("LHIST", $hist_gui->getEmbeddedHtml($from_unix, $to_unix, $classes, $a_mode));
255 return $tpl->get();
256 }
257
258 return ilPCLearningHistoryGUI::getPlaceHolderPresentation();
259 }
260}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
const IL_CAL_DATETIME
const IL_INSERT_AFTER
@classDescription Date and time handling
Learning history main GUI class.
static _lookupOwner($a_id)
lookup object owner
Learning history page content.
static beforePageDelete($a_page)
Before page is being deleted.
create(ilPageObject $a_pg_obj, string $a_hier_id, $a_pc_id="")
Create learning history node.
init()
Init page content component.
static getLangVars()
Get lang vars needed for editing.
static afterPageHistoryEntry($a_page, DOMDocument $a_old_domdoc, $a_old_xml, $a_old_nr)
After page history entry has been created.
modifyPageContentPostXsl($a_html, $a_mode, $a_abstract_only=false)
@inheritDoc
setClasses($a_val)
Set classes.
static afterPageUpdate($a_page, DOMDocument $a_domdoc, $a_xml, $a_creation)
After page has been updated (or created)
getPresentation($from, $to, $classes, $a_mode)
Get presentation.
Class ilPageContent.
createPageContentNode($a_set_this_node=true)
Create page content node (always use this method first when adding a new element)
setType($a_type)
Set Type.
Class ilPageObject.
insertContent(&$a_cont_obj, $a_pos, $a_mode=IL_INSERT_AFTER, $a_pcid="")
insert a content node before/after a sibling or as first child of a parent
special template class to simplify handling of ITX/PEAR
$i
Definition: metadata.php:24
$lng
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
$DIC
Definition: xapitoken.php:46
$param
Definition: xapitoken.php:31