src/Entity/Sogec/Promotion.php line 35

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Sogec;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Entity\MediaObject\MediaPromotion;
  5. use App\Entity\User\User;
  6. use App\Repository\Sogec\PromotionRepository;
  7. use App\Validator\Constraints as AppAssert;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Ramsey\Uuid\Doctrine\UuidGenerator;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use Symfony\Component\Serializer\Annotation\SerializedName;
  13. /**
  14.  * @ORM\Entity(repositoryClass=PromotionRepository::class)
  15.  *
  16.  * @ApiResource(
  17.  *     attributes={
  18.  *          "normalization_context"={"groups"={
  19.  *              "Promotion:output",
  20.  *              "Promotion:io",
  21.  *          }},
  22.  *          "denormalization_context"={"groups"={
  23.  *              "Promotion:input",
  24.  *              "Promotion:io",
  25.  *          }}
  26.  *      },
  27.  *     itemOperations={
  28.  *         "get"
  29.  *     }
  30.  * )
  31.  */
  32. class Promotion
  33. {
  34.     /**
  35.      * @ORM\Id
  36.      * @ORM\Column(type="uuid", unique=true)
  37.      * @ORM\GeneratedValue(strategy="CUSTOM")
  38.      * @ORM\CustomIdGenerator(class=UuidGenerator::class)
  39.      */
  40.     private $id;
  41.     /**
  42.      * @ORM\Column(type="datetime")
  43.      * @AppAssert\OverlappingDate(
  44.      *     class="App\Entity\Sogec\Promotion",
  45.      *     startField="startedAt",
  46.      *     endField="endedAt",
  47.      *     customMsg="Une autre promotion est déjà paramétrée dans cette tranche de date",
  48.      *     groups={
  49.      *     "Promotion",
  50.      * }
  51.      * )
  52.      */
  53.     private $startedAt;
  54.     /**
  55.      * @ORM\Column(type="datetime")
  56.      * @AppAssert\OverlappingDate(
  57.      *     class="App\Entity\Sogec\Promotion",
  58.      *     startField="startedAt",
  59.      *     endField="endedAt",
  60.      *     customMsg="Une autre promotion est déjà paramétrée dans cette tranche de date",
  61.      * )
  62.      */
  63.     private $endedAt;
  64.     /**
  65.      * @ORM\Column(type="boolean", options={"default" : 0})
  66.      */
  67.     private $quantity;
  68.     /**
  69.      * @ORM\Column(type="boolean", options={"default" : 0})
  70.      */
  71.     private $amount;
  72.     /**
  73.      * @ORM\Column(type="integer")
  74.      */
  75.     private $multiplier;
  76.     /**
  77.      * @var MediaPromotion
  78.      * @ORM\OneToMany(targetEntity=MediaPromotion::class, mappedBy="promotion", cascade={"persist"})
  79.      * @SerializedName("thumbnail_blogs")
  80.      * @Groups({
  81.      *     "Promotion:output",
  82.      *     "MediaPromotion:io"
  83.      * })
  84.      */
  85.     private $mediaPromotions;
  86.     /**
  87.      * @ORM\ManyToOne(targetEntity=User::class)
  88.      * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
  89.      */
  90.     private User $user;
  91.     public function __construct()
  92.     {
  93.         $this->mediaPromotions = new ArrayCollection();
  94.     }
  95.     public function getId(): ?string
  96.     {
  97.         return $this->id;
  98.     }
  99.     public function getStartedAt(): ?\DateTimeInterface
  100.     {
  101.         return $this->startedAt;
  102.     }
  103.     public function setStartedAt(\DateTimeInterface $startedAt): self
  104.     {
  105.         $this->startedAt $startedAt;
  106.         return $this;
  107.     }
  108.     public function getEndedAt(): ?\DateTimeInterface
  109.     {
  110.         return $this->endedAt;
  111.     }
  112.     public function setEndedAt(\DateTimeInterface $endedAt): self
  113.     {
  114.         $date = new \DateTime($endedAt->format('Y-m-d H:i:s'));
  115.         $this->endedAt $date->setTime(235959);
  116.         return $this;
  117.     }
  118.     public function getQuantity(): ?bool
  119.     {
  120.         return $this->quantity;
  121.     }
  122.     public function setQuantity(bool $quantity): self
  123.     {
  124.         $this->quantity $quantity;
  125.         return $this;
  126.     }
  127.     public function getAmount(): ?bool
  128.     {
  129.         return $this->amount;
  130.     }
  131.     public function setAmount(bool $amount): self
  132.     {
  133.         $this->amount $amount;
  134.         return $this;
  135.     }
  136.     public function getMultiplier(): ?int
  137.     {
  138.         return $this->multiplier;
  139.     }
  140.     public function setMultiplier(int $multiplier): self
  141.     {
  142.         $this->multiplier $multiplier;
  143.         return $this;
  144.     }
  145.     public function getMediaPromotions()
  146.     {
  147.         return $this->mediaPromotions;
  148.     }
  149.     public function setMediaPromotions(MediaPromotion $mediaPromotions): Promotion
  150.     {
  151.         $this->mediaPromotions $mediaPromotions;
  152.         return $this;
  153.     }
  154.     public function addMediaPromotion(MediaPromotion $mediaPromotion)
  155.     {
  156.         if ($this->mediaPromotions->contains($mediaPromotion)) {
  157.             return;
  158.         }
  159.         $this->mediaPromotions[] = $mediaPromotion;
  160.         $mediaPromotion->setPromotion($this);
  161.     }
  162.     public function getUser(): User
  163.     {
  164.         return $this->user;
  165.     }
  166.     public function setUser(User $user): self
  167.     {
  168.         $this->user $user;
  169.         return $this;
  170.     }
  171. }