<?php
namespace AdminBundle\Admin\Filters;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
use AdminBundle\Admin\BaseAdmin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Route\RouteCollection;
use Sonata\AdminBundle\Route\RouteCollectionInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
class VehicleAutoriaAdmin extends BaseAdmin
{
protected function configureRoutes(RouteCollectionInterface $collection): void
{
$collection->remove('create');
}
protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
{
$datagridMapper
->add('created_at', 'doctrine_orm_date_range', [
'label' => 'Дата створення',
'field_options_start' => [
'format' => 'yyyy-MM-dd',
'widget' => 'single_text',
'attr' => ['class' => 'datepicker_start']
],
'field_options_end' => [
'format' => 'yyyy-MM-dd',
'widget' => 'single_text',
'attr' => ['class' => 'datepicker_end']
]
]);
}
/**
* @param string $context
* @return ProxyQueryInterface
*/
public function configureQuery($context = 'list'): ProxyQueryInterface
{
$user = $this->getUser();
$query = parent::configureQuery($context);
$dealer = $user->getDealer();
if(!$dealer) {
throw new AccessDeniedException();
}
$query->where($query->getRootAliases()[0] . '.is_delete is NULL OR ' . $query->getRootAliases()[0] . '.is_delete = 0');
$query->andWhere($query->getRootAliases()[0] . '.state is NULL OR ' . $query->getRootAliases()[0] . '.state = 0 OR ' . $query->getRootAliases()[0] . '.is_auto_send = 1');
$query->leftJoin($query->getRootAliases()[0] . '.vehicle_filter', 'vf');
$query->andWhere('vf.dealer = :dealer');
$query->setParameter('dealer', $dealer->getId());
return $query;
}
protected function configureListFields(ListMapper $listMapper): void
{
$listMapper->addIdentifier('id')
->add('autoria_id',null, ['label' => 'AUTORIA ID'])
->add('crm_id',null, ['label' => 'CRM ID'])
->add('state', null, ['label' => 'STATE'])
->add('_action', 'actions', [
'label' => 'Дія',
'actions' => [
'edit' => [],
]
])
;
}
protected function configure(): void
{
parent::configure(); // TODO: Change the autogenerated stub
$this->setTemplate('list', '@Admin\CRUD\VehicleFilter\autoria-list.html.twig');
}
}