src/AdminBundle/Admin/DCAutoSite/BodyRepairCertificateAdmin.php line 16

Open in your IDE?
  1. <?php
  2. namespace AdminBundle\Admin\DCAutoSite;
  3. use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
  4. use AdminBundle\Admin\BaseAdmin;
  5. use DcSiteBundle\Entity\BodyRepairCertificate;
  6. use Sonata\AdminBundle\Datagrid\ListMapper;
  7. use Sonata\AdminBundle\Form\FormMapper;
  8. use Sonata\MediaBundle\Form\Type\MediaType;
  9. use Symfony\Component\Finder\Exception\AccessDeniedException;
  10. use Symfony\Component\Form\Extension\Core\Type\DateType;
  11. class BodyRepairCertificateAdmin extends BaseAdmin
  12. {
  13.     /**
  14.      * @param BodyRepairCertificate $object
  15.      */
  16.     public function prePersist($object): void
  17.     {
  18.         $user $this->getUser();
  19.         if (!$user->getDealer() && !$object->getDealer()) {
  20.             throw new AccessDeniedException('User without dealer');
  21.         }
  22.         $object->setDealer($user->getDealer());
  23.     }
  24.     /**
  25.      * @param string $context
  26.      * @return ProxyQueryInterface
  27.      */
  28.     public function configureQuery($context 'list'): ProxyQueryInterface
  29.     {
  30.         $user $this->security->getUser();
  31.         $query parent::configureQuery($context);
  32.         $dealer $user->getDealer();
  33.         if (!$dealer) {
  34.             throw new AccessDeniedException();
  35.         }
  36.         $query->andWhere($query->getRootAliases()[0] . '.dealer = :dealer');
  37.         $query->setParameter('dealer'$dealer->getId());
  38.         return $query;
  39.     }
  40.     /**
  41.      * @param FormMapper $form
  42.      */
  43.     public function configureFormFields(FormMapper $form): void
  44.     {
  45.         $form
  46.             ->tab('Информация')
  47.             ->with(' ', ['class' => 'col-lg-6 without-box-heder'])
  48.             ->add('file'MediaType::class, [
  49.                 'label' => 'Сертифікат (PDF)',
  50.                 'provider' => 'sonata.media.provider.file',
  51.                 'context' => 'dc_file'
  52.             ])
  53.             ->add('title_ua'null, [
  54.                 'label' => 'Название UA',
  55.             ])
  56.             ->add('title_ru'null, [
  57.                 'label' => 'Название RU',
  58.             ])
  59.             ->add('begin_date'DateType::class, [
  60.                 'label' => 'Сертифікат від',
  61.                 'widget' => 'single_text',
  62.             ])
  63.             ->end()
  64.             ->end();
  65.     }
  66.     /**
  67.      * @param ListMapper $list
  68.      */
  69.     public function configureListFields(ListMapper $list): void
  70.     {
  71.         $list->addIdentifier('id')
  72.             ->add('title_ua'null, ['label' => 'Назва договору'])
  73.             ->add('begin_date'null, [
  74.                 'label' => 'Редакція договору від',
  75.                 'format' => 'd.m.Y',
  76.             ])
  77.             ->add('_action''actions', [
  78.                 'label' => 'Действия',
  79.                 'actions' => [
  80.                     'edit' => [],
  81.                 ]
  82.             ]);
  83.     }
  84. }