<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Adminmailing
*
* @ORM\Table(name="adminmailing", options={"collate"="latin1_general_ci","charset"="latin1"})
* @ORM\Entity(repositoryClass="App\Repository\AdminmailingRepository")
*/
class Adminmailing {
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var \DateTime
*
* @ORM\Column(name="datefr", type="datetime", nullable=false)
*/
private $datefr;
/**
* @var string
*
* @ORM\Column(name="titre", type="string", length=250, nullable=false)
*/
private $titre;
/**
* @var string
*
* @ORM\Column(name="type", type="string", length=50, nullable=false)
*/
private $type;
/**
* @var string
*
* @ORM\Column(name="destinataires", type="text", nullable=false)
*/
private $destinataires;
/**
* @var UploadedFile
*
* @ORM\Column(name="document", type="string", length=250, nullable=true)
* @Assert\File(maxSize="6000000")
*/
private $document;
/**
* @var string
*
* @ORM\Column(name="description", type="text", nullable=false)
*/
private $description;
/**
* @var boolean
*
* @ORM\Column(name="etat", type="boolean", nullable=false)
*/
private $etat;
public function __construct() {
$this->datefr = new \DateTime("now");
$this->type = 'fax';
$this->etat = false;
}
/**
* Get id
*
* @return integer
*/
public function getId() {
return $this->id;
}
/**
* Set datefr
*
* @param \DateTime $datefr
* @return Adminmailing
*/
public function setDatefr($datefr) {
$this->datefr = $datefr;
return $this;
}
/**
* Get datefr
*
* @return \DateTime
*/
public function getDatefr() {
return $this->datefr;
}
/**
* Set titre
*
* @param string $titre
* @return Adminmailing
*/
public function setTitre($titre) {
$this->titre = $titre;
return $this;
}
/**
* Get titre
*
* @return string
*/
public function getTitre() {
return $this->titre;
}
/**
* Set type
*
* @param string $type
* @return Adminmailing
*/
public function setType($type) {
$this->type = $type;
return $this;
}
/**
* Get type
*
* @return string
*/
public function getType() {
return $this->type;
}
/**
* Set destinataires
*
* @param string $destinataires
* @return Adminmailing
*/
public function setDestinataires($destinataires) {
$this->destinataires = $destinataires;
return $this;
}
/**
* Get destinataires
*
* @return string
*/
public function getDestinataires() {
return $this->destinataires;
}
/**
* Set document
*
* @param string $document
* @return Adminmailing
*/
public function setDocument($document) {
$this->document = $document;
return $this;
}
/**
* Get document
*
* @return string
*/
public function getDocument() {
return $this->document;
}
/**
* Set description
*
* @param string $description
* @return Adminmailing
*/
public function setDescription($description) {
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription() {
return $this->description;
}
/**
* Set etat
*
* @param boolean $etat
* @return Adminmailing
*/
public function setEtat($etat) {
$this->etat = $etat;
return $this;
}
/**
* Get etat
*
* @return boolean
*/
public function getEtat() {
return $this->etat;
}
/**
* Get nbDestinataires
*
* @return integer
*/
public function getNbDestinataires() {
return count(explode('|', $this->destinataires));
}
protected function getUploadRootDir() {
return __DIR__ . '/../../../../public/documents';
}
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/fax';
}
/**
* @return UploadedFile
*/
public function upload() {
// utilisez le nom de fichier original ici mais
// vous devriez « l'assainir » pour au moins éviter
// quelconques problèmes de sécurité
// la méthode « move » prend comme arguments le répertoire cible et
// le nom de fichier cible où le fichier doit être déplacé
$name = str_replace(" ", "_", $this->document->getClientOriginalName());
$this->document->move($this->getUploadRootDir(), $name);
// définit la propriété « path » comme étant le nom de fichier où vous
// avez stocké le fichier
$this->document = $name;
}
}