src/Containers/CrmSection/PrintablesContainer/Entities/TemplateEntity.php line 120

Open in your IDE?
  1. <?php
  2. namespace App\Containers\CrmSection\PrintablesContainer\Entities;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\ApiProperty;
  5. use ApiPlatform\Metadata\Delete;
  6. use ApiPlatform\Metadata\Get;
  7. use ApiPlatform\Metadata\GetCollection;
  8. use ApiPlatform\Metadata\Patch;
  9. use ApiPlatform\Metadata\Put;
  10. use ApiPlatform\Metadata\Post;
  11. use ApiPlatform\Metadata\ApiFilter;
  12. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  13. use ApiPlatform\Doctrine\Orm\Filter\NumericFilter;
  14. use ApiPlatform\Doctrine\Orm\Filter\RangeFilter;
  15. use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
  16. use Doctrine\ORM\Mapping as ORM;
  17. use Doctrine\DBAL\Types\Types;
  18. use Gedmo\Mapping\Annotation as Gedmo;
  19. use Symfony\Component\Serializer\Annotation\Groups;
  20. use Symfony\Component\Serializer\Annotation\MaxDepth;
  21. use App\Containers\CrmSection\PrintablesContainer\Data\Repositories\TemplateRepository;
  22. use App\Containers\CrmSection\PrintablesContainer\Entities\ProviderEntity;
  23. use App\Containers\CrmSection\PrintablesContainer\UI\ApiPlatform\Controllers\PostTemplateSetByBinaryController;
  24. use App\Containers\CrmSection\PrintablesContainer\UI\ApiPlatform\Controllers\DeleteTemplateController;
  25. use App\Containers\CrmSection\IndexContainer\Entities\TranslationEntity;
  26. use App\Ship\Entities\MediaEntity;
  27. use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
  28. /** 
  29.  * Шаблон печатных форм
  30. */
  31. #[ApiResource(
  32.     routePrefix'/crm',
  33.     normalizationContext: [
  34.         'groups' => 'read',
  35.         'enable_max_depth' => true
  36.     ],
  37.     operations: [
  38.         new Get(
  39.             uriTemplate'/printable_templates/{id}'requirements: ['id' => '\d+'],
  40.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  41.         ),
  42.         // new Patch(
  43.         //     uriTemplate: '/printable_templates/{id}', requirements: ['id' => '\d+'],
  44.         //     security: "is_granted('ROLE_ADMIN')"
  45.         // ),
  46.         // new Put(
  47.         //     uriTemplate: '/printable_templates/{id}', requirements: ['id' => '\d+'],
  48.         //     security: "is_granted('ROLE_ADMIN')"
  49.         // ),
  50.         new Delete(
  51.             uriTemplate'/printable_templates/{id}'requirements: ['id' => '\d+'],
  52.             controllerDeleteTemplateController::class,
  53.             security"is_granted('ROLE_ADMIN')"
  54.         ),
  55.         new Post(
  56.             uriTemplate'/printable_templates/set_by_binary',
  57.             controllerPostTemplateSetByBinaryController::class,
  58.             deserializefalse
  59.             validationContext: ['groups' => ['read''media_object_create']], 
  60.             openapiContext: [
  61.                 'requestBody' => [
  62.                     'required' => true,
  63.                     'content' => [
  64.                         'multipart/form-data' => [
  65.                             'schema' => [
  66.                                 'type' => 'object'
  67.                                 'properties' => [
  68.                                     'name' => [
  69.                                         'type' => 'string'
  70.                                     ],
  71.                                     'file' => [
  72.                                         'type' => 'string'
  73.                                         'format' => 'binary'
  74.                                     ],
  75.                                     'provider' => [
  76.                                         'type' => 'string'
  77.                                     ],
  78.                                     'externalCode' => [
  79.                                         'type' => 'string'
  80.                                     ]
  81.                                 ],
  82.                                 'required' => [
  83.                                     'name',
  84.                                     'file',
  85.                                     'provider'
  86.                                 ]
  87.                             ]
  88.                         ]
  89.                     ]
  90.                 ]
  91.             ],
  92.             security"is_granted('ROLE_ADMIN')"
  93.         ),
  94.         new GetCollection(
  95.             uriTemplate'/printable_templates',
  96.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  97.         ),
  98.     ],
  99.     shortName'CRM_Printables'
  100. )]
  101. #[ApiFilter(SearchFilter::class, properties: [
  102.     'id' => 'exact',
  103.     'name' => 'exact',
  104.     'externalCode' => 'partial',
  105.     'provider' => 'exact'
  106.     'provider.name' => 'exact'
  107.     'provider.objectClass' => 'exact'
  108.     'provider.taskClass' => 'exact'
  109. ])]
  110. #[ApiFilter(NumericFilter::class, properties: ['id'])]
  111. #[ApiFilter(RangeFilter::class, properties: ['id'])]
  112. #[ApiFilter(OrderFilter::class)]
  113. #[ApiFilter(filterClassSimpleSearchFilter::class, properties: ['externalCode'])]
  114. #[ORM\Entity(repositoryClassTemplateRepository::class)]
  115. #[ORM\Table(name'`crm_printable_templates`')]
  116. #[Gedmo\TranslationEntity(class: TranslationEntity::class)]
  117. class TemplateEntity
  118. {   
  119.     #[ORM\Id]
  120.     #[ORM\GeneratedValue]
  121.     #[ORM\Column(typeTypes::INTEGER)]
  122.     #[Groups(['read'])]
  123.     private ?int $id null;
  124.     // Название
  125.     #[ORM\Column(typeTypes::STRINGlength150nullablefalse)]
  126.     #[Gedmo\Translatable]
  127.     #[Groups(['read'])]
  128.     private string $name;
  129.     // Файл
  130.     #[ORM\ManyToOne(targetEntityMediaEntity::class)]
  131.     #[ORM\JoinColumn(name'file_id'referencedColumnName'id'nullablefalse)]
  132.     private MediaEntity $file;
  133.     #[ApiProperty(types: ['https://schema.org/contentUrl'])]
  134.     #[Groups(['read''media_object:read'])]
  135.     public ?string $contentUrl null;
  136.     // Провайдер
  137.     #[ORM\ManyToOne(targetEntityProviderEntity::class)]
  138.     #[ORM\JoinColumn(name'provider_id'referencedColumnName'id'nullablefalse)]
  139.     #[Groups(['read'])]
  140.     #[MaxDepth(2)]
  141.     private ProviderEntity $provider;
  142.     // Код
  143.     #[ORM\Column(typeTypes::STRINGlength255nullabletrueuniquetrue)]
  144.     #[Groups(['read'])]
  145.     private ?string $externalCode null;
  146.     #[Gedmo\Timestampable(on'create')]
  147.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  148.     protected $createdAt;
  149.     #[Gedmo\Timestampable(on'update')]
  150.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  151.     protected $updatedAt;
  152.     /**
  153.      * Used locale to override Translation listener`s locale
  154.      * this is not a mapped field of entity metadata, just a simple property
  155.      */
  156.     #[Gedmo\Locale]
  157.     private $locale;
  158.     public function getId(): ?int
  159.     {
  160.         return $this->id;
  161.     }
  162.     public function getName()
  163.     {
  164.         return $this->name;
  165.     }
  166.     public function setName($name)
  167.     {
  168.         $this->name $name;
  169.         return $this;
  170.     }
  171.     public function getFile()
  172.     {
  173.         return $this->file;
  174.     }
  175.     public function setFile($file)
  176.     {
  177.         $this->file $file;
  178.         return $this;
  179.     }
  180.     public function getProvider()
  181.     {
  182.         return $this->provider;
  183.     }
  184.     public function setProvider($provider)
  185.     {
  186.         $this->provider $provider;
  187.         return $this;
  188.     }
  189.     public function getExternalCode()
  190.     {
  191.         return $this->externalCode;
  192.     }
  193.     public function setExternalCode($code)
  194.     {
  195.         $this->externalCode $code;
  196.         return $this;
  197.     }
  198.     public function setTranslatableLocale($locale)
  199.     {
  200.         $this->locale $locale;
  201.     }
  202. }