ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilECSUserConsents.php
Go to the documentation of this file.
1 <?php
2 
19 declare(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 }
$res
Definition: ltiservices.php:66
hasConsented(int $server_id, int $a_mid)
Class ilECSUserConsents.
global $DIC
Definition: shib_login.php:22
static getInstanceByUserId(int $a_usr_id)
Class ilECSUserConsent.
add(int $server_id, int $a_mid)