<?php
namespace AdminBundle\Admin\DCAutoSite;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
use AdminBundle\Admin\BaseAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Route\RouteCollectionInterface;
use Symfony\Component\Finder\Exception\AccessDeniedException;
class InfoSyncAdmin extends BaseAdmin
{
/**
* @param RouteCollectionInterface $collection
*/
protected function configureRoutes(RouteCollectionInterface $collection): void
{
$collection->remove('view');
$collection->remove('delete');
$collection->remove('create');
$collection->add('sync');
}
/**
* @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->getRootAliases()[0].'.dealer = :dealer');
$query->setParameter('dealer', $dealer->getId());
return $query;
}
/**
* @param ListMapper $listMapper
*/
protected function configureListFields(ListMapper $listMapper): void
{
$listMapper->addIdentifier('id')
->add('dealer.name_ru',null, ['label' => 'Дилер'])
->add('_action', 'actions', [
'label' => 'Действия',
'actions' => [
'configurator' => [
'template' => '@AdminBundle/CRUD/list__action_sync.html.twig'
],
]
])
;
}
protected function configure(): void
{
parent::configure(); // TODO: Change the autogenerated stub
$this->setTemplate('edit', '@Admin/admin/CRUD/sync-price.html.twig');
}
}