Completed
Push — master ( 24cba5...b295a0 )
by Vladimir
02:09
created

PageView::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
namespace allejo\stakx\Object;
4
5
class PageView extends FrontMatterObject
6
{
7
    /**
8
     * The Content Items that belong to this Page View. This array will only have elements if it is a dynamic Page View.
9
     *
10
     * @var ContentItem[]
11
     */
12
    private $contentItems;
13
14
    /**
15
     * @var PageView[]
16
     */
17
    private $children;
18
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function __construct($filePath)
23
    {
24
        parent::__construct($filePath);
25
26
        $this->children = array();
27
    }
28
29
    /**
30
     * @param ContentItem $contentItem
31
     */
32
    public function addContentItem (&$contentItem)
33
    {
34
        $filePath = $this->fs->getRelativePath($contentItem->getFilePath());
35
36
        $this->contentItems[$filePath] = &$contentItem;
37
        $contentItem->setPageView($this);
38
    }
39
40
    /**
41
     * Get child PageViews
42
     *
43
     * A child is defined as a static PageView whose URL has a parent. For example, a PageView with a URL of
44
     * `/gallery/france/` would have the PageView whose URL is `/gallery` as a parent.
45
     *
46
     * @return PageView[]
47
     */
48
    public function &getChildren ()
49
    {
50
        return $this->children;
51
    }
52
53
    /**
54
     * @return string Twig body
55
     */
56
    public function getContent ()
57
    {
58
        return $this->bodyContent;
59
    }
60
61
    /**
62
     * Get all of the Content Items
63
     *
64
     * @return ContentItem[]
65
     */
66
    public function getContentItems ()
67
    {
68
        return $this->contentItems;
69
    }
70
71
    /**
72
     * A page is considered "dynamic" if it is dynamically generated from data in a collection.
73
     *
74
     * @return bool
75
     */
76
    public function isDynamicPage ()
77
    {
78
        return isset($this->frontMatter['collection']);
79
    }
80
81
    /**
82
     * A fallback for the site menus that use the `url` field.
83
     *
84
     * @deprecated 0.1.0
85
     * @todo Remove this in the next major release
0 ignored issues
show
Coding Style introduced by
Comment refers to a TODO task

This check looks TODO comments that have been left in the code.

``TODO``s show that something is left unfinished and should be attended to.

Loading history...
86
     */
87
    public function getUrl ()
88
    {
89
        return $this->getPermalink();
90
    }
91
}