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