ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
PushRepository.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use ilObjUser;
27
28readonly class PushRepository
29{
30 public function __construct(private ilDBInterface $database, private ilObjUser $user)
31 {
32 }
33
34 public function addSubscription(PushSubscription $subscription): void
35 {
36 $this->database->insert(
37 'push_subscriptions',
38 [
39 'endpoint' => [ilDBConstants::T_TEXT, $subscription->getEndpoint()],
40 'user_id' => [ilDBConstants::T_INTEGER, $this->user->getId()],
41 'p256dh' => [ilDBConstants::T_TEXT, $subscription->getP256dh()],
42 'auth' => [ilDBConstants::T_TEXT, $subscription->getAuth()],
43 ]
44 );
45 }
46
47 public function deleteSubscription(string $auth): void
48 {
49 $this->database->manipulateF('DELETE FROM push_subscriptions WHERE auth = %s', [ilDBConstants::T_TEXT], [$auth]);
50 }
51
55 public function getUserSubscriptions(?int $user_id = null): array
56 {
57 $stmt = $this->database->queryF(
58 'SELECT * FROM push_subscriptions WHERE user_id = %s',
60 [$user_id ?? $this->user->getId()]
61 );
62
63 $result = [];
64 while ($row = $stmt->fetchAssoc()) {
65 $result[] = new PushSubscription(
66 $row['endpoint'],
67 $row['auth'],
68 $row['p256dh']
69 );
70 }
71
72 return $result;
73 }
74}
addSubscription(PushSubscription $subscription)
__construct(private ilDBInterface $database, private ilObjUser $user)
Class ilDBConstants.
User class.
Interface ilDBInterface.