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\Groups
;
10 use JMS\Serializer\Annotation\XmlRoot
;
11 use Wallabag\UserBundle\Entity\User
;
17 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\EntryRepository")
18 * @ORM\Table(name="`entry`")
19 * @ORM\HasLifecycleCallbacks()
20 * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())")
24 /** @Serializer\XmlAttribute */
28 * @ORM\Column(name="id", type="integer")
30 * @ORM\GeneratedValue(strategy="AUTO")
32 * @Groups({"entries_for_user", "export_all"})
39 * @ORM\Column(name="title", type="text", nullable=true)
41 * @Groups({"entries_for_user", "export_all"})
49 * @ORM\Column(name="url", type="text", nullable=true)
51 * @Groups({"entries_for_user", "export_all"})
58 * @ORM\Column(name="is_archived", type="boolean")
60 * @Groups({"entries_for_user", "export_all"})
62 private $isArchived = false;
67 * @ORM\Column(name="is_starred", type="boolean")
69 * @Groups({"entries_for_user", "export_all"})
71 private $isStarred = false;
76 * @ORM\Column(name="content", type="text", nullable=true)
78 * @Groups({"entries_for_user", "export_all"})
85 * @ORM\Column(name="created_at", type="datetime")
87 * @Groups({"export_all"})
94 * @ORM\Column(name="updated_at", type="datetime")
96 * @Groups({"export_all"})
103 * @ORM\Column(name="comments", type="text", nullable=true)
105 * @Groups({"export_all"})
112 * @ORM\Column(name="mimetype", type="text", nullable=true)
114 * @Groups({"entries_for_user", "export_all"})
121 * @ORM\Column(name="language", type="text", nullable=true)
123 * @Groups({"entries_for_user", "export_all"})
130 * @ORM\Column(name="reading_time", type="integer", nullable=true)
132 * @Groups({"entries_for_user", "export_all"})
134 private $readingTime;
139 * @ORM\Column(name="domain_name", type="text", nullable=true)
141 * @Groups({"entries_for_user", "export_all"})
148 * @ORM\Column(name="preview_picture", type="text", nullable=true)
150 * @Groups({"entries_for_user", "export_all"})
152 private $previewPicture;
157 * @ORM\Column(name="is_public", type="boolean", nullable=true, options={"default" = false})
159 * @Groups({"export_all"})
164 * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="entries")
166 * @Groups({"export_all"})
171 * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"})
174 * @Groups({"entries_for_user", "export_all"})
181 public function __construct(\Wallabag\UserBundle\Entity\User
$user)
184 $this->tags
= new ArrayCollection();
192 public function getId()
200 * @param string $title
204 public function setTitle($title)
206 $this->title
= $title;
216 public function getTitle()
228 public function setUrl($url)
240 public function getUrl()
248 * @param string $isArchived
252 public function setArchived($isArchived)
254 $this->isArchived
= $isArchived;
264 public function isArchived()
266 return $this->isArchived
;
269 public function toggleArchive()
271 $this->isArchived
= $this->isArchived() ^
1;
279 * @param string $isStarred
283 public function setStarred($isStarred)
285 $this->isStarred
= $isStarred;
295 public function isStarred()
297 return $this->isStarred
;
300 public function toggleStar()
302 $this->isStarred
= $this->isStarred() ^
1;
310 * @param string $content
314 public function setContent($content)
316 $this->content
= $content;
326 public function getContent()
328 return $this->content
;
334 public function getUser()
342 public function getCreatedAt()
344 return $this->createdAt
;
350 public function getUpdatedAt()
352 return $this->updatedAt
;
359 public function timestamps()
361 if (is_null($this->createdAt
)) {
362 $this->createdAt
= new \
DateTime();
365 $this->updatedAt
= new \
DateTime();
371 public function getComments()
373 return $this->comments
;
377 * @param string $comments
379 public function setComments($comments)
381 $this->comments
= $comments;
387 public function getMimetype()
389 return $this->mimetype
;
393 * @param string $mimetype
395 public function setMimetype($mimetype)
397 $this->mimetype
= $mimetype;
403 public function getReadingTime()
405 return $this->readingTime
;
409 * @param int $readingTime
411 public function setReadingTime($readingTime)
413 $this->readingTime
= $readingTime;
419 public function getDomainName()
421 return $this->domainName
;
425 * @param string $domainName
427 public function setDomainName($domainName)
429 $this->domainName
= $domainName;
435 public function isPublic()
437 return $this->isPublic
;
441 * @param bool $isPublic
443 public function setIsPublic($isPublic)
445 $this->isPublic
= $isPublic;
449 * @return ArrayCollection<Tag>
451 public function getTags()
459 public function addTag(Tag
$tag)
461 if ($this->tags
->contains($tag)) {
465 // check if tag already exist but has not yet be persisted
466 // it seems that the previous condition with `contains()` doesn't check that case
467 foreach ($this->tags
as $existingTag) {
468 if ($existingTag->getUser() !== $tag->getUser() || $existingTag->getLabel() === $tag->getLabel()) {
473 $this->tags
[] = $tag;
474 $tag->addEntry($this);
477 public function removeTag(Tag
$tag)
479 $this->tags
->removeElement($tag);
483 * Set previewPicture.
485 * @param string $previewPicture
489 public function setPreviewPicture($previewPicture)
491 $this->previewPicture
= $previewPicture;
497 * Get previewPicture.
501 public function getPreviewPicture()
503 return $this->previewPicture
;
509 * @param string $language
513 public function setLanguage($language)
515 $this->language
= $language;
525 public function getLanguage()
527 return $this->language
;