src/Entity/Livraison.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\LivraisonRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=LivraisonRepository::class)
  9.  */
  10. class Livraison
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="datetime_immutable")
  20.      */
  21.     private $createdAt;
  22.     /**
  23.      * @ORM\Column(type="float")
  24.      */
  25.     private $tarif;
  26.     /**
  27.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="livraisons")
  28.      * @ORM\JoinColumn(nullable=true)
  29.      */
  30.     private $livreur;
  31.     /**
  32.      * @ORM\OneToMany(targetEntity=Parcours::class, mappedBy="livraison")
  33.      */
  34.     private $parcours;
  35.     /**
  36.      * @ORM\ManyToOne(targetEntity=SocieteLivraison::class, inversedBy="livraisons")
  37.      * @ORM\JoinColumn(nullable=false)
  38.      */
  39.     private $societeLivraison;
  40.     /**
  41.      * @ORM\Column(type="integer", nullable=true)
  42.      */
  43.     private $code;
  44.     /**
  45.      * @ORM\Column(type="integer", nullable=true)
  46.      */
  47.     private $codeSecret;
  48.     public function __construct()
  49.     {
  50.         $this->parcours = new ArrayCollection();
  51.         $this->createdAt = new \DateTimeImmutable();
  52.         $this->code $this->genererChiffreAleatoire(6);
  53.         $this->codeSecret $this->genererChiffreAleatoire(2);
  54.     }
  55.     public function getId(): ?int
  56.     {
  57.         return $this->id;
  58.     }
  59.     public function getCreatedAt(): ?\DateTimeImmutable
  60.     {
  61.         return $this->createdAt;
  62.     }
  63.     public function setCreatedAt(\DateTimeImmutable $createdAt): self
  64.     {
  65.         $this->createdAt $createdAt;
  66.         return $this;
  67.     }
  68.     public function getTarif(): ?float
  69.     {
  70.         return $this->tarif;
  71.     }
  72.     public function setTarif(float $tarif): self
  73.     {
  74.         $this->tarif $tarif;
  75.         return $this;
  76.     }
  77.     public function getLivreur(): ?User
  78.     {
  79.         return $this->livreur;
  80.     }
  81.     public function setLivreur(?User $livreur): self
  82.     {
  83.         $this->livreur $livreur;
  84.         return $this;
  85.     }
  86.     /**
  87.      * @return Collection<int, Parcours>
  88.      */
  89.     public function getParcours(): Collection
  90.     {
  91.         return $this->parcours;
  92.     }
  93.     public function addParcour(Parcours $parcour): self
  94.     {
  95.         if (!$this->parcours->contains($parcour)) {
  96.             $this->parcours[] = $parcour;
  97.             $parcour->setLivraison($this);
  98.         }
  99.         return $this;
  100.     }
  101.     public function removeParcour(Parcours $parcour): self
  102.     {
  103.         if ($this->parcours->removeElement($parcour)) {
  104.             // set the owning side to null (unless already changed)
  105.             if ($parcour->getLivraison() === $this) {
  106.                 $parcour->setLivraison(null);
  107.             }
  108.         }
  109.         return $this;
  110.     }
  111.     public function getSocieteLivraison(): ?SocieteLivraison
  112.     {
  113.         return $this->societeLivraison;
  114.     }
  115.     public function setSocieteLivraison(?SocieteLivraison $societeLivraison): self
  116.     {
  117.         $this->societeLivraison $societeLivraison;
  118.         return $this;
  119.     }
  120.     public function getCode(): ?int
  121.     {
  122.         return $this->code;
  123.     }
  124.     public function setCode(?int $code): self
  125.     {
  126.         $this->code $code;
  127.         return $this;
  128.     }
  129.     public function getCodeSecret(): ?int
  130.     {
  131.         return $this->codeSecret;
  132.     }
  133.     public function setCodeSecret(?int $codeSecret): self
  134.     {
  135.         $this->codeSecret $codeSecret;
  136.         return $this;
  137.     }
  138.     public function genererChiffreAleatoire($nbChiffres)
  139.     {
  140.         if ($nbChiffres <= 0) {
  141.             return 0;
  142.         }
  143.         $min pow(10$nbChiffres 1);
  144.         $max pow(10$nbChiffres) - 1;
  145.         return random_int($min$max);
  146.     }
  147. }