src/Entity/Livreurs.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\LivreursRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassLivreursRepository::class)]
  9. #[ApiResource]
  10. class Livreurs
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column]
  15.     private ?int $id null;
  16.     #[ORM\Column(length255)]
  17.     private ?string $nom null;
  18.     #[ORM\Column(length255)]
  19.     private ?string $telephone null;
  20.     #[ORM\Column(length255)]
  21.     private ?string $cni null;
  22.     #[ORM\Column(length255)]
  23.     private ?string $adresse null;
  24.     #[ORM\Column]
  25.     private ?bool $disponibilite null;
  26.     #[ORM\Column(length255)]
  27.     private ?string $email null;
  28.     #[ORM\Column(length180uniquetrue)]
  29.     private ?string $userprofile ;
  30.     #[ORM\OneToMany(mappedBy'id_livreurs'targetEntityLivraisons::class)]
  31.     private Collection $livraisons;
  32.     #[ORM\ManyToOne(inversedBy'livreurs')]
  33.     private ?TypeTransport $id_TypeTransport null;
  34.     #[ORM\OneToMany(mappedBy'deliverer'targetEntityComment::class, orphanRemovaltrue)]
  35.     private Collection $comments;
  36.     #[ORM\Column(length255nullabletrue)]
  37.     private ?string $prenom null;
  38.     #[ORM\Column(nullabletrue)]
  39.     private ?float $longitude null;
  40.     #[ORM\Column(nullabletrue)]
  41.     private ?float $latitude null;
  42.     
  43.     // Méthode pour calculer la moyenne des étoiles
  44.     public function getAverageRating(): ?float
  45.     {
  46.         if ($this->comments->isEmpty()) {
  47.             return null;
  48.         }
  49.         $total array_reduce($this->comments->toArray(), function ($sumComment $comment) {
  50.             return $sum $comment->getRating();
  51.         }, 0);
  52.         return $total count($this->comments);
  53.     }
  54.     public function __construct()
  55.     {
  56.         $this->livraisons = new ArrayCollection();
  57.         $this->comments = new ArrayCollection();
  58.     }
  59.     public function getId(): ?int
  60.     {
  61.         return $this->id;
  62.     }
  63.     public function getNom(): ?string
  64.     {
  65.         return $this->nom;
  66.     }
  67.     public function setNom(string $nom)
  68.     {
  69.         $this->nom $nom;
  70.         return $this;
  71.     }
  72.     public function isDisponibilite(): ?bool
  73.     {
  74.         return $this->disponibilite;
  75.     }
  76.     public function setDisponibilite(bool $disponibilite)
  77.     {
  78.         $this->disponibilite $disponibilite;
  79.         return $this;
  80.     }
  81.     public function getEmail(): ?string
  82.     {
  83.         return $this->email;
  84.     }
  85.     public function setEmail(string $email)
  86.     {
  87.         $this->email $email;
  88.         return $this;
  89.     }
  90.     /**
  91.      * @return Collection<int, Livraisons>
  92.      */
  93.     public function getLivraisons(): Collection
  94.     {
  95.         return $this->livraisons;
  96.     }
  97.     public function addLivraison(Livraisons $livraison)
  98.     {
  99.         if (!$this->livraisons->contains($livraison)) {
  100.             $this->livraisons->add($livraison);
  101.             $livraison->setIdLivreurs($this);
  102.         }
  103.         return $this;
  104.     }
  105.     public function removeLivraison(Livraisons $livraison)
  106.     {
  107.         if ($this->livraisons->removeElement($livraison)) {
  108.             // set the owning side to null (unless already changed)
  109.             if ($livraison->getIdLivreurs() === $this) {
  110.                 $livraison->setIdLivreurs(null);
  111.             }
  112.         }
  113.         return $this;
  114.     }
  115.     public function getIdTypeTransport(): ?TypeTransport
  116.     {
  117.         return $this->id_TypeTransport;
  118.     }
  119.     public function setIdTypeTransport(?TypeTransport $id_TypeTransport)
  120.     {
  121.         $this->id_TypeTransport $id_TypeTransport;
  122.         return $this;
  123.     }
  124.     public function getTelephone(): ?string
  125.     {
  126.         return $this->telephone;
  127.     }
  128.     public function setTelephone(string $telephone): static
  129.     {
  130.         $this->telephone $telephone;
  131.         return $this;
  132.     }
  133.     public function getCni(): ?string
  134.     {
  135.         return $this->cni;
  136.     }
  137.     public function setCni(string $cni): static
  138.     {
  139.         $this->cni $cni;
  140.         return $this;
  141.     }
  142.     public function getAdresse(): ?string
  143.     {
  144.         return $this->adresse;
  145.     }
  146.     public function setAdresse(string $adresse): static
  147.     {
  148.         $this->adresse $adresse;
  149.         return $this;
  150.     }
  151.     public function __toString(): string
  152.     {
  153.         return $this->prenom.' '.$this->nom// Return a string representation
  154.     }
  155.     /**
  156.      * @return Collection<int, Comment>
  157.      */
  158.     public function getComments(): Collection
  159.     {
  160.         return $this->comments;
  161.     }
  162.     public function addComment(Comment $comment): static
  163.     {
  164.         if (!$this->comments->contains($comment)) {
  165.             $this->comments->add($comment);
  166.             $comment->setDeliverer($this);
  167.         }
  168.         return $this;
  169.     }
  170.     public function removeComment(Comment $comment): static
  171.     {
  172.         if ($this->comments->removeElement($comment)) {
  173.             // set the owning side to null (unless already changed)
  174.             if ($comment->getDeliverer() === $this) {
  175.                 $comment->setDeliverer(null);
  176.             }
  177.         }
  178.         return $this;
  179.     }
  180.     public function getUserprofile(): ?string
  181.     {
  182.         return $this->userprofile;
  183.     }
  184.     public function setUserprofile(string $userprofile): static
  185.     {
  186.         $this->userprofile $userprofile;
  187.         return $this;
  188.     }
  189.     public function getPrenom(): ?string
  190.     {
  191.         return $this->prenom;
  192.     }
  193.     public function setPrenom(?string $prenom): static
  194.     {
  195.         $this->prenom $prenom;
  196.         return $this;
  197.     }
  198.     public function getLongitude(): ?float
  199.     {
  200.         return $this->longitude;
  201.     }
  202.     public function setLongitude(?float $longitude): static
  203.     {
  204.         $this->longitude $longitude;
  205.         return $this;
  206.     }
  207.     public function getLatitude(): ?float
  208.     {
  209.         return $this->latitude;
  210.     }
  211.     public function setLatitude(?float $latitude): static
  212.     {
  213.         $this->latitude $latitude;
  214.         return $this;
  215.     }
  216.     
  217. }