]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Entity/Entry.php
Add a real configuration for CS-Fixer
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Entity / Entry.php
index 31e594bf349f7f1aff92a9829b430e1d57d47a8f..581e890666ba9e5c6ea21a25646d1e759435e5c7 100644 (file)
@@ -5,14 +5,14 @@ namespace Wallabag\CoreBundle\Entity;
 use Doctrine\Common\Collections\ArrayCollection;
 use Doctrine\ORM\Mapping as ORM;
 use Hateoas\Configuration\Annotation as Hateoas;
-use JMS\Serializer\Annotation\Groups;
-use JMS\Serializer\Annotation\XmlRoot;
 use JMS\Serializer\Annotation\Exclude;
-use JMS\Serializer\Annotation\VirtualProperty;
+use JMS\Serializer\Annotation\Groups;
 use JMS\Serializer\Annotation\SerializedName;
+use JMS\Serializer\Annotation\VirtualProperty;
+use JMS\Serializer\Annotation\XmlRoot;
 use Symfony\Component\Validator\Constraints as Assert;
-use Wallabag\UserBundle\Entity\User;
 use Wallabag\AnnotationBundle\Entity\Annotation;
+use Wallabag\UserBundle\Entity\User;
 
 /**
  * Entry.
@@ -22,7 +22,10 @@ use Wallabag\AnnotationBundle\Entity\Annotation;
  * @ORM\Table(
  *     name="`entry`",
  *     options={"collate"="utf8mb4_unicode_ci", "charset"="utf8mb4"},
- *     indexes={@ORM\Index(name="created_at", columns={"created_at"})}
+ *     indexes={
+ *         @ORM\Index(name="created_at", columns={"created_at"}),
+ *         @ORM\Index(name="uid", columns={"uid"})
+ *     }
  * )
  * @ORM\HasLifecycleCallbacks()
  * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())")
@@ -44,11 +47,11 @@ class Entry
     /**
      * @var string
      *
-     * @ORM\Column(name="uuid", type="text", nullable=true)
+     * @ORM\Column(name="uid", type="string", length=23, nullable=true)
      *
      * @Groups({"entries_for_user", "export_all"})
      */
-    private $uuid;
+    private $uid;
 
     /**
      * @var string
@@ -118,6 +121,24 @@ class Entry
      */
     private $updatedAt;
 
+    /**
+     * @var \DateTime
+     *
+     * @ORM\Column(name="published_at", type="datetime", nullable=true)
+     *
+     * @Groups({"entries_for_user", "export_all"})
+     */
+    private $publishedAt;
+
+    /**
+     * @var array
+     *
+     * @ORM\Column(name="published_by", type="array", nullable=true)
+     *
+     * @Groups({"entries_for_user", "export_all"})
+     */
+    private $publishedBy;
+
     /**
      * @ORM\OneToMany(targetEntity="Wallabag\AnnotationBundle\Entity\Annotation", mappedBy="entry", cascade={"persist", "remove"})
      * @ORM\JoinTable
@@ -172,22 +193,22 @@ class Entry
     private $previewPicture;
 
     /**
-     * @var bool
+     * @var string
      *
-     * @ORM\Column(name="is_public", type="boolean", nullable=true, options={"default" = false})
+     * @ORM\Column(name="http_status", type="string", length=3, nullable=true)
      *
-     * @Groups({"export_all"})
+     * @Groups({"entries_for_user", "export_all"})
      */
-    private $isPublic;
+    private $httpStatus;
 
     /**
-     * @var int
+     * @var array
      *
-     * @ORM\Column(name="http_status", type="integer", nullable=true)
+     * @ORM\Column(name="headers", type="array", nullable=true)
      *
      * @Groups({"entries_for_user", "export_all"})
      */
-    private $httpStatus;
+    private $headers;
 
     /**
      * @Exclude
@@ -457,7 +478,7 @@ class Entry
      */
     public function timestamps()
     {
-        if (is_null($this->createdAt)) {
+        if (null === $this->createdAt) {
             $this->createdAt = new \DateTime();
         }
 
@@ -529,23 +550,7 @@ class Entry
     }
 
     /**
-     * @return bool
-     */
-    public function isPublic()
-    {
-        return $this->isPublic;
-    }
-
-    /**
-     * @param bool $isPublic
-     */
-    public function setIsPublic($isPublic)
-    {
-        $this->isPublic = $isPublic;
-    }
-
-    /**
-     * @return ArrayCollection<Tag>
+     * @return ArrayCollection
      */
     public function getTags()
     {
@@ -649,38 +654,53 @@ class Entry
     /**
      * @return string
      */
-    public function getUuid()
+    public function getUid()
     {
-        return $this->uuid;
+        return $this->uid;
     }
 
     /**
-     * @param string $uuid
+     * @param string $uid
      *
      * @return Entry
      */
-    public function setUuid($uuid)
+    public function setUid($uid)
     {
-        $this->uuid = $uuid;
+        $this->uid = $uid;
 
         return $this;
     }
 
-    public function generateUuid()
+    public function generateUid()
     {
-        if (null === $this->uuid) {
+        if (null === $this->uid) {
             // @see http://blog.kevingomez.fr/til/2015/07/26/why-is-uniqid-slow/ for true parameter
-            $this->uuid = uniqid('', true);
+            $this->uid = uniqid('', true);
         }
     }
 
-    public function cleanUuid()
+    public function cleanUid()
     {
-        $this->uuid = null;
+        $this->uid = null;
     }
 
     /**
-     * @return int
+     * Used in the entries filter so it's more explicit for the end user than the uid.
+     * Also used in the API.
+     *
+     * @VirtualProperty
+     * @SerializedName("is_public")
+     * @Groups({"entries_for_user"})
+     *
+     * @return bool
+     */
+    public function isPublic()
+    {
+        return null !== $this->uid;
+    }
+
+    /**
+     * @return string
      */
     public function getHttpStatus()
     {
@@ -688,7 +708,7 @@ class Entry
     }
 
     /**
-     * @param int $httpStatus
+     * @param string $httpStatus
      *
      * @return Entry
      */
@@ -698,4 +718,64 @@ class Entry
 
         return $this;
     }
+
+    /**
+     * @return \Datetime
+     */
+    public function getPublishedAt()
+    {
+        return $this->publishedAt;
+    }
+
+    /**
+     * @param \Datetime $publishedAt
+     *
+     * @return Entry
+     */
+    public function setPublishedAt(\Datetime $publishedAt)
+    {
+        $this->publishedAt = $publishedAt;
+
+        return $this;
+    }
+
+    /**
+     * @return array
+     */
+    public function getPublishedBy()
+    {
+        return $this->publishedBy;
+    }
+
+    /**
+     * @param array $publishedBy
+     *
+     * @return Entry
+     */
+    public function setPublishedBy($publishedBy)
+    {
+        $this->publishedBy = $publishedBy;
+
+        return $this;
+    }
+
+    /**
+     * @return array
+     */
+    public function getHeaders()
+    {
+        return $this->headers;
+    }
+
+    /**
+     * @param array $headers
+     *
+     * @return Entry
+     */
+    public function setHeaders($headers)
+    {
+        $this->headers = $headers;
+
+        return $this;
+    }
 }