<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Clientdocument
*
* @ORM\Table(name="clientdocument", options={"collate"="latin1_general_ci","charset"="latin1"})
* @ORM\Entity(repositoryClass="App\Repository\ClientdocumentRepository")
*/
class Clientdocument {
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Client", cascade={"persist"})
* @ORM\JoinColumn(nullable=false)
*/
private $idclient;
/**
* @var integer
*
* @ORM\Column(name="date", type="integer", nullable=false)
*/
private $date;
/**
* @var \DateTime
*
* @ORM\Column(name="datefr", type="datetime", nullable=false)
*/
private $datefr;
/**
* @var string
*
* @ORM\Column(name="nom", type="string", length=150, nullable=false)
*/
private $nom;
/**
* @var UploadedFile|string
*
* @ORM\Column(name="fichier", type="string", length=150, nullable=false)
* @Assert\File(maxSize="6000000")
*/
private $fichier;
/**
* @var boolean
*
* @ORM\Column(name="clientall", type="boolean", nullable=false)
*/
private $clientall;
/**
* @var boolean
*
* @ORM\Column(name="etat", type="boolean", nullable=false)
*/
private $etat;
public function __construct() {
$this->etat = true;
$this->clientall = false;
$this->date = time();
$this->datefr = new \DateTime('now');
}
/**
* Get id
*
* @return integer
*/
public function getId() {
return $this->id;
}
/**
* Set date
*
* @param integer $date
* @return Clientdocument
*/
public function setDate($date) {
$this->date = $date;
return $this;
}
/**
* Get date
*
* @return integer
*/
public function getDate() {
return $this->date;
}
/**
* Set datefr
*
* @param \DateTime $datefr
* @return Clientdocument
*/
public function setDatefr($datefr) {
$this->datefr = $datefr;
return $this;
}
/**
* Get datefr
*
* @return \DateTime
*/
public function getDatefr() {
return $this->datefr;
}
/**
* Set nom
*
* @param string $nom
* @return Clientdocument
*/
public function setNom($nom) {
$this->nom = $nom;
return $this;
}
/**
* Get nom
*
* @return string
*/
public function getNom() {
return $this->nom;
}
/**
* Set fichier
*
* @param string $fichier
* @return Clientdocument
*/
public function setFichier($fichier) {
$this->fichier = $fichier;
return $this;
}
/**
* Get fichier
*
* @return string
*/
public function getFichier() {
return $this->fichier;
}
/**
* Set clientall
*
* @param boolean $clientall
* @return Clientdocument
*/
public function setClientall($clientall) {
$this->clientall = $clientall;
return $this;
}
/**
* Get clientall
*
* @return boolean
*/
public function getClientall() {
return $this->clientall;
}
/**
* Set etat
*
* @param boolean $etat
* @return Clientdocument
*/
public function setEtat($etat) {
$this->etat = $etat;
return $this;
}
/**
* Get etat
*
* @return boolean
*/
public function getEtat() {
return $this->etat;
}
/**
* Set idclient
*
* @param Client $idclient
* @return Clientdocument
*/
public function setIdclient(Client $idclient) {
$this->idclient = $idclient;
return $this;
}
/**
* Get idclient
*
* @return Client
*/
public function getIdclient() {
return $this->idclient;
}
protected function getUploadRootDir() {
// le chemin absolu du répertoire où les documents uploadés doivent être sauvegardés
return realpath(__DIR__ . '/../../') . '/public/' . $this->getUploadDir();
}
protected function getUploadDir() {
// on se débarrasse de « __DIR__ » afin de ne pas avoir de problème lorsqu'on affiche
// le document/image dans la vue.
return 'documents';
}
/**
* @var UploadedFile|string
*/
public function upload($id_client) {
if ($this->fichier instanceof UploadedFile) {
// Use the original file name and sanitize it for safety
$name = "C".$id_client."-".str_replace(" ", "_", $this->fichier->getClientOriginalName());
// Move the file to the desired directory
$this->fichier->move($this->getUploadRootDir(), $name);
// Update the fichier property with the new file name
$this->fichier = $name;
} else {
// Handle error if $this->fichier is not an instance of UploadedFile
throw new \Exception("Invalid file upload.");
}
}
}