src/Entity/DocUpload.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\DocUploadRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=DocUploadRepository::class)
  9.  */
  10. class DocUpload
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="datetime", nullable=true)
  20.      */
  21.     private $createdAt;
  22.     /**
  23.      * @ORM\Column(type="string", length=255)
  24.      */
  25.     private $name;
  26.     /**
  27.      * @ORM\Column(type="string", length=255)
  28.      */
  29.     private $path;
  30.     /**
  31.      * @ORM\Column(type="string", length=255, nullable=true)
  32.      */
  33.     private $token;
  34.     /**
  35.      * @ORM\Column(type="string", length=255, nullable=true)
  36.      */
  37.     private $nomenclature ;
  38.     /**
  39.      * @ORM\Column(type="string", length=255, nullable=true)
  40.      */
  41.     private $idDropbox ;
  42.     /**
  43.      * @ORM\Column(type="string", length=255, nullable=true)
  44.      */
  45.     private $pathDropbox ;
  46.     /**
  47.      * @ORM\ManyToOne(targetEntity="User", cascade={"persist"})
  48.      * @ORM\JoinColumn(name="user_created_id", referencedColumnName="id",nullable=true)
  49.      */
  50.     private $userCreated;
  51.     /**
  52.      * @ORM\Column(type="boolean", nullable=true)
  53.      */
  54.     private $isArchived;
  55.     /**
  56.      * @ORM\OneToMany(targetEntity="App\Entity\CommentDoc",mappedBy="docUpload", cascade={"persist"})
  57.      * @ORM\OrderBy({"createdAt" = "ASC"})
  58.      */
  59.     private $commentDoc;
  60.     /**
  61.      * @ORM\Column(type="string", length=255, nullable=true)
  62.      */
  63.     private $titreDoc;
  64.     public function __construct()
  65.     {
  66.         $this->createdAt = new \DateTime();
  67.         $this->token =  md5(uniqid());
  68.         $this->commentDoc = new ArrayCollection();
  69.     }
  70.     public function getId(): ?int
  71.     {
  72.         return $this->id;
  73.     }
  74.     public function getCreatedAt(): ?\DateTimeInterface
  75.     {
  76.         return $this->createdAt;
  77.     }
  78.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  79.     {
  80.         $this->createdAt = $createdAt;
  81.         return $this;
  82.     }
  83.     public function getName(): ?string
  84.     {
  85.         return $this->name;
  86.     }
  87.     public function setName(string $name): self
  88.     {
  89.         $this->name = $name;
  90.         return $this;
  91.     }
  92.     public function getPath(): ?string
  93.     {
  94.         return $this->path;
  95.     }
  96.     public function setPath(string $path): self
  97.     {
  98.         $this->path = $path;
  99.         return $this;
  100.     }
  101.     public function getToken(): ?string
  102.     {
  103.         return $this->token;
  104.     }
  105.     public function setToken(?string $token): self
  106.     {
  107.         $this->token = $token;
  108.         return $this;
  109.     }
  110.     public function getNomenclature(): ?string
  111.     {
  112.         return $this->nomenclature;
  113.     }
  114.     public function setNomenclature(string $nomenclature): self
  115.     {
  116.         $this->nomenclature = $nomenclature;
  117.         return $this;
  118.     }
  119.     public function getIdDropbox(): ?string
  120.     {
  121.         return $this->idDropbox;
  122.     }
  123.     public function setIdDropbox(?string $idDropbox): self
  124.     {
  125.         $this->idDropbox = $idDropbox;
  126.         return $this;
  127.     }
  128.     public function getPathDropbox(): ?string
  129.     {
  130.         return $this->pathDropbox;
  131.     }
  132.     public function setPathDropbox(?string $pathDropbox): self
  133.     {
  134.         $this->pathDropbox = $pathDropbox;
  135.         return $this;
  136.     }
  137.     public function getUserCreated(): ?User
  138.     {
  139.         return $this->userCreated;
  140.     }
  141.     public function setUserCreated(?User $userCreated): self
  142.     {
  143.         $this->userCreated = $userCreated;
  144.         return $this;
  145.     }
  146.     public function getIsArchived(): ?bool
  147.     {
  148.         return $this->isArchived;
  149.     }
  150.     public function setIsArchived(?bool $isArchived): self
  151.     {
  152.         $this->isArchived = $isArchived;
  153.         return $this;
  154.     }
  155.     /**
  156.      * @return Collection|CommentDoc[]
  157.      */
  158.     public function getCommentDoc(): Collection
  159.     {
  160.         return $this->commentDoc;
  161.     }
  162.     public function addCommentDoc(CommentDoc $commentDoc): self
  163.     {
  164.         if (!$this->commentDoc->contains($commentDoc)) {
  165.             $this->commentDoc[] = $commentDoc;
  166.             $commentDoc->setDocUpload($this);
  167.         }
  168.         return $this;
  169.     }
  170.     public function removeCommentDoc(CommentDoc $commentDoc): self
  171.     {
  172.         if ($this->commentDoc->removeElement($commentDoc)) {
  173.             // set the owning side to null (unless already changed)
  174.             if ($commentDoc->getDocUpload() === $this) {
  175.                 $commentDoc->setDocUpload(null);
  176.             }
  177.         }
  178.         return $this;
  179.     }
  180.     public function __clone() {
  181.         if ($this->id) {
  182.             $this->setCreatedAt(new \DateTime());
  183.             if($this->path){
  184.                 $filePath = $this->getUploadRootDir().$this->path;
  185.                 $token = md5(uniqid());
  186.                 $pathNew = $token.strrchr($this->path,'.');
  187.                 $fileCopy = $this->getUploadRootDir().$pathNew;
  188.                 if(file_exists($filePath)){
  189.                     copy($filePath , $fileCopy);
  190.                 }
  191.                 $this->setToken($token);
  192.                 $this->setPath($pathNew);
  193.                 $this->setIdDropbox('');
  194.                 $this->setNomenclature('');
  195.                 $this->setPathDropbox('');
  196.                 $commentDocArray = $this->getCommentDoc();
  197.                 $this->commentDoc = new ArrayCollection();
  198.                 if (!$commentDocArray->isEmpty()) {
  199.                     foreach ($commentDocArray as $item) {
  200.                         $val = clone $item;
  201.                         $this->addCommentDoc($val);
  202.                     }
  203.                 }
  204.             }
  205.         }
  206.     }
  207.     protected function getUploadRootDir()
  208.     {
  209.         return __DIR__.'/../../public/uploads/';
  210.     }
  211.     public function getTitreDoc(): ?string
  212.     {
  213.         return $this->titreDoc;
  214.     }
  215.     public function setTitreDoc(?string $titreDoc): self
  216.     {
  217.         $this->titreDoc = $titreDoc;
  218.         return $this;
  219.     }
  220. }