ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLearningModuleKioskModeView.php
Go to the documentation of this file.
1<?php
2
26use Psr\Http\Message\ServerRequestInterface;
27
34{
35 public const CMD_TOGGLE_LEARNING_PROGRESS = 'toggleManualLearningProgress';
37
40 protected ?ilLMPresentationGUI $lm_pres = null;
41 protected ilObjUser $user;
45 protected ServerRequestInterface $httpRequest;
46 protected ilTabsGUI $tabs;
47 protected array $messages = [];
48 protected ?int $current_page_id = 0;
49 protected array $additional_content = [];
50 protected ?array $menu_entries = null;
51
52 protected function getObjectClass(): string
53 {
54 return \ilObjLearningModule::class;
55 }
56
57 protected function setObject(\ilObject $object): void
58 {
59 global $DIC;
60
62 $this->lm = $object;
63 $this->ctrl = $DIC->ctrl();
64 $this->mainTemplate = $DIC->ui()->mainTemplate();
65 $this->uiFactory = $DIC->ui()->factory();
66 $this->uiRenderer = $DIC->ui()->renderer();
67 $this->httpRequest = $DIC->http()->request();
68 $this->tabs = $DIC->tabs();
69 $this->user = $DIC->user();
70 }
71
72 public function updateGet(
73 State $state,
74 string $command,
75 ?int $parameter = null
76 ): State {
77 switch ($command) {
78 case "layout":
79 if ($parameter > 0) {
80 $this->current_page_id = $parameter;
81 $state = $state->withValueFor("current_page", (string) $this->current_page_id);
82 }
83 break;
85 $this->toggleLearningProgress($command);
86 break;
87 }
88
89 //$this->initLMService($this->current_page_id);
90
91 return $state;
92 }
93
94 // Init learning module presentation service
95 protected function initLMService(?int $current_page): void
96 {
97 if (is_object($this->lm_pres)) {
98 return;
99 }
100 $this->lm_pres = new ilLMPresentationGUI(
101 "",
102 false,
103 "",
104 false,
105 ["ref_id" => $this->lm->getRefId(),
106 "obj_id" => (int) $current_page],
107 true
108 );
109
110 $this->lm_pres_service = $this->lm_pres->getService();
111 }
112
113 protected function hasPermissionToAccessKioskMode(): bool
114 {
115 return $this->access->checkAccess('read', '', $this->lm->getRefId());
116 }
117
118 public function buildInitialState(State $empty_state): State
119 {
120 return $empty_state->withValueFor("current_page", "");
121 }
122
123 public function buildControls(
124 State $state,
125 ControlBuilder $builder
126 ): ControlBuilder {
127 global $DIC;
128
129 $main_tpl = $DIC->ui()->mainTemplate();
130
131 // this may be necessary if updateGet has not been processed
132
133 // THIS currently fails
134 $this->initLMService((int) $state->getValueFor("current_page"));
135 $nav_stat = $this->lm_pres_service->getNavigationStatus();
136
137 // next
138 $succ_id = $nav_stat->getSuccessorPageId();
139 if ($succ_id > 0) {
140 $builder->next("layout", $succ_id);
141 }
142
143 // previous
144 $prev_id = $nav_stat->getPredecessorPageId();
145 if ($prev_id > 0) {
146 $builder->previous("layout", $prev_id);
147 }
148
149 $toc = $builder->tableOfContent($this->lm->getTitle(), 'layout', 0);
150 $lm_toc_renderer = new ilLMSlateTocRendererGUI($this->lm_pres_service);
151 $lm_toc_renderer->renderLSToc($toc);
152
153 // learning progress
154 $builder = $this->maybeBuildLearningProgressToggleControl($builder);
155
156 // menu
157 foreach ($this->getMenuEntries() as $entry) {
158 if (is_object($entry["signal"])) {
159 $builder = $builder->genericWithSignal(
160 $entry["label"],
161 $entry["signal"]
162 );
163 }
164 if ($entry["on_load"] != "") {
165 $main_tpl->addOnLoadCode($entry["on_load"]);
166 }
167 }
168
169 //$builder = $this->addPrintViewSelectionMenuButton($builder);
170
171 return $builder;
172 }
173
174 protected function getMenuEntries(): array
175 {
176 if (is_null($this->menu_entries)) {
177 $menu = new \ILIAS\LearningModule\Menu\ilLMMenuGUI($this->lm_pres_service);
178 $this->menu_entries = $menu->getEntries();
179 }
180 return $this->menu_entries;
181 }
182
184 ControlBuilder $builder
185 ): ControlBuilder {
186 $learningProgress = \ilObjectLP::getInstance($this->lm->getId());
187 if ($learningProgress->getCurrentMode() == \ilLPObjSettings::LP_MODE_MANUAL) {
188 $isCompleted = \ilLPMarks::_hasCompleted($this->user->getId(), $this->lm->getId());
189
190 $this->lng->loadLanguageModule('lm');
191 $learningProgressToggleCtrlLabel = $this->lng->txt('lm_btn_lp_toggle_state_completed');
192 if (!$isCompleted) {
193 $learningProgressToggleCtrlLabel = $this->lng->txt('lm_btn_lp_toggle_state_not_completed');
194 }
195 $builder = $builder->generic(
196 $learningProgressToggleCtrlLabel,
197 self::CMD_TOGGLE_LEARNING_PROGRESS,
198 1
199 );
200 }
201 return $builder;
202 }
203
204 protected function toggleLearningProgress(
205 string $command
206 ): void {
207 if (self::CMD_TOGGLE_LEARNING_PROGRESS === $command) {
208 $learningProgress = \ilObjectLP::getInstance($this->lm->getId());
209 if ($learningProgress->getCurrentMode() == \ilLPObjSettings::LP_MODE_MANUAL) {
210 $marks = new \ilLPMarks($this->lm->getId(), $this->user->getId());
211 $marks->setCompleted(!$marks->getCompleted());
212 $marks->update();
213
214 \ilLPStatusWrapper::_updateStatus($this->lm->getId(), $this->user->getId());
215
216 $this->lng->loadLanguageModule('trac');
217 $this->messages[] = $this->uiFactory->messageBox()->success(
218 $this->lng->txt('trac_updated_status')
219 );
220 }
221 }
222 }
223
224 public function updatePost(
225 State $state,
226 string $command,
227 array $post
228 ): State {
229 return $state;
230 }
231
232 public function render(
233 State $state,
234 Factory $factory,
235 URLBuilder $url_builder,
236 ?array $post = null
237 ): Component {
238 $this->initLMService((int) $state->getValueFor("current_page"));
239
240 $additional_content = [];
241 foreach ($this->getMenuEntries() as $entry) {
242 if (is_object($entry["modal"])) {
243 $additional_content[] = $entry["modal"];
244 }
245 }
246
247 $this->ctrl->setParameterByClass("illmpresentationgui", 'ref_id', $this->lm->getRefId());
248 $content = $this->uiRenderer->render($this->messages);
249 $content .= $this->ctrl->getHTML($this->lm_pres, ["cmd" => "layout"], ["illmpresentationgui"]);
250 $content .= $this->uiRenderer->render($additional_content);
251 return $factory->legacy()->content($content);
252 }
253}
mainTemplate()
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Keeps the state of a view in a simple stringly type key-value store.
Definition: State.php:27
withValueFor(string $key, string $value)
Set a value for a key of the state.
Definition: State.php:36
getValueFor(string $key)
Get the value for the given key.
Definition: State.php:56
Base class to be implemented and put in class-directory of module with the name il$MODULEKioskModeVie...
setObject(ilObject $object)
Set the object for this view.
Class ilLMPresentationGUI GUI class for learning module presentation.
Main service init and factory.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _hasCompleted(int $a_usr_id, int $a_obj_id)
static _updateStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null, bool $a_percentage=false, bool $a_force_raise=false)
Class ilLearningModuleKioskModeView.
render(State $state, Factory $factory, URLBuilder $url_builder, ?array $post=null)
getObjectClass()
Get the class of objects this view displays.
maybeBuildLearningProgressToggleControl(ControlBuilder $builder)
updatePost(State $state, string $command, array $post)
Update the state and the object based on the provided command and post-data.
hasPermissionToAccessKioskMode()
Check if the global user has permission to access the kiosk mode of the supplied object.
buildControls(State $state, ControlBuilder $builder)
Construct the controls for the view based on the current state.
updateGet(State $state, string $command, ?int $parameter=null)
Update the state based on the provided command.
buildInitialState(State $empty_state)
Build an initial state based on the Provided empty state.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User class.
Base class for object lp connectors.
static getInstance(int $obj_id)
Class ilObject Basic functions for all objects.
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Build controls for the view.
generic(string $label, string $command, ?int $parameter=null)
A generic control needs to have a label that tells what it does.
tableOfContent(string $label, string $command, ?int $parameter=null, $state=null)
A table of content allows the user to get an overview over the generally available content in the obj...
next(string $command, ?int $parameter=null)
A next control allows the user to progress to the next item in the object.
genericWithSignal(string $label, UI\Component\Signal $signal)
A genericWithSignal will trigger the Signal rather than refreshing the View.
previous(string $command, ?int $parameter=null)
A previous control allows the user to go back to the previous item in the object.
The URLBuilder allows views to get links that are used somewhere inline in the content.
Definition: URLBuilder.php:30
A component is the most general form of an entity in the UI.
Definition: Component.php:28
This is how the factory for UI elements looks.
Definition: Factory.php:38
An entity that renders components to a string output.
Definition: Renderer.php:31
$post
Definition: ltitoken.php:46
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26