src/Entity/File/Parsable.php line 54
<?php
namespace App\Entity\File;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Post;
use ApiPlatform\OpenApi\Model;
use App\Controller\Purchasing\PurchaseOrderDatasheetUploadAction;
use App\Doctrine\Type\File\ParsableStatus;
use App\Doctrine\Type\File\ParsableType;
use App\Dto\Expediting\FreightDatasheetInput;
use App\Entity\Purchasing\Order;
use App\Entity\Sales\WorkOrder;
use App\Validator\IsValidEnum\IsValidEnum;
use ArrayObject;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
#[ORM\Entity]
#[Vich\Uploadable]
#[ApiResource(
// FIXME : This does not work well with docker
uriTemplate: '/purchasing/orders/import',
operations: [
new Post(
controller: PurchaseOrderDatasheetUploadAction::class,
openapi: new Model\Operation(
requestBody: new Model\RequestBody(
content: new ArrayObject([
'multipart/form-data' => [
'schema' => [
'type' => 'object',
'properties' => [
'file' => [
'type' => 'string',
'format' => 'binary'
]
]
]
]
])
)
),
shortName: 'Upload',
validationContext: ['groups' => ['Default', 'upload:create']],
deserialize: false,
),
],
)]
class Parsable extends File
{
use Archivable;
#[Assert\Type(type: FreightDatasheetInput::class)]
#[ORM\Column(type: 'json_document', options: ['jsonb' => true])]
private ?FreightDatasheetInput $data = null;
#[ORM\Column(type: Types::JSON, nullable: true, options: ['jsonb' => true])]
private ?array $errors = [];
#[Assert\NotNull]
#[IsValidEnum(enum: ParsableType::class)]
#[ORM\Column(name: 'parsable_type', type: Types::STRING, nullable: false, enumType: ParsableType::class)]
private ?ParsableType $type = null;
#[Assert\NotNull]
#[IsValidEnum(enum: ParsableStatus::class)]
#[ORM\Column(name: 'parsable_status', type: Types::STRING, nullable: true, enumType: ParsableStatus::class)]
private ?ParsableStatus $status = ParsableStatus::UPLOADED;
#[ORM\OneToOne(mappedBy: 'source', targetEntity: WorkOrder::class)]
private ?WorkOrder $workOrder = null;
/** @var Collection<int, Order> $orders */
#[ORM\OneToMany(mappedBy: 'source', targetEntity: Order::class)]
private Collection $orders;
public function __construct()
{
$this->orders = new ArrayCollection();
}
public function getData(): ?FreightDatasheetInput
{
return $this->data;
}
public function setData(?FreightDatasheetInput $data): self
{
$this->data = $data;
return $this;
}
public function getErrors(): array
{
return $this->errors;
}
public function setErrors(?array $errors): self
{
$this->errors = $errors;
return $this;
}
public function getType(): ?ParsableType
{
return $this->type;
}
public function setType(ParsableType $type): self
{
$this->type = $type;
return $this;
}
public function getStatus(): ?ParsableStatus
{
return $this->status;
}
public function setStatus(?ParsableStatus $status): self
{
$this->status = $status;
return $this;
}
public function getWorkOrder(): ?WorkOrder
{
return $this->workOrder;
}
public function setWorkOrder(?WorkOrder $workOrder): self
{
$this->workOrder = $workOrder;
return $this;
}
/**
* @return Collection<int, Order>
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Order $order): self
{
if (!$this->orders->contains($order)) {
$this->orders->add($order);
$order->setSource($this);
}
return $this;
}
public function removeOrder(Order $order): self
{
if ($this->orders->removeElement($order)) {
// set the owning side to null (unless already changed)
if ($order->getSource() === $this) {
$order->setSource(null);
}
}
return $this;
}
}