ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilExerciseMembers.php
Go to the documentation of this file.
1<?php
2
20
27{
29 protected ilDBInterface $db;
30 public int $ref_id;
31 public int $obj_id;
32 public array $members;
33 public string $status;
36
37 public function __construct(ilObjExercise $a_exc)
38 {
39 global $DIC;
40
41 $this->db = $DIC->database();
42 $this->exc = $a_exc;
43 $this->obj_id = $a_exc->getId();
44 $this->ref_id = $a_exc->getRefId();
45 $this->read();
46 $this->recommended_content_manager = new ilRecommendedContentManager();
47 $this->individual_deadlines = $DIC->exercise()->internal()->domain()->individualDeadline();
48 }
49
50 // Get exercise ref id
51 public function getRefId(): int
52 {
53 return $this->ref_id;
54 }
55
56 // Get exercise obj id
57 public function getObjId(): int
58 {
59 return $this->obj_id;
60 }
61
62 public function setObjId(int $a_obj_id): void
63 {
64 $this->obj_id = $a_obj_id;
65 }
66
67 public function getMembers(): array
68 {
69 return $this->members ?: array();
70 }
71
72 public function setMembers(array $a_members): void
73 {
74 $this->members = $a_members;
75 }
76
80 public function assignMember(int $a_usr_id): void
81 {
83
84 $ilDB->manipulate("DELETE FROM exc_members " .
85 "WHERE obj_id = " . $ilDB->quote($this->getObjId(), "integer") . " " .
86 "AND usr_id = " . $ilDB->quote($a_usr_id, "integer") . " ");
87
88 // @todo: some of this fields may not be needed anymore
89 $ilDB->manipulateF(
90 "INSERT INTO exc_members (obj_id, usr_id, status, sent, feedback) " .
91 " VALUES (%s,%s,%s,%s,%s)",
92 array("integer", "integer", "text", "integer", "integer"),
93 array($this->getObjId(), $a_usr_id, 'notgraded', 0, 0)
94 );
95
97
98 $this->read();
99
100 ilLPStatusWrapper::_updateStatus($this->getObjId(), $a_usr_id);
101 }
102
103 // Is user assigned to exercise?
104 public function isAssigned(int $a_id): bool
105 {
106 return in_array($a_id, $this->getMembers());
107 }
108
114 public function assignMembers(array $a_members): bool
115 {
116 $assigned = 0;
117 if (is_array($a_members)) {
118 foreach ($a_members as $member) {
119 if (!$this->isAssigned($member)) {
120 $this->assignMember($member);
121 } else {
122 ++$assigned;
123 }
124 }
125 }
126 if ($assigned == count($a_members)) {
127 return false;
128 } else {
129 return true;
130 }
131 }
132
137 public function deassignMember(int $a_usr_id): void
138 {
140
141 $this->recommended_content_manager->removeObjectRecommendation($a_usr_id, $this->getRefId());
142 $this->individual_deadlines->deleteAllOfUserInExercise($this->getObjId(), $a_usr_id, false);
143
144 $query = "DELETE FROM exc_members " .
145 "WHERE obj_id = " . $ilDB->quote($this->getObjId(), "integer") . " " .
146 "AND usr_id = " . $ilDB->quote($a_usr_id, "integer") . " ";
147
148 $ilDB->manipulate($query);
149
150 $this->read();
151
152 ilLPStatusWrapper::_updateStatus($this->getObjId(), $a_usr_id);
153
154 // delete all delivered files of the member
155 ilExSubmission::deleteUser($this->exc->getId(), $a_usr_id);
156
157 // delete individual deadline/starting time entries
158 foreach (ilExAssignment::getInstancesByExercise($this->exc->getId()) as $ass) {
159 $idl = ilExcIndividualDeadline::getInstance($ass->getId(), $a_usr_id, false);
160 $idl->delete();
161 }
162
163 // @todo: delete all assignment associations (and their files)
164 }
165
166 public function read(): void
167 {
169
170 $tmp_arr_members = array();
171
172 $query = "SELECT * FROM exc_members " .
173 "WHERE obj_id = " . $ilDB->quote($this->getObjId(), "integer");
174
175 $res = $ilDB->query($query);
176 while ($row = $ilDB->fetchObject($res)) {
177 if (ilObject::_lookupType($row->usr_id) == "usr") {
178 $tmp_arr_members[] = $row->usr_id;
179 }
180 }
181 $this->setMembers($tmp_arr_members);
182 }
183
184 // @todo: clone also assignments
185 public function ilClone(int $a_new_id): void
186 {
188
189 $data = array();
190
191 $query = "SELECT * FROM exc_members " .
192 "WHERE obj_id = " . $ilDB->quote($this->getObjId(), "integer");
193
194 $res = $ilDB->query($query);
195 while ($row = $ilDB->fetchObject($res)) {
196 $data[] = array("usr_id" => $row->usr_id,
197 "notice" => $row->notice,
198 "returned" => $row->returned,
199 "status" => $row->status,
200 "sent" => $row->sent,
201 "feedback" => $row->feedback
202 );
203 }
204 foreach ($data as $row) {
205 $ilDB->manipulateF(
206 "INSERT INTO exc_members " .
207 " (obj_id, usr_id, notice, returned, status, feedback, sent) VALUES " .
208 " (%s,%s,%s,%s,%s,%s,%s)",
209 array("integer", "integer", "text", "integer", "text", "integer", "integer"),
210 array($a_new_id, $row["usr_id"], $row["notice"], (int) $row["returned"],
211 $row["status"], (int) $row["feedback"], (int) $row["sent"])
212 );
213
214 ilLPStatusWrapper::_updateStatus($a_new_id, $row["usr_id"]);
215 }
216 }
217
218 // @todo: delete also assignments
219 public function delete(): void
220 {
222
223 $query = "DELETE FROM exc_members WHERE obj_id = " .
224 $ilDB->quote($this->getObjId(), "integer");
225 $ilDB->manipulate($query);
226
228 }
229
230 public static function _getMembers(int $a_obj_id): array
231 {
232 global $DIC;
233
234 $ilDB = $DIC->database();
235
236 // #14963 - see ilExAssignment::getMemberListData()
237 $query = "SELECT DISTINCT(excm.usr_id) ud" .
238 " FROM exc_members excm" .
239 " JOIN object_data od ON (od.obj_id = excm.usr_id)" .
240 " WHERE excm.obj_id = " . $ilDB->quote($a_obj_id, "integer") .
241 " AND od.type = " . $ilDB->quote("usr", "text");
242
243 $res = $ilDB->query($query);
244 $usr_ids = [];
245 while ($row = $ilDB->fetchObject($res)) {
246 $usr_ids[] = $row->ud;
247 }
248
249 return $usr_ids;
250 }
251
262 public static function _lookupStatus(int $a_obj_id, int $a_user_id): ?string
263 {
264 global $DIC;
265
266 $ilDB = $DIC->database();
267
268 $query = "SELECT status FROM exc_members " .
269 "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") .
270 " AND usr_id = " . $ilDB->quote($a_user_id, "integer");
271
272 $res = $ilDB->query($query);
273 if ($row = $ilDB->fetchAssoc($res)) {
274 return $row["status"];
275 }
276
277 return null;
278 }
279
286 public static function _writeStatus(
287 int $a_obj_id,
288 int $a_user_id,
289 string $a_status
290 ): void {
291 global $DIC;
292
293 $ilDB = $DIC->database();
294
295 $ilDB->manipulate(
296 "UPDATE exc_members SET " .
297 " status = " . $ilDB->quote($a_status, "text") .
298 " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") .
299 " AND usr_id = " . $ilDB->quote($a_user_id, "integer")
300 );
301
302 ilLPStatusWrapper::_updateStatus($a_obj_id, $a_user_id);
303 }
304
313 public static function _writeReturned(
314 int $a_obj_id,
315 int $a_user_id,
316 int $a_status
317 ): void {
318 global $DIC;
319
320 $ilDB = $DIC->database();
321
322 $ilDB->manipulate(
323 "UPDATE exc_members SET " .
324 " returned = " . $ilDB->quote($a_status, "integer") .
325 " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") .
326 " AND usr_id = " . $ilDB->quote($a_user_id, "integer")
327 );
328
329 ilLPStatusWrapper::_updateStatus($a_obj_id, $a_user_id);
330 }
331
332
333 //
334 // LP
335 //
336
341 public static function _getReturned(int $a_obj_id): array
342 {
343 global $DIC;
344
345 $ilDB = $DIC->database();
346
347 $query = "SELECT DISTINCT(usr_id) as ud FROM exc_members " .
348 "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") . " " .
349 "AND returned = 1";
350
351 $res = $ilDB->query($query);
352 $usr_ids = [];
353 while ($row = $ilDB->fetchObject($res)) {
354 $usr_ids[] = $row->ud;
355 }
356
357 return $usr_ids;
358 }
359
363 public static function _hasReturned(int $a_obj_id, int $a_user_id): bool
364 {
365 global $DIC;
366
367 $ilDB = $DIC->database();
368
369 $set = $ilDB->query(
370 "SELECT DISTINCT(usr_id) FROM exc_members WHERE " .
371 " obj_id = " . $ilDB->quote($a_obj_id, "integer") . " AND " .
372 " returned = " . $ilDB->quote(1, "integer") . " AND " .
373 " usr_id = " . $ilDB->quote($a_user_id, "integer")
374 );
375 return (bool) $ilDB->fetchAssoc($set);
376 }
377
381 public static function _getPassedUsers(int $a_obj_id): array
382 {
383 global $DIC;
384
385 $ilDB = $DIC->database();
386
387 $query = "SELECT DISTINCT(usr_id) FROM exc_members " .
388 "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") . " " .
389 "AND status = " . $ilDB->quote("passed", "text");
390 $res = $ilDB->query($query);
391 $usr_ids = [];
392 while ($row = $ilDB->fetchObject($res)) {
393 $usr_ids[] = $row->usr_id;
394 }
395 return $usr_ids;
396 }
397
401 public static function _getFailedUsers(int $a_obj_id): array
402 {
403 global $DIC;
404
405 $ilDB = $DIC->database();
406
407 $query = "SELECT DISTINCT(usr_id) FROM exc_members " .
408 "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") . " " .
409 "AND status = " . $ilDB->quote("failed", "text");
410 $res = $ilDB->query($query);
411 $usr_ids = [];
412 while ($row = $ilDB->fetchObject($res)) {
413 $usr_ids[] = $row->usr_id;
414 }
415 return $usr_ids;
416 }
417}
static getInstancesByExercise(int $a_exc_id)
static createNewUserRecords(int $a_user_id, int $a_exc_id)
static deleteUser(int $a_exc_id, int $a_user_id)
Deletes already delivered files.
static getInstance(int $a_ass_id, int $a_participant_id, bool $a_is_team=false)
Class ilExerciseMembers.
static _getReturned(int $a_obj_id)
Get returned status for all members (if they have anything returned for any assignment)
static _writeStatus(int $a_obj_id, int $a_user_id, string $a_status)
Write user status This information is determined by the assignment status and saved redundantly in th...
static _getMembers(int $a_obj_id)
static _hasReturned(int $a_obj_id, int $a_user_id)
Has user returned anything in any assignment?
IndividualDeadlineManager $individual_deadlines
assignMember(int $a_usr_id)
Assign a user to the exercise.
static _writeReturned(int $a_obj_id, int $a_user_id, int $a_status)
Write returned status.
static _getPassedUsers(int $a_obj_id)
Get all users that passed the exercise.
deassignMember(int $a_usr_id)
Detaches a user from an exercise.
assignMembers(array $a_members)
Assign members to exercise.
ilRecommendedContentManager $recommended_content_manager
static _lookupStatus(int $a_obj_id, int $a_user_id)
Lookup current status (notgraded|passed|failed)
static _getFailedUsers(int $a_obj_id)
Get all users that failed the exercise.
__construct(ilObjExercise $a_exc)
setMembers(array $a_members)
static _refreshStatus(int $a_obj_id, ?array $a_users=null)
static _updateStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null, bool $a_percentage=false, bool $a_force_raise=false)
Class ilObjExercise.
static _lookupType(int $id, bool $reference=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26