ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilLearnerProgressDB.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
12 {
16  protected $state_db;
17 
18  public function __construct(ilLSStateDB $state_db, ilAccess $access)
19  {
20  $this->state_db = $state_db;
21  $this->access = $access;
22  }
23 
28  public function getLearnerItems(int $usr_id, int $container_ref_id, array $ls_items) : array
29  {
30  $items = [];
31  $states = $this->state_db->getStatesFor($container_ref_id, [$usr_id]);
32  foreach ($ls_items as $ls_item) {
33  if ($this->isItemVisibleForUser($usr_id, $ls_item) === false) {
34  continue;
35  }
36  $lp_refresher = $this->getLPStatusRefresher();
37  $av = $this->getAvailabilityFor($usr_id, $ls_item);
38  $state = $this->getStateFor($ls_item, $states[$usr_id]);
39  $items[] = new LSLearnerItem($usr_id, $lp_refresher, $av, $state, $ls_item);
40  }
41 
42  return $items;
43  }
44 
45  protected function getLPStatusRefresher(): \Closure {
46  return function(int $ref_id, int $usr_id) {
47  $obj_id = ilObject::_lookupObjId($ref_id);
48  return (int)ilLPStatus::_lookupStatus($obj_id, $usr_id, true);
49  };
50  }
51 
52 
53  protected function getObjIdForRefId(int $ref_id) : int
54  {
55  return (int) ilObject::_lookupObjId($ref_id);
56  }
57 
58  protected function getStateFor(LSItem $ls_item, array $states) : ILIAS\KioskMode\State
59  {
60  if (array_key_exists($ls_item->getRefId(), $states)) {
61  return $states[$ls_item->getRefId()];
62  }
63 
64  return new ILIAS\KioskMode\State();
65  }
66 
67  protected function getLearningProgressFor(int $usr_id, LSItem $ls_item) : int
68  {
69  $obj_id = $this->getObjIdForRefId($ls_item->getRefId());
70  $il_lp_status = ilLPStatus::_lookupStatus($obj_id, $usr_id, true);
71 
72  return (int) $il_lp_status;
73  }
74 
75  protected function isItemVisibleForUser(int $usr_id, LSItem $ls_item) : bool
76  {
77  $online = $ls_item->isOnline();
78  $access = $this->access->checkAccessOfUser(
79  $usr_id,
80  "visible",
81  "",
82  $ls_item->getRefId()
83  );
84 
85  if (!($online && $access)) {
86  return false;
87  }
88 
89  return true;
90  }
91 
92  protected function getAvailabilityFor(int $usr_id, LSItem $ls_item) : int
93  {
94  $readable = $this->access->checkAccessOfUser($usr_id, 'read', '', $ls_item->getRefId());
95  if ($readable) {
97  }
98 
100  }
101 }
getLearningProgressFor(int $usr_id, LSItem $ls_item)
Class BaseForm.
isItemVisibleForUser(int $usr_id, LSItem $ls_item)
getRefId()
Definition: LSItem.php:129
Class ilAccessHandler.
getAvailabilityFor(int $usr_id, LSItem $ls_item)
isOnline()
Definition: LSItem.php:93
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
Data holding class LSItem .
Definition: LSItem.php:11
static _lookupObjId($a_id)
Persistence for View-States.
Get LearningProgress and availability of items in sequence.
__construct(ilLSStateDB $state_db, ilAccess $access)
getStateFor(LSItem $ls_item, array $states)
getLearnerItems(int $usr_id, int $container_ref_id, array $ls_items)
Decorate LSItems with learning progress, availability (from conditions) kiosk-mode state information...
static _lookupStatus($a_obj_id, $a_user_id, $a_create=true)
Lookup status.
Add learning progress and availability information to the LSItem.