ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
182  public function modifyPageContentPostXsl($a_html, $a_mode)
183  {
184  $lng = $this->lng;
185  $ilPluginAdmin = $this->plugin_admin;
186 
187  $start = strpos($a_html, "{{{{{LearningHistory");
188  if (is_int($start)) {
189  $end = strpos($a_html, "}}}}}", $start);
190  }
191 
192  while ($end > 0) {
193  $param = substr($a_html, $start + 5, $end - $start - 5);
194  $param = str_replace(' xmlns:xhtml="http://www.w3.org/1999/xhtml"', "", $param);
195  $param = explode("#", $param);
196  $from = $param[1];
197  $to = $param[2];
198  $classes = explode(";", $param[3]);
199  $classes = array_map(function ($i) {
200  return trim($i);
201  }, $classes);
202 
203 
204  $a_html = substr($a_html, 0, $start) .
205  $this->getPresentation($from, $to, $classes, $a_mode) .
206  substr($a_html, $end + 5);
207 
208  if (strlen($a_html) > $start + 5) {
209  $start = strpos($a_html, "{{{{{LearningHistory", $start + 5);
210  } else {
211  $start = false;
212  }
213  $end = 0;
214  if (is_int($start)) {
215  $end = strpos($a_html, "}}}}}", $start);
216  }
217  }
218 
219  return $a_html;
220  }
221 
232  protected function getPresentation($from, $to, $classes, $a_mode) : string
233  {
234  if ($a_mode == "preview" || $a_mode == "presentation" || $a_mode == "print") {
235  if ($this->getPage()->getParentType() == "prtf") {
236  $user_id = ilObject::_lookupOwner($this->getPage()->getPortfolioId());
237  }
238  }
239  if ($user_id > 0) {
240  $tpl = new ilTemplate("tpl.pc_lhist.html", true, true, "Services/LearningHistory");
241  $hist_gui = new ilLearningHistoryGUI();
242  $hist_gui->setUserId($user_id);
243  $from_unix = ($from != "")
244  ? (new ilDateTime($from . " 00:00:00", IL_CAL_DATETIME))->get(IL_CAL_UNIX)
245  : null;
246  $to_unix = ($to != "")
247  ? (new ilDateTime($to . " 23:59:59", IL_CAL_DATETIME))->get(IL_CAL_UNIX)
248  : null;
249  $classes = (is_array($classes))
250  ? array_filter($classes, function ($i) {
251  return ($i != "");
252  })
253  : null;
254  if (count($classes) == 0) {
255  $classes = null;
256  }
257  $tpl->setVariable("LHIST", $hist_gui->getEmbeddedHtml($from_unix, $to_unix, $classes, $a_mode));
258  return $tpl->get();
259  }
260 
261  return ilPCLearningHistoryGUI::getPlaceHolderPresentation();
262  }
263 }
const IL_CAL_DATETIME
getPresentation($from, $to, $classes, $a_mode)
Get presentation.
create(ilPageObject $a_pg_obj, string $a_hier_id, $a_pc_id="")
Create learning history node.
global $DIC
Definition: saml.php:7
Learning history page content.
$tpl
Definition: ilias.php:10
Learning history main GUI class.
static afterPageUpdate($a_page, DOMDocument $a_domdoc, $a_xml, $a_creation)
After page has been updated (or created)
setType($a_type)
Set Type.
$from
static beforePageDelete($a_page)
Before page is being deleted.
const IL_CAL_UNIX
user()
Definition: user.php:4
Class ilPageContent.
$start
Definition: bench.php:8
static getLangVars()
Get lang vars needed for editing.
init()
Init page content component.
$lng
static afterPageHistoryEntry($a_page, DOMDocument $a_old_domdoc, $a_old_xml, $a_old_nr)
After page history entry has been created.
special template class to simplify handling of ITX/PEAR
Class ilPageObject.
modifyPageContentPostXsl($a_html, $a_mode)
Modify page content after xsl.
Date and time handling
static _lookupOwner($a_id)
lookup object owner
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
const IL_INSERT_AFTER
createPageContentNode($a_set_this_node=true)
Create page content node (always use this method first when adding a new element) ...
setClasses($a_val)
Set classes.
$i
Definition: disco.tpl.php:19
$key
Definition: croninfo.php:18