Completed
Pull Request — master (#20)
by Vladimir
02:43
created

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