ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilLearningModuleKioskModeView.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2020 ILIAS open source, Extended GPL, see docs/LICENSE */
4
12use Psr\Http\Message\ServerRequestInterface;
13
20{
21 const CMD_TOGGLE_LEARNING_PROGRESS = 'toggleManualLearningProgress';
25 protected $menu_entries = null;
26
28 protected $lm;
29
37 protected $lm_pres;
38
40 protected $user;
41
43 protected $uiFactory;
44
46 protected $uiRenderer;
47
49 protected $ctrl;
50
52 protected $mainTemplate;
53
55 protected $httpRequest;
56
58 protected $tabs;
59
61 protected $messages = [];
62
63 protected $current_page_id = 0;
64
66 protected $additional_content = [];
67
71 protected function getObjectClass() : string
72 {
73 return \ilObjLearningModule::class;
74 }
75
79 protected function setObject(\ilObject $object)
80 {
81 global $DIC;
82
83 $this->lm = $object;
84 $this->ctrl = $DIC->ctrl();
85 $this->mainTemplate = $DIC->ui()->mainTemplate();
86 $this->uiFactory = $DIC->ui()->factory();
87 $this->uiRenderer = $DIC->ui()->renderer();
88 $this->httpRequest = $DIC->http()->request();
89 $this->tabs = $DIC->tabs();
90 $this->user = $DIC->user();
91 }
92
96 public function updateGet(State $state, string $command, int $param = null) : State
97 {
98 switch ($command) {
99 case "layout":
100 if ($param > 0) {
101 $this->current_page_id = $param;
102 $state = $state->withValueFor("current_page", (string) $this->current_page_id);
103 }
104 break;
106 $this->toggleLearningProgress($command);
107 break;
108 }
109
110 //$this->initLMService($this->current_page_id);
111
112 return $state;
113 }
114
118 protected function initLMService($current_page)
119 {
120 if (is_object($this->lm_pres)) {
121 return;
122 }
123 $this->lm_pres = new ilLMPresentationGUI(
124 "",
125 false,
126 "",
127 false,
128 ["ref_id" => $this->lm->getRefId(),
129 "obj_id" => (int) $current_page],
130 true
131 );
132
133 $this->lm_pres_service = $this->lm_pres->getService();
134 }
135
139 protected function hasPermissionToAccessKioskMode() : bool
140 {
141 return $this->access->checkAccess('read', '', $this->lm->getRefId());
142 }
143
147 public function buildInitialState(State $state) : State
148 {
149 return $state->withValueFor("current_page", "");
150 }
151
156 {
157 global $DIC;
158
159 $main_tpl = $DIC->ui()->mainTemplate();
160
161 // this may be necessary if updateGet has not been processed
162
163 // THIS currently fails
164 $this->initLMService($state->getValueFor("current_page"));
165 $nav_stat = $this->lm_pres_service->getNavigationStatus();
166
167 // next
168 $succ_id = $nav_stat->getSuccessorPageId();
169 if ($succ_id > 0) {
170 $builder->next("layout", $succ_id);
171 }
172
173 // previous
174 $prev_id = $nav_stat->getPredecessorPageId();
175 if ($prev_id > 0) {
176 $builder->previous("layout", $prev_id);
177 }
178
179 $toc = $builder->tableOfContent($this->lm->getTitle(), 'layout', 0);
180 $lm_toc_renderer = new ilLMSlateTocRendererGUI($this->lm_pres_service);
181 $lm_toc_renderer->renderLSToc($toc, $lm_toc_renderer, 0);
182
183
184 // learning progress
186
187 // menu
188 foreach ($this->getMenuEntries() as $entry) {
189 if (is_object($entry["signal"])) {
190 $builder = $builder->genericWithSignal(
191 $entry["label"],
192 $entry["signal"]
193 );
194 }
195 if ($entry["on_load"] != "") {
196 $main_tpl->addOnLoadCode($entry["on_load"]);
197 }
198 }
199
200 //$builder = $this->addPrintViewSelectionMenuButton($builder);
201
202 return $builder;
203 }
204
211 protected function getMenuEntries() : array
212 {
213 if (is_null($this->menu_entries)) {
214 $menu = new \ILIAS\LearningModule\Menu\ilLMMenuGUI($this->lm_pres_service);
215 $this->menu_entries = $menu->getEntries();
216 }
217 return $this->menu_entries;
218 }
219
224 {
225 $learningProgress = \ilObjectLP::getInstance($this->lm->getId());
226 if ($learningProgress->getCurrentMode() == \ilLPObjSettings::LP_MODE_MANUAL) {
227 $isCompleted = \ilLPMarks::_hasCompleted($this->user->getId(), $this->lm->getId());
228
229 $this->lng->loadLanguageModule('lm');
230 $learningProgressToggleCtrlLabel = $this->lng->txt('lm_btn_lp_toggle_state_completed');
231 if (!$isCompleted) {
232 $learningProgressToggleCtrlLabel = $this->lng->txt('lm_btn_lp_toggle_state_not_completed');
233 }
234 $builder = $builder->generic(
235 $learningProgressToggleCtrlLabel,
236 self::CMD_TOGGLE_LEARNING_PROGRESS,
237 1
238 );
239 }
240 return $builder;
241 }
242
246 protected function toggleLearningProgress(string $command)
247 {
248 if (self::CMD_TOGGLE_LEARNING_PROGRESS === $command) {
249 $learningProgress = \ilObjectLP::getInstance($this->lm->getId());
250 if ($learningProgress->getCurrentMode() == \ilLPObjSettings::LP_MODE_MANUAL) {
251 $marks = new \ilLPMarks($this->lm->getId(), $this->user->getId());
252 $marks->setCompleted(!$marks->getCompleted());
253 $marks->update();
254
255 \ilLPStatusWrapper::_updateStatus($this->lm->getId(), $this->user->getId());
256
257 $this->lng->loadLanguageModule('trac');
258 $this->messages[] = $this->uiFactory->messageBox()->success(
259 $this->lng->txt('trac_updated_status')
260 );
261 }
262 }
263 }
264
268 public function updatePost(State $state, string $command, array $post) : State
269 {
270 return $state;
271 }
272
276 public function render(
277 State $state,
279 URLBuilder $url_builder,
280 array $post = null
281 ) : Component {
282 $this->initLMService($state->getValueFor("current_page"));
283
285 foreach ($this->getMenuEntries() as $entry) {
286 if (is_object($entry["modal"])) {
287 $additional_content[] = $entry["modal"];
288 }
289 }
290
291 $this->ctrl->setParameterByClass("illmpresentationgui", 'ref_id', $this->lm->getRefId());
292 $content = $this->uiRenderer->render($this->messages);
293 $content .= $this->ctrl->getHTML($this->lm_pres, ["cmd" => "layout"], ["illmpresentationgui"]);
294 $content .= $this->uiRenderer->render($additional_content);
295 return $factory->legacy($content);
296 }
297
301 protected function renderContentStyle()
302 {
303 $this->mainTemplate->addCss(\ilObjStyleSheet::getSyntaxStylePath());
304 $this->mainTemplate->addCss(
306 $this->contentPageObject->getStyleSheetId()
307 )
308 );
309 }
310}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
Keeps the state of a view in a simple stringly type key-value store.
Definition: State.php:10
withValueFor(string $key, string $value)
Set a value for a key of the state.
Definition: State.php:20
getValueFor(string $key)
Get the value for the given key.
Definition: State.php:40
Base class to be implemented and put in class-directory of module with the name il$MODULEKioskModeVie...
Class ilLMPresentationGUI.
static _hasCompleted($a_usr_id, $a_obj_id)
static _updateStatus($a_obj_id, $a_usr_id, $a_obj=null, $a_percentage=false, $a_force_raise=false)
Update status.
Class ilLearningModuleKioskModeView.
renderContentStyle()
Renders the content style of a ContentPage object into main template.
initLMService($current_page)
Init learning module presentation service.
maybeBuildLearningProgressToggleControl(ControlBuilder $builder)
updatePost(State $state, string $command, array $post)
@inheritDoc
buildControls(State $state, ControlBuilder $builder)
@inheritDoc
render(State $state, Factory $factory, URLBuilder $url_builder, array $post=null)
@inheritDoc
updateGet(State $state, string $command, int $param=null)
@inheritDoc
static getSyntaxStylePath()
get syntax style path
static getContentStylePath($a_style_id, $add_random=true, $add_token=true)
get content style path
static getInstance($a_obj_id)
Class ilObject Basic functions for all objects.
global $DIC
Definition: goto.php:24
Build controls for the view.
The URLBuilder allows views to get links that are used somewhere inline in the content.
Definition: URLBuilder.php:13
A component is the most general form of an entity in the UI.
Definition: Component.php:14
This is how the factory for UI elements looks.
Definition: Factory.php:18
An entity that renders components to a string output.
Definition: Renderer.php:15
$factory
Definition: metadata.php:58
$builder
Definition: parser.php:5
$param
Definition: xapitoken.php:29