HomepagePresenter::beforeRender()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace FrontendModule;
4
5
/**
6
 * Admin presenter.
7
 * @author Tomáš Voslař <tomas.voslar at webcook.cz>
8
 * @package WebCMS2
9
 */
10
class HomepagePresenter extends \FrontendModule\BasePresenter
11
{
12
    protected function beforeRender()
13
    {
14
        parent::beforeRender();
15
    }
16
17
    protected function startup()
18
    {
19
        parent::startup();
20
21
        $page = $this->em->getRepository('WebCMS\Entity\Page')->findOneBy(array(
22
            'default' => 1,
23
            'language' => $this->language,
24
        ));
25
26
        if (is_object($page)) {
27
            $root = $this->settings->get('Root domain', \WebCMS\Settings::SECTION_BASIC);
28
            $abbr = $page->getLanguage()->getDefaultFrontend() ? '' : $page->getLanguage()->getAbbr().'/';
29
            $params = array('id' => $page->getId(), 'path' => $page->getPath(), 'abbr' => $abbr);
30
31
            // Hotfix UTM params and gclid for homepage redirect
32
            // TODO - refactor / move into appropriate place
33
            if ($this->getParam('utm_source')) {
0 ignored issues
show
Deprecated Code introduced by
The method Nette\Application\UI\Pre...erComponent::getParam() has been deprecated.

This method has been deprecated.

Loading history...
34
35
                $utm = array(
36
                    'utm_source' => $this->getParam('utm_source'),
0 ignored issues
show
Deprecated Code introduced by
The method Nette\Application\UI\Pre...erComponent::getParam() has been deprecated.

This method has been deprecated.

Loading history...
37
                    'utm_medium' => $this->getParam('utm_medium'),
0 ignored issues
show
Deprecated Code introduced by
The method Nette\Application\UI\Pre...erComponent::getParam() has been deprecated.

This method has been deprecated.

Loading history...
38
                    'utm_term' => $this->getParam('utm_term'),
0 ignored issues
show
Deprecated Code introduced by
The method Nette\Application\UI\Pre...erComponent::getParam() has been deprecated.

This method has been deprecated.

Loading history...
39
                    'utm_content' => $this->getParam('utm_content'),
0 ignored issues
show
Deprecated Code introduced by
The method Nette\Application\UI\Pre...erComponent::getParam() has been deprecated.

This method has been deprecated.

Loading history...
40
                    'utm_campaign' => $this->getParam('utm_campaign')
0 ignored issues
show
Deprecated Code introduced by
The method Nette\Application\UI\Pre...erComponent::getParam() has been deprecated.

This method has been deprecated.

Loading history...
41
                );
42
43
                $params = array_merge($params, array_filter($utm));
44
            }
45
46
            if ($this->getParam('gclid')) {
0 ignored issues
show
Deprecated Code introduced by
The method Nette\Application\UI\Pre...erComponent::getParam() has been deprecated.

This method has been deprecated.

Loading history...
47
                $params = array_merge($params, array('gclid' => $this->getParam('gclid')));
0 ignored issues
show
Deprecated Code introduced by
The method Nette\Application\UI\Pre...erComponent::getParam() has been deprecated.

This method has been deprecated.

Loading history...
48
            }
49
50
            if ($root->getValue()) {
51
                $this->forward(':Frontend:'.$page->getModuleName().':'.$page->getPresenter().':default', $params);
52
            } else {
53
                $this->redirect(':Frontend:'.$page->getModuleName().':'.$page->getPresenter().':default', $params);
54
            }
55
        }
56
57
        $this->forward(':Admin:Login:');
58
    }
59
}
60