ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilLSPlayer Class Reference

Implementation of KioskMode Player. More...

+ Collaboration diagram for ilLSPlayer:

Public Member Functions

 __construct (int $lso_ref_id, string $lso_title, int $usr_id, array $items, ilLSStateDB $state_db, LSControlBuilder $control_builder, LSUrlBuilder $url_builder, ilLSCurriculumBuilder $curriculum_builder, ilLSViewFactory $view_factory, ilKioskPageRenderer $renderer, ILIAS\UI\Factory $ui_factory)
 
 render (array $get, array $post=null)
 

Data Fields

const PARAM_LSO_COMMAND = 'lsocmd'
 
const PARAM_LSO_PARAMETER = 'lsov'
 
const LSO_CMD_NEXT = 'lsonext'
 
const LSO_CMD_GOTO = 'lsogoto'
 
const LSO_CMD_SUSPEND = 'lsosuspend'
 
const LSO_CMD_FINISH = 'lsofinish'
 

Protected Member Functions

 storeState (ILIAS\KioskMode\State $state, int $state_item_ref_id, int $current_item_ref_id)
 
 updateViewState (ILIAS\KioskMode\State $state, ILIAS\KioskMode\View $view, array $get, array $post=null)
 
 getNextItem (LSLearnerItem $current_item, int $direction)
 $direction is either -1 or 1; More...
 
 findItemByRefId (int $ref_id)
 
 buildDefaultControls (LSControlBuilder $control_builder, LSLearnerItem $item, int $item_position)
 
 renderComponentView ( $state, ILIAS\KioskMode\View $view)
 

Detailed Description

Implementation of KioskMode Player.

Author
Nils Haagen nils..nosp@m.haag.nosp@m.en@co.nosp@m.ncep.nosp@m.ts-an.nosp@m.d-tr.nosp@m.ainin.nosp@m.g.de

Definition at line 13 of file class.ilLSPlayer.php.

Constructor & Destructor Documentation

◆ __construct()

ilLSPlayer::__construct ( int  $lso_ref_id,
string  $lso_title,
int  $usr_id,
array  $items,
ilLSStateDB  $state_db,
LSControlBuilder  $control_builder,
LSUrlBuilder  $url_builder,
ilLSCurriculumBuilder  $curriculum_builder,
ilLSViewFactory  $view_factory,
ilKioskPageRenderer  $renderer,
ILIAS\UI\Factory  $ui_factory 
)

Definition at line 23 of file class.ilLSPlayer.php.

35  {
36  $this->lso_ref_id = $lso_ref_id;
37  $this->lso_title = $lso_title;
38  $this->usr_id = $usr_id;
39  $this->items = $items;
40  $this->state_db = $state_db;
41  $this->control_builder = $control_builder;
42  $this->url_builder = $url_builder;
43  $this->curriculum_builder = $curriculum_builder;
44  $this->view_factory = $view_factory;
45  $this->page_renderer = $renderer;
46  $this->ui_factory = $ui_factory;
47  }

Member Function Documentation

◆ buildDefaultControls()

ilLSPlayer::buildDefaultControls ( LSControlBuilder  $control_builder,
LSLearnerItem  $item,
int  $item_position 
)
protected

Definition at line 208 of file class.ilLSPlayer.php.

References LSControlBuilder\exit(), LSControlBuilder\getExitControl(), LSControlBuilder\getNextControl(), getNextItem(), LSControlBuilder\getPreviousControl(), LSControlBuilder\next(), and LSControlBuilder\previous().

Referenced by render().

212  : ControlBuilder {
213  $is_first = $item_position === 0;
214  $is_last = $item_position === count($this->items) - 1;
215 
216  if (!$control_builder->getExitControl()) {
217  $cmd = self::LSO_CMD_SUSPEND;
218  if ($is_last) {
219  $cmd = self::LSO_CMD_FINISH;
220  }
221  $control_builder = $control_builder->exit($cmd);
222  }
223 
224  if (!$control_builder->getPreviousControl()) {
225  $direction_prev = -1;
226  $cmd = ''; //disables control
227 
228  if (!$is_first) {
229  $available = $this->getNextItem($item, $direction_prev)
230  ->getAvailability() === Step::AVAILABLE;
231 
232  if ($available) {
233  $cmd = self::LSO_CMD_NEXT;
234  }
235  }
236 
237  $control_builder = $control_builder
238  ->previous($cmd, $direction_prev);
239  }
240 
241  if (!$control_builder->getNextControl()) {
242  $direction_next = 1;
243  $cmd = '';
244  if (!$is_last) {
245  $available = $this->getNextItem($item, $direction_next)
246  ->getAvailability() === Step::AVAILABLE;
247 
248  if ($available) {
249  $cmd = self::LSO_CMD_NEXT;
250  }
251  }
252 
253  $control_builder = $control_builder
254  ->next($cmd, $direction_next);
255  }
256 
257  return $control_builder;
258  }
previous(string $command, int $parameter=null)
A previous control allows the user to go back to the previous item in the object.The $parameter can b...
getNextItem(LSLearnerItem $current_item, int $direction)
$direction is either -1 or 1;
exit(string $command)
An exit control allows the user to gracefully leave the object providing the kiosk mode...
next(string $command, int $parameter=null)
A next control allows the user to progress to the next item in the object.The $parameter can be used ...
Build controls for the view.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findItemByRefId()

ilLSPlayer::findItemByRefId ( int  $ref_id)
protected
Returns
array <int, LSLearnerItem> position=>item

Definition at line 198 of file class.ilLSPlayer.php.

References $index.

Referenced by getNextItem(), and render().

198  : array
199  {
200  foreach ($this->items as $index => $item) {
201  if ($item->getRefId() === $ref_id) {
202  return [$index, $item];
203  }
204  }
205  throw new \Exception("This is not a valid item.", 1);
206  }
$index
Definition: metadata.php:60
+ Here is the caller graph for this function:

◆ getNextItem()

ilLSPlayer::getNextItem ( LSLearnerItem  $current_item,
int  $direction 
)
protected

$direction is either -1 or 1;

Definition at line 185 of file class.ilLSPlayer.php.

References findItemByRefId(), and LSItem\getRefId().

Referenced by buildDefaultControls(), and render().

185  : LSLearnerItem
186  {
187  list($position, $item) = $this->findItemByRefId($current_item->getRefId());
188  $next = $position + $direction;
189  if ($next >= 0 && $next < count($this->items)) {
190  return $this->items[$next];
191  }
192  return $current_item;
193  }
getRefId()
Definition: LSItem.php:129
findItemByRefId(int $ref_id)
Add learning progress and availability information to the LSItem.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ render()

ilLSPlayer::render ( array  $get,
array  $post = null 
)

Definition at line 49 of file class.ilLSPlayer.php.

References $_GET, $post, $state, ILIAS\UI\Component\Listing\Workflow\Step\AVAILABLE, buildDefaultControls(), findItemByRefId(), getNextItem(), renderComponentView(), storeState(), and updateViewState().

50  {
51  //init state and current item
52  $stored = $this->state_db->getCurrentItemsFor(
53  $this->lso_ref_id,
54  [$this->usr_id]
55  );
56 
57  $current_item = $this->items[0];
58  $current_item_ref_id = $current_item->getRefId();
59 
60  if (count($stored) > 0 ||
61  $stored[$this->usr_id] > -1 //returns -1 if there is no current item
62  ) {
63  $current_item_ref_id = $stored[$this->usr_id];
64 
65  //maybe item is not available?
66  $valid_ref_ids = array_map(
67  function ($item) {
68  return $item->getRefId();
69  },
70  array_values($this->items)
71  );
72 
73  if (in_array($current_item_ref_id, $valid_ref_ids)) {
74  list($position, $current_item) = $this->findItemByRefId($current_item_ref_id);
75  }
76  }
77 
78  $command = $_GET[self::PARAM_LSO_COMMAND];
79  $param = (int) $_GET[self::PARAM_LSO_PARAMETER];
80 
81  while ($current_item->getAvailability() !== \ILIAS\UI\Component\Listing\Workflow\Step::AVAILABLE) {
82  $prev_item = $this->getNextItem($current_item, -1);
83  if ($prev_item === $current_item) {
84  throw new \Exception("Cannot view first LSO-item", 1);
85  }
86  $current_item = $prev_item;
87  }
88 
89  $view = $this->view_factory->getViewFor($current_item);
90  $state = $current_item->getState();
91  $state = $this->updateViewState($state, $view, $get, $post);
92 
93  switch ($command) {
94  case self::LSO_CMD_SUSPEND:
95  case self::LSO_CMD_FINISH:
96  //store state and exit
97  $this->storeState($state, $current_item_ref_id, $current_item_ref_id);
98  return 'EXIT::' . $command;
99  case self::LSO_CMD_NEXT:
100  $next_item = $this->getNextItem($current_item, $param);
101  if ($next_item->getAvailability() !== \ILIAS\UI\Component\Listing\Workflow\Step::AVAILABLE) {
102  $next_item = $current_item;
103  }
104  break;
105  case self::LSO_CMD_GOTO:
106  list($position, $next_item) = $this->findItemByRefId($param);
107  break;
108  default:
109  $next_item = $current_item;
110  }
111  //write State to DB
112  $this->storeState($state, $current_item_ref_id, $next_item->getRefId());
113 
114  //get proper view
115  if ($next_item !== $current_item) {
116  $view = $this->view_factory->getViewFor($next_item);
117  }
118  //get position
119  list($item_position, $item) = $this->findItemByRefId($next_item->getRefId());
120 
121  //have the view build controls
122  $control_builder = $this->control_builder;
123  $view->buildControls($state, $control_builder);
124  //amend controls not set by the view
125  $this->buildDefaultControls($control_builder, $item, $item_position);
126 
127  //content
128  $obj_title = $next_item->getTitle();
129  $icon = $this->ui_factory->icon()
130  ->standard($next_item->getType(), $next_item->getType(), 'medium');
131 
132  $curriculum = $this->curriculum_builder->getLearnerCurriculum(true)
133  ->withActive($item_position);
134 
135  $content = $this->renderComponentView($state, $view);
136  $panel = $this->ui_factory->panel()->standard(
137  '', //panel_title
138  $content
139  );
140  $content = [$panel];
141 
142  return $this->page_renderer->render(
143  $this->lso_title,
144  $control_builder,
145  $obj_title,
146  $icon,
147  $content,
148  $curriculum
149  );
150  }
updateViewState(ILIAS\KioskMode\State $state, ILIAS\KioskMode\View $view, array $get, array $post=null)
$_GET["client_id"]
getNextItem(LSLearnerItem $current_item, int $direction)
$direction is either -1 or 1;
storeState(ILIAS\KioskMode\State $state, int $state_item_ref_id, int $current_item_ref_id)
findItemByRefId(int $ref_id)
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
$post
Definition: post.php:34
buildDefaultControls(LSControlBuilder $control_builder, LSLearnerItem $item, int $item_position)
renderComponentView( $state, ILIAS\KioskMode\View $view)
+ Here is the call graph for this function:

◆ renderComponentView()

ilLSPlayer::renderComponentView (   $state,
ILIAS\KioskMode\View  $view 
)
protected

Definition at line 260 of file class.ilLSPlayer.php.

References $state.

Referenced by render().

263  {
264  $component = $view->render(
265  $state,
266  $this->ui_factory,
267  $this->url_builder,
268  []
269  );
270  return $component;
271  }
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
+ Here is the caller graph for this function:

◆ storeState()

ilLSPlayer::storeState ( ILIAS\KioskMode\State  $state,
int  $state_item_ref_id,
int  $current_item_ref_id 
)
protected

Definition at line 152 of file class.ilLSPlayer.php.

Referenced by render().

156  {
157  $this->state_db->updateState(
158  $this->lso_ref_id,
159  $this->usr_id,
160  $state_item_ref_id,
161  $state,
162  $current_item_ref_id
163  );
164  }
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
+ Here is the caller graph for this function:

◆ updateViewState()

ilLSPlayer::updateViewState ( ILIAS\KioskMode\State  $state,
ILIAS\KioskMode\View  $view,
array  $get,
array  $post = null 
)
protected

Definition at line 166 of file class.ilLSPlayer.php.

References $_GET, and $state.

Referenced by render().

172  //get view internal command
173  $command = $_GET[self::PARAM_LSO_COMMAND];
174  $param = (int) $_GET[self::PARAM_LSO_PARAMETER];
175  if (!is_null($command)) {
176  $state = $view->updateGet($state, $command, $param);
177  }
178  //$state = $view->updatePOST($state, $command, $post);
179  return $state;
180  }
$_GET["client_id"]
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
+ Here is the caller graph for this function:

Field Documentation

◆ LSO_CMD_FINISH

const ilLSPlayer::LSO_CMD_FINISH = 'lsofinish'

Definition at line 21 of file class.ilLSPlayer.php.

Referenced by LSControlBuilder\exit().

◆ LSO_CMD_GOTO

const ilLSPlayer::LSO_CMD_GOTO = 'lsogoto'

Definition at line 19 of file class.ilLSPlayer.php.

Referenced by ilObjLearningSequence\getCurriculumBuilder().

◆ LSO_CMD_NEXT

const ilLSPlayer::LSO_CMD_NEXT = 'lsonext'

Definition at line 18 of file class.ilLSPlayer.php.

◆ LSO_CMD_SUSPEND

const ilLSPlayer::LSO_CMD_SUSPEND = 'lsosuspend'

Definition at line 20 of file class.ilLSPlayer.php.

◆ PARAM_LSO_COMMAND

const ilLSPlayer::PARAM_LSO_COMMAND = 'lsocmd'

Definition at line 15 of file class.ilLSPlayer.php.

◆ PARAM_LSO_PARAMETER

const ilLSPlayer::PARAM_LSO_PARAMETER = 'lsov'

Definition at line 16 of file class.ilLSPlayer.php.


The documentation for this class was generated from the following file: