ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLPStatusCollectionTLT.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
20
27{
28 public static function _getInProgress(int $a_obj_id): array
29 {
30 $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
31
32 $users = array();
33 if (isset($status_info['in_progress'])) {
34 foreach ($status_info['in_progress'] as $in_progress) {
35 $users = array_merge($users, $in_progress);
36 }
37 $users = array_unique($users);
38 }
39
40 $users = array_diff(
41 $users,
43 );
44
45 return $users;
46 }
47
48 public static function _getCompleted(int $a_obj_id): array
49 {
50 $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
51
52 $counter = 0;
53 $users = array();
54 foreach ($status_info['items'] as $item_id) {
55 $tmp_users = $status_info['completed'][$item_id];
56
57 if (!$counter++) {
58 $users = $tmp_users;
59 } else {
60 $users = array_intersect($users, $tmp_users);
61 }
62 }
63 $users = array_unique($users);
64
65 return $users;
66 }
67
68 public static function _getStatusInfo(int $a_obj_id): array
69 {
70 global $DIC;
71
72 $ilDB = $DIC['ilDB'];
73 $status_info = array();
74 $olp = ilObjectLP::getInstance($a_obj_id);
75 $collection = $olp->getCollectionInstance();
76 if ($collection) {
77 // @todo check if obj_id can be removed
78 $status_info["items"] = $collection->getItems($a_obj_id);
79
80 foreach ($status_info["items"] as $item_id) {
81 $status_info["in_progress"][$item_id] = array();
82 $status_info["completed"][$item_id] = array();
83
84 /*
85 * Seems to only be used for collections of LM chapters,
86 * so we manually set 'st' for chapters here.
87 */
88 $status_info["tlt"][$item_id] = parent::_getTypicalLearningTime(
89 'st',
90 $a_obj_id,
91 $item_id
92 );
93 }
94
95 $ref_ids = ilObject::_getAllReferences($a_obj_id);
96 $ref_id = end($ref_ids);
97 $possible_items = $collection->getPossibleItems($ref_id);
98 $chapter_ids = array_intersect(
99 array_keys($possible_items),
100 $status_info["items"]
101 );
102
103 // fix order (adapt from possible items)
104 $status_info["items"] = $chapter_ids;
105
106 if ($chapter_ids) {
107 foreach ($chapter_ids as $item_id) {
108 $status_info["item_titles"][$item_id] = $possible_items[$item_id]["title"];
109 }
110
111 $set = $ilDB->query(
112 "SELECT obj_id,usr_id,spent_seconds" .
113 " FROM lm_read_event" .
114 " WHERE " . $ilDB->in("obj_id", $chapter_ids, "", "integer")
115 );
116 while ($row = $ilDB->fetchAssoc($set)) {
117 if ($row["spent_seconds"] < $status_info["tlt"][$row["obj_id"]]) {
118 $status_info["in_progress"][$row["obj_id"]][] = $row["usr_id"];
119 } else {
120 $status_info["completed"][$row["obj_id"]][] = $row["usr_id"];
121 }
122 }
123 }
124 }
125 return $status_info;
126 }
127
128 public function determineStatus(
129 int $a_obj_id,
130 int $a_usr_id,
131 ?object $a_obj = null
132 ): int {
133 $info = self::_getStatusInfo($a_obj_id);
134
135 $completed_once = false;
136
137 if (isset($info["completed"])) {
138 $completed = true;
139 foreach ($info["completed"] as $user_ids) {
140 // must have completed all items to complete collection
141 if (!in_array($a_usr_id, $user_ids)) {
142 $completed = false;
143 break;
144 } else {
145 $completed_once = true;
146 }
147 }
148 if ($completed) {
150 }
151 }
152
153 // #14997
154 if ($completed_once) {
156 }
157
158 if (isset($info["in_progress"])) {
159 foreach ($info["in_progress"] as $user_ids) {
160 if (in_array($a_usr_id, $user_ids)) {
162 }
163 }
164 }
165
167 }
168}
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 'completed'.
static _getStatusInfo(int $a_obj_id)
Reads informations about the object e.g test results, tlt, number of visits.
Abstract class ilLPStatus for all learning progress modes E.g ilLPStatusManual, ilLPStatusObjectives ...
const LP_STATUS_COMPLETED_NUM
const LP_STATUS_IN_PROGRESS_NUM
const LP_STATUS_NOT_ATTEMPTED_NUM
static getInstance(int $obj_id)
static _getAllReferences(int $id)
get all reference ids for object ID
$info
Definition: entry_point.php:21
$ref_id
Definition: ltiauth.php:66
global $DIC
Definition: shib_login.php:26
$counter