]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Entity/Entry.php
Use lang attribute
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Entity / Entry.php
index 6227413682be4ddf4ab934b378bb1d237cae4c3d..190457983f92eb9d5bc77a25c24b08646ddb918f 100644 (file)
@@ -27,9 +27,13 @@ use Wallabag\UserBundle\Entity\User;
  *     indexes={
  *         @ORM\Index(name="created_at", columns={"created_at"}),
  *         @ORM\Index(name="uid", columns={"uid"}),
- *         @ORM\Index(name="hashed_url_user_id", columns={"user_id", "hashed_url"}, options={"lengths"={null, 40}})
- *     },
- *     uniqueConstraints={@ORM\UniqueConstraint(name="IDX_entry_given_url",columns={"url", "given_url", "user_id"})}
+ *         @ORM\Index(name="hashed_url_user_id", columns={"user_id", "hashed_url"}, options={"lengths"={null, 40}}),
+ *         @ORM\Index(name="hashed_given_url_user_id", columns={"user_id", "hashed_given_url"}, options={"lengths"={null, 40}}),
+ *         @ORM\Index(name="user_language", columns={"language", "user_id"}),
+ *         @ORM\Index(name="user_archived", columns={"user_id", "is_archived", "archived_at"}),
+ *         @ORM\Index(name="user_created", columns={"user_id", "created_at"}),
+ *         @ORM\Index(name="user_starred", columns={"user_id", "is_starred", "starred_at"})
+ *     }
  * )
  * @ORM\HasLifecycleCallbacks()
  * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())")
@@ -69,30 +73,52 @@ class Entry
     private $title;
 
     /**
+     * Define the url fetched by wallabag (the final url after potential redirections).
+     *
      * @var string
      *
-     * @ORM\Column(name="given_url", type="text", nullable=true)
+     * @Assert\NotBlank()
+     * @ORM\Column(name="url", type="text", nullable=true)
      *
      * @Groups({"entries_for_user", "export_all"})
      */
-    private $givenUrl;
+    private $url;
 
     /**
      * @var string
      *
-     * @Assert\NotBlank()
-     * @ORM\Column(name="url", type="text", nullable=true)
+     * @ORM\Column(name="hashed_url", type="string", length=40, nullable=true)
+     */
+    private $hashedUrl;
+
+    /**
+     * From where user retrieved/found the url (an other article, a twitter, or the given_url if non are provided).
+     *
+     * @var string
+     *
+     * @ORM\Column(name="origin_url", type="text", nullable=true)
      *
      * @Groups({"entries_for_user", "export_all"})
      */
-    private $url;
+    private $originUrl;
 
     /**
+     * Define the url entered by the user (without redirections).
+     *
      * @var string
      *
-     * @ORM\Column(name="hashed_url", type="string", length=40, nullable=true)
+     * @ORM\Column(name="given_url", type="text", nullable=true)
+     *
+     * @Groups({"entries_for_user", "export_all"})
      */
-    private $hashedUrl;
+    private $givenUrl;
+
+    /**
+     * @var string
+     *
+     * @ORM\Column(name="hashed_given_url", type="string", length=40, nullable=true)
+     */
+    private $hashedGivenUrl;
 
     /**
      * @var bool
@@ -199,7 +225,7 @@ class Entry
     /**
      * @var string
      *
-     * @ORM\Column(name="language", type="text", nullable=true)
+     * @ORM\Column(name="language", type="string", length=20, nullable=true)
      *
      * @Groups({"entries_for_user", "export_all"})
      */
@@ -273,15 +299,6 @@ class Entry
      */
     private $tags;
 
-    /**
-     * @var string
-     *
-     * @ORM\Column(name="origin_url", type="text", nullable=true)
-     *
-     * @Groups({"entries_for_user", "export_all"})
-     */
-    private $originUrl;
-
     /*
      * @param User     $user
      */
@@ -325,30 +342,6 @@ class Entry
         return $this->title;
     }
 
-    /**
-     * Set given url.
-     *
-     * @param string $givenUrl
-     *
-     * @return Entry
-     */
-    public function setGivenUrl($givenUrl)
-    {
-        $this->givenUrl = $givenUrl;
-
-        return $this;
-    }
-
-    /**
-     * Get given Url.
-     *
-     * @return string
-     */
-    public function getGivenUrl()
-    {
-        return $this->givenUrl;
-    }
-
     /**
      * Set url.
      *
@@ -557,8 +550,6 @@ class Entry
      * Set created_at.
      * Only used when importing data from an other service.
      *
-     * @param \DateTime $createdAt
-     *
      * @return Entry
      */
     public function setCreatedAt(\DateTime $createdAt)
@@ -630,9 +621,6 @@ class Entry
         return $this->annotations;
     }
 
-    /**
-     * @param Annotation $annotation
-     */
     public function setAnnotation(Annotation $annotation)
     {
         $this->annotations[] = $annotation;
@@ -709,9 +697,6 @@ class Entry
         return $data;
     }
 
-    /**
-     * @param Tag $tag
-     */
     public function addTag(Tag $tag)
     {
         if ($this->tags->contains($tag)) {
@@ -732,8 +717,6 @@ class Entry
 
     /**
      * Remove the given tag from the entry (if the tag is associated).
-     *
-     * @param Tag $tag
      */
     public function removeTag(Tag $tag)
     {
@@ -805,7 +788,20 @@ class Entry
     }
 
     /**
-     * @return string
+     * Format the entry language to a valid html lang attribute.
+     */
+    public function getHTMLLanguage()
+    {
+        $parsedLocale = \Locale::parseLocale($this->getLanguage());
+        $lang = '';
+        $lang .= $parsedLocale['language'] ?? '';
+        $lang .= isset($parsedLocale['region']) ? '-' . $parsedLocale['region'] : '';
+
+        return $lang;
+    }
+
+    /**
+     * @return string|null
      */
     public function getUid()
     {
@@ -881,8 +877,6 @@ class Entry
     }
 
     /**
-     * @param \Datetime $publishedAt
-     *
      * @return Entry
      */
     public function setPublishedAt(\Datetime $publishedAt)
@@ -956,6 +950,31 @@ class Entry
         return $this->originUrl;
     }
 
+    /**
+     * Set given url.
+     *
+     * @param string $givenUrl
+     *
+     * @return Entry
+     */
+    public function setGivenUrl($givenUrl)
+    {
+        $this->givenUrl = $givenUrl;
+        $this->hashedGivenUrl = UrlHasher::hashUrl($givenUrl);
+
+        return $this;
+    }
+
+    /**
+     * Get given url.
+     *
+     * @return string
+     */
+    public function getGivenUrl()
+    {
+        return $this->givenUrl;
+    }
+
     /**
      * @return string
      */