3 namespace Wallabag\CoreBundle\Entity
;
5 use Doctrine\Common\Collections\ArrayCollection
;
6 use Doctrine\ORM\Mapping
as ORM
;
7 use Hateoas\Configuration\Annotation
as Hateoas
;
8 use JMS\Serializer\Annotation\Groups
;
9 use JMS\Serializer\Annotation\XmlRoot
;
10 use JMS\Serializer\Annotation\Exclude
;
11 use JMS\Serializer\Annotation\VirtualProperty
;
12 use JMS\Serializer\Annotation\SerializedName
;
13 use Symfony\Component\Validator\Constraints
as Assert
;
14 use Wallabag\UserBundle\Entity\User
;
15 use Wallabag\AnnotationBundle\Entity\Annotation
;
21 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\EntryRepository")
22 * @ORM\Table(name="`entry`")
23 * @ORM\HasLifecycleCallbacks()
24 * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())")
28 /** @Serializer\XmlAttribute */
32 * @ORM\Column(name="id", type="integer")
34 * @ORM\GeneratedValue(strategy="AUTO")
36 * @Groups({"entries_for_user", "export_all"})
43 * @ORM\Column(name="uuid", type="text", nullable=true)
45 * @Groups({"entries_for_user", "export_all"})
52 * @ORM\Column(name="title", type="text", nullable=true)
54 * @Groups({"entries_for_user", "export_all"})
62 * @ORM\Column(name="url", type="text", nullable=true)
64 * @Groups({"entries_for_user", "export_all"})
73 * @ORM\Column(name="is_archived", type="boolean")
75 * @Groups({"entries_for_user", "export_all"})
77 private $isArchived = false;
84 * @ORM\Column(name="is_starred", type="boolean")
86 * @Groups({"entries_for_user", "export_all"})
88 private $isStarred = false;
93 * @ORM\Column(name="content", type="text", nullable=true)
95 * @Groups({"entries_for_user", "export_all"})
102 * @ORM\Column(name="created_at", type="datetime")
104 * @Groups({"export_all"})
111 * @ORM\Column(name="updated_at", type="datetime")
113 * @Groups({"export_all"})
118 * @ORM\OneToMany(targetEntity="Wallabag\AnnotationBundle\Entity\Annotation", mappedBy="entry", cascade={"persist", "remove"})
121 * @Groups({"entries_for_user", "export_all"})
123 private $annotations;
128 * @ORM\Column(name="mimetype", type="text", nullable=true)
130 * @Groups({"entries_for_user", "export_all"})
137 * @ORM\Column(name="language", type="text", nullable=true)
139 * @Groups({"entries_for_user", "export_all"})
146 * @ORM\Column(name="reading_time", type="integer", nullable=true)
148 * @Groups({"entries_for_user", "export_all"})
150 private $readingTime;
155 * @ORM\Column(name="domain_name", type="text", nullable=true)
157 * @Groups({"entries_for_user", "export_all"})
164 * @ORM\Column(name="preview_picture", type="text", nullable=true)
166 * @Groups({"entries_for_user", "export_all"})
168 private $previewPicture;
173 * @ORM\Column(name="is_public", type="boolean", nullable=true, options={"default" = false})
175 * @Groups({"export_all"})
182 * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="entries")
184 * @Groups({"export_all"})
189 * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"})
193 * @ORM\JoinColumn(name="entry_id", referencedColumnName="id")
195 * inverseJoinColumns={
196 * @ORM\JoinColumn(name="tag_id", referencedColumnName="id")
200 * @Groups({"entries_for_user", "export_all"})
207 public function __construct(User
$user)
210 $this->tags
= new ArrayCollection();
218 public function getId()
226 * @param string $title
230 public function setTitle($title)
232 $this->title
= $title;
242 public function getTitle()
254 public function setUrl($url)
266 public function getUrl()
274 * @param bool $isArchived
278 public function setArchived($isArchived)
280 $this->isArchived
= $isArchived;
290 public function isArchived()
292 return $this->isArchived
;
297 * @SerializedName("is_archived")
298 * @Groups({"entries_for_user", "export_all"})
300 public function is_Archived()
302 return (int) $this->isArchived();
305 public function toggleArchive()
307 $this->isArchived
= $this->isArchived() ^
1;
315 * @param bool $isStarred
319 public function setStarred($isStarred)
321 $this->isStarred
= $isStarred;
331 public function isStarred()
333 return $this->isStarred
;
338 * @SerializedName("is_starred")
339 * @Groups({"entries_for_user", "export_all"})
341 public function is_Starred()
343 return (int) $this->isStarred();
346 public function toggleStar()
348 $this->isStarred
= $this->isStarred() ^
1;
356 * @param string $content
360 public function setContent($content)
362 $this->content
= $content;
372 public function getContent()
374 return $this->content
;
380 public function getUser()
387 * @SerializedName("user_name")
389 public function getUserName()
391 return $this->user
->getUserName();
396 * @SerializedName("user_email")
398 public function getUserEmail()
400 return $this->user
->getEmail();
405 * @SerializedName("user_id")
407 public function getUserId()
409 return $this->user
->getId();
415 public function getCreatedAt()
417 return $this->createdAt
;
423 public function getUpdatedAt()
425 return $this->updatedAt
;
432 public function timestamps()
434 if (is_null($this->createdAt
)) {
435 $this->createdAt
= new \
DateTime();
438 $this->updatedAt
= new \
DateTime();
440 $this->generateUuid();
444 * @return ArrayCollection<Annotation>
446 public function getAnnotations()
448 return $this->annotations
;
452 * @param Annotation $annotation
454 public function setAnnotation(Annotation
$annotation)
456 $this->annotations
[] = $annotation;
462 public function getMimetype()
464 return $this->mimetype
;
468 * @param string $mimetype
470 public function setMimetype($mimetype)
472 $this->mimetype
= $mimetype;
478 public function getReadingTime()
480 return $this->readingTime
;
484 * @param int $readingTime
486 public function setReadingTime($readingTime)
488 $this->readingTime
= $readingTime;
494 public function getDomainName()
496 return $this->domainName
;
500 * @param string $domainName
502 public function setDomainName($domainName)
504 $this->domainName
= $domainName;
510 public function isPublic()
512 return $this->isPublic
;
516 * @param bool $isPublic
518 public function setIsPublic($isPublic)
520 $this->isPublic
= $isPublic;
524 * @return ArrayCollection<Tag>
526 public function getTags()
534 public function addTag(Tag
$tag)
536 if ($this->tags
->contains($tag)) {
540 // check if tag already exist but has not yet be persisted
541 // it seems that the previous condition with `contains()` doesn't check that case
542 foreach ($this->tags
as $existingTag) {
543 if ($existingTag->getLabel() === $tag->getLabel()) {
548 $this->tags
->add($tag);
549 $tag->addEntry($this);
552 public function removeTag(Tag
$tag)
554 if (!$this->tags
->contains($tag)) {
558 $this->tags
->removeElement($tag);
559 $tag->removeEntry($this);
563 * Set previewPicture.
565 * @param string $previewPicture
569 public function setPreviewPicture($previewPicture)
571 $this->previewPicture
= $previewPicture;
577 * Get previewPicture.
581 public function getPreviewPicture()
583 return $this->previewPicture
;
589 * @param string $language
593 public function setLanguage($language)
595 $this->language
= $language;
605 public function getLanguage()
607 return $this->language
;
613 public function getUuid()
623 public function setUuid($uuid)
630 public function generateUuid()
632 if (empty($this->uuid
) || is_null($this->uuid
)) {
633 $this->uuid
= uniqid();