From a991c46eedec0efb24d0a9974b1c7fcabf8cfa66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20D?= Date: Wed, 23 Aug 2017 23:06:40 +0200 Subject: Set a starred_at field when an entry is starred. This date is used to sort starred entries. Can not use Entry::timestamps method otherwise starred_at will be updated each time entry is updated. Add an updateStar method into Entry class A migration script has been added in order to set starred_at field. --- src/Wallabag/CoreBundle/Entity/Entry.php | 47 ++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'src/Wallabag/CoreBundle/Entity') diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index 61d01bdc..4367902e 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -142,6 +142,15 @@ class Entry */ 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 @@ -475,6 +484,44 @@ class Entry 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 */ -- cgit v1.2.3