src/Entity/Promotion.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\PromotionRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClassPromotionRepository::class)]
  8. class Promotion
  9. {
  10.     #[ORM\Id]
  11.     #[ORM\GeneratedValue]
  12.     #[ORM\Column]
  13.     private ?int $id null;
  14.     #[ORM\Column]
  15.     private ?float $rate null;
  16.     #[ORM\OneToMany(mappedBy'promotion'targetEntityproduitpromotion::class, orphanRemovaltrue)]
  17.     private Collection $promotions;
  18.     public function __construct()
  19.     {
  20.         $this->promotions = new ArrayCollection();
  21.     }
  22.     public function getId(): ?int
  23.     {
  24.         return $this->id;
  25.     }
  26.     public function getRate(): ?float
  27.     {
  28.         // dd($this->rate);
  29.         // return $this->rate;
  30.         if ($this->rate === null) {
  31.             // Retourner une valeur par défaut (par exemple, 0.0) ou gérer l'erreur
  32.             return 0.0// ou retourner null selon le besoin
  33.         }
  34.         return (float)($this->rate);
  35.     }
  36.     public function setRate(float $rate): self
  37.     {
  38.         $this->rate $rate;
  39.         return $this;
  40.     }
  41.     /**
  42.      * @return Collection<int, produitpromotion>
  43.      */
  44.     public function getPromotions(): Collection
  45.     {
  46.         return $this->promotions;
  47.     }
  48.     public function addPromotion(produitpromotion $promotion): self
  49.     {
  50.         if (!$this->promotions->contains($promotion)) {
  51.             $this->promotions->add($promotion);
  52.             $promotion->setPromotion($this);
  53.         }
  54.         return $this;
  55.     }
  56.     public function removePromotion(produitpromotion $promotion): self
  57.     {
  58.         if ($this->promotions->removeElement($promotion)) {
  59.             // set the owning side to null (unless already changed)
  60.             if ($promotion->getPromotion() === $this) {
  61.                 $promotion->setPromotion(null);
  62.             }
  63.         }
  64.         return $this;
  65.     }
  66. }