src/AdminBundle/Admin/DCAutoSite/InfoSyncAdmin.php line 12

Open in your IDE?
  1. <?php
  2. namespace AdminBundle\Admin\DCAutoSite;
  3. use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
  4. use AdminBundle\Admin\BaseAdmin;
  5. use Sonata\AdminBundle\Datagrid\ListMapper;
  6. use Sonata\AdminBundle\Route\RouteCollectionInterface;
  7. use Symfony\Component\Finder\Exception\AccessDeniedException;
  8. class InfoSyncAdmin extends BaseAdmin
  9. {
  10.     /**
  11.      * @param RouteCollectionInterface $collection
  12.      */
  13.     protected function configureRoutes(RouteCollectionInterface $collection): void
  14.     {
  15.         $collection->remove('view');
  16.         $collection->remove('delete');
  17.         $collection->remove('create');
  18.         $collection->add('sync');
  19.     }
  20.     /**
  21.      * @param string $context
  22.      * @return ProxyQueryInterface
  23.      */
  24.     public function configureQuery($context 'list'): ProxyQueryInterface
  25.     {
  26.         $user $this->security->getUser();
  27.         $query parent::configureQuery($context);
  28.         $dealer $user->getDealer();
  29.         if(!$dealer) {
  30.             throw new AccessDeniedException();
  31.         }
  32.         $query->andWhere($query->getRootAliases()[0].'.dealer = :dealer');
  33.         $query->setParameter('dealer'$dealer->getId());
  34.         return $query;
  35.     }
  36.     /**
  37.      * @param ListMapper $listMapper
  38.      */
  39.     protected function configureListFields(ListMapper $listMapper): void
  40.     {
  41.         $listMapper->addIdentifier('id')
  42.             ->add('dealer.name_ru',null, ['label' => 'Дилер'])
  43.             ->add('_action''actions', [
  44.                 'label' => 'Действия',
  45.                 'actions' => [
  46.                     'configurator' => [
  47.                         'template' => '@AdminBundle/CRUD/list__action_sync.html.twig'
  48.                     ],
  49.                 ]
  50.             ])
  51.         ;
  52.     }
  53.     protected function configure(): void
  54.     {
  55.         parent::configure(); // TODO: Change the autogenerated stub
  56.         $this->setTemplate('edit''@Admin/admin/CRUD/sync-price.html.twig');
  57.     }
  58. }