<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Fournisseurdocument
*
* @ORM\Table(name="fournisseurdocument", options={"collate"="latin1_general_ci","charset"="latin1"})
* @ORM\Entity
*/
class Fournisseurdocument {
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Fournisseur", cascade={"persist"})
* @ORM\JoinColumn(nullable=false)
*/
private $idfournisseur;
/**
* @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 Fournisseurdocument
*/
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 Fournisseurdocument
*/
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 Fournisseurdocument
*/
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 Fournisseurdocument
*/
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 Fournisseurdocument
*/
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 Fournisseurdocument
*/
public function setEtat($etat) {
$this->etat = $etat;
return $this;
}
/**
* Get etat
*
* @return boolean
*/
public function getEtat() {
return $this->etat;
}
/**
* @param Fournisseur $idfournisseur
* @return $this
*
*/
public function setIdfournisseur(Fournisseur $idfournisseur) {
$this->idfournisseur = $idfournisseur;
return $this;
}
/**
* Get idclient
*
* @return \App\Entity\Client
*/
public function getIdfournisseur() {
return $this->idfournisseur;
}
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';
}
public function upload($id_client) {
// Vérifie que $this->fichier est bien un objet UploadedFile
if ($this->fichier instanceof \Symfony\Component\HttpFoundation\File\UploadedFile) {
// Utiliser le nom de fichier original ici mais le nettoyer pour éviter les problèmes de sécurité
$name = "F" . $id_client . "-" . str_replace(" ", "_", $this->fichier->getClientOriginalName());
// Déplacer le fichier dans le répertoire de destination
$this->fichier->move($this->getUploadRootDir(), $name);
// Mettre à jour la propriété fichier avec le nom du fichier déplacé
$this->fichier = $name;
} else {
// Si ce n'est pas un fichier valide, lance une exception
throw new \Exception("Le fichier n'est pas valide.");
}
}
}