ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLearningHistoryGUI.php
Go to the documentation of this file.
1<?php
2
20
26{
27 public const TAB_ID_LEARNING_HISTORY = 'lhist_learning_history';
28 public const TAB_ID_MY_CERTIFICATES = 'certificates';
29 public const MAX = 50;
30 protected \ILIAS\HTTP\Services $http;
31 protected ?int $to;
32 protected ?int $from;
33 protected int $user_id;
36 protected ilCtrl $ctrl;
38 protected ilLanguage $lng;
39 protected \ILIAS\DI\UIServices $ui;
41 protected ilTabsGUI $tabs;
42 protected bool $show_more = false;
43 protected int $last_ts = 0;
44
45 public function __construct()
46 {
47 global $DIC;
48
49 $this->ctrl = $DIC->ctrl();
50
51 $this->lhist_service = $DIC->learningHistory();
52 $this->ui = $this->lhist_service->ui();
53 $this->main_tpl = $this->ui->mainTemplate();
54 $this->lng = $this->lhist_service->language();
55 $this->access = $this->lhist_service->access();
56 $this->tabs = $DIC->tabs();
57
58 $this->lng->loadLanguageModule("lhist");
59
60 $this->user_id = $this->lhist_service->user()->getId();
61
62 $this->certificateSettings = new ilSetting("certificate");
63
64 $request = $this->lhist_service->request();
65 $to = $request->getToTS();
66 $this->from = null;
67 $this->to = ($to > 0)
68 ? $to
69 : null;
70
71 $this->main_tpl->addJavaScript("assets/js/LearningHistory.js");
72 $this->http = $DIC->http();
73 }
74
75 public function setUserId(int $user_id): void
76 {
77 $this->user_id = $user_id;
78 }
79
80 public function executeCommand(): void
81 {
83
84 $next_class = $ctrl->getNextClass($this);
85 $cmd = $ctrl->getCmd("show");
86
87 switch ($next_class) {
88 default:
89 if (in_array($cmd, array("show", "renderAsync"))) {
90 $this->$cmd();
91 }
92 }
93 }
94
95 protected function show(): void
96 {
99 $f = $this->ui->factory();
100 $renderer = $this->ui->renderer();
101
102 $html = $this->getHistoryHtml($this->from, $this->to);
103
104 if ($html !== "") {
105 $main_tpl->setContent($html);
106 } else {
108 $renderer->render(
109 $f->messageBox()->info($lng->txt("lhist_no_entries"))
110 )
111 );
112 }
113 }
114
115 protected function renderAsync(): void
116 {
117 $response["timeline"] = $this->renderTimeline($this->from, $this->to);
118 $response["more"] = $this->show_more ? $this->renderButton() : "";
119 $this->send(json_encode($response, JSON_THROW_ON_ERROR));
120 }
121
126 protected function send(string $output): void
127 {
128 $this->http->saveResponse($this->http->response()->withBody(
129 Streams::ofString($output)
130 ));
131 $this->http->sendResponse();
132 $this->http->close();
133 }
134
138 public function getEmbeddedHTML(
139 ?int $from = null,
140 ?int $to = null,
141 ?array $classes = null,
142 ?string $a_mode = null
143 ): string {
144 return $this->ctrl->getHTML($this, ["from" => $from, "to" => $to, "classes" => $classes, "mode" => $a_mode]);
145 }
146
150 public function getHTML(array $par): string
151 {
152 return $this->getHistoryHtml($par["from"], $par["to"], $par["classes"], $par["mode"]);
153 }
154
158 protected function getHistoryHtml(
159 ?int $from = null,
160 ?int $to = null,
161 ?array $classes = null,
162 ?string $mode = null
163 ): string {
164 $tpl = new ilTemplate("tpl.timeline.html", true, true, "components/ILIAS/LearningHistory");
165
166 $tpl->setVariable("TIMELINE", $this->renderTimeline($from, $to, $classes, $mode));
167
168 if ($this->show_more && $mode !== "print") {
169 $tpl->setCurrentBlock("show_more");
170 $tpl->setVariable("SHOW_MORE_BUTTON", $this->renderButton());
171 $tpl->parseCurrentBlock();
172 }
173
174 return $tpl->get();
175 }
176
180 protected function renderTimeline(
181 ?int $from = null,
182 ?int $to = null,
183 ?array $classes = null,
184 ?string $mode = null
185 ): string {
186 $collector = $this->lhist_service->factory()->collector();
187 $ctrl = $this->ctrl;
188
189 $to = (is_null($to))
190 ? time()
191 : $to;
192 $from = (is_null($from))
193 ? $to - (365 * 24 * 60 * 60)
194 : $from;
195
196 $entries = $collector->getEntries($from, $to, $this->user_id, $classes);
197
198 $timeline = ilTimelineGUI::getInstance();
199 $cnt = 0;
200
201 reset($entries);
202 while (($e = current($entries)) && $cnt < self::MAX) {
204 $timeline->addItem(new ilLearningHistoryTimelineItem(
205 $e,
206 $this->ui,
207 $this->user_id,
208 $this->access,
209 $this->lhist_service->repositoryTree()
210 ));
211 $this->last_ts = $e->getTimestamp();
212 next($entries);
213 $cnt++;
214 }
215
216 $html = "";
217 if (count($entries) > 0) {
218 $html = $timeline->render($ctrl->isAsynch());
219 }
220
221 $this->show_more = (count($entries) > $cnt);
222
223 return $html;
224 }
225
226 protected function renderButton(): string
227 {
228 $ctrl = $this->ctrl;
229 $f = $this->ui->factory();
230 $renderer = $this->ui->renderer();
231 $ctrl->setParameter($this, "to_ts", $this->last_ts - 1);
232 $url = $ctrl->getLinkTarget($this, "renderAsync", "", true);
233
234 $button = $f->button()->standard($this->lng->txt("lhist_show_more"), "")
235 ->withLoadingAnimationOnClick(true)
236 ->withOnLoadCode(static function ($id) use ($url): string {
237 return "il.LearningHistory.initShowMore('$id', '" . $url . "');";
238 });
239 if ($ctrl->isAsynch()) {
240 return $renderer->renderAsync($button);
241 }
242
243 return $renderer->render($button);
244 }
245}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
factory()
$renderer
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
Stream factory which enables the user to create streams without the knowledge of the concrete class.
Definition: Streams.php:32
return true
Class ilCtrl provides processing control methods.
getLinkTarget(object $a_gui_obj, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
getNextClass($a_gui_class=null)
@inheritDoc
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
@inheritDoc
isAsynch()
@inheritDoc
getCmd(?string $fallback_command=null)
@inheritDoc
language handling
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
Learning history main GUI class.
ilLearningHistoryService $lhist_service
getEmbeddedHTML(?int $from=null, ?int $to=null, ?array $classes=null, ?string $a_mode=null)
ilGlobalTemplateInterface $main_tpl
getHistoryHtml(?int $from=null, ?int $to=null, ?array $classes=null, ?string $mode=null)
Get history html.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS Setting Class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
special template class to simplify handling of ITX/PEAR
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setContent(string $a_html)
Sets content for standard template.
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
static http()
Fetches the global http state from ILIAS.
to(\GdImage $image, ?int $quality=null)
Currently this is the only way to make a FileStream from a GD image resource.
global $DIC
Definition: shib_login.php:26
$url
Definition: shib_logout.php:68
$response
Definition: xapitoken.php:93