ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilContentPageKioskModeView.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
29use ILIAS\Refinery\Factory as Refinery;
31
33{
34 private const string CMD_LP_TO_COMPLETED = 'lp_completed';
35 private const string CMD_LP_TO_INCOMPLETE = 'lp_incomplete';
36
39 protected ilObjUser $user;
44 protected Refinery $refinery;
45 protected ilTabsGUI $tabs;
47 protected array $messages = [];
48 protected \ILIAS\Style\Content\Object\ObjectFacade $content_style_domain;
49 protected \ILIAS\Style\Content\GUIService $content_style_gui;
50
51 protected function getObjectClass(): string
52 {
53 return ilObjContentPage::class;
54 }
55
56 protected function setObject(ilObject $object): void
57 {
58 global $DIC;
59
60 $this->contentPageObject = $object;
61
62 $this->ctrl = $DIC->ctrl();
63 $this->mainTemplate = $DIC->ui()->mainTemplate();
64 $this->uiFactory = $DIC->ui()->factory();
65 $this->uiRenderer = $DIC->ui()->renderer();
66 $this->http = $DIC->http();
67 $this->refinery = $DIC->refinery();
68 $this->tabs = $DIC->tabs();
69 $this->user = $DIC->user();
70 $cs = $DIC->contentStyle();
71 $this->content_style_gui = $cs->gui();
72 $this->content_style_domain = $cs->domain()->styleForRefId($object->getRefId());
73
74 $this->translation = $object->getObjectProperties()->getPropertyTranslations();
75 }
76
77 protected function hasPermissionToAccessKioskMode(): bool
78 {
79 return $this->access->checkAccess('read', '', $this->contentPageObject->getRefId());
80 }
81
82 public function buildInitialState(State $empty_state): State
83 {
84 return $empty_state;
85 }
86
87 public function buildControls(State $state, ControlBuilder $builder): void
88 {
90 }
91
92 protected function buildLearningProgressToggleControl(ControlBuilder $builder): void
93 {
94 $learningProgress = ilObjectLP::getInstance($this->contentPageObject->getId());
95 if ($learningProgress->getCurrentMode() === ilLPObjSettings::LP_MODE_MANUAL) {
96 $isCompleted = ilLPMarks::_hasCompleted($this->user->getId(), $this->contentPageObject->getId());
97
98 $this->lng->loadLanguageModule('copa');
99 $learningProgressToggleCtrlLabel = $this->lng->txt('copa_btn_lp_toggle_state_completed');
101 if (!$isCompleted) {
102 $learningProgressToggleCtrlLabel = $this->lng->txt('copa_btn_lp_toggle_state_not_completed');
104 }
105
106 $builder->generic(
107 $learningProgressToggleCtrlLabel,
108 $cmd,
109 1
110 );
111 }
112 }
113
114 public function updateGet(State $state, string $command, ?int $parameter = null): State
115 {
116 $this->toggleLearningProgress($command);
117
118 return $state;
119 }
120
121 protected function toggleLearningProgress(string $command): void
122 {
123 if (in_array($command, [
124 self::CMD_LP_TO_COMPLETED,
125 self::CMD_LP_TO_INCOMPLETE
126 ])) {
127 $learningProgress = ilObjectLP::getInstance($this->contentPageObject->getId());
128 if ($learningProgress->getCurrentMode() === ilLPObjSettings::LP_MODE_MANUAL) {
129 $marks = new ilLPMarks($this->contentPageObject->getId(), $this->user->getId());
130
131 $old_state = $marks->getCompleted();
132 $new_state = ($command === self::CMD_LP_TO_COMPLETED);
133 $marks->setCompleted($new_state);
134 $marks->update();
135 ilLPStatusWrapper::_updateStatus($this->contentPageObject->getId(), $this->user->getId());
136
137 if ((int) $old_state !== (int) $new_state) {
138 $this->lng->loadLanguageModule('trac');
139 $this->messages[] = $this->uiFactory->messageBox()->success(
140 $this->lng->txt('trac_updated_status')
141 );
142 }
143 }
144 }
145 }
146
147 public function updatePost(State $state, string $command, array $post): State
148 {
149 return $state;
150 }
151
152 public function render(
153 State $state,
154 Factory $factory,
155 URLBuilder $url_builder,
156 ?array $post = null
157 ): Component {
158 ilLearningProgress::_tracProgress(
159 $this->user->getId(),
160 $this->contentPageObject->getId(),
161 $this->contentPageObject->getRefId(),
162 $this->contentPageObject->getType()
163 );
164
165 $this->renderContentStyle();
166
167 $forwarder = new ilContentPagePageCommandForwarder(
168 $this->http,
169 $this->ctrl,
170 $this->tabs,
171 $this->lng,
172 $this->contentPageObject,
173 $this->translation,
174 $this->user,
175 $this->refinery,
176 $this->content_style_domain
177 );
179
180 $this->ctrl->setParameterByClass(ilContentPagePageGUI::class, 'ref_id', $this->contentPageObject->getRefId());
181
182 return $factory->legacy()->content(implode('', [
183 $this->uiRenderer->render($this->messages),
184 $forwarder->forward($this->ctrl->getLinkTargetByClass([
185 ilRepositoryGUI::class, ilObjContentPageGUI::class, ilContentPagePageGUI::class
186 ]))
187 ]));
188 }
189
193 protected function renderContentStyle(): void
194 {
196 $this->content_style_gui->addCss(
197 $this->mainTemplate,
198 $this->contentPageObject->getRefId()
199 );
200 }
201}
mainTemplate()
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
Class handles translation mode for an object.
Keeps the state of a view in a simple stringly type key-value store.
Definition: State.php:27
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
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.
updateGet(State $state, string $command, ?int $parameter=null)
Update the state based on the provided command.
renderContentStyle()
Renders the content style of a ContentPage object into main template.
render(State $state, Factory $factory, URLBuilder $url_builder, ?array $post=null)
buildLearningProgressToggleControl(ControlBuilder $builder)
ILIAS Style Content GUIService $content_style_gui
final const string 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)
Class ilObject Basic functions for all objects.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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: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
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:26