ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilLSItemsQueries.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2
10{
11 public function __construct(
12 ilLearnerProgressDB $progress_db,
13 ilLSStateDB $states_db,
14 int $ls_ref_id,
15 int $usr_id
16 ) {
17 $this->progress_db = $progress_db;
18 $this->states_db = $states_db;
19 $this->ls_ref_id = $ls_ref_id;
20 $this->usr_id = $usr_id;
21 }
22
26 public function getItems() : array
27 {
28 return $this->progress_db->getLearnerItems($this->usr_id, $this->ls_ref_id);
29 }
30
31 public function getCurrentItemRefId() : int
32 {
33 $current = $this->states_db->getCurrentItemsFor($this->ls_ref_id, [$this->usr_id]);
34 $ref_id = max(0, $current[$this->usr_id]); //0 or greater
35 return $ref_id;
36 }
37
38 public function getCurrentItemPosition() : int
39 {
40 $current_position = 0;
41 $items = $this->getItems();
42 foreach ($items as $index => $item) {
43 if ($item->getRefId() === $this->getCurrentItemRefId()) {
44 $current_position = $index;
45 }
46 }
47 return $current_position;
48 }
49
50 public function getStateFor(LSItem $ls_item, \ILIAS\KioskMode\View $view) : ILIAS\KioskMode\State
51 {
52 $states = $this->states_db->getStatesFor($this->ls_ref_id, [$this->usr_id]);
53 $states = $states[$this->usr_id];
54
55 if (array_key_exists($ls_item->getRefId(), $states)) {
56 return $states[$ls_item->getRefId()];
57 }
58 return $view->buildInitialState(
59 new ILIAS\KioskMode\State()
60 );
61 }
62
63 public function storeState(
64 ILIAS\KioskMode\State $state,
65 int $state_item_ref_id,
66 int $current_item_ref_id
67 ) {
68 $this->states_db->updateState(
69 $this->ls_ref_id,
70 $this->usr_id,
71 $state_item_ref_id,
72 $state,
73 $current_item_ref_id
74 );
75 }
76
77 public function getFirstAccess()
78 {
79 $first_access = $this->states_db->getFirstAccessFor($this->ls_ref_id, [$this->usr_id]);
80 return $first_access[$this->usr_id];
81 }
82}
An exception for terminatinating execution or to throw for unit testing.
Data holding class LSItem .
Definition: LSItem.php:12
getRefId()
Definition: LSItem.php:129
This combines calls to ProgressDB and StateDB to handle learner-items in the context of a specific LS...
getStateFor(LSItem $ls_item, \ILIAS\KioskMode\View $view)
__construct(ilLearnerProgressDB $progress_db, ilLSStateDB $states_db, int $ls_ref_id, int $usr_id)
storeState(ILIAS\KioskMode\State $state, int $state_item_ref_id, int $current_item_ref_id)
Persistence for View-States.
Get LearningProgress and availability of items in sequence.
$index
Definition: metadata.php:128
Class ChatMainBarProvider \MainMenu\Provider.