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