<?php
namespace App\Entity\Vetoadom;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Animal
*
* @ORM\Table(name="animal", indexes={@ORM\Index(name="FK_animal_animal_espece", columns={"animal_espece_id"}), @ORM\Index(name="FK_animal_animal_race", columns={"animal_race_id"}), @ORM\Index(name="FK_animal_animal_sexe", columns={"animal_sexe_id"}), @ORM\Index(name="FK_animal_client", columns={"client_id"})})
* @ORM\Entity(repositoryClass="App\Repository\Vetoadom\AnimalRepository")
* @ORM\HasLifecycleCallbacks()
*/
class Animal
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="nom", type="string", length=190, nullable=false)
* @Assert\NotBlank(
* groups={"nom"},
* message="common.blank"
* )
* @Assert\Length(
* groups={"nom"},
* max=190,
* maxMessage="common.too_long"
* )
*/
private $nom;
/**
* @var \DateTime
*
* @ORM\Column(name="date_naissance", type="date", nullable=false)
* @Assert\NotBlank(
* groups={"dateNaissance"},
* message="common.blank"
* )
* @Assert\Expression(
* "this.isValidDateNaissanceMax()",
* groups={"dateNaissance"},
* message="common.value_wrong"
* )
*/
private $dateNaissance;
/**
* @var bool|null
*
* @ORM\Column(name="deces", type="boolean", nullable=true)
*/
private $deces = '0';
/**
* @var \DateTime
*
* @ORM\Column(name="date_creation", type="datetime", nullable=false)
*/
private $dateCreation;
/**
* @var \DateTime
*
* @ORM\Column(name="date_modification", type="datetime", nullable=false, options={"default"="CURRENT_TIMESTAMP"})
*/
private $dateModification;
/**
* @var \DateTime|null
*
* @ORM\Column(name="date_suppression", type="datetime", nullable=true)
*/
private $dateSuppression;
/**
* @var bool
*
* @ORM\Column(name="active", type="boolean", nullable=false, options={"default"="1"})
*/
private $active = true;
/**
* @var string|null
*
* @ORM\Column(name="animal_race_autre_nom", type="string", length=190, nullable=true)
* @Assert\NotBlank(
* groups={"animalRaceAutreNom"},
* message="common.blank"
* )
* @Assert\Length(
* groups={"animalRaceAutreNom"},
* max=190,
* maxMessage="common.too_long"
* )
*/
private $animalRaceAutreNom;
/**
* @var \AnimalSexe
*
* @ORM\ManyToOne(targetEntity="AnimalSexe")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="animal_sexe_id", referencedColumnName="id")
* })
* @Assert\NotBlank(
* groups={"animalSexe"},
* message="common.blank"
* )
*/
private $animalSexe;
/**
* @var \Client
*
* @ORM\ManyToOne(targetEntity="Client")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="client_id", referencedColumnName="id")
* })
*/
private $client;
/**
* @var \AnimalEspece
*
* @ORM\ManyToOne(targetEntity="AnimalEspece")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="animal_espece_id", referencedColumnName="id")
* })
* @Assert\NotBlank(
* groups={"animalEspece"},
* message="common.blank"
* )
*/
private $animalEspece;
/**
* @var \AnimalRace
*
* @ORM\ManyToOne(targetEntity="AnimalRace")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="animal_race_id", referencedColumnName="id")
* })
*/
private $animalRace;
public function getId(): ?int
{
return $this->id;
}
public function getNom(): ?string
{
return $this->nom;
}
public function setNom(string $nom): self
{
$this->nom = $nom;
return $this;
}
public function getAnimalRaceAutreNom(): ?string
{
return $this->animalRaceAutreNom;
}
public function setAnimalRaceAutreNom(?string $animalRaceAutreNom): self
{
if ($animalRaceAutreNom === '') $animalRaceAutreNom = null;
$this->animalRaceAutreNom = $animalRaceAutreNom;
return $this;
}
public function getDateNaissance(): ?\DateTimeInterface
{
return $this->dateNaissance;
}
public function setDateNaissance(?\DateTimeInterface $dateNaissance): self
{
$this->dateNaissance = $dateNaissance;
return $this;
}
public function getDeces(): ?bool
{
return $this->deces;
}
public function setDeces(?bool $deces): self
{
$this->deces = $deces;
return $this;
}
public function getDateCreation(): ?\DateTimeInterface
{
return $this->dateCreation;
}
public function setDateCreation(\DateTimeInterface $dateCreation): self
{
$this->dateCreation = $dateCreation;
return $this;
}
public function getDateModification(): ?\DateTimeInterface
{
return $this->dateModification;
}
public function setDateModification(\DateTimeInterface $dateModification): self
{
$this->dateModification = $dateModification;
return $this;
}
public function getDateSuppression(): ?\DateTimeInterface
{
return $this->dateSuppression;
}
public function setDateSuppression(?\DateTimeInterface $dateSuppression): self
{
$this->dateSuppression = $dateSuppression;
return $this;
}
public function getActive(): ?bool
{
return $this->active;
}
public function setActive(bool $active): self
{
$this->active = $active;
return $this;
}
public function getAnimalSexe(): ?AnimalSexe
{
return $this->animalSexe;
}
public function setAnimalSexe(?AnimalSexe $animalSexe): self
{
$this->animalSexe = $animalSexe;
return $this;
}
public function getClient(): ?Client
{
return $this->client;
}
public function setClient(?Client $client): self
{
$this->client = $client;
return $this;
}
public function getAnimalEspece(): ?AnimalEspece
{
return $this->animalEspece;
}
public function setAnimalEspece(?AnimalEspece $animalEspece): self
{
$this->animalEspece = $animalEspece;
return $this;
}
public function getAnimalRace(): ?AnimalRace
{
return $this->animalRace;
}
public function setAnimalRace(?AnimalRace $animalRace): self
{
$this->animalRace = $animalRace;
return $this;
}
public function getDateNaissanceMax(): ?\DateTimeInterface
{
return new \DateTimeImmutable("today");
}
public function isValidDateNaissanceMax()
{
return !$this->getDateNaissance() || ($this->getDateNaissance() <= $this->getDateNaissanceMax());
}
/**
* @ORM\PrePersist
*/
public function setCreatedAtValue()
{
$this->dateCreation = new \DateTimeImmutable();
}
/**
* Helpres
*/
public function getAnimalAge(): array
{
$today = new \DateTime("today");
$diff = $today->diff($this->getDateNaissance());
if ($diff->m === 0) {
return ['age' => $diff->d, 'animalAgeUnit' => 'days'];
}
if ($diff->y) {
return ['age' => $diff->y, 'animalAgeUnit' => 'years'];
}
return ['age' => $diff->m, 'animalAgeUnit' => 'months'];
}
}