]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Entity/Entry.php
Merge pull request #1653 from wallabag/v2-annotator-comments
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Entity / Entry.php
index 608ed2f0d4ababf41230640cfb45804b137cf687..bd712a0449c498ed9108bd3aac174a809a13a75d 100644 (file)
@@ -4,11 +4,12 @@ namespace Wallabag\CoreBundle\Entity;
 
 use Doctrine\Common\Collections\ArrayCollection;
 use Doctrine\ORM\Mapping as ORM;
-use Symfony\Component\Validator\Constraints as Assert;
 use Hateoas\Configuration\Annotation as Hateoas;
 use JMS\Serializer\Annotation\Groups;
 use JMS\Serializer\Annotation\XmlRoot;
+use Symfony\Component\Validator\Constraints as Assert;
 use Wallabag\UserBundle\Entity\User;
+use Wallabag\AnnotationBundle\Entity\Annotation;
 
 /**
  * Entry.
@@ -98,13 +99,12 @@ class Entry
     private $updatedAt;
 
     /**
-     * @var string
-     *
-     * @ORM\Column(name="comments", type="text", nullable=true)
+     * @ORM\OneToMany(targetEntity="Wallabag\AnnotationBundle\Entity\Annotation", mappedBy="entry", cascade={"persist", "remove"})
+     * @ORM\JoinTable
      *
-     * @Groups({"export_all"})
+     * @Groups({"entries_for_user", "export_all"})
      */
-    private $comments;
+    private $annotations;
 
     /**
      * @var string
@@ -168,7 +168,7 @@ class Entry
     private $user;
 
     /**
-     * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"})
+     * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist", "remove"})
      * @ORM\JoinTable
      *
      * @Groups({"entries_for_user", "export_all"})
@@ -245,7 +245,7 @@ class Entry
     /**
      * Set isArchived.
      *
-     * @param string $isArchived
+     * @param bool $isArchived
      *
      * @return Entry
      */
@@ -259,7 +259,7 @@ class Entry
     /**
      * Get isArchived.
      *
-     * @return string
+     * @return bool
      */
     public function isArchived()
     {
@@ -276,7 +276,7 @@ class Entry
     /**
      * Set isStarred.
      *
-     * @param string $isStarred
+     * @param bool $isStarred
      *
      * @return Entry
      */
@@ -290,7 +290,7 @@ class Entry
     /**
      * Get isStarred.
      *
-     * @return string
+     * @return bool
      */
     public function isStarred()
     {
@@ -366,19 +366,19 @@ class Entry
     }
 
     /**
-     * @return string
+     * @return ArrayCollection<Annotation>
      */
-    public function getComments()
+    public function getAnnotations()
     {
-        return $this->comments;
+        return $this->annotations;
     }
 
     /**
-     * @param string $comments
+     * @param Annotation $annotation
      */
-    public function setComments($comments)
+    public function setAnnotation(Annotation $annotation)
     {
-        $this->comments = $comments;
+        $this->annotations[] = $annotation;
     }
 
     /**
@@ -462,6 +462,14 @@ class Entry
             return;
         }
 
+        // check if tag already exist but has not yet be persisted
+        // it seems that the previous condition with `contains()` doesn't check that case
+        foreach ($this->tags as $existingTag) {
+            if ($existingTag->getLabel() === $tag->getLabel()) {
+                return;
+            }
+        }
+
         $this->tags[] = $tag;
         $tag->addEntry($this);
     }