1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Victoire\Bundle\BlogBundle\Entity; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
use Doctrine\ORM\Mapping as ORM; |
7
|
|
|
use Victoire\Bundle\PageBundle\Entity\Page; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* PostPage. |
11
|
|
|
* |
12
|
|
|
* @ORM\Entity(repositoryClass="Victoire\Bundle\BlogBundle\Repository\BlogRepository")) |
13
|
|
|
* @ORM\Table("vic_blog") |
14
|
|
|
*/ |
15
|
|
|
class Blog extends Page |
16
|
|
|
{ |
17
|
|
|
const TYPE = 'blog'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var ArrayCollection |
21
|
|
|
* @ORM\OneToMany(targetEntity="Category", mappedBy="blog", cascade={"persist", "remove"}, orphanRemoval=true) |
22
|
|
|
*/ |
23
|
|
|
protected $categories; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var ArrayCollection |
27
|
|
|
* @ORM\OneToMany(targetEntity="\Victoire\Bundle\BlogBundle\Entity\Article", mappedBy="blog") |
28
|
|
|
*/ |
29
|
|
|
protected $articles; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var ArrayCollection |
33
|
|
|
* @ORM\OneToMany(targetEntity="\Victoire\Bundle\BlogBundle\Entity\Tag", mappedBy="blog") |
34
|
|
|
*/ |
35
|
|
|
protected $tags; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Constructor. |
39
|
|
|
*/ |
40
|
|
|
public function __construct() |
41
|
|
|
{ |
42
|
|
|
$this->categories = new ArrayCollection(); |
43
|
|
|
$this->articles = new ArrayCollection(); |
44
|
|
|
$this->tags = new ArrayCollection(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return ArrayCollection |
49
|
|
|
*/ |
50
|
|
|
public function getArticles() |
51
|
|
|
{ |
52
|
|
|
return $this->articles; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
|
|
|
|
56
|
|
|
* @param $articles |
|
|
|
|
57
|
|
|
* |
58
|
|
|
* @return $this |
59
|
|
|
*/ |
60
|
|
|
public function setArticles($articles) |
61
|
|
|
{ |
62
|
|
|
$this->articles = $articles; |
63
|
|
|
|
64
|
|
|
return $this; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param Article $article |
69
|
|
|
* |
70
|
|
|
* @return $this |
71
|
|
|
*/ |
72
|
|
|
public function addArticle(Article $article) |
73
|
|
|
{ |
74
|
|
|
$article->setBlog($this); |
75
|
|
|
$this->articles->add($article); |
76
|
|
|
|
77
|
|
|
return $this; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Set categories. |
82
|
|
|
* |
83
|
|
|
* @param array $categories |
84
|
|
|
* |
85
|
|
|
* @return Blog |
86
|
|
|
*/ |
87
|
|
|
public function setCategories($categories) |
88
|
|
|
{ |
89
|
|
|
foreach ($categories as $category) { |
90
|
|
|
$category->setBlog($this); |
91
|
|
|
} |
92
|
|
|
$this->categories = $categories; |
|
|
|
|
93
|
|
|
|
94
|
|
|
return $this; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param Category $category |
99
|
|
|
* |
100
|
|
|
* @return $this |
101
|
|
|
*/ |
102
|
|
|
public function addCategorie(Category $category) |
103
|
|
|
{ |
104
|
|
|
$category->setBlog($this); |
105
|
|
|
$this->categories->add($category); |
106
|
|
|
|
107
|
|
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Remove category. |
112
|
|
|
* |
113
|
|
|
* @param string $category |
114
|
|
|
* |
115
|
|
|
* @return Blog |
116
|
|
|
*/ |
117
|
|
|
public function removeCategorie($category) |
118
|
|
|
{ |
119
|
|
|
$this->categories->removeElement($category); |
120
|
|
|
|
121
|
|
|
return $this; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Get categories. |
126
|
|
|
* |
127
|
|
|
* @return string |
128
|
|
|
*/ |
129
|
|
|
public function getCategories() |
130
|
|
|
{ |
131
|
|
|
return $this->categories; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Get root categories. |
136
|
|
|
* |
137
|
|
|
* @return string |
138
|
|
|
*/ |
139
|
|
|
public function getRootCategories() |
140
|
|
|
{ |
141
|
|
|
$rootCategories = []; |
142
|
|
|
foreach ($this->categories as $categories) { |
143
|
|
|
if ($categories->getLvl() == 0) { |
144
|
|
|
$rootCategories[] = $categories; |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
return $rootCategories; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @param Category $rootCategory |
153
|
|
|
* |
154
|
|
|
* @return $this |
155
|
|
|
*/ |
156
|
|
|
public function addRootCategory(Category $rootCategory) |
157
|
|
|
{ |
158
|
|
|
$rootCategory->setBlog($this); |
159
|
|
|
$this->categories->add($rootCategory); |
160
|
|
|
|
161
|
|
|
return $this; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Remove rootCategory. |
166
|
|
|
* |
167
|
|
|
* @param string $rootCategory |
168
|
|
|
* |
169
|
|
|
* @return Blog |
170
|
|
|
*/ |
171
|
|
|
public function removeRootCategory($rootCategory) |
172
|
|
|
{ |
173
|
|
|
$this->categories->removeElement($rootCategory); |
174
|
|
|
|
175
|
|
|
return $this; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @return string |
180
|
|
|
*/ |
181
|
|
|
public function getTags() |
182
|
|
|
{ |
183
|
|
|
return $this->tags; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @param string $tags |
188
|
|
|
*/ |
189
|
|
|
public function setTags($tags) |
190
|
|
|
{ |
191
|
|
|
$this->tags = $tags; |
|
|
|
|
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @param Tag $tag |
196
|
|
|
* |
197
|
|
|
* @return Tag |
198
|
|
|
*/ |
199
|
|
|
public function addTag(Tag $tag) |
200
|
|
|
{ |
201
|
|
|
$tag->setBlog($this); |
202
|
|
|
$this->tags->add($tag); |
203
|
|
|
|
204
|
|
|
return $tag; |
205
|
|
|
} |
206
|
|
|
} |
207
|
|
|
|