1 | <?php |
||
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) |
||
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) |
||
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) |
||
123 | |||
124 | /** |
||
125 | * Get categories. |
||
126 | * |
||
127 | * @return string |
||
128 | */ |
||
129 | public function getCategories() |
||
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) |
||
177 | |||
178 | /** |
||
179 | * @return string |
||
180 | */ |
||
181 | public function getTags() |
||
185 | |||
186 | /** |
||
187 | * @param string $tags |
||
188 | */ |
||
189 | public function setTags($tags) |
||
193 | |||
194 | /** |
||
195 | * @param Tag $tag |
||
196 | * |
||
197 | * @return Tag |
||
198 | */ |
||
199 | public function addTag(Tag $tag) |
||
206 | } |
||
207 |