<?php
namespace AdminBundle\Admin\DCAutoSite;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
use AdminBundle\Admin\BaseAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Route\RouteCollection;
use Sonata\AdminBundle\Route\RouteCollectionInterface;
use Sonata\AdminBundle\Show\ShowMapper;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
class ConfiguratorOfferAdmin extends BaseAdmin
{
protected $datagridValues = [
'_page' => 1,
'_sort_order' => 'DESC',
'_sort_by' => 'id',
];
/**
* @param RouteCollectionInterface $collection
*/
protected function configureRoutes(RouteCollectionInterface $collection): void
{
$collection->remove('edit');
$collection->remove('create');
$collection->remove('delete');
}
/**
* @param string $context
* @return ProxyQueryInterface
*/
public function configureQuery($context = 'list'): ProxyQueryInterface
{
$user = $this->security->getUser();
$query = parent::configureQuery($context);
$dealer = $user->getDealer();
if(!$dealer) {
throw new AccessDeniedException();
}
$query->andWhere(
$query->expr()->eq($query->getRootAliases()[0].'.dealer', ':dealer')
);
$query->setParameter('dealer', $dealer->getId());
return $query;
}
protected function configureShowFields(ShowMapper $show): void
{
$show
->add('date_create',null, ['label' => 'Дата создания'])
->add('name',null, ['label' => 'Имя'])
->add('email',null, ['label' => 'E-mail'])
->add('phone',null, ['label' => 'Телефон'])
->add('vehicle_item.equipment.vehicle.model',null, ['label' => 'Модель'])
->add('vehicle_item.equipment',null, ['label' => 'Комплектация'])
->add('vehicle_item',null, ['label' => 'Вариация'])
->add('color',null, ['label' => 'Цвет'])
->add('interier',null, ['label' => 'Цвет'])
->add('accessories', null, ['label' => 'Аскессуары'])
->add('options', null, ['label' => 'Опции'])
->add('total_price', null, ['label' => 'Цена автомобиля', 'template' => '@AdminBundle/CRUD/price_show.html.twig'])
->add('offer_price', null, ['label' => 'Цена предложения с учетом страховки', 'template' => '@AdminBundle/CRUD/price_show.html.twig'])
->add('insuranceArray', null, ['label' => 'Страховка', 'template' => '@AdminBundle/CRUD/c_insurance_show.html.twig'])
->add('creditArray', null, ['label' => 'Кредит', 'template' => '@AdminBundle/CRUD/c_credit_show.html.twig']);
}
/**
* @param ListMapper $listMapper
*/
protected function configureListFields(ListMapper $listMapper): void
{
$listMapper->addIdentifier('id')
->add('date_create',null, ['label' => 'Дата создания'])
->add('name',null, ['label' => 'Имя'])
->add('email',null, ['label' => 'E-mail'])
->add('vehicle_item.equipment.car.model',null, ['label' => 'Модель'])
->add('vehicle_item.equipment',null, ['label' => 'Комплектация'])
->add('vehicle_item',null, ['label' => 'Вариация'])
->add('offer_price',null, ['label' => 'Общая стоимость', 'template' => '@AdminBundle/CRUD/price.html.twig'])
->add('_action','actions',[
'label' => 'Действия',
'actions' => [
'view' => [],
]
])
;
}
}