ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilECSUserConsents.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26{
30 private static array $instances = [];
31
32 private int $usr_id;
36 private array $consents = [];
37
38 protected ilDBInterface $db;
39
40 protected function __construct(int $a_usr_id)
41 {
42 global $DIC;
43
44 $this->db = $DIC->database();
45 $this->usr_id = $a_usr_id;
46 if ($a_usr_id > 0) {
47 $this->read();
48 }
49 }
50
51 public static function getInstanceByUserId(int $a_usr_id): self
52 {
53 if (!isset(self::$instances[$a_usr_id])) {
54 self::$instances[$a_usr_id] = new self($a_usr_id);
55 }
56 return self::$instances[$a_usr_id];
57 }
58
59 public function getUserId(): int
60 {
61 return $this->usr_id;
62 }
63
64 public function hasConsented(int $server_id, int $a_mid): bool
65 {
66 return array_key_exists("{$server_id}:{$a_mid}", $this->consents);
67 }
68
69 public function delete(): void
70 {
71 foreach ($this->consents as $mid => $consent) {
72 $consent->delete();
73 }
74 $this->consents = [];
75 }
76
77 public function add(int $server_id, int $a_mid): void
78 {
79 if (!$this->hasConsented($server_id, $a_mid)) {
80 $consent = new ilECSUserConsent($this->getUserId(), $server_id, $a_mid);
81 $consent->save();
82 $this->consents["{$server_id}:{$a_mid}"] = $consent;
83 }
84 }
85
86 protected function read(): void
87 {
88 $query = 'SELECT * FROM ecs_user_consent ' .
89 'WHERE usr_id = ' . $this->db->quote(
90 $this->getUserId(),
92 );
93 $res = $this->db->query($query);
94 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
95 $this->consents["{$row->server_id}:{$row->mid}"] = new ilECSUserConsent(
96 (int) $row->usr_id,
97 (int) $row->server_id,
98 (int) $row->mid
99 );
100 }
101 }
102}
Class ilECSUserConsent.
Class ilECSUserConsents.
hasConsented(int $server_id, int $a_mid)
add(int $server_id, int $a_mid)
static getInstanceByUserId(int $a_usr_id)
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26