ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilObjLearningSequenceLearnerGUI.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2
7{
8 const CMD_STANDARD = 'learnerView';
9 const CMD_EXTRO = 'learnerViewFinished';
10 const CMD_UNSUBSCRIBE = 'unsubscribe';
11 const CMD_VIEW = 'view';
12 const CMD_START = 'start';
13 const PARAM_LSO_NEXT_ITEM = 'lsoni';
14 const LSO_CMD_NEXT = 'lson';
15 const LSO_CMD_PREV = 'lsop';
16
17 public function __construct(
18 int $ls_ref_id,
19 bool $has_items,
20 $first_access,
21 int $usr_id,
22 ilAccess $access,
23 ilCtrl $ctrl,
26 ilToolbarGUI $toolbar,
27 ILIAS\UI\Factory $ui_factory,
28 ILIAS\UI\Renderer $ui_renderer,
31 ilLSCurriculumBuilder $curriculum_builder,
32 ilLSPlayer $player
33 ) {
34 $this->ls_object = $ls_object;
35 $this->ls_ref_id = $ls_ref_id;
36 $this->has_items = $has_items;
37 $this->first_access = $first_access;
38 $this->usr_id = $usr_id;
39 $this->access = $access;
40 $this->ctrl = $ctrl;
41 $this->lng = $lng;
42 $this->tpl = $tpl;
43 $this->toolbar = $toolbar;
44 $this->ui_factory = $ui_factory;
45 $this->renderer = $ui_renderer;
46 $this->roles = $roles;
47 $this->settings = $settings;
48 $this->curriculum_builder = $curriculum_builder;
49 $this->player = $player;
50 }
51
52 public function executeCommand()
53 {
54 $cmd = $this->ctrl->getCmd();
55 switch ($cmd) {
57 case self::CMD_EXTRO:
58 $this->view($cmd);
59 break;
60 case self::CMD_START:
61 $this->addMember($this->usr_id);
62 $this->ctrl->redirect($this, self::CMD_VIEW);
63 break;
65 if ($this->userMayUnparticipate()) {
66 $this->roles->leave($this->usr_id);
67 }
68 $this->ctrl->redirect($this, self::CMD_STANDARD);
69 break;
70 case self::CMD_VIEW:
71 $this->play();
72 break;
73
76
77 // no break
78 default:
79 throw new ilException(
80 "ilObjLearningSequenceLearnerGUI: " .
81 "Command not supported: $cmd"
82 );
83 }
84 }
85
86 protected function view(string $cmd)
87 {
88 $this->initToolbar($cmd);
89
90 $content = $this->getMainContent($cmd);
91 $this->tpl->setContent(
92 $this->getWrappedHTML($content)
93 );
94
95 $curriculum = $this->curriculum_builder->getLearnerCurriculum();
96 if (count($curriculum->getSteps()) > 0) {
97 $this->tpl->setRightContent(
98 $this->getWrappedHTML([$curriculum])
99 );
100 }
101 }
102
103 protected function addMember(int $usr_id)
104 {
105 $admins = $this->roles->getLearningSequenceAdminIds();
106 if (!in_array($usr_id, $admins)) {
107 $this->roles->join($usr_id);
108 }
109 }
110
111
112 protected function userMayUnparticipate() : bool
113 {
114 return $this->access->checkAccess('unparticipate', '', $this->ls_ref_id);
115 }
116
117 protected function userMayJoin() : bool
118 {
119 return $this->access->checkAccess('participate', '', $this->ls_ref_id);
120 }
121
122 protected function initToolbar(string $cmd)
123 {
124 $is_member = $this->roles->isMember($this->usr_id);
125 $completed = $this->roles->isCompletedByUser($this->usr_id);
126 $has_items = $this->has_items;
127
128 if (!$is_member) {
129 if ($has_items) {
130 $may_subscribe = $this->userMayJoin();
131 if ($may_subscribe) {
132 $this->toolbar->addButton(
133 $this->lng->txt("lso_player_start"),
134 $this->ctrl->getLinkTarget($this, self::CMD_START)
135 );
136 }
137 }
138 } else {
139 if (!$completed) {
140 if ($has_items) {
141 $label = "lso_player_resume";
142 if ($this->first_access === -1) {
143 $label = "lso_player_start";
144 }
145
146 $this->toolbar->addButton(
147 $this->lng->txt($label),
148 $this->ctrl->getLinkTarget($this, self::CMD_VIEW)
149 );
150 }
151 } else {
152 if ($has_items) {
153 $this->toolbar->addButton(
154 $this->lng->txt("lso_player_review"),
155 $this->ctrl->getLinkTarget($this, self::CMD_VIEW)
156 );
157 }
158 if ($cmd === self::CMD_STANDARD) {
159 $this->toolbar->addButton(
160 $this->lng->txt("lso_player_extro"),
161 $this->ctrl->getLinkTarget($this, self::CMD_EXTRO)
162 );
163 }
164 if ($cmd === self::CMD_EXTRO) {
165 $this->toolbar->addButton(
166 $this->lng->txt("lso_player_abstract"),
167 $this->ctrl->getLinkTarget($this, self::CMD_STANDARD)
168 );
169 }
170 }
171
172 $may_unsubscribe = $this->userMayUnparticipate();
173 if ($may_unsubscribe) {
174 $this->toolbar->addButton(
175 $this->lng->txt("unparticipate"),
176 $this->ctrl->getLinkTarget($this, self::CMD_UNSUBSCRIBE)
177 );
178 }
179 }
180 }
181
182 private function getWrappedHTML(array $components) : string
183 {
184 array_unshift(
185 $components,
186 $this->ui_factory->legacy('<div class="ilLSOLearnerView">')
187 );
188 $components[] = $this->ui_factory->legacy('</div>');
189
190 return $this->renderer->render($components);
191 }
192
193 private function getMainContent(string $cmd) : array
194 {
195 if ($cmd === self::CMD_STANDARD) {
196 $txt = $this->settings->getAbstract();
197 $img = $this->settings->getAbstractImage();
198 }
199
200 if ($cmd === self::CMD_EXTRO) {
201 $txt = $this->settings->getExtro();
202 $img = $this->settings->getExtroImage();
203 }
204
205 $contents = [$this->ui_factory->legacy($txt)];
206 if (!is_null($img)) {
207 $contents[] = $this->ui_factory->image()->responsive($img, '');
208 }
209
210 return $contents;
211 }
212
213 protected function play()
214 {
215 $response = $this->player->play($_GET, $_POST);
216
217 switch ($response) {
218 case null:
219 //render the page
220 $this->tpl->enableDragDropFileUpload(null);
221 $this->tpl->setContent('THIS SHOULD NOT SHOW');
222 return;
223
224 case 'EXIT::' . $this->player::LSO_CMD_FINISH:
225 $cmd = self::CMD_EXTRO;
226 break;
227
228 case 'EXIT::' . $this->player::LSO_CMD_SUSPEND:
229 default:
230 $cmd = self::CMD_STANDARD;
231 break;
232 }
233 $href = $this->ctrl->getLinkTarget($this, $cmd, '', false, false);
234 \ilUtil::redirect($href);
235 }
236
238 {
239 print $this->player->getCurrentItemLearningProgress();
240 exit;
241 }
242}
if(! $in) print
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Class ilAccessHandler.
This class provides processing control methods.
Base class for ILIAS Exception handling.
Builds the overview (curriculum) of a LearningSequence.
Implementation of KioskMode Player.
language handling
Settings for an LSO (like abstract, extro)
Class ilObjLearningSequenceLearnerGUI.
__construct(int $ls_ref_id, bool $has_items, $first_access, int $usr_id, ilAccess $access, ilCtrl $ctrl, ilLanguage $lng, ilGlobalTemplateInterface $tpl, ilToolbarGUI $toolbar, ILIAS\UI\Factory $ui_factory, ILIAS\UI\Renderer $ui_renderer, ilLearningSequenceRoles $roles, ilLearningSequenceSettings $settings, ilLSCurriculumBuilder $curriculum_builder, ilLSPlayer $player)
static redirect($a_script)
$txt
Definition: error.php:13
exit
Definition: login.php:29
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
$response
$lng
settings()
Definition: settings.php:2
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl