<?php namespace App\Entity; use App\Repository\SliderRepository; use App\Traits\DateTrait; use DateTimeInterface; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use JMS\Serializer\Annotation as Serializer; use JMS\Serializer\Annotation\Expose; use JMS\Serializer\Annotation\Groups; /** * @ORM\Entity(repositoryClass=SliderRepository::class) * * @Serializer\ExclusionPolicy("ALL") */ class Slider { /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") * * @Expose * @Groups({"slider"}) */ private $id; /** * @ORM\Column(type="string", length=255) * * @Expose * @Groups({"slider"}) */ private $title; /** * @ORM\OneToMany(targetEntity=SliderItem::class, mappedBy="slider", cascade={"persist","remove"}) * @ORM\OrderBy({"orderItem" = "ASC"}) */ private $items; /** * @ORM\Column(type="datetime", nullable=true) * * @Expose * @Groups({"slider"}) */ private $dateStart; /** * @ORM\Column(type="datetime", nullable=true) * * @Expose * @Groups({"slider"}) */ private $dateEnd; /** * @ORM\Column(type="string", length=64) * * @Expose * @Groups({"slider"}) */ private $slug; /** * @ORM\Column(type="string", length=255) * * @Expose * @Groups({"slider"}) */ private $subdomain; use DateTrait; public function __construct() { $this->items = new ArrayCollection(); } public function __toString() { return $this->title; } /* * ============================================================================================ * =============================== FONCTIONS CUSTOM =========================================== * ============================================================================================ */ public function getItemsNumber() { return count( $this->getItems() ); } /* * ============================================================================================ * ============================== FIN FONCTIONS CUSTOM ======================================== * ============================================================================================ */ /** * @return Collection|SliderItem[] */ public function getItems(): Collection { return $this->items; } public function getId(): ?int { return $this->id; } public function getTitle(): ?string { return $this->title; } public function setTitle( string $title ): self { $this->title = $title; return $this; } public function addSliderItem( SliderItem $sliderItem ): self { if ( !$this->items->contains( $sliderItem ) ) { $this->items[] = $sliderItem; $sliderItem->setSlider( $this ); } return $this; } public function removeSliderItem( SliderItem $sliderItem ): self { if ( $this->items->removeElement( $sliderItem ) ) { // set the owning side to null (unless already changed) if ( $sliderItem->getSlider() === $this ) { $sliderItem->setSlider( NULL ); } } return $this; } public function addItem( SliderItem $item ): self { if ( !$this->items->contains( $item ) ) { $this->items[] = $item; $item->setSlider( $this ); } return $this; } public function removeItem( SliderItem $item ): self { if ( $this->items->removeElement( $item ) ) { // set the owning side to null (unless already changed) if ( $item->getSlider() === $this ) { $item->setSlider( NULL ); } } return $this; } public function getDateStart(): ?DateTimeInterface { return $this->dateStart; } public function setDateStart( ?DateTimeInterface $dateStart ): self { $this->dateStart = $dateStart; return $this; } public function getDateEnd(): ?DateTimeInterface { return $this->dateEnd; } public function setDateEnd( ?DateTimeInterface $dateEnd ): self { $this->dateEnd = $dateEnd; return $this; } public function getSlug(): ?string { return $this->slug; } public function setSlug( string $slug ): self { $this->slug = $slug; return $this; } public function getSubdomain(): ?string { return $this->subdomain; } public function setSubdomain(string $subdomain): self { $this->subdomain = $subdomain; return $this; } }