ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilContentPageKioskModeView.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
12 
17 {
18  const CMD_LP_TO_COMPLETED = 'lp_completed';
19  const CMD_LP_TO_INCOMPLETE = 'lp_incomplete';
20 
22  protected $contentPageObject;
24  protected $user;
26  protected $uiFactory;
28  protected $uiRenderer;
30  protected $ctrl;
32  protected $mainTemplate;
34  protected $httpRequest;
36  protected $tabs;
38  protected $messages = [];
39 
43  protected function getObjectClass() : string
44  {
45  return ilObjContentPage::class;
46  }
47 
51  protected function setObject(ilObject $object)
52  {
53  global $DIC;
54 
55  $this->contentPageObject = $object;
56 
57  $this->ctrl = $DIC->ctrl();
58  $this->mainTemplate = $DIC->ui()->mainTemplate();
59  $this->uiFactory = $DIC->ui()->factory();
60  $this->uiRenderer = $DIC->ui()->renderer();
61  $this->httpRequest = $DIC->http()->request();
62  $this->tabs = $DIC->tabs();
63  $this->user = $DIC->user();
64  }
65 
69  protected function hasPermissionToAccessKioskMode() : bool
70  {
71  return $this->access->checkAccess('read', '', $this->contentPageObject->getRefId());
72  }
73 
77  public function buildInitialState(State $empty_state) : State
78  {
79  return $empty_state;
80  }
81 
85  public function buildControls(State $state, ControlBuilder $builder)
86  {
87  $this->buildLearningProgressToggleControl($builder);
88  }
89 
94  {
95  $learningProgress = ilObjectLP::getInstance($this->contentPageObject->getId());
96  if ($learningProgress->getCurrentMode() == ilLPObjSettings::LP_MODE_MANUAL) {
97  $isCompleted = ilLPMarks::_hasCompleted($this->user->getId(), $this->contentPageObject->getId());
98 
99  $this->lng->loadLanguageModule('copa');
100  $learningProgressToggleCtrlLabel = $this->lng->txt('copa_btn_lp_toggle_state_completed');
101  $cmd = self::CMD_LP_TO_INCOMPLETE;
102  if (!$isCompleted) {
103  $learningProgressToggleCtrlLabel = $this->lng->txt('copa_btn_lp_toggle_state_not_completed');
104  $cmd = self::CMD_LP_TO_COMPLETED;
105  }
106 
107  $builder->generic(
108  $learningProgressToggleCtrlLabel,
109  $cmd,
110  1
111  );
112  }
113  }
114 
118  public function updateGet(State $state, string $command, int $param = null) : State
119  {
120  $this->toggleLearningProgress($command);
121 
122  return $state;
123  }
124 
128  protected function toggleLearningProgress(string $command) : void
129  {
130  if (in_array($command, [
131  self::CMD_LP_TO_COMPLETED,
132  self::CMD_LP_TO_INCOMPLETE
133  ])) {
134  $learningProgress = ilObjectLP::getInstance($this->contentPageObject->getId());
135  if ($learningProgress->getCurrentMode() == ilLPObjSettings::LP_MODE_MANUAL) {
136  $marks = new ilLPMarks($this->contentPageObject->getId(), $this->user->getId());
137 
138  $old_state = $marks->getCompleted();
139  $new_state = ($command === self::CMD_LP_TO_COMPLETED);
140  $marks->setCompleted($new_state);
141  $marks->update();
142  ilLPStatusWrapper::_updateStatus($this->contentPageObject->getId(), $this->user->getId());
143 
144  if ($old_state != $new_state) {
145  $this->lng->loadLanguageModule('trac');
146  $this->messages[] = $this->uiFactory->messageBox()->success(
147  $this->lng->txt('trac_updated_status')
148  );
149  }
150  }
151  }
152  }
153 
157  public function updatePost(State $state, string $command, array $post) : State
158  {
159  return $state;
160  }
161 
165  public function render(
166  State $state,
168  URLBuilder $url_builder,
169  array $post = null
170  ) : Component {
172  $this->user->getId(),
173  $this->contentPageObject->getId(),
174  $this->contentPageObject->getRefId(),
175  $this->contentPageObject->getType()
176  );
177 
178  $this->renderContentStyle();
179 
180  $forwarder = new ilContentPagePageCommandForwarder(
181  $this->httpRequest,
182  $this->ctrl,
183  $this->tabs,
184  $this->lng,
185  $this->contentPageObject,
186  $this->user
187  );
189 
190  $this->ctrl->setParameterByClass(ilContentPagePageGUI::class, 'ref_id', $this->contentPageObject->getRefId());
191 
192  return $factory->legacy(implode('', [
193  $this->uiRenderer->render($this->messages),
194  $forwarder->forward($this->ctrl->getLinkTargetByClass([
195  ilRepositoryGUI::class, ilObjContentPageGUI::class, ilContentPagePageGUI::class
196  ]))
197  ]));
198  }
199 
203  protected function renderContentStyle() : void
204  {
205  $this->mainTemplate->addCss(ilObjStyleSheet::getSyntaxStylePath());
206  $this->mainTemplate->addCss(
208  $this->contentPageObject->getStyleSheetId()
209  )
210  );
211  }
212 }
static getContentStylePath($a_style_id, $add_random=true, $add_token=true)
get content style path
Class ilContentPagePageCommandForwarder.
buildControls(State $state, ControlBuilder $builder)
static _hasCompleted($a_usr_id, $a_obj_id)
Base class to be implemented and put in class-directory of module with the name il$MODULEKioskModeVie...
renderContentStyle()
Renders the content style of a ContentPage object into main template.
updatePost(State $state, string $command, array $post)
render(State $state, Factory $factory, URLBuilder $url_builder, array $post=null)
static _updateStatus($a_obj_id, $a_usr_id, $a_obj=null, $a_percentage=false, $a_force_raise=false)
Update status.
const PRESENTATION_MODE_EMBEDDED_PRESENTATION
presentation mode for embedded presentation, e.g.
static _tracProgress($a_user_id, $a_obj_id, $a_ref_id, $a_obj_type='')
buildLearningProgressToggleControl(ControlBuilder $builder)
user()
Definition: user.php:4
Keeps the state of a view in a simple stringly type key-value store.
Definition: State.php:9
updateGet(State $state, string $command, int $param=null)
This is how the factory for UI elements looks.
Definition: Factory.php:17
$param
Definition: xapitoken.php:29
global $DIC
Definition: goto.php:24
legacy($content)
description: purpose: > This component is used to wrap an existing ILIAS UI element into a UI compon...
static getSyntaxStylePath()
get syntax style path
The URLBuilder allows views to get links that are used somewhere inline in the content.
Definition: URLBuilder.php:12
Class ilContentPageKioskModeView.
Build controls for the view.
$builder
Definition: parser.php:5
static getInstance($a_obj_id)
$factory
Definition: metadata.php:58
generic(string $label, string $command, int $parameter=null)
A generic control needs to have a label that tells what it does.