src/AdminBundle/Admin/DCAutoSite/ResumeAdmin.php line 13

Open in your IDE?
  1. <?php
  2. namespace AdminBundle\Admin\DCAutoSite;
  3. use Sonata\AdminBundle\Admin\AbstractAdmin;
  4. use Sonata\AdminBundle\Datagrid\ListMapper;
  5. use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
  6. use Sonata\AdminBundle\Route\RouteCollection;
  7. use Sonata\AdminBundle\Route\RouteCollectionInterface;
  8. use Symfony\Component\Security\Core\Exception\AccessDeniedException;
  9. use Symfony\Component\Security\Core\Security;
  10. class ResumeAdmin extends AbstractAdmin
  11. {
  12.     protected Security $security;
  13.     public function setContainerServices(Security $security): void
  14.     {
  15.         $this->security $security;
  16.     }
  17.     /**
  18.      * @param RouteCollectionInterface $collection
  19.      */
  20.     protected function configureRoutes(RouteCollectionInterface $collection): void
  21.     {
  22.         $collection->remove('view');
  23.         $collection->remove('create');
  24.         $collection->remove('edit');
  25.         $collection->add('download'$this->getBaseRouteName(). '/');
  26.     }
  27.     /**
  28.      * @param ListMapper $listMapper
  29.      */
  30.     protected function configureListFields(ListMapper $listMapper): void
  31.     {
  32.         $listMapper->addIdentifier('id')
  33.             ->add('dealer')
  34.             ->add('vacancy.title'null, [
  35.                 'label' => 'Название вакансии'
  36.             ])
  37.             ->add('name'null, [
  38.                 'label' => 'Имя'
  39.             ])
  40.             ->add('phone'null, [
  41.                 'label' => 'Телефон'
  42.             ])
  43.             ->add('email'null)
  44.             ->add('cv''url', [
  45.                 'route' => [
  46.                     'name' => 'dc.vacancy.resume.download',
  47.                     'identifier_parameter_name' => 'id',
  48.                 ],
  49.             ])
  50.         ;
  51.     }
  52.     public function configureQuery($context 'list'): ProxyQueryInterface
  53.     {
  54.         $User $this->security->getUser();
  55.         if(!$User->getDealer()) {
  56.             throw new AccessDeniedException('User without dealer');
  57.         }
  58.         $query parent::configureQuery($context);
  59.         $query->andWhere(
  60.             $query->expr()->eq($query->getRootAliases()[0] . '.dealer'':dealer')
  61.         );
  62.         $query->setParameter('dealer'$User->getDealer()->getId());
  63.         return $query;
  64.     }
  65. }