<?php
namespace App\Entity\Music;
use App\Entity\Annotation\Annotation;
use App\Entity\EntityIdTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use InvalidArgumentException;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass="App\Repository\Music\ResourceRepository")
* @Vich\Uploadable()
*/
class Resource
{
use EntityIdTrait;
public const TYPE_MEI = 'mei';
public const TYPE_KERN = 'kern';
public const TYPE_HUMDRUM = 'humdrum';
public const TYPE_MUSICXML = 'musicxml';
public static function getTypes(): array
{
return [
self::TYPE_MEI,
self::TYPE_KERN,
self::TYPE_HUMDRUM,
self::TYPE_MUSICXML,
];
}
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank()
*/
private $name;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\Url()
* @Groups("resource:read")
*/
private $href;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Music\Opus", inversedBy="resources")
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
* @Groups("resource:read")
*/
private $opus;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank()
* @Groups("resource:read")
*/
private $type;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Annotation\Annotation", mappedBy="resource")
* @Groups("resource:read")
* @ORM\OrderBy({"createdAt" = "ASC"})
*/
private $annotations;
/**
* @Vich\UploadableField(mapping="resource_file", fileNameProperty="fileName")
*/
private $file;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*
* @var string
*/
private $fileName;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $updatedAt;
/**
* @ORM\Column(type="string", nullable=true, length=255)
* @Groups("resource:read")
*/
private $licence;
/**
* @ORM\Column(type="string", nullable=true, length=255)
* @Groups("resource:read")
*/
private $copyright;
/**
* @ORM\Column(type="string", nullable=true, length=255)
* @Groups("resource:read")
*/
private $projectUrl;
/**
* @ORM\Column(type="string", nullable=true, length=255)
* @Groups("resource:read")
*/
private $sourceUrl;
/**
* @ORM\Column(type="string", nullable=true, length=255)
* @Groups("resource:read")
*/
private $infoUrl;
/**
* @ORM\Column(type="string", nullable=true, length=255)
* @Groups("resource:read")
*/
private $originalDocument;
/**
* @ORM\Column(type="string", nullable=true, length=255)
* @Groups("resource:read")
*/
private $electronicEditor;
/**
* @ORM\Column(type="string", nullable=true, length=255)
* @Groups("resource:read")
*/
private $encoderOfElectronicDocument;
/**
* @ORM\Column(type="string", nullable=true, length=255)
* @Groups("resource:read")
*/
private $electronicEditionVersion;
/**
* @ORM\Column(type="string", nullable=true, length=255)
* @Groups("resource:read")
*/
private $publisherElectronicEdition;
public function __construct()
{
$this->annotations = new ArrayCollection();
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): void
{
$this->name = $name;
}
public function getHref(): ?string
{
return $this->href;
}
public function setHref(?string $href): void
{
$this->href = $href;
}
public function getOpus(): ?Opus
{
return $this->opus;
}
public function setOpus(Opus $opus): void
{
$this->opus = $opus;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): void
{
if (!\in_array($type, self::getTypes(), true)) {
throw new InvalidArgumentException('Invalid type');
}
$this->type = $type;
}
/**
* @return Collection|Annotation[]
*/
public function getAnnotations(): Collection
{
return $this->annotations;
}
public function addAnnotation(Annotation $annotation): void
{
if (!$this->annotations->contains($annotation)) {
$this->annotations[] = $annotation;
$annotation->setResource($this);
}
}
public function removeAnnotation(Annotation $annotation): void
{
if ($this->annotations->contains($annotation)) {
$this->annotations->removeElement($annotation);
// set the owning side to null (unless already changed)
if ($annotation->getResource() === $this) {
$annotation->setResource(null);
}
}
}
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $file
*/
public function setFile(?File $file = null): void
{
$this->file = $file;
if (null !== $file) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new \DateTimeImmutable();
}
}
public function getFile(): ?File
{
return $this->file;
}
public function setFileName(?string $fileName): void
{
$this->fileName = $fileName;
}
public function getFileName(): ?string
{
return $this->fileName;
}
public function getLicence(): ?string
{
return $this->licence;
}
public function setLicence(?string $licence): void
{
$this->licence = $licence;
}
public function getCopyright(): ?string
{
return $this->copyright;
}
public function setCopyright(?string $copyright): void
{
$this->copyright = $copyright;
}
public function getProjectUrl(): ?string
{
return $this->projectUrl;
}
public function setProjectUrl(?string $projectUrl): void
{
$this->projectUrl = $projectUrl;
}
public function getSourceUrl(): ?string
{
return $this->sourceUrl;
}
public function setSourceUrl(?string $sourceUrl): void
{
$this->sourceUrl = $sourceUrl;
}
public function getInfoUrl(): ?string
{
return $this->infoUrl;
}
public function setInfoUrl(?string $infoUrl): void
{
$this->infoUrl = $infoUrl;
}
public function getOriginalDocument(): ?string
{
return $this->originalDocument;
}
public function setOriginalDocument(?string $originalDocument): void
{
$this->originalDocument = $originalDocument;
}
public function getElectronicEditor(): ?string
{
return $this->electronicEditor;
}
public function setElectronicEditor(?string $electronicEditor): void
{
$this->electronicEditor = $electronicEditor;
}
public function getEncoderOfElectronicDocument(): ?string
{
return $this->encoderOfElectronicDocument;
}
public function setEncoderOfElectronicDocument(?string $encoderOfElectronicDocument): void
{
$this->encoderOfElectronicDocument = $encoderOfElectronicDocument;
}
public function getElectronicEditionVersion(): ?string
{
return $this->electronicEditionVersion;
}
public function setElectronicEditionVersion(?string $electronicEditionVersion): void
{
$this->electronicEditionVersion = $electronicEditionVersion;
}
public function getPublisherElectronicEdition(): ?string
{
return $this->publisherElectronicEdition;
}
public function setPublisherElectronicEdition(?string $publisherElectronicEdition): void
{
$this->publisherElectronicEdition = $publisherElectronicEdition;
}
}