|
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 ArrayCollection|ChannelInterface[] */ |
|
33
|
|
|
private $channels; |
|
34
|
|
|
|
|
35
|
|
|
/** @var ArrayCollection|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 $imageName): void |
|
141
|
|
|
{ |
|
142
|
|
|
/** @var BannerTranslationInterface $bannerTranslation */ |
|
143
|
|
|
$bannerTranslation = $this->getTranslation(); |
|
144
|
|
|
|
|
145
|
|
|
$bannerTranslation->setMobileImageName($imageName); |
|
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 getChannels(): Collection |
|
185
|
|
|
{ |
|
186
|
|
|
return $this->channels; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* {@inheritdoc} |
|
191
|
|
|
*/ |
|
192
|
|
|
public function hasChannel(ChannelInterface $channel): bool |
|
193
|
|
|
{ |
|
194
|
|
|
return $this->channels->contains($channel); |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* {@inheritdoc} |
|
199
|
|
|
*/ |
|
200
|
|
|
public function addChannel(ChannelInterface $channel): void |
|
201
|
|
|
{ |
|
202
|
|
|
if (!$this->hasChannel($channel)) { |
|
203
|
|
|
$this->channels->add($channel); |
|
204
|
|
|
} |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
/** |
|
208
|
|
|
* {@inheritdoc} |
|
209
|
|
|
*/ |
|
210
|
|
|
public function removeChannel(ChannelInterface $channel): void |
|
211
|
|
|
{ |
|
212
|
|
|
if ($this->hasChannel($channel)) { |
|
213
|
|
|
$this->channels->removeElement($channel); |
|
214
|
|
|
} |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
/** |
|
218
|
|
|
* {@inheritdoc} |
|
219
|
|
|
*/ |
|
220
|
|
|
public function getTaxons(): Collection |
|
221
|
|
|
{ |
|
222
|
|
|
return $this->taxons; |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
/** |
|
226
|
|
|
* {@inheritdoc} |
|
227
|
|
|
*/ |
|
228
|
|
|
public function hasTaxon(TaxonInterface $taxon): bool |
|
229
|
|
|
{ |
|
230
|
|
|
return $this->taxons->contains($taxon); |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
/** |
|
234
|
|
|
* {@inheritdoc} |
|
235
|
|
|
*/ |
|
236
|
|
|
public function addTaxon(TaxonInterface $taxon): void |
|
237
|
|
|
{ |
|
238
|
|
|
if (!$this->taxons->contains($taxon)) { |
|
239
|
|
|
$this->taxons->add($taxon); |
|
240
|
|
|
} |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
/** |
|
244
|
|
|
* {@inheritdoc} |
|
245
|
|
|
*/ |
|
246
|
|
|
public function removeTaxon(TaxonInterface $taxon): void |
|
247
|
|
|
{ |
|
248
|
|
|
if ($this->taxons->contains($taxon)) { |
|
249
|
|
|
$this->taxons->removeElement($taxon); |
|
250
|
|
|
} |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
/** |
|
254
|
|
|
* {@inheritdoc} |
|
255
|
|
|
*/ |
|
256
|
|
|
public function getTranslation(?string $locale = null): TranslationInterface |
|
257
|
|
|
{ |
|
258
|
|
|
/** @var BannerTranslation $translation */ |
|
259
|
|
|
$translation = $this->doGetTranslation($locale); |
|
260
|
|
|
|
|
261
|
|
|
return $translation; |
|
262
|
|
|
} |
|
263
|
|
|
|
|
264
|
|
|
/** |
|
265
|
|
|
* {@inheritdoc} |
|
266
|
|
|
*/ |
|
267
|
|
|
protected function createTranslation(): TranslationInterface |
|
268
|
|
|
{ |
|
269
|
|
|
return new BannerTranslation(); |
|
270
|
|
|
} |
|
271
|
|
|
} |
|
272
|
|
|
|