<?php
namespace App\Entity;
use App\Repository\DocUploadRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=DocUploadRepository::class)
*/
class DocUpload
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $createdAt;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="string", length=255)
*/
private $path;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $token;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $nomenclature ;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $idDropbox ;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $pathDropbox ;
/**
* @ORM\ManyToOne(targetEntity="User", cascade={"persist"})
* @ORM\JoinColumn(name="user_created_id", referencedColumnName="id",nullable=true)
*/
private $userCreated;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isArchived;
/**
* @ORM\OneToMany(targetEntity="App\Entity\CommentDoc",mappedBy="docUpload", cascade={"persist"})
* @ORM\OrderBy({"createdAt" = "ASC"})
*/
private $commentDoc;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $titreDoc;
public function __construct()
{
$this->createdAt = new \DateTime();
$this->token = md5(uniqid());
$this->commentDoc = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getPath(): ?string
{
return $this->path;
}
public function setPath(string $path): self
{
$this->path = $path;
return $this;
}
public function getToken(): ?string
{
return $this->token;
}
public function setToken(?string $token): self
{
$this->token = $token;
return $this;
}
public function getNomenclature(): ?string
{
return $this->nomenclature;
}
public function setNomenclature(string $nomenclature): self
{
$this->nomenclature = $nomenclature;
return $this;
}
public function getIdDropbox(): ?string
{
return $this->idDropbox;
}
public function setIdDropbox(?string $idDropbox): self
{
$this->idDropbox = $idDropbox;
return $this;
}
public function getPathDropbox(): ?string
{
return $this->pathDropbox;
}
public function setPathDropbox(?string $pathDropbox): self
{
$this->pathDropbox = $pathDropbox;
return $this;
}
public function getUserCreated(): ?User
{
return $this->userCreated;
}
public function setUserCreated(?User $userCreated): self
{
$this->userCreated = $userCreated;
return $this;
}
public function getIsArchived(): ?bool
{
return $this->isArchived;
}
public function setIsArchived(?bool $isArchived): self
{
$this->isArchived = $isArchived;
return $this;
}
/**
* @return Collection|CommentDoc[]
*/
public function getCommentDoc(): Collection
{
return $this->commentDoc;
}
public function addCommentDoc(CommentDoc $commentDoc): self
{
if (!$this->commentDoc->contains($commentDoc)) {
$this->commentDoc[] = $commentDoc;
$commentDoc->setDocUpload($this);
}
return $this;
}
public function removeCommentDoc(CommentDoc $commentDoc): self
{
if ($this->commentDoc->removeElement($commentDoc)) {
// set the owning side to null (unless already changed)
if ($commentDoc->getDocUpload() === $this) {
$commentDoc->setDocUpload(null);
}
}
return $this;
}
public function __clone() {
if ($this->id) {
$this->setCreatedAt(new \DateTime());
if($this->path){
$filePath = $this->getUploadRootDir().$this->path;
$token = md5(uniqid());
$pathNew = $token.strrchr($this->path,'.');
$fileCopy = $this->getUploadRootDir().$pathNew;
if(file_exists($filePath)){
copy($filePath , $fileCopy);
}
$this->setToken($token);
$this->setPath($pathNew);
$this->setIdDropbox('');
$this->setNomenclature('');
$this->setPathDropbox('');
$commentDocArray = $this->getCommentDoc();
$this->commentDoc = new ArrayCollection();
if (!$commentDocArray->isEmpty()) {
foreach ($commentDocArray as $item) {
$val = clone $item;
$this->addCommentDoc($val);
}
}
}
}
}
protected function getUploadRootDir()
{
return __DIR__.'/../../public/uploads/';
}
public function getTitreDoc(): ?string
{
return $this->titreDoc;
}
public function setTitreDoc(?string $titreDoc): self
{
$this->titreDoc = $titreDoc;
return $this;
}
}