X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FEntity%2FEntry.php;h=cfb8db75275c2e42d1b994e5f037a58220bd31d5;hb=1953a872932a63792293b4aec087880265ba89f7;hp=cba72d31e07385ba736638df84c14862a31cf5a1;hpb=a05b61159e147776f63baee731b5026796e5f7ae;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index cba72d31..cfb8db75 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -12,6 +12,7 @@ use JMS\Serializer\Annotation\VirtualProperty; use JMS\Serializer\Annotation\XmlRoot; use Symfony\Component\Validator\Constraints as Assert; use Wallabag\AnnotationBundle\Entity\Annotation; +use Wallabag\CoreBundle\Helper\EntityTimestampsTrait; use Wallabag\UserBundle\Entity\User; /** @@ -32,6 +33,8 @@ use Wallabag\UserBundle\Entity\User; */ class Entry { + use EntityTimestampsTrait; + /** @Serializer\XmlAttribute */ /** * @var int @@ -139,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 @@ -168,11 +180,11 @@ class Entry /** * @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 @@ -473,16 +485,41 @@ class Entry } /** - * @ORM\PrePersist - * @ORM\PreUpdate + * @return \DateTime|null */ - public function timestamps() + public function getStarredAt() { - if (null === $this->createdAt) { - $this->createdAt = new \DateTime(); + 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()); } - $this->updatedAt = new \DateTime(); + return $this; } /**