ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilExcRandomAssignmentDBRepository.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
13{
14
18 protected $db;
19
23 public function __construct(ilDBInterface $db = null)
24 {
25 global $DIC;
26
27 $this->db = (is_null($db))
28 ? $DIC->database()
29 : $db;
30 }
31
39 public function getAssignmentsOfUser(int $user_id, int $exc_id)
40 {
41 $db = $this->db;
42
43 $set = $db->queryF(
44 "SELECT * FROM exc_mandatory_random " .
45 " WHERE usr_id = %s " .
46 " AND exc_id = %s ",
47 array("integer", "integer"),
48 array($user_id, $exc_id)
49 );
50 $ass_ids = [];
51 while ($rec = $db->fetchAssoc($set)) {
52 if (ilExAssignment::isInExercise($rec["ass_id"], $exc_id)) {
53 $ass_ids[] = $rec["ass_id"];
54 }
55 }
56 return $ass_ids;
57 }
58
66 public function saveAssignmentsOfUser(int $user_id, int $exc_id, array $ass_ids)
67 {
68 $db = $this->db;
69
70 $db->manipulateF(
71 "DELETE FROM exc_mandatory_random WHERE " .
72 " exc_id = %s" .
73 " AND usr_id = %s",
74 array("integer", "integer"),
75 array($exc_id, $user_id)
76 );
77
78 foreach ($ass_ids as $ass_id) {
79 if (ilExAssignment::isInExercise((int) $ass_id, $exc_id)) {
80 $db->replace("exc_mandatory_random", array( // pk
81 "usr_id" => array("integer", $user_id),
82 "exc_id" => array("integer", $exc_id),
83 "ass_id" => array("integer", $ass_id)
84 ), []);
85 }
86 }
87 }
88}
An exception for terminatinating execution or to throw for unit testing.
static isInExercise($a_ass_id, $a_ex_id)
Is assignment in exercise?
Stores info about random assignments for users in exercises.
getAssignmentsOfUser(int $user_id, int $exc_id)
Get mandatory assignments of user.
saveAssignmentsOfUser(int $user_id, int $exc_id, array $ass_ids)
Save assignments of user.
global $DIC
Definition: goto.php:24
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...