<?php
namespace App\Entity\Produit\Service;
use Doctrine\ORM\Mapping as ORM;
use App\Validator\Validatortext\Email;
use App\Validator\Validatortext\Taillemin;
use App\Validator\Validatortext\Taillemax;
use App\Repository\Produit\Service\MessageRepository;
use App\Entity\Users\User\User;
/**
* Message
*
* @ORM\Table("message")
* @ORM\Entity(repositoryClass=MessageRepository::class)
*/
class Message
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="titre", type="string", length=255,nullable=true)
*@Taillemin(valeur=3, message="Au moins 3 caractères")
*@Taillemax(valeur=250, message="Au plus 250 caractès")
*/
private $titre;
/**
* @var string
*
* @ORM\Column(name="nom", type="string", length=255,nullable=true)
*@Taillemax(valeur=100, message="Au plus 100 caractès")
*/
private $nom;
/**
* @var integer
*
* @ORM\Column(name="tel", type="integer", nullable=true)
*/
private $tel;
/**
* @var string
*
* @ORM\Column(name="contenu", type="text")
*@Taillemax(valeur=300, message="Au plus 300 caractès")
*/
private $contenu;
/**
* @var integer
*
* @ORM\Column(name="timestamp", type="bigint")
*/
private $timestamp;
/**
* @var boolean
*
* @ORM\Column(name="valide", type="boolean")
*/
private $valide;
/**
* @var boolean
*
* @ORM\Column(name="lut", type="boolean")
*/
private $lut;
/**
* @var \DateTime
*
* @ORM\Column(name="date", type="datetime")
*/
private $date;
/**
* @var string
*
*@ORM\Column(name="email", type="string", length=255,nullable=true)
*@Email()
*/
private $email;
/**
* @ORM\ManyToOne(targetEntity=User::class)
* @ORM\JoinColumn(nullable=true)
*/
private $user;
public function __construct()
{
$this->date = new \Datetime();
$this->timestamp = time();
$this->valide = false;
$this->lut = false;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set titre
*
* @param string $titre
* @return Message
*/
public function setTitre($titre)
{
$this->titre = $titre;
return $this;
}
/**
* Get titre
*
* @return string
*/
public function getTitre()
{
return $this->titre;
}
/**
* Set contenu
*
* @param string $contenu
* @return Message
*/
public function setContenu($contenu)
{
$this->contenu = $contenu;
return $this;
}
/**
* Get contenu
*
* @return string
*/
public function getContenu()
{
return $this->contenu;
}
/**
* Set date
*
* @param \DateTime $date
* @return Message
*/
public function setDate($date)
{
$this->date = $date;
return $this;
}
/**
* Get date
*
* @return \DateTime
*/
public function getDate()
{
return $this->date;
}
/**
* Set email
*
* @param string $email
* @return Message
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set nom
*
* @param string $nom
* @return Message
*/
public function setNom($nom)
{
$this->nom = $nom;
return $this;
}
/**
* Get nom
*
* @return string
*/
public function getNom()
{
return $this->nom;
}
/**
* Set user
* @return Message
*/
public function setUser(User $user = null): self
{
$this->user = $user;
return $this;
}
/**
* Get user
*/
public function getUser(): ?User
{
return $this->user;
}
public function getDuree()
{
$seconde = time() - $this->timestamp;
$minute = round($seconde/60);
if($minute < 60)
{
if($minute < 3)
{
$duree = 'à l\'instant';
}else{
$duree = $minute.' min';
}
}else{
if($minute < 60*24)
{
$duree = (floor(($minute/60))).'h'.($minute%60).'min';
}else{
if($minute < 60*24*30)
{
$reste = $minute - (floor($minute/(60*24)))*(60*24);
$duree = (floor($minute/(60*24))).'j'.(floor($reste/60)).'h';
}else{
$nbjour = $this->date->diff(new \Datetime())->days;
$age = floor($nbjour/365);
if($age < 1)
{
$reste = $nbjour - (floor($nbjour/(30)))*(30);
if(floor($nbjour/(30)) != 0)
{
$duree = (floor($nbjour/(30))).'Mois'.($reste - (floor($reste/30)*30)).'J';
}else{
$duree = ($reste - (floor($reste/30)*30)).'J';
}
}else{
$courantyear = date('Y');
$duree = $courantyear - $age;
}
}
}
}
return $duree;
}
/**
* Set timestamp
*
* @param integer $timestamp
* @return Message
*/
public function setTimestamp($timestamp)
{
$this->timestamp = $timestamp;
return $this;
}
/**
* Get timestamp
*
* @return integer
*/
public function getTimestamp()
{
return $this->timestamp;
}
/**
* Set valide
*
* @param boolean $valide
* @return Message
*/
public function setValide($valide)
{
$this->valide = $valide;
return $this;
}
/**
* Get valide
*
* @return boolean
*/
public function getValide()
{
return $this->valide;
}
/**
* Set lut
*
* @param boolean $lut
* @return Message
*/
public function setLut($lut)
{
$this->lut = $lut;
return $this;
}
/**
* Get lut
*
* @return boolean
*/
public function getLut()
{
return $this->lut;
}
/**
* Set tel
*
* @param integer $tel
* @return Message
*/
public function setTel($tel)
{
$this->tel = $tel;
return $this;
}
/**
* Get tel
*
* @return integer
*/
public function getTel()
{
return $this->tel;
}
}