ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilECSCourseMemberAssignment.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
25{
26 public const STATUS_ASSIGNED = 0;
27 public const STATUS_LOCAL_DELETED = 1;
28
30
31 private int $id;
32 private int $server;
33 private int $mid;
34 private int $cms_id;
35 private ?int $cms_sub_id = null;
36 private int $obj_id;
37 private string $uid;
38 private bool $status = false;
39
40
44 public function __construct(int $a_id = 0)
45 {
46 global $DIC;
47
48 $this->db = $DIC->database();
49
50 $this->id = $a_id;
51
52 $this->read();
53 }
54
60 public static function lookupMissingAssignmentsOfUser(string $a_usr_id): array
61 {
62 global $DIC;
63
64 $ilDB = $DIC['ilDB'];
65
66 $query = 'SELECT id FROM ecs_course_assignments ' .
67 'WHERE usr_id = ' . $ilDB->quote($a_usr_id, 'text');
68 $res = $ilDB->query($query);
69
70 $assignments = array();
71 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
72 $assignments[] = new self((int) $row->id);
73 }
74 return $assignments;
75 }
76
80 public static function deleteByObjId(int $a_obj_id): bool
81 {
82 global $DIC;
83
84 $ilDB = $DIC['ilDB'];
85
86 $query = 'DELETE FROM ecs_course_assignments ' .
87 'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer');
88 $ilDB->manipulate($query);
89 return true;
90 }
91
95 public static function deleteByServerId(int $a_server_id): bool
96 {
97 global $DIC;
98
99 $ilDB = $DIC['ilDB'];
100
101 $query = 'DELETE FROM ecs_course_assignments ' .
102 'WHERE sid = ' . $ilDB->quote($a_server_id, 'integer');
103 $ilDB->manipulate($query);
104 return true;
105 }
106
110 public static function lookupUserIds(int $a_cms_id, ?int $a_cms_sub_id, int $a_obj_id): array
111 {
112 global $DIC;
113
114 $ilDB = $DIC['ilDB'];
115
116 if (is_null($a_cms_sub_id)) {
117 $cms_sub_id_query = 'AND (cms_sub_id IS NULL OR cms_sub_id = 0) ';
118 } else {
119 $cms_sub_id_query = 'AND cms_sub_id = ' . $ilDB->quote($a_cms_sub_id, 'integer') . ' ';
120 }
121
122 $query = 'SELECT usr_id FROM ecs_course_assignments ' .
123 'WHERE cms_id = ' . $ilDB->quote($a_cms_id, 'integer') . ' ' .
124 $cms_sub_id_query .
125 'AND obj_id = ' . $ilDB->quote($a_obj_id, 'integer');
126 $res = $ilDB->query($query);
127
128 $usr_ids = [];
129 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
130 $usr_ids[] = $row->usr_id;
131 }
132 return $usr_ids;
133 }
134
138 public static function lookupAssignment(int $a_cms_id, ?int $a_cms_sub_id, int $a_obj_id, string $a_usr_id): ?ilECSCourseMemberAssignment
139 {
140 global $DIC;
141
142 $ilDB = $DIC['ilDB'];
143
144 if (is_null($a_cms_sub_id)) {
145 $cms_sub_id_query = 'AND (cms_sub_id IS NULL OR cms_sub_id = 0) ';
146 } else {
147 $cms_sub_id_query = 'AND cms_sub_id = ' . $ilDB->quote($a_cms_sub_id, 'integer') . ' ';
148 }
149
150 $query = 'SELECT id FROM ecs_course_assignments ' .
151 'WHERE cms_id = ' . $ilDB->quote($a_cms_id, 'integer') . ' ' .
152 $cms_sub_id_query .
153 'AND obj_id = ' . $ilDB->quote($a_obj_id, 'integer') . ' ' .
154 'AND usr_id = ' . $ilDB->quote($a_usr_id, 'text');
155 $res = $ilDB->query($query);
156 if ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
157 return new ilECSCourseMemberAssignment((int) $row->id);
158 }
159 return null;
160 }
161
162
163 public function getId(): int
164 {
165 return $this->id;
166 }
167
171 public function setServer(int $a_server): void
172 {
173 $this->server = $a_server;
174 }
175
179 public function getServer(): int
180 {
181 return $this->server;
182 }
183
184 public function setMid(int $a_mid): void
185 {
186 $this->mid = $a_mid;
187 }
188
189 public function getMid(): int
190 {
191 return $this->mid;
192 }
193
194 public function setCmsId(int $a_id): void
195 {
196 $this->cms_id = $a_id;
197 }
198
199 public function getCmsId(): int
200 {
201 return $this->cms_id;
202 }
203
204 public function setCmsSubId(?int $a_id): void
205 {
206 $this->cms_sub_id = $a_id;
207 }
208
209 public function getCmsSubId(): ?int
210 {
211 return $this->cms_sub_id;
212 }
213
214 public function setObjId(int $a_id): void
215 {
216 $this->obj_id = $a_id;
217 }
218
219 public function getObjId(): int
220 {
221 return $this->obj_id;
222 }
223
224 public function setUid(string $a_id): void
225 {
226 $this->uid = $a_id;
227 }
228
229 public function getUid(): string
230 {
231 return $this->uid;
232 }
233
234 public function setStatus(bool $a_status): void
235 {
236 $this->status = $a_status;
237 }
238
239 public function getStatus(): bool
240 {
241 return $this->status;
242 }
243
244 private function getArrayForDatabase(): array
245 {
246 return [
247 'id' => ['integer', $this->getId()],
248 'sid' => ['integer', $this->getServer()],
249 'mid' => ['integer', $this->getMid()],
250 'cms_id' => ['integer', $this->getCmsId()],
251 'cms_sub_id' => ['integer', $this->getCmsSubId()],
252 'obj_id' => ['integer', $this->getObjId()],
253 'usr_id' => ['text', $this->getUid()],
254 'status' => ['integer', $this->getStatus()],
255 ];
256 }
260 public function save(): bool
261 {
262 $this->id = $this->db->nextId('ecs_course_assignments');
263
264 $assignment = self::lookupAssignment(
265 $this->getCmsId(),
266 $this->getCmsSubId(),
267 $this->getObjId(),
268 $this->getUid()
269 );
270 if ($assignment instanceof self) {
271 $assignment->update();
272 return true;
273 }
274 $this->db->insert('ecs_course_assignments', $this->getArrayForDatabase());
275 return true;
276 }
277
281 public function update(): bool
282 {
283 $this->db->update('ecs_course_assignments', $this->getArrayForDatabase(), [
284 'id' => [
285 'integer',
286 $this->getId(),
287 ],
288 ]);
289 return true;
290 }
291
295 public function delete(): bool
296 {
297 $query = 'DELETE FROM ecs_course_assignments ' .
298 'WHERE id = ' . $this->db->quote($this->getId(), 'integer');
299 $this->db->manipulate($query);
300 return true;
301 }
302
303
304
308 protected function read(): bool
309 {
310 if (!$this->getId()) {
311 return false;
312 }
313 $r = $this->db->queryF(
314 "SELECT sid,mid,cms_id,cms_sub_id,obj_id,usr_id,status FROM ecs_course_assignments WHERE id = %d",
315 ['integer'],
316 [$this->getId()]
317 );
318 $row = $this->db->fetchObject($r);
319 $this->setServer((int) $row->sid);
320 $this->setMid((int) $row->mid);
321 $this->setCmsId((int) $row->cms_id);
322 $this->setCmsSubId((int) $row->cms_sub_id);
323 $this->setObjId((int) $row->obj_id);
324 $this->setUid($row->usr_id);
325 $this->setStatus((bool) $row->status);
326 return true;
327 }
328}
Storage of ecs course assignments.
static lookupMissingAssignmentsOfUser(string $a_usr_id)
Lookup missing assignments;.
static lookupAssignment(int $a_cms_id, ?int $a_cms_sub_id, int $a_obj_id, string $a_usr_id)
Lookup assignment of user.
static deleteByServerId(int $a_server_id)
Delete by server id.
static lookupUserIds(int $a_cms_id, ?int $a_cms_sub_id, int $a_obj_id)
Lookup user ids.
static deleteByObjId(int $a_obj_id)
Delete by obj_id.
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26