1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Odiseo\SyliusBannerPlugin\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\Resource\Model\TimestampableTrait; |
11
|
|
|
use Sylius\Component\Resource\Model\ToggleableTrait; |
12
|
|
|
use Sylius\Component\Resource\Model\TranslatableTrait; |
13
|
|
|
use Sylius\Component\Resource\Model\TranslationInterface; |
14
|
|
|
use Sylius\Component\Taxonomy\Model\TaxonInterface; |
15
|
|
|
use Symfony\Component\HttpFoundation\File\File; |
16
|
|
|
|
17
|
|
|
class Banner implements BannerInterface |
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 $code; |
31
|
|
|
|
32
|
|
|
/** @var Collection|ChannelInterface[] */ |
33
|
|
|
private $channels; |
34
|
|
|
|
35
|
|
|
/** @var Collection|TaxonInterface[] */ |
36
|
|
|
private $taxons; |
37
|
|
|
|
38
|
|
|
public function __construct() |
39
|
|
|
{ |
40
|
|
|
$this->initializeTranslationsCollection(); |
41
|
|
|
|
42
|
|
|
$this->channels = new ArrayCollection(); |
43
|
|
|
$this->taxons = new ArrayCollection(); |
44
|
|
|
$this->createdAt = new \DateTime(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritdoc} |
49
|
|
|
*/ |
50
|
|
|
public function getId(): ?int |
51
|
|
|
{ |
52
|
|
|
return $this->id; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritdoc} |
57
|
|
|
*/ |
58
|
|
|
public function getCode(): ?string |
59
|
|
|
{ |
60
|
|
|
return $this->code; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* {@inheritdoc} |
65
|
|
|
*/ |
66
|
|
|
public function setCode(?string $code): void |
67
|
|
|
{ |
68
|
|
|
$this->code = $code; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* {@inheritdoc} |
73
|
|
|
*/ |
74
|
|
|
public function setImageFile(?File $file): void |
75
|
|
|
{ |
76
|
|
|
/** @var BannerTranslationInterface $bannerTranslation */ |
77
|
|
|
$bannerTranslation = $this->getTranslation(); |
78
|
|
|
|
79
|
|
|
$bannerTranslation->setImageFile($file); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* {@inheritdoc} |
84
|
|
|
*/ |
85
|
|
|
public function getImageFile(): ?File |
86
|
|
|
{ |
87
|
|
|
/** @var BannerTranslationInterface $bannerTranslation */ |
88
|
|
|
$bannerTranslation = $this->getTranslation(); |
89
|
|
|
|
90
|
|
|
return $bannerTranslation->getImageFile(); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* {@inheritdoc} |
95
|
|
|
*/ |
96
|
|
|
public function setImageName(?string $imageName): void |
97
|
|
|
{ |
98
|
|
|
/** @var BannerTranslationInterface $bannerTranslation */ |
99
|
|
|
$bannerTranslation = $this->getTranslation(); |
100
|
|
|
|
101
|
|
|
$bannerTranslation->setImageName($imageName); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* {@inheritdoc} |
106
|
|
|
*/ |
107
|
|
|
public function getImageName(): ?string |
108
|
|
|
{ |
109
|
|
|
/** @var BannerTranslationInterface $bannerTranslation */ |
110
|
|
|
$bannerTranslation = $this->getTranslation(); |
111
|
|
|
|
112
|
|
|
return $bannerTranslation->getImageName(); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* {@inheritdoc} |
117
|
|
|
*/ |
118
|
|
|
public function setMobileImageFile(?File $file): void |
119
|
|
|
{ |
120
|
|
|
/** @var BannerTranslationInterface $bannerTranslation */ |
121
|
|
|
$bannerTranslation = $this->getTranslation(); |
122
|
|
|
|
123
|
|
|
$bannerTranslation->setMobileImageFile($file); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* {@inheritdoc} |
128
|
|
|
*/ |
129
|
|
|
public function getMobileImageFile(): ?File |
130
|
|
|
{ |
131
|
|
|
/** @var BannerTranslationInterface $bannerTranslation */ |
132
|
|
|
$bannerTranslation = $this->getTranslation(); |
133
|
|
|
|
134
|
|
|
return $bannerTranslation->getMobileImageFile(); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* {@inheritdoc} |
139
|
|
|
*/ |
140
|
|
|
public function setMobileImageName(?string $mobileImageName): void |
141
|
|
|
{ |
142
|
|
|
/** @var BannerTranslationInterface $bannerTranslation */ |
143
|
|
|
$bannerTranslation = $this->getTranslation(); |
144
|
|
|
|
145
|
|
|
$bannerTranslation->setMobileImageName($mobileImageName); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* {@inheritdoc} |
150
|
|
|
*/ |
151
|
|
|
public function getMobileImageName(): ?string |
152
|
|
|
{ |
153
|
|
|
/** @var BannerTranslationInterface $bannerTranslation */ |
154
|
|
|
$bannerTranslation = $this->getTranslation(); |
155
|
|
|
|
156
|
|
|
return $bannerTranslation->getMobileImageName(); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* {@inheritdoc} |
161
|
|
|
*/ |
162
|
|
|
public function setUrl(?string $url): void |
163
|
|
|
{ |
164
|
|
|
/** @var BannerTranslationInterface $bannerTranslation */ |
165
|
|
|
$bannerTranslation = $this->getTranslation(); |
166
|
|
|
|
167
|
|
|
$bannerTranslation->setUrl($url); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* {@inheritdoc} |
172
|
|
|
*/ |
173
|
|
|
public function getUrl(): ?string |
174
|
|
|
{ |
175
|
|
|
/** @var BannerTranslationInterface $bannerTranslation */ |
176
|
|
|
$bannerTranslation = $this->getTranslation(); |
177
|
|
|
|
178
|
|
|
return $bannerTranslation->getUrl(); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* {@inheritdoc} |
183
|
|
|
*/ |
184
|
|
|
public function setMainText(?string $mainText): void |
185
|
|
|
{ |
186
|
|
|
/** @var BannerTranslationInterface $bannerTranslation */ |
187
|
|
|
$bannerTranslation = $this->getTranslation(); |
188
|
|
|
|
189
|
|
|
$bannerTranslation->setMainText($mainText); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* {@inheritdoc} |
194
|
|
|
*/ |
195
|
|
|
public function getMainText(): ?string |
196
|
|
|
{ |
197
|
|
|
/** @var BannerTranslationInterface $bannerTranslation */ |
198
|
|
|
$bannerTranslation = $this->getTranslation(); |
199
|
|
|
|
200
|
|
|
return $bannerTranslation->getMainText(); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* {@inheritdoc} |
205
|
|
|
*/ |
206
|
|
|
public function setSecondaryText(?string $secondaryText): void |
207
|
|
|
{ |
208
|
|
|
/** @var BannerTranslationInterface $bannerTranslation */ |
209
|
|
|
$bannerTranslation = $this->getTranslation(); |
210
|
|
|
|
211
|
|
|
$bannerTranslation->setSecondaryText($secondaryText); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* {@inheritdoc} |
216
|
|
|
*/ |
217
|
|
|
public function getSecondaryText(): ?string |
218
|
|
|
{ |
219
|
|
|
/** @var BannerTranslationInterface $bannerTranslation */ |
220
|
|
|
$bannerTranslation = $this->getTranslation(); |
221
|
|
|
|
222
|
|
|
return $bannerTranslation->getSecondaryText(); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* {@inheritdoc} |
227
|
|
|
*/ |
228
|
|
|
public function getChannels(): Collection |
229
|
|
|
{ |
230
|
|
|
return $this->channels; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* {@inheritdoc} |
235
|
|
|
*/ |
236
|
|
|
public function hasChannel(ChannelInterface $channel): bool |
237
|
|
|
{ |
238
|
|
|
return $this->channels->contains($channel); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* {@inheritdoc} |
243
|
|
|
*/ |
244
|
|
|
public function addChannel(ChannelInterface $channel): void |
245
|
|
|
{ |
246
|
|
|
if (!$this->hasChannel($channel)) { |
247
|
|
|
$this->channels->add($channel); |
248
|
|
|
} |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* {@inheritdoc} |
253
|
|
|
*/ |
254
|
|
|
public function removeChannel(ChannelInterface $channel): void |
255
|
|
|
{ |
256
|
|
|
if ($this->hasChannel($channel)) { |
257
|
|
|
$this->channels->removeElement($channel); |
258
|
|
|
} |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* {@inheritdoc} |
263
|
|
|
*/ |
264
|
|
|
public function getTaxons(): Collection |
265
|
|
|
{ |
266
|
|
|
return $this->taxons; |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* {@inheritdoc} |
271
|
|
|
*/ |
272
|
|
|
public function hasTaxon(TaxonInterface $taxon): bool |
273
|
|
|
{ |
274
|
|
|
return $this->taxons->contains($taxon); |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* {@inheritdoc} |
279
|
|
|
*/ |
280
|
|
|
public function addTaxon(TaxonInterface $taxon): void |
281
|
|
|
{ |
282
|
|
|
if (!$this->taxons->contains($taxon)) { |
283
|
|
|
$this->taxons->add($taxon); |
284
|
|
|
} |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* {@inheritdoc} |
289
|
|
|
*/ |
290
|
|
|
public function removeTaxon(TaxonInterface $taxon): void |
291
|
|
|
{ |
292
|
|
|
if ($this->taxons->contains($taxon)) { |
293
|
|
|
$this->taxons->removeElement($taxon); |
294
|
|
|
} |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* {@inheritdoc} |
299
|
|
|
*/ |
300
|
|
|
public function getTranslation(?string $locale = null): TranslationInterface |
301
|
|
|
{ |
302
|
|
|
/** @var BannerTranslation $translation */ |
303
|
|
|
$translation = $this->doGetTranslation($locale); |
304
|
|
|
|
305
|
|
|
return $translation; |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* {@inheritdoc} |
310
|
|
|
*/ |
311
|
|
|
protected function createTranslation(): TranslationInterface |
312
|
|
|
{ |
313
|
|
|
return new BannerTranslation(); |
314
|
|
|
} |
315
|
|
|
} |
316
|
|
|
|