src/Entity/PieceJustificative.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\PieceJustificativeRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use App\Entity\TimestampableTrait;
  9. /**
  10.  * @ORM\Entity(repositoryClass=PieceJustificativeRepository::class)
  11.  */
  12. class PieceJustificative
  13. {
  14.     use TimestampableTrait;
  15.     /**
  16.      * @ORM\Id
  17.      * @ORM\GeneratedValue
  18.      * @ORM\Column(type="integer")
  19.      */
  20.     private $id;
  21.     /**
  22.      * @ORM\OneToOne(targetEntity=Transporteur::class, mappedBy="pieceJustificative")
  23.      */
  24.     private $transporteur;
  25.     /**
  26.      * @ORM\OneToMany(targetEntity=Cin::class, mappedBy="pieceJustificative", orphanRemoval=true, cascade={"persist"})
  27.      */
  28.     private $cins;
  29.     /**
  30.      * @ORM\OneToMany(targetEntity=Justification::class, mappedBy="pieceJustificative", orphanRemoval=true, cascade={"persist"})
  31.      */
  32.     private $justifications;
  33.     /**
  34.      * @ORM\Column(type="text", nullable=true)
  35.      */
  36.     private $motifRefus;
  37.     public function __construct()
  38.     {
  39.         $this->cins = new ArrayCollection();
  40.         $this->justifications = new ArrayCollection();
  41.     }
  42.     public function getId(): ?int
  43.     {
  44.         return $this->id;
  45.     }
  46.     public function getTransporteur(): ?Transporteur
  47.     {
  48.         return $this->transporteur;
  49.     }
  50.     public function setTransporteur(?Transporteur $transporteur): self
  51.     {
  52.         // unset the owning side of the relation if necessary
  53.         if ($transporteur === null && $this->transporteur !== null) {
  54.             $this->transporteur->setPieceJustificative(null);
  55.         }
  56.         // set the owning side of the relation if necessary
  57.         if ($transporteur !== null && $transporteur->getPieceJustificative() !== $this) {
  58.             $transporteur->setPieceJustificative($this);
  59.         }
  60.         $this->transporteur $transporteur;
  61.         return $this;
  62.     }
  63.     /**
  64.      * @return Collection<int, Cin>
  65.      */
  66.     public function getCins(): Collection
  67.     {
  68.         return $this->cins;
  69.     }
  70.     public function addCin(Cin $cin): self
  71.     {
  72.         if (!$this->cins->contains($cin)) {
  73.             $this->cins[] = $cin;
  74.             $cin->setPieceJustificative($this);
  75.         }
  76.         return $this;
  77.     }
  78.     public function removeCin(Cin $cin): self
  79.     {
  80.         if ($this->cins->removeElement($cin)) {
  81.             // set the owning side to null (unless already changed)
  82.             if ($cin->getPieceJustificative() === $this) {
  83.                 $cin->setPieceJustificative(null);
  84.             }
  85.         }
  86.         return $this;
  87.     }
  88.     /**
  89.      * @return Collection<int, Justification>
  90.      */
  91.     public function getJustifications(): Collection
  92.     {
  93.         return $this->justifications;
  94.     }
  95.     public function addJustification(Justification $justification): self
  96.     {
  97.         if (!$this->justifications->contains($justification)) {
  98.             $this->justifications[] = $justification;
  99.             $justification->setPieceJustificative($this);
  100.         }
  101.         return $this;
  102.     }
  103.     public function removeJustification(Justification $justification): self
  104.     {
  105.         if ($this->justifications->removeElement($justification)) {
  106.             // set the owning side to null (unless already changed)
  107.             if ($justification->getPieceJustificative() === $this) {
  108.                 $justification->setPieceJustificative(null);
  109.             }
  110.         }
  111.         return $this;
  112.     }
  113.     public function getUploadCinDir()
  114.     {
  115.         return 'uploads/files/transporteur/cin';
  116.     }
  117.     public function getUploadJustificationDir()
  118.     {
  119.         return 'uploads/files/transporteur/justification';
  120.     }
  121.     
  122.     protected function getUploadCinRootDir()
  123.     {
  124.         return __DIR__.'/../../../../public/'.$this->getUploadCinDir();
  125.     }
  126.     protected function getUploadJustificationRootDir()
  127.     {
  128.         return __DIR__.'/../../../../public/'.$this->getUploadJustificationDir();
  129.     }
  130.     protected function removeCinThumb()
  131.     {
  132.         $tab = ['117x117''160x100''180x92''214x214''300x200','720x480','900x300''1033x276'];
  133.         foreach ($tab as $type) {
  134.             $url __DIR__.'/../../../../public/media/cache/'.$type.'/'.$this->getUploadCinDir().'/'.$this->cins;
  135.             if (file_exists($url)) {
  136.                 @unlink($url);
  137.             }
  138.         }
  139.     }
  140.     protected function removeJustificationThumb()
  141.     {
  142.         $tab = ['117x117''160x100''180x92''214x214''300x200','720x480','900x300''1033x276'];
  143.         foreach ($tab as $type) {
  144.             $url __DIR__.'/../../../../public/media/cache/'.$type.'/'.$this->getUploadJustificationDir().'/'.$this->justifications;
  145.             if (file_exists($url)) {
  146.                 @unlink($url);
  147.             }
  148.         }
  149.     }
  150.     public function getMotifRefus(): ?string
  151.     {
  152.         return $this->motifRefus;
  153.     }
  154.     public function setMotifRefus(?string $motifRefus): self
  155.     {
  156.         $this->motifRefus $motifRefus;
  157.         return $this;
  158.     }
  159. }