Completed
Push — 3.x ( db377c...cd74a2 )
by Andrey F.
12:41
created

DashboardAction::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

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