src/Containers/CrmSection/PrintablesContainer/Entities/PrintableEntity.php line 152

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\DateFilter;
  16. use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
  17. use Doctrine\ORM\Mapping as ORM;
  18. use Doctrine\DBAL\Types\Types;
  19. use Gedmo\Mapping\Annotation as Gedmo;
  20. use Symfony\Component\Serializer\Annotation\Groups;
  21. use Symfony\Component\Serializer\Annotation\MaxDepth;
  22. use Symfony\Component\Serializer\Annotation\Context;
  23. use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
  24. use App\Containers\CrmSection\PrintablesContainer\Data\Repositories\PrintableRepository;
  25. use App\Containers\SettingSection\ListContainer\Entities\StatusEntity;
  26. use App\Containers\CrmSection\ClientContainer\Entities\ClientEntity;
  27. use App\Containers\CrmSection\PrintablesContainer\Entities\TemplateEntity;
  28. use App\Containers\CrmSection\PrintablesContainer\UI\ApiPlatform\Controllers\PostPrintableSetByBinaryController;
  29. use App\Containers\CrmSection\PrintablesContainer\UI\ApiPlatform\Controllers\GetPrintableByObjectController;
  30. use App\Containers\CrmSection\PrintablesContainer\UI\ApiPlatform\Controllers\DeletePrintableController;
  31. use App\Containers\CrmSection\PrintablesContainer\Entities\FileEntity;
  32. use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
  33. /** 
  34.  * Печатные формы
  35. */
  36. #[ApiResource(
  37.     routePrefix'/crm',
  38.     normalizationContext: [
  39.         'groups' => 'read',
  40.         'enable_max_depth' => true
  41.     ],
  42.     operations: [
  43.         new Get(
  44.             uriTemplate'/printables/{id}'requirements: ['id' => '\d+'],
  45.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  46.         ),
  47.         new Get(
  48.             uriTemplate'/printables/by_object',
  49.             controllerGetPrintableByObjectController::class,
  50.             openapiContext: [
  51.                 "summary" => "Get printable by object",
  52.                 "description" => "",
  53.                 'parameters' => [
  54.                     [
  55.                         'in' => 'query',
  56.                         'name' => 'object',
  57.                         'required' => true,
  58.                         'schema' => [
  59.                             'type' => 'string'
  60.                         ]
  61.                     ]
  62.                 ]
  63.             ],
  64.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  65.         ),
  66.         // new Patch(
  67.         //     uriTemplate: '/printables/{id}', requirements: ['id' => '\d+'],
  68.         //     security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  69.         // ),
  70.         // new Put(
  71.         //     uriTemplate: '/printables/{id}', requirements: ['id' => '\d+'],
  72.         //     security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  73.         // ),
  74.         new Delete(
  75.             uriTemplate'/printables/{id}'requirements: ['id' => '\d+'],
  76.             controllerDeletePrintableController::class,
  77.             security"is_granted('ROLE_ADMIN')"
  78.         ),
  79.         // new Post(
  80.         //     uriTemplate: '/printables',
  81.         //     security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  82.         // ),
  83.         // new Post(
  84.         //     uriTemplate: '/printables/set_by_binary',
  85.         //     controller: PostPrintableSetByBinaryController::class,
  86.         //     deserialize: false, 
  87.         //     validationContext: ['groups' => ['read', 'media_object_create']], 
  88.         //     openapiContext: [
  89.         //         'requestBody' => [
  90.         //             'required' => true,
  91.         //             'content' => [
  92.         //                 'multipart/form-data' => [
  93.         //                     'schema' => [
  94.         //                         'type' => 'object', 
  95.         //                         'properties' => [
  96.         //                             'object' => [
  97.         //                                 'type' => 'string'
  98.         //                             ],
  99.         //                             'file' => [
  100.         //                                 'type' => 'string', 
  101.         //                                 'format' => 'binary'
  102.         //                             ]
  103.         //                         ],
  104.         //                         'required' => [
  105.         //                             'object',
  106.         //                             'file'
  107.         //                         ]
  108.         //                     ]
  109.         //                 ]
  110.         //             ]
  111.         //         ]
  112.         //     ],
  113.         //     security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  114.         // ),
  115.         new GetCollection(
  116.             uriTemplate'/printables',
  117.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  118.         )
  119.     ],
  120.     shortName'CRM_Printables'
  121. )]
  122. #[ApiFilter(SearchFilter::class, properties: [
  123.     'id' => 'exact',
  124.     'objectId' => 'exact',
  125.     'objectClass' => 'exact',
  126.     'externalCode' => 'partial'
  127.     'status' => 'exact'
  128.     'status.name' => 'exact'
  129.     'status.externalCode' => 'exact',
  130.     'client' => 'exact'
  131.     'client.name' => 'partial'
  132.     'client.lastName' => 'partial'
  133.     'client.patronymic' => 'partial'
  134.     'client.externalCode' => 'partial'
  135.     'client.phone' => 'exact'
  136.     'client.email' => 'exact'
  137.     'client.inn' => 'exact'
  138.     'template' => 'exact'
  139.     'template.name' => 'partial',
  140.     'template.externalCode' => 'exact' 
  141. ])]
  142. #[ApiFilter(NumericFilter::class, properties: ['id''objectId'])]
  143. #[ApiFilter(RangeFilter::class, properties: ['id''objectId'])]
  144. #[ApiFilter(DateFilter::class, properties: ['dateGeneration''dateSigning'])]
  145. #[ApiFilter(OrderFilter::class)]
  146. #[ApiFilter(filterClassSimpleSearchFilter::class, properties: ['externalCode'])]
  147. #[ORM\Entity(repositoryClassPrintableRepository::class)]
  148. #[ORM\Table(name'`crm_printables`')]
  149. class PrintableEntity
  150. {   
  151.     #[ORM\Id]
  152.     #[ORM\GeneratedValue]
  153.     #[ORM\Column(typeTypes::INTEGER)]
  154.     #[Groups(['read'])]
  155.     private ?int $id null;
  156.     // Статус
  157.     #[ORM\ManyToOne(targetEntityStatusEntity::class)]
  158.     #[ORM\JoinColumn(name'status_id'referencedColumnName'id'nullablefalse)]
  159.     #[Groups(['read'])]
  160.     #[MaxDepth(1)]
  161.     private StatusEntity $status;
  162.     // Клиент
  163.     #[ORM\ManyToOne(targetEntityClientEntity::class)]
  164.     #[ORM\JoinColumn(name'client_id'referencedColumnName'id'nullablefalse)]
  165.     #[Groups(['read'])]
  166.     #[MaxDepth(2)]
  167.     private ClientEntity $client;
  168.     // Шаблон
  169.     #[ORM\ManyToOne(targetEntityTemplateEntity::class)]
  170.     #[ORM\JoinColumn(name'template_id'referencedColumnName'id'nullablefalse)]
  171.     #[Groups(['read'])]
  172.     #[MaxDepth(2)]
  173.     private TemplateEntity $template;
  174.     // Дата генерации
  175.     #[Gedmo\Timestampable(on'update')]
  176.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  177.     #[Context(
  178.         normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s'],
  179.         denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s']
  180.     )]
  181.     #[Groups(['read'])]
  182.     protected \DateTimeInterface $dateGeneration;
  183.     // Файл
  184.     #[ORM\ManyToOne(targetEntityFileEntity::class)]
  185.     #[ORM\JoinColumn(name'file_id'referencedColumnName'id'nullablefalse)]
  186.     private FileEntity $file;
  187.     #[ApiProperty(types: ['https://schema.org/contentUrl'])]
  188.     #[Groups(['read''printables_object:read'])]
  189.     public ?string $contentUrl null;
  190.     // Код подписи
  191.     #[ORM\Column(typeTypes::STRINGlength100nullabletrue)]
  192.     #[Groups(['read'])]
  193.     private ?string $codeSigning null;
  194.     // Дата подписи
  195.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLEnullabletrue)]
  196.     #[Context(
  197.         normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s'],
  198.         denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s']
  199.     )]
  200.     #[Groups(['read'])]
  201.     private ?\DateTimeInterface $dateSigning null;
  202.     // Подписанный файл
  203.     #[ORM\ManyToOne(targetEntityFileEntity::class)]
  204.     #[ORM\JoinColumn(name'signed_file_id'referencedColumnName'id'nullabletrue)]
  205.     private ?FileEntity $signedFile null;
  206.     #[ApiProperty(types: ['https://schema.org/contentUrl'])]
  207.     #[Groups(['read''printables_object:read'])]
  208.     public ?string $signedContentUrl null;
  209.     // Код
  210.     #[ORM\Column(typeTypes::STRINGlength255nullabletrueuniquetrue)]
  211.     #[Groups(['read'])]
  212.     private ?string $externalCode null;
  213.     // Класс объекта
  214.     #[ORM\Column(typeTypes::STRINGlength191nullablefalse)]
  215.     private string $objectClass;
  216.     // Id объекта
  217.     #[ORM\Column(typeTypes::INTEGERnullablefalse)]
  218.     private int $objectId;
  219.     #[Groups(['read'])]
  220.     public ?object $object null;
  221.     #[Gedmo\Timestampable(on'create')]
  222.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  223.     protected $createdAt;
  224.     #[Gedmo\Timestampable(on'update')]
  225.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  226.     protected $updatedAt;
  227.     public function getId(): ?int
  228.     {
  229.         return $this->id;
  230.     }
  231.     public function getStatus()
  232.     {
  233.         return $this->status;
  234.     }
  235.     public function setStatus($status)
  236.     {
  237.         $this->status $status;
  238.         return $this;
  239.     }
  240.     public function getDateGeneration()
  241.     {
  242.         return $this->dateGeneration;
  243.     }
  244.     public function setDateGeneration(\DateTimeImmutable $date)
  245.     {
  246.         $this->dateGeneration $date;
  247.         return $this;
  248.     }
  249.     public function getClient()
  250.     {
  251.         return $this->client;
  252.     }
  253.     public function setClient($client)
  254.     {
  255.         $this->client $client;
  256.         return $this;
  257.     }
  258.     public function getTemplate()
  259.     {
  260.         return $this->template;
  261.     }
  262.     public function setTemplate($template)
  263.     {
  264.         $this->template $template;
  265.         return $this;
  266.     }
  267.     public function getFile()
  268.     {
  269.         return $this->file;
  270.     }
  271.     public function setFile($file)
  272.     {
  273.         $this->file $file;
  274.         return $this;
  275.     }
  276.     public function getCodeSigning()
  277.     {
  278.         return $this->codeSigning;
  279.     }
  280.     public function setCodeSigning($code)
  281.     {
  282.         $this->codeSigning $code;
  283.         return $this;
  284.     }
  285.     public function getDateSigning()
  286.     {
  287.         return $this->dateSigning;
  288.     }
  289.     public function setDateSigning(\DateTimeImmutable|null $date)
  290.     {
  291.         $this->dateSigning $date;
  292.         return $this;
  293.     }
  294.     public function getSignedFile()
  295.     {
  296.         return $this->signedFile;
  297.     }
  298.     public function setSignedFile($file)
  299.     {
  300.         $this->signedFile $file;
  301.         return $this;
  302.     }
  303.     public function getExternalCode()
  304.     {
  305.         return $this->externalCode;
  306.     }
  307.     public function setExternalCode($code)
  308.     {
  309.         $this->externalCode $code;
  310.         return $this;
  311.     }
  312.     public function setObjectClass($objectClass)
  313.     {
  314.         $this->objectClass $objectClass;
  315.         return $this;
  316.     }
  317.     public function getObjectClass()
  318.     {
  319.         return $this->objectClass;
  320.     }
  321.     public function setObjectId($Id)
  322.     {
  323.         $this->objectId $Id;
  324.         return $this;
  325.     }
  326.     public function getObjectId()
  327.     {
  328.         return $this->objectId;
  329.     }
  330. }