ILIAS  release_8 Revision v8.24
class.ilExerciseMembers.php
Go to the documentation of this file.
1<?php
2
25{
26 protected ilDBInterface $db;
27 public int $ref_id;
28 public int $obj_id;
29 public array $members;
30 public string $status;
33
34 public function __construct(ilObjExercise $a_exc)
35 {
36 global $DIC;
37
38 $this->db = $DIC->database();
39 $this->exc = $a_exc;
40 $this->obj_id = $a_exc->getId();
41 $this->ref_id = $a_exc->getRefId();
42 $this->read();
43 $this->recommended_content_manager = new ilRecommendedContentManager();
44 }
45
46 // Get exercise ref id
47 public function getRefId(): int
48 {
49 return $this->ref_id;
50 }
51
52 // Get exercise obj id
53 public function getObjId(): int
54 {
55 return $this->obj_id;
56 }
57
58 public function setObjId(int $a_obj_id): void
59 {
60 $this->obj_id = $a_obj_id;
61 }
62
63 public function getMembers(): array
64 {
65 return $this->members ?: array();
66 }
67
68 public function setMembers(array $a_members): void
69 {
70 $this->members = $a_members;
71 }
72
76 public function assignMember(int $a_usr_id): void
77 {
79
80 $ilDB->manipulate("DELETE FROM exc_members " .
81 "WHERE obj_id = " . $ilDB->quote($this->getObjId(), "integer") . " " .
82 "AND usr_id = " . $ilDB->quote($a_usr_id, "integer") . " ");
83
84 // @todo: some of this fields may not be needed anymore
85 $ilDB->manipulateF(
86 "INSERT INTO exc_members (obj_id, usr_id, status, sent, feedback) " .
87 " VALUES (%s,%s,%s,%s,%s)",
88 array("integer", "integer", "text", "integer", "integer"),
89 array($this->getObjId(), $a_usr_id, 'notgraded', 0, 0)
90 );
91
93
94 $this->read();
95
96 ilLPStatusWrapper::_updateStatus($this->getObjId(), $a_usr_id);
97 }
98
99 // Is user assigned to exercise?
100 public function isAssigned(int $a_id): bool
101 {
102 return in_array($a_id, $this->getMembers());
103 }
104
110 public function assignMembers(array $a_members): bool
111 {
112 $assigned = 0;
113 if (is_array($a_members)) {
114 foreach ($a_members as $member) {
115 if (!$this->isAssigned($member)) {
116 $this->assignMember($member);
117 } else {
118 ++$assigned;
119 }
120 }
121 }
122 if ($assigned == count($a_members)) {
123 return false;
124 } else {
125 return true;
126 }
127 }
128
133 public function deassignMember(int $a_usr_id): void
134 {
136
137 $this->recommended_content_manager->removeObjectRecommendation($a_usr_id, $this->getRefId());
138
139 $query = "DELETE FROM exc_members " .
140 "WHERE obj_id = " . $ilDB->quote($this->getObjId(), "integer") . " " .
141 "AND usr_id = " . $ilDB->quote($a_usr_id, "integer") . " ";
142
143 $ilDB->manipulate($query);
144
145 $this->read();
146
147 ilLPStatusWrapper::_updateStatus($this->getObjId(), $a_usr_id);
148
149 // delete all delivered files of the member
150 ilExSubmission::deleteUser($this->exc->getId(), $a_usr_id);
151
152 // delete individual deadline/starting time entries
153 foreach (ilExAssignment::getInstancesByExercise($this->exc->getId()) as $ass) {
154 $idl = ilExcIndividualDeadline::getInstance($ass->getId(), $a_usr_id, false);
155 $idl->delete();
156 }
157
158 // @todo: delete all assignment associations (and their files)
159 }
160
161 public function read(): void
162 {
164
165 $tmp_arr_members = array();
166
167 $query = "SELECT * FROM exc_members " .
168 "WHERE obj_id = " . $ilDB->quote($this->getObjId(), "integer");
169
170 $res = $ilDB->query($query);
171 while ($row = $ilDB->fetchObject($res)) {
172 if (ilObject::_lookupType($row->usr_id) == "usr") {
173 $tmp_arr_members[] = $row->usr_id;
174 }
175 }
176 $this->setMembers($tmp_arr_members);
177 }
178
179 // @todo: clone also assignments
180 public function ilClone(int $a_new_id): void
181 {
183
184 $data = array();
185
186 $query = "SELECT * FROM exc_members " .
187 "WHERE obj_id = " . $ilDB->quote($this->getObjId(), "integer");
188
189 $res = $ilDB->query($query);
190 while ($row = $ilDB->fetchObject($res)) {
191 $data[] = array("usr_id" => $row->usr_id,
192 "notice" => $row->notice,
193 "returned" => $row->returned,
194 "status" => $row->status,
195 "sent" => $row->sent,
196 "feedback" => $row->feedback
197 );
198 }
199 foreach ($data as $row) {
200 $ilDB->manipulateF(
201 "INSERT INTO exc_members " .
202 " (obj_id, usr_id, notice, returned, status, feedback, sent) VALUES " .
203 " (%s,%s,%s,%s,%s,%s,%s)",
204 array("integer", "integer", "text", "integer", "text", "integer", "integer"),
205 array($a_new_id, $row["usr_id"], $row["notice"], (int) $row["returned"],
206 $row["status"], (int) $row["feedback"], (int) $row["sent"])
207 );
208
209 ilLPStatusWrapper::_updateStatus($a_new_id, $row["usr_id"]);
210 }
211 }
212
213 // @todo: delete also assignments
214 public function delete(): void
215 {
217
218 $query = "DELETE FROM exc_members WHERE obj_id = " .
219 $ilDB->quote($this->getObjId(), "integer");
220 $ilDB->manipulate($query);
221
223 }
224
225 public static function _getMembers(int $a_obj_id): array
226 {
227 global $DIC;
228
229 $ilDB = $DIC->database();
230
231 // #14963 - see ilExAssignment::getMemberListData()
232 $query = "SELECT DISTINCT(excm.usr_id) ud" .
233 " FROM exc_members excm" .
234 " JOIN object_data od ON (od.obj_id = excm.usr_id)" .
235 " WHERE excm.obj_id = " . $ilDB->quote($a_obj_id, "integer") .
236 " AND od.type = " . $ilDB->quote("usr", "text");
237
238 $res = $ilDB->query($query);
239 $usr_ids = [];
240 while ($row = $ilDB->fetchObject($res)) {
241 $usr_ids[] = $row->ud;
242 }
243
244 return $usr_ids;
245 }
246
257 public static function _lookupStatus(int $a_obj_id, int $a_user_id): ?string
258 {
259 global $DIC;
260
261 $ilDB = $DIC->database();
262
263 $query = "SELECT status FROM exc_members " .
264 "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") .
265 " AND usr_id = " . $ilDB->quote($a_user_id, "integer");
266
267 $res = $ilDB->query($query);
268 if ($row = $ilDB->fetchAssoc($res)) {
269 return $row["status"];
270 }
271
272 return null;
273 }
274
281 public static function _writeStatus(
282 int $a_obj_id,
283 int $a_user_id,
284 string $a_status
285 ): void {
286 global $DIC;
287
288 $ilDB = $DIC->database();
289
290 $ilDB->manipulate(
291 "UPDATE exc_members SET " .
292 " status = " . $ilDB->quote($a_status, "text") .
293 " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") .
294 " AND usr_id = " . $ilDB->quote($a_user_id, "integer")
295 );
296
297 ilLPStatusWrapper::_updateStatus($a_obj_id, $a_user_id);
298 }
299
308 public static function _writeReturned(
309 int $a_obj_id,
310 int $a_user_id,
311 int $a_status
312 ): void {
313 global $DIC;
314
315 $ilDB = $DIC->database();
316
317 $ilDB->manipulate(
318 "UPDATE exc_members SET " .
319 " returned = " . $ilDB->quote($a_status, "integer") .
320 " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") .
321 " AND usr_id = " . $ilDB->quote($a_user_id, "integer")
322 );
323
324 ilLPStatusWrapper::_updateStatus($a_obj_id, $a_user_id);
325 }
326
327
328 //
329 // LP
330 //
331
336 public static function _getReturned(int $a_obj_id): array
337 {
338 global $DIC;
339
340 $ilDB = $DIC->database();
341
342 $query = "SELECT DISTINCT(usr_id) as ud FROM exc_members " .
343 "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") . " " .
344 "AND returned = 1";
345
346 $res = $ilDB->query($query);
347 $usr_ids = [];
348 while ($row = $ilDB->fetchObject($res)) {
349 $usr_ids[] = $row->ud;
350 }
351
352 return $usr_ids;
353 }
354
358 public static function _hasReturned(int $a_obj_id, int $a_user_id): bool
359 {
360 global $DIC;
361
362 $ilDB = $DIC->database();
363
364 $set = $ilDB->query(
365 "SELECT DISTINCT(usr_id) FROM exc_members WHERE " .
366 " obj_id = " . $ilDB->quote($a_obj_id, "integer") . " AND " .
367 " returned = " . $ilDB->quote(1, "integer") . " AND " .
368 " usr_id = " . $ilDB->quote($a_user_id, "integer")
369 );
370 return (bool) $ilDB->fetchAssoc($set);
371 }
372
376 public static function _getPassedUsers(int $a_obj_id): array
377 {
378 global $DIC;
379
380 $ilDB = $DIC->database();
381
382 $query = "SELECT DISTINCT(usr_id) FROM exc_members " .
383 "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") . " " .
384 "AND status = " . $ilDB->quote("passed", "text");
385 $res = $ilDB->query($query);
386 $usr_ids = [];
387 while ($row = $ilDB->fetchObject($res)) {
388 $usr_ids[] = $row->usr_id;
389 }
390 return $usr_ids;
391 }
392
396 public static function _getFailedUsers(int $a_obj_id): array
397 {
398 global $DIC;
399
400 $ilDB = $DIC->database();
401
402 $query = "SELECT DISTINCT(usr_id) FROM exc_members " .
403 "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") . " " .
404 "AND status = " . $ilDB->quote("failed", "text");
405 $res = $ilDB->query($query);
406 $usr_ids = [];
407 while ($row = $ilDB->fetchObject($res)) {
408 $usr_ids[] = $row->usr_id;
409 }
410 return $usr_ids;
411 }
412}
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)
Delete all delivered files of user.
static getInstance(int $a_ass_id, int $a_participant_id, bool $a_is_team=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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?
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...
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
$query