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