ILIAS  release_8 Revision v8.24
class.ilPCLearningHistory.php
Go to the documentation of this file.
1<?php
2
24{
26 protected ilObjUser $user;
27
28 public function init(): void
29 {
30 global $DIC;
31
32 $this->user = $DIC->user();
33 $this->setType("lhist");
34 }
35
36 public function setNode(php4DOMElement $a_node): void
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
45 public function create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id = ""): void
46 {
47 $this->node = $this->createPageContentNode();
48 $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
49 $this->lhist_node = $this->dom->create_element("LearningHistory");
50 $this->lhist_node = $this->node->append_child($this->lhist_node);
51 }
52
53 public function setFrom(string $a_val): void
54 {
55 $this->lhist_node->set_attribute("From", $a_val);
56 }
57
58 public function getFrom(): string
59 {
60 return (string) $this->lhist_node->get_attribute("From");
61 }
62
63 public function setTo(string $a_val): void
64 {
65 $this->lhist_node->set_attribute("To", $a_val);
66 }
67
68 public function getTo(): string
69 {
70 return (string) $this->lhist_node->get_attribute("To");
71 }
72
73 public function setClasses(array $a_val): void
74 {
75 // delete properties
76 $children = $this->lhist_node->child_nodes();
77 foreach ($children as $iValue) {
78 $this->lhist_node->remove_child($iValue);
79 }
80 // set classes
81 foreach ($a_val as $key => $class) {
82 $prop_node = $this->dom->create_element("LearningHistoryProvider");
83 $prop_node = $this->lhist_node->append_child($prop_node);
84 $prop_node->set_attribute("Name", $class);
85 }
86 }
87
88 public function getClasses(): array
89 {
90 $classes = [];
91 // delete properties
92 $children = $this->lhist_node->child_nodes();
93 foreach ($children as $iValue) {
94 $classes[] = $iValue->get_attribute("Name");
95 }
96 return $classes;
97 }
98
99 public static function afterPageUpdate(
100 ilPageObject $a_page,
101 DOMDocument $a_domdoc,
102 string $a_xml,
103 bool $a_creation
104 ): void {
105 }
106
108 ilPageObject $a_page
109 ): void {
110 }
111
120 ilPageObject $a_page,
121 DOMDocument $a_old_domdoc,
122 string $a_old_xml,
123 int $a_old_nr
124 ): void {
125 }
126
130 public static function getLangVars(): array
131 {
132 return array("ed_insert_learning_history", "pc_learning_history");
133 }
134
136 string $a_output,
137 string $a_mode,
138 bool $a_abstract_only = false
139 ): string {
140 $start = strpos($a_output, "{{{{{LearningHistory");
141 $end = 0;
142 if (is_int($start)) {
143 $end = strpos($a_output, "}}}}}", $start);
144 }
145
146 while ($end > 0) {
147 $param = substr($a_output, $start + 5, $end - $start - 5);
148 $param = str_replace(' xmlns:xhtml="http://www.w3.org/1999/xhtml"', "", $param);
149 $param = explode("#", $param);
150 $from = $param[1];
151 $to = $param[2];
152 $classes = explode(";", $param[3]);
153 $classes = array_map(static function ($i) {
154 return trim($i);
155 }, $classes);
156
157
158 $a_output = substr($a_output, 0, $start) .
159 $this->getPresentation($from, $to, $classes, $a_mode) .
160 substr($a_output, $end + 5);
161
162 if (strlen($a_output) > $start + 5) {
163 $start = strpos($a_output, "{{{{{LearningHistory", $start + 5);
164 } else {
165 $start = false;
166 }
167 $end = 0;
168 if (is_int($start)) {
169 $end = strpos($a_output, "}}}}}", $start);
170 }
171 }
172
173 return $a_output;
174 }
175
181 protected function getPresentation(
182 string $from,
183 string $to,
184 array $classes,
185 string $a_mode
186 ): string {
187 $user_id = 0;
188 if ($a_mode === "preview" || $a_mode === "presentation" || $a_mode === "print") {
189 if ($this->getPage()->getParentType() === "prtf") {
190 $user_id = ilObject::_lookupOwner($this->getPage()->getPortfolioId());
191 }
192 }
193 if ($user_id > 0) {
194 $tpl = new ilTemplate("tpl.pc_lhist.html", true, true, "Services/LearningHistory");
195 $hist_gui = new ilLearningHistoryGUI();
196 $hist_gui->setUserId($user_id);
197 $from_unix = ($from != "")
198 ? (new ilDateTime($from . " 00:00:00", IL_CAL_DATETIME))->get(IL_CAL_UNIX)
199 : null;
200 $to_unix = ($to != "")
201 ? (new ilDateTime($to . " 23:59:59", IL_CAL_DATETIME))->get(IL_CAL_UNIX)
202 : null;
203 $classes = (is_array($classes))
204 ? array_filter($classes, static function ($i): bool {
205 return ($i != "");
206 })
207 : [];
208 if (count($classes) === 0) {
209 $classes = null;
210 }
211 $tpl->setVariable("LHIST", $hist_gui->getEmbeddedHTML($from_unix, $to_unix, $classes, $a_mode));
212 return $tpl->get();
213 }
214
216 }
217}
static return function(ContainerConfigurator $containerConfigurator)
Definition: basic_rector.php:9
const IL_CAL_UNIX
const IL_CAL_DATETIME
const IL_INSERT_AFTER
@classDescription Date and time handling
Learning history main GUI class.
User class.
static _lookupOwner(int $obj_id)
Lookup owner user ID for object ID.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
modifyPageContentPostXsl(string $a_output, string $a_mode, bool $a_abstract_only=false)
Modify page content after xsl.
create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id="")
Create learning history node.
static afterPageUpdate(ilPageObject $a_page, DOMDocument $a_domdoc, string $a_xml, bool $a_creation)
After page has been updated (or created)
static afterPageHistoryEntry(ilPageObject $a_page, DOMDocument $a_old_domdoc, string $a_old_xml, int $a_old_nr)
After page history entry has been created.
static getLangVars()
Get lang vars needed for editing.
setNode(php4DOMElement $a_node)
Set xml node of page content.
getPresentation(string $from, string $to, array $classes, string $a_mode)
Get presentation.
static beforePageDelete(ilPageObject $a_page)
Before page is being deleted.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
createPageContentNode(bool $a_set_this_node=true)
Create page content node (always use this method first when adding a new element)
setType(string $a_type)
Set Type.
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
insertContent(ilPageContent $a_cont_obj, string $a_pos, int $a_mode=IL_INSERT_AFTER, string $a_pcid="", bool $remove_placeholder=true)
insert a content node before/after a sibling or as first child of a parent
special template class to simplify handling of ITX/PEAR
global $DIC
Definition: feed.php:28
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$i
Definition: metadata.php:41
string $key
Consumer key/client ID value.
Definition: System.php:193
$param
Definition: xapitoken.php:46