1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Silverback\ApiComponentBundle\Entity\Content\Component\Gallery; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Mapping as ORM; |
6
|
|
|
use Silverback\ApiComponentBundle\Entity\Content\Component\AbstractComponent; |
7
|
|
|
use Silverback\ApiComponentBundle\Entity\Content\FileInterface; |
8
|
|
|
use Silverback\ApiComponentBundle\Entity\Content\FileTrait; |
9
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
10
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
11
|
|
|
use Symfony\Component\Validator\Mapping\ClassMetadata; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class GalleryItem |
15
|
|
|
* @package Silverback\ApiComponentBundle\Entity\Content\Component\Gallery |
16
|
|
|
* @author Daniel West <[email protected]> |
17
|
|
|
* @ORM\Entity() |
18
|
|
|
*/ |
19
|
|
|
class GalleryItem extends AbstractComponent implements FileInterface |
20
|
|
|
{ |
21
|
|
|
use FileTrait; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @ORM\Column() |
25
|
|
|
* @Groups({"component", "content"}) |
26
|
|
|
* @var null|string |
27
|
|
|
*/ |
28
|
|
|
protected $title; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @ORM\Column() |
32
|
|
|
* @Groups({"component", "content"}) |
33
|
|
|
* @var null|string |
34
|
|
|
*/ |
35
|
|
|
protected $caption; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param ClassMetadata $metadata |
39
|
|
|
*/ |
40
|
3 |
|
public static function loadValidatorMetadata(ClassMetadata $metadata) |
41
|
|
|
{ |
42
|
3 |
|
$metadata->addPropertyConstraints( |
43
|
3 |
|
'filePath', |
44
|
3 |
|
[ new Assert\Image() ] // new Assert\NotBlank(), |
45
|
|
|
); |
46
|
3 |
|
$metadata->addPropertyConstraint( |
47
|
3 |
|
'title', |
48
|
3 |
|
new Assert\NotBlank() |
49
|
|
|
); |
50
|
3 |
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Gallery constructor. |
54
|
|
|
*/ |
55
|
4 |
|
public function __construct() |
56
|
|
|
{ |
57
|
4 |
|
parent::__construct(); |
58
|
4 |
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return null|string |
62
|
|
|
*/ |
63
|
1 |
|
public function getTitle(): ?string |
64
|
|
|
{ |
65
|
1 |
|
return $this->title; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param null|string $title |
70
|
|
|
* @return GalleryItem |
71
|
|
|
*/ |
72
|
2 |
|
public function setTitle(?string $title): self |
73
|
|
|
{ |
74
|
2 |
|
$this->title = $title; |
75
|
2 |
|
return $this; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return null|string |
80
|
|
|
*/ |
81
|
1 |
|
public function getCaption(): ?string |
82
|
|
|
{ |
83
|
1 |
|
return $this->caption; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param null|string $caption |
88
|
|
|
* @return GalleryItem |
89
|
|
|
*/ |
90
|
2 |
|
public function setCaption(?string $caption): self |
91
|
|
|
{ |
92
|
2 |
|
$this->caption = $caption; |
93
|
2 |
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function getDir(): ?string |
97
|
|
|
{ |
98
|
|
|
return 'gallery'; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|