ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
class.ilLSLearnerItemsQueries.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28{
31 protected int $ls_ref_id;
32 protected int $usr_id;
33
34 public function __construct(
37 int $ls_ref_id,
38 int $usr_id
39 ) {
40 $this->progress_db = $progress_db;
41 $this->states_db = $states_db;
42 $this->ls_ref_id = $ls_ref_id;
43 $this->usr_id = $usr_id;
44 }
45
46 public function getLearningSequenceRefId(): int
47 {
48 return $this->ls_ref_id;
49 }
50
51 public function hasItems(): bool
52 {
53 return count($this->getItems()) > 0;
54 }
55
59 public function getItems(): array
60 {
61 return $this->progress_db->getLearnerItems($this->usr_id, $this->ls_ref_id);
62 }
63
64 public function getCurrentItemRefId(): int
65 {
66 $current = $this->states_db->getCurrentItemsFor($this->ls_ref_id, [$this->usr_id]); //0 or greater
67 return max(0, $current[$this->usr_id]);
68 }
69
70 public function getCurrentItemPosition(): int
71 {
72 $current_position = 0;
73 $items = $this->getItems();
74 foreach ($items as $index => $item) {
75 if ($item->getRefId() === $this->getCurrentItemRefId()) {
76 $current_position = $index;
77 }
78 }
79 return $current_position;
80 }
81
82 public function getStateFor(LSItem $ls_item, View $view): ILIAS\KioskMode\State
83 {
84 $states = $this->states_db->getStatesFor($this->ls_ref_id, [$this->usr_id]);
85 $states = $states[$this->usr_id];
86
87 if (array_key_exists($ls_item->getRefId(), $states)) {
88 return $states[$ls_item->getRefId()];
89 }
90 return $view->buildInitialState(
91 new ILIAS\KioskMode\State()
92 );
93 }
94
95 public function storeState(
96 ILIAS\KioskMode\State $state,
97 int $state_item_ref_id,
98 int $current_item_ref_id
99 ): void {
100 $this->states_db->updateState(
101 $this->ls_ref_id,
102 $this->usr_id,
103 $state_item_ref_id,
104 $state,
105 $current_item_ref_id
106 );
107 }
108
109 public function getFirstAccess(): string
110 {
111 $first_access = $this->states_db->getFirstAccessFor($this->ls_ref_id, [$this->usr_id]);
112 return $first_access[$this->usr_id];
113 }
114}
Data holding class LSItem .
Definition: LSItem.php:25
getRefId()
Definition: LSItem.php:93
This combines calls to ProgressDB and StateDB to handle learner-items in the context of a specific LS...
getStateFor(LSItem $ls_item, 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.
A kiosk mode view on a certain object.
Definition: View.php:31
buildInitialState(State $empty_state)
Build an initial state based on the Provided empty state.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.