src/Entity/File/Upload.php line 89
<?php
namespace App\Entity\File;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Link;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Put;
use App\Doctrine\Type\File\UploadableStatus;
use App\Doctrine\Type\File\UploadableType;
use App\Doctrine\Type\SelectableType;
use App\Entity\Common\Company;
use App\Entity\Expediting\Container;
use App\Entity\Expediting\Freight;
use App\Entity\Expediting\Package;
use App\Entity\Expediting\Shipment;
use App\Entity\Sales\Contract;
use App\Entity\Sales\WorkOrder;
use App\Processor\Files\UploadDeleteProcessor;
use App\Validator\IsValidEnum\IsValidEnum;
use App\Validator\IsValidEnumArray\IsValidEnumArray;
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(
operations: [
new Get(),
new Delete(processor: UploadDeleteProcessor::class),
new Patch(),
new Put(),
],
)]
#[ApiResource(
uriTemplate: '/companies/{slug}/attachments',
operations: [new GetCollection()],
uriVariables: [
'slug' => new Link(fromProperty: 'attachments', fromClass: Company::class),
],
)]
#[ApiResource(
uriTemplate: '/sales/contracts/{slug}/attachments',
operations: [new GetCollection()],
uriVariables: [
'slug' => new Link(fromProperty: 'attachments', fromClass: Contract::class),
],
)]
#[ApiResource(
uriTemplate: '/work_orders/{slug}/attachments',
operations: [new GetCollection()],
uriVariables: [
'slug' => new Link(fromProperty: 'attachments', fromClass: WorkOrder::class),
],
)]
#[ApiResource(
uriTemplate: '/expediting/freights/{slug}/attachments',
operations: [new GetCollection()],
uriVariables: [
'slug' => new Link(fromProperty: 'attachments', fromClass: Freight::class),
],
)]
#[ApiResource(
uriTemplate: '/expediting/shipments/{slug}/attachments',
operations: [new GetCollection()],
uriVariables: [
'slug' => new Link(fromProperty: 'attachments', fromClass: Shipment::class),
],
)]
#[ApiResource(
uriTemplate: '/expediting/containers/{id}/attachments',
operations: [new GetCollection()],
uriVariables: [
'id' => new Link(fromProperty: 'attachments', fromClass: Container::class),
],
)]
#[ApiResource(
uriTemplate: '/expediting/packages/{slug}/attachments',
operations: [new GetCollection()],
uriVariables: [
'slug' => new Link(fromProperty: 'attachments', fromClass: Package::class),
],
)]
class Upload extends File
{
use Archivable;
/** @var UploadableType[] $types */
#[Assert\Count(min: 1)]
#[IsValidEnumArray(enum: UploadableType::class)]
#[ORM\Column(name: 'uploadable_types', type: SelectableType::NAME, nullable: true, enumType: UploadableType::class)]
private array $types = [];
#[Assert\NotNull]
#[IsValidEnum(enum: UploadableStatus::class)]
#[ORM\Column(name: 'uploadable_status', type: Types::STRING, nullable: true, enumType: UploadableStatus::class)]
private ?UploadableStatus $status = UploadableStatus::PUBLISHED;
public function getTypes(): array
{
return $this->types;
}
public function addType(UploadableType $type): static
{
if (!in_array($type, $this->types)) {
$this->types []= $type;
}
return $this;
}
public function setTypes($types): self
{
$this->types = $types;
return $this;
}
public function removeType(UploadableType $type): static
{
$key = array_search($type, $this->types, true);
if ($key !== false) {
unset($this->types[$key]);
}
return $this;
}
public function getStatus(): ?UploadableStatus
{
return $this->status;
}
public function setStatus(?UploadableStatus $status): self
{
$this->status = $status;
return $this;
}
}