src/Entity/Music/Resource.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Music;
  3. use App\Entity\Annotation\Annotation;
  4. use App\Entity\EntityIdTrait;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use InvalidArgumentException;
  9. use Symfony\Component\HttpFoundation\File\File;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  13. /**
  14.  * @ORM\Entity(repositoryClass="App\Repository\Music\ResourceRepository")
  15.  * @Vich\Uploadable()
  16.  */
  17. class Resource
  18. {
  19.     use EntityIdTrait;
  20.     public const TYPE_MEI 'mei';
  21.     public const TYPE_KERN 'kern';
  22.     public const TYPE_HUMDRUM 'humdrum';
  23.     public const TYPE_MUSICXML 'musicxml';
  24.     public static function getTypes(): array
  25.     {
  26.         return [
  27.             self::TYPE_MEI,
  28.             self::TYPE_KERN,
  29.             self::TYPE_HUMDRUM,
  30.             self::TYPE_MUSICXML,
  31.         ];
  32.     }
  33.     /**
  34.      * @ORM\Column(type="string", length=255)
  35.      * @Assert\NotBlank()
  36.      */
  37.     private $name;
  38.     /**
  39.      * @ORM\Column(type="string", length=255, nullable=true)
  40.      * @Assert\Url()
  41.      * @Groups("resource:read")
  42.      */
  43.     private $href;
  44.     /**
  45.      * @ORM\ManyToOne(targetEntity="App\Entity\Music\Opus", inversedBy="resources")
  46.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  47.      * @Groups("resource:read")
  48.      */
  49.     private $opus;
  50.     /**
  51.      * @ORM\Column(type="string", length=255)
  52.      * @Assert\NotBlank()
  53.      * @Groups("resource:read")
  54.      */
  55.     private $type;
  56.     /**
  57.      * @ORM\OneToMany(targetEntity="App\Entity\Annotation\Annotation", mappedBy="resource")
  58.      * @Groups("resource:read")
  59.      * @ORM\OrderBy({"createdAt" = "ASC"})
  60.      */
  61.     private $annotations;
  62.     /**
  63.      * @Vich\UploadableField(mapping="resource_file", fileNameProperty="fileName")
  64.      */
  65.     private $file;
  66.     /**
  67.      * @ORM\Column(type="string", length=255, nullable=true)
  68.      *
  69.      * @var string
  70.      */
  71.     private $fileName;
  72.     /**
  73.      * @ORM\Column(type="datetime", nullable=true)
  74.      */
  75.     private $updatedAt;
  76.     /**
  77.      * @ORM\Column(type="string", nullable=true, length=255)
  78.      * @Groups("resource:read")
  79.      */
  80.     private $licence;
  81.     /**
  82.      * @ORM\Column(type="string", nullable=true, length=255)
  83.      * @Groups("resource:read")
  84.      */
  85.     private $copyright;
  86.     /**
  87.      * @ORM\Column(type="string", nullable=true, length=255)
  88.      * @Groups("resource:read")
  89.      */
  90.     private $projectUrl;
  91.     /**
  92.      * @ORM\Column(type="string", nullable=true, length=255)
  93.      * @Groups("resource:read")
  94.      */
  95.     private $sourceUrl;
  96.     /**
  97.      * @ORM\Column(type="string", nullable=true, length=255)
  98.      * @Groups("resource:read")
  99.      */
  100.     private $infoUrl;
  101.     /**
  102.      * @ORM\Column(type="string", nullable=true, length=255)
  103.      * @Groups("resource:read")
  104.      */
  105.     private $originalDocument;
  106.     /**
  107.      * @ORM\Column(type="string", nullable=true, length=255)
  108.      * @Groups("resource:read")
  109.      */
  110.     private $electronicEditor;
  111.     /**
  112.      * @ORM\Column(type="string", nullable=true, length=255)
  113.      * @Groups("resource:read")
  114.      */
  115.     private $encoderOfElectronicDocument;
  116.     /**
  117.      * @ORM\Column(type="string", nullable=true, length=255)
  118.      * @Groups("resource:read")
  119.      */
  120.     private $electronicEditionVersion;
  121.     /**
  122.      * @ORM\Column(type="string", nullable=true, length=255)
  123.      * @Groups("resource:read")
  124.      */
  125.     private $publisherElectronicEdition;
  126.     public function __construct()
  127.     {
  128.         $this->annotations = new ArrayCollection();
  129.     }
  130.     public function getName(): ?string
  131.     {
  132.         return $this->name;
  133.     }
  134.     public function setName(string $name): void
  135.     {
  136.         $this->name $name;
  137.     }
  138.     public function getHref(): ?string
  139.     {
  140.         return $this->href;
  141.     }
  142.     public function setHref(?string $href): void
  143.     {
  144.         $this->href $href;
  145.     }
  146.     public function getOpus(): ?Opus
  147.     {
  148.         return $this->opus;
  149.     }
  150.     public function setOpus(Opus $opus): void
  151.     {
  152.         $this->opus $opus;
  153.     }
  154.     public function getType(): ?string
  155.     {
  156.         return $this->type;
  157.     }
  158.     public function setType(string $type): void
  159.     {
  160.         if (!\in_array($typeself::getTypes(), true)) {
  161.             throw new InvalidArgumentException('Invalid type');
  162.         }
  163.         $this->type $type;
  164.     }
  165.     /**
  166.      * @return Collection|Annotation[]
  167.      */
  168.     public function getAnnotations(): Collection
  169.     {
  170.         return $this->annotations;
  171.     }
  172.     public function addAnnotation(Annotation $annotation): void
  173.     {
  174.         if (!$this->annotations->contains($annotation)) {
  175.             $this->annotations[] = $annotation;
  176.             $annotation->setResource($this);
  177.         }
  178.     }
  179.     public function removeAnnotation(Annotation $annotation): void
  180.     {
  181.         if ($this->annotations->contains($annotation)) {
  182.             $this->annotations->removeElement($annotation);
  183.             // set the owning side to null (unless already changed)
  184.             if ($annotation->getResource() === $this) {
  185.                 $annotation->setResource(null);
  186.             }
  187.         }
  188.     }
  189.     /**
  190.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  191.      * of 'UploadedFile' is injected into this setter to trigger the update. If this
  192.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  193.      * must be able to accept an instance of 'File' as the bundle will inject one here
  194.      * during Doctrine hydration.
  195.      *
  196.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $file
  197.      */
  198.     public function setFile(?File $file null): void
  199.     {
  200.         $this->file $file;
  201.         if (null !== $file) {
  202.             // It is required that at least one field changes if you are using doctrine
  203.             // otherwise the event listeners won't be called and the file is lost
  204.             $this->updatedAt = new \DateTimeImmutable();
  205.         }
  206.     }
  207.     public function getFile(): ?File
  208.     {
  209.         return $this->file;
  210.     }
  211.     public function setFileName(?string $fileName): void
  212.     {
  213.         $this->fileName $fileName;
  214.     }
  215.     public function getFileName(): ?string
  216.     {
  217.         return $this->fileName;
  218.     }
  219.     public function getLicence(): ?string
  220.     {
  221.         return $this->licence;
  222.     }
  223.     public function setLicence(?string $licence): void
  224.     {
  225.         $this->licence $licence;
  226.     }
  227.     public function getCopyright(): ?string
  228.     {
  229.         return $this->copyright;
  230.     }
  231.     public function setCopyright(?string $copyright): void
  232.     {
  233.         $this->copyright $copyright;
  234.     }
  235.     public function getProjectUrl(): ?string
  236.     {
  237.         return $this->projectUrl;
  238.     }
  239.     public function setProjectUrl(?string $projectUrl): void
  240.     {
  241.         $this->projectUrl $projectUrl;
  242.     }
  243.     public function getSourceUrl(): ?string
  244.     {
  245.         return $this->sourceUrl;
  246.     }
  247.     public function setSourceUrl(?string $sourceUrl): void
  248.     {
  249.         $this->sourceUrl $sourceUrl;
  250.     }
  251.     public function getInfoUrl(): ?string
  252.     {
  253.         return $this->infoUrl;
  254.     }
  255.     public function setInfoUrl(?string $infoUrl): void
  256.     {
  257.         $this->infoUrl $infoUrl;
  258.     }
  259.     public function getOriginalDocument(): ?string
  260.     {
  261.         return $this->originalDocument;
  262.     }
  263.     public function setOriginalDocument(?string $originalDocument): void
  264.     {
  265.         $this->originalDocument $originalDocument;
  266.     }
  267.     public function getElectronicEditor(): ?string
  268.     {
  269.         return $this->electronicEditor;
  270.     }
  271.     public function setElectronicEditor(?string $electronicEditor): void
  272.     {
  273.         $this->electronicEditor $electronicEditor;
  274.     }
  275.     public function getEncoderOfElectronicDocument(): ?string
  276.     {
  277.         return $this->encoderOfElectronicDocument;
  278.     }
  279.     public function setEncoderOfElectronicDocument(?string $encoderOfElectronicDocument): void
  280.     {
  281.         $this->encoderOfElectronicDocument $encoderOfElectronicDocument;
  282.     }
  283.     public function getElectronicEditionVersion(): ?string
  284.     {
  285.         return $this->electronicEditionVersion;
  286.     }
  287.     public function setElectronicEditionVersion(?string $electronicEditionVersion): void
  288.     {
  289.         $this->electronicEditionVersion $electronicEditionVersion;
  290.     }
  291.     public function getPublisherElectronicEdition(): ?string
  292.     {
  293.         return $this->publisherElectronicEdition;
  294.     }
  295.     public function setPublisherElectronicEdition(?string $publisherElectronicEdition): void
  296.     {
  297.         $this->publisherElectronicEdition $publisherElectronicEdition;
  298.     }
  299. }