ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilLearnerProgressDB.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 {
27  protected ilAccess $access;
29 
30  public function __construct(
31  ilLSItemsDB $items_db,
32  ilAccess $access,
33  ilObjectDataCache $obj_data_cache
34  ) {
35  $this->items_db = $items_db;
36  $this->access = $access;
37  $this->obj_data_cache = $obj_data_cache;
38  }
39 
45  public function getLearnerItems(int $usr_id, int $container_ref_id): array
46  {
47  $items = [];
48  $ls_items = $this->items_db->getLSItems($container_ref_id);
49 
50  foreach ($ls_items as $ls_item) {
51  if ($this->isItemVisibleForUser($usr_id, $ls_item) === false) {
52  continue;
53  }
54  $lp = $this->getLearningProgressFor($usr_id, $ls_item);
55  $av = $this->getAvailabilityFor($usr_id, $ls_item);
56  $items[] = new LSLearnerItem($usr_id, $lp, $av, $ls_item);
57  }
58 
59  return $items;
60  }
61 
62  protected function getObjIdForRefId(int $ref_id): int
63  {
64  return ilObject::_lookupObjId($ref_id);
65  }
66 
67  protected function getLearningProgressFor(int $usr_id, LSItem $ls_item): int
68  {
69  $obj_id = $this->getObjIdForRefId($ls_item->getRefId());
70 
72  if (ilObjectLP::isSupportedObjectType($this->obj_data_cache->lookupType($obj_id))) {
73  $il_lp_status = ilLPStatus::_lookupStatus($obj_id, $usr_id, true);
74  }
75  return (int) $il_lp_status;
76  }
77 
78  protected function isItemVisibleForUser(int $usr_id, LSItem $ls_item): bool
79  {
80  $online = $ls_item->isOnline();
81  $access = $this->access->checkAccessOfUser(
82  $usr_id,
83  "visible",
84  "",
85  $ls_item->getRefId()
86  );
87  return ($online && $access);
88  }
89 
90  protected function getAvailabilityFor(int $usr_id, LSItem $ls_item): int
91  {
92  $this->access->clear(); //clear access cache; condition-checks refer to previous state otherwise.
93  $readable = $this->access->checkAccessOfUser($usr_id, 'read', '', $ls_item->getRefId());
94  if ($readable) {
96  }
98  }
99 }
getLearningProgressFor(int $usr_id, LSItem $ls_item)
static isSupportedObjectType(string $type)
Class ilLSItemsDB.
Definition: ilLSItemsDB.php:24
isItemVisibleForUser(int $usr_id, LSItem $ls_item)
getRefId()
Definition: LSItem.php:93
getLearnerItems(int $usr_id, int $container_ref_id)
Decorate LSItems with learning progress and availability (from conditions)
ilObjectDataCache $obj_data_cache
static _lookupObjId(int $ref_id)
getAvailabilityFor(int $usr_id, LSItem $ls_item)
isOnline()
Definition: LSItem.php:78
Data holding class LSItem .
Definition: LSItem.php:24
$ref_id
Definition: ltiauth.php:65
static _lookupStatus(int $a_obj_id, int $a_user_id, bool $a_create=true)
Lookup status.
const LP_STATUS_NOT_ATTEMPTED_NUM
__construct(ilLSItemsDB $items_db, ilAccess $access, ilObjectDataCache $obj_data_cache)
Get LearningProgress and availability of items in sequence.
Add learning progress and availability information to the LSItem.