ILIAS  release_8 Revision v8.24
class.ilECSRemoteUserRepository.php
Go to the documentation of this file.
1<?php
2
18declare(strict_types=1);
19
24{
26
27 public function __construct()
28 {
29 global $DIC;
30
31 $this->db = $DIC['ilDB'];
32 }
33
37 private function exists(
38 int $sid,
39 int $mid,
40 int $usr_id
41 ): bool {
42 $query = 'SELECT eru_id FROM ecs_remote_user ' .
43 'WHERE sid = ' . $this->db->quote($sid, 'integer') . ' ' .
44 'AND mid = ' . $this->db->quote($mid, 'integer') . ' ' .
45 'AND usr_id = ' . $this->db->quote($usr_id, 'integer');
46 $res = $this->db->query($query);
47 if ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
48 return (bool) $row->eru_id;
49 }
50 return false;
51 }
52
53 private function remoteUserExists(
54 int $sid,
55 int $mid,
56 string $remote_usr_id
57 ): bool {
58 $query = 'SELECT eru_id FROM ecs_remote_user ' .
59 'WHERE sid = ' . $this->db->quote($sid, 'integer') . ' ' .
60 'AND mid = ' . $this->db->quote($mid, 'integer') . ' ' .
61 'AND remote_usr_id = ' . $this->db->quote($remote_usr_id, 'text');
62 $res = $this->db->query($query);
63 if ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
64 return (bool) $row->eru_id;
65 }
66 return false;
67 }
68
72 public function createIfNotExisting(
73 int $sid,
74 int $mid,
75 int $usr_id,
76 string $remote_usr_id
77 ): void {
78 if (!$this->exists($sid, $mid, $usr_id)) {
79 $next_id = $this->db->nextId('ecs_remote_user');
80 $query = 'INSERT INTO ecs_remote_user (eru_id, sid, mid, usr_id, remote_usr_id) ' .
81 'VALUES( ' .
82 $this->db->quote($next_id) . ', ' .
83 $this->db->quote($sid, 'integer') . ', ' .
84 $this->db->quote($mid, 'integer') . ', ' .
85 $this->db->quote($usr_id, 'integer') . ', ' .
86 $this->db->quote($remote_usr_id, 'text') . ' ' .
87 ')';
88 $this->db->manipulate($query);
89 }
90 }
92 int $sid,
93 int $mid,
94 int $usr_id,
95 string $remote_usr_id
96 ): void {
97 if (!$this->remoteUserExists($sid, $mid, $remote_usr_id)) {
98 $next_id = $this->db->nextId('ecs_remote_user');
99 $query = 'INSERT INTO ecs_remote_user (eru_id, sid, mid, usr_id, remote_usr_id) ' .
100 'VALUES( ' .
101 $this->db->quote($next_id) . ', ' .
102 $this->db->quote($sid, 'integer') . ', ' .
103 $this->db->quote($mid, 'integer') . ', ' .
104 $this->db->quote($usr_id, 'integer') . ', ' .
105 $this->db->quote($remote_usr_id, 'text') . ' ' .
106 ')';
107 $this->db->manipulate($query);
108 }
109 }
113 public function getECSRemoteUserById(int $remoteUserId): ?ilECSRemoteUser
114 {
115 $query = 'SELECT * FROM ecs_remote_user ' .
116 'WHERE eru_id = ' . $this->db->quote($remoteUserId, 'integer');
117 $res = $this->db->query($query);
118 if ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
119 return new ilECSRemoteUser(
120 $remoteUserId,
121 (int) $row->sid,
122 (int) $row->mid,
123 (int) $row->usr_id,
124 $row->remote_usr_id
125 );
126 }
127 return null;
128 }
129
133 public function getECSRemoteUserByUsrId(int $a_usr_id): ?ilECSRemoteUser
134 {
135 $query = 'SELECT eru_id FROM ecs_remote_user ' .
136 'WHERE usr_id = ' . $this->db->quote($a_usr_id, 'integer');
137 $res = $this->db->query($query);
138 if ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
139 return $this->getECSRemoteUserById((int) $row->eru_id);
140 }
141 return null;
142 }
143
147 public function getECSRemoteUserByRemoteId(string $remoteUserId): ?ilECSRemoteUser
148 {
149 $query = 'SELECT eru_id FROM ecs_remote_user ' .
150 'WHERE remote_usr_id = ' . $this->db->quote($remoteUserId, 'text');
151 $res = $this->db->query($query);
152 if ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
153 return $this->getECSRemoteUserById($row->eru_id);
154 }
155 return null;
156 }
157}
getECSRemoteUserById(int $remoteUserId)
Read data set.
exists(int $sid, int $mid, int $usr_id)
Check if entry exists for user.
remoteUserExists(int $sid, int $mid, string $remote_usr_id)
getECSRemoteUserByRemoteId(string $remoteUserId)
Get instance for remote usr_id (login|external_account)
getECSRemoteUserByUsrId(int $a_usr_id)
Get instance for usr_id.
createIfRemoteUserNotExisting(int $sid, int $mid, int $usr_id, string $remote_usr_id)
createIfNotExisting(int $sid, int $mid, int $usr_id, string $remote_usr_id)
Create new remote user entry.
Storage of ecs remote user.
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
$query