<?php
namespace App\Entity;
use App\Repository\PieceJustificativeRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use App\Entity\TimestampableTrait;
/**
* @ORM\Entity(repositoryClass=PieceJustificativeRepository::class)
*/
class PieceJustificative
{
use TimestampableTrait;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\OneToOne(targetEntity=Transporteur::class, mappedBy="pieceJustificative")
*/
private $transporteur;
/**
* @ORM\OneToMany(targetEntity=Cin::class, mappedBy="pieceJustificative", orphanRemoval=true, cascade={"persist"})
*/
private $cins;
/**
* @ORM\OneToMany(targetEntity=Justification::class, mappedBy="pieceJustificative", orphanRemoval=true, cascade={"persist"})
*/
private $justifications;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $motifRefus;
public function __construct()
{
$this->cins = new ArrayCollection();
$this->justifications = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTransporteur(): ?Transporteur
{
return $this->transporteur;
}
public function setTransporteur(?Transporteur $transporteur): self
{
// unset the owning side of the relation if necessary
if ($transporteur === null && $this->transporteur !== null) {
$this->transporteur->setPieceJustificative(null);
}
// set the owning side of the relation if necessary
if ($transporteur !== null && $transporteur->getPieceJustificative() !== $this) {
$transporteur->setPieceJustificative($this);
}
$this->transporteur = $transporteur;
return $this;
}
/**
* @return Collection<int, Cin>
*/
public function getCins(): Collection
{
return $this->cins;
}
public function addCin(Cin $cin): self
{
if (!$this->cins->contains($cin)) {
$this->cins[] = $cin;
$cin->setPieceJustificative($this);
}
return $this;
}
public function removeCin(Cin $cin): self
{
if ($this->cins->removeElement($cin)) {
// set the owning side to null (unless already changed)
if ($cin->getPieceJustificative() === $this) {
$cin->setPieceJustificative(null);
}
}
return $this;
}
/**
* @return Collection<int, Justification>
*/
public function getJustifications(): Collection
{
return $this->justifications;
}
public function addJustification(Justification $justification): self
{
if (!$this->justifications->contains($justification)) {
$this->justifications[] = $justification;
$justification->setPieceJustificative($this);
}
return $this;
}
public function removeJustification(Justification $justification): self
{
if ($this->justifications->removeElement($justification)) {
// set the owning side to null (unless already changed)
if ($justification->getPieceJustificative() === $this) {
$justification->setPieceJustificative(null);
}
}
return $this;
}
public function getUploadCinDir()
{
return 'uploads/files/transporteur/cin';
}
public function getUploadJustificationDir()
{
return 'uploads/files/transporteur/justification';
}
protected function getUploadCinRootDir()
{
return __DIR__.'/../../../../public/'.$this->getUploadCinDir();
}
protected function getUploadJustificationRootDir()
{
return __DIR__.'/../../../../public/'.$this->getUploadJustificationDir();
}
protected function removeCinThumb()
{
$tab = ['117x117', '160x100', '180x92', '214x214', '300x200','720x480','900x300', '1033x276'];
foreach ($tab as $type) {
$url = __DIR__.'/../../../../public/media/cache/'.$type.'/'.$this->getUploadCinDir().'/'.$this->cins;
if (file_exists($url)) {
@unlink($url);
}
}
}
protected function removeJustificationThumb()
{
$tab = ['117x117', '160x100', '180x92', '214x214', '300x200','720x480','900x300', '1033x276'];
foreach ($tab as $type) {
$url = __DIR__.'/../../../../public/media/cache/'.$type.'/'.$this->getUploadJustificationDir().'/'.$this->justifications;
if (file_exists($url)) {
@unlink($url);
}
}
}
public function getMotifRefus(): ?string
{
return $this->motifRefus;
}
public function setMotifRefus(?string $motifRefus): self
{
$this->motifRefus = $motifRefus;
return $this;
}
}