]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Entity/Entry.php
first draft of hypermedia implementation
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Entity / Entry.php
index a00762cadfbc1a58a4250f09b1e803529fbd71af..4f57eb0afcfbe993d211aab06041eb97a4866ea1 100644 (file)
@@ -4,17 +4,21 @@ namespace Wallabag\CoreBundle\Entity;
 
 use Doctrine\ORM\Mapping as ORM;
 use Symfony\Component\Validator\Constraints as Assert;
+use Hateoas\Configuration\Annotation as Hateoas;
+use JMS\Serializer\Annotation\XmlRoot;
 
 /**
  * Entry
  *
+ * @XmlRoot("entry")
  * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\EntryRepository")
  * @ORM\Table(name="entry")
  * @ORM\HasLifecycleCallbacks()
- *
+ * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())")
  */
 class Entry
 {
+    /** @Serializer\XmlAttribute */
     /**
      * @var integer
      *
@@ -81,13 +85,6 @@ class Entry
      */
     private $updatedAt;
 
-    /**
-     * @var string
-     *
-     * @ORM\Column(name="user_id", type="decimal", precision=10, scale=0, nullable=true)
-     */
-    private $userId;
-
     /**
      * @var string
      *
@@ -123,6 +120,19 @@ class Entry
      */
     private $isPublic;
 
+    /**
+     * @ORM\ManyToOne(targetEntity="User", inversedBy="entries")
+     */
+    private $user;
+
+    /*
+     * @param User     $user
+     */
+    public function __construct(User $user)
+    {
+        $this->user = $user;
+    }
+
     /**
      * Get id
      *
@@ -263,26 +273,11 @@ class Entry
     }
 
     /**
-     * Set userId
-     *
-     * @param  string $userId
-     * @return Entry
-     */
-    public function setUserId($userId)
-    {
-        $this->userId = $userId;
-
-        return $this;
-    }
-
-    /**
-     * Get userId
-     *
-     * @return string
+     * @return User
      */
-    public function getUserId()
+    public function getUser()
     {
-        return $this->userId;
+        return $this->user;
     }
 
     /**