src/Entity/Vetoadom/Animal.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Vetoadom;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Symfony\Component\Validator\Constraints as Assert;
  5. /**
  6.  * Animal
  7.  *
  8.  * @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"})})
  9.  * @ORM\Entity(repositoryClass="App\Repository\Vetoadom\AnimalRepository")
  10.  * @ORM\HasLifecycleCallbacks()
  11.  */
  12. class Animal
  13. {
  14.     /**
  15.      * @var int
  16.      *
  17.      * @ORM\Column(name="id", type="integer", nullable=false)
  18.      * @ORM\Id
  19.      * @ORM\GeneratedValue(strategy="IDENTITY")
  20.      */
  21.     private $id;
  22.     /**
  23.      * @var string
  24.      *
  25.      * @ORM\Column(name="nom", type="string", length=190, nullable=false)
  26.      * @Assert\NotBlank(
  27.      *        groups={"nom"},
  28.      *        message="common.blank"
  29.      *     )
  30.      * @Assert\Length(
  31.      *        groups={"nom"},
  32.      *        max=190,
  33.      *        maxMessage="common.too_long"
  34.      *     )
  35.      */
  36.     private $nom;
  37.     /**
  38.      * @var \DateTime
  39.      *
  40.      * @ORM\Column(name="date_naissance", type="date", nullable=false)
  41.      * @Assert\NotBlank(
  42.      *          groups={"dateNaissance"},
  43.      *          message="common.blank"
  44.      *       )
  45.      * @Assert\Expression(
  46.      *   "this.isValidDateNaissanceMax()",
  47.      *   groups={"dateNaissance"},
  48.      *   message="common.value_wrong"
  49.      *  )
  50.      */
  51.     private $dateNaissance;
  52.     /**
  53.      * @var bool|null
  54.      *
  55.      * @ORM\Column(name="deces", type="boolean", nullable=true)
  56.      */
  57.     private $deces '0';
  58.     /**
  59.      * @var \DateTime
  60.      *
  61.      * @ORM\Column(name="date_creation", type="datetime", nullable=false)
  62.      */
  63.     private $dateCreation;
  64.     /**
  65.      * @var \DateTime
  66.      *
  67.      * @ORM\Column(name="date_modification", type="datetime", nullable=false, options={"default"="CURRENT_TIMESTAMP"})
  68.      */
  69.     private $dateModification;
  70.     /**
  71.      * @var \DateTime|null
  72.      *
  73.      * @ORM\Column(name="date_suppression", type="datetime", nullable=true)
  74.      */
  75.     private $dateSuppression;
  76.     /**
  77.      * @var bool
  78.      *
  79.      * @ORM\Column(name="active", type="boolean", nullable=false, options={"default"="1"})
  80.      */
  81.     private $active true;
  82.     /**
  83.      * @var string|null
  84.      *
  85.      * @ORM\Column(name="animal_race_autre_nom", type="string", length=190, nullable=true)
  86.      * @Assert\NotBlank(
  87.      *         groups={"animalRaceAutreNom"},
  88.      *         message="common.blank"
  89.      *      )
  90.      * @Assert\Length(
  91.      *         groups={"animalRaceAutreNom"},
  92.      *         max=190,
  93.      *         maxMessage="common.too_long"
  94.      *      )
  95.      */
  96.     private $animalRaceAutreNom;
  97.     /**
  98.      * @var \AnimalSexe
  99.      *
  100.      * @ORM\ManyToOne(targetEntity="AnimalSexe")
  101.      * @ORM\JoinColumns({
  102.      *   @ORM\JoinColumn(name="animal_sexe_id", referencedColumnName="id")
  103.      * })
  104.      * @Assert\NotBlank(
  105.      *        groups={"animalSexe"},
  106.      *        message="common.blank"
  107.      *     )
  108.      */
  109.     private $animalSexe;
  110.     /**
  111.      * @var \Client
  112.      *
  113.      * @ORM\ManyToOne(targetEntity="Client")
  114.      * @ORM\JoinColumns({
  115.      *   @ORM\JoinColumn(name="client_id", referencedColumnName="id")
  116.      * })
  117.      */
  118.     private $client;
  119.     /**
  120.      * @var \AnimalEspece
  121.      *
  122.      * @ORM\ManyToOne(targetEntity="AnimalEspece")
  123.      * @ORM\JoinColumns({
  124.      *   @ORM\JoinColumn(name="animal_espece_id", referencedColumnName="id")
  125.      * })
  126.      * @Assert\NotBlank(
  127.      *         groups={"animalEspece"},
  128.      *         message="common.blank"
  129.      *      )
  130.      */
  131.     private $animalEspece;
  132.     /**
  133.      * @var \AnimalRace
  134.      *
  135.      * @ORM\ManyToOne(targetEntity="AnimalRace")
  136.      * @ORM\JoinColumns({
  137.      *   @ORM\JoinColumn(name="animal_race_id", referencedColumnName="id")
  138.      * })
  139.      */
  140.     private $animalRace;
  141.     public function getId(): ?int
  142.     {
  143.         return $this->id;
  144.     }
  145.     public function getNom(): ?string
  146.     {
  147.         return $this->nom;
  148.     }
  149.     public function setNom(string $nom): self
  150.     {
  151.         $this->nom $nom;
  152.         return $this;
  153.     }
  154.     public function getAnimalRaceAutreNom(): ?string
  155.     {
  156.         return $this->animalRaceAutreNom;
  157.     }
  158.     public function setAnimalRaceAutreNom(?string $animalRaceAutreNom): self
  159.     {
  160.         if ($animalRaceAutreNom === ''$animalRaceAutreNom null;
  161.         $this->animalRaceAutreNom $animalRaceAutreNom;
  162.         return $this;
  163.     }
  164.     public function getDateNaissance(): ?\DateTimeInterface
  165.     {
  166.         return $this->dateNaissance;
  167.     }
  168.     public function setDateNaissance(?\DateTimeInterface $dateNaissance): self
  169.     {
  170.         $this->dateNaissance $dateNaissance;
  171.         return $this;
  172.     }
  173.     public function getDeces(): ?bool
  174.     {
  175.         return $this->deces;
  176.     }
  177.     public function setDeces(?bool $deces): self
  178.     {
  179.         $this->deces $deces;
  180.         return $this;
  181.     }
  182.     public function getDateCreation(): ?\DateTimeInterface
  183.     {
  184.         return $this->dateCreation;
  185.     }
  186.     public function setDateCreation(\DateTimeInterface $dateCreation): self
  187.     {
  188.         $this->dateCreation $dateCreation;
  189.         return $this;
  190.     }
  191.     public function getDateModification(): ?\DateTimeInterface
  192.     {
  193.         return $this->dateModification;
  194.     }
  195.     public function setDateModification(\DateTimeInterface $dateModification): self
  196.     {
  197.         $this->dateModification $dateModification;
  198.         return $this;
  199.     }
  200.     public function getDateSuppression(): ?\DateTimeInterface
  201.     {
  202.         return $this->dateSuppression;
  203.     }
  204.     public function setDateSuppression(?\DateTimeInterface $dateSuppression): self
  205.     {
  206.         $this->dateSuppression $dateSuppression;
  207.         return $this;
  208.     }
  209.     public function getActive(): ?bool
  210.     {
  211.         return $this->active;
  212.     }
  213.     public function setActive(bool $active): self
  214.     {
  215.         $this->active $active;
  216.         return $this;
  217.     }
  218.     public function getAnimalSexe(): ?AnimalSexe
  219.     {
  220.         return $this->animalSexe;
  221.     }
  222.     public function setAnimalSexe(?AnimalSexe $animalSexe): self
  223.     {
  224.         $this->animalSexe $animalSexe;
  225.         return $this;
  226.     }
  227.     public function getClient(): ?Client
  228.     {
  229.         return $this->client;
  230.     }
  231.     public function setClient(?Client $client): self
  232.     {
  233.         $this->client $client;
  234.         return $this;
  235.     }
  236.     public function getAnimalEspece(): ?AnimalEspece
  237.     {
  238.         return $this->animalEspece;
  239.     }
  240.     public function setAnimalEspece(?AnimalEspece $animalEspece): self
  241.     {
  242.         $this->animalEspece $animalEspece;
  243.         return $this;
  244.     }
  245.     public function getAnimalRace(): ?AnimalRace
  246.     {
  247.         return $this->animalRace;
  248.     }
  249.     public function setAnimalRace(?AnimalRace $animalRace): self
  250.     {
  251.         $this->animalRace $animalRace;
  252.         return $this;
  253.     }
  254.     public function getDateNaissanceMax(): ?\DateTimeInterface
  255.     {
  256.         return new \DateTimeImmutable("today");
  257.     }
  258.     public function isValidDateNaissanceMax()
  259.     {
  260.         return !$this->getDateNaissance() || ($this->getDateNaissance() <= $this->getDateNaissanceMax());
  261.     }
  262.     /**
  263.      * @ORM\PrePersist
  264.      */
  265.     public function setCreatedAtValue()
  266.     {
  267.         $this->dateCreation = new \DateTimeImmutable();
  268.     }
  269.     /**
  270.      * Helpres
  271.      */
  272.     public function getAnimalAge(): array
  273.     {
  274.         $today = new \DateTime("today");
  275.         $diff $today->diff($this->getDateNaissance());
  276.         if ($diff->=== 0) {
  277.             return ['age' => $diff->d'animalAgeUnit' => 'days'];
  278.         }
  279.         if ($diff->y) {
  280.             return ['age' => $diff->y'animalAgeUnit' => 'years'];
  281.         }
  282.         return ['age' => $diff->m'animalAgeUnit' => 'months'];
  283.     }
  284. }