1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the zibios/sharep. |
7
|
|
|
* |
8
|
|
|
* (c) Zbigniew Ślązak |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace App\Entity\Parking; |
12
|
|
|
|
13
|
|
|
use ApiPlatform\Core\Annotation as OA; |
14
|
|
|
use App\Entity\EntityInterface; |
15
|
|
|
use App\Entity\GetMemberInterface; |
16
|
|
|
use App\Entity\Traits; |
17
|
|
|
use Doctrine\ORM\Mapping as ORM; |
18
|
|
|
use PascalDeVink\ShortUuid\ShortUuid; |
19
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints as OrmAssert; |
20
|
|
|
use Symfony\Component\Serializer\Annotation as Serializer; |
21
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @ORM\Entity() |
25
|
|
|
* @ORM\Table( |
26
|
|
|
* name="parking_member_needs", |
27
|
|
|
* uniqueConstraints={@ORM\UniqueConstraint(name="parking_member_needs_date_member_uidx", columns={"date", "member_id"})} |
28
|
|
|
* ) |
29
|
|
|
* @OrmAssert\UniqueEntity(fields={"date", "member"}, errorPath="member", message="Date for Member already exist") |
30
|
|
|
* @OA\ApiResource( |
31
|
|
|
* normalizationContext={"groups"={"get"}}, |
32
|
|
|
* itemOperations={ |
33
|
|
|
* "get"={ |
34
|
|
|
* "access_control"="is_granted('PARKING_MEMBER_NEED_READ')" |
35
|
|
|
* }, |
36
|
|
|
* "delete"={ |
37
|
|
|
* "access_control"="is_granted('PARKING_MEMBER_NEED_DELETE', object)" |
38
|
|
|
* }, |
39
|
|
|
* "put"={ |
40
|
|
|
* "denormalization_context"={"groups"={"put"}}, |
41
|
|
|
* "access_control"="is_granted('PARKING_MEMBER_NEED_UPDATE', object) and is_granted('PARKING_MEMBER_NEED_UPDATE', previous_object)" |
42
|
|
|
* } |
43
|
|
|
* }, |
44
|
|
|
* collectionOperations={ |
45
|
|
|
* "get"={ |
46
|
|
|
* "access_control"="is_granted('PARKING_MEMBER_NEED_READ')" |
47
|
|
|
* }, |
48
|
|
|
* "post"={ |
49
|
|
|
* "denormalization_context"={"groups"={"post"}}, |
50
|
|
|
* "access_control"="is_granted('PARKING_MEMBER_NEED_CREATE', object)" |
51
|
|
|
* } |
52
|
|
|
* } |
53
|
|
|
* ) |
54
|
|
|
*/ |
55
|
|
|
class MemberNeed implements EntityInterface, GetMemberInterface |
56
|
|
|
{ |
57
|
|
|
use Traits\PropertyIdGeneratedTrait; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var \DateTimeImmutable |
61
|
|
|
* @ORM\Column(name="date", type="date_immutable", nullable=false) |
62
|
|
|
* |
63
|
|
|
* @Assert\Date() |
64
|
|
|
* |
65
|
|
|
* @Serializer\Groups({"get", "put", "post"}) |
66
|
|
|
* @@OA\ApiProperty( |
67
|
|
|
* attributes={ |
68
|
|
|
* "swagger_context"={"type"="string", "format"="date_immutable", "example"="2000-01-01"}, |
69
|
|
|
* "normalization_context"={"date_format"="Y-m-d", "datetime_format"="Y-m-d"}, |
70
|
|
|
* } |
71
|
|
|
* ) |
72
|
|
|
* @OA\ApiFilter( |
73
|
|
|
* ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter::class, |
74
|
|
|
* strategy="ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter::INCLUDE_NULL_BEFORE" |
75
|
|
|
* ) |
76
|
|
|
* @OA\ApiFilter( |
77
|
|
|
* ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter::class, |
78
|
|
|
* strategy="exact" |
79
|
|
|
* ) |
80
|
|
|
*/ |
81
|
|
|
private $date; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @var int |
85
|
|
|
* @ORM\Column(name="places", type="integer", nullable=false) |
86
|
|
|
* |
87
|
|
|
* @Assert\PositiveOrZero() |
88
|
|
|
* |
89
|
|
|
* @Serializer\Groups({"get"}) |
90
|
|
|
* @@OA\ApiProperty( |
91
|
|
|
* attributes={ |
92
|
|
|
* "swagger_context"={"type"="integer", "example"=0}, |
93
|
|
|
* } |
94
|
|
|
* ) |
95
|
|
|
* @OA\ApiFilter( |
96
|
|
|
* ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\RangeFilter::class |
97
|
|
|
* ) |
98
|
|
|
* @OA\ApiFilter( |
99
|
|
|
* ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter::class, |
100
|
|
|
* strategy="exact" |
101
|
|
|
* ) |
102
|
|
|
*/ |
103
|
|
|
private $places; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @var string |
107
|
|
|
* @ORM\Column(name="reason", type="string", length=255, nullable=false) |
108
|
|
|
* |
109
|
|
|
* @Assert\NotBlank() |
110
|
|
|
* @Assert\Length(min="1", max="255") |
111
|
|
|
* |
112
|
|
|
* @Serializer\Groups({"get", "put", "post"}) |
113
|
|
|
* @OA\ApiFilter( |
114
|
|
|
* ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter::class, |
115
|
|
|
* strategy="partial" |
116
|
|
|
* ) |
117
|
|
|
*/ |
118
|
|
|
private $reason; |
119
|
|
|
|
120
|
|
|
//------------------------------------------------------------------------------------------- |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @var Member |
124
|
|
|
* @ORM\ManyToOne(targetEntity="App\Entity\Parking\Member", inversedBy="memberNeeds") |
125
|
|
|
* @ORM\JoinColumn(name="member_id", referencedColumnName="id") |
126
|
|
|
* |
127
|
|
|
* @Assert\NotNull() |
128
|
|
|
* |
129
|
|
|
* @Serializer\Groups({"get", "post"}) |
130
|
|
|
* @OA\ApiProperty() |
131
|
|
|
* @OA\ApiSubresource(maxDepth=1) |
132
|
|
|
* @OA\ApiFilter( |
133
|
|
|
* ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter::class, |
134
|
|
|
* strategy="exact" |
135
|
|
|
* ) |
136
|
|
|
* @OA\ApiFilter( |
137
|
|
|
* ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter::class, |
138
|
|
|
* strategy="exact", |
139
|
|
|
* properties={"member.id"} |
140
|
|
|
* ) |
141
|
|
|
*/ |
142
|
|
|
protected $member; |
143
|
|
|
|
144
|
|
|
//------------------------------------------------------------------------------------------- |
145
|
|
|
|
146
|
|
|
public function __construct( |
147
|
|
|
Member $member, |
148
|
|
|
int $places, |
149
|
|
|
string $reason, |
150
|
|
|
\DateTimeImmutable $date |
151
|
|
|
) { |
152
|
|
|
$this->id = ShortUuid::uuid4(); |
153
|
|
|
$this->member = $member; |
154
|
|
|
$this->places = $places; |
155
|
|
|
$this->setReason($reason); |
156
|
|
|
$this->setDate($date); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
//------------------------------------------------------------------------------------------- |
160
|
|
|
|
161
|
|
|
public function getMember(): Member |
162
|
|
|
{ |
163
|
|
|
return $this->member; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
public function getPlaces(): int |
167
|
|
|
{ |
168
|
|
|
return $this->places; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
public function getReason(): string |
172
|
|
|
{ |
173
|
|
|
return $this->reason; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
public function setReason(string $reason): self |
177
|
|
|
{ |
178
|
|
|
$this->reason = $reason; |
179
|
|
|
|
180
|
|
|
return $this; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
public function getDate(): \DateTimeImmutable |
184
|
|
|
{ |
185
|
|
|
return $this->date; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
public function setDate(\DateTimeImmutable $date): self |
189
|
|
|
{ |
190
|
|
|
$this->date = $date; |
191
|
|
|
|
192
|
|
|
return $this; |
193
|
|
|
} |
194
|
|
|
} |
195
|
|
|
|