Completed
Push — master ( 285bc9...932fc1 )
by Marko
14s
created

DashboardAction   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 63
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
B __invoke() 0 28 4
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\AdminBundle\Action;
15
16
use Sonata\AdminBundle\Admin\BreadcrumbsBuilderInterface;
17
use Sonata\AdminBundle\Admin\Pool;
18
use Sonata\AdminBundle\Templating\TemplateRegistryInterface;
19
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
20
use Symfony\Component\HttpFoundation\Request;
21
22
final class DashboardAction extends Controller
23
{
24
    /**
25
     * @var array
26
     */
27
    private $dashboardBlocks;
28
29
    /**
30
     * @var BreadcrumbsBuilderInterface
31
     */
32
    private $breadcrumbsBuilder;
33
34
    /**
35
     * @var TemplateRegistryInterface
36
     */
37
    private $templateRegistry;
38
39
    /**
40
     * @var Pool
41
     */
42
    private $pool;
43
44
    public function __construct(
45
        array $dashboardBlocks,
46
        BreadcrumbsBuilderInterface $breadcrumbsBuilder,
47
        TemplateRegistryInterface $templateRegistry,
48
        Pool $pool
49
    ) {
50
        $this->dashboardBlocks = $dashboardBlocks;
51
        $this->breadcrumbsBuilder = $breadcrumbsBuilder;
52
        $this->templateRegistry = $templateRegistry;
53
        $this->pool = $pool;
54
    }
55
56
    public function __invoke(Request $request)
57
    {
58
        $blocks = [
59
            'top' => [],
60
            'left' => [],
61
            'center' => [],
62
            'right' => [],
63
            'bottom' => [],
64
        ];
65
66
        foreach ($this->dashboardBlocks as $block) {
67
            $blocks[$block['position']][] = $block;
68
        }
69
70
        $parameters = [
71
            'base_template' => $request->isXmlHttpRequest() ?
72
                $this->templateRegistry->getTemplate('ajax') :
73
                $this->templateRegistry->getTemplate('layout'),
74
            'admin_pool' => $this->pool,
75
            'blocks' => $blocks,
76
        ];
77
78
        if (!$request->isXmlHttpRequest()) {
79
            $parameters['breadcrumbs_builder'] = $this->breadcrumbsBuilder;
80
        }
81
82
        return $this->render($this->templateRegistry->getTemplate('dashboard'), $parameters);
83
    }
84
}
85