src/Entity/File/Upload.php line 89

  1. <?php
  2. namespace App\Entity\File;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Delete;
  5. use ApiPlatform\Metadata\Get;
  6. use ApiPlatform\Metadata\GetCollection;
  7. use ApiPlatform\Metadata\Link;
  8. use ApiPlatform\Metadata\Patch;
  9. use ApiPlatform\Metadata\Put;
  10. use App\Doctrine\Type\File\UploadableStatus;
  11. use App\Doctrine\Type\File\UploadableType;
  12. use App\Doctrine\Type\SelectableType;
  13. use App\Entity\Common\Company;
  14. use App\Entity\Expediting\Container;
  15. use App\Entity\Expediting\Freight;
  16. use App\Entity\Expediting\Package;
  17. use App\Entity\Expediting\Shipment;
  18. use App\Entity\Sales\Contract;
  19. use App\Entity\Sales\WorkOrder;
  20. use App\Processor\Files\UploadDeleteProcessor;
  21. use App\Validator\IsValidEnum\IsValidEnum;
  22. use App\Validator\IsValidEnumArray\IsValidEnumArray;
  23. use Doctrine\DBAL\Types\Types;
  24. use Doctrine\ORM\Mapping as ORM;
  25. use Symfony\Component\Validator\Constraints as Assert;
  26. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  27. #[ORM\Entity]
  28. #[Vich\Uploadable]
  29. #[ApiResource(
  30.     operations: [
  31.         new Get(),
  32.         new Delete(processorUploadDeleteProcessor::class),
  33.         new Patch(),
  34.         new Put(),
  35.     ],
  36. )]
  37. #[ApiResource(
  38.     uriTemplate'/companies/{slug}/attachments',
  39.     operations: [new GetCollection()],
  40.     uriVariables: [
  41.         'slug' => new Link(fromProperty'attachments'fromClassCompany::class),
  42.     ],
  43. )]
  44. #[ApiResource(
  45.     uriTemplate'/sales/contracts/{slug}/attachments',
  46.     operations: [new GetCollection()],
  47.     uriVariables: [
  48.         'slug' => new Link(fromProperty'attachments'fromClassContract::class),
  49.     ],
  50. )]
  51. #[ApiResource(
  52.     uriTemplate'/work_orders/{slug}/attachments',
  53.     operations: [new GetCollection()],
  54.     uriVariables: [
  55.         'slug' => new Link(fromProperty'attachments'fromClassWorkOrder::class),
  56.     ],
  57. )]
  58. #[ApiResource(
  59.     uriTemplate'/expediting/freights/{slug}/attachments',
  60.     operations: [new GetCollection()],
  61.     uriVariables: [
  62.         'slug' => new Link(fromProperty'attachments'fromClassFreight::class),
  63.     ],
  64. )]
  65. #[ApiResource(
  66.     uriTemplate'/expediting/shipments/{slug}/attachments',
  67.     operations: [new GetCollection()],
  68.     uriVariables: [
  69.         'slug' => new Link(fromProperty'attachments'fromClassShipment::class),
  70.     ],
  71. )]
  72. #[ApiResource(
  73.     uriTemplate'/expediting/containers/{id}/attachments',
  74.     operations: [new GetCollection()],
  75.     uriVariables: [
  76.         'id' => new Link(fromProperty'attachments'fromClassContainer::class),
  77.     ],
  78. )]
  79. #[ApiResource(
  80.     uriTemplate'/expediting/packages/{slug}/attachments',
  81.     operations: [new GetCollection()],
  82.     uriVariables: [
  83.         'slug' => new Link(fromProperty'attachments'fromClassPackage::class),
  84.     ],
  85. )]
  86. class Upload extends File
  87. {
  88.     use Archivable;
  89.     /** @var UploadableType[] $types */
  90.     #[Assert\Count(min1)]
  91.     #[IsValidEnumArray(enumUploadableType::class)]
  92.     #[ORM\Column(name'uploadable_types'typeSelectableType::NAMEnullabletrueenumTypeUploadableType::class)]
  93.     private array $types = [];
  94.     #[Assert\NotNull]
  95.     #[IsValidEnum(enumUploadableStatus::class)]
  96.     #[ORM\Column(name'uploadable_status'typeTypes::STRINGnullabletrueenumTypeUploadableStatus::class)]
  97.     private ?UploadableStatus $status UploadableStatus::PUBLISHED;
  98.     public function getTypes(): array
  99.     {
  100.         return $this->types;
  101.     }
  102.     public function addType(UploadableType $type): static
  103.     {
  104.         if (!in_array($type$this->types)) {
  105.             $this->types []= $type;
  106.         }
  107.         return $this;
  108.     }
  109.     public function setTypes($types): self
  110.     {
  111.         $this->types $types;
  112.         return $this;
  113.     }
  114.     public function removeType(UploadableType $type): static
  115.     {
  116.         $key array_search($type$this->typestrue);
  117.         if ($key !== false) {
  118.             unset($this->types[$key]);
  119.         }
  120.         return $this;
  121.     }
  122.     public function getStatus(): ?UploadableStatus
  123.     {
  124.         return $this->status;
  125.     }
  126.     public function setStatus(?UploadableStatus $status): self
  127.     {
  128.         $this->status $status;
  129.         return $this;
  130.     }
  131. }