Completed
Push — master ( 1be64b...a322af )
by Vladimir
03:02
created

ContentItem::setCollection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
ccs 3
cts 3
cp 1
crap 1
1
<?php
2
3
namespace allejo\stakx\Object;
4
5
use allejo\stakx\Engines\MarkdownEngine;
6
use allejo\stakx\Engines\RstEngine;
7
8
class ContentItem extends FrontMatterObject
9
{
10
    /**
11
     * The collection this Content Item belongs to
12
     *
13
     * @var string
14
     */
15
    private $parentCollection;
16
17
    /**
18
     * The Page View that will be used to render this Content Item
19
     *
20
     * @var PageView
21
     */
22
    private $parentPageView;
23
24 1
    public function getCollection ()
25
    {
26 1
        return $this->parentCollection;
27
    }
28
29 3
    public function setCollection ($collection)
30
    {
31 3
        $this->parentCollection = $collection;
32 3
    }
33
34
    /**
35
     * Return the body of the Content Item parsed as markdown
36
     *
37
     * @return string
38
     */
39 3
    public function getContent ()
40
    {
41 3
        if (!$this->bodyContentEvaluated)
42 3
        {
43 3
            $twig = Website::getTwigInstance();
44
45 3
            if ($twig instanceof \Twig_Environment)
46 3
            {
47
                $template = $twig->createTemplate($this->bodyContent);
48
                $this->bodyContent = $template->render(array());
49
            }
50
51 3
            switch ($this->extension)
52
            {
53 3
                case "md":
54 3
                case "markdown":
55 1
                    $pd = new MarkdownEngine();
56 1
                    break;
57
58 2
                case "rst":
59 1
                    $pd = new RstEngine();
60 1
                    break;
61
62 1
                default:
63 1
                    $pd = null;
64 1
                    break;
65 3
            }
66
67 3
            if (!is_null($pd)) // No parser needed
68 3
            {
69 2
                $this->bodyContent = $pd->parse($this->bodyContent);
70 2
            }
71
72 3
            $this->bodyContentEvaluated = true;
73 3
        }
74
75 3
        return (string)$this->bodyContent;
76
    }
77
78
    /**
79
     * @return PageView
80
     */
81
    public function &getPageView ()
82
    {
83
        return $this->parentPageView;
84
    }
85
86
    /**
87
     * Set the parent Page View that this Content Item will have be assigned to
88
     *
89
     * @param PageView $pageView
90
     */
91
    public function setPageView (&$pageView)
92
    {
93
        $this->parentPageView = &$pageView;
94
    }
95
}