1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AppBundle\Entity; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
use Doctrine\ORM\Mapping as ORM; |
7
|
|
|
use Gedmo\Mapping\Annotation as Gedmo; |
8
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Tag |
12
|
|
|
* |
13
|
|
|
* @ORM\Table(name="tag") |
14
|
|
|
* @ORM\Entity(repositoryClass="AppBundle\Repository\TagRepository") |
15
|
|
|
*/ |
16
|
|
|
class Tag |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var int |
20
|
|
|
* |
21
|
|
|
* @ORM\Column(name="id", type="integer") |
22
|
|
|
* @ORM\Id |
23
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
24
|
|
|
*/ |
25
|
|
|
private $id; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var string |
29
|
|
|
* |
30
|
|
|
* @ORM\Column(name="name", type="string", length=50, unique=true) |
31
|
|
|
* |
32
|
|
|
* @Assert\NotBlank() |
33
|
|
|
* @Assert\Length(max = 50) |
34
|
|
|
*/ |
35
|
|
|
private $name; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var string |
39
|
|
|
* |
40
|
|
|
* @Gedmo\Slug(fields={"name"}, updatable=true, separator="_") |
41
|
|
|
* @ORM\Column(name="slug", type="string", length=60, unique=true) |
42
|
|
|
* |
43
|
|
|
* @Assert\Length(max = 60) |
44
|
|
|
*/ |
45
|
|
|
private $slug; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @ORM\ManyToMany(targetEntity="Article", mappedBy="tags") |
49
|
|
|
*/ |
50
|
|
|
private $articles; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Get id |
54
|
|
|
* |
55
|
|
|
* @return int |
56
|
|
|
*/ |
57
|
|
|
public function getId() |
58
|
|
|
{ |
59
|
|
|
return $this->id; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Set name |
64
|
|
|
* |
65
|
|
|
* @param string $name |
66
|
|
|
* |
67
|
|
|
* @return Tag |
68
|
|
|
*/ |
69
|
|
|
public function setName($name) |
70
|
|
|
{ |
71
|
|
|
$this->name = $name; |
72
|
|
|
|
73
|
|
|
return $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Get name |
78
|
|
|
* |
79
|
|
|
* @return string |
80
|
|
|
*/ |
81
|
|
|
public function getNme() |
82
|
|
|
{ |
83
|
|
|
return $this->name; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Constructor |
88
|
|
|
*/ |
89
|
|
|
public function __construct() |
90
|
|
|
{ |
91
|
|
|
$this->articles = new ArrayCollection(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Add article |
96
|
|
|
* |
97
|
|
|
* @param \AppBundle\Entity\Article $article |
98
|
|
|
* |
99
|
|
|
* @return Tag |
100
|
|
|
*/ |
101
|
|
|
public function addArticle(Article $article) |
102
|
|
|
{ |
103
|
|
|
$this->articles[] = $article; |
104
|
|
|
|
105
|
|
|
return $this; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Remove article |
110
|
|
|
* |
111
|
|
|
* @param \AppBundle\Entity\Article $article |
112
|
|
|
*/ |
113
|
|
|
public function removeArticle(Article $article) |
114
|
|
|
{ |
115
|
|
|
$this->articles->removeElement($article); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Get articles |
120
|
|
|
* |
121
|
|
|
* @return \Doctrine\Common\Collections\Collection |
122
|
|
|
*/ |
123
|
|
|
public function getArticles() |
124
|
|
|
{ |
125
|
|
|
return $this->articles; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Get name |
130
|
|
|
* |
131
|
|
|
* @return string |
132
|
|
|
*/ |
133
|
|
|
public function getName() |
134
|
|
|
{ |
135
|
|
|
return $this->name; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Set slug |
140
|
|
|
* |
141
|
|
|
* @param string $slug |
142
|
|
|
* |
143
|
|
|
* @return Tag |
144
|
|
|
*/ |
145
|
|
|
public function setSlug($slug) |
146
|
|
|
{ |
147
|
|
|
$this->slug = $slug; |
148
|
|
|
|
149
|
|
|
return $this; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Get slug |
154
|
|
|
* |
155
|
|
|
* @return string |
156
|
|
|
*/ |
157
|
|
|
public function getSlug() |
158
|
|
|
{ |
159
|
|
|
return $this->slug; |
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
|