PageListener   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 35
rs 10
c 1
b 0
f 0
ccs 0
cts 16
cp 0
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A postLoad() 0 15 4
A preRemove() 0 6 3
1
<?php
2
3
namespace PiedWeb\CMSBundle\EventListener;
4
5
use PiedWeb\CMSBundle\Entity\PageInterface as Page;
6
use PiedWeb\CMSBundle\Service\App;
7
use PiedWeb\CMSBundle\Service\PageMainContentManager\PageMainContentManager;
8
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
9
10
class PageListener
11
{
12
    protected $params;
13
    protected $mainContentManager;
14
15
    public function __construct(ParameterBagInterface $params, PageMainContentManager $mainContentManager)
16
    {
17
        $this->params = $params;
18
        //$this->app = new App(null, $this->params);
19
        $this->mainContentManager = $mainContentManager;
20
    }
21
22
    public function postLoad(Page $page)
23
    {
24
        // todo
25
        //$this->switchCurrentApp($page->getHost());
26
        //$page->setApp(clone $this->app);
27
28
        if (false === $this->params->get('pwc.main_content_twig') || null === $page->getOtherProperty('twig')) {
29
            $page->setTwig($this->params->get('pwc.main_content_twig'));
30
        }
31
32
        if (null === $page->getMainContentType()) {
33
            $page->setMainContentType($this->params->get('pwc.main_content_type_default'));
34
        }
35
36
        $page->setContent($this->mainContentManager->manage($page));
37
    }
38
39
    public function preRemove(Page $page)
40
    {
41
        // method_exists($page, 'getChildrenPages') &&
42
        if (! $page->getChildrenPages()->isEmpty()) {
43
            foreach ($page->getChildrenPages() as $cPage) {
44
                $cPage->setParentPage(null);
45
            }
46
        }
47
    }
48
}
49