Completed
Push — master ( 97ef90...b0c954 )
by Matt
04:54
created

Image::setImageUri()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 2
rs 10
1
<?php
2
3
namespace App\Entity;
4
5
use ApiPlatform\Core\Annotation\ApiFilter;
6
use ApiPlatform\Core\Annotation\ApiResource;
7
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\ExistsFilter;
8
use App\EventListener\ImageCalculatedFieldSetterListener;
9
use App\EventListener\WanderUploadListener;
10
use App\Repository\ImageRepository;
11
use Doctrine\Common\Collections\ArrayCollection;
12
use Doctrine\Common\Collections\Collection;
13
use Doctrine\ORM\Mapping as ORM;
14
use Symfony\Component\HttpFoundation\File\File;
15
use Vich\UploaderBundle\Mapping\Annotation as Vich;
16
use Symfony\Component\Validator\Constraints as Assert;
17
use Symfony\Component\Serializer\Annotation\Groups;
18
use Symfony\Component\Serializer\Annotation\Ignore;
19
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
20
21
/**
22
 * @ApiResource(
23
 *  collectionOperations={"get"={"normalization_context"={"groups"="image:list"}}},
24
 *  itemOperations={"get"={"normalization_context"={"groups"="image:item"}}},
25
 *  order={"capturedAt"="ASC"},
26
 *  paginationEnabled=false
27
 * )
28
 *
29
 * @ApiFilter(SearchFilter::class, properties={"wanders": "exact"})
30
 * @ApiFilter(ExistsFilter::class, properties={"latlng"})
31
 *
32
 * @ORM\Entity(repositoryClass=ImageRepository::class)
33
 *
34
 * @ORM\EntityListeners({
35
 *     ImageCalculatedFieldSetterListener::class
36
 * })
37
 *
38
 * This is just to control the stuff that goes back from our one controller
39
 * action that returns a JSON response, ImageController::upload
40
 *
41
 * @Vich\Uploadable
42
 */
43
44
class Image
45
{
46
    /**
47
     * @ORM\Id
48
     * @ORM\GeneratedValue
49
     * @ORM\Column(type="integer")
50
     *
51
     * @Groups({"image:list", "image:item"})
52
     */
53
    private $id;
54
55
    // TODO: We probably don't want this massive field being returned
56
    // as part of any API response, etc.
57
    /**
58
     * @Vich\UploadableField(mapping="image", fileNameProperty="name", size="sizeInBytes",
59
     *  mimeType="mimeType", originalName="originalName", dimensions="dimensions")
60
     *
61
     * @Ignore()
62
     */
63
    private $imageFile;
64
65
    /**
66
     * @ORM\Column(type="string", length=255, nullable=true)
67
     *
68
     * @Groups({"image:list", "image:item"})
69
     */
70
    private $name; // For Vich, not for us. We use Title.
71
72
    /**
73
     * @ORM\Column(type="string", length=255, nullable=true)
74
     *
75
     * @Groups({"image:list", "image:item"})
76
     */
77
    private $title;
78
79
    /**
80
     * @ORM\Column(type="text", nullable=true)
81
     *
82
     * @Groups({"image:list", "image:item"})
83
     */
84
    private $description;
85
86
    /**
87
     * @ORM\Column(type="integer", nullable=true)
88
     *
89
     * @Groups({"image:list", "image:item"})
90
     */
91
    private $sizeInBytes;
92
93
    /**
94
     * @ORM\Column(type="string", length=255, nullable=true)
95
     *
96
     * @Groups({"image:list", "image:item"})
97
     */
98
    private $mimeType;
99
100
    /**
101
     * @ORM\Column(type="string", length=255, nullable=true)
102
     *
103
     * @Groups({"image:list", "image:item"})
104
     */
105
    private $originalName;
106
107
    /**
108
     * @ORM\Column(type="simple_array", nullable=true)
109
     *
110
     * @Groups({"image:list", "image:item"})
111
     */
112
    private $dimensions = [];
113
114
    /**
115
     * @ORM\Column(type="datetime")
116
     *
117
     * @Groups({"image:list", "image:item"})
118
     *
119
     * @var \DateTimeInterface|null
120
     */
121
    private $updatedAt;
122
123
    /**
124
     * @ORM\Column(type="simple_array", nullable=true)
125
     * @Assert\Count(
126
     *      min = 2,
127
     *      max = 2,
128
     *      minMessage = "There must be exactly two numbers in a latitude/longitude pair",
129
     *      maxMessage = "There must be exactly two numbers in a latitude/longitude pair",
130
     *      exactMessage = "Co-ordinates must consist of a latitude, longitude pair."
131
     * )
132
     *
133
     * @Groups({"image:list", "image:item"})
134
     *
135
     */
136
    private $latlng = [];
137
138
    /**
139
     * @ORM\Column(type="array", nullable=true, )
140
     *
141
     * @Groups({"image:list", "image:item"})
142
     */
143
    private $keywords = [];
144
145
    /**
146
     * @ORM\Column(type="datetime", nullable=true)
147
     *
148
     * @Groups({"image:list", "image:item"})
149
     */
150
    private $capturedAt;
151
152
    /**
153
     * @ORM\Column(type="integer", nullable=true)
154
     * @Groups({"image:list", "image:item"})
155
     */
156
    private $rating;
157
158
159
    // TODO: This @Ignore was here from when this was a many-to-many. Do we still
160
    // need it?
161
    /**
162
     * @ORM\ManyToOne(targetEntity=Wander::class, inversedBy="images")
163
     *
164
     * @Ignore()
165
     */
166
    private $wander;
167
168
    public function __construct()
169
    {
170
        // $this->wanders = new ArrayCollection();
171
    }
172
173
    /**
174
     * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
175
     * of 'UploadedFile' is injected into this setter to trigger the update. If this
176
     * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
177
     * must be able to accept an instance of 'File' as the bundle will inject one here
178
     * during Doctrine hydration.
179
     *
180
     * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
181
     */
182
    public function setImageFile(?File $imageFile = null): void
183
    {
184
        $this->imageFile = $imageFile;
185
186
        if (null !== $imageFile) {
187
            // It is required that at least one field changes if you are using doctrine
188
            // otherwise the event listeners won't be called and the file is lost
189
            $this->updatedAt = new \DateTimeImmutable();
190
        }
191
    }
192
193
    /**
194
     * @Ignore()
195
     */
196
    public function getImageFile(): ?File
197
    {
198
        return $this->imageFile;
199
    }
200
201
    public function getId(): ?int
202
    {
203
        return $this->id;
204
    }
205
206
    public function getName(): ?string
207
    {
208
        return $this->name;
209
    }
210
211
    public function setName(?string $name): self
212
    {
213
        $this->name = $name;
214
215
        return $this;
216
    }
217
218
    public function getTitle(): ?string
219
    {
220
        return $this->title;
221
    }
222
223
    public function setTitle(?string $title): self
224
    {
225
        $this->title = $title;
226
227
        return $this;
228
    }
229
230
    public function getDescription(): ?string
231
    {
232
        return $this->description;
233
    }
234
235
    public function setDescription(?string $description): self
236
    {
237
        $this->description = $description;
238
239
        return $this;
240
    }
241
242
    public function getSizeInBytes(): ?int
243
    {
244
        return $this->sizeInBytes;
245
    }
246
247
    public function setSizeInBytes(?int $sizeInBytes): self
248
    {
249
        $this->sizeInBytes = $sizeInBytes;
250
251
        return $this;
252
    }
253
254
    public function getMimeType(): ?string
255
    {
256
        return $this->mimeType;
257
    }
258
259
    public function setMimeType(?string $mimeType): self
260
    {
261
        $this->mimeType = $mimeType;
262
263
        return $this;
264
    }
265
266
    public function getOriginalName(): ?string
267
    {
268
        return $this->originalName;
269
    }
270
271
    public function setOriginalName(?string $originalName): self
272
    {
273
        $this->originalName = $originalName;
274
275
        return $this;
276
    }
277
278
    public function getDimensions(): ?array
279
    {
280
        return $this->dimensions;
281
    }
282
283
    public function setDimensions(?array $dimensions): self
284
    {
285
        $this->dimensions = $dimensions;
286
287
        return $this;
288
    }
289
290
    public function getUpdatedAt(): ?\DateTimeInterface
291
    {
292
        return $this->updatedAt;
293
    }
294
295
    public function setUpdatedAt(\DateTimeInterface $updatedAt): self
296
    {
297
        $this->updatedAt = $updatedAt;
298
        return $this;
299
    }
300
301
    public function getLatlng(): ?array
302
    {
303
        return $this->latlng;
304
    }
305
306
    public function setLatlng(?array $latlng): self
307
    {
308
        $this->latlng = $latlng;
309
310
        return $this;
311
    }
312
313
    public function getKeywords(): ?array
314
    {
315
        return $this->keywords;
316
    }
317
318
    public function setKeywords(?array $keywords): self
319
    {
320
        $this->keywords = $keywords;
321
322
        return $this;
323
    }
324
325
    public function getCapturedAt(): ?\DateTimeInterface
326
    {
327
        return $this->capturedAt;
328
    }
329
330
    public function setCapturedAt(\DateTimeInterface $capturedAt): self
331
    {
332
        $this->capturedAt = $capturedAt;
333
334
        return $this;
335
    }
336
337
    // /**
338
    //  * @return Collection|Wander[]
339
    //  */
340
    // public function getWanders(): Collection
341
    // {
342
    //     return $this->wanders;
343
    // }
344
345
    // public function addWander(Wander $wander): self
346
    // {
347
    //     if (!$this->wanders->contains($wander)) {
348
    //         $this->wanders[] = $wander;
349
    //         $wander->addImage($this);
350
    //     }
351
352
    //     return $this;
353
    // }
354
355
    // public function removeWander(Wander $wander): self
356
    // {
357
    //     if ($this->wanders->removeElement($wander)) {
358
    //         $wander->removeImage($this);
359
    //     }
360
361
    //     return $this;
362
    // }
363
364
    public function getWander(): ?Wander
365
    {
366
        return $this->wander;
367
    }
368
369
    public function setWander(?Wander $wander): self
370
    {
371
        $this->wander = $wander;
372
        return $this;
373
    }
374
375
    public function getRating(): ?int
376
    {
377
        return $this->rating;
378
    }
379
380
    public function setRating(?int $rating): self
381
    {
382
        $this->rating = $rating;
383
384
        return $this;
385
    }
386
387
388
    /* Computed (set up by Doctrine postLoad listener) */
389
390
    /**
391
     * @Groups({"image:list", "image:item"})
392
     */
393
    private $imageUri;
394
395
    /**
396
     * @Groups({"image:list", "image:item"})
397
     */
398
    private $markerImageUri;
399
400
    /**
401
     * @Groups({"image:list", "image:item"})
402
     */
403
    private $mediumImageUri;
404
405
    /**
406
     * @Groups({"image:list", "image:item"})
407
     */
408
    private $imageShowUri;
409
410
411
    public function setImageUri($imageUri) {
412
        $this->imageUri = $imageUri;
413
    }
414
415
    public function getImageUri(): ?string {
416
        return $this->imageUri;
417
    }
418
419
    public function setMarkerImageUri($markerImageUri) {
420
        $this->markerImageUri = $markerImageUri;
421
    }
422
    public function getMarkerImageUri(): ?string {
423
        return $this->markerImageUri;
424
    }
425
426
    public function setMediumImageUri($mediumImageUri) {
427
        $this->mediumImageUri = $mediumImageUri;
428
    }
429
    public function getMediumImageUri(): ?string {
430
        return $this->mediumImageUri;
431
    }
432
433
    public function setImageShowUri($imageShowUri) {
434
        $this->imageShowUri = $imageShowUri;
435
    }
436
    public function getImageShowUri(): ?string {
437
        return $this->imageShowUri;
438
    }
439
}
440
441