ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilContentPageKioskModeView.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
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;
40  protected Factory $uiFactory;
41  protected Renderer $uiRenderer;
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  {
89  $this->buildLearningProgressToggleControl($builder);
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');
100  $cmd = self::CMD_LP_TO_INCOMPLETE;
101  if (!$isCompleted) {
102  $learningProgressToggleCtrlLabel = $this->lng->txt('copa_btn_lp_toggle_state_not_completed');
103  $cmd = self::CMD_LP_TO_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 {
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 }
ILIAS Style Content GUIService $content_style_gui
legacy()
description: purpose: > legacy components are used as provisional elements in the UI framework while...
buildControls(State $state, ControlBuilder $builder)
Construct the controls for the view based on the current state.
Base class to be implemented and put in class-directory of module with the name il$MODULEKioskModeVie...
updateGet(State $state, string $command, ?int $parameter=null)
Update the state based on the provided command.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
renderContentStyle()
Renders the content style of a ContentPage object into main template.
updatePost(State $state, string $command, array $post)
Update the state and the object based on the provided command and post-data.
Class handles translation mode for an object.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
buildLearningProgressToggleControl(ControlBuilder $builder)
generic(string $label, string $command, ?int $parameter=null)
A generic control needs to have a label that tells what it does.
buildInitialState(State $empty_state)
Build an initial state based on the Provided empty state.
render(State $state, Factory $factory, URLBuilder $url_builder, ?array $post=null)
static _tracProgress(int $a_user_id, int $a_obj_id, int $a_ref_id, string $a_obj_type='')
static _hasCompleted(int $a_usr_id, int $a_obj_id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static http()
Fetches the global http state from ILIAS.
This is how the factory for UI elements looks.
Definition: Factory.php:37
final const string PRESENTATION_MODE_EMBEDDED_PRESENTATION
presentation mode for embedded presentation, e.g.
ILIAS Style Content Object ObjectFacade $content_style_domain
global $DIC
Definition: shib_login.php:26
The URLBuilder allows views to get links that are used somewhere inline in the content.
Definition: URLBuilder.php:29
Build controls for the view.
$post
Definition: ltitoken.php:46
static getInstance(int $obj_id)
mainTemplate()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _updateStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null, bool $a_percentage=false, bool $a_force_raise=false)