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