src/Entity/Slider.php line 61

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
  5. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
  6. use ApiPlatform\Core\Annotation\ApiProperty;
  7. use ApiPlatform\Core\Annotation\ApiResource;
  8. use App\Entity\MediaObject\MediaSlider;
  9. use App\Entity\MediaObject\MediaMobileSlider;
  10. use App\Repository\SliderRepository;
  11. use Doctrine\Common\Annotations\Annotation\IgnoreAnnotation;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use Gedmo\Timestampable\Traits\TimestampableEntity;
  15. use Ramsey\Uuid\Doctrine\UuidGenerator;
  16. use Ramsey\Uuid\Uuid;
  17. use Symfony\Component\Serializer\Annotation\Groups;
  18. use Symfony\Component\Serializer\Annotation\SerializedName;
  19. /**
  20.  * @ApiResource(
  21.  *     attributes={
  22.  *          "normalization_context"={
  23.  *              "groups"={
  24.  *                  "Slider:output",
  25.  *                  "Slider:io",
  26.  *              },
  27.  *          },
  28.  *          "denormalization_context"={
  29.  *              "groups"={
  30.  *                  "Slider:input",
  31.  *                  "Slider:io",
  32.  *              }
  33.  *          },
  34.  *         "order"={"position": "ASC"}
  35.  *      },
  36.  *     collectionOperations={
  37.  *          "public-get"={
  38.  *              "path"="/public/sliders",
  39.  *              "method"="GET",
  40.  *              "access_control"="is_granted('ROLE_PUBLIC')",
  41.  *          },
  42.  *          "get"={
  43.  *              "method"="GET",
  44.  *              "access_control"="is_granted('ROLE_USER')",
  45.  *          }
  46.  *     },
  47.  *     itemOperations={
  48.  *          "get-public"={
  49.  *              "method"="GET",
  50.  *              "path"="/public/sliders/{id}",
  51.  *          },
  52.  *     }
  53.  * )
  54.  *
  55.  * @ORM\Entity(repositoryClass=SliderRepository::class)
  56.  *
  57.  */
  58. class Slider
  59. {
  60.     /**
  61.      * Hook timestampable behavior
  62.      * updates createdAt, updatedAt fields
  63.      */
  64.     use TimestampableEntity;
  65.     /**
  66.      * @ORM\Id
  67.      * @ORM\Column(type="uuid", unique=true)
  68.      * @ORM\GeneratedValue(strategy="CUSTOM")
  69.      * @ORM\CustomIdGenerator(class=UuidGenerator::class)
  70.      * @SerializedName("id")
  71.      * @ApiProperty(identifier=true)
  72.      * @Groups({
  73.      *     "Slider:output",
  74.      * })
  75.      */
  76.     private string $id;
  77.     /**
  78.      * @ORM\Column(type="string", length=255)
  79.      * @SerializedName("libelle")
  80.      * @Groups({
  81.      *     "Slider:output",
  82.      * })
  83.      */
  84.     private ?string $libelle;
  85.     /**
  86.      * @ORM\Column(type="integer", options={"default": 0})
  87.      * @SerializedName("position")
  88.      * @Groups({
  89.      *     "Slider:output",
  90.      * })
  91.      */
  92.     private ?int $position;
  93.     /**
  94.      * @var \DateTime
  95.      * @ORM\Column(type="datetime", nullable=true)
  96.      * @SerializedName("start_date")
  97.      * @Groups({
  98.      *     "Slider:output",
  99.      * })
  100.      * @ApiFilter(DateFilter::class, strategy=DateFilter::EXCLUDE_NULL)
  101.      */
  102.     public $startDate;
  103.     /**
  104.      * @var \DateTime
  105.      * @ORM\Column(type="datetime", nullable=true)
  106.      * @SerializedName("ended_date")
  107.      * @Groups({
  108.      *     "Slider:output",
  109.      * })
  110.      * @ApiFilter(DateFilter::class, strategy=DateFilter::EXCLUDE_NULL)
  111.      */
  112.     private $endDate;
  113.     /**
  114.      * @ORM\Column(type="boolean", options={"default": 0})
  115.      * @Groups({
  116.      *     "Slider:output"
  117.      * })
  118.      * @ApiFilter(BooleanFilter::class)
  119.      */
  120.     private bool $online false;
  121.     /**
  122.      * @ORM\Column(type="boolean", options={"default": 0})
  123.      * @Groups({
  124.      *     "Slider:output"
  125.      * })
  126.      * @ApiFilter(BooleanFilter::class)
  127.      */
  128.     private bool $cible false;
  129.     /**
  130.      * @var MediaSlider|null
  131.      * @ORM\OneToMany(targetEntity=MediaSlider::class, mappedBy="slider", cascade={"persist"})
  132.      * @SerializedName("media_sliders")
  133.      * @Groups({
  134.      *     "Slider:output",
  135.      *     "MediaSlider:io"
  136.      * })
  137.      */
  138.     private $mediaSliders;
  139.     /**
  140.      * @var MediaMobileSlider|null
  141.      * @ORM\OneToMany(targetEntity=MediaMobileSlider::class, mappedBy="slider", cascade={"persist"})
  142.      * @SerializedName("mobile_sliders")
  143.      * @Groups({
  144.      *     "Slider:output",
  145.      *     "MediaMobileSlider:io",
  146.      * })
  147.      */
  148.     private $mobileSliders;
  149.     /**
  150.      * @ORM\Column(type="string", length=255, nullable=true)
  151.      * @Groups({
  152.      *     "Slider:output",
  153.      * })
  154.      */
  155.     private ?string $url;
  156.     public function __construct()
  157.     {
  158.         $this->id Uuid::uuid4();
  159.         $this->mediaSliders = new ArrayCollection();
  160.         $this->mobileSliders = new ArrayCollection();
  161.     }
  162.     public function getId(): ?string
  163.     {
  164.         return $this->id;
  165.     }
  166.     public function getLibelle(): ?string
  167.     {
  168.         return $this->libelle;
  169.     }
  170.     public function setLibelle(string $libelle): self
  171.     {
  172.         $this->libelle $libelle;
  173.         return $this;
  174.     }
  175.     public function getPosition(): ?int
  176.     {
  177.         return $this->position;
  178.     }
  179.     public function setPosition(int $position): Slider
  180.     {
  181.         $this->position $position;
  182.         return $this;
  183.     }
  184.     public function getStartDate(): ?\DateTimeInterface
  185.     {
  186.         return $this->startDate;
  187.     }
  188.     public function setStartDate(\DateTimeInterface $startDate): self
  189.     {
  190.         $this->startDate $startDate;
  191.         return $this;
  192.     }
  193.     public function getEndDate(): ?\DateTimeInterface
  194.     {
  195.         return $this->endDate;
  196.     }
  197.     public function setEndDate(\DateTimeInterface $endDate): self
  198.     {
  199.         $this->endDate $endDate;
  200.         return $this;
  201.     }
  202.     public function isOnline(): bool
  203.     {
  204.         return $this->online;
  205.     }
  206.     public function getOnline(): bool
  207.     {
  208.         return $this->online;
  209.     }
  210.     public function setOnline(bool $online): self
  211.     {
  212.         $this->online $online;
  213.         return $this;
  214.     }
  215.     public function isCible(): bool
  216.     {
  217.         return $this->cible;
  218.     }
  219.     public function getCible(): bool
  220.     {
  221.         return $this->cible;
  222.     }
  223.     public function setCible(bool $cible): self
  224.     {
  225.         $this->cible $cible;
  226.         return $this;
  227.     }
  228.     public function getUrl(): ?string
  229.     {
  230.         return $this->url;
  231.     }
  232.     public function setUrl(?string $url): Slider
  233.     {
  234.         $this->url $url;
  235.         return $this;
  236.     }
  237.     public function getMediaSliders()
  238.     {
  239.         return $this->mediaSliders;
  240.     }
  241.     public function setMediaSlider(MediaSlider $mediaSliders): Slider
  242.     {
  243.         $this->mediaSliders $mediaSliders;
  244.         return $this;
  245.     }
  246.     public function addMediaSlider(MediaSlider $mediaSlider): self
  247.     {
  248.         if (!$this->mediaSliders->contains($mediaSlider)) {
  249.             $this->mediaSliders[] = $mediaSlider;
  250.             $mediaSlider->setSlider($this);
  251.         }
  252.         return $this;
  253.     }
  254.     public function __toString()
  255.     {
  256.         return $this->libelle;
  257.     }
  258.     public function getMobileSliders()
  259.     {
  260.         return $this->mobileSliders;
  261.     }
  262.     public function setMobileSlider(MediaMobileSlider $mobileSliders): Slider
  263.     {
  264.         $this->mobileSliders $mobileSliders;
  265.         return $this;
  266.     }
  267.     public function addMobileSlider(MediaMobileSlider $mobileSlider): self
  268.     {
  269.         if (!$this->mobileSliders->contains($mobileSlider)) {
  270.             $this->mobileSliders[] = $mobileSlider;
  271.             $mobileSlider->setSlider($this);
  272.         }
  273.         return $this;
  274.     }
  275. }