18 declare(strict_types=1);
47 $this->db = $DIC->database();
65 $query =
'SELECT id FROM ecs_course_assignments ' .
66 'WHERE usr_id = ' .
$ilDB->quote($a_usr_id,
'text');
69 $assignments = array();
71 $assignments[] =
new self((
int) $row->id);
85 $query =
'DELETE FROM ecs_course_assignments ' .
86 'WHERE obj_id = ' .
$ilDB->quote($a_obj_id,
'integer');
100 $query =
'DELETE FROM ecs_course_assignments ' .
101 'WHERE sid = ' .
$ilDB->quote($a_server_id,
'integer');
109 public static function lookupUserIds(
int $a_cms_id, ?
int $a_cms_sub_id,
int $a_obj_id): array
113 $ilDB = $DIC[
'ilDB'];
115 if (is_null($a_cms_sub_id)) {
116 $cms_sub_id_query =
'AND (cms_sub_id IS NULL or cms_sub_id = 0) ';
118 $cms_sub_id_query =
'AND cms_sub_id = ' .
$ilDB->quote($a_cms_sub_id,
'integer') .
' ';
121 $query =
'SELECT usr_id FROM ecs_course_assignments ' .
122 'WHERE cms_id = ' .
$ilDB->quote($a_cms_id,
'integer') .
' ' .
124 'AND obj_id = ' .
$ilDB->quote($a_obj_id,
'integer');
129 $usr_ids[] = $row->usr_id;
141 $ilDB = $DIC[
'ilDB'];
143 if (is_null($a_cms_sub_id)) {
144 $cms_sub_id_query =
'AND (cms_sub_id IS NULL or cms_sub_id = 0) ';
146 $cms_sub_id_query =
'AND cms_sub_id = ' .
$ilDB->quote($a_cms_sub_id,
'integer') .
' ';
149 $query =
'SELECT id FROM ecs_course_assignments ' .
150 'WHERE cms_id = ' .
$ilDB->quote($a_cms_id,
'integer') .
' ' .
152 'AND obj_id = ' .
$ilDB->quote($a_obj_id,
'integer') .
' ' .
153 'AND usr_id = ' .
$ilDB->quote($a_usr_id,
'text');
172 $this->server = $a_server;
195 $this->cms_id = $a_id;
205 $this->cms_sub_id = $a_id;
215 $this->obj_id = $a_id;
223 public function setUid(
string $a_id): void
235 $this->status = $a_status;
248 $this->
id = $this->db->nextId(
'ecs_course_assignments');
250 $assignment = self::lookupAssignment(
256 if ($assignment instanceof
self) {
257 $assignment->update();
261 $query =
'INSERT INTO ecs_course_assignments ' .
262 '(id,sid,mid,cms_id,cms_sub_id,obj_id,usr_id,status) ' .
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') .
' ' .
273 $this->db->manipulate(
$query);
282 $query =
'UPDATE ecs_course_assignments ' .
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);
299 public function delete():
bool 301 $query =
'DELETE FROM ecs_course_assignments ' .
302 'WHERE id = ' . $this->db->quote($this->
getId(),
'integer');
303 $this->db->manipulate(
$query);
312 protected function read(): bool
314 if (!$this->
getId()) {
318 $query =
'SELECT * FROM ecs_course_assignments ' .
319 'WHERE id = ' . $this->db->quote($this->
getId(),
'integer');
323 $this->
setMid((
int) $row->mid);
324 $this->
setCmsId((
int) $row->cms_id);
325 if (!is_null($row->cms_sub_id)) {
328 $this->
setObjId((
int) $row->obj_id);
329 if (!is_null($row->usr_id)) {
330 $this->
setUid($row->usr_id);
update()
Update assignment.
setStatus(bool $a_status)
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.
setServer(int $a_server)
Set server.
Storage of ecs course assignments.
static lookupMissingAssignmentsOfUser(string $a_usr_id)
Lookup missing assignments;.
__construct(int $a_id=0)
Constructor.
const STATUS_LOCAL_DELETED