<?php
/*
* @since 1.0.0
* @copyright Copyright (C) 2021 ArtMedia. All rights reserved.
* @website http://artmedia.biz.pl
* @author Arkadiusz Tobiasz
* @email kontakt@artmedia.biz.pl
*/
namespace App\Entity\Media;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Profile;
use App\Entity\Core\Configuration;
use Symfony\Component\Validator\Constraints as Assert;
use App\Entity\Traits\BaseEntity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Knp\DoctrineBehaviors\Contract\Entity\SluggableInterface;
use Knp\DoctrineBehaviors\Model\Sluggable\SluggableTrait;
/**
* @ORM\Entity(repositoryClass="App\Repository\Media\AlbumRepository")
* @ORM\Table(name="media_album", uniqueConstraints={@ORM\UniqueConstraint(columns={"profile_id", "title"}),@ORM\UniqueConstraint(columns={"profile_id", "slug"})})
*/
class Album implements SluggableInterface
{
use SluggableTrait;
use BaseEntity;
/**
* @var int
*
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @var string
*
* @ORM\Column(type="string")
* @Assert\NotBlank()
*/
private $title;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $description;
/**
* @var Profile
*
* @ORM\ManyToOne(targetEntity="App\Entity\Profile", inversedBy="albums")
* @ORM\JoinColumn(name="profile_id", referencedColumnName="id", nullable=false)
*/
protected $profile;
/**
* @var AlbumMedia[]|ArrayCollection
*
* @ORM\OneToMany(
* targetEntity="App\Entity\Media\AlbumMedia",
* mappedBy="album",
* cascade={"persist"}
* )
*/
private $media;
/**
* @var boolean
*
* @ORM\Column(type="boolean", nullable=true, options={"default": 0})
*/
private $portfolio = false;
/**
* @var AlbumCover
*
* @ORM\OneToOne(targetEntity="App\Entity\Media\AlbumCover", mappedBy="album", cascade={"persist"})
*/
protected $cover;
public function __construct()
{
$this->media = new ArrayCollection();
$this->portfolio = false;
}
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 getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function setProfile(Profile $profile): self
{
$this->profile = $profile;
return $this;
}
public function getProfile(): ?Profile
{
return $this->profile;
}
public function isPortfolio(): ?bool
{
return $this->portfolio;
}
public function setPortfolio(?bool $portfolio): self
{
$this->portfolio = $portfolio;
return $this;
}
public function addMedia(AlbumMedia $media): self
{
$media->setAlbum($this);
if (!$this->media->contains($media)) {
$this->media->add($media);
}
return $this;
}
public function removeMedia(AlbumMedia $media): self
{
$this->media->removeElement($media);
return $this;
}
public function getAlbumsMedia(): Collection
{
return $this->media;
}
public function getMedia(): array
{
$media = [];
if ($this->media) {
foreach ($this->media as $item) {
$media[$item->getSortOrder()] = $item->getMedia();
}
ksort($media);
}
return $media;
}
public function setCover(AlbumCover $cover): self
{
$this->cover = $cover;
return $this;
}
public function getCover(): ?AlbumCover
{
return $this->cover;
}
/**
* @return string[]
*/
public function getSluggableFields(): array
{
return ['title'];
}
}