1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace FSi\FixturesBundle\Entity; |
6
|
|
|
|
7
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
8
|
|
|
use Doctrine\Common\Collections\Collection; |
9
|
|
|
use Doctrine\ORM\Mapping as ORM; |
10
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @ORM\Entity |
14
|
|
|
* @ORM\Table(name="tag") |
15
|
|
|
*/ |
16
|
|
|
class Tag |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var int |
20
|
|
|
* |
21
|
|
|
* @ORM\Column(type="integer") |
22
|
|
|
* @ORM\Id |
23
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
24
|
|
|
*/ |
25
|
|
|
protected $id; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var string |
29
|
|
|
* |
30
|
|
|
* @Assert\NotBlank |
31
|
|
|
* @ORM\Column(type="string", length=255) |
32
|
|
|
*/ |
33
|
|
|
protected $name; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var News |
37
|
|
|
* |
38
|
|
|
* @ORM\ManyToOne(targetEntity="News", inversedBy="tags") |
39
|
|
|
*/ |
40
|
|
|
protected $news; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var ArrayCollection|TagElement[] |
44
|
|
|
* |
45
|
|
|
* @ORM\OneToMany(targetEntity="TagElement", mappedBy="tag", cascade={"persist"}, orphanRemoval=true) |
46
|
|
|
*/ |
47
|
|
|
protected $elements; |
48
|
|
|
|
49
|
|
|
public function __construct() |
50
|
|
|
{ |
51
|
|
|
$this->elements = new ArrayCollection(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getId(): ?int |
55
|
|
|
{ |
56
|
|
|
return $this->id; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function getName(): ?string |
60
|
|
|
{ |
61
|
|
|
return $this->name; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function setName(?string $name): void |
65
|
|
|
{ |
66
|
|
|
$this->name = $name; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function getNews(): ?News |
70
|
|
|
{ |
71
|
|
|
return $this->news; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function setNews(?News $news): void |
75
|
|
|
{ |
76
|
|
|
$this->news = $news; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return TagElement[]|Collection |
81
|
|
|
*/ |
82
|
|
|
public function getElements(): Collection |
83
|
|
|
{ |
84
|
|
|
return $this->elements; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function addElement(TagElement $element): void |
88
|
|
|
{ |
89
|
|
|
if (!$this->elements->contains($element)) { |
90
|
|
|
$element->setTag($this); |
91
|
|
|
$this->elements->add($element); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function removeElement(TagElement $element): void |
96
|
|
|
{ |
97
|
|
|
$element->setTag(null); |
98
|
|
|
$this->elements->removeElement($element); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|