ILIAS  release_8 Revision v8.24
class.ilObjLearningSequenceLearnerGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
22
24{
25 public const CMD_STANDARD = 'learnerView';
26 public const CMD_EXTRO = 'learnerViewFinished';
27 public const CMD_UNSUBSCRIBE = 'unsubscribe';
28 public const CMD_VIEW = 'view';
29 public const CMD_START = 'start';
30 public const PARAM_LSO_NEXT_ITEM = 'lsoni';
31 public const LSO_CMD_NEXT = 'lson';
32 public const LSO_CMD_PREV = 'lsop';
33
34 protected ilAccess $access;
35 protected ilCtrl $ctrl;
36 protected ilLanguage $lng;
46 protected string $intro;
47 protected string $extro;
49
50
51
52 public function __construct(
53 int $usr_id,
59 ILIAS\UI\Factory $ui_factory,
60 ILIAS\UI\Renderer $ui_renderer,
66 string $intro,
67 string $extro,
69 ) {
70 $this->usr_id = $usr_id;
71 $this->access = $access;
72 $this->ctrl = $ctrl;
73 $this->lng = $lng;
74 $this->tpl = $tpl;
75 $this->toolbar = $toolbar;
76 $this->ui_factory = $ui_factory;
77 $this->renderer = $ui_renderer;
78 $this->roles = $roles;
79 $this->settings = $settings;
80 $this->curriculum_builder = $curriculum_builder;
81 $this->launchlinks_builder = $launchlinks_builder;
82 $this->player = $player;
83 $this->intro = $intro;
84 $this->extro = $extro;
85 $this->get = $get;
86 }
87
88 public function executeCommand(): void
89 {
90 $cmd = $this->ctrl->getCmd();
91 switch ($cmd) {
93 case self::CMD_EXTRO:
94 $this->view($cmd);
95 break;
96 case self::CMD_START:
97 $this->addMember($this->usr_id);
98 $this->ctrl->redirect($this, self::CMD_VIEW);
99 break;
101 if ($this->launchlinks_builder->currentUserMayUnparticipate()) {
102 $this->roles->leave($this->usr_id);
103 }
104 $this->ctrl->redirect($this, self::CMD_STANDARD);
105 break;
106 case self::CMD_VIEW:
107 $this->play();
108 break;
109
110 default:
111 throw new ilException(
112 "ilObjLearningSequenceLearnerGUI: " .
113 "Command not supported: $cmd"
114 );
115 }
116 }
117
118 protected function view(string $cmd): void
119 {
120 $content = $this->getWrappedHTML(
121 $this->getMainContent($cmd)
122 );
123
124 $this->tpl->setContent($content);
125
126 $element = '<' . ilPCLauncher::PCELEMENT . '>';
127 if (!str_contains($content, $element)) {
128 $this->initToolbar($cmd);
129 }
130
131 $element = '<' . ilPCCurriculum::PCELEMENT . '>';
132 if (!str_contains($content, $element)) {
133 $curriculum = $this->curriculum_builder->getLearnerCurriculum();
134 $this->tpl->setRightContent(
135 $this->getWrappedHTML([$curriculum])
136 );
137 }
138 }
139
140 protected function addMember(int $usr_id): void
141 {
142 $admins = $this->roles->getLearningSequenceAdminIds();
143 if (!in_array($usr_id, $admins)) {
144 $this->roles->join($usr_id);
145 }
146 }
147
148 protected function initToolbar(string $cmd)
149 {
150 foreach ($this->launchlinks_builder->getLinks() as $entry) {
151 list($label, $link, $primary) = $entry;
152 $sub_button = ilLinkButton::getInstance();
153 $sub_button->setPrimary($primary);
154 $sub_button->setCaption($label, false);
155 $sub_button->setUrl($link);
156 $this->toolbar->addButtonInstance($sub_button);
157 }
158 }
159
160 private function getWrappedHTML(array $components): string
161 {
162 array_unshift(
163 $components,
164 $this->ui_factory->legacy('<div class="ilLSOLearnerView">')
165 );
166 $components[] = $this->ui_factory->legacy('</div>');
167
168 return $this->renderer->render($components);
169 }
170
171 private function getMainContent(string $cmd): array
172 {
173 $img = null;
174 $contents = [];
175
176 if ($cmd === self::CMD_STANDARD) {
177 if ($this->intro === '') {
178 $contents[] = $this->ui_factory->legacy($this->settings->getAbstract());
179 $img = $this->settings->getAbstractImage();
180 if ($img) {
181 $contents[] = $this->ui_factory->image()->responsive($img, '');
182 }
183 } else {
184 $contents[] = $this->ui_factory->legacy($this->intro);
185 }
186 }
187
188 if ($cmd === self::CMD_EXTRO) {
189 if ($this->extro === '') {
190 $contents[] = $this->ui_factory->legacy($this->settings->getExtro());
191 $img = $this->settings->getExtroImage();
192 if ($img) {
193 $contents[] = $this->ui_factory->image()->responsive($img, '');
194 }
195 } else {
196 $contents[] = $this->ui_factory->legacy($this->extro);
197 }
198 }
199 return $contents;
200 }
201
202 protected function play(): void
203 {
204 $response = $this->player->play($this->get);
205
206 switch ($response) {
207 case null:
208 //render the page
209 $this->tpl->setContent('THIS SHOULD NOT SHOW');
210 return;
211
212 case 'EXIT::' . $this->player::LSO_CMD_FINISH:
213 $cmd = self::CMD_EXTRO;
214 break;
215
216 case 'EXIT::' . $this->player::LSO_CMD_SUSPEND:
217 default:
218 $cmd = self::CMD_STANDARD;
219 break;
220 }
221 $href = $this->ctrl->getLinkTarget($this, $cmd, '', false, false);
222 \ilUtil::redirect($href);
223 }
224}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Implementation of KioskMode Player.
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(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, ilLSLaunchlinksBuilder $launchlinks_builder, ilLSPlayer $player, string $intro, string $extro, 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)
$img
Definition: imgupload.php:83
Interface RequestWrapper.
This is how the factory for UI elements looks.
Definition: Factory.php:38
An entity that renders components to a string output.
Definition: Renderer.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
$response