ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLPStatusCollectionManual.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
25{
26 public static function _getInProgress(int $a_obj_id): array
27 {
28 $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
29
30 // find any completed item
31 $users = array();
32 if (isset($status_info['completed'])) {
33 foreach ($status_info['completed'] as $in_progress) {
34 $users = array_merge($users, $in_progress);
35 }
36 $users = array_unique($users);
37 }
38 // remove all users which have completed ALL items
39 return array_diff($users, ilLPStatusWrapper::_getCompleted($a_obj_id));
40 }
41
42 public static function _getCompleted(int $a_obj_id): array
43 {
44 $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
45
46 $counter = 0;
47 $users = array();
48 foreach ($status_info['items'] as $item_id) {
49 $tmp_users = $status_info['completed'][$item_id];
50
51 if (!$counter++) {
52 $users = $tmp_users;
53 } else {
54 $users = array_intersect($users, $tmp_users);
55 }
56 }
57 return array_unique($users);
58 }
59
60 public static function _getStatusInfo(int $a_obj_id): array
61 {
62 $status_info = array();
63
64 $olp = ilObjectLP::getInstance($a_obj_id);
65 $collection = $olp->getCollectionInstance();
66 if ($collection) {
67 // @todo check if obj_id can be removed
68 $status_info["items"] = $collection->getItems($a_obj_id);
69
70 foreach ($status_info["items"] as $item_id) {
71 $status_info["completed"][$item_id] = array();
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 $status = self::_getObjectStatus($a_obj_id);
87
88 foreach ($chapter_ids as $item_id) {
89 $status_info["item_titles"][$item_id] = $possible_items[$item_id]["title"];
90
91 if (isset($status[$item_id])) {
92 foreach ($status[$item_id] as $user_id => $user_status) {
93 if ($user_status) {
94 $status_info["completed"][$item_id][] = $user_id;
95 }
96 }
97 }
98 }
99 }
100 }
101 return $status_info;
102 }
103
104 public function determineStatus(
105 int $a_obj_id,
106 int $a_usr_id,
107 ?object $a_obj = null
108 ): int {
109 $info = self::_getStatusInfo($a_obj_id);
110
111 if (isset($info["completed"])) {
112 $completed = true;
113 $in_progress = false;
114 foreach ($info["completed"] as $user_ids) {
115 // has completed at least 1 item
116 if (in_array($a_usr_id, $user_ids)) {
117 $in_progress = true;
118 } // must have completed all items to complete collection
119 else {
120 $completed = false;
121 }
122 }
123 if ($completed) {
125 }
126 if ($in_progress) {
128 }
129 }
130
132 }
133
134 public static function _getObjectStatus(
135 $a_obj_id,
136 $a_user_id = null
137 ): array {
138 global $DIC;
139
140 $ilDB = $DIC['ilDB'];
141
142 $res = array();
143
144 $sql = "SELECT subitem_id, completed, usr_id, last_change" .
145 " FROM ut_lp_coll_manual" .
146 " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer");
147 if ($a_user_id) {
148 $sql .= " AND usr_id = " . $ilDB->quote($a_user_id, "integer");
149 }
150 $set = $ilDB->query($sql);
151 while ($row = $ilDB->fetchAssoc($set)) {
152 if (!$a_user_id) {
153 $res[(int) $row["subitem_id"]][(int) $row["usr_id"]] = (int) $row["completed"];
154 } else {
155 $res[(int) $row["subitem_id"]] = array((int) $row["completed"],
156 $row["last_change"]
157 );
158 }
159 }
160 return $res;
161 }
162
163 public static function _setObjectStatus(
164 int $a_obj_id,
165 int $a_user_id,
166 ?array $a_completed = null
167 ): void {
168 global $DIC;
169
170 $ilDB = $DIC['ilDB'];
171
172 $now = time();
173
174 if (!$a_completed) {
175 $a_completed = array();
176 }
177
178 $olp = ilObjectLP::getInstance($a_obj_id);
179 $collection = $olp->getCollectionInstance();
180 if ($collection) {
181 $existing = self::_getObjectStatus($a_obj_id, $a_user_id);
182
183 foreach ($collection->getItems() as $item_id) {
184 if (isset($existing[$item_id])) {
185 // value changed
186 if ((!$existing[$item_id][0] && in_array(
187 $item_id,
188 $a_completed
189 )) ||
190 ($existing[$item_id][0] && !in_array(
191 $item_id,
192 $a_completed
193 ))) {
194 $ilDB->manipulate(
195 "UPDATE ut_lp_coll_manual SET " .
196 " completed = " . $ilDB->quote(
197 in_array($item_id, $a_completed),
198 "integer"
199 ) .
200 " , last_change = " . $ilDB->quote(
201 $now,
202 "integer"
203 ) .
204 " WHERE obj_id = " . $ilDB->quote(
205 $a_obj_id,
206 "integer"
207 ) .
208 " AND usr_id = " . $ilDB->quote(
209 $a_user_id,
210 "integer"
211 ) .
212 " AND subitem_id = " . $ilDB->quote(
213 $item_id,
214 "integer"
215 )
216 );
217 }
218 } elseif (in_array($item_id, $a_completed)) {
219 $ilDB->manipulate(
220 "INSERT INTO ut_lp_coll_manual" .
221 "(obj_id,usr_id,subitem_id,completed,last_change)" .
222 " VALUES (" . $ilDB->quote($a_obj_id, "integer") .
223 " , " . $ilDB->quote($a_user_id, "integer") .
224 " , " . $ilDB->quote($item_id, "integer") .
225 " , " . $ilDB->quote(1, "integer") .
226 " , " . $ilDB->quote($now, "integer") . ")"
227 );
228 }
229 }
230 }
231
232 ilLPStatusWrapper::_updateStatus($a_obj_id, $a_user_id);
233 }
234}
determineStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null)
static _setObjectStatus(int $a_obj_id, int $a_user_id, ?array $a_completed=null)
static _getObjectStatus( $a_obj_id, $a_user_id=null)
static _updateStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null, bool $a_percentage=false, bool $a_force_raise=false)
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
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26
$counter