1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Superdesk Web Publisher Content Bundle. |
5
|
|
|
* |
6
|
|
|
* Copyright 2016 Sourcefabric z.ú. and contributors. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please see the |
9
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* @copyright 2016 Sourcefabric z.ú |
12
|
|
|
* @license http://www.superdesk.org/license |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace SWP\Bundle\ContentBundle\Model; |
16
|
|
|
|
17
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
18
|
|
|
use function in_array; |
19
|
|
|
use SWP\Component\Common\Model\TimestampableTrait; |
20
|
|
|
|
21
|
|
|
class Image implements ImageInterface |
22
|
|
|
{ |
23
|
|
|
use TimestampableTrait; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $id; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Uploaded file extension. |
32
|
|
|
* |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
protected $fileExtension; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
protected $assetId; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var ArticleMediaInterface |
44
|
|
|
*/ |
45
|
|
|
protected $media; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var int |
49
|
|
|
*/ |
50
|
|
|
protected $width; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var int |
54
|
|
|
*/ |
55
|
|
|
protected $height; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var float |
59
|
|
|
*/ |
60
|
|
|
protected $length; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var ArrayCollection |
64
|
|
|
*/ |
65
|
|
|
protected $renditions; |
66
|
|
|
|
67
|
|
|
protected $variants = []; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* File constructor. |
71
|
|
|
*/ |
72
|
|
|
public function __construct() |
73
|
|
|
{ |
74
|
|
|
$this->setCreatedAt(new \DateTime()); |
75
|
|
|
$this->setRenditions(new ArrayCollection()); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return ArticleMediaInterface |
80
|
|
|
*/ |
81
|
|
|
public function getMedia(): ArticleMediaInterface |
82
|
|
|
{ |
83
|
|
|
return $this->media; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param ArticleMediaInterface $media |
88
|
|
|
*/ |
89
|
|
|
public function setMedia(ArticleMediaInterface $media) |
90
|
|
|
{ |
91
|
|
|
$this->media = $media; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param string $id |
96
|
|
|
*/ |
97
|
|
|
public function setId($id) |
98
|
|
|
{ |
99
|
|
|
$this->id = $id; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* {@inheritdoc} |
104
|
|
|
*/ |
105
|
|
|
public function getId() |
106
|
|
|
{ |
107
|
|
|
return $this->id; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* {@inheritdoc} |
112
|
|
|
*/ |
113
|
|
|
public function setFileExtension($extension) |
114
|
|
|
{ |
115
|
|
|
$this->fileExtension = $extension; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* {@inheritdoc} |
120
|
|
|
*/ |
121
|
|
|
public function getFileExtension() |
122
|
|
|
{ |
123
|
|
|
return $this->fileExtension; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return string |
128
|
|
|
*/ |
129
|
|
|
public function getAssetId(): string |
130
|
|
|
{ |
131
|
|
|
return $this->assetId; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* {@inheritdoc} |
136
|
|
|
*/ |
137
|
|
|
public function setAssetId(string $assetId) |
138
|
|
|
{ |
139
|
|
|
$this->assetId = $assetId; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @return ArrayCollection |
144
|
|
|
*/ |
145
|
|
|
public function getRenditions() |
146
|
|
|
{ |
147
|
|
|
return $this->renditions; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @param ImageRendition $rendition |
152
|
|
|
*/ |
153
|
|
|
public function addRendition(ImageRendition $rendition) |
154
|
|
|
{ |
155
|
|
|
$this->renditions->add($rendition); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param ArrayCollection $renditions |
160
|
|
|
*/ |
161
|
|
|
public function setRenditions($renditions) |
162
|
|
|
{ |
163
|
|
|
$this->renditions = $renditions; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
public function getWidth(): int |
167
|
|
|
{ |
168
|
|
|
return $this->width; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
public function setWidth(int $width): void |
172
|
|
|
{ |
173
|
|
|
$this->width = $width; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
public function getHeight(): int |
177
|
|
|
{ |
178
|
|
|
return $this->height; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
public function setHeight(int $height): void |
182
|
|
|
{ |
183
|
|
|
$this->height = $height; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
public function getLength(): float |
187
|
|
|
{ |
188
|
|
|
return $this->length; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
public function setLength(float $length): void |
192
|
|
|
{ |
193
|
|
|
$this->length = $length; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
public function getVariants(): array |
197
|
|
|
{ |
198
|
|
|
return $this->variants; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
public function setVariants(array $variants): void |
202
|
|
|
{ |
203
|
|
|
$this->variants = $variants; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
public function addVariant(string $variant): void |
207
|
|
|
{ |
208
|
|
|
if (!$this->hasVariant($variant)) { |
209
|
|
|
$this->variants[] = $variant; |
210
|
|
|
} |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
public function hasVariant(string $variant): bool |
214
|
|
|
{ |
215
|
|
|
return in_array($variant, $this->getVariants(), true); |
216
|
|
|
} |
217
|
|
|
} |
218
|
|
|
|