1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Webcook\Cms\CoreBundle\Entity; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Mapping as ORM; |
6
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
7
|
|
|
use Gedmo\Mapping\Annotation as Gedmo; |
8
|
|
|
use Webcook\Cms\CoreBundle\Base\BasicEntity; |
9
|
|
|
use ApiPlatform\Core\Annotation\ApiResource; |
10
|
|
|
use ApiPlatform\Core\Annotation\ApiProperty; |
11
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
12
|
|
|
use Symfony\Component\Serializer\Annotation\MaxDepth; |
13
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @ApiResource( |
17
|
|
|
* itemOperations={ |
18
|
|
|
* "get"={"method"="GET"}, |
19
|
|
|
* "put"={"method"="PUT"}, |
20
|
|
|
* "delete"={"method"="DELETE"}, |
21
|
|
|
* "section_order"={"route_name"="page_section_order"} |
22
|
|
|
* }) |
23
|
|
|
* |
24
|
|
|
* @Gedmo\Tree(type="nested") |
25
|
|
|
* |
26
|
|
|
* @ORM\Table(name="Page") |
27
|
|
|
* @ORM\Entity(repositoryClass="Gedmo\Tree\Entity\Repository\NestedTreeRepository") |
28
|
|
|
* @ORM\HasLifecycleCallbacks |
29
|
|
|
* |
30
|
|
|
* TODO: redirects, inheritance from parents |
31
|
|
|
*/ |
32
|
|
|
class Page extends BasicEntity |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* @ORM\Column(length=64) |
36
|
|
|
* @Groups({"write"}) |
37
|
|
|
* @Assert\NotBlank |
38
|
|
|
*/ |
39
|
|
|
private $title; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @ORM\Column(length=64, nullable=true) |
43
|
|
|
* @Groups({"write"}) |
44
|
|
|
*/ |
45
|
|
|
private $h1; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @ORM\Column(length=64, nullable=true) |
49
|
|
|
* @Groups({"write"}) |
50
|
|
|
*/ |
51
|
|
|
private $keywords; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @ORM\Column(length=64, nullable=true) |
55
|
|
|
* @Groups({"write"}) |
56
|
|
|
*/ |
57
|
|
|
private $description; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @Gedmo\Slug(handlers={ |
61
|
|
|
* @Gedmo\SlugHandler(class="Gedmo\Sluggable\Handler\TreeSlugHandler", options={ |
62
|
|
|
* @Gedmo\SlugHandlerOption(name="parentRelationField", value="parent"), |
63
|
|
|
* @Gedmo\SlugHandlerOption(name="separator", value="/"), |
64
|
|
|
* @Gedmo\SlugHandlerOption(name="urilize", value=true) |
65
|
|
|
* }) |
66
|
|
|
* }, fields={"title"}, unique_base="language") |
67
|
|
|
* @Doctrine\ORM\Mapping\Column(length=128) |
68
|
|
|
*/ |
69
|
|
|
private $slug; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @Gedmo\TreeLeft |
73
|
|
|
* @ORM\Column(type="integer") |
74
|
|
|
*/ |
75
|
|
|
private $lft; |
|
|
|
|
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @Gedmo\TreeLevel |
79
|
|
|
* @ORM\Column(type="integer") |
80
|
|
|
*/ |
81
|
|
|
private $lvl; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @Gedmo\TreeRight |
85
|
|
|
* @ORM\Column(type="integer") |
86
|
|
|
*/ |
87
|
|
|
private $rgt; |
|
|
|
|
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @Gedmo\TreeRoot |
91
|
|
|
* @ORM\ManyToOne(targetEntity="Page") |
92
|
|
|
* @ORM\JoinColumn(referencedColumnName="id", onDelete="CASCADE") |
93
|
|
|
* @MaxDepth(2) |
94
|
|
|
*/ |
95
|
|
|
private $root; |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @Gedmo\TreeParent |
99
|
|
|
* @ORM\ManyToOne(targetEntity="Page", inversedBy="children") |
100
|
|
|
* @ORM\JoinColumn(referencedColumnName="id", onDelete="CASCADE") |
101
|
|
|
* @MaxDepth(2) |
102
|
|
|
*/ |
103
|
|
|
private $parent; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @ORM\OneToMany(targetEntity="Page", mappedBy="parent") |
107
|
|
|
* @ORM\OrderBy({"lft" = "ASC"}) |
108
|
|
|
* @MaxDepth(2) |
109
|
|
|
*/ |
110
|
|
|
private $children; |
|
|
|
|
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @ORM\ManyToOne(targetEntity="Webcook\Cms\I18nBundle\Entity\Language") |
114
|
|
|
* @Groups({"write"}) |
115
|
|
|
* @Assert\NotBlank |
116
|
|
|
*/ |
117
|
|
|
private $language; |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @ORM\Column(length=2) |
121
|
|
|
*/ |
122
|
|
|
private $languageAbbr; |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @ORM\Column(length=64) |
126
|
|
|
* @Groups({"write"}) |
127
|
|
|
* @Assert\NotBlank |
128
|
|
|
*/ |
129
|
|
|
private $layout; |
130
|
|
|
|
131
|
|
|
/** |
132
|
20 |
|
* @ORM\OneToMany(targetEntity="PageSection", mappedBy="page", cascade={"persist"}, fetch="EAGER") |
133
|
|
|
* @MaxDepth(5) |
134
|
20 |
|
* @ApiProperty(readable = false) |
135
|
20 |
|
*/ |
136
|
|
|
private $sections; |
137
|
|
|
|
138
|
20 |
|
public function __construct() |
139
|
|
|
{ |
140
|
20 |
|
$this->sections = new ArrayCollection(); |
141
|
20 |
|
} |
142
|
|
|
|
143
|
6 |
|
/** @ORM\PrePersist */ |
144
|
|
|
public function setLanguageAbbr() |
145
|
6 |
|
{ |
146
|
|
|
$this->languageAbbr = $this->language->getLocale(); |
147
|
|
|
} |
148
|
20 |
|
|
149
|
|
|
public function getId() |
150
|
20 |
|
{ |
151
|
20 |
|
return $this->id; |
152
|
|
|
} |
153
|
4 |
|
|
154
|
|
|
public function setTitle($title) |
155
|
4 |
|
{ |
156
|
|
|
$this->title = $title; |
157
|
|
|
} |
158
|
6 |
|
|
159
|
|
|
public function getTitle() |
160
|
6 |
|
{ |
161
|
|
|
return $this->title; |
162
|
|
|
} |
163
|
20 |
|
|
164
|
|
|
public function getRoot() |
165
|
20 |
|
{ |
166
|
20 |
|
return $this->root; |
167
|
|
|
} |
168
|
7 |
|
|
169
|
|
|
public function setParent(Page $parent = null) |
170
|
7 |
|
{ |
171
|
|
|
$this->parent = $parent; |
172
|
|
|
} |
173
|
20 |
|
|
174
|
|
|
public function getParent() |
175
|
20 |
|
{ |
176
|
|
|
return $this->parent; |
177
|
20 |
|
} |
178
|
|
|
|
179
|
|
|
public function setLanguage($language) |
180
|
6 |
|
{ |
181
|
|
|
$this->language = $language; |
182
|
6 |
|
|
183
|
|
|
return $this; |
184
|
|
|
} |
185
|
20 |
|
|
186
|
|
|
public function getLanguage() |
187
|
20 |
|
{ |
188
|
|
|
return $this->language; |
189
|
20 |
|
} |
190
|
|
|
|
191
|
|
|
public function setLayout($layout) |
192
|
6 |
|
{ |
193
|
|
|
$this->layout = $layout; |
194
|
6 |
|
|
195
|
|
|
return $this; |
196
|
|
|
} |
197
|
3 |
|
|
198
|
|
|
public function getLayout() |
199
|
3 |
|
{ |
200
|
2 |
|
return $this->layout; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
public function getSections($inherit = false) |
204
|
3 |
|
{ |
205
|
|
|
if ($this->sections->isEmpty() && $this->parent && $inherit) { |
206
|
|
|
return $this->parent->getSections(true); |
207
|
|
|
} |
208
|
3 |
|
|
209
|
|
|
// FIXME, need to merge sections and lookup into parent for single items! |
210
|
|
|
if (!is_null($this->parent)) { |
211
|
6 |
|
$this->sections = new ArrayCollection(array_merge($this->sections->toArray(), $this->parent->getSections()->toArray())); |
212
|
|
|
} |
213
|
6 |
|
|
214
|
|
|
return $this->sections; |
215
|
|
|
} |
216
|
6 |
|
|
217
|
|
|
public function getSlug() |
218
|
6 |
|
{ |
219
|
|
|
return $this->slug; |
220
|
|
|
} |
221
|
6 |
|
|
222
|
|
|
public function getRouteName() |
223
|
6 |
|
{ |
224
|
|
|
return $this->getLanguage()->getLocale().'_'.str_replace('/', '_', $this->slug); |
225
|
6 |
|
} |
226
|
|
|
|
227
|
|
|
public function getPath() |
228
|
4 |
|
{ |
229
|
|
|
$path = (!$this->getLanguage()->isDefault() ? $this->getLanguage()->getLocale() : '') . $this->getSlug(); |
230
|
4 |
|
|
231
|
|
|
return str_replace($this->getRoot()->getSlug(), '', $path); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
public function getLvl() |
235
|
|
|
{ |
236
|
|
|
return $this->lvl; |
237
|
|
|
} |
238
|
4 |
|
|
239
|
|
|
/** |
240
|
4 |
|
* Gets the value of h1. |
241
|
3 |
|
* |
242
|
|
|
* @return mixed |
243
|
|
|
*/ |
244
|
2 |
|
public function getH1() |
245
|
|
|
{ |
246
|
|
|
if (empty($this->h1)) { |
247
|
|
|
return $this->title; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
return $this->h1; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
20 |
|
* Sets the value of h1. |
255
|
|
|
* |
256
|
20 |
|
* @param mixed $h1 the h1 |
257
|
|
|
* |
258
|
20 |
|
* @return self |
259
|
|
|
*/ |
260
|
|
|
public function setH1($h1) |
261
|
|
|
{ |
262
|
|
|
$this->h1 = $h1; |
263
|
|
|
|
264
|
|
|
return $this; |
265
|
|
|
} |
266
|
4 |
|
|
267
|
|
|
/** |
268
|
4 |
|
* Gets the value of keywords. |
269
|
|
|
* |
270
|
|
|
* @return mixed |
271
|
|
|
*/ |
272
|
|
|
public function getKeywords() |
273
|
|
|
{ |
274
|
|
|
return $this->keywords; |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
20 |
|
* Sets the value of keywords. |
279
|
|
|
* |
280
|
20 |
|
* @param mixed $keywords the keywords |
281
|
|
|
* |
282
|
20 |
|
* @return self |
283
|
|
|
*/ |
284
|
|
|
public function setKeywords($keywords) |
285
|
|
|
{ |
286
|
|
|
$this->keywords = $keywords; |
287
|
|
|
|
288
|
|
|
return $this; |
289
|
|
|
} |
290
|
4 |
|
|
291
|
|
|
/** |
292
|
4 |
|
* Gets the value of description. |
293
|
|
|
* |
294
|
|
|
* @return mixed |
295
|
|
|
*/ |
296
|
|
|
public function getDescription() |
297
|
|
|
{ |
298
|
|
|
return $this->description; |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
/** |
302
|
20 |
|
* Sets the value of description. |
303
|
|
|
* |
304
|
20 |
|
* @param mixed $description the description |
305
|
|
|
* |
306
|
20 |
|
* @return self |
307
|
|
|
*/ |
308
|
|
|
public function setDescription($description) |
309
|
|
|
{ |
310
|
|
|
$this->description = $description; |
311
|
|
|
|
312
|
|
|
return $this; |
313
|
|
|
} |
314
|
|
|
} |
315
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.