src/Entity/MediaGroup.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Doctrine\Common\Collections\Criteria;
  7. /**
  8.  * @ORM\Entity(repositoryClass="App\Repository\MediaGroupRepository")
  9.  */
  10. class MediaGroup
  11. {
  12.     
  13.     const TYPE_GENERAL 1;
  14.     const TYPE_AD_GROUP 2;
  15.     const TYPE_MENU_AD_GROUP 3;
  16.     const TYPE_HEADER_AD_GROUP 4;
  17.     const TYPE_AAR_AD_GROUP 5;
  18.     const TYPE_VIDEO_AD_GROUP 6;
  19.     const TYPE_POPOUT_AD_GROUP 7;
  20.     const TYPE_CURTAIN_AD_GROUP 8;
  21.     
  22.     public function isAdGroup() {
  23.         return $this->getType() > 1;
  24.     }
  25.     
  26.     /**
  27.      * @ORM\Id()
  28.      * @ORM\GeneratedValue()
  29.      * @ORM\Column(type="bigint")
  30.      */
  31.     private $id;
  32.     /**
  33.      * @ORM\Column(type="string", length=255)
  34.      */
  35.     private $title;
  36.     /**
  37.      * @ORM\Column(type="text")
  38.      */
  39.     private $description;
  40.     /* *
  41.      * @ O R M\ManyToMany(targetEntity="App\Entity\Media", mappedBy="media_groups", cascade={"persist"})
  42.      * /
  43.     private $media;
  44.     */
  45.     /**
  46.      * @ORM\Column(type="datetime")
  47.      */
  48.     private $modifiedAt;
  49.     /**
  50.      * @ORM\Column(type="datetime")
  51.      */
  52.     private $createdAt;
  53.     /**
  54.      * @ORM\OneToMany(targetEntity="App\Entity\MediaGroupItem", mappedBy="mediaGroup", orphanRemoval=true, cascade={"all"})
  55.      * @ORM\OrderBy({"sort" = "ASC"})
  56.      */
  57.     private $mediaGroupItems;
  58.     /**
  59.      * @ORM\Column(type="integer")
  60.      */
  61.     private $status;
  62.     /**
  63.      * @ORM\Column(type="text")
  64.      */
  65.     private $attributes;
  66.     /**
  67.      * @ORM\OneToOne(targetEntity="App\Entity\Customer", mappedBy="literature", cascade={"persist"})
  68.      */
  69.     private $customer_literature;
  70.     /**
  71.      * @ORM\OneToOne(targetEntity="App\Entity\Customer", mappedBy="photo_gallery", cascade={"persist"})
  72.      */
  73.     private $customer_photo_gallery;
  74.     /**
  75.      * @ORM\OneToOne(targetEntity="App\Entity\Customer", mappedBy="video_gallery", cascade={"persist"})
  76.      */
  77.     private $customer_video_gallery;
  78.     /**
  79.      * @ORM\Column(type="integer")
  80.      */
  81.     private $sort_type;
  82.     
  83.     /**
  84.      * @ORM\Column(type="integer")
  85.      */
  86.     private $display_limit;
  87.     /**
  88.      * @ORM\Column(type="string", length=255)
  89.      */
  90.     private $position;
  91.     /**
  92.      * @ORM\Column(type="integer")
  93.      */
  94.     private $type;
  95.     
  96.     /**
  97.      * @ O R M \ Column(type="boolean")
  98.      * /
  99.     private $has_random_sort;
  100.     */
  101.     
  102.     /**
  103.      * @ORM\OneToMany(targetEntity="App\Entity\MediaGroupContainer", mappedBy="media_group", cascade={"persist"})
  104.      */
  105.     private $media_group_containers;
  106.     
  107.     /**
  108.      * @ORM\ManyToMany(targetEntity="App\Entity\Content", mappedBy="media_groups", cascade={"persist"})
  109.      */
  110.     private $contents;
  111.     public function __construct()
  112.     {
  113.         $this->title "";
  114.         $this->description "";
  115.         $this->attributes "";
  116.         $this->position "";
  117.         $this->type 1;
  118.         
  119.         $this->contents = new ArrayCollection();
  120.         $this->media_group_containers = new ArrayCollection();
  121.         $this->mediaGroupItems = new ArrayCollection();
  122.         // $this->media = new ArrayCollection();
  123.         $this->modifiedAt = new \DateTime("now");
  124.         $this->createdAt = new \DateTime("now");
  125.         $this->sort_type 1;
  126.         $this->display_limit 0;
  127.         $this->status 1;
  128.     }
  129.     public function getId()
  130.     {
  131.         return $this->id;
  132.     }
  133.     public function getTitle(): ?string
  134.     {
  135.         return $this->title;
  136.     }
  137.     public function setTitle(string $title null): self
  138.     {
  139.         $this->title $title $title "";
  140.         return $this;
  141.     }
  142.     public function getDescription(): ?string
  143.     {
  144.         return $this->description;
  145.     }
  146.     public function setDescription(string $description null): self
  147.     {
  148.         $this->description $description $description "";
  149.         return $this;
  150.     }
  151.     /* *
  152.      * @return Collection|Media[]
  153.      * /
  154.     public function getMedia(): Collection
  155.     {
  156.         return $this->media;
  157.     }
  158.     public function addMedia(Media $media): self
  159.     {
  160.         if (!$this->media->contains($media)) {
  161.             $this->media[] = $media;
  162.             $media->addMediaGroup($this);
  163.         }
  164.         return $this;
  165.     }
  166.     
  167.     public function setMedia (ArrayCollection $media): self
  168.     {
  169.         for ($i = 0; $i < count ($media); $i++) {
  170.             $this->addMedia($media[$i]);
  171.         }
  172.         
  173.         return $this;
  174.     }
  175.     public function removeMedia(Media $media): self
  176.     {
  177.         if ($this->media->contains($media)) {
  178.             $this->media->removeElement($media);
  179.             $media->removeMediaGroup($this);
  180.         }
  181.         return $this;
  182.     }
  183.     */
  184.     public function getModifiedAt(): ?\DateTimeInterface
  185.     {
  186.         return $this->modifiedAt;
  187.     }
  188.     public function setModifiedAt(\DateTimeInterface $modifiedAt null): self
  189.     {
  190.         $this->modifiedAt $modifiedAt;
  191.         return $this;
  192.     }
  193.     public function getCreatedAt(): ?\DateTimeInterface
  194.     {
  195.         return $this->createdAt;
  196.     }
  197.     public function setCreatedAt(\DateTimeInterface $createdAt null): self
  198.     {
  199.         $this->createdAt $createdAt;
  200.         return $this;
  201.     }
  202.     
  203.     public function __toString ()
  204.     {
  205.         return $this->title $this->title "";
  206.     }
  207.     
  208.     public function sortBy ($type ""): self
  209.     {
  210.         /*
  211.         //When called from RCSExtension, this is causing all the media group items to be deleted...
  212.         //Needs further research, but for now just shuffling after getting the items
  213.         switch (strtolower($type)) {
  214.             case "random": 
  215.                 $temp = $this->getMediaGroupItems()->toArray();
  216.                 shuffle($temp);
  217.                 $this->setMediaGroupItems(new ArrayCollection($temp));
  218.                 break;
  219.         }
  220.         */
  221.         
  222.         return $this;
  223.     }
  224.     /**
  225.      * @return Collection|MediaGroupItem[]
  226.      */
  227.     public function getMediaGroupItems(): Collection
  228.     {
  229.         return $this->mediaGroupItems;
  230.     }
  231.     public function addMediaGroupItem(MediaGroupItem $mediaGroupItem): self
  232.     {
  233.         if (!$this->mediaGroupItems->contains($mediaGroupItem)) {
  234.             $this->mediaGroupItems[] = $mediaGroupItem;
  235.             $mediaGroupItem->setMediaGroup($this);
  236.         }
  237.         return $this;
  238.     }
  239.     
  240.     public function setMediaGroupItems (Collection $mediaGroupItems):self
  241.     {
  242.         $this->mediaGroupItems $mediaGroupItems;
  243.         return $this;
  244.     }
  245.     public function removeMediaGroupItem(MediaGroupItem $mediaGroupItem): self
  246.     {
  247.         if ($this->mediaGroupItems->contains($mediaGroupItem)) {
  248.             $this->mediaGroupItems->removeElement($mediaGroupItem);
  249.             // set the owning side to null (unless already changed)
  250.             if ($mediaGroupItem->getMediaGroup() === $this) {
  251.                 $mediaGroupItem->setMediaGroup(null);
  252.             }
  253.         }
  254.         return $this;
  255.     }
  256.     
  257.     public function getActiveMediaGroupItems(): Collection
  258.     {
  259.         $criteria Criteria::create()
  260.             ->where(Criteria::expr()->eq("status""1"))
  261.             //->orderBy(["sort" => Criteria::DESC])
  262.         ;
  263.         
  264.         return $this->mediaGroupItems->matching($criteria);
  265.     }
  266.     
  267.     public function getMediaGroupItemsBySiteId($site_id)
  268.     {
  269.         $items $this->mediaGroupItems;
  270.         $return = [];
  271.         foreach($items as $item) {
  272.             foreach($item->getSite() as $site) {
  273.                 if($site->getId() == $site_id) {
  274.                     $return[] = $item;
  275.                     continue;
  276.                 }
  277.             }
  278.         }
  279.         
  280.         return $return;
  281.     }
  282.     
  283.     public function getActiveMediaGroupItemsBySiteId($site_id)
  284.     {
  285.         $items $this->mediaGroupItems;
  286.         $return = [];
  287.         foreach($items as $item) {
  288.             if($item->getStatus() == 1) {
  289.                 foreach($item->getSite() as $site) {
  290.                     if($site->getId() == $site_id) {
  291.                         $return[] = $item;
  292.                         continue;
  293.                     }
  294.                 }
  295.             }
  296.         }
  297.         
  298.         return $return;
  299.     }
  300.     
  301.     public function getMediaGroupItemsForGallery(): Collection
  302.     {
  303.         $criteria Criteria::create()
  304.             ->where(Criteria::expr()->eq("status"1))
  305.             ->orderBy(["published_at" => Criteria::DESC])
  306.         ;
  307.         
  308.         return $this->mediaGroupItems->matching($criteria);
  309.     }
  310.     
  311.     public function getMediaGroupItemsForDirectoryPreview(): Collection
  312.     {
  313.         $criteria Criteria::create()
  314.             ->where(Criteria::expr()->eq("status"1))
  315.             ->orderBy(["published_at" => Criteria::DESC])
  316.             ->setMaxResults(5)
  317.         ;
  318.         
  319.         return $this->mediaGroupItems->matching($criteria);
  320.     }
  321.     
  322.     public function getFirstPublishedActiveMediaGroupItem($site_id ""): ?MediaGroupItem
  323.     {
  324.         $criteria Criteria::create()
  325.             ->where(Criteria::expr()->eq("status""1"))
  326.             ->orderBy(["published_at" => Criteria::ASC])
  327.         ;
  328.         
  329.         $items $this->mediaGroupItems->matching($criteria);
  330.         if($site_id) {
  331.             foreach($items as $item) {
  332.                 foreach($item->getSite() as $site) {
  333.                     if($site->getId() == $site_id) {
  334.                         return $item;
  335.                     }
  336.                 }
  337.             }
  338.             return null;
  339.         }
  340.         
  341.         $item $items->first();
  342.         
  343.         return $item $item null;
  344.     }
  345.     public function getStatus(): ?int
  346.     {
  347.         return $this->status;
  348.     }
  349.     public function setStatus(int $status): self
  350.     {
  351.         $this->status $status;
  352.         return $this;
  353.     }
  354.     public function getAttributes(): ?string
  355.     {
  356.         return $this->attributes;
  357.     }
  358.     public function setAttributes(string $attributes null): self
  359.     {
  360.         $this->attributes $attributes $attributes null;
  361.         return $this;
  362.     }
  363.     public function getCustomerLiterature(): ?Customer
  364.     {
  365.         return $this->customer_literature;
  366.     }
  367.     public function setCustomerLiterature(?Customer $customer_literature): self
  368.     {
  369.         $this->customer_literature $customer_literature;
  370.         // set (or unset) the owning side of the relation if necessary
  371.         $newLiterature $customer_literature === null null $this;
  372.         if ($newLiterature !== $customer_literature->getLiterature()) {
  373.             $customer_literature->setLiterature($newLiterature);
  374.         }
  375.         return $this;
  376.     }
  377.     public function getCustomerPhotoGallery(): ?Customer
  378.     {
  379.         return $this->customer_photo_gallery;
  380.     }
  381.     public function setCustomerPhotoGallery(?Customer $customer_photo_gallery): self
  382.     {
  383.         $this->customer_photo_gallery $customer_photo_gallery;
  384.         // set (or unset) the owning side of the relation if necessary
  385.         $newPhoto_gallery $customer_photo_gallery === null null $this;
  386.         if ($newPhoto_gallery !== $customer_photo_gallery->getPhotoGallery()) {
  387.             $customer_photo_gallery->setPhotoGallery($newPhoto_gallery);
  388.         }
  389.         return $this;
  390.     }
  391.     public function getCustomerVideoGallery(): ?Customer
  392.     {
  393.         return $this->customer_video_gallery;
  394.     }
  395.     public function setCustomerVideoGallery(?Customer $customer_video_gallery): self
  396.     {
  397.         $this->customer_video_gallery $customer_video_gallery;
  398.         // set (or unset) the owning side of the relation if necessary
  399.         $newVideo_gallery $customer_video_gallery === null null $this;
  400.         if ($newVideo_gallery !== $customer_video_gallery->getVideoGallery()) {
  401.             $customer_video_gallery->setVideoGallery($newVideo_gallery);
  402.         }
  403.         return $this;
  404.     }
  405.     public function getSortType(): ?int
  406.     {
  407.         return $this->sort_type;
  408.     }
  409.     public function setSortType(int $sort_type): self
  410.     {
  411.         $this->sort_type $sort_type;
  412.         
  413.         return $this;
  414.     }
  415.     
  416.     public function getDisplayLimit(): ?int
  417.     {
  418.         return $this->display_limit;
  419.     }
  420.     public function setDisplayLimit(int $display_limit): self
  421.     {
  422.         $this->display_limit $display_limit;
  423.         
  424.         return $this;
  425.     }
  426.     public function getPosition(): ?string
  427.     {
  428.         return $this->position;
  429.     }
  430.     public function setPosition(string $position null): self
  431.     {
  432.         $this->position $position $position "";
  433.         return $this;
  434.     }
  435.     public function getType(): ?int
  436.     {
  437.         return $this->type;
  438.     }
  439.     public function setType(int $type): self
  440.     {
  441.         $this->type $type;
  442.         return $this;
  443.     }
  444.     
  445.     
  446.     public function getMediaGroupContainers(): Collection
  447.     {
  448.         return $this->media_group_containers;
  449.     }
  450.     public function addMediaGroupContainer(MediaGroupContainer $media_group_container): self
  451.     {
  452.         if (!$this->media_group_containers->contains($media_group_container)) {
  453.             $this->media_group_containers[] = $media_group_container;
  454.             $media_group_container->setMediaGroup($this);
  455.         }
  456.         return $this;
  457.     }
  458.     public function removeMediaGroupContainer(MediaGroupContainer $media_group_container): self
  459.     {
  460.         if ($this->media_group_containers->contains($media_group_container)) {
  461.             $this->media_group_containers->removeElement($media_group_container);
  462.             // set the owning side to null (unless already changed)
  463.             if ($media_group_container->getMediaGroup() === $this) {
  464.                 $media_group_container->setMediaGroup(null);
  465.             }
  466.         }
  467.         return $this;
  468.     }
  469.     
  470.     
  471.     
  472.     
  473.     public function getContents(): Collection
  474.     {
  475.         return $this->contents;
  476.     }
  477.     
  478.     public function addContent(Content $content): self
  479.     {
  480.         if (!$this->contents->contains($content)) {
  481.             $this->contents[] = $content;
  482.             $content->addMediaGroup($this);
  483.         }
  484.         
  485.         return $this;
  486.     }
  487.     
  488.     public function removeContent(Content $content): self
  489.     {
  490.      if ($this->contents->contains($content)) {
  491.          $this->contents->removeElement($content);
  492.          $content->removeMediaGroup($this);
  493.      }
  494.      
  495.      return $this;
  496.     }
  497.     
  498.     public function setContents (Collection $contents): self
  499.     {
  500.         $this->contents $contents;
  501.         return $this;
  502.     }
  503.     
  504.     
  505.     
  506.     
  507.     
  508.     /*
  509.     public function getHasRandomSort(): ?bool
  510.     {
  511.         return $this->has_random_sort;
  512.     }
  513.     public function setHasRandomSort(bool $has_random_sort): self
  514.     {
  515.         $this->has_random_sort = $has_random_sort;
  516.         return $this;
  517.     }
  518.     */
  519.     
  520. }