<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use App\Controller\Action\UploadDataTmpFileAction;
use App\Repository\DataTmpRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\PreUpdate;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\HttpFoundation\File\File;
#[ORM\Entity(repositoryClass: DataTmpRepository::class)]
#[ApiResource(
operations: [
new Get(),
new Post(
controller: UploadDataTmpFileAction::class,
deserialize: false,
uriTemplate: '/data_tmps/upload',
openapiContext: [
'requestBody' => [
'content' => [
'multipart/form-data' => [
'schema' => [
'type' => 'object',
'properties' => [
'site'=> [
'type' => 'string',
'format' => 'int'
],
'type'=> [
'type' => 'string',
'format' => 'string'
],
'file' => [
'type' => 'string',
'format' => 'binary'
]
]
]
]
]
]
]
)
]
)]
#[ORM\HasLifecycleCallbacks]
class DataTmp
{
const PENDING_STATUS = 'pending';
const COMPLETE_STATUS = 'complete';
const DOCUMENT_TYPE = 'document';
const EVALUATION_TYPE = 'evaluation';
const COMPLIANCE_TYPE = 'compliance';
const SYNTHESE_TYPE = 'synthese';
const DOCUMENT_OFFICILE_TYPE = 'document_officile';
#[ORM\Column(name: 'id', type: 'bigint', nullable: false)]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
private int $id;
#[Vich\UploadableField(mapping: "datatmp", fileNameProperty: "path")]
public ?File $fileObject = null;
#[ORM\Column(type: Types::BIGINT, nullable: true)]
private ?string $siteId = null;
#[ORM\Column(type: 'text', nullable: true)]
private ?string $path = null;
#[ORM\Column(type: 'text', nullable: true)]
private ?string $parent = null;
#[ORM\Column(type: 'text', nullable: true)]
private ?string $file = null;
#[ORM\Column(length: 200, nullable: true)]
private ?string $type = null;
#[ORM\Column(length: 50, nullable: true)]
private ?string $status = self::PENDING_STATUS;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $startTime = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $endTime = null;
public function getId(): int
{
return $this->id;
}
public function getSiteId(): ?string
{
return $this->siteId;
}
public function setSiteId(?string $siteId): self
{
$this->siteId = $siteId;
return $this;
}
public function getPath(): ?string
{
return $this->path;
}
public function setPath(?string $path): self
{
$this->path = $path;
return $this;
}
public function getParent(): ?string
{
return $this->parent;
}
public function setParent(?string $parent): self
{
$this->parent = $parent;
return $this;
}
public function getFile(): ?string
{
return $this->file;
}
public function setFile(?string $file): self
{
$this->file = $file;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(?string $type): self
{
$this->type = $type;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(?string $status): self
{
$this->status = $status;
return $this;
}
public function getStartTime(): ?\DateTimeInterface
{
return $this->startTime;
}
public function setStartTime(?\DateTimeInterface $startTime): self
{
$this->startTime = $startTime;
return $this;
}
public function getEndTime(): ?\DateTimeInterface
{
return $this->endTime;
}
public function setEndTime(?\DateTimeInterface $endTime): self
{
$this->endTime = $endTime;
return $this;
}
#[PreUpdate]
public function updateUpdatedAt()
{
$this->startTime = new \DateTime('now');
$this->endTime = new \DateTime('now');
}
}