ACPOverviewController::appearanceAction()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
/*
4
 * (c) Jim Martens <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace TwoMartens\Bundle\CoreBundle\Controller;
11
12
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
13
use Symfony\Component\HttpFoundation\Response;
14
use TwoMartens\Bundle\CoreBundle\Event\OverviewEvent;
15
use TwoMartens\Bundle\CoreBundle\Model\Breadcrumb;
16
17
/**
18
 * Manages the routes for the overview pages.
19
 *
20
 * @author    Jim Martens <[email protected]>
21
 * @copyright 2013-2015 Jim Martens
22
 */
23
class ACPOverviewController extends AbstractACPController
24
{
25
    /**
26
     * the current page
27
     * @var string
28
     */
29
    private $page;
30
31
    /**
32
     * Initializes the controller.
33
     */
34
    public function __construct()
35
    {
36
        parent::__construct();
37
        $this->page = '';
38
    }
39
40
    /**
41
     * Shows the system overview page.
42
     *
43
     * @return Response
44
     */
45
    public function systemAction()
46
    {
47
        $this->page = 'system';
48
        return $this->overviewAction();
49
    }
50
51
    /**
52
     * Shows the user overview page.
53
     *
54
     * @return Response
55
     */
56
    public function userAction()
57
    {
58
        $this->page = 'user';
59
        return $this->overviewAction();
60
    }
61
62
    /**
63
     * Shows the appearance overview page.
64
     *
65
     * @return Response
66
     */
67
    public function appearanceAction()
68
    {
69
        $this->page = 'appearance';
70
        return $this->overviewAction();
71
    }
72
73
    /**
74
     * Shows the content overview page.
75
     *
76
     * @return Response
77
     */
78
    public function contentAction()
79
    {
80
        $this->page = 'content';
81
        return $this->overviewAction();
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87
    protected function setBreadcrumbs()
88
    {
89
        $activeBreadcrumb = new Breadcrumb(
90
            'acp.'.$this->page,
91
            $this->get('translator')->trans(
92
                'acp.breadcrumb.'.$this->page,
93
                [],
94
                'TwoMartensCoreBundle'
95
            )
96
        );
97
        $activeBreadcrumb->activate();
98
        $this->breadcrumbs = [
99
            $activeBreadcrumb
100
        ];
101
    }
102
103
    /**
104
     * {@inheritdoc}
105
     */
106
    protected function assignVariables()
107
    {
108
        $this->templateVariables = [
109
            'area' => [
110
                'showBreadcrumbs' => true,
111
                'title' => $this->get('translator')->trans('acp.'.$this->page, [], 'TwoMartensCoreBundle')
112
            ],
113
            'siteTitle' => $this->get('translator')->trans(
114
                'acp.siteTitle',
115
                ['globalTitle' => 'CoreBundle Test'],
116
                'TwoMartensCoreBundle'
117
            ),
118
            'navigation' => [
119
                'active' => $this->page
120
            ]
121
        ];
122
        parent::assignVariables();
123
    }
124
125
    /**
126
     * Includes all the main action.
127
     *
128
     * @return Response
129
     */
130
    private function overviewAction()
131
    {
132
        /** @var EventDispatcherInterface $eventDispatcher */
133
        $eventDispatcher = $this->get('event_dispatcher');
134
        $event = new OverviewEvent();
135
        $eventDispatcher->dispatch(
136
            'twomartens.core.'. $this->page . '_overview',
137
            $event
138
        );
139
        $categories = $event->getCategories();
140
        $entries = $event->getEntries();
141
142
        $this->assignVariables();
143
        $this->templateVariables['categories'] = $categories;
144
        $this->templateVariables['entries'] = $entries;
145
146
        return $this->render(
147
            'TwoMartensCoreBundle:ACPOverview:index.html.twig',
148
            $this->templateVariables
149
        );
150
    }
151
}
152