src/Entity/Gallery.php line 9

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Sonata\MediaBundle\Entity\BaseGallery;
  6. class Gallery {
  7.     /**
  8.      * @var int
  9.      */
  10.     private $id;
  11.     /**
  12.      * @var int
  13.      */
  14.     private $ownerID;
  15.     /**
  16.      * @var string
  17.      */
  18.     private $context;
  19.     /**
  20.      * @var string
  21.      */
  22.     private $name;
  23.     /**
  24.      * @var boolean
  25.      */
  26.     private $enabled;
  27.     /**
  28.      * @var \DateTime
  29.      */
  30.     private $updatedAt;
  31.     /**
  32.      * @var \DateTime
  33.      */
  34.     private $createdAt;
  35.     /**
  36.      * @var string
  37.      */
  38.     private $defaultFormat 'reference';
  39.     /**
  40.      * @var \Doctrine\Common\Collections\Collection
  41.      */
  42.     private $galleryItems;
  43.     public function __construct() {
  44.         $this->galleryItems = new ArrayCollection();
  45.     }
  46.     /**
  47.      * Get id
  48.      *
  49.      * @return integer
  50.      */
  51.     public function getId() {
  52.         return $this->id;
  53.     }
  54.     /**
  55.      * Set ownerID
  56.      *
  57.      * @param integer $ownerID
  58.      *
  59.      * @return Gallery
  60.      */
  61.     public function setOwnerID($ownerID) {
  62.         $this->ownerID $ownerID;
  63.         return $this;
  64.     }
  65.     /**
  66.      * Get ownerID
  67.      *
  68.      * @return integer
  69.      */
  70.     public function getOwnerID() {
  71.         return $this->ownerID;
  72.     }
  73.     public function setName($name) {
  74.         $this->name $name;
  75.     }
  76.     public function getName() {
  77.         return $this->name;
  78.     }
  79.     public function setContext($context) {
  80.         $this->context $context;
  81.     }
  82.     public function getContext() {
  83.         return $this->context;
  84.     }
  85.     public function setEnabled($enabled) {
  86.         $this->enabled $enabled;
  87.     }
  88.     public function getEnabled() {
  89.         return $this->enabled;
  90.     }
  91.     public function setUpdatedAt($updatedAt) {
  92.         $this->updatedAt $updatedAt;
  93.     }
  94.     public function getUpdatedAt() {
  95.         return $this->updatedAt;
  96.     }
  97.     public function setCreatedAt($createdAt) {
  98.         $this->createdAt $createdAt;
  99.     }
  100.     public function getCreatedAt() {
  101.         return $this->createdAt;
  102.     }
  103.     public function setDefaultFormat($defaultFormat) {
  104.         $this->defaultFormat $defaultFormat;
  105.     }
  106.     public function getDefaultFormat() {
  107.         return $this->defaultFormat;
  108.     }
  109.     public function setGalleryItems($galleryItems) {
  110.         $this->galleryItems->clear();
  111.         foreach ($galleryItems as $galleryItem) {
  112.             $this->addGalleryItem($galleryItem);
  113.         }
  114.     }
  115.     public function getGalleryItems() {
  116.         return $this->galleryItems;
  117.     }
  118.     public function addGalleryItem($galleryItem) {
  119.         $galleryItem->setGallery($this);
  120.         $this->galleryItems[] = $galleryItem;
  121.     }
  122.     public function removeGalleryItem($galleryItem) {
  123.         if ($this->galleryItems->contains($galleryItem)) {
  124.             $this->galleryItems->removeElement($galleryItem);
  125.         }
  126.     }
  127.     public function reorderGalleryItems() {
  128.         $iterator $this->getGalleryItems()->getIterator();
  129.         if (!$iterator instanceof \ArrayIterator) {
  130.             throw new \RuntimeException(sprintf(
  131.                                     'The gallery %s cannot be reordered, $galleryItems should implement %s',
  132.                                     $this->getId() ?? '',
  133.                                     \ArrayIterator::class
  134.             ));
  135.         }
  136.         $iterator->uasort(static function ($a$b): int {
  137.             return $a->getPosition() <=> $b->getPosition();
  138.         });
  139.         $this->setGalleryItems($iterator);
  140.     }
  141.     /**
  142.      * @var \App\Entity\MediaGalleryCategory
  143.      */
  144.     private $mediaGalleryCategory;
  145.     /**
  146.      * Set mediaGalleryCategory.
  147.      *
  148.      * @param \App\Entity\MediaGalleryCategory|null $mediaGalleryCategory
  149.      *
  150.      * @return Gallery
  151.      */
  152.     public function setMediaGalleryCategory(\App\Entity\MediaGalleryCategory $mediaGalleryCategory null) {
  153.         $this->mediaGalleryCategory $mediaGalleryCategory;
  154.         return $this;
  155.     }
  156.     /**
  157.      * Get mediaGalleryCategory.
  158.      *
  159.      * @return \App\Entity\MediaGalleryCategory|null
  160.      */
  161.     public function getMediaGalleryCategory() {
  162.         return $this->mediaGalleryCategory;
  163.     }
  164.     public function __toString() {
  165.         return $this->getName() ?? '-';
  166.     }
  167. }