src/Entity/Annotation/Annotation.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Annotation;
  3. use App\Entity\EntityIdTrait;
  4. use App\Entity\Music\Resource;
  5. use App\Entity\SetUserPrePersistInterface;
  6. use App\Entity\User;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface;
  11. use Knp\DoctrineBehaviors\Model\Timestampable\TimestampableTrait;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. /**
  15.  * @ORM\Entity(repositoryClass="App\Repository\Annotation\AnnotationRepository")
  16.  * @ORM\EntityListeners({"App\EventListener\SetUserEventListener"})
  17.  */
  18. class Annotation implements SetUserPrePersistInterfaceTimestampableInterface
  19. {
  20.     use EntityIdTrait;
  21.     use TimestampableTrait;
  22.     /**
  23.      * @ORM\Column(type="string", length=255)
  24.      * @Assert\NotBlank()
  25.      * @Groups({"annotation:write", "annotation:read", "resource:read"})
  26.      */
  27.     private $name;
  28.     /**
  29.      * @ORM\OneToMany(targetEntity="App\Entity\Annotation\Anchor", mappedBy="annotation", cascade={"persist"})
  30.      * @Groups({"annotation:write", "annotation:read", "resource:read"})
  31.      * @Assert\Count(min=1)
  32.      * @Assert\Valid()
  33.      */
  34.     private $anchors;
  35.     /**
  36.      * @ORM\OneToMany(targetEntity="App\Entity\Annotation\Block", mappedBy="annotation", cascade={"persist"})
  37.      * @Groups({"annotation:write", "annotation:read", "resource:read"})
  38.      * @ORM\OrderBy({"position" = "ASC"})
  39.      * @Assert\Valid()
  40.      */
  41.     private $blocks;
  42.     /**
  43.      * @ORM\ManyToMany(targetEntity="App\Entity\Annotation\Tag", inversedBy="annotations")
  44.      * @ORM\OrderBy({"name" = "ASC"})
  45.      * @Groups({"annotation:read", "annotation:write", "resource:read"})
  46.      * @ORM\OrderBy({"name" = "ASC"})
  47.      */
  48.     private $tags;
  49.     /**
  50.      * @ORM\ManyToOne(targetEntity="App\Entity\Music\Resource", inversedBy="annotations")
  51.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  52.      * @Groups({"annotation:write", "annotation:read"})
  53.      */
  54.     private $resource;
  55.     /**
  56.      * @ORM\OneToMany(targetEntity="App\Entity\Annotation\Comment", mappedBy="annotation")
  57.      * @Groups({"annotation:read", "resource:read"})
  58.      * @ORM\OrderBy({"createdAt" = "ASC"})
  59.      */
  60.     private $comments;
  61.     /**
  62.      * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="annotations")
  63.      * @ORM\JoinColumn(nullable=false)
  64.      * @Groups({"annotation:read"})
  65.      */
  66.     private $user;
  67.     public function __construct()
  68.     {
  69.         $this->anchors = new ArrayCollection();
  70.         $this->blocks = new ArrayCollection();
  71.         $this->tags = new ArrayCollection();
  72.         $this->comments = new ArrayCollection();
  73.     }
  74.     public function getName(): ?string
  75.     {
  76.         return $this->name;
  77.     }
  78.     public function setName(string $name): void
  79.     {
  80.         $this->name $name;
  81.     }
  82.     /**
  83.      * @return Collection|Anchor[]
  84.      */
  85.     public function getAnchors(): Collection
  86.     {
  87.         return $this->anchors;
  88.     }
  89.     public function addAnchor(Anchor $anchor): void
  90.     {
  91.         if (!$this->anchors->contains($anchor)) {
  92.             $this->anchors[] = $anchor;
  93.             $anchor->setAnnotation($this);
  94.         }
  95.     }
  96.     public function removeAnchor(Anchor $anchor): void
  97.     {
  98.         if ($this->anchors->contains($anchor)) {
  99.             $this->anchors->removeElement($anchor);
  100.             // set the owning side to null (unless already changed)
  101.             if ($anchor->getAnnotation() === $this) {
  102.                 $anchor->setAnnotation(null);
  103.             }
  104.         }
  105.     }
  106.     /**
  107.      * @return Collection|Block[]
  108.      */
  109.     public function getBlocks(): Collection
  110.     {
  111.         return $this->blocks;
  112.     }
  113.     public function addBlock(Block $block): void
  114.     {
  115.         if (!$this->blocks->contains($block)) {
  116.             $this->blocks[] = $block;
  117.             $block->setAnnotation($this);
  118.         }
  119.     }
  120.     public function removeBlock(Block $block): void
  121.     {
  122.         if ($this->blocks->contains($block)) {
  123.             $this->blocks->removeElement($block);
  124.             // set the owning side to null (unless already changed)
  125.             if ($block->getAnnotation() === $this) {
  126.                 $block->setAnnotation(null);
  127.             }
  128.         }
  129.     }
  130.     /**
  131.      * @return Collection|Tag[]
  132.      */
  133.     public function getTags(): Collection
  134.     {
  135.         return $this->tags;
  136.     }
  137.     public function addTag(Tag $tag): void
  138.     {
  139.         if (!$this->tags->contains($tag)) {
  140.             $this->tags[] = $tag;
  141.         }
  142.     }
  143.     public function removeTag(Tag $tag): void
  144.     {
  145.         if ($this->tags->contains($tag)) {
  146.             $this->tags->removeElement($tag);
  147.         }
  148.     }
  149.     public function getResource(): ?Resource
  150.     {
  151.         return $this->resource;
  152.     }
  153.     public function setResource(?Resource $resource): void
  154.     {
  155.         $this->resource $resource;
  156.     }
  157.     /**
  158.      * @return Collection|Comment[]
  159.      */
  160.     public function getComments(): Collection
  161.     {
  162.         return $this->comments;
  163.     }
  164.     public function addComment(Comment $comment): void
  165.     {
  166.         if (!$this->comments->contains($comment)) {
  167.             $this->comments[] = $comment;
  168.             $comment->setAnnotation($this);
  169.         }
  170.     }
  171.     public function removeComment(Comment $comment): void
  172.     {
  173.         if ($this->comments->contains($comment)) {
  174.             $this->comments->removeElement($comment);
  175.             // set the owning side to null (unless already changed)
  176.             if ($comment->getAnnotation() === $this) {
  177.                 $comment->setAnnotation(null);
  178.             }
  179.         }
  180.     }
  181.     public function getUser(): ?User
  182.     {
  183.         return $this->user;
  184.     }
  185.     public function setUser(?User $user): void
  186.     {
  187.         $this->user $user;
  188.     }
  189. }