X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FEntity%2FEntry.php;h=61d01bdcdadd5f0a52ceb3e66f08ae1eb0228cb9;hb=927c9e796ff6fad2bf82a965234f52932cdee657;hp=9a7dd4e7b77e43613e7a1048a847fda7afb724d4;hpb=757ec837bea7f57dcefb71b3b90c66299ed6a922;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index 9a7dd4e7..61d01bdc 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. @@ -32,6 +33,8 @@ use Wallabag\AnnotationBundle\Entity\Annotation; */ class Entry { + use EntityTimestampsTrait; + /** @Serializer\XmlAttribute */ /** * @var int @@ -472,19 +475,6 @@ class Entry return $this->updatedAt; } - /** - * @ORM\PrePersist - * @ORM\PreUpdate - */ - public function timestamps() - { - if (is_null($this->createdAt)) { - $this->createdAt = new \DateTime(); - } - - $this->updatedAt = new \DateTime(); - } - /** * @return ArrayCollection */ @@ -593,6 +583,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 +598,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. * @@ -684,6 +690,21 @@ class Entry $this->uid = null; } + /** + * 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 */