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