ILIAS  trunk Revision v11.0_alpha-1731-gff9cd7e2bd3
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilPCLearningHistory.php
Go to the documentation of this file.
1 <?php
2 
24 {
25  protected ilObjUser $user;
26 
27  public function init(): void
28  {
29  global $DIC;
30 
31  $this->user = $DIC->user();
32  $this->setType("lhist");
33  }
34 
38  public function create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id = ""): void
39  {
40  $this->createPageContentNode();
41  $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
42  $lhist_node = $this->dom_doc->createElement("LearningHistory");
43  $lhist_node = $this->getDomNode()->appendChild($lhist_node);
44  }
45 
46  public function setFrom(string $a_val): void
47  {
48  $this->getChildNode()->setAttribute("From", $a_val);
49  }
50 
51  public function getFrom(): string
52  {
53  return (string) $this->getChildNode()->getAttribute("From");
54  }
55 
56  public function setTo(string $a_val): void
57  {
58  $this->getChildNode()->setAttribute("To", $a_val);
59  }
60 
61  public function getTo(): string
62  {
63  return (string) $this->getChildNode()->getAttribute("To");
64  }
65 
66  public function setClasses(array $a_val): void
67  {
68  // delete properties
69  $children = $this->getChildNode()->childNodes;
70  foreach ($children as $iValue) {
71  $this->getChildNode()->removeChild($iValue);
72  }
73  // set classes
74  foreach ($a_val as $key => $class) {
75  $prop_node = $this->dom_doc->createElement("LearningHistoryProvider");
76  $prop_node = $this->getChildNode()->appendChild($prop_node);
77  $prop_node->setAttribute("Name", $class);
78  }
79  }
80 
81  public function getClasses(): array
82  {
83  $classes = [];
84  // delete properties
85  $children = $this->getChildNode()->childNodes;
86  foreach ($children as $iValue) {
87  $classes[] = $iValue->getAttribute("Name");
88  }
89  return $classes;
90  }
91 
92  public static function afterPageUpdate(
93  ilPageObject $a_page,
94  DOMDocument $a_domdoc,
95  string $a_xml,
96  bool $a_creation
97  ): void {
98  }
99 
100  public static function beforePageDelete(
101  ilPageObject $a_page
102  ): void {
103  }
104 
112  public static function afterPageHistoryEntry(
113  ilPageObject $a_page,
114  DOMDocument $a_old_domdoc,
115  string $a_old_xml,
116  int $a_old_nr
117  ): void {
118  }
119 
123  public static function getLangVars(): array
124  {
125  return array("ed_insert_learning_history", "pc_learning_history");
126  }
127 
128  public function modifyPageContentPostXsl(
129  string $a_output,
130  string $a_mode,
131  bool $a_abstract_only = false
132  ): string {
133  $start = strpos($a_output, "{{{{{LearningHistory");
134  $end = 0;
135  if (is_int($start)) {
136  $end = strpos($a_output, "}}}}}", $start);
137  }
138 
139  while ($end > 0) {
140  $param = substr($a_output, $start + 5, $end - $start - 5);
141  $param = str_replace(' xmlns:xhtml="http://www.w3.org/1999/xhtml"', "", $param);
142  $param = explode("#", $param);
143  $from = $param[1];
144  $to = $param[2];
145  $classes = explode(";", $param[3]);
146  $classes = array_map(static function ($i) {
147  return trim($i);
148  }, $classes);
149 
150 
151  $a_output = substr($a_output, 0, $start) .
152  $this->getPresentation($from, $to, $classes, $a_mode) .
153  substr($a_output, $end + 5);
154 
155  if (strlen($a_output) > $start + 5) {
156  $start = strpos($a_output, "{{{{{LearningHistory", $start + 5);
157  } else {
158  $start = false;
159  }
160  $end = 0;
161  if (is_int($start)) {
162  $end = strpos($a_output, "}}}}}", $start);
163  }
164  }
165 
166  return $a_output;
167  }
168 
174  protected function getPresentation(
175  string $from,
176  string $to,
177  array $classes,
178  string $a_mode
179  ): string {
180  $user_id = 0;
181  if ($a_mode === "preview" || $a_mode === "presentation" || $a_mode === "print") {
182  if ($this->getPage()->getParentType() === "prtf") {
183  $user_id = ilObject::_lookupOwner($this->getPage()->getPortfolioId());
184  }
185  }
186  if ($user_id > 0) {
187  $tpl = new ilTemplate("tpl.pc_lhist.html", true, true, "components/ILIAS/LearningHistory");
188  $hist_gui = new ilLearningHistoryGUI();
189  $hist_gui->setUserId($user_id);
190  $from_unix = ($from != "")
191  ? (new ilDateTime($from . " 00:00:00", IL_CAL_DATETIME))->get(IL_CAL_UNIX)
192  : null;
193  $to_unix = ($to != "")
194  ? (new ilDateTime($to . " 23:59:59", IL_CAL_DATETIME))->get(IL_CAL_UNIX)
195  : null;
196  $classes = (is_array($classes))
197  ? array_filter($classes, static function ($i): bool {
198  return ($i != "");
199  })
200  : [];
201  if (count($classes) === 0) {
202  $classes = null;
203  }
204  $tpl->setVariable("LHIST", $hist_gui->getEmbeddedHTML($from_unix, $to_unix, $classes, $a_mode));
205  return $tpl->get();
206  }
207 
209  }
210 }
static beforePageDelete(ilPageObject $a_page)
setType(string $a_type)
Set Type.
const IL_CAL_DATETIME
getPresentation(string $from, string $to, array $classes, string $a_mode)
Get presentation.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupOwner(int $obj_id)
Lookup owner user ID for object ID.
const IL_CAL_UNIX
Content object of ilPageObject (see ILIAS DTD).
static getLangVars()
Get lang vars needed for editing.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id="")
Create learning history node.
static afterPageHistoryEntry(ilPageObject $a_page, DOMDocument $a_old_domdoc, string $a_old_xml, int $a_old_nr)
After page history entry has been created.
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
$param
Definition: xapitoken.php:46
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
global $DIC
Definition: shib_login.php:22
static afterPageUpdate(ilPageObject $a_page, DOMDocument $a_domdoc, string $a_xml, bool $a_creation)
const IL_INSERT_AFTER
createPageContentNode(bool $a_set_this_node=true)
Create page content node (always use this method first when adding a new element) ...
modifyPageContentPostXsl(string $a_output, string $a_mode, bool $a_abstract_only=false)