1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Odiseo\SyliusVendorPlugin\Entity; |
6
|
|
|
|
7
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
8
|
|
|
use Doctrine\Common\Collections\Collection; |
9
|
|
|
use Sylius\Component\Channel\Model\ChannelInterface; |
10
|
|
|
use Sylius\Component\Product\Model\ProductInterface; |
11
|
|
|
use Sylius\Component\Resource\Model\TimestampableTrait; |
12
|
|
|
use Sylius\Component\Resource\Model\ToggleableTrait; |
13
|
|
|
use Sylius\Component\Resource\Model\TranslatableTrait; |
14
|
|
|
use Sylius\Component\Resource\Model\TranslationInterface; |
15
|
|
|
use Symfony\Component\HttpFoundation\File\File; |
16
|
|
|
|
17
|
|
|
class Vendor implements VendorInterface |
18
|
|
|
{ |
19
|
|
|
use TranslatableTrait { |
20
|
|
|
__construct as private initializeTranslationsCollection; |
21
|
|
|
getTranslation as private doGetTranslation; |
22
|
|
|
} |
23
|
|
|
use TimestampableTrait; |
24
|
|
|
use ToggleableTrait; |
25
|
|
|
|
26
|
|
|
/** @var int|null */ |
27
|
|
|
protected $id; |
28
|
|
|
|
29
|
|
|
/** @var string|null */ |
30
|
|
|
protected $name; |
31
|
|
|
|
32
|
|
|
/** @var string|null */ |
33
|
|
|
protected $slug; |
34
|
|
|
|
35
|
|
|
/** @var string|null */ |
36
|
|
|
protected $email; |
37
|
|
|
|
38
|
|
|
/** @var File|null */ |
39
|
|
|
protected $logoFile; |
40
|
|
|
|
41
|
|
|
/** @var string|null */ |
42
|
|
|
protected $logoName; |
43
|
|
|
|
44
|
|
|
/** @var int|null */ |
45
|
|
|
protected $position; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var Collection|ChannelInterface[] |
49
|
|
|
* |
50
|
|
|
* @psalm-var Collection<array-key, ChannelInterface> |
51
|
|
|
*/ |
52
|
|
|
protected $channels; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var Collection|ProductInterface[] |
56
|
|
|
* |
57
|
|
|
* @psalm-var Collection<array-key, ProductInterface> |
58
|
|
|
*/ |
59
|
|
|
protected $products; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var Collection|VendorEmailInterface[] |
63
|
|
|
* |
64
|
|
|
* @psalm-var Collection<array-key, VendorEmailInterface> |
65
|
|
|
*/ |
66
|
|
|
protected $extraEmails; |
67
|
|
|
|
68
|
|
|
public function __construct() |
69
|
|
|
{ |
70
|
|
|
$this->initializeTranslationsCollection(); |
71
|
|
|
|
72
|
|
|
$this->channels = new ArrayCollection(); |
73
|
|
|
$this->products = new ArrayCollection(); |
74
|
|
|
$this->extraEmails = new ArrayCollection(); |
75
|
|
|
$this->createdAt = new \DateTime(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* {@inheritdoc} |
80
|
|
|
*/ |
81
|
|
|
public function getId(): ?int |
82
|
|
|
{ |
83
|
|
|
return $this->id; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* {@inheritdoc} |
88
|
|
|
*/ |
89
|
|
|
public function getName(): ?string |
90
|
|
|
{ |
91
|
|
|
return $this->name; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* {@inheritdoc} |
96
|
|
|
*/ |
97
|
|
|
public function setName(?string $name): void |
98
|
|
|
{ |
99
|
|
|
$this->name = $name; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* {@inheritdoc} |
104
|
|
|
*/ |
105
|
|
|
public function getDescription(): ?string |
106
|
|
|
{ |
107
|
|
|
/** @var VendorTranslationInterface $vendorTranslation */ |
108
|
|
|
$vendorTranslation = $this->getTranslation(); |
109
|
|
|
|
110
|
|
|
return $vendorTranslation->getDescription(); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* {@inheritdoc} |
115
|
|
|
*/ |
116
|
|
|
public function setDescription(?string $description): void |
117
|
|
|
{ |
118
|
|
|
/** @var VendorTranslationInterface $vendorTranslation */ |
119
|
|
|
$vendorTranslation = $this->getTranslation(); |
120
|
|
|
|
121
|
|
|
$vendorTranslation->setDescription($description); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* {@inheritdoc} |
126
|
|
|
*/ |
127
|
|
|
public function getSlug(): ?string |
128
|
|
|
{ |
129
|
|
|
return $this->slug; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* {@inheritdoc} |
134
|
|
|
*/ |
135
|
|
|
public function setSlug(?string $slug = null): void |
136
|
|
|
{ |
137
|
|
|
$this->slug = $slug; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* {@inheritdoc} |
142
|
|
|
*/ |
143
|
|
|
public function getEmail(): ?string |
144
|
|
|
{ |
145
|
|
|
return $this->email; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* {@inheritdoc} |
150
|
|
|
*/ |
151
|
|
|
public function setEmail(?string $email): void |
152
|
|
|
{ |
153
|
|
|
$this->email = $email; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* {@inheritdoc} |
158
|
|
|
*/ |
159
|
|
|
public function setLogoFile(?File $file): void |
160
|
|
|
{ |
161
|
|
|
$this->logoFile = $file; |
162
|
|
|
|
163
|
|
|
$this->setUpdatedAt(new \DateTime()); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* {@inheritdoc} |
168
|
|
|
*/ |
169
|
|
|
public function getLogoFile(): ?File |
170
|
|
|
{ |
171
|
|
|
return $this->logoFile; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* {@inheritdoc} |
176
|
|
|
*/ |
177
|
|
|
public function setLogoName(?string $logoName): void |
178
|
|
|
{ |
179
|
|
|
$this->logoName = $logoName; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* {@inheritdoc} |
184
|
|
|
*/ |
185
|
|
|
public function getLogoName(): ?string |
186
|
|
|
{ |
187
|
|
|
return $this->logoName; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* {@inheritdoc} |
192
|
|
|
*/ |
193
|
|
|
public function getPosition(): ?int |
194
|
|
|
{ |
195
|
|
|
return $this->position; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* {@inheritdoc} |
200
|
|
|
*/ |
201
|
|
|
public function setPosition(?int $position): void |
202
|
|
|
{ |
203
|
|
|
$this->position = $position; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* {@inheritdoc} |
208
|
|
|
*/ |
209
|
|
|
public function getChannels(): Collection |
210
|
|
|
{ |
211
|
|
|
return $this->channels; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* {@inheritdoc} |
216
|
|
|
*/ |
217
|
|
|
public function hasChannel(ChannelInterface $channel): bool |
218
|
|
|
{ |
219
|
|
|
return $this->channels->contains($channel); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* {@inheritdoc} |
224
|
|
|
*/ |
225
|
|
|
public function addChannel(ChannelInterface $channel): void |
226
|
|
|
{ |
227
|
|
|
if (!$this->hasChannel($channel)) { |
228
|
|
|
$this->channels->add($channel); |
229
|
|
|
|
230
|
|
|
if ($channel instanceof VendorsAwareInterface) { |
231
|
|
|
$channel->addVendor($this); |
232
|
|
|
} |
233
|
|
|
} |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* {@inheritdoc} |
238
|
|
|
*/ |
239
|
|
|
public function removeChannel(ChannelInterface $channel): void |
240
|
|
|
{ |
241
|
|
|
if ($this->hasChannel($channel)) { |
242
|
|
|
$this->channels->removeElement($channel); |
243
|
|
|
|
244
|
|
|
if ($channel instanceof VendorsAwareInterface) { |
245
|
|
|
$channel->removeVendor($this); |
246
|
|
|
} |
247
|
|
|
} |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* {@inheritdoc} |
252
|
|
|
*/ |
253
|
|
|
public function getProducts(): Collection |
254
|
|
|
{ |
255
|
|
|
return $this->products; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* {@inheritdoc} |
260
|
|
|
*/ |
261
|
|
|
public function hasProduct(ProductInterface $product): bool |
262
|
|
|
{ |
263
|
|
|
return $this->products->contains($product); |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* {@inheritdoc} |
268
|
|
|
*/ |
269
|
|
|
public function addProduct(ProductInterface $product): void |
270
|
|
|
{ |
271
|
|
|
if (!$this->hasProduct($product)) { |
272
|
|
|
$this->products->add($product); |
273
|
|
|
|
274
|
|
|
if ($product instanceof VendorAwareInterface) { |
275
|
|
|
$product->setVendor($this); |
276
|
|
|
} |
277
|
|
|
} |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* {@inheritdoc} |
282
|
|
|
*/ |
283
|
|
|
public function removeProduct(ProductInterface $product): void |
284
|
|
|
{ |
285
|
|
|
if ($this->hasProduct($product)) { |
286
|
|
|
$this->products->removeElement($product); |
287
|
|
|
|
288
|
|
|
if ($product instanceof VendorAwareInterface) { |
289
|
|
|
$product->setVendor(null); |
290
|
|
|
} |
291
|
|
|
} |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* {@inheritdoc} |
296
|
|
|
*/ |
297
|
|
|
public function getExtraEmails(): Collection |
298
|
|
|
{ |
299
|
|
|
return $this->extraEmails; |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* {@inheritdoc} |
304
|
|
|
*/ |
305
|
|
|
public function hasExtraEmail(VendorEmailInterface $email): bool |
306
|
|
|
{ |
307
|
|
|
return $this->extraEmails->contains($email); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* {@inheritdoc} |
312
|
|
|
*/ |
313
|
|
|
public function addExtraEmail(VendorEmailInterface $email): void |
314
|
|
|
{ |
315
|
|
|
if (!$this->hasExtraEmail($email)) { |
316
|
|
|
$this->extraEmails->add($email); |
317
|
|
|
$email->setVendor($this); |
318
|
|
|
} |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
/** |
322
|
|
|
* {@inheritdoc} |
323
|
|
|
*/ |
324
|
|
|
public function removeExtraEmail(VendorEmailInterface $email): void |
325
|
|
|
{ |
326
|
|
|
if ($this->hasExtraEmail($email)) { |
327
|
|
|
$this->extraEmails->removeElement($email); |
328
|
|
|
$email->setVendor(null); |
329
|
|
|
} |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
/** |
333
|
|
|
* {@inheritdoc} |
334
|
|
|
*/ |
335
|
|
|
protected function createTranslation(): TranslationInterface |
336
|
|
|
{ |
337
|
|
|
return new VendorTranslation(); |
338
|
|
|
} |
339
|
|
|
} |
340
|
|
|
|