Completed
Push — master ( 8d5df0...85472d )
by Tomáš
05:57
created

Page::getKeywords()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
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
10
/**
11
 * @Gedmo\Tree(type="nested")
12
 * @ORM\Table(name="Page")
13
 * @ORM\Entity(repositoryClass="Gedmo\Tree\Entity\Repository\NestedTreeRepository")
14
 * @ORM\HasLifecycleCallbacks
15
 * TODO: redirects, SEO features, inheritance from parents
16
 */
17
class Page extends BasicEntity
18
{
19
    /**
20
     * @ORM\Column(length=64)
21
     */
22
    private $title;
23
24
    /**
25
     * @ORM\Column(length=64, nullable=true)
26
     */
27
    private $h1;
28
29
    /**
30
     * @ORM\Column(length=64, nullable=true)
31
     */
32
    private $keywords;
33
34
    /**
35
     * @ORM\Column(length=64, nullable=true)
36
     */
37
    private $description;
38
39
    /**
40
     * @Gedmo\Slug(handlers={
41
     *      @Gedmo\SlugHandler(class="Gedmo\Sluggable\Handler\TreeSlugHandler", options={
42
     *          @Gedmo\SlugHandlerOption(name="parentRelationField", value="parent"),
43
     *          @Gedmo\SlugHandlerOption(name="separator", value="/"),
44
     *          @Gedmo\SlugHandlerOption(name="urilize", value=true)
45
     *      })
46
     * }, fields={"title"}, unique_base="language")
47
     * @Doctrine\ORM\Mapping\Column(length=128)
48
     */
49
    private $slug;
50
51
    /**
52
     * @Gedmo\TreeLeft
53
     * @ORM\Column(type="integer")
54
     */
55
    private $lft;
0 ignored issues
show
Unused Code introduced by
The property $lft is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
56
57
    /**
58
     * @Gedmo\TreeLevel
59
     * @ORM\Column(type="integer")
60
     */
61
    private $lvl;
62
63
    /**
64
     * @Gedmo\TreeRight
65
     * @ORM\Column(type="integer")
66
     */
67
    private $rgt;
0 ignored issues
show
Unused Code introduced by
The property $rgt is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
68
69
    /**
70
     * @Gedmo\TreeRoot
71
     * @ORM\ManyToOne(targetEntity="Page")
72
     * @ORM\JoinColumn(referencedColumnName="id", onDelete="CASCADE")
73
     */
74
    private $root;
75
76
    /**
77
     * @Gedmo\TreeParent
78
     * @ORM\ManyToOne(targetEntity="Page", inversedBy="children")
79
     * @ORM\JoinColumn(referencedColumnName="id", onDelete="CASCADE")
80
     */
81
    private $parent;
82
83
    /**
84
     * @ORM\OneToMany(targetEntity="Page", mappedBy="parent")
85
     * @ORM\OrderBy({"lft" = "ASC"})
86
     */
87
    private $children;
0 ignored issues
show
Unused Code introduced by
The property $children is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
88
89
    /**
90
     * @ORM\ManyToOne(targetEntity="Webcook\Cms\I18nBundle\Entity\Language")
91
     */
92
    private $language;
93
94
    /**
95
     * @ORM\Column(length=2)
96
     */
97
    private $languageAbbr;
98
99
    /**
100
     * @ORM\Column(length=64)
101
     */
102
    private $layout;
103
104
    /**
105
     * @ORM\OneToMany(targetEntity="PageSection", mappedBy="page", cascade={"persist"}, fetch="EAGER")
106
     */
107
    private $sections;
108
109 22
    public function __construct()
110
    {
111 22
        $this->sections = new ArrayCollection();
112 22
    }
113
114
    /** @ORM\PrePersist */
115 22
    public function setLanguageAbbr()
116
    {
117 22
        $this->languageAbbr = $this->language->getLocale();
118 22
    }
119
120 2
    public function getId()
121
    {
122 2
        return $this->id;
123
    }
124
125 22
    public function setTitle($title)
126
    {
127 22
        $this->title = $title;
128 22
    }
129
130 8
    public function getTitle()
131
    {
132 8
        return $this->title;
133
    }
134
135 2
    public function getRoot()
136
    {
137 2
        return $this->root;
138
    }
139
140 22
    public function setParent(Page $parent = null)
141
    {
142 22
        $this->parent = $parent;
143 22
    }
144
145 8
    public function getParent()
146
    {
147 8
        return $this->parent;
148
    }
149
150 22
    public function setLanguage($language)
151
    {
152 22
        $this->language = $language;
153
154 22
        return $this;
155
    }
156
157 7
    public function getLanguage()
158
    {
159 7
        return $this->language;
160
    }
161
162 22
    public function setLayout($layout)
163
    {
164 22
        $this->layout = $layout;
165
166 22
        return $this;
167
    }
168
169 7
    public function getLayout()
170
    {
171 7
        return $this->layout;
172
    }
173
174 6
    public function getSections($inherit = false)
175
    {
176 6
        if ($this->sections->isEmpty() && $this->parent && $inherit) {
177 2
            return $this->parent->getSections(true);
178
        }
179
180
        // FIXME, need to merge sections and lookup into parent for single items!
181 6
        if (!is_null($this->parent)) {
182
            $this->sections = new ArrayCollection(array_merge($this->sections->toArray(), $this->parent->getSections()->toArray()));
183
        }
184
185 6
        return $this->sections;
186
    }
187
188 2
    public function getSlug()
189
    {
190 2
        return $this->slug;
191
    }
192
193 2
    public function getRouteName()
194
    {
195 2
        return $this->getLanguage()->getLocale().'_'.str_replace('/', '_', $this->slug);
196
    }
197
198 2
    public function getPath()
199
    {
200 2
        $path = (!$this->getLanguage()->isDefault() ? $this->getLanguage()->getLocale() : '') . $this->getSlug();
201
202 2
        return str_replace($this->getRoot()->getSlug(), '', $path);
203
    }
204
205
    public function getLvl()
206
    {
207
        return $this->lvl;
208
    }
209
210
    /**
211
     * Gets the value of h1.
212
     *
213
     * @return mixed
214
     */
215 5
    public function getH1()
216
    {
217 5
        if (empty($this->h1)) {
218 4
            return $this->title;
219
        }
220
221 4
        return $this->h1;
222
    }
223
224
    /**
225
     * Sets the value of h1.
226
     *
227
     * @param mixed $h1 the h1
228
     *
229
     * @return self
230
     */
231 22
    public function setH1($h1)
232
    {
233 22
        $this->h1 = $h1;
234
235 22
        return $this;
236
    }
237
238
    /**
239
     * Gets the value of keywords.
240
     *
241
     * @return mixed
242
     */
243 5
    public function getKeywords()
244
    {
245 5
        return $this->keywords;
246
    }
247
248
    /**
249
     * Sets the value of keywords.
250
     *
251
     * @param mixed $keywords the keywords
252
     *
253
     * @return self
254
     */
255 22
    public function setKeywords($keywords)
256
    {
257 22
        $this->keywords = $keywords;
258
259 22
        return $this;
260
    }
261
262
    /**
263
     * Gets the value of description.
264
     *
265
     * @return mixed
266
     */
267 5
    public function getDescription()
268
    {
269 5
        return $this->description;
270
    }
271
272
    /**
273
     * Sets the value of description.
274
     *
275
     * @param mixed $description the description
276
     *
277
     * @return self
278
     */
279 22
    public function setDescription($description)
280
    {
281 22
        $this->description = $description;
282
283 22
        return $this;
284
    }
285
}
286