src/Entity/Slider.php line 29

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\ActiveTrait;
  4. use App\Entity\Traits\DeleteTrait;
  5. use App\Entity\Traits\LinkTrait;
  6. use App\Entity\Traits\MetaTrait;
  7. use App\Entity\Traits\TitleAndContentTrait;
  8. use App\Entity\Traits\TranslateTrait;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Gedmo\Mapping\Annotation as Gedmo;
  13. use Gedmo\Timestampable\Traits\TimestampableEntity;
  14. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  15. /**
  16.  * Slider.
  17.  *
  18.  * @Gedmo\Loggable
  19.  *
  20.  * @Gedmo\TranslationEntity(class="App\Entity\SliderTranslations")
  21.  */
  22. #[UniqueEntity(fields: ['identifier'], errorPath'identifier'message'A slider has already be created with that identifier.')]
  23. #[ORM\Entity(repositoryClass\App\Repository\SliderRepository::class)]
  24. #[ORM\HasLifecycleCallbacks]
  25. #[ORM\Table(name'slider')]
  26. class Slider
  27. {
  28.     use TitleAndContentTrait;
  29.     use LinkTrait;
  30.     use MetaTrait;
  31.     use ActiveTrait;
  32.     use DeleteTrait;
  33.     use TimestampableEntity;
  34.     use TranslateTrait;
  35.     #[ORM\Column(name'id'type'integer')]
  36.     #[ORM\Id]
  37.     #[ORM\GeneratedValue(strategy'AUTO')]
  38.     private int $id;
  39.     #[ORM\Column(name'identifier'type'string'length255)]
  40.     private ?string $identifier null;
  41.     #[ORM\OneToMany(targetEntity'SliderImages'mappedBy'slider')]
  42.     #[ORM\OrderBy(['position' => 'ASC'])]
  43.     private Collection $images;
  44.     #[ORM\ManyToMany(targetEntity\App\Entity\Page::class, inversedBy'slider')]
  45.     private Collection $pages;
  46.     /**
  47.      * Constructor.
  48.      */
  49.     public function __construct()
  50.     {
  51.         $this->images = new ArrayCollection();
  52.         $this->pages = new ArrayCollection();
  53.     }
  54.     public function getFilePath(): string
  55.     {
  56.         return 'userfiles/images/slider';
  57.     }
  58.     /**
  59.      * Get id.
  60.      *
  61.      * @return int
  62.      */
  63.     public function getId()
  64.     {
  65.         return $this->id;
  66.     }
  67.     /**
  68.      * Set identifier.
  69.      *
  70.      * @param string $identifier
  71.      *
  72.      * @return Slider
  73.      */
  74.     public function setIdentifier($identifier)
  75.     {
  76.         $this->identifier $identifier;
  77.         return $this;
  78.     }
  79.     /**
  80.      * Get identifier.
  81.      *
  82.      * @return string
  83.      */
  84.     public function getIdentifier()
  85.     {
  86.         return $this->identifier;
  87.     }
  88.     /**
  89.      * Add images.
  90.      *
  91.      * @return Slider
  92.      */
  93.     public function addImage(SliderImages $images)
  94.     {
  95.         $this->images[] = $images;
  96.         return $this;
  97.     }
  98.     /**
  99.      * Remove images.
  100.      */
  101.     public function removeImage(SliderImages $images)
  102.     {
  103.         $this->images->removeElement($images);
  104.     }
  105.     /**
  106.      * Get images.
  107.      *
  108.      * @return ArrayCollection
  109.      */
  110.     public function getImages()
  111.     {   $activeImages = [];
  112.         foreach ($this->images as $image) {
  113.             if (! $image->isDeleted()) {
  114.                 $activeImages[] = $image;
  115.             }
  116.         }
  117.         return $this->images;
  118.     }
  119.     public function getActiveImages()
  120.     {
  121.         return $this->images;
  122.     }
  123.     /**
  124.      * Add pages.
  125.      *
  126.      * @return Slider
  127.      */
  128.     public function addPage(Page $page)
  129.     {
  130.         $this->pages[] = $page;
  131.         return $this;
  132.     }
  133.     /**
  134.      * Remove pages.
  135.      */
  136.     public function removePage(Page $page)
  137.     {
  138.         $this->pages->removeElement($page);
  139.     }
  140.     /**
  141.      * Get pages.
  142.      *
  143.      * @return ArrayCollection
  144.      */
  145.     public function getPages()
  146.     {
  147.         return $this->pages;
  148.     }
  149.     // REQUIRED BY THE META LINKS TRAIT - NOT REALLY NEEDED HERE BUT WHATEVS :)
  150.     public function getLinkedPageId(): int
  151.     {
  152.         return 1;
  153.     }
  154. }