ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilObjLearningSequenceLearnerGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
7 
12 {
13  const CMD_STANDARD = 'learnerView';
14  const CMD_EXTRO = 'learnerViewFinished';
15  const CMD_UNSUBSCRIBE = 'unsubscribe';
16  const CMD_VIEW = 'view';
17  const CMD_START = 'start';
18  const PARAM_LSO_NEXT_ITEM = 'lsoni';
19  const LSO_CMD_NEXT = 'lson';
20  const LSO_CMD_PREV = 'lsop';
21 
25  protected $ls_learner_items;
26 
27  public function __construct(
28  ilObjLearningSequence $ls_object,
29  int $usr_id,
30  array $ls_learner_items,
31  int $current_item,
32  ilCtrl $ctrl,
35  ilToolbarGUI $toolbar,
36  ILIAS\UI\Factory $ui_factory,
37  ILIAS\UI\Renderer $ui_renderer
38  ) {
39  $this->ls_object = $ls_object;
40  $this->usr_id = $usr_id;
41  $this->ls_learner_items = $ls_learner_items;
42  $this->current_item = $current_item;
43  $this->ctrl = $ctrl;
44  $this->lng = $lng;
45  $this->tpl = $tpl;
46  $this->toolbar = $toolbar;
47  $this->ui_factory = $ui_factory;
48  $this->renderer = $ui_renderer;
49  }
50 
51  public function executeCommand()
52  {
53  $cmd = $this->ctrl->getCmd();
54  switch ($cmd) {
55  case self::CMD_STANDARD:
56  case self::CMD_EXTRO:
57  $this->view($cmd);
58  break;
59  case self::CMD_START:
60  $this->addMember($this->usr_id);
61  $this->ctrl->redirect($this, self::CMD_VIEW);
62  break;
63  case self::CMD_UNSUBSCRIBE:
64  if ($this->ls_object->userMayUnparticipate()) {
65  $this->removeMember($this->usr_id);
66  }
67  $this->ctrl->redirect($this, self::CMD_STANDARD);
68  break;
69  case self::CMD_VIEW:
70  $this->play();
71  break;
72 
73  default:
74  throw new ilException(
75  "ilObjLearningSequenceLearnerGUI: " .
76  "Command not supported: $cmd"
77  );
78  }
79  }
80 
81  protected function view(string $cmd)
82  {
83  $content = $this->getWrappedHTML($this->getMainContent($cmd));
84  $curriculum = $this->getWrappedHTML($this->getCurriculum());
85 
86  $this->initToolbar($cmd);
87  $this->tpl->setContent($content);
88  $this->tpl->setRightContent($curriculum);
89  }
90 
91  protected function addMember(int $usr_id)
92  {
93  $admins = $this->ls_object->getLearningSequenceAdminIds();
94  if (!in_array($usr_id, $admins)) {
95  $this->ls_object->join($usr_id);
96  }
97  }
98 
99  protected function removeMember(int $usr_id)
100  {
101  $this->ls_object->leave($usr_id);
102  }
103 
104  protected function initToolbar(string $cmd)
105  {
106  $is_member = $this->ls_object->isMember($this->usr_id);
107  $completed = $this->ls_object->isCompletedByUser($this->usr_id);
108  $has_items = count($this->ls_learner_items) > 0;
109 
110  if (!$is_member) {
111  if ($has_items) {
112  $may_subscribe = $this->ls_object->userMayJoin();
113  if ($may_subscribe) {
114  $this->toolbar->addButton(
115  $this->lng->txt("lso_player_start"),
116  $this->ctrl->getLinkTarget($this, self::CMD_START)
117  );
118  }
119  }
120  } else {
121  if (!$completed) {
122  if ($has_items) {
123  $state_db = $this->ls_object->getStateDB();
124  $obj_ref_id = (int) $this->ls_object->getRefId();
125  $first_access = $state_db->getFirstAccessFor(
126  $obj_ref_id,
127  array($this->usr_id)
128  )[$this->usr_id];
129 
130  $label = "lso_player_resume";
131  if ($first_access === -1) {
132  $label = "lso_player_start";
133  }
134 
135  $this->toolbar->addButton(
136  $this->lng->txt($label),
137  $this->ctrl->getLinkTarget($this, self::CMD_VIEW)
138  );
139  }
140  } else {
141  if ($has_items) {
142  $this->toolbar->addButton(
143  $this->lng->txt("lso_player_review"),
144  $this->ctrl->getLinkTarget($this, self::CMD_VIEW)
145  );
146  }
147  if ($cmd === self::CMD_STANDARD) {
148  $this->toolbar->addButton(
149  $this->lng->txt("lso_player_extro"),
150  $this->ctrl->getLinkTarget($this, self::CMD_EXTRO)
151  );
152  }
153  if ($cmd === self::CMD_EXTRO) {
154  $this->toolbar->addButton(
155  $this->lng->txt("lso_player_abstract"),
156  $this->ctrl->getLinkTarget($this, self::CMD_STANDARD)
157  );
158  }
159  }
160 
161  $may_unsubscribe = $this->ls_object->userMayUnparticipate();
162  if ($may_unsubscribe) {
163  $this->toolbar->addButton(
164  $this->lng->txt("unparticipate"),
165  $this->ctrl->getLinkTarget($this, self::CMD_UNSUBSCRIBE)
166  );
167  }
168  }
169  }
170 
171  private function getWrappedHTML(array $components) : string
172  {
173  array_unshift(
174  $components,
175  $this->ui_factory->legacy('<div class="ilLSOLearnerView">')
176  );
177  $components[] = $this->ui_factory->legacy('</div>');
178 
179  return $this->renderer->render($components);
180  }
181 
182  private function getCurriculum() : array
183  {
184  $current_position = 0;
185  foreach ($this->ls_learner_items as $index => $item) {
186  if ($item->getRefId() === $this->current_item) {
187  $current_position = $index;
188  }
189  }
190 
191  $curriculum = $this->ls_object
192  ->getCurriculumBuilder($this->ls_learner_items)
193  ->getLearnerCurriculum();
194 
195  if (count($this->ls_learner_items) > 0) {
196  $curriculum = $curriculum->withActive($current_position);
197  }
198  return array($curriculum);
199  }
200 
201  private function getMainContent(string $cmd) : array
202  {
203  $settings = $this->ls_object->getLSSettings();
204 
205  if ($cmd === self::CMD_STANDARD) {
206  $txt = $settings->getAbstract();
207  $img = $settings->getAbstractImage();
208  }
209 
210  if ($cmd === self::CMD_EXTRO) {
211  $txt = $settings->getExtro();
212  $img = $settings->getExtroImage();
213  }
214 
215  $contents = [$this->ui_factory->legacy($txt)];
216  if (!is_null($img)) {
217  $contents[] = $this->ui_factory->image()->responsive($img, '');
218  }
219 
220  return $contents;
221  }
222 
223 
224  protected function play()
225  {
226  //enforce tree is visible/active for ToC
227  //(this does not work for first item, since there is no page-change)
228  //how is this done?
229 
230  if (!$_SESSION["lso_old_il_rep_mode"]) {
231  $_SESSION["lso_old_il_rep_mode"] = $_SESSION["il_rep_mode"];
232  }
233  $_SESSION["il_rep_mode"] = 'tree';
234 
235 
236  $player = $this->ls_object->getSequencePlayer(
237  $this,
238  self::CMD_VIEW,
239  $this->usr_id
240  );
241  $html = $player->render($_GET, $_POST);
242 
243  if ($html === 'EXIT::' . $player::LSO_CMD_SUSPEND) {
244  $cmd = self::CMD_STANDARD;
245  }
246  if ($html === 'EXIT::' . $player::LSO_CMD_FINISH) {
247  $cmd = self::CMD_EXTRO;
248  }
249  if (is_null($html)) {
250  $cmd = self::CMD_STANDARD;
251  }
252 
253  if (is_null($cmd)) {
254  print $html;
255  exit();
256  } else {
257  $_SESSION["il_rep_mode"] = $_SESSION["lso_old_il_rep_mode"];
258 
259  $href = $this->ctrl->getLinkTarget($this, $cmd, '', false, false);
260  \ilUtil::redirect($href);
261  }
262  }
263 }
An entity that renders components to a string output.
Definition: Renderer.php:14
This class provides processing control methods.
Class Factory.
$_SESSION["AccountId"]
$_GET["client_id"]
$tpl
Definition: ilias.php:10
Class ilObjLearningSequence.
Class BaseForm.
Class ilObjLearningSequenceLearnerGUI.
$index
Definition: metadata.php:60
__construct(ilObjLearningSequence $ls_object, int $usr_id, array $ls_learner_items, int $current_item, ilCtrl $ctrl, ilLanguage $lng, ilTemplate $tpl, ilToolbarGUI $toolbar, ILIAS\UI\Factory $ui_factory, ILIAS\UI\Renderer $ui_renderer)
$lng
This is how the factory for UI elements looks.
Definition: Factory.php:15
special template class to simplify handling of ITX/PEAR
$txt
Definition: error.php:11
exit
Definition: backend.php:16
language handling
static redirect($a_script)
$_POST["username"]
$html
Definition: example_001.php:87