ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilLPStatusCollectionTLT.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=0);
4 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
5 
11 {
12  public static function _getInProgress(int $a_obj_id): array
13  {
14  $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
15 
16  $users = array();
17  if (isset($status_info['in_progress'])) {
18  foreach ($status_info['in_progress'] as $in_progress) {
19  $users = array_merge($users, $in_progress);
20  }
21  $users = array_unique($users);
22  }
23 
24  $users = array_diff(
25  $users,
27  );
28 
29  return $users;
30  }
31 
32  public static function _getCompleted(int $a_obj_id): array
33  {
34  $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
35 
36  $counter = 0;
37  $users = array();
38  foreach ($status_info['items'] as $item_id) {
39  $tmp_users = $status_info['completed'][$item_id];
40 
41  if (!$counter++) {
42  $users = $tmp_users;
43  } else {
44  $users = array_intersect($users, $tmp_users);
45  }
46  }
47  $users = array_unique($users);
48 
49  return $users;
50  }
51 
52  public static function _getStatusInfo(int $a_obj_id): array
53  {
54  global $DIC;
55 
56  $ilDB = $DIC['ilDB'];
57  $status_info = array();
58  $olp = ilObjectLP::getInstance($a_obj_id);
59  $collection = $olp->getCollectionInstance();
60  if ($collection) {
61  // @todo check if obj_id can be removed
62  $status_info["items"] = $collection->getItems($a_obj_id);
63 
64  foreach ($status_info["items"] as $item_id) {
65  $status_info["in_progress"][$item_id] = array();
66  $status_info["completed"][$item_id] = array();
67 
68  $status_info["tlt"][$item_id] = ilMDEducational::_getTypicalLearningTimeSeconds(
69  $a_obj_id,
70  $item_id
71  );
72  }
73 
74  $ref_ids = ilObject::_getAllReferences($a_obj_id);
75  $ref_id = end($ref_ids);
76  $possible_items = $collection->getPossibleItems($ref_id);
77  $chapter_ids = array_intersect(
78  array_keys($possible_items),
79  $status_info["items"]
80  );
81 
82  // fix order (adapt from possible items)
83  $status_info["items"] = $chapter_ids;
84 
85  if ($chapter_ids) {
86  foreach ($chapter_ids as $item_id) {
87  $status_info["item_titles"][$item_id] = $possible_items[$item_id]["title"];
88  }
89 
90  $set = $ilDB->query(
91  "SELECT obj_id,usr_id,spent_seconds" .
92  " FROM lm_read_event" .
93  " WHERE " . $ilDB->in("obj_id", $chapter_ids, "", "integer")
94  );
95  while ($row = $ilDB->fetchAssoc($set)) {
96  if ($row["spent_seconds"] < $status_info["tlt"][$row["obj_id"]]) {
97  $status_info["in_progress"][$row["obj_id"]][] = $row["usr_id"];
98  } else {
99  $status_info["completed"][$row["obj_id"]][] = $row["usr_id"];
100  }
101  }
102  }
103  }
104  return $status_info;
105  }
106 
107  public function determineStatus(
108  int $a_obj_id,
109  int $a_usr_id,
110  object $a_obj = null
111  ): int {
112  $info = self::_getStatusInfo($a_obj_id);
113 
114  $completed_once = false;
115 
116  if (isset($info["completed"])) {
117  $completed = true;
118  foreach ($info["completed"] as $user_ids) {
119  // must have completed all items to complete collection
120  if (!in_array($a_usr_id, $user_ids)) {
121  $completed = false;
122  break;
123  } else {
124  $completed_once = true;
125  }
126  }
127  if ($completed) {
128  return self::LP_STATUS_COMPLETED_NUM;
129  }
130  }
131 
132  // #14997
133  if ($completed_once) {
134  return self::LP_STATUS_IN_PROGRESS_NUM;
135  }
136 
137  if (isset($info["in_progress"])) {
138  foreach ($info["in_progress"] as $user_ids) {
139  if (in_array($a_usr_id, $user_ids)) {
140  return self::LP_STATUS_IN_PROGRESS_NUM;
141  }
142  }
143  }
144 
145  return self::LP_STATUS_NOT_ATTEMPTED_NUM;
146  }
147 }
determineStatus(int $a_obj_id, int $a_usr_id, object $a_obj=null)
static _getCompleted(int $a_obj_id)
Static function to read the users who have the status &#39;completed&#39;.
static _getStatusInfo(int $a_obj_id)
Reads informations about the object e.g test results, tlt, number of visits.
static _getAllReferences(int $id)
get all reference ids for object ID
global $DIC
Definition: feed.php:28
static _getTypicalLearningTimeSeconds(int $a_rbac_id, int $a_obj_id=0)
$ref_id
Definition: ltiauth.php:67
static getInstance(int $obj_id)