ILIAS  release_8 Revision v8.24
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("./Services/LearningHistory/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, "Services/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
return true
Class ilCtrl provides processing control methods.
getNextClass($a_gui_class=null)
@inheritDoc
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
@inheritDoc
getCmd(string $fallback_command=null)
@inheritDoc
isAsynch()
@inheritDoc
getLinkTarget(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@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...
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...
special template class to simplify handling of ITX/PEAR
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
global $DIC
Definition: feed.php:28
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...
setContent(string $a_html)
Sets content for standard template.
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
static http()
Fetches the global http state from ILIAS.
$url
$response