ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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;
23 
25  protected $user;
26 
28  protected $uiFactory;
29 
31  protected $uiRenderer;
32 
34  protected $ctrl;
35 
37  protected $mainTemplate;
38 
40  protected $httpRequest;
41 
43  protected $tabs;
44 
46  protected $messages = [];
47 
51  protected function getObjectClass() : string
52  {
53  return \ilObjContentPage::class;
54  }
55 
59  protected function setObject(\ilObject $object)
60  {
61  global $DIC;
62 
63  $this->contentPageObject = $object;
64 
65  $this->ctrl = $DIC->ctrl();
66  $this->mainTemplate = $DIC->ui()->mainTemplate();
67  $this->uiFactory = $DIC->ui()->factory();
68  $this->uiRenderer = $DIC->ui()->renderer();
69  $this->httpRequest = $DIC->http()->request();
70  $this->tabs = $DIC->tabs();
71  $this->user = $DIC->user();
72  }
73 
77  protected function hasPermissionToAccessKioskMode() : bool
78  {
79  return $this->access->checkAccess('read', '', $this->contentPageObject->getRefId());
80  }
81 
85  public function buildInitialState(State $empty_state) : State
86  {
87  return $empty_state;
88  }
89 
94  {
95  $this->builtLearningProgressToggleControl($builder);
96  }
97 
102  {
103  $learningProgress = \ilObjectLP::getInstance($this->contentPageObject->getId());
104  if ($learningProgress->getCurrentMode() == \ilLPObjSettings::LP_MODE_MANUAL) {
105  $isCompleted = \ilLPMarks::_hasCompleted($this->user->getId(), $this->contentPageObject->getId());
106 
107  $this->lng->loadLanguageModule('copa');
108  $learningProgressToggleCtrlLabel = $this->lng->txt('copa_btn_lp_toggle_state_completed');
109  $cmd = self::CMD_LP_TO_INCOMPLETE;
110  if (!$isCompleted) {
111  $learningProgressToggleCtrlLabel = $this->lng->txt('copa_btn_lp_toggle_state_not_completed');
112  $cmd = self::CMD_LP_TO_COMPLETED;
113  }
114 
115  $builder->generic(
116  $learningProgressToggleCtrlLabel,
117  $cmd,
118  1
119  );
120  }
121  }
122 
126  public function updateGet(State $state, string $command, int $param = null) : State
127  {
128  $this->toggleLearningProgress($command);
129 
130  return $state;
131  }
132 
136  protected function toggleLearningProgress(string $command)
137  {
138  if (in_array($command, [
139  self::CMD_LP_TO_COMPLETED,
140  self::CMD_LP_TO_INCOMPLETE
141  ])) {
142  $learningProgress = ilObjectLP::getInstance($this->contentPageObject->getId());
143  if ($learningProgress->getCurrentMode() == ilLPObjSettings::LP_MODE_MANUAL) {
144  $marks = new ilLPMarks($this->contentPageObject->getId(), $this->user->getId());
145 
146  $old_state = $marks->getCompleted();
147  $new_state = ($command === self::CMD_LP_TO_COMPLETED);
148  $marks->setCompleted($new_state);
149  $marks->update();
150  ilLPStatusWrapper::_updateStatus($this->contentPageObject->getId(), $this->user->getId());
151 
152  if ($old_state != $new_state) {
153  $this->lng->loadLanguageModule('trac');
154  $this->messages[] = $this->uiFactory->messageBox()->success(
155  $this->lng->txt('trac_updated_status')
156  );
157  }
158  }
159  }
160  }
161 
165  public function updatePost(State $state, string $command, array $post) : State
166  {
167  return $state;
168  }
169 
173  public function render(
174  State $state,
176  URLBuilder $url_builder,
177  array $post = null
178  ) : Component {
180  $this->user->getId(),
181  $this->contentPageObject->getId(),
182  $this->contentPageObject->getRefId(),
183  $this->contentPageObject->getType()
184  );
185 
186  $this->renderContentStyle();
187 
188  $forwarder = new \ilContentPagePageCommandForwarder(
189  $this->httpRequest,
190  $this->ctrl,
191  $this->tabs,
192  $this->lng,
193  $this->contentPageObject
194  );
196 
197  $this->ctrl->setParameterByClass(\ilContentPagePageGUI::class, 'ref_id', $this->contentPageObject->getRefId());
198 
199  return $factory->legacy(implode('', [
200  $this->uiRenderer->render($this->messages),
201  $forwarder->forward($this->ctrl->getLinkTargetByClass([
202  \ilRepositoryGUI::class, \ilObjContentPageGUI::class, \ilContentPagePageGUI::class
203  ]))
204  ]));
205  }
206 
210  protected function renderContentStyle()
211  {
212  $this->mainTemplate->addCss(\ilObjStyleSheet::getSyntaxStylePath());
213  $this->mainTemplate->addCss(
215  $this->contentPageObject->getStyleSheetId()
216  )
217  );
218  }
219 }
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...
global $DIC
Definition: saml.php:7
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)
builtLearningProgressToggleControl(ControlBuilder $builder)
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.
$factory
Definition: metadata.php:43
static _tracProgress($a_user_id, $a_obj_id, $a_ref_id, $a_obj_type='')
user()
Definition: user.php:4
Keeps the state of a view in a simple stringly type key-value store.
Definition: State.php:9
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
updateGet(State $state, string $command, int $param=null)
This is how the factory for UI elements looks.
Definition: Factory.php:15
legacy($content)
description: purpose: > This component is used to wrap an existing ILIAS UI element into a UI compon...
$post
Definition: post.php:34
static getSyntaxStylePath()
get syntax style path
static getContentStylePath($a_style_id, $add_random=true)
get content 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)
generic(string $label, string $command, int $parameter=null)
A generic control needs to have a label that tells what it does.