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
|
|
|
* Get available locales for Articles from this Blog. |
49
|
|
|
* |
50
|
|
|
* @return array |
51
|
|
|
*/ |
52
|
|
|
public function getAvailableLocales() |
53
|
|
|
{ |
54
|
|
|
$availableLocales = []; |
55
|
|
|
$translations = $this->getTranslations(); |
56
|
|
|
foreach ($translations as $translation) { |
57
|
|
|
$availableLocales[] = $translation->getLocale(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return $availableLocales; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return ArrayCollection |
65
|
|
|
*/ |
66
|
|
|
public function getArticles() |
67
|
|
|
{ |
68
|
|
|
return $this->articles; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
|
|
|
|
72
|
|
|
* @param $articles |
|
|
|
|
73
|
|
|
* |
74
|
|
|
* @return $this |
75
|
|
|
*/ |
76
|
|
|
public function setArticles($articles) |
77
|
|
|
{ |
78
|
|
|
$this->articles = $articles; |
79
|
|
|
|
80
|
|
|
return $this; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param Article $article |
85
|
|
|
* |
86
|
|
|
* @return $this |
87
|
|
|
*/ |
88
|
|
|
public function addArticle(Article $article) |
89
|
|
|
{ |
90
|
|
|
$article->setBlog($this); |
91
|
|
|
$this->articles->add($article); |
92
|
|
|
|
93
|
|
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Set categories. |
98
|
|
|
* |
99
|
|
|
* @param array $categories |
100
|
|
|
* |
101
|
|
|
* @return Blog |
102
|
|
|
*/ |
103
|
|
|
public function setCategories($categories) |
104
|
|
|
{ |
105
|
|
|
foreach ($categories as $category) { |
106
|
|
|
$category->setBlog($this); |
107
|
|
|
} |
108
|
|
|
$this->categories = $categories; |
|
|
|
|
109
|
|
|
|
110
|
|
|
return $this; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param Category $category |
115
|
|
|
* |
116
|
|
|
* @return $this |
117
|
|
|
*/ |
118
|
|
|
public function addCategorie(Category $category) |
119
|
|
|
{ |
120
|
|
|
$category->setBlog($this); |
121
|
|
|
$this->categories->add($category); |
122
|
|
|
|
123
|
|
|
return $this; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Remove category. |
128
|
|
|
* |
129
|
|
|
* @param string $category |
130
|
|
|
* |
131
|
|
|
* @return Blog |
132
|
|
|
*/ |
133
|
|
|
public function removeCategorie($category) |
134
|
|
|
{ |
135
|
|
|
$this->categories->removeElement($category); |
136
|
|
|
|
137
|
|
|
return $this; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Get categories. |
142
|
|
|
* |
143
|
|
|
* @return string |
144
|
|
|
*/ |
145
|
|
|
public function getCategories() |
146
|
|
|
{ |
147
|
|
|
return $this->categories; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Get root categories. |
152
|
|
|
* |
153
|
|
|
* @return string |
154
|
|
|
*/ |
155
|
|
|
public function getRootCategories() |
156
|
|
|
{ |
157
|
|
|
$rootCategories = []; |
158
|
|
|
foreach ($this->categories as $categories) { |
159
|
|
|
if ($categories->getLvl() == 0) { |
160
|
|
|
$rootCategories[] = $categories; |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
return $rootCategories; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @param Category $rootCategory |
169
|
|
|
* |
170
|
|
|
* @return $this |
171
|
|
|
*/ |
172
|
|
|
public function addRootCategory(Category $rootCategory) |
173
|
|
|
{ |
174
|
|
|
$rootCategory->setBlog($this); |
175
|
|
|
$this->categories->add($rootCategory); |
176
|
|
|
|
177
|
|
|
return $this; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Remove rootCategory. |
182
|
|
|
* |
183
|
|
|
* @param string $rootCategory |
184
|
|
|
* |
185
|
|
|
* @return Blog |
186
|
|
|
*/ |
187
|
|
|
public function removeRootCategory($rootCategory) |
188
|
|
|
{ |
189
|
|
|
$this->categories->removeElement($rootCategory); |
190
|
|
|
|
191
|
|
|
return $this; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @return string |
196
|
|
|
*/ |
197
|
|
|
public function getTags() |
198
|
|
|
{ |
199
|
|
|
return $this->tags; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @param string $tags |
204
|
|
|
*/ |
205
|
|
|
public function setTags($tags) |
206
|
|
|
{ |
207
|
|
|
$this->tags = $tags; |
|
|
|
|
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @param Tag $tag |
212
|
|
|
* |
213
|
|
|
* @return Tag |
214
|
|
|
*/ |
215
|
|
|
public function addTag(Tag $tag) |
216
|
|
|
{ |
217
|
|
|
$tag->setBlog($this); |
218
|
|
|
$this->tags->add($tag); |
219
|
|
|
|
220
|
|
|
return $tag; |
221
|
|
|
} |
222
|
|
|
} |
223
|
|
|
|