ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjLearningSequenceLearnerGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
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 public function __construct(
35 protected int $usr_id,
36 protected ilAccess $access,
37 protected ilCtrl $ctrl,
38 protected ilLanguage $lng,
39 protected ilGlobalTemplateInterface $tpl,
40 protected ilToolbarGUI $toolbar,
41 protected ILIAS\UI\Factory $ui_factory,
42 protected ILIAS\UI\Renderer $renderer,
43 protected ilLearningSequenceRoles $roles,
44 protected ilLearningSequenceSettings $settings,
45 protected ilLSCurriculumBuilder $curriculum_builder,
46 protected ilLSLaunchlinksBuilder $launchlinks_builder,
47 protected ilLSPlayer $player,
48 protected string $intro,
49 protected string $extro,
50 protected RequestWrapper $get
51 ) {
52 }
53
54 public function executeCommand(): void
55 {
56 $cmd = $this->ctrl->getCmd();
57 switch ($cmd) {
59 case self::CMD_EXTRO:
60 $this->view($cmd);
61 break;
62 case self::CMD_START:
63 $this->addMember($this->usr_id);
64 $this->ctrl->redirect($this, self::CMD_VIEW);
65 break;
67 if ($this->launchlinks_builder->currentUserMayUnparticipate()) {
68 $this->roles->leave($this->usr_id);
69 }
70 $this->ctrl->redirect($this, self::CMD_STANDARD);
71 break;
72 case self::CMD_VIEW:
73 $this->play();
74 break;
75
76 default:
77 throw new ilException(
78 "ilObjLearningSequenceLearnerGUI: " .
79 "Command not supported: $cmd"
80 );
81 }
82 }
83
84 protected function view(string $cmd): void
85 {
86 $content = $this->getWrappedHTML(
87 $this->getMainContent($cmd)
88 );
89
90 $this->tpl->setContent($content);
91
92 $element = '<' . ilPCLauncher::PCELEMENT . '>';
93 if (!str_contains($content, $element)) {
94 $this->initToolbar($cmd);
95 }
96
97 $element = '<' . ilPCCurriculum::PCELEMENT . '>';
98 if (!str_contains($content, $element)) {
99 $curriculum = $this->curriculum_builder->getLearnerCurriculum();
100 $this->tpl->setRightContent(
101 $this->getWrappedHTML([$curriculum])
102 );
103 }
104 }
105
106 protected function addMember(int $usr_id): void
107 {
108 $admins = $this->roles->getLearningSequenceAdminIds();
109 if (!in_array($usr_id, $admins)) {
110 $this->roles->join($usr_id);
111 }
112 }
113
114 protected function initToolbar(string $cmd)
115 {
116 foreach ($this->launchlinks_builder->getLinks() as $entry) {
117 list($label, $link, $primary) = $entry;
118
119 if ($primary) {
120 $btn = $this->ui_factory->button()->primary($label, $link);
121 } else {
122 $btn = $this->ui_factory->button()->standard($label, $link);
123 }
124 $this->toolbar->addComponent($btn);
125 }
126 }
127
128 private function getWrappedHTML(array $components): string
129 {
130 array_unshift(
132 $this->ui_factory->legacy()->content('<div class="ilLSOLearnerView">')
133 );
134 $components[] = $this->ui_factory->legacy()->content('</div>');
135
136 return $this->renderer->render($components);
137 }
138
139 private function getMainContent(string $cmd): array
140 {
141 $img = null;
142 $contents = [];
143
144 if ($cmd === self::CMD_STANDARD) {
145 if ($this->intro === '') {
146 $contents[] = $this->ui_factory->legacy()->content($this->settings->getAbstract());
147 $img = $this->settings->getAbstractImage();
148 if ($img) {
149 $contents[] = $this->ui_factory->image()->responsive($img, '');
150 }
151 } else {
152 $contents[] = $this->ui_factory->legacy()->content($this->intro);
153 }
154 }
155
156 if ($cmd === self::CMD_EXTRO) {
157 if ($this->extro === '') {
158 $contents[] = $this->ui_factory->legacy()->content($this->settings->getExtro());
159 $img = $this->settings->getExtroImage();
160 if ($img) {
161 $contents[] = $this->ui_factory->image()->responsive($img, '');
162 }
163 } else {
164 $contents[] = $this->ui_factory->legacy()->content($this->extro);
165 }
166 }
167 return $contents;
168 }
169
170 protected function play(): void
171 {
172 $response = $this->player->play($this->get);
173
174 switch ($response) {
175 case null:
176 //render the page
177 $this->tpl->setContent($this->lng->txt('lso_player_noitems'));
178 return;
179
180 case 'EXIT::' . $this->player::LSO_CMD_FINISH:
181 $cmd = self::CMD_EXTRO;
182 break;
183
184 case 'EXIT::' . $this->player::LSO_CMD_SUSPEND:
185 default:
186 $cmd = self::CMD_STANDARD;
187 break;
188 }
189 $href = $this->ctrl->getLinkTarget($this, $cmd, '', false, false);
190 \ilUtil::redirect($href);
191 }
192}
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.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $lng
Definition: privfeed.php:31
$response
Definition: xapitoken.php:93