3 namespace Wallabag\CoreBundle\Entity
;
5 use Doctrine\Common\Collections\ArrayCollection
;
6 use Doctrine\ORM\Mapping
as ORM
;
7 use Symfony\Component\Validator\Constraints
as Assert
;
8 use Hateoas\Configuration\Annotation
as Hateoas
;
9 use JMS\Serializer\Annotation\XmlRoot
;
10 use Wallabag\CoreBundle\Helper\Tools
;
16 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\EntryRepository")
18 * @ORM\HasLifecycleCallbacks()
19 * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())")
23 /** @Serializer\XmlAttribute */
27 * @ORM\Column(name="id", type="integer")
29 * @ORM\GeneratedValue(strategy="AUTO")
36 * @ORM\Column(name="title", type="text", nullable=true)
44 * @ORM\Column(name="url", type="text", nullable=true)
51 * @ORM\Column(name="is_archived", type="boolean")
53 private $isArchived = false;
58 * @ORM\Column(name="is_starred", type="boolean")
60 private $isStarred = false;
65 * @ORM\Column(name="content", type="text", nullable=true)
72 * @ORM\Column(name="created_at", type="datetime")
79 * @ORM\Column(name="updated_at", type="datetime")
86 * @ORM\Column(name="comments", type="text", nullable=true)
93 * @ORM\Column(name="mimetype", type="text", nullable=true)
100 * @ORM\Column(name="reading_time", type="integer", nullable=true)
102 private $readingTime;
107 * @ORM\Column(name="domain_name", type="text", nullable=true)
114 * @ORM\Column(name="is_public", type="boolean", nullable=true, options={"default" = false})
119 * @ORM\ManyToOne(targetEntity="User", inversedBy="entries")
124 * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"})
132 public function __construct(User
$user)
135 $this->tags
= new ArrayCollection();
143 public function getId()
151 * @param string $title
155 public function setTitle($title)
157 $this->title
= $title;
167 public function getTitle()
179 public function setUrl($url)
191 public function getUrl()
199 * @param string $isArchived
203 public function setArchived($isArchived)
205 $this->isArchived
= $isArchived;
215 public function isArchived()
217 return $this->isArchived
;
220 public function toggleArchive()
222 $this->isArchived
= $this->isArchived() ^
1;
230 * @param string $isStarred
234 public function setStarred($isStarred)
236 $this->isStarred
= $isStarred;
246 public function isStarred()
248 return $this->isStarred
;
251 public function toggleStar()
253 $this->isStarred
= $this->isStarred() ^
1;
261 * @param string $content
265 public function setContent($content)
267 $this->content
= $content;
268 $this->readingTime
= Tools
::getReadingTime($content);
278 public function getContent()
280 return $this->content
;
286 public function getUser()
294 public function getCreatedAt()
296 return $this->createdAt
;
302 public function getUpdatedAt()
304 return $this->updatedAt
;
311 public function timestamps()
313 if (is_null($this->createdAt
)) {
314 $this->createdAt
= new \
DateTime();
317 $this->updatedAt
= new \
DateTime();
323 public function getComments()
325 return $this->comments
;
329 * @param string $comments
331 public function setComments($comments)
333 $this->comments
= $comments;
339 public function getMimetype()
341 return $this->mimetype
;
345 * @param string $mimetype
347 public function setMimetype($mimetype)
349 $this->mimetype
= $mimetype;
355 public function getReadingTime()
357 return $this->readingTime
;
361 * @param int $readingTime
363 public function setReadingTime($readingTime)
365 $this->readingTime
= $readingTime;
371 public function getDomainName()
373 return $this->domainName
;
377 * @param string $domainName
379 public function setDomainName($domainName)
381 $this->domainName
= $domainName;
387 public function isPublic()
389 return $this->isPublic
;
393 * @param bool $isPublic
395 public function setIsPublic($isPublic)
397 $this->isPublic
= $isPublic;
401 * @return ArrayCollection<Tag>
403 public function getTags()
411 public function addTag(Tag
$tag)
413 $this->tags
[] = $tag;
414 $tag->addEntry($this);
417 public function removeTag(Tag
$tag)
419 $this->tags
->removeElement($tag);