src/AdminBundle/Admin/Vidi/ResumeAdmin.php line 12

Open in your IDE?
  1. <?php
  2. namespace AdminBundle\Admin\Vidi;
  3. use Sonata\AdminBundle\Admin\AbstractAdmin;
  4. use Sonata\AdminBundle\Datagrid\ListMapper;
  5. use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
  6. use Sonata\AdminBundle\Route\RouteCollectionInterface;
  7. use Symfony\Component\Security\Core\Exception\AccessDeniedException;
  8. use Symfony\Component\Security\Core\Security;
  9. class ResumeAdmin extends AbstractAdmin
  10. {
  11.     protected $baseRouteName 'vidi-resume';
  12.     protected $baseRoutePattern 'vidi-resume';
  13.     protected Security $security;
  14.     public function setContainerServices(Security $security): void
  15.     {
  16.         $this->security $security;
  17.     }
  18.     /**
  19.      * @param RouteCollectionInterface $collection
  20.      */
  21.     protected function configureRoutes(RouteCollectionInterface $collection): void
  22.     {
  23.         $collection->remove('view');
  24.         $collection->remove('create');
  25.         $collection->remove('edit');
  26.         $collection->add('download'$this->getBaseRouteName(). '/');
  27.     }
  28.     /**
  29.      * @param ListMapper $listMapper
  30.      */
  31.     protected function configureListFields(ListMapper $listMapper): void
  32.     {
  33.         $listMapper->addIdentifier('id')
  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()->isNull($query->getRootAliases()[0] . '.dealer')
  61.         );
  62.         return $query;
  63.     }
  64. }