<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Criteria;
/**
* @ORM\Entity(repositoryClass="App\Repository\MediaGroupRepository")
*/
class MediaGroup
{
const TYPE_GENERAL = 1;
const TYPE_AD_GROUP = 2;
const TYPE_MENU_AD_GROUP = 3;
const TYPE_HEADER_AD_GROUP = 4;
const TYPE_AAR_AD_GROUP = 5;
const TYPE_VIDEO_AD_GROUP = 6;
const TYPE_POPOUT_AD_GROUP = 7;
const TYPE_CURTAIN_AD_GROUP = 8;
public function isAdGroup() {
return $this->getType() > 1;
}
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="bigint")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $title;
/**
* @ORM\Column(type="text")
*/
private $description;
/* *
* @ O R M\ManyToMany(targetEntity="App\Entity\Media", mappedBy="media_groups", cascade={"persist"})
* /
private $media;
*/
/**
* @ORM\Column(type="datetime")
*/
private $modifiedAt;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @ORM\OneToMany(targetEntity="App\Entity\MediaGroupItem", mappedBy="mediaGroup", orphanRemoval=true, cascade={"all"})
* @ORM\OrderBy({"sort" = "ASC"})
*/
private $mediaGroupItems;
/**
* @ORM\Column(type="integer")
*/
private $status;
/**
* @ORM\Column(type="text")
*/
private $attributes;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Customer", mappedBy="literature", cascade={"persist"})
*/
private $customer_literature;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Customer", mappedBy="photo_gallery", cascade={"persist"})
*/
private $customer_photo_gallery;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Customer", mappedBy="video_gallery", cascade={"persist"})
*/
private $customer_video_gallery;
/**
* @ORM\Column(type="integer")
*/
private $sort_type;
/**
* @ORM\Column(type="integer")
*/
private $display_limit;
/**
* @ORM\Column(type="string", length=255)
*/
private $position;
/**
* @ORM\Column(type="integer")
*/
private $type;
/**
* @ O R M \ Column(type="boolean")
* /
private $has_random_sort;
*/
/**
* @ORM\OneToMany(targetEntity="App\Entity\MediaGroupContainer", mappedBy="media_group", cascade={"persist"})
*/
private $media_group_containers;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Content", mappedBy="media_groups", cascade={"persist"})
*/
private $contents;
public function __construct()
{
$this->title = "";
$this->description = "";
$this->attributes = "";
$this->position = "";
$this->type = 1;
$this->contents = new ArrayCollection();
$this->media_group_containers = new ArrayCollection();
$this->mediaGroupItems = new ArrayCollection();
// $this->media = new ArrayCollection();
$this->modifiedAt = new \DateTime("now");
$this->createdAt = new \DateTime("now");
$this->sort_type = 1;
$this->display_limit = 0;
$this->status = 1;
}
public function getId()
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title = null): self
{
$this->title = $title ? $title : "";
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description = null): self
{
$this->description = $description ? $description : "";
return $this;
}
/* *
* @return Collection|Media[]
* /
public function getMedia(): Collection
{
return $this->media;
}
public function addMedia(Media $media): self
{
if (!$this->media->contains($media)) {
$this->media[] = $media;
$media->addMediaGroup($this);
}
return $this;
}
public function setMedia (ArrayCollection $media): self
{
for ($i = 0; $i < count ($media); $i++) {
$this->addMedia($media[$i]);
}
return $this;
}
public function removeMedia(Media $media): self
{
if ($this->media->contains($media)) {
$this->media->removeElement($media);
$media->removeMediaGroup($this);
}
return $this;
}
*/
public function getModifiedAt(): ?\DateTimeInterface
{
return $this->modifiedAt;
}
public function setModifiedAt(\DateTimeInterface $modifiedAt = null): self
{
$this->modifiedAt = $modifiedAt;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt = null): self
{
$this->createdAt = $createdAt;
return $this;
}
public function __toString ()
{
return $this->title ? $this->title : "";
}
public function sortBy ($type = ""): self
{
/*
//When called from RCSExtension, this is causing all the media group items to be deleted...
//Needs further research, but for now just shuffling after getting the items
switch (strtolower($type)) {
case "random":
$temp = $this->getMediaGroupItems()->toArray();
shuffle($temp);
$this->setMediaGroupItems(new ArrayCollection($temp));
break;
}
*/
return $this;
}
/**
* @return Collection|MediaGroupItem[]
*/
public function getMediaGroupItems(): Collection
{
return $this->mediaGroupItems;
}
public function addMediaGroupItem(MediaGroupItem $mediaGroupItem): self
{
if (!$this->mediaGroupItems->contains($mediaGroupItem)) {
$this->mediaGroupItems[] = $mediaGroupItem;
$mediaGroupItem->setMediaGroup($this);
}
return $this;
}
public function setMediaGroupItems (Collection $mediaGroupItems):self
{
$this->mediaGroupItems = $mediaGroupItems;
return $this;
}
public function removeMediaGroupItem(MediaGroupItem $mediaGroupItem): self
{
if ($this->mediaGroupItems->contains($mediaGroupItem)) {
$this->mediaGroupItems->removeElement($mediaGroupItem);
// set the owning side to null (unless already changed)
if ($mediaGroupItem->getMediaGroup() === $this) {
$mediaGroupItem->setMediaGroup(null);
}
}
return $this;
}
public function getActiveMediaGroupItems(): Collection
{
$criteria = Criteria::create()
->where(Criteria::expr()->eq("status", "1"))
//->orderBy(["sort" => Criteria::DESC])
;
return $this->mediaGroupItems->matching($criteria);
}
public function getMediaGroupItemsBySiteId($site_id)
{
$items = $this->mediaGroupItems;
$return = [];
foreach($items as $item) {
foreach($item->getSite() as $site) {
if($site->getId() == $site_id) {
$return[] = $item;
continue;
}
}
}
return $return;
}
public function getActiveMediaGroupItemsBySiteId($site_id)
{
$items = $this->mediaGroupItems;
$return = [];
foreach($items as $item) {
if($item->getStatus() == 1) {
foreach($item->getSite() as $site) {
if($site->getId() == $site_id) {
$return[] = $item;
continue;
}
}
}
}
return $return;
}
public function getMediaGroupItemsForGallery(): Collection
{
$criteria = Criteria::create()
->where(Criteria::expr()->eq("status", 1))
->orderBy(["published_at" => Criteria::DESC])
;
return $this->mediaGroupItems->matching($criteria);
}
public function getMediaGroupItemsForDirectoryPreview(): Collection
{
$criteria = Criteria::create()
->where(Criteria::expr()->eq("status", 1))
->orderBy(["published_at" => Criteria::DESC])
->setMaxResults(5)
;
return $this->mediaGroupItems->matching($criteria);
}
public function getFirstPublishedActiveMediaGroupItem($site_id = ""): ?MediaGroupItem
{
$criteria = Criteria::create()
->where(Criteria::expr()->eq("status", "1"))
->orderBy(["published_at" => Criteria::ASC])
;
$items = $this->mediaGroupItems->matching($criteria);
if($site_id) {
foreach($items as $item) {
foreach($item->getSite() as $site) {
if($site->getId() == $site_id) {
return $item;
}
}
}
return null;
}
$item = $items->first();
return $item ? $item : null;
}
public function getStatus(): ?int
{
return $this->status;
}
public function setStatus(int $status): self
{
$this->status = $status;
return $this;
}
public function getAttributes(): ?string
{
return $this->attributes;
}
public function setAttributes(string $attributes = null): self
{
$this->attributes = $attributes ? $attributes : null;
return $this;
}
public function getCustomerLiterature(): ?Customer
{
return $this->customer_literature;
}
public function setCustomerLiterature(?Customer $customer_literature): self
{
$this->customer_literature = $customer_literature;
// set (or unset) the owning side of the relation if necessary
$newLiterature = $customer_literature === null ? null : $this;
if ($newLiterature !== $customer_literature->getLiterature()) {
$customer_literature->setLiterature($newLiterature);
}
return $this;
}
public function getCustomerPhotoGallery(): ?Customer
{
return $this->customer_photo_gallery;
}
public function setCustomerPhotoGallery(?Customer $customer_photo_gallery): self
{
$this->customer_photo_gallery = $customer_photo_gallery;
// set (or unset) the owning side of the relation if necessary
$newPhoto_gallery = $customer_photo_gallery === null ? null : $this;
if ($newPhoto_gallery !== $customer_photo_gallery->getPhotoGallery()) {
$customer_photo_gallery->setPhotoGallery($newPhoto_gallery);
}
return $this;
}
public function getCustomerVideoGallery(): ?Customer
{
return $this->customer_video_gallery;
}
public function setCustomerVideoGallery(?Customer $customer_video_gallery): self
{
$this->customer_video_gallery = $customer_video_gallery;
// set (or unset) the owning side of the relation if necessary
$newVideo_gallery = $customer_video_gallery === null ? null : $this;
if ($newVideo_gallery !== $customer_video_gallery->getVideoGallery()) {
$customer_video_gallery->setVideoGallery($newVideo_gallery);
}
return $this;
}
public function getSortType(): ?int
{
return $this->sort_type;
}
public function setSortType(int $sort_type): self
{
$this->sort_type = $sort_type;
return $this;
}
public function getDisplayLimit(): ?int
{
return $this->display_limit;
}
public function setDisplayLimit(int $display_limit): self
{
$this->display_limit = $display_limit;
return $this;
}
public function getPosition(): ?string
{
return $this->position;
}
public function setPosition(string $position = null): self
{
$this->position = $position ? $position : "";
return $this;
}
public function getType(): ?int
{
return $this->type;
}
public function setType(int $type): self
{
$this->type = $type;
return $this;
}
public function getMediaGroupContainers(): Collection
{
return $this->media_group_containers;
}
public function addMediaGroupContainer(MediaGroupContainer $media_group_container): self
{
if (!$this->media_group_containers->contains($media_group_container)) {
$this->media_group_containers[] = $media_group_container;
$media_group_container->setMediaGroup($this);
}
return $this;
}
public function removeMediaGroupContainer(MediaGroupContainer $media_group_container): self
{
if ($this->media_group_containers->contains($media_group_container)) {
$this->media_group_containers->removeElement($media_group_container);
// set the owning side to null (unless already changed)
if ($media_group_container->getMediaGroup() === $this) {
$media_group_container->setMediaGroup(null);
}
}
return $this;
}
public function getContents(): Collection
{
return $this->contents;
}
public function addContent(Content $content): self
{
if (!$this->contents->contains($content)) {
$this->contents[] = $content;
$content->addMediaGroup($this);
}
return $this;
}
public function removeContent(Content $content): self
{
if ($this->contents->contains($content)) {
$this->contents->removeElement($content);
$content->removeMediaGroup($this);
}
return $this;
}
public function setContents (Collection $contents): self
{
$this->contents = $contents;
return $this;
}
/*
public function getHasRandomSort(): ?bool
{
return $this->has_random_sort;
}
public function setHasRandomSort(bool $has_random_sort): self
{
$this->has_random_sort = $has_random_sort;
return $this;
}
*/
}