src/Entity/Media/Album.php line 27

Open in your IDE?
  1. <?php
  2. /*
  3.  * @since 1.0.0
  4.  * @copyright Copyright (C) 2021 ArtMedia. All rights reserved.
  5.  * @website http://artmedia.biz.pl
  6.  * @author Arkadiusz Tobiasz
  7.  * @email kontakt@artmedia.biz.pl
  8.  */
  9. namespace App\Entity\Media;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use App\Entity\Profile;
  12. use App\Entity\Core\Configuration;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. use App\Entity\Traits\BaseEntity;
  15. use Doctrine\Common\Collections\ArrayCollection;
  16. use Doctrine\Common\Collections\Collection;
  17. use Knp\DoctrineBehaviors\Contract\Entity\SluggableInterface;
  18. use Knp\DoctrineBehaviors\Model\Sluggable\SluggableTrait;
  19. /**
  20.  * @ORM\Entity(repositoryClass="App\Repository\Media\AlbumRepository")
  21.  * @ORM\Table(name="media_album", uniqueConstraints={@ORM\UniqueConstraint(columns={"profile_id", "title"}),@ORM\UniqueConstraint(columns={"profile_id", "slug"})})
  22.  */
  23. class Album implements SluggableInterface
  24. {
  25.     use SluggableTrait;
  26.     use BaseEntity;
  27.     /**
  28.      * @var int
  29.      *
  30.      * @ORM\Id
  31.      * @ORM\GeneratedValue
  32.      * @ORM\Column(type="integer")
  33.      */
  34.     private $id;
  35.     /**
  36.      * @var string
  37.      *
  38.      * @ORM\Column(type="string")
  39.      * @Assert\NotBlank()
  40.      */
  41.     private $title;
  42.     /**
  43.      * @ORM\Column(type="text", nullable=true)
  44.      */
  45.     private $description;
  46.     /**
  47.      * @var Profile
  48.      * 
  49.      * @ORM\ManyToOne(targetEntity="App\Entity\Profile", inversedBy="albums")
  50.      * @ORM\JoinColumn(name="profile_id", referencedColumnName="id", nullable=false)
  51.      */
  52.     protected $profile;
  53.     /**
  54.      * @var AlbumMedia[]|ArrayCollection
  55.      * 
  56.      * @ORM\OneToMany(
  57.      *      targetEntity="App\Entity\Media\AlbumMedia",
  58.      *      mappedBy="album",
  59.      *      cascade={"persist"}
  60.      * )
  61.      */
  62.     private $media;
  63.     /**
  64.      * @var boolean
  65.      *
  66.      * @ORM\Column(type="boolean", nullable=true, options={"default": 0})
  67.      */
  68.     private $portfolio false;
  69.     /**
  70.      * @var AlbumCover
  71.      * 
  72.      * @ORM\OneToOne(targetEntity="App\Entity\Media\AlbumCover", mappedBy="album", cascade={"persist"})
  73.      */
  74.     protected $cover;
  75.     public function __construct()
  76.     {
  77.         $this->media = new ArrayCollection();
  78.         $this->portfolio false;
  79.     }
  80.     public function getId(): ?int
  81.     {
  82.         return $this->id;
  83.     }
  84.     public function getTitle(): ?string
  85.     {
  86.         return $this->title;
  87.     }
  88.     public function setTitle(string $title): self
  89.     {
  90.         $this->title $title;
  91.         return $this;
  92.     }
  93.     public function getDescription(): ?string
  94.     {
  95.         return $this->description;
  96.     }
  97.     public function setDescription(string $description): self
  98.     {
  99.         $this->description $description;
  100.         return $this;
  101.     }
  102.     
  103.     public function setProfile(Profile $profile): self
  104.     {
  105.         $this->profile $profile;
  106.         return $this;
  107.     }
  108.     public function getProfile(): ?Profile
  109.     {
  110.         return $this->profile;
  111.     }
  112.     public function isPortfolio(): ?bool
  113.     {
  114.         return $this->portfolio;
  115.     }
  116.     public function setPortfolio(?bool $portfolio): self
  117.     {
  118.         $this->portfolio $portfolio;
  119.         return $this;
  120.     }
  121.     public function addMedia(AlbumMedia $media): self
  122.     {
  123.         $media->setAlbum($this);
  124.         if (!$this->media->contains($media)) {
  125.             $this->media->add($media);
  126.         }
  127.         return $this;
  128.     }
  129.     public function removeMedia(AlbumMedia $media): self
  130.     {
  131.         $this->media->removeElement($media);
  132.         return $this;
  133.     }
  134.     public function getAlbumsMedia(): Collection
  135.     {
  136.         return $this->media;
  137.     }
  138.     public function getMedia(): array
  139.     {
  140.         $media = [];
  141.         if ($this->media) {
  142.             foreach ($this->media as $item) {
  143.                 $media[$item->getSortOrder()] = $item->getMedia();
  144.             }
  145.             ksort($media);
  146.         }
  147.         return $media;
  148.     }
  149.     public function setCover(AlbumCover $cover): self
  150.     {
  151.         $this->cover $cover;
  152.         return $this;
  153.     }
  154.     public function getCover(): ?AlbumCover
  155.     {
  156.         return $this->cover;
  157.     }
  158.     /**
  159.      * @return string[]
  160.      */
  161.     public function getSluggableFields(): array
  162.     {
  163.         return ['title'];
  164.     }
  165. }