zend-blog-3-backend

Форк
0
247 строк · 4.2 Кб
1
<?php
2

3
namespace App\Entity;
4

5
use App\Entity\Embedded\NestedSet;
6
use Doctrine\Common\Collections\ArrayCollection;
7
use Doctrine\Common\Collections\Collection;
8
use Doctrine\ORM\Mapping as ORM;
9
use 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
 */
19
class Category
20
{
21
    /**
22
     * @var int
23
     *
24
     * @ORM\Id
25
     * @ORM\Column(type="integer")
26
     * @ORM\GeneratedValue(strategy="AUTO")
27
     */
28
    protected $id;
29

30
    /**
31
     * @var Collection
32
     *
33
     * @ORM\OneToMany(targetEntity="Category", mappedBy="parent")
34
     **/
35
    protected $children;
36

37
    /**
38
     * @ORM\ManyToOne(targetEntity="Category", inversedBy="children")
39
     * @ORM\JoinColumn(onDelete="SET NULL")
40
     **/
41
    protected $parent;
42

43
    /**
44
     * @var string
45
     *
46
     * @ORM\Column(type="string", length=100)
47
     */
48
    protected $name;
49

50
    /**
51
     * @var string
52
     *
53
     * @ORM\Column(type="string", length=255, unique=true)
54
     */
55
    protected $url;
56

57
    /**
58
     * @var Collection
59
     *
60
     * @ORM\OneToMany(targetEntity="Post", mappedBy="category")
61
     */
62
    protected $posts;
63

64
    /**
65
     * @var NestedSet
66
     *
67
     * @ORM\Embedded(class="App\Entity\Embedded\NestedSet", columnPrefix = "tree_")
68
     */
69
    private $nestedSet;
70

71
    public 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
     */
83
    public function getId()
84
    {
85
        return $this->id;
86
    }
87

88
    /**
89
     * Set name
90
     *
91
     * @param string $name
92
     *
93
     * @return Category
94
     */
95
    public function setName($name)
96
    {
97
        $this->name = $name;
98

99
        return $this;
100
    }
101

102
    /**
103
     * Get name
104
     *
105
     * @return string
106
     */
107
    public function getName()
108
    {
109
        return $this->name;
110
    }
111

112
    /**
113
     * Set url
114
     *
115
     * @param string $url
116
     *
117
     * @return Category
118
     */
119
    public function setUrl($url)
120
    {
121
        $this->url = $url;
122

123
        return $this;
124
    }
125

126
    /**
127
     * Get url
128
     *
129
     * @return string
130
     */
131
    public function getUrl()
132
    {
133
        return $this->url;
134
    }
135

136
    /**
137
     * Add children
138
     *
139
     * @param Category $children
140
     *
141
     * @return Category
142
     */
143
    public function addChild(self $children)
144
    {
145
        $this->children[] = $children;
146

147
        return $this;
148
    }
149

150
    /**
151
     * Remove children
152
     *
153
     * @param Category $children
154
     */
155
    public function removeChild(self $children)
156
    {
157
        $this->children->removeElement($children);
158
    }
159

160
    /**
161
     * Get children
162
     *
163
     * @return Collection
164
     */
165
    public function getChildren()
166
    {
167
        return $this->children;
168
    }
169

170
    /**
171
     * Set parent
172
     *
173
     * @param Category|null $parent
174
     *
175
     * @return Category
176
     */
177
    public function setParent(self $parent = null)
178
    {
179
        $this->parent = $parent;
180

181
        return $this;
182
    }
183

184
    /**
185
     * Get parent
186
     *
187
     * @return Category
188
     */
189
    public function getParent()
190
    {
191
        return $this->parent;
192
    }
193

194
    /**
195
     * Add posts
196
     *
197
     * @param Post $posts
198
     *
199
     * @return Category
200
     */
201
    public function addPost(Post $posts)
202
    {
203
        $this->posts[] = $posts;
204

205
        return $this;
206
    }
207

208
    /**
209
     * Remove posts
210
     *
211
     * @param Post $posts
212
     */
213
    public function removePost(Post $posts)
214
    {
215
        $this->posts->removeElement($posts);
216
    }
217

218
    /**
219
     * Get posts
220
     *
221
     * @return Collection
222
     */
223
    public function getPosts()
224
    {
225
        return $this->posts;
226
    }
227

228
    /**
229
     * @return NestedSet
230
     */
231
    public function getNestedSet(): NestedSet
232
    {
233
        return $this->nestedSet;
234
    }
235

236
    /**
237
     * @param NestedSet $nestedSet
238
     *
239
     * @return $this
240
     */
241
    public function setNestedSet(NestedSet $nestedSet): self
242
    {
243
        $this->nestedSet = $nestedSet;
244

245
        return $this;
246
    }
247
}
248

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.