ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilExerciseMembers.php
Go to the documentation of this file.
1<?php
2
20
27{
28 protected \ILIAS\Exercise\InternalDomainService $domain;
30 protected ilDBInterface $db;
31 public int $ref_id;
32 public int $obj_id;
33 public array $members;
34 public string $status;
37
38 public function __construct(ilObjExercise $a_exc)
39 {
40 global $DIC;
41
42 $this->db = $DIC->database();
43 $this->exc = $a_exc;
44 $this->obj_id = $a_exc->getId();
45 $this->ref_id = $a_exc->getRefId();
46 $this->read();
47 $this->recommended_content_manager = new ilRecommendedContentManager();
48 $this->individual_deadlines = $DIC->exercise()->internal()->domain()->individualDeadline();
49 $this->domain = $DIC->exercise()->internal()->domain();
50 }
51
52 // Get exercise ref id
53 public function getRefId(): int
54 {
55 return $this->ref_id;
56 }
57
58 // Get exercise obj id
59 public function getObjId(): int
60 {
61 return $this->obj_id;
62 }
63
64 public function setObjId(int $a_obj_id): void
65 {
66 $this->obj_id = $a_obj_id;
67 }
68
69 public function getMembers(): array
70 {
71 return $this->members ?: array();
72 }
73
74 public function setMembers(array $a_members): void
75 {
76 $this->members = $a_members;
77 }
78
82 public function assignMember(int $a_usr_id): void
83 {
85
86 $ilDB->manipulate("DELETE FROM exc_members " .
87 "WHERE obj_id = " . $ilDB->quote($this->getObjId(), "integer") . " " .
88 "AND usr_id = " . $ilDB->quote($a_usr_id, "integer") . " ");
89
90 // @todo: some of this fields may not be needed anymore
91 $ilDB->manipulateF(
92 "INSERT INTO exc_members (obj_id, usr_id, status, sent, feedback) " .
93 " VALUES (%s,%s,%s,%s,%s)",
94 array("integer", "integer", "text", "integer", "integer"),
95 array($this->getObjId(), $a_usr_id, 'notgraded', 0, 0)
96 );
97
99
100 $this->read();
101
102 ilLPStatusWrapper::_updateStatus($this->getObjId(), $a_usr_id);
103 }
104
105 // Is user assigned to exercise?
106 public function isAssigned(int $a_id): bool
107 {
108 return in_array($a_id, $this->getMembers());
109 }
110
116 public function assignMembers(array $a_members): bool
117 {
118 $assigned = 0;
119 if (is_array($a_members)) {
120 foreach ($a_members as $member) {
121 if (!$this->isAssigned($member)) {
122 $this->assignMember($member);
123 } else {
124 ++$assigned;
125 }
126 }
127 }
128 if ($assigned == count($a_members)) {
129 return false;
130 } else {
131 return true;
132 }
133 }
134
139 public function deassignMember(int $a_usr_id): void
140 {
142
143 $this->recommended_content_manager->removeObjectRecommendation($a_usr_id, $this->getRefId());
144 $this->individual_deadlines->deleteAllOfUserInExercise($this->getObjId(), $a_usr_id, false);
145
146 $query = "DELETE FROM exc_members " .
147 "WHERE obj_id = " . $ilDB->quote($this->getObjId(), "integer") . " " .
148 "AND usr_id = " . $ilDB->quote($a_usr_id, "integer") . " ";
149
150 $ilDB->manipulate($query);
151
152 $this->read();
153
154 ilLPStatusWrapper::_updateStatus($this->getObjId(), $a_usr_id);
155
156 // delete all delivered files of the member
157 ilExSubmission::deleteUser($this->exc->getId(), $a_usr_id);
158
159 // delete individual deadline/starting time entries
160 foreach (ilExAssignment::getInstancesByExercise($this->exc->getId()) as $ass) {
161 $idl = ilExcIndividualDeadline::getInstance($ass->getId(), $a_usr_id, false);
162 $idl->delete();
163 }
164
165 // delete random assignments
166 $random = $this->domain->assignment()->randomAssignments($this->exc);
167 $random->deleteAssignmentsOfUser($a_usr_id);
168
169 // @todo: delete all assignment associations (and their files)
170 }
171
172 public function read(): void
173 {
175
176 $tmp_arr_members = array();
177
178 $query = "SELECT * FROM exc_members " .
179 "WHERE obj_id = " . $ilDB->quote($this->getObjId(), "integer");
180
181 $res = $ilDB->query($query);
182 while ($row = $ilDB->fetchObject($res)) {
183 if (ilObject::_lookupType($row->usr_id) == "usr") {
184 $tmp_arr_members[] = $row->usr_id;
185 }
186 }
187 $this->setMembers($tmp_arr_members);
188 }
189
190 // @todo: clone also assignments
191 public function ilClone(int $a_new_id): void
192 {
194
195 $data = array();
196
197 $query = "SELECT * FROM exc_members " .
198 "WHERE obj_id = " . $ilDB->quote($this->getObjId(), "integer");
199
200 $res = $ilDB->query($query);
201 while ($row = $ilDB->fetchObject($res)) {
202 $data[] = array("usr_id" => $row->usr_id,
203 "notice" => $row->notice,
204 "returned" => $row->returned,
205 "status" => $row->status,
206 "sent" => $row->sent,
207 "feedback" => $row->feedback
208 );
209 }
210 foreach ($data as $row) {
211 $ilDB->manipulateF(
212 "INSERT INTO exc_members " .
213 " (obj_id, usr_id, notice, returned, status, feedback, sent) VALUES " .
214 " (%s,%s,%s,%s,%s,%s,%s)",
215 array("integer", "integer", "text", "integer", "text", "integer", "integer"),
216 array($a_new_id, $row["usr_id"], $row["notice"], (int) $row["returned"],
217 $row["status"], (int) $row["feedback"], (int) $row["sent"])
218 );
219
220 ilLPStatusWrapper::_updateStatus($a_new_id, $row["usr_id"]);
221 }
222 }
223
224 // @todo: delete also assignments
225 public function delete(): void
226 {
228
229 $query = "DELETE FROM exc_members WHERE obj_id = " .
230 $ilDB->quote($this->getObjId(), "integer");
231 $ilDB->manipulate($query);
232
234 }
235
236 public static function _getMembers(int $a_obj_id): array
237 {
238 global $DIC;
239
240 $ilDB = $DIC->database();
241
242 // #14963 - see ilExAssignment::getMemberListData()
243 $query = "SELECT DISTINCT(excm.usr_id) ud" .
244 " FROM exc_members excm" .
245 " JOIN object_data od ON (od.obj_id = excm.usr_id)" .
246 " WHERE excm.obj_id = " . $ilDB->quote($a_obj_id, "integer") .
247 " AND od.type = " . $ilDB->quote("usr", "text");
248
249 $res = $ilDB->query($query);
250 $usr_ids = [];
251 while ($row = $ilDB->fetchObject($res)) {
252 $usr_ids[] = $row->ud;
253 }
254
255 return $usr_ids;
256 }
257
268 public static function _lookupStatus(int $a_obj_id, int $a_user_id): ?string
269 {
270 global $DIC;
271
272 $ilDB = $DIC->database();
273
274 $query = "SELECT status FROM exc_members " .
275 "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") .
276 " AND usr_id = " . $ilDB->quote($a_user_id, "integer");
277
278 $res = $ilDB->query($query);
279 if ($row = $ilDB->fetchAssoc($res)) {
280 return $row["status"];
281 }
282
283 return null;
284 }
285
292 public static function _writeStatus(
293 int $a_obj_id,
294 int $a_user_id,
295 string $a_status
296 ): void {
297 global $DIC;
298
299 $ilDB = $DIC->database();
300
301 $ilDB->manipulate(
302 "UPDATE exc_members SET " .
303 " status = " . $ilDB->quote($a_status, "text") .
304 " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") .
305 " AND usr_id = " . $ilDB->quote($a_user_id, "integer")
306 );
307
308 ilLPStatusWrapper::_updateStatus($a_obj_id, $a_user_id);
309 }
310
319 public static function _writeReturned(
320 int $a_obj_id,
321 int $a_user_id,
322 int $a_status
323 ): void {
324 global $DIC;
325
326 $ilDB = $DIC->database();
327
328 $ilDB->manipulate(
329 "UPDATE exc_members SET " .
330 " returned = " . $ilDB->quote($a_status, "integer") .
331 " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") .
332 " AND usr_id = " . $ilDB->quote($a_user_id, "integer")
333 );
334
335 ilLPStatusWrapper::_updateStatus($a_obj_id, $a_user_id);
336 }
337
338
339 //
340 // LP
341 //
342
347 public static function _getReturned(int $a_obj_id): array
348 {
349 global $DIC;
350
351 $ilDB = $DIC->database();
352
353 $query = "SELECT DISTINCT(usr_id) as ud FROM exc_members " .
354 "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") . " " .
355 "AND returned = 1";
356
357 $res = $ilDB->query($query);
358 $usr_ids = [];
359 while ($row = $ilDB->fetchObject($res)) {
360 $usr_ids[] = $row->ud;
361 }
362
363 return $usr_ids;
364 }
365
369 public static function _hasReturned(int $a_obj_id, int $a_user_id): bool
370 {
371 global $DIC;
372
373 $ilDB = $DIC->database();
374
375 $set = $ilDB->query(
376 "SELECT DISTINCT(usr_id) FROM exc_members WHERE " .
377 " obj_id = " . $ilDB->quote($a_obj_id, "integer") . " AND " .
378 " returned = " . $ilDB->quote(1, "integer") . " AND " .
379 " usr_id = " . $ilDB->quote($a_user_id, "integer")
380 );
381 return (bool) $ilDB->fetchAssoc($set);
382 }
383
387 public static function _getPassedUsers(int $a_obj_id): array
388 {
389 global $DIC;
390
391 $ilDB = $DIC->database();
392
393 $query = "SELECT DISTINCT(usr_id) FROM exc_members " .
394 "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") . " " .
395 "AND status = " . $ilDB->quote("passed", "text");
396 $res = $ilDB->query($query);
397 $usr_ids = [];
398 while ($row = $ilDB->fetchObject($res)) {
399 $usr_ids[] = $row->usr_id;
400 }
401 return $usr_ids;
402 }
403
407 public static function _getFailedUsers(int $a_obj_id): array
408 {
409 global $DIC;
410
411 $ilDB = $DIC->database();
412
413 $query = "SELECT DISTINCT(usr_id) FROM exc_members " .
414 "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") . " " .
415 "AND status = " . $ilDB->quote("failed", "text");
416 $res = $ilDB->query($query);
417 $usr_ids = [];
418 while ($row = $ilDB->fetchObject($res)) {
419 $usr_ids[] = $row->usr_id;
420 }
421 return $usr_ids;
422 }
423}
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.
ILIAS Exercise InternalDomainService $domain
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