<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Validator\Constraints as Assert;
/**
* FournisseurClientdocument
*
* @ORM\Table(name="founisseurclientdocument", options={"collate"="latin1_general_ci","charset"="latin1"})
* @ORM\Entity(repositoryClass="App\Repository\FournisseurClientdocumentRepository")
*/
class FournisseurClientdocument
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Clientrelation",inversedBy="documents", cascade={"persist"})
* @ORM\JoinColumn(nullable=false)
*/
private $idrelation;
/**
* @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 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 FournisseurClientdocument
*/
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 FournisseurClientdocument
*/
public function setDatefr($datefr)
{
$this->datefr = $datefr;
return $this;
}
/**
* Get datefr
*
* @return \DateTime
*/
public function getDatefr()
{
return $this->datefr;
}
/**
* @param string $nom
* @return $this
*/
public function setNom($nom)
{
$this->nom = $nom;
return $this;
}
/**
* Get nom
*
* @return string
*/
public function getNom()
{
return $this->nom;
}
/**
* @param mixed $fichier
*/
public function setFichier($fichier)
{
if ($fichier instanceof UploadedFile) {
$this->fichier = $fichier;
} else {
throw new \InvalidArgumentException('Expected instance of UploadedFile');
}
return $this;
}
/**
* Get fichier
*
* @return string
*/
public function getFichier()
{
return $this->fichier;
}
/**
* @param mixed $clientall
* @return $this
*/
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 FournisseurClientdocument
*/
public function setEtat($etat)
{
$this->etat = $etat;
return $this;
}
/**
* Get etat
*
* @return boolean
*/
public function getEtat()
{
return $this->etat;
}
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) {
$name = "C" . $id_client . "-" . str_replace(" ", "_", $this->fichier->getClientOriginalName());
$this->fichier->move($this->getUploadRootDir(), $name);
// Define the new file path
$this->fichier = $name;
} else {
// Handle the case where $this->fichier is not an UploadedFile instance
throw new \Exception('Fichier must be an instance of UploadedFile');
}
}
/**
* @return mixed
*/
public function getIdrelation()
{
return $this->idrelation;
}
/**
* @param mixed $idrelation
*/
public function setIdrelation($idrelation): void
{
$this->idrelation = $idrelation;
}
}