61 lines
1.7 KiB
PHP
61 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Trinity\Bundle\DashBoardBundle\DashBoard;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Routing\Router;
|
|
use Trinity\Bundle\SecurityBundle\AccessControl\RouteAccessControl;
|
|
use Trinity\Bundle\DashBoardBundle\DashBoard\DashBoard;
|
|
|
|
class ConfigurationTransformer
|
|
{
|
|
protected $router;
|
|
|
|
protected $config;
|
|
|
|
protected $user;
|
|
|
|
public function __construct(RouteAccessControl $rac, Router $router, array $config, $user)
|
|
{
|
|
$this->router = $router;
|
|
$this->config = $config;
|
|
$this->rac = $rac;
|
|
$this->user = $user;
|
|
}
|
|
|
|
public function getDash()
|
|
{
|
|
$dashboard = new DashBoard($this->config['title']);
|
|
|
|
foreach ($this->config['zones'] as $zone) {
|
|
$objZone = call_user_func_array(
|
|
array(
|
|
new \ReflectionClass($zone['model_class']),
|
|
'newInstance'
|
|
),
|
|
$zone['model_params']
|
|
);
|
|
|
|
$objZone->setUser($this->user);
|
|
|
|
foreach ($zone['items'] as $item) {
|
|
$objItem = call_user_func_array(
|
|
array(
|
|
new \ReflectionClass($item['model_class']),
|
|
'newInstance'
|
|
),
|
|
$item['model_params']
|
|
);
|
|
|
|
$method = $item['test_is_granted'] ? 'addItemIfGranted' : 'addChild';
|
|
$this->rac->setRoute(!empty($item['route_uri']) ? $item['route_uri'] : $this->router->generate($item['route_name'], $item['route_params']));
|
|
|
|
call_user_func(array($objZone, $method), $objItem, $this->rac);
|
|
}
|
|
|
|
$dashboard->addZone($objZone);
|
|
}
|
|
|
|
return $dashboard;
|
|
}
|
|
}
|