use Symfony\Component\Validator\Constraints as Assert;
use Wallabag\AnnotationBundle\Entity\Annotation;
use Wallabag\CoreBundle\Helper\EntityTimestampsTrait;
+use Wallabag\CoreBundle\Helper\UrlHasher;
use Wallabag\UserBundle\Entity\User;
/**
* options={"collate"="utf8mb4_unicode_ci", "charset"="utf8mb4"},
* indexes={
* @ORM\Index(name="created_at", columns={"created_at"}),
- * @ORM\Index(name="uid", columns={"uid"})
+ * @ORM\Index(name="uid", columns={"uid"}),
+ * @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\HasLifecycleCallbacks()
private $title;
/**
+ * Define the url fetched by wallabag (the final url after potential redirections).
+ *
* @var string
*
* @Assert\NotBlank()
*/
private $url;
+ /**
+ * @var string
+ *
+ * @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 $originUrl;
+
+ /**
+ * Define the url entered by the user (without redirections).
+ *
+ * @var string
+ *
+ * @ORM\Column(name="given_url", type="text", nullable=true)
+ *
+ * @Groups({"entries_for_user", "export_all"})
+ */
+ private $givenUrl;
+
+ /**
+ * @var string
+ *
+ * @ORM\Column(name="hashed_given_url", type="string", length=40, nullable=true)
+ */
+ private $hashedGivenUrl;
+
/**
* @var bool
*
*/
private $isArchived = false;
+ /**
+ * @var \DateTime
+ *
+ * @ORM\Column(name="archived_at", type="datetime", nullable=true)
+ *
+ * @Groups({"entries_for_user", "export_all"})
+ */
+ private $archivedAt = null;
+
/**
* @var bool
*
*/
private $publishedBy;
+ /**
+ * @var \DateTime
+ *
+ * @ORM\Column(name="starred_at", type="datetime", nullable=true)
+ *
+ * @Groups({"entries_for_user", "export_all"})
+ */
+ private $starredAt = null;
+
/**
* @ORM\OneToMany(targetEntity="Wallabag\AnnotationBundle\Entity\Annotation", mappedBy="entry", cascade={"persist", "remove"})
* @ORM\JoinTable
/**
* @var int
*
- * @ORM\Column(name="reading_time", type="integer", nullable=true)
+ * @ORM\Column(name="reading_time", type="integer", nullable=false)
*
* @Groups({"entries_for_user", "export_all"})
*/
- private $readingTime;
+ private $readingTime = 0;
/**
* @var string
public function setUrl($url)
{
$this->url = $url;
+ $this->hashedUrl = UrlHasher::hashUrl($url);
return $this;
}
return $this;
}
+ /**
+ * update isArchived and archive_at fields.
+ *
+ * @param bool $isArchived
+ *
+ * @return Entry
+ */
+ public function updateArchived($isArchived = false)
+ {
+ $this->setArchived($isArchived);
+ $this->setArchivedAt(null);
+ if ($this->isArchived()) {
+ $this->setArchivedAt(new \DateTime());
+ }
+
+ return $this;
+ }
+
+ /**
+ * @return \DateTime|null
+ */
+ public function getArchivedAt()
+ {
+ return $this->archivedAt;
+ }
+
+ /**
+ * @param \DateTime|null $archivedAt
+ *
+ * @return Entry
+ */
+ public function setArchivedAt($archivedAt = null)
+ {
+ $this->archivedAt = $archivedAt;
+
+ return $this;
+ }
+
/**
* Get isArchived.
*
public function toggleArchive()
{
- $this->isArchived = $this->isArchived() ^ 1;
+ $this->updateArchived($this->isArchived() ^ 1);
return $this;
}
return $this->updatedAt;
}
+ /**
+ * @return \DateTime|null
+ */
+ public function getStarredAt()
+ {
+ return $this->starredAt;
+ }
+
+ /**
+ * @param \DateTime|null $starredAt
+ *
+ * @return Entry
+ */
+ public function setStarredAt($starredAt = null)
+ {
+ $this->starredAt = $starredAt;
+
+ return $this;
+ }
+
+ /**
+ * update isStarred and starred_at fields.
+ *
+ * @param bool $isStarred
+ *
+ * @return Entry
+ */
+ public function updateStar($isStarred = false)
+ {
+ $this->setStarred($isStarred);
+ $this->setStarredAt(null);
+ if ($this->isStarred()) {
+ $this->setStarredAt(new \DateTime());
+ }
+
+ return $this;
+ }
+
/**
* @return ArrayCollection<Annotation>
*/
return $this;
}
+
+ /**
+ * Set origin url.
+ *
+ * @param string $originUrl
+ *
+ * @return Entry
+ */
+ public function setOriginUrl($originUrl)
+ {
+ $this->originUrl = $originUrl;
+
+ return $this;
+ }
+
+ /**
+ * Get origin url.
+ *
+ * @return string
+ */
+ public function getOriginUrl()
+ {
+ return $this->originUrl;
+ }
+
+ /**
+ * Set origin url.
+ *
+ * @param string $givenUrl
+ *
+ * @return Entry
+ */
+ public function setGivenUrl($givenUrl)
+ {
+ $this->givenUrl = $givenUrl;
+ $this->hashedGivenUrl = UrlHasher::hashUrl($givenUrl);
+
+ return $this;
+ }
+
+ /**
+ * Get origin url.
+ *
+ * @return string
+ */
+ public function getGivenUrl()
+ {
+ return $this->givenUrl;
+ }
+
+ /**
+ * @return string
+ */
+ public function getHashedUrl()
+ {
+ return $this->hashedUrl;
+ }
+
+ /**
+ * @param mixed $hashedUrl
+ *
+ * @return Entry
+ */
+ public function setHashedUrl($hashedUrl)
+ {
+ $this->hashedUrl = $hashedUrl;
+
+ return $this;
+ }
}