src/Entity/Promotion.php line 16

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. use JsonSerializable;
  8. use ApiPlatform\Core\Annotation\ApiResource;
  9. use phpDocumentor\Reflection\Types\Boolean;
  10. /**
  11.  * @ORM\Entity(repositoryClass=PromotionRepository::class)
  12.  */
  13. class Promotion implements JsonSerializable
  14. {
  15.     /**
  16.      * @ORM\Id
  17.      * @ORM\GeneratedValue
  18.      * @ORM\Column(type="integer")
  19.      */
  20.     private $id;
  21.     /**
  22.      * @ORM\Column(type="string", length=255)
  23.      */
  24.     private $name;
  25.     /**
  26.      * @ORM\Column(type="text", nullable=true)
  27.      */
  28.     private $description;
  29.     /**
  30.      * @ORM\Column(type="datetime")
  31.      */
  32.     private $startAt;
  33.     /**
  34.      * @ORM\Column(type="datetime")
  35.      */
  36.     private $endAt;
  37.     /**
  38.      * @ORM\Column(type="datetime")
  39.      */
  40.     private $createdAt;
  41.     /**
  42.      * @ORM\Column(type="string", length=255, nullable=true)
  43.      */
  44.     private $discountType;
  45.     /**
  46.      * @ORM\Column(type="float", nullable=true)
  47.      */
  48.     private $discountValue;
  49.     /**
  50.      * @ORM\Column(type="string", length=255, nullable=true)
  51.      */
  52.     private $code;
  53.     /**
  54.      * @ORM\Column(type="integer", nullable=true)
  55.      */
  56.     private $totalQuantity;
  57.     /**
  58.      * @ORM\Column(type="integer", nullable=true)
  59.      */
  60.     private $quntityUser;
  61.     /**
  62.      * @ORM\OneToMany(targetEntity=Produit::class, mappedBy="promotion")
  63.      */
  64.     private $produits;
  65.     /**
  66.      * @ORM\OneToMany(targetEntity=User::class, mappedBy="promotion")
  67.      */
  68.     private $clients;
  69.     public function __construct()
  70.     {
  71.         $this->produits = new ArrayCollection();
  72.         $this->clients = new ArrayCollection();
  73.     }
  74.     public function getId(): ?int
  75.     {
  76.         return $this->id;
  77.     }
  78.     public function getName(): ?string
  79.     {
  80.         return $this->name;
  81.     }
  82.     public function setName(string $name): self
  83.     {
  84.         $this->name $name;
  85.         return $this;
  86.     }
  87.     public function getDescription(): ?string
  88.     {
  89.         return $this->description;
  90.     }
  91.     public function setDescription(?string $description): self
  92.     {
  93.         $this->description $description;
  94.         return $this;
  95.     }
  96.     public function getStartAt(): ?\DateTimeInterface
  97.     {
  98.         return $this->startAt;
  99.     }
  100.     public function setStartAt(\DateTimeInterface $startAt): self
  101.     {
  102.         $this->startAt $startAt;
  103.         return $this;
  104.     }
  105.     public function getEndAt(): ?\DateTimeInterface
  106.     {
  107.         return $this->endAt;
  108.     }
  109.     public function setEndAt(\DateTimeInterface $endAt): self
  110.     {
  111.         $this->endAt $endAt;
  112.         return $this;
  113.     }
  114.     public function getCreatedAt(): ?\DateTimeInterface
  115.     {
  116.         return $this->createdAt;
  117.     }
  118.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  119.     {
  120.         $this->createdAt $createdAt;
  121.         return $this;
  122.     }
  123.     public function getDiscountType(): ?string
  124.     {
  125.         return $this->discountType;
  126.     }
  127.     public function setDiscountType(?string $discountType): self
  128.     {
  129.         $this->discountType $discountType;
  130.         return $this;
  131.     }
  132.     public function getDiscountValue(): ?float
  133.     {
  134.         return $this->discountValue;
  135.     }
  136.     public function setDiscountValue(?float $discountValue): self
  137.     {
  138.         $this->discountValue $discountValue;
  139.         return $this;
  140.     }
  141.     public function getCode(): ?string
  142.     {
  143.         return $this->code;
  144.     }
  145.     public function setCode(?string $code): self
  146.     {
  147.         $this->code $code;
  148.         return $this;
  149.     }
  150.     public function getTotalQuantity(): ?int
  151.     {
  152.         return $this->totalQuantity;
  153.     }
  154.     public function setTotalQuantity(?int $totalQuantity): self
  155.     {
  156.         $this->totalQuantity $totalQuantity;
  157.         return $this;
  158.     }
  159.     public function getQuntityUser(): ?int
  160.     {
  161.         return $this->quntityUser;
  162.     }
  163.     public function setQuntityUser(?int $quntityUser): self
  164.     {
  165.         $this->quntityUser $quntityUser;
  166.         return $this;
  167.     }
  168.     /**
  169.      * @return Collection|Produit[]
  170.      */
  171.     public function getProduits(): Collection
  172.     {
  173.         return $this->produits;
  174.     }
  175.     public function addProduit(Produit $produit): self
  176.     {
  177.         if (!$this->produits->contains($produit)) {
  178.             $this->produits[] = $produit;
  179.             $produit->setPromotion($this);
  180.         }
  181.         return $this;
  182.     }
  183.     public function removeProduit(Produit $produit): self
  184.     {
  185.         if ($this->produits->removeElement($produit)) {
  186.             // set the owning side to null (unless already changed)
  187.             if ($produit->getPromotion() === $this) {
  188.                 $produit->setPromotion(null);
  189.             }
  190.         }
  191.         return $this;
  192.     }
  193.     /**
  194.      * @return Collection|User[]
  195.      */
  196.     public function getClients(): Collection
  197.     {
  198.         return $this->clients;
  199.     }
  200.     public function addClient(User $client): self
  201.     {
  202.         if (!$this->clients->contains($client)) {
  203.             $this->clients[] = $client;
  204.             $client->setPromotion($this);
  205.         }
  206.         return $this;
  207.     }
  208.     public function removeClient(User $client): self
  209.     {
  210.         if ($this->clients->removeElement($client)) {
  211.             // set the owning side to null (unless already changed)
  212.             if ($client->getPromotion() === $this) {
  213.                 $client->setPromotion(null);
  214.             }
  215.         }
  216.         return $this;
  217.     }
  218.     // Fonction pour déterminer la validité de promo en temps
  219.     public function isValid(): ?bool
  220.     {
  221.         $dateJour = new \DateTime('now');
  222.         if ($dateJour >= $this->startAt && $dateJour <= $this->endAt) {
  223.             return true;
  224.         }
  225.         return false;
  226.     }
  227.     public function jsonSerialize()
  228.     {
  229.         return array(
  230.             'id' => $this->getId(),
  231.             'start' => $this->getStartAt(),
  232.             'end' => $this->getEndAt(),
  233.             'discountType' => $this->getDiscountType(),
  234.             'discountValue' => $this->getDiscountValue(),
  235.             'code' => $this->getCode(),
  236.             'isValid' => $this->isValid()
  237.         );
  238.     }
  239. }