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.
*/
class Entry
{
+ use EntityTimestampsTrait;
+
/** @Serializer\XmlAttribute */
/**
* @var int
*/
private $updatedAt;
+ /**
+ * @var \DateTime
+ *
+ * @ORM\Column(name="published_at", type="datetime", nullable=true)
+ *
+ * @Groups({"entries_for_user", "export_all"})
+ */
+ private $publishedAt;
+
+ /**
+ * @var array
+ *
+ * @ORM\Column(name="published_by", type="array", nullable=true)
+ *
+ * @Groups({"entries_for_user", "export_all"})
+ */
+ 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
*/
private $httpStatus;
+ /**
+ * @var array
+ *
+ * @ORM\Column(name="headers", type="array", nullable=true)
+ *
+ * @Groups({"entries_for_user", "export_all"})
+ */
+ private $headers;
+
/**
* @Exclude
*
*/
private $tags;
+ /**
+ * @var string
+ *
+ * @ORM\Column(name="origin_url", type="text", nullable=true)
+ *
+ * @Groups({"entries_for_user", "export_all"})
+ */
+ private $originUrl;
+
/*
* @param User $user
*/
}
/**
- * @ORM\PrePersist
- * @ORM\PreUpdate
+ * @return \DateTime|null
+ */
+ public function getStarredAt()
+ {
+ return $this->starredAt;
+ }
+
+ /**
+ * @param \DateTime|null $starredAt
+ *
+ * @return Entry
*/
- public function timestamps()
+ public function setStarredAt($starredAt = null)
{
- if (is_null($this->createdAt)) {
- $this->createdAt = new \DateTime();
+ $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;
}
/**
}
/**
- * @return ArrayCollection<Tag>
+ * @return ArrayCollection
*/
public function getTags()
{
$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)) {
$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.
*
}
/**
- * @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()
{
}
/**
- * @param int $httpStatus
+ * @param string $httpStatus
*
* @return Entry
*/
return $this;
}
+
+ /**
+ * @return \Datetime
+ */
+ public function getPublishedAt()
+ {
+ return $this->publishedAt;
+ }
+
+ /**
+ * @param \Datetime $publishedAt
+ *
+ * @return Entry
+ */
+ public function setPublishedAt(\Datetime $publishedAt)
+ {
+ $this->publishedAt = $publishedAt;
+
+ return $this;
+ }
+
+ /**
+ * @return array
+ */
+ public function getPublishedBy()
+ {
+ return $this->publishedBy;
+ }
+
+ /**
+ * @param array $publishedBy
+ *
+ * @return Entry
+ */
+ public function setPublishedBy($publishedBy)
+ {
+ $this->publishedBy = $publishedBy;
+
+ return $this;
+ }
+
+ /**
+ * @return array
+ */
+ public function getHeaders()
+ {
+ return $this->headers;
+ }
+
+ /**
+ * @param array $headers
+ *
+ * @return Entry
+ */
+ public function setHeaders($headers)
+ {
+ $this->headers = $headers;
+
+ 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;
+ }
}