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