src/AdminBundle/Admin/DCAutoSite/TermsMaintenanceAdmin.php line 20

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\TermsMaintenance;
  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. /**
  12.  * Class TermsMaintenanceAdmin
  13.  * @package AdminBundle\Admin\DCAutoSite
  14.  */
  15. class TermsMaintenanceAdmin extends BaseAdmin
  16. {
  17.     /**
  18.      * @param TermsMaintenance $object
  19.      */
  20.     public function prePersist($object): void
  21.     {
  22.         $user $this->getUser();
  23.         if(!$user->getDealer() && !$object->getDealer()) {
  24.             throw new AccessDeniedException('User without dealer');
  25.         }
  26.         $object->setDealer($user->getDealer());
  27.     }
  28.     /**
  29.      * @param string $context
  30.      * @return ProxyQueryInterface
  31.      */
  32.     public function configureQuery($context 'list'): ProxyQueryInterface
  33.     {
  34.         $user $this->getUser();
  35.         $query parent::configureQuery($context);
  36.         $dealer $user->getDealer();
  37.         if(!$dealer) {
  38.             throw new AccessDeniedException();
  39.         }
  40.         $query->andWhere($query->getRootAliases()[0].'.dealer = :dealer');
  41.         $query->setParameter('dealer'$dealer->getId());
  42.         return $query;
  43.     }
  44.     /**
  45.      * @param FormMapper $form
  46.      */
  47.     public function configureFormFields(FormMapper $form): void
  48.     {
  49.         $form
  50.             ->tab('Информация')
  51.             ->with(' ', ['class' => 'col-lg-6 without-box-heder'])
  52.             ->add('file'MediaType::class, [
  53.                 'label' => 'Файл договору',
  54.                 'provider' => 'sonata.media.provider.file',
  55.                 'context'  => 'dc_file'
  56.             ])
  57.             ->add('title_ua'null, [
  58.                 'label' => 'Название UA',
  59.             ])
  60.             ->add('title_ru'null, [
  61.                 'label' => 'Название RU',
  62.             ])
  63.             ->add('begin_date'DateType::class, [
  64.                 'label' => 'Редакція договору від',
  65.                 'widget' => 'single_text',
  66.             ])
  67.             ->end()
  68.             ->end()
  69.         ;
  70.     }
  71.     /**
  72.      * @param ListMapper $list
  73.      */
  74.     public function configureListFields(ListMapper $list): void
  75.     {
  76.         $list->addIdentifier('id')
  77.             ->add('title_ua'null, ['label' => 'Назва договору'])
  78.             ->add('begin_date'null, [
  79.                 'label' => 'Редакція договору від',
  80.                 'format' => 'd.m.Y',
  81.             ])
  82.             ->add('_action''actions', [
  83.                 'label' => 'Действия',
  84.                 'actions' => [
  85.                     'edit' => [],
  86.                 ]
  87.             ])
  88.         ;
  89.     }
  90. }