<?php
namespace App\Entity\RevueManagement;
use App\Entity\LovManagement\NumeroStatus;
use App\Entity\RapportManagement\Rapport;
use App\Entity\SearchManagement\Indexation;
use App\Repository\RevueManagement\Numero2Repository;
use App\Traits\ActorTrait;
use App\Traits\DateTrait;
use App\Traits\IsDeletedTrait;
use App\Traits\IsValidTrait;
use Datetime;
use DatetimeInterface;
use DH\DoctrineAuditBundle\Annotation as Audit;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\MaxDepth;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass=Numero2Repository::class)
* @ORM\HasLifecycleCallbacks()
* @Audit\Auditable
* @Audit\Security(view={"ROLE_AUDIT"})
* @Vich\Uploadable
*/
class Numero2
{
use ActorTrait;
use DateTrait;
use IsValidTrait;
use IsDeletedTrait;
public const SUBMITTED = "submitted";
public const REJECTED = "rejected";
public const REPORTED = "reported";
public const CONTROLLED = "controlled";
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"detail", "list"})
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Groups({"detail", "list"})
*/
private $title;
/**
* @ORM\Column(type="string", length=255)
* @Groups({"detail", "list"})
*/
private $numero;
/**
* @ORM\Column(type="datetime")
* @Groups({"detail", "list"})
*/
private $receiptDate;
/**
* @ORM\ManyToOne(targetEntity=Revue::class, inversedBy="numeros")
* @ORM\JoinColumn(nullable=false)
*/
private $revue;
/**
* @Vich\UploadableField(mapping="uploads_file_revue", fileNameProperty="fileUri")
*
* @var File
*/
protected $file;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"detail", "list"})
*/
private $fileUri;
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"detail", "list"})
*/
private $isImage = false;
/**
* @ORM\OneToMany(targetEntity=Image::class, mappedBy="numero", fetch="LAZY", cascade={"persist"}, orphanRemoval=true)
* @ORM\JoinColumn(onDelete="CASCADE")
* @ORM\OrderBy({"numeroPage" = "ASC"})
* @Groups({"detail", "list"})
* @MaxDepth(2)
*/
private $images;
protected $imagesZip;
/**
* @ORM\Column(type="string", length=255, options={"default": "submitted"})
*/
private $state = 'submitted';
/**
* @ORM\OneToMany(targetEntity=Rapport::class, mappedBy="numero", fetch="LAZY", cascade={"persist"}, orphanRemoval=true)
* @ORM\JoinColumn(onDelete="CASCADE")
*/
private $rapports;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $description;
/**
* @ORM\ManyToOne(targetEntity=NumeroStatus::class)
* @ORM\JoinColumn(nullable=false)
*/
private $numeroStatus;
/**
* @ORM\OneToMany(targetEntity=Numero2History::class, mappedBy="numero2", orphanRemoval=true)
* @ORM\OrderBy({"createDate" = "ASC"})
*/
private $numero2Historys;
public function __construct()
{
$this->images = new ArrayCollection();
$this->rapports = new ArrayCollection();
$this->numero2Historys = new ArrayCollection();
}
public function __toString(): string
{
return (string) $this->getTitle();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getNumero(): ?string
{
return $this->numero;
}
public function setNumero(string $numero): self
{
$this->numero = $numero;
return $this;
}
public function getReceiptDate(): ?DatetimeInterface
{
return $this->receiptDate;
}
public function setReceiptDate(DatetimeInterface $receiptDate): self
{
$this->receiptDate = $receiptDate;
return $this;
}
public function getRevue(): ?Revue
{
return $this->revue;
}
public function setRevue(?Revue $revue): self
{
$this->revue = $revue;
return $this;
}
public function getFileUri(): ?string
{
return $this->fileUri;
}
public function setFileUri(?string $fileUri): self
{
$this->fileUri = $fileUri;
return $this;
}
public function getFile(): ?File
{
return $this->file;
}
public function setFile(File $file = null): self
{
$this->file = $file;
return $this;
}
public function getIsImage(): ?bool
{
return $this->isImage;
}
public function setIsImage(?bool $isImage): self
{
$this->isImage = $isImage;
return $this;
}
public function isImage(): bool
{
return $this->getIsImage();
}
public function isPdf(): bool
{
return !$this->getIsImage();
}
public function getIsPdf(): ?bool
{
return $this->isPdf();
}
/**
* @return Collection|Image[]
*/
public function getImages(): Collection
{
return $this->images;
}
public function addImage(Image $image): self
{
if (!$this->images->contains($image)) {
$this->images[] = $image;
$image->setNumero($this);
}
return $this;
}
public function removeImage(Image $image): self
{
if ($this->images->removeElement($image)) {
// set the owning side to null (unless already changed)
if ($image->getNumero() === $this) {
$image->setNumero(null);
}
}
return $this;
}
public function getImagesZip()
{
return $this->imagesZip;
}
public function setImagesZip(File $imagesZip = null)
{
$this->imagesZip = $imagesZip;
}
public function getState(): ?string
{
return $this->state;
}
public function setState(string $state): self
{
$this->state = $state;
return $this;
}
/**
* @return Collection|Rapport[]
*/
public function getRapports(): Collection
{
return $this->rapports;
}
public function addRapport(Rapport $rapport): self
{
if (!$this->rapports->contains($rapport)) {
$this->rapports[] = $rapport;
$rapport->setNumero($this);
}
return $this;
}
public function removeRapport(Rapport $rapport): self
{
if ($this->rapports->removeElement($rapport)) {
// set the owning side to null (unless already changed)
if ($rapport->getNumero() === $this) {
$rapport->setNumero(null);
}
}
return $this;
}
public function hasRapport(): ?Rapport
{
foreach ($this->rapports as $rapport) {
return $rapport;
}
return null;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getNumeroStatus(): ?NumeroStatus
{
return $this->numeroStatus;
}
public function setNumeroStatus(?NumeroStatus $numeroStatus): self
{
$this->numeroStatus = $numeroStatus;
return $this;
}
/**
* @return Collection<int, NumeroHistory>
*/
public function getNumero2Historys(): Collection
{
return $this->numero2Historys;
}
public function addNumero2History(Numero2History $numeroHistory): self
{
if (!$this->numero2Historys->contains($numeroHistory)) {
$this->numero2Historys[] = $numeroHistory;
$numeroHistory->setNumero2($this);
}
return $this;
}
public function removeNumero2History(Numero2History $numeroHistory): self
{
if ($this->numero2Historys->removeElement($numeroHistory)) {
// set the owning side to null (unless already changed)
if ($numeroHistory->getNumero2() === $this) {
$numeroHistory->setNumero2(null);
}
}
return $this;
}
public Numero2History $lastNumero2History;
// get last NumeroHistory
public function getLastNumero2History(): ?Numero2History
{
if ($this->getNumero2Historys()->count() > 0) {
return $this->getNumero2Historys()->last();
}
return null;
}
public function getCreateDate(): ?Datetime
{
return $this->createDate;
}
public function getCreateUser()
{
return $this->createUser;
}
public function getPDFpath(): ?string
{
return $this->getLastNumero2History()->getId() . ".pdf";
}
}