ILIAS  release_8 Revision v8.24
class.ilContentPageKioskModeView.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
29use ILIAS\Refinery\Factory as Refinery;
30
32{
33 private const CMD_LP_TO_COMPLETED = 'lp_completed';
34 private const CMD_LP_TO_INCOMPLETE = 'lp_incomplete';
35
37 protected ilObjUser $user;
42 protected Refinery $refinery;
43 protected ilTabsGUI $tabs;
45 protected array $messages = [];
46 protected \ILIAS\Style\Content\Object\ObjectFacade $content_style_domain;
47 protected \ILIAS\Style\Content\GUIService $content_style_gui;
48
49 protected function getObjectClass(): string
50 {
51 return ilObjContentPage::class;
52 }
53
54 protected function setObject(ilObject $object): void
55 {
56 global $DIC;
57
58 $this->contentPageObject = $object;
59
60 $this->ctrl = $DIC->ctrl();
61 $this->mainTemplate = $DIC->ui()->mainTemplate();
62 $this->uiFactory = $DIC->ui()->factory();
63 $this->uiRenderer = $DIC->ui()->renderer();
64 $this->http = $DIC->http();
65 $this->refinery = $DIC->refinery();
66 $this->tabs = $DIC->tabs();
67 $this->user = $DIC->user();
68 $cs = $DIC->contentStyle();
69 $this->content_style_gui = $cs->gui();
70 $this->content_style_domain = $cs->domain()->styleForRefId($object->getRefId());
71 }
72
73 protected function hasPermissionToAccessKioskMode(): bool
74 {
75 return $this->access->checkAccess('read', '', $this->contentPageObject->getRefId());
76 }
77
78 public function buildInitialState(State $empty_state): State
79 {
80 return $empty_state;
81 }
82
83 public function buildControls(State $state, ControlBuilder $builder): void
84 {
86 }
87
88 protected function buildLearningProgressToggleControl(ControlBuilder $builder): void
89 {
90 $learningProgress = ilObjectLP::getInstance($this->contentPageObject->getId());
91 if ($learningProgress->getCurrentMode() === ilLPObjSettings::LP_MODE_MANUAL) {
92 $isCompleted = ilLPMarks::_hasCompleted($this->user->getId(), $this->contentPageObject->getId());
93
94 $this->lng->loadLanguageModule('copa');
95 $learningProgressToggleCtrlLabel = $this->lng->txt('copa_btn_lp_toggle_state_completed');
97 if (!$isCompleted) {
98 $learningProgressToggleCtrlLabel = $this->lng->txt('copa_btn_lp_toggle_state_not_completed');
100 }
101
102 $builder->generic(
103 $learningProgressToggleCtrlLabel,
104 $cmd,
105 1
106 );
107 }
108 }
109
110 public function updateGet(State $state, string $command, int $parameter = null): State
111 {
112 $this->toggleLearningProgress($command);
113
114 return $state;
115 }
116
117 protected function toggleLearningProgress(string $command): void
118 {
119 if (in_array($command, [
120 self::CMD_LP_TO_COMPLETED,
121 self::CMD_LP_TO_INCOMPLETE
122 ])) {
123 $learningProgress = ilObjectLP::getInstance($this->contentPageObject->getId());
124 if ($learningProgress->getCurrentMode() === ilLPObjSettings::LP_MODE_MANUAL) {
125 $marks = new ilLPMarks($this->contentPageObject->getId(), $this->user->getId());
126
127 $old_state = $marks->getCompleted();
128 $new_state = ($command === self::CMD_LP_TO_COMPLETED);
129 $marks->setCompleted($new_state);
130 $marks->update();
131 ilLPStatusWrapper::_updateStatus($this->contentPageObject->getId(), $this->user->getId());
132
133 if ((int) $old_state !== (int) $new_state) {
134 $this->lng->loadLanguageModule('trac');
135 $this->messages[] = $this->uiFactory->messageBox()->success(
136 $this->lng->txt('trac_updated_status')
137 );
138 }
139 }
140 }
141 }
142
143 public function updatePost(State $state, string $command, array $post): State
144 {
145 return $state;
146 }
147
148 public function render(
149 State $state,
151 URLBuilder $url_builder,
152 array $post = null
153 ): Component {
154 ilLearningProgress::_tracProgress(
155 $this->user->getId(),
156 $this->contentPageObject->getId(),
157 $this->contentPageObject->getRefId(),
158 $this->contentPageObject->getType()
159 );
160
161 $this->renderContentStyle();
162
163 $forwarder = new ilContentPagePageCommandForwarder(
164 $this->http,
165 $this->ctrl,
166 $this->tabs,
167 $this->lng,
168 $this->contentPageObject,
169 $this->user,
170 $this->refinery,
171 $this->content_style_domain
172 );
174
175 $this->ctrl->setParameterByClass(ilContentPagePageGUI::class, 'ref_id', $this->contentPageObject->getRefId());
176
177 return $factory->legacy(implode('', [
178 $this->uiRenderer->render($this->messages),
179 $forwarder->forward($this->ctrl->getLinkTargetByClass([
180 ilRepositoryGUI::class, ilObjContentPageGUI::class, ilContentPagePageGUI::class
181 ]))
182 ]));
183 }
184
188 protected function renderContentStyle(): void
189 {
191 $this->content_style_gui->addCss(
192 $this->mainTemplate,
193 $this->contentPageObject->getRefId()
194 );
195 }
196}
Builds data types.
Definition: Factory.php:21
Keeps the state of a view in a simple stringly type key-value store.
Definition: State.php:13
hasPermissionToAccessKioskMode()
Check if the global user has permission to access the kiosk mode of the supplied object.
ILIAS Style Content Object ObjectFacade $content_style_domain
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.
buildControls(State $state, ControlBuilder $builder)
Construct the controls for the view based on the current state.
updatePost(State $state, string $command, array $post)
Update the state and the object based on the provided command and post-data.
getObjectClass()
Get the class of objects this view displays.
setObject(ilObject $object)
Set the object for this view.
renderContentStyle()
Renders the content style of a ContentPage object into main template.
buildLearningProgressToggleControl(ControlBuilder $builder)
ILIAS Style Content GUIService $content_style_gui
render(State $state, Factory $factory, URLBuilder $url_builder, array $post=null)
const PRESENTATION_MODE_EMBEDDED_PRESENTATION
presentation mode for embedded presentation, e.g.
Base class to be implemented and put in class-directory of module with the name il$MODULEKioskModeVie...
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)
User class.
static getInstance(int $obj_id)
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...
global $DIC
Definition: feed.php:28
Interface GlobalHttpState.
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.
The URLBuilder allows views to get links that are used somewhere inline in the content.
Definition: URLBuilder.php:16
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
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$post
Definition: ltitoken.php:49
$factory
Definition: metadata.php:75
static http()
Fetches the global http state from ILIAS.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...