ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilLearnerProgressDB.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
12{
16 protected $items_db;
20 protected $access;
21
23 protected $obj_data_cache;
24
25 public function __construct(
29 ) {
30 $this->items_db = $items_db;
31 $this->access = $access;
32 $this->obj_data_cache = $obj_data_cache;
33 }
37 public function getLearnerItems(int $usr_id, int $container_ref_id) : array
38 {
39 $items = [];
40 $ls_items = $this->items_db->getLSItems($container_ref_id);
41
42 foreach ($ls_items as $ls_item) {
43 if ($this->isItemVisibleForUser($usr_id, $ls_item) === false) {
44 continue;
45 }
46 $lp = $this->getLearningProgressFor($usr_id, $ls_item);
47 $av = $this->getAvailabilityFor($usr_id, $ls_item);
48 $items[] = new LSLearnerItem($usr_id, $lp, $av, $ls_item);
49 }
50
51 return $items;
52 }
53
54 protected function getObjIdForRefId(int $ref_id) : int
55 {
56 return (int) $this->obj_data_cache->lookupObjId($ref_id);
57 }
58
59 protected function getLearningProgressFor(int $usr_id, LSItem $ls_item) : int
60 {
61 $obj_id = $this->getObjIdForRefId($ls_item->getRefId());
62
64 if (ilObjectLP::isSupportedObjectType($this->obj_data_cache->lookupType($obj_id))) {
65 $il_lp_status = ilLPStatus::_lookupStatus($obj_id, $usr_id, true);
66 }
67 return (int) $il_lp_status;
68 }
69
70 protected function isItemVisibleForUser(int $usr_id, LSItem $ls_item) : bool
71 {
72 $online = $ls_item->isOnline();
73 $access = $this->access->checkAccessOfUser(
74 $usr_id,
75 "visible",
76 "",
77 $ls_item->getRefId()
78 );
79 return ($online && $access);
80 }
81
82 protected function getAvailabilityFor(int $usr_id, LSItem $ls_item) : int
83 {
84 $this->access->clear(); //clear access cache; condition-checks refer to previous state otherwise.
85 $readable = $this->access->checkAccessOfUser($usr_id, 'read', '', $ls_item->getRefId());
86 if ($readable) {
88 }
90 }
91}
An exception for terminatinating execution or to throw for unit testing.
Data holding class LSItem .
Definition: LSItem.php:12
getRefId()
Definition: LSItem.php:129
isOnline()
Definition: LSItem.php:93
Add learning progress and availability information to the LSItem.
Class ilAccessHandler.
static _lookupStatus($a_obj_id, $a_user_id, $a_create=true)
Lookup status.
const LP_STATUS_NOT_ATTEMPTED_NUM
Class ilLSItemsDB.
Definition: ilLSItemsDB.php:12
Get LearningProgress and availability of items in sequence.
isItemVisibleForUser(int $usr_id, LSItem $ls_item)
getLearningProgressFor(int $usr_id, LSItem $ls_item)
getLearnerItems(int $usr_id, int $container_ref_id)
Decorate LSItems with learning progress and availability (from conditions)
__construct(ilLSItemsDB $items_db, ilAccess $access, ilObjectDataCache $obj_data_cache)
getAvailabilityFor(int $usr_id, LSItem $ls_item)
class ilObjectDataCache
static isSupportedObjectType($type)