src/Entity/Expediting/Container.php line 52

  1. <?php
  2. namespace App\Entity\Expediting;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Delete;
  5. use ApiPlatform\Metadata\Get;
  6. use ApiPlatform\Metadata\GetCollection;
  7. use ApiPlatform\Metadata\Patch;
  8. use ApiPlatform\Metadata\Post;
  9. use ApiPlatform\Metadata\Put;
  10. use App\Doctrine\Type\Expediting\ContainerSize;
  11. use App\Doctrine\Type\Expediting\ContainerType;
  12. use App\Dto\Expediting\ContainerSurveyInput;
  13. use App\Entity\Common as Common;
  14. use App\Entity\File\File;
  15. use App\Processor\Expediting\ContainerSurveyInputProcessor;
  16. use App\Validator\IsValidEnum\IsValidEnum;
  17. use Doctrine\Common\Collections\ArrayCollection;
  18. use Doctrine\Common\Collections\Collection;
  19. use Doctrine\DBAL\Types\Types;
  20. use Doctrine\ORM\Mapping as ORM;
  21. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  22. use Symfony\Component\Uid\Ulid;
  23. use Symfony\Component\Validator\Constraints as Assert;
  24. #[ORM\Table(name'expediting_container')]
  25. #[ORM\Index(columns: ['shipment_id'], name'expediting_container_shipment_id_idx')]
  26. #[ORM\Index(columns: ['created_by'], name'expediting_container_created_by_idx')]
  27. #[ORM\Index(columns: ['updated_by'], name'expediting_container_updated_by_idx')]
  28. #[ORM\UniqueConstraint(name'expediting_container_seal_number_key'columns: ['seal_number'])]
  29. #[ORM\UniqueConstraint(name'expediting_container_identifier_key'columns: ['identifier'])]
  30. #[UniqueEntity(fields: ['seal_number''identifier'])]
  31. #[ORM\Entity]
  32. #[ApiResource(
  33.     operations: [
  34.         new Get(),
  35.         new GetCollection(),
  36.         new Post(),
  37.         new Put(),
  38.         new Patch(),
  39.         new Delete(),
  40.         new Post(
  41.             uriTemplate'/containers/survey',
  42.             inputFormats: ['json' => ['application/json'], 'multipart' => ['multipart/form-data']],
  43.             inputContainerSurveyInput::class,
  44.             processorContainerSurveyInputProcessor::class
  45.         ),
  46.     ],
  47.     routePrefix'/expediting'
  48. )]
  49. class Container
  50. {
  51.     use Common\Blameable;
  52.     use Common\Trackable;
  53.     #[ORM\Id]
  54.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  55.     #[ORM\SequenceGenerator(sequenceName'expediting_container_id_seq')]
  56.     #[ORM\Column(typeTypes::INTEGER)]
  57.     private ?int $id null;
  58.     #[Assert\Ulid]
  59.     #[Assert\NotNull]
  60.     #[ORM\Column(type'ulid'uniquetrue)]
  61.     private ?Ulid $identifier null;
  62.     #[ORM\ManyToOne(targetEntityShipment::class, inversedBy'containers')]
  63.     #[ORM\JoinColumn(name'shipment_id')]
  64.     private ?Shipment $shipment null;
  65.     #[Assert\Type(typeTypes::STRING)]
  66.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  67.     private ?string $sealNumber null;
  68.     #[Assert\Type(typeTypes::STRING)]
  69.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  70.     private ?string $identificationNumber null;
  71.     #[IsValidEnum(enumContainerType::class)]
  72.     #[ORM\Column(typeTypes::STRINGenumTypeContainerType::class)]
  73.     private ?ContainerType $containerType null;
  74.     #[IsValidEnum(enumContainerSize::class)]
  75.     #[ORM\Column(typeTypes::STRINGenumTypeContainerSize::class)]
  76.     private ?ContainerSize $containerSize null;
  77.     /** @var Collection<int, Package> */
  78.     #[ORM\ManyToMany(targetEntityPackage::class, inversedBy'containers')]
  79.     #[ORM\JoinTable(name'expediting_container_package_map')]
  80.     #[ORM\JoinColumn(name'container_id')]
  81.     #[ORM\InverseJoinColumn(name'package_id')]
  82.     private Collection $packages;
  83.     /** @var Collection<int, File> */
  84.     #[ORM\ManyToMany(targetEntityFile::class, cascade: ['persist''remove'])]
  85.     #[ORM\JoinTable(name'expediting_container_file_map')]
  86.     #[ORM\JoinColumn(name'container_id')]
  87.     #[ORM\InverseJoinColumn(name'file_id')]
  88.     #[ORM\OrderBy(['id' => 'ASC'])]
  89.     private Collection $attachments;
  90.     public function __construct()
  91.     {
  92.         $this->identifier = new Ulid();
  93.         $this->packages = new ArrayCollection();
  94.         $this->attachments = new ArrayCollection();
  95.     }
  96.     public function getId(): ?int
  97.     {
  98.         return $this->id;
  99.     }
  100.     public function getIdentifier(): ?Ulid
  101.     {
  102.         return $this->identifier;
  103.     }
  104.     public function setIdentifier(Ulid $identifier): self
  105.     {
  106.         $this->identifier $identifier;
  107.         return $this;
  108.     }
  109.     public function getSealNumber(): ?string
  110.     {
  111.         return $this->sealNumber;
  112.     }
  113.     public function setSealNumber(?string $sealNumber): self
  114.     {
  115.         $this->sealNumber $sealNumber;
  116.         return $this;
  117.     }
  118.     public function getIdentificationNumber(): ?string
  119.     {
  120.         return $this->identificationNumber;
  121.     }
  122.     public function setIdentificationNumber(?string $identificationNumber): self
  123.     {
  124.         $this->identificationNumber $identificationNumber;
  125.         return $this;
  126.     }
  127.     public function getContainerType(): ?ContainerType
  128.     {
  129.         return $this->containerType;
  130.     }
  131.     public function setContainerType(?ContainerType $containerType): self
  132.     {
  133.         $this->containerType $containerType;
  134.         return $this;
  135.     }
  136.     public function getContainerSize(): ?ContainerSize
  137.     {
  138.         return $this->containerSize;
  139.     }
  140.     public function setContainerSize(?ContainerSize $containerSize): self
  141.     {
  142.         $this->containerSize $containerSize;
  143.         return $this;
  144.     }
  145.     public function getShipment(): ?Shipment
  146.     {
  147.         return $this->shipment;
  148.     }
  149.     public function setShipment(?Shipment $shipment): static
  150.     {
  151.         $this->shipment $shipment;
  152.         return $this;
  153.     }
  154.     /**
  155.      * @return Collection<int, Package>
  156.      */
  157.     public function getPackages(): Collection
  158.     {
  159.         return $this->packages;
  160.     }
  161.     public function addPackage(Package $package): self
  162.     {
  163.         if (!$this->packages->contains($package)) {
  164.             $this->packages->add($package);
  165.         }
  166.         return $this;
  167.     }
  168.     public function removePackage(Package $package): self
  169.     {
  170.         $this->packages->removeElement($package);
  171.         return $this;
  172.     }
  173.     /**
  174.      * @return Collection<int, File>
  175.      */
  176.     public function getAttachments(): Collection
  177.     {
  178.         return $this->attachments;
  179.     }
  180.     public function addAttachment(File $attachment): self
  181.     {
  182.         if (!$this->attachments->contains($attachment)) {
  183.             $this->attachments->add($attachment);
  184.         }
  185.         return $this;
  186.     }
  187.     public function removeAttachment(File $attachment): self
  188.     {
  189.         $this->attachments->removeElement($attachment);
  190.         return $this;
  191.     }
  192. }