ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
class.ilObjLearningSequenceLearnerGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
25{
26 public const CMD_STANDARD = 'learnerView';
27 public const CMD_EXTRO = 'learnerViewFinished';
28 public const CMD_UNSUBSCRIBE_CONFIRMATION = 'unsubscribeConfirmation';
29 public const CMD_UNSUBSCRIBE = 'unsubscribe';
30 public const CMD_VIEW = 'view';
31 public const CMD_START = 'start';
32 public const PARAM_LSO_NEXT_ITEM = 'lsoni';
33 public const LSO_CMD_NEXT = 'lson';
34 public const LSO_CMD_PREV = 'lsop';
35
36 public function __construct(
37 protected int $usr_id,
38 protected ilAccess $access,
39 protected ilCtrl $ctrl,
40 protected ilLanguage $lng,
41 protected ilGlobalTemplateInterface $tpl,
42 protected ilToolbarGUI $toolbar,
43 protected ILIAS\UI\Factory $ui_factory,
44 protected ILIAS\UI\Renderer $renderer,
45 protected ilLearningSequenceRoles $roles,
46 protected ilLearningSequenceSettings $settings,
47 protected ilLSCurriculumBuilder $curriculum_builder,
48 protected ilLSLaunchlinksBuilder $launchlinks_builder,
49 protected ilLSPlayer $player,
50 protected string $intro,
51 protected string $extro,
52 protected RequestWrapper $get
53 ) {
54 }
55
56 public function executeCommand(): void
57 {
58 $cmd = $this->ctrl->getCmd();
59 switch ($cmd) {
61 case self::CMD_EXTRO:
62 $this->view($cmd);
63 break;
64 case self::CMD_START:
65 $this->addMember($this->usr_id);
66 $this->ctrl->redirect($this, self::CMD_VIEW);
67 break;
70 break;
72 if ($this->launchlinks_builder->currentUserMayUnparticipate()) {
73 $this->roles->leave($this->usr_id);
74 }
75 $this->ctrl->redirect($this, self::CMD_STANDARD);
76 break;
77 case self::CMD_VIEW:
78 $this->play();
79 break;
80
81 default:
82 throw new ilException(
83 "ilObjLearningSequenceLearnerGUI: " .
84 "Command not supported: $cmd"
85 );
86 }
87 }
88
90 {
91 return $this->ui_factory->modal()->interruptive(
92 $this->lng->txt('obj_lso'),
93 $this->lng->txt("unparticipate"),
94 $this->ctrl->getLinkTarget($this, self::CMD_UNSUBSCRIBE),
95 );
96 }
97
98 protected function view(string $cmd): void
99 {
100 $content = $this->getWrappedHTML(
101 $this->getMainContent($cmd)
102 );
103
104 $modal = $this->unsubscribeConfirmationModal();
105
106 $this->tpl->setContent($content . $this->renderer->render($modal));
107
108 $element = '<' . ilPCLauncher::PCELEMENT . '>';
109 if (!str_contains($content, $element)) {
110 $this->initToolbar($cmd, $modal);
111 }
112
113 $element = '<' . ilPCCurriculum::PCELEMENT . '>';
114 if (!str_contains($content, $element)) {
115 $curriculum = $this->curriculum_builder->getLearnerCurriculum();
116 $this->tpl->setRightContent(
117 $this->getWrappedHTML([$curriculum])
118 );
119 }
120 }
121
122 protected function addMember(int $usr_id): void
123 {
124 $admins = $this->roles->getLearningSequenceAdminIds();
125 if (!in_array($usr_id, $admins)) {
126 $this->roles->join($usr_id);
127 }
128 }
129
130 protected function initToolbar(string $cmd, Interruptive $modal): void
131 {
132 foreach ($this->launchlinks_builder->getLinks() as $entry) {
133 list($label, $link, $primary) = $entry;
134
135 if ($primary) {
136 $btn = $this->ui_factory->button()->primary($label, $link);
137 } else {
138 $btn = $this->ui_factory->button()->standard($label, $link);
139 }
140
141 if ($label === $this->lng->txt("unparticipate")) {
142 $btn = $this->ui_factory->button()->standard($label, $link)->withOnClick($modal->getShowSignal());
143 }
144
145 $this->toolbar->addComponent($btn);
146 }
147 }
148
149 private function getWrappedHTML(array $components): string
150 {
151 array_unshift(
153 $this->ui_factory->legacy()->content('<div class="ilLSOLearnerView">')
154 );
155 $components[] = $this->ui_factory->legacy()->content('</div>');
156
157 return $this->renderer->render($components);
158 }
159
160 private function getMainContent(string $cmd): array
161 {
162 $img = null;
163 $contents = [];
164
165 if ($cmd === self::CMD_STANDARD) {
166 if ($this->intro === '') {
167 $contents[] = $this->ui_factory->legacy()->content($this->settings->getAbstract());
168 $img = $this->settings->getAbstractImage();
169 if ($img) {
170 $contents[] = $this->ui_factory->image()->responsive($img, '');
171 }
172 } else {
173 $contents[] = $this->ui_factory->legacy()->content($this->intro);
174 }
175 }
176
177 if ($cmd === self::CMD_EXTRO) {
178 if ($this->extro === '') {
179 $contents[] = $this->ui_factory->legacy()->content($this->settings->getExtro());
180 $img = $this->settings->getExtroImage();
181 if ($img) {
182 $contents[] = $this->ui_factory->image()->responsive($img, '');
183 }
184 } else {
185 $contents[] = $this->ui_factory->legacy()->content($this->extro);
186 }
187 }
188 return $contents;
189 }
190
191 protected function play(): void
192 {
193 $response = $this->player->play($this->get);
194
195 switch ($response) {
196 case null:
197 //render the page
198 $this->tpl->setContent($this->lng->txt('lso_player_noitems'));
199 return;
200
201 case 'EXIT::' . $this->player::LSO_CMD_FINISH:
202 $cmd = self::CMD_EXTRO;
203 break;
204
205 case 'EXIT::' . $this->player::LSO_CMD_SUSPEND:
206 default:
207 $cmd = self::CMD_STANDARD;
208 break;
209 }
210 $href = $this->ctrl->getLinkTarget($this, $cmd, '', false, false);
211 \ilUtil::redirect($href);
212 }
213}
renderer()
$components
$renderer
Class ilAccessHandler Checks access for ILIAS objects.
Class ilCtrl provides processing control methods.
Base class for ILIAS Exception handling.
Builds the overview (curriculum) of a LearningSequence.
Builds the links to join/(re-)start the LearningSequence.
Implementation of KioskMode Player.
language handling
Settings for an LSO (like abstract, extro)
__construct(protected int $usr_id, protected ilAccess $access, protected ilCtrl $ctrl, protected ilLanguage $lng, protected ilGlobalTemplateInterface $tpl, protected ilToolbarGUI $toolbar, protected ILIAS\UI\Factory $ui_factory, protected ILIAS\UI\Renderer $renderer, protected ilLearningSequenceRoles $roles, protected ilLearningSequenceSettings $settings, protected ilLSCurriculumBuilder $curriculum_builder, protected ilLSLaunchlinksBuilder $launchlinks_builder, protected ilLSPlayer $player, protected string $intro, protected string $extro, protected RequestWrapper $get)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static redirect(string $a_script)
Interface RequestWrapper.
getShowSignal()
Get the signal to show this modal in the frontend.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $lng
Definition: privfeed.php:26
$response
Definition: xapitoken.php:90