1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Silverback\ApiComponentBundle\Entity\Component\Article; |
4
|
|
|
|
5
|
|
|
use ApiPlatform\Core\Annotation\ApiResource; |
6
|
|
|
use Doctrine\ORM\Mapping as ORM; |
7
|
|
|
use Silverback\ApiComponentBundle\Entity\Component\AbstractComponent; |
8
|
|
|
use Silverback\ApiComponentBundle\Entity\Component\FileInterface; |
9
|
|
|
use Silverback\ApiComponentBundle\Entity\Component\FileTrait; |
10
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
11
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
12
|
|
|
use Symfony\Component\Validator\Mapping\ClassMetadata; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class News |
16
|
|
|
* @package Silverback\ApiComponentBundle\Entity\Component\News |
17
|
|
|
* @author Daniel West <[email protected]> |
18
|
|
|
* @ApiResource(shortName="component/article") |
19
|
|
|
* @ORM\Entity() |
20
|
|
|
* @ORM\AttributeOverrides({ |
21
|
|
|
* @ORM\AttributeOverride( |
22
|
|
|
* name="filePath", |
23
|
|
|
* column=@ORM\Column( |
24
|
|
|
* nullable=true |
25
|
|
|
* ) |
26
|
|
|
* ) |
27
|
|
|
* }) |
28
|
|
|
*/ |
29
|
|
|
class Article extends AbstractComponent implements FileInterface |
30
|
|
|
{ |
31
|
|
|
use FileTrait; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @ORM\Column(type="string", nullable=false) |
35
|
|
|
* @Groups({"content", "component"}) |
36
|
|
|
* @var null|string |
37
|
|
|
*/ |
38
|
|
|
private $title; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @ORM\Column(type="string") |
42
|
|
|
* @Groups({"content", "component"}) |
43
|
|
|
* @var null|string |
44
|
|
|
*/ |
45
|
|
|
private $subtitle; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @ORM\Column(type="text") |
49
|
|
|
* @Groups({"content", "component"}) |
50
|
|
|
* @var string |
51
|
|
|
*/ |
52
|
|
|
private $content; |
53
|
|
|
|
54
|
1 |
|
public static function loadValidatorMetadata(ClassMetadata $metadata): void |
55
|
|
|
{ |
56
|
1 |
|
$metadata->addPropertyConstraint( |
57
|
1 |
|
'filePath', |
58
|
1 |
|
new Assert\Image() |
59
|
|
|
); |
60
|
|
|
|
61
|
1 |
|
$metadata->addPropertyConstraint( |
62
|
1 |
|
'title', |
63
|
1 |
|
new Assert\NotNull() |
64
|
|
|
); |
65
|
|
|
|
66
|
1 |
|
$metadata->addPropertyConstraint( |
67
|
1 |
|
'content', |
68
|
1 |
|
new Assert\NotNull() |
69
|
|
|
); |
70
|
1 |
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return null|string |
74
|
|
|
*/ |
75
|
1 |
|
public function getTitle(): ?string |
76
|
|
|
{ |
77
|
1 |
|
return $this->title; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param null|string $title |
82
|
|
|
*/ |
83
|
1 |
|
public function setTitle(?string $title): void |
84
|
|
|
{ |
85
|
1 |
|
$this->title = $title; |
86
|
1 |
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return null|string |
90
|
|
|
*/ |
91
|
1 |
|
public function getSubtitle(): ?string |
92
|
|
|
{ |
93
|
1 |
|
return $this->subtitle; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param null|string $subtitle |
98
|
|
|
*/ |
99
|
1 |
|
public function setSubtitle(?string $subtitle): void |
100
|
|
|
{ |
101
|
1 |
|
$this->subtitle = $subtitle; |
102
|
1 |
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return string |
106
|
|
|
*/ |
107
|
1 |
|
public function getContent(): string |
108
|
|
|
{ |
109
|
1 |
|
return $this->content; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @param string $content |
114
|
|
|
*/ |
115
|
1 |
|
public function setContent(string $content): void |
116
|
|
|
{ |
117
|
1 |
|
$this->content = $content; |
118
|
1 |
|
} |
119
|
|
|
} |
120
|
|
|
|