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
|
|
|
|