ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 hasItems() : bool
47 {
48 return count($this->getItems()) > 0;
49 }
50
54 public function getItems(): array
55 {
56 return $this->progress_db->getLearnerItems($this->usr_id, $this->ls_ref_id);
57 }
58
59 public function getCurrentItemRefId(): int
60 {
61 $current = $this->states_db->getCurrentItemsFor($this->ls_ref_id, [$this->usr_id]); //0 or greater
62 return max(0, $current[$this->usr_id]);
63 }
64
65 public function getCurrentItemPosition(): int
66 {
67 $current_position = 0;
68 $items = $this->getItems();
69 foreach ($items as $index => $item) {
70 if ($item->getRefId() === $this->getCurrentItemRefId()) {
71 $current_position = $index;
72 }
73 }
74 return $current_position;
75 }
76
77 public function getStateFor(LSItem $ls_item, View $view): ILIAS\KioskMode\State
78 {
79 $states = $this->states_db->getStatesFor($this->ls_ref_id, [$this->usr_id]);
80 $states = $states[$this->usr_id];
81
82 if (array_key_exists($ls_item->getRefId(), $states)) {
83 return $states[$ls_item->getRefId()];
84 }
85 return $view->buildInitialState(
86 new ILIAS\KioskMode\State()
87 );
88 }
89
90 public function storeState(
91 ILIAS\KioskMode\State $state,
92 int $state_item_ref_id,
93 int $current_item_ref_id
94 ): void {
95 $this->states_db->updateState(
96 $this->ls_ref_id,
97 $this->usr_id,
98 $state_item_ref_id,
99 $state,
100 $current_item_ref_id
101 );
102 }
103
104 public function getFirstAccess(): string
105 {
106 $first_access = $this->states_db->getFirstAccessFor($this->ls_ref_id, [$this->usr_id]);
107 return $first_access[$this->usr_id];
108 }
109}
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.