src/Entity/Expediting/Container.php line 52
<?php
namespace App\Entity\Expediting;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use App\Doctrine\Type\Expediting\ContainerSize;
use App\Doctrine\Type\Expediting\ContainerType;
use App\Dto\Expediting\ContainerSurveyInput;
use App\Entity\Common as Common;
use App\Entity\File\File;
use App\Processor\Expediting\ContainerSurveyInputProcessor;
use App\Validator\IsValidEnum\IsValidEnum;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Uid\Ulid;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Table(name: 'expediting_container')]
#[ORM\Index(columns: ['shipment_id'], name: 'expediting_container_shipment_id_idx')]
#[ORM\Index(columns: ['created_by'], name: 'expediting_container_created_by_idx')]
#[ORM\Index(columns: ['updated_by'], name: 'expediting_container_updated_by_idx')]
#[ORM\UniqueConstraint(name: 'expediting_container_seal_number_key', columns: ['seal_number'])]
#[ORM\UniqueConstraint(name: 'expediting_container_identifier_key', columns: ['identifier'])]
#[UniqueEntity(fields: ['seal_number', 'identifier'])]
#[ORM\Entity]
#[ApiResource(
operations: [
new Get(),
new GetCollection(),
new Post(),
new Put(),
new Patch(),
new Delete(),
new Post(
uriTemplate: '/containers/survey',
inputFormats: ['json' => ['application/json'], 'multipart' => ['multipart/form-data']],
input: ContainerSurveyInput::class,
processor: ContainerSurveyInputProcessor::class
),
],
routePrefix: '/expediting'
)]
class Container
{
use Common\Blameable;
use Common\Trackable;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
#[ORM\SequenceGenerator(sequenceName: 'expediting_container_id_seq')]
#[ORM\Column(type: Types::INTEGER)]
private ?int $id = null;
#[Assert\Ulid]
#[Assert\NotNull]
#[ORM\Column(type: 'ulid', unique: true)]
private ?Ulid $identifier = null;
#[ORM\ManyToOne(targetEntity: Shipment::class, inversedBy: 'containers')]
#[ORM\JoinColumn(name: 'shipment_id')]
private ?Shipment $shipment = null;
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, nullable: true)]
private ?string $sealNumber = null;
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, nullable: true)]
private ?string $identificationNumber = null;
#[IsValidEnum(enum: ContainerType::class)]
#[ORM\Column(type: Types::STRING, enumType: ContainerType::class)]
private ?ContainerType $containerType = null;
#[IsValidEnum(enum: ContainerSize::class)]
#[ORM\Column(type: Types::STRING, enumType: ContainerSize::class)]
private ?ContainerSize $containerSize = null;
/** @var Collection<int, Package> */
#[ORM\ManyToMany(targetEntity: Package::class, inversedBy: 'containers')]
#[ORM\JoinTable(name: 'expediting_container_package_map')]
#[ORM\JoinColumn(name: 'container_id')]
#[ORM\InverseJoinColumn(name: 'package_id')]
private Collection $packages;
/** @var Collection<int, File> */
#[ORM\ManyToMany(targetEntity: File::class, cascade: ['persist', 'remove'])]
#[ORM\JoinTable(name: 'expediting_container_file_map')]
#[ORM\JoinColumn(name: 'container_id')]
#[ORM\InverseJoinColumn(name: 'file_id')]
#[ORM\OrderBy(['id' => 'ASC'])]
private Collection $attachments;
public function __construct()
{
$this->identifier = new Ulid();
$this->packages = new ArrayCollection();
$this->attachments = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getIdentifier(): ?Ulid
{
return $this->identifier;
}
public function setIdentifier(Ulid $identifier): self
{
$this->identifier = $identifier;
return $this;
}
public function getSealNumber(): ?string
{
return $this->sealNumber;
}
public function setSealNumber(?string $sealNumber): self
{
$this->sealNumber = $sealNumber;
return $this;
}
public function getIdentificationNumber(): ?string
{
return $this->identificationNumber;
}
public function setIdentificationNumber(?string $identificationNumber): self
{
$this->identificationNumber = $identificationNumber;
return $this;
}
public function getContainerType(): ?ContainerType
{
return $this->containerType;
}
public function setContainerType(?ContainerType $containerType): self
{
$this->containerType = $containerType;
return $this;
}
public function getContainerSize(): ?ContainerSize
{
return $this->containerSize;
}
public function setContainerSize(?ContainerSize $containerSize): self
{
$this->containerSize = $containerSize;
return $this;
}
public function getShipment(): ?Shipment
{
return $this->shipment;
}
public function setShipment(?Shipment $shipment): static
{
$this->shipment = $shipment;
return $this;
}
/**
* @return Collection<int, Package>
*/
public function getPackages(): Collection
{
return $this->packages;
}
public function addPackage(Package $package): self
{
if (!$this->packages->contains($package)) {
$this->packages->add($package);
}
return $this;
}
public function removePackage(Package $package): self
{
$this->packages->removeElement($package);
return $this;
}
/**
* @return Collection<int, File>
*/
public function getAttachments(): Collection
{
return $this->attachments;
}
public function addAttachment(File $attachment): self
{
if (!$this->attachments->contains($attachment)) {
$this->attachments->add($attachment);
}
return $this;
}
public function removeAttachment(File $attachment): self
{
$this->attachments->removeElement($attachment);
return $this;
}
}