|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* For licensing terms, see /license.txt */ |
|
6
|
|
|
|
|
7
|
|
|
namespace Chamilo\CoreBundle\Entity; |
|
8
|
|
|
|
|
9
|
|
|
use ApiPlatform\Doctrine\Orm\Filter\NumericFilter; |
|
10
|
|
|
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter; |
|
11
|
|
|
use ApiPlatform\Metadata\ApiFilter; |
|
12
|
|
|
use ApiPlatform\Metadata\ApiResource; |
|
13
|
|
|
use ApiPlatform\Metadata\Delete; |
|
14
|
|
|
use ApiPlatform\Metadata\Get; |
|
15
|
|
|
use ApiPlatform\Metadata\GetCollection; |
|
16
|
|
|
use ApiPlatform\Metadata\Post; |
|
17
|
|
|
use Chamilo\CoreBundle\Repository\PushSubscriptionRepository; |
|
18
|
|
|
use DateTime; |
|
19
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
20
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
|
21
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
|
22
|
|
|
|
|
23
|
|
|
#[ApiResource( |
|
24
|
|
|
operations: [ |
|
25
|
|
|
new Get(security: "is_granted('ROLE_USER')"), |
|
26
|
|
|
new Post(security: "is_granted('ROLE_USER')"), |
|
27
|
|
|
new GetCollection(security: "is_granted('ROLE_USER')"), |
|
28
|
|
|
new Delete(security: "is_granted('ROLE_USER')") |
|
29
|
|
|
], |
|
30
|
|
|
normalizationContext: ['groups' => ['pushsubscription:read']], |
|
31
|
|
|
denormalizationContext: ['groups' => ['pushsubscription:write']], |
|
32
|
|
|
paginationClientEnabled: false |
|
33
|
|
|
)] |
|
34
|
|
|
#[ApiFilter(SearchFilter::class, properties: [ |
|
35
|
|
|
'endpoint' => 'exact', |
|
36
|
|
|
])] |
|
37
|
|
|
#[ApiFilter(NumericFilter::class, properties: [ |
|
38
|
|
|
'user.id', |
|
39
|
|
|
])] |
|
40
|
|
|
#[ORM\Table(name: 'push_subscription')] |
|
41
|
|
|
#[ORM\Index(columns: ['user_id'], name: 'idx_push_subscription_user')] |
|
42
|
|
|
#[ORM\Entity(repositoryClass: PushSubscriptionRepository::class)] |
|
43
|
|
|
class PushSubscription |
|
44
|
|
|
{ |
|
45
|
|
|
#[Groups(['pushsubscription:read'])] |
|
46
|
|
|
#[ORM\Id] |
|
47
|
|
|
#[ORM\GeneratedValue] |
|
48
|
|
|
#[ORM\Column(type: 'integer')] |
|
49
|
|
|
private ?int $id = null; |
|
50
|
|
|
|
|
51
|
|
|
#[Groups(['pushsubscription:read', 'pushsubscription:write'])] |
|
52
|
|
|
#[Assert\NotBlank] |
|
53
|
|
|
#[ORM\Column(name: 'endpoint', type: 'text')] |
|
54
|
|
|
private string $endpoint; |
|
55
|
|
|
|
|
56
|
|
|
#[Groups(['pushsubscription:read', 'pushsubscription:write'])] |
|
57
|
|
|
#[Assert\NotBlank] |
|
58
|
|
|
#[ORM\Column(name: 'public_key', type: 'text')] |
|
59
|
|
|
private string $publicKey; |
|
60
|
|
|
|
|
61
|
|
|
#[Groups(['pushsubscription:read', 'pushsubscription:write'])] |
|
62
|
|
|
#[Assert\NotBlank] |
|
63
|
|
|
#[ORM\Column(name: 'auth_token', type: 'text')] |
|
64
|
|
|
private string $authToken; |
|
65
|
|
|
|
|
66
|
|
|
#[Groups(['pushsubscription:read', 'pushsubscription:write'])] |
|
67
|
|
|
#[ORM\Column(name: 'content_encoding', type: 'string', length: 20, nullable: true, options: ['default' => 'aesgcm'])] |
|
68
|
|
|
private ?string $contentEncoding = 'aesgcm'; |
|
69
|
|
|
|
|
70
|
|
|
#[Groups(['pushsubscription:read', 'pushsubscription:write'])] |
|
71
|
|
|
#[ORM\Column(name: 'user_agent', type: 'text', nullable: true)] |
|
72
|
|
|
private ?string $userAgent = null; |
|
73
|
|
|
|
|
74
|
|
|
#[Groups(['pushsubscription:read'])] |
|
75
|
|
|
#[ORM\Column(name: 'created_at', type: 'datetime')] |
|
76
|
|
|
private DateTime $createdAt; |
|
77
|
|
|
|
|
78
|
|
|
#[Groups(['pushsubscription:read'])] |
|
79
|
|
|
#[ORM\Column(name: 'updated_at', type: 'datetime')] |
|
80
|
|
|
private DateTime $updatedAt; |
|
81
|
|
|
|
|
82
|
|
|
#[Groups(['pushsubscription:read', 'pushsubscription:write'])] |
|
83
|
|
|
#[ORM\ManyToOne(targetEntity: User::class)] |
|
84
|
|
|
#[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', onDelete: 'CASCADE')] |
|
85
|
|
|
private ?User $user = null; |
|
86
|
|
|
|
|
87
|
|
|
public function __construct() |
|
88
|
|
|
{ |
|
89
|
|
|
$this->createdAt = new DateTime(); |
|
90
|
|
|
$this->updatedAt = new DateTime(); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function getId(): ?int |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->id; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function getEndpoint(): string |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->endpoint; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function setEndpoint(string $endpoint): self |
|
104
|
|
|
{ |
|
105
|
|
|
$this->endpoint = $endpoint; |
|
106
|
|
|
|
|
107
|
|
|
return $this; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function getPublicKey(): string |
|
111
|
|
|
{ |
|
112
|
|
|
return $this->publicKey; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
public function setPublicKey(string $publicKey): self |
|
116
|
|
|
{ |
|
117
|
|
|
$this->publicKey = $publicKey; |
|
118
|
|
|
|
|
119
|
|
|
return $this; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
public function getAuthToken(): string |
|
123
|
|
|
{ |
|
124
|
|
|
return $this->authToken; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
public function setAuthToken(string $authToken): self |
|
128
|
|
|
{ |
|
129
|
|
|
$this->authToken = $authToken; |
|
130
|
|
|
|
|
131
|
|
|
return $this; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
public function getContentEncoding(): ?string |
|
135
|
|
|
{ |
|
136
|
|
|
return $this->contentEncoding; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
public function setContentEncoding(?string $contentEncoding): self |
|
140
|
|
|
{ |
|
141
|
|
|
$this->contentEncoding = $contentEncoding; |
|
142
|
|
|
|
|
143
|
|
|
return $this; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
public function getUserAgent(): ?string |
|
147
|
|
|
{ |
|
148
|
|
|
return $this->userAgent; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
public function setUserAgent(?string $userAgent): self |
|
152
|
|
|
{ |
|
153
|
|
|
$this->userAgent = $userAgent; |
|
154
|
|
|
|
|
155
|
|
|
return $this; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
public function getCreatedAt(): DateTime |
|
159
|
|
|
{ |
|
160
|
|
|
return $this->createdAt; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
public function setCreatedAt(DateTime $createdAt): self |
|
164
|
|
|
{ |
|
165
|
|
|
$this->createdAt = $createdAt; |
|
166
|
|
|
|
|
167
|
|
|
return $this; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
public function getUpdatedAt(): DateTime |
|
171
|
|
|
{ |
|
172
|
|
|
return $this->updatedAt; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
public function setUpdatedAt(DateTime $updatedAt): self |
|
176
|
|
|
{ |
|
177
|
|
|
$this->updatedAt = $updatedAt; |
|
178
|
|
|
|
|
179
|
|
|
return $this; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
public function getUser(): ?User |
|
183
|
|
|
{ |
|
184
|
|
|
return $this->user; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
public function setUser(?User $user): self |
|
188
|
|
|
{ |
|
189
|
|
|
$this->user = $user; |
|
190
|
|
|
|
|
191
|
|
|
return $this; |
|
192
|
|
|
} |
|
193
|
|
|
} |
|
194
|
|
|
|