src/Entity/File/Parsable.php line 54

  1. <?php
  2. namespace App\Entity\File;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Post;
  5. use ApiPlatform\OpenApi\Model;
  6. use App\Controller\Purchasing\PurchaseOrderDatasheetUploadAction;
  7. use App\Doctrine\Type\File\ParsableStatus;
  8. use App\Doctrine\Type\File\ParsableType;
  9. use App\Dto\Expediting\FreightDatasheetInput;
  10. use App\Entity\Purchasing\Order;
  11. use App\Entity\Sales\WorkOrder;
  12. use App\Validator\IsValidEnum\IsValidEnum;
  13. use ArrayObject;
  14. use Doctrine\Common\Collections\ArrayCollection;
  15. use Doctrine\Common\Collections\Collection;
  16. use Doctrine\DBAL\Types\Types;
  17. use Doctrine\ORM\Mapping as ORM;
  18. use Symfony\Component\Validator\Constraints as Assert;
  19. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  20. #[ORM\Entity]
  21. #[Vich\Uploadable]
  22. #[ApiResource(
  23.     // FIXME : This does not work well with docker
  24.     uriTemplate'/purchasing/orders/import',
  25.     operations: [
  26.         new Post(
  27.             controllerPurchaseOrderDatasheetUploadAction::class,
  28.             openapi: new Model\Operation(
  29.                 requestBody: new Model\RequestBody(
  30.                     content: new ArrayObject([
  31.                         'multipart/form-data' => [
  32.                             'schema' => [
  33.                                 'type' => 'object',
  34.                                 'properties' => [
  35.                                     'file' => [
  36.                                         'type' => 'string',
  37.                                         'format' => 'binary'
  38.                                     ]
  39.                                 ]
  40.                             ]
  41.                         ]
  42.                     ])
  43.                 )
  44.             ),
  45.             shortName'Upload',
  46.             validationContext: ['groups' => ['Default''upload:create']],
  47.             deserializefalse,
  48.         ),
  49.     ],
  50. )]
  51. class Parsable extends File
  52. {
  53.     use Archivable;
  54.     #[Assert\Type(typeFreightDatasheetInput::class)]
  55.     #[ORM\Column(type'json_document'options: ['jsonb' => true])]
  56.     private ?FreightDatasheetInput $data null;
  57.     #[ORM\Column(typeTypes::JSONnullabletrueoptions: ['jsonb' => true])]
  58.     private ?array $errors = [];
  59.     #[Assert\NotNull]
  60.     #[IsValidEnum(enumParsableType::class)]
  61.     #[ORM\Column(name'parsable_type'typeTypes::STRINGnullablefalseenumTypeParsableType::class)]
  62.     private ?ParsableType $type null;
  63.     #[Assert\NotNull]
  64.     #[IsValidEnum(enumParsableStatus::class)]
  65.     #[ORM\Column(name'parsable_status'typeTypes::STRINGnullabletrueenumTypeParsableStatus::class)]
  66.     private ?ParsableStatus $status ParsableStatus::UPLOADED;
  67.     #[ORM\OneToOne(mappedBy'source'targetEntityWorkOrder::class)]
  68.     private ?WorkOrder $workOrder null;
  69.     /** @var Collection<int, Order> $orders */
  70.     #[ORM\OneToMany(mappedBy'source'targetEntityOrder::class)]
  71.     private Collection $orders;
  72.     public function __construct()
  73.     {
  74.         $this->orders = new ArrayCollection();
  75.     }
  76.     public function getData(): ?FreightDatasheetInput
  77.     {
  78.         return $this->data;
  79.     }
  80.     public function setData(?FreightDatasheetInput $data): self
  81.     {
  82.         $this->data $data;
  83.         return $this;
  84.     }
  85.     public function getErrors(): array
  86.     {
  87.         return $this->errors;
  88.     }
  89.     public function setErrors(?array $errors): self
  90.     {
  91.         $this->errors $errors;
  92.         return $this;
  93.     }
  94.     public function getType(): ?ParsableType
  95.     {
  96.         return $this->type;
  97.     }
  98.     public function setType(ParsableType $type): self
  99.     {
  100.         $this->type $type;
  101.         return $this;
  102.     }
  103.     public function getStatus(): ?ParsableStatus
  104.     {
  105.         return $this->status;
  106.     }
  107.     public function setStatus(?ParsableStatus $status): self
  108.     {
  109.         $this->status $status;
  110.         return $this;
  111.     }
  112.     public function getWorkOrder(): ?WorkOrder
  113.     {
  114.         return $this->workOrder;
  115.     }
  116.     public function setWorkOrder(?WorkOrder $workOrder): self
  117.     {
  118.         $this->workOrder $workOrder;
  119.         return $this;
  120.     }
  121.     /**
  122.      * @return Collection<int, Order>
  123.      */
  124.     public function getOrders(): Collection
  125.     {
  126.         return $this->orders;
  127.     }
  128.     public function addOrder(Order $order): self
  129.     {
  130.         if (!$this->orders->contains($order)) {
  131.             $this->orders->add($order);
  132.             $order->setSource($this);
  133.         }
  134.         return $this;
  135.     }
  136.     public function removeOrder(Order $order): self
  137.     {
  138.         if ($this->orders->removeElement($order)) {
  139.             // set the owning side to null (unless already changed)
  140.             if ($order->getSource() === $this) {
  141.                 $order->setSource(null);
  142.             }
  143.         }
  144.         return $this;
  145.     }
  146. }