zend-blog-3-backend
247 строк · 4.2 Кб
1<?php
2
3namespace App\Entity;
4
5use App\Entity\Embedded\NestedSet;
6use Doctrine\Common\Collections\ArrayCollection;
7use Doctrine\Common\Collections\Collection;
8use Doctrine\ORM\Mapping as ORM;
9use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
10
11/**
12* @ORM\Table(name="category", indexes={
13* @ORM\Index(name="left_key_idx", columns={"tree_left_key"}),
14* @ORM\Index(name="right_key_idx", columns={"tree_right_key"})
15* })
16* @ORM\Entity(repositoryClass="App\Repository\CategoryRepository")
17* @UniqueEntity(fields={"url"})
18*/
19class Category
20{
21/**
22* @var int
23*
24* @ORM\Id
25* @ORM\Column(type="integer")
26* @ORM\GeneratedValue(strategy="AUTO")
27*/
28protected $id;
29
30/**
31* @var Collection
32*
33* @ORM\OneToMany(targetEntity="Category", mappedBy="parent")
34**/
35protected $children;
36
37/**
38* @ORM\ManyToOne(targetEntity="Category", inversedBy="children")
39* @ORM\JoinColumn(onDelete="SET NULL")
40**/
41protected $parent;
42
43/**
44* @var string
45*
46* @ORM\Column(type="string", length=100)
47*/
48protected $name;
49
50/**
51* @var string
52*
53* @ORM\Column(type="string", length=255, unique=true)
54*/
55protected $url;
56
57/**
58* @var Collection
59*
60* @ORM\OneToMany(targetEntity="Post", mappedBy="category")
61*/
62protected $posts;
63
64/**
65* @var NestedSet
66*
67* @ORM\Embedded(class="App\Entity\Embedded\NestedSet", columnPrefix = "tree_")
68*/
69private $nestedSet;
70
71public function __construct()
72{
73$this->children = new ArrayCollection();
74$this->posts = new ArrayCollection();
75$this->nestedSet = new NestedSet();
76}
77
78/**
79* Get id
80*
81* @return int
82*/
83public function getId()
84{
85return $this->id;
86}
87
88/**
89* Set name
90*
91* @param string $name
92*
93* @return Category
94*/
95public function setName($name)
96{
97$this->name = $name;
98
99return $this;
100}
101
102/**
103* Get name
104*
105* @return string
106*/
107public function getName()
108{
109return $this->name;
110}
111
112/**
113* Set url
114*
115* @param string $url
116*
117* @return Category
118*/
119public function setUrl($url)
120{
121$this->url = $url;
122
123return $this;
124}
125
126/**
127* Get url
128*
129* @return string
130*/
131public function getUrl()
132{
133return $this->url;
134}
135
136/**
137* Add children
138*
139* @param Category $children
140*
141* @return Category
142*/
143public function addChild(self $children)
144{
145$this->children[] = $children;
146
147return $this;
148}
149
150/**
151* Remove children
152*
153* @param Category $children
154*/
155public function removeChild(self $children)
156{
157$this->children->removeElement($children);
158}
159
160/**
161* Get children
162*
163* @return Collection
164*/
165public function getChildren()
166{
167return $this->children;
168}
169
170/**
171* Set parent
172*
173* @param Category|null $parent
174*
175* @return Category
176*/
177public function setParent(self $parent = null)
178{
179$this->parent = $parent;
180
181return $this;
182}
183
184/**
185* Get parent
186*
187* @return Category
188*/
189public function getParent()
190{
191return $this->parent;
192}
193
194/**
195* Add posts
196*
197* @param Post $posts
198*
199* @return Category
200*/
201public function addPost(Post $posts)
202{
203$this->posts[] = $posts;
204
205return $this;
206}
207
208/**
209* Remove posts
210*
211* @param Post $posts
212*/
213public function removePost(Post $posts)
214{
215$this->posts->removeElement($posts);
216}
217
218/**
219* Get posts
220*
221* @return Collection
222*/
223public function getPosts()
224{
225return $this->posts;
226}
227
228/**
229* @return NestedSet
230*/
231public function getNestedSet(): NestedSet
232{
233return $this->nestedSet;
234}
235
236/**
237* @param NestedSet $nestedSet
238*
239* @return $this
240*/
241public function setNestedSet(NestedSet $nestedSet): self
242{
243$this->nestedSet = $nestedSet;
244
245return $this;
246}
247}
248