X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FEntity%2FEntry.php;h=17a1ed58fa54c8585a2abbd970b331da1042cf24;hb=bfe02a0b481055bb4e799200c8daa9a0ad987c71;hp=08a67c34b1f00275b1f61b3cf5bed3b734800560;hpb=06568b15bb9e9116fa4d4a42246e1b0e497bbf25;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index 08a67c34..17a1ed58 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -5,14 +5,15 @@ 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\CoreBundle\Helper\EntityTimestampsTrait; +use Wallabag\UserBundle\Entity\User; /** * Entry. @@ -24,7 +25,8 @@ use Wallabag\AnnotationBundle\Entity\Annotation; * 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="hashedurl", columns={"hashedurl"}) * } * ) * @ORM\HasLifecycleCallbacks() @@ -32,6 +34,8 @@ use Wallabag\AnnotationBundle\Entity\Annotation; */ class Entry { + use EntityTimestampsTrait; + /** @Serializer\XmlAttribute */ /** * @var int @@ -72,6 +76,13 @@ class Entry */ private $url; + /** + * @var string + * + * @ORM\Column(name="hashedurl", type="text", nullable=true) + */ + private $hashedUrl; + /** * @var bool * @@ -83,6 +94,15 @@ class Entry */ 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 * @@ -139,6 +159,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 +197,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 @@ -233,6 +262,15 @@ 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 */ @@ -314,6 +352,44 @@ class Entry 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. * @@ -336,7 +412,7 @@ class Entry public function toggleArchive() { - $this->isArchived = $this->isArchived() ^ 1; + $this->updateArchived($this->isArchived() ^ 1); return $this; } @@ -473,16 +549,41 @@ class Entry } /** - * @ORM\PrePersist - * @ORM\PreUpdate + * @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 timestamps() + public function updateStar($isStarred = false) { - if (is_null($this->createdAt)) { - $this->createdAt = new \DateTime(); + $this->setStarred($isStarred); + $this->setStarredAt(null); + if ($this->isStarred()) { + $this->setStarredAt(new \DateTime()); } - $this->updatedAt = new \DateTime(); + return $this; } /** @@ -550,7 +651,7 @@ class Entry } /** - * @return ArrayCollection + * @return ArrayCollection */ public function getTags() { @@ -593,6 +694,11 @@ class Entry $tag->addEntry($this); } + /** + * Remove the given tag from the entry (if the tag is associated). + * + * @param Tag $tag + */ public function removeTag(Tag $tag) { if (!$this->tags->contains($tag)) { @@ -603,6 +709,17 @@ class Entry $tag->removeEntry($this); } + /** + * Remove all assigned tags from the entry. + */ + public function removeAllTags() + { + foreach ($this->tags as $tag) { + $this->tags->removeElement($tag); + $tag->removeEntry($this); + } + } + /** * Set previewPicture. * @@ -685,7 +802,22 @@ class Entry } /** - * @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() { @@ -693,7 +825,7 @@ class Entry } /** - * @param int $httpStatus + * @param string $httpStatus * * @return Entry */ @@ -763,4 +895,48 @@ class Entry 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; + } + + /** + * @return string + */ + public function getHashedUrl() + { + return $this->hashedUrl; + } + + /** + * @param mixed $hashedUrl + * + * @return Entry + */ + public function setHashedUrl($hashedUrl) + { + $this->hashedUrl = $hashedUrl; + + return $this; + } }