src/Controller/EasyAdmin/Ozon/OzonClientCrudController.php line 80

Open in your IDE?
  1. <?php
  2. namespace App\Controller\EasyAdmin\Ozon;
  3. use App\Entity\OzonClient;
  4. use App\Service\AdminUser\Type\AdminUserRoleType;
  5. use App\Service\Ozon\Type\OzonWarhouseAdditionalSettings;
  6. use Doctrine\ORM\QueryBuilder;
  7. use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
  8. use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection;
  9. use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
  10. use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
  11. use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
  12. use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
  13. use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
  14. use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto;
  15. use EasyCorp\Bundle\EasyAdminBundle\Field\ArrayField;
  16. use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
  17. use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
  18. use EasyCorp\Bundle\EasyAdminBundle\Field\Field;
  19. use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
  20. use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
  21. use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
  22. use EasyCorp\Bundle\EasyAdminBundle\Orm\EntityRepository;
  23. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  24. class OzonClientCrudController extends AbstractCrudController
  25. {
  26.     private UrlGeneratorInterface $urlGenerator;
  27.     public function __construct(UrlGeneratorInterface $urlGenerator)
  28.     {
  29.         $this->urlGenerator $urlGenerator;
  30.     }
  31.     public static function getEntityFqcn(): string
  32.     {
  33.         return OzonClient::class;
  34.     }
  35.     /**
  36.      * @param SearchDto $searchDto
  37.      * @param EntityDto $entityDto
  38.      * @param FieldCollection $fields
  39.      * @param FilterCollection $filters
  40.      * @return QueryBuilder
  41.      */
  42.     public function createIndexQueryBuilder(SearchDto $searchDtoEntityDto $entityDtoFieldCollection $fieldsFilterCollection $filters): QueryBuilder
  43.     {
  44.         $response $this->get(EntityRepository::class)->createQueryBuilder($searchDto$entityDto$fields$filters);
  45.         if(!in_array(AdminUserRoleType::ROLE_ADMIN$this->getUser()->getRoles())) {
  46.             $response
  47.                 ->andWhere('entity.id IN (:clients)')
  48.                 ->setParameter('clients'$this->getUser()->getOzonClients());
  49.         }
  50.         return $response
  51.             ->orderBy('entity.id''DESC')
  52.             ;
  53.     }
  54.     public function configureCrud(Crud $crud): Crud
  55.     {
  56.         return $crud
  57.             ->setSearchFields([
  58.                 'id''name''url''storeUrl''apiClientId''apiKey''storeFbs''storeFbo''orderType',
  59.                 'orderPriceDeflection''minStock''legalName'
  60.             ])
  61.             ->setDefaultSort(['id' => 'DESC'])
  62.             ->setPaginatorPageSize(50)
  63.             ->setEntityLabelInSingular('Торговая площадка')
  64.             ->setEntityLabelInPlural('Торговые площадки')
  65.             ->setEntityPermission(AdminUserRoleType::ROLE_OZON_CLIENT_VIEW);
  66.     }
  67.     public function configureActions(Actions $actions): Actions
  68.     {
  69.         $getHidePriceProducts Action::new('getLastPostings''Получить заказы за 24ч')
  70.             ->linkToUrl(function (OzonClient $client): string {
  71.                 return $this->urlGenerator->generate(
  72.                     'ozon_posting_client_load',
  73.                     ['id' => $client->getId()],
  74.                     UrlGeneratorInterface::ABSOLUTE_PATH
  75.                 );
  76.             });
  77.         $actions
  78.             ->add(Crud::PAGE_INDEX$getHidePriceProducts);
  79.         if(!in_array(AdminUserRoleType::ROLE_OZON_CLIENT_EDIT$this->getUser()->getRoles())) {
  80.             $actions->disable(Crud::PAGE_NEWCrud::PAGE_EDIT);
  81.         }
  82.         return $actions;
  83.     }
  84.     public function configureFields(string $pageName): iterable
  85.     {
  86.         $name TextField::new('name''Название');
  87.         $legalName TextField::new('legalName''Юр. лицо');
  88.         $storeUrl TextField::new('storeUrl''Url\\Адрес магазина');
  89.         $url TextField::new('url''URL');
  90.         $apiClientId TextField::new('apiClientId''Client ID');
  91.         $apiKey TextField::new('apiKey''API Key');
  92.         $retailCrmId TextField::new('retailCrmId''API Key RetailCRM');
  93.         $site TextField::new('retailCrmSite''Site RetailCRM');
  94.         $omsStoreId TextField::new('omsStoreId''oms store');
  95.         $omsApiKey TextField::new('omsApiKey''oms api key');
  96.         $omsPassword TextField::new('omsPassword''oms password');
  97. //        $storeFbsObject = Field::new('storeFbsObject', 'Склад FBS');
  98. //        $storeFboObject = Field::new('storeFboObject', 'Склад FBO');
  99. //        $orderTypeObject = Field::new('orderTypeObject', 'Тип заказа');
  100.         $isEnabled Field::new('isEnabled''Активно');
  101.         $isEnabledOrders Field::new('isEnabledOrders''Заказы в 1C');
  102.         $isEnabledStatuses Field::new('isEnabledStatuses''Статусы в 1C');
  103.         $startOrdersTm DateTimeField::new('startOrdersTm''Передавать заказы начиная с');
  104.         $orderPriceDeflection IntegerField::new('orderPriceDeflection''Отклонение стоимости заказа, %');
  105.         $isEnabledStocks Field::new('isEnabledStocks''Обновление остатков');
  106.         $isEnabledPrice Field::new('isEnabledPrice''Обновление цен');
  107.         $useNightPrice Field::new('useNightPrice''Ночные цены');
  108.         $currencyCode IntegerField::new('currencyCode''Валюта магазина');
  109.         $id IntegerField::new('id''ID');
  110.         $storeFbs TextField::new('storeFbs''Склад FBS');
  111.         $storeFbo TextField::new('storeFbo''Склад FBO');
  112.         $orderType TextField::new('orderType''Тип заказа');
  113.         $currency TextareaField::new('currency''Валюта');
  114.         $targets ArrayField::new('targets''Базы 1C');
  115.         $company ChoiceField::new('legalName''Юр. лицо')
  116.             ->setChoices([
  117.                 'ООО “Гипер”' => 'ООО “Гипер”',
  118.                 'ООО “Фирменные Решения”' => 'ООО “Фирменные Решения”',
  119.                 'ООО “Официальный магазин”' => 'ООО “Официальный магазин”',
  120.                 'ИП Кунгуров' => 'ИП Кунгуров',
  121.             ])
  122.             ->allowMultipleChoices(false)
  123.             ->renderExpanded(false);
  124.         $thankyouMsg TextareaField::new('thankyouMessage''Текст сообщения после вручения заказа');
  125.         $thankyouMsgIsSend Field::new('isThankyouMsgSend''Отправлять сообщение после вручения заказа');
  126.         switch ($pageName) {
  127.             case Crud::PAGE_INDEX:
  128.                 $fields = [
  129.                     $id$name$legalName$url$apiClientId$apiKey$storeFbs$storeFbo$orderType$currency,
  130.                     $targets$isEnabled$isEnabledOrders$isEnabledStatuses$isEnabledPrice$isEnabledStocks$company$omsStoreId
  131.                 ];
  132.                 break;
  133.             case Crud::PAGE_DETAIL:
  134.                 $fields = [
  135.                     $id$name$legalName$url$apiClientId$apiKey$retailCrmId$site$storeFbs$storeFbo$orderType$currency,
  136.                     $targets$isEnabled$isEnabledOrders$isEnabledStatuses$isEnabledPrice$isEnabledStocks$company,
  137.                     $thankyouMsgIsSend$thankyouMsg$omsStoreId$omsApiKey$omsPassword
  138.                 ];
  139.                 break;
  140.             case Crud::PAGE_NEW:
  141.             case Crud::PAGE_EDIT:
  142.                 $fields = [
  143.                     $name$legalName$storeUrl$url$apiClientId$apiKey$retailCrmId$site$storeFbs$storeFbo$orderType,
  144.                     $isEnabled$isEnabledOrders$isEnabledStatuses$startOrdersTm$orderPriceDeflection,
  145.                     $isEnabledStocks$isEnabledPrice$currencyCode$company,
  146.                     $thankyouMsgIsSend$thankyouMsg$omsStoreId$omsApiKey$omsPassword
  147.                 ];
  148.                 break;
  149.             default:
  150.                 $fields = [];
  151.         }
  152.         return $fields;
  153.     }
  154. }