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")
24 * options={"collate"="utf8mb4_unicode_ci", "charset"="utf8mb4"},
26 * @ORM\Index(name="created_at", columns={"created_at"}),
27 * @ORM\Index(name="uid", columns={"uid"})
30 * @ORM\HasLifecycleCallbacks()
31 * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())")
35 /** @Serializer\XmlAttribute */
39 * @ORM\Column(name="id", type="integer")
41 * @ORM\GeneratedValue(strategy="AUTO")
43 * @Groups({"entries_for_user", "export_all"})
50 * @ORM\Column(name="uid", type="string", length=23, nullable=true)
52 * @Groups({"entries_for_user", "export_all"})
59 * @ORM\Column(name="title", type="text", nullable=true)
61 * @Groups({"entries_for_user", "export_all"})
69 * @ORM\Column(name="url", type="text", nullable=true)
71 * @Groups({"entries_for_user", "export_all"})
80 * @ORM\Column(name="is_archived", type="boolean")
82 * @Groups({"entries_for_user", "export_all"})
84 private $isArchived = false;
91 * @ORM\Column(name="is_starred", type="boolean")
93 * @Groups({"entries_for_user", "export_all"})
95 private $isStarred = false;
100 * @ORM\Column(name="content", type="text", nullable=true)
102 * @Groups({"entries_for_user", "export_all"})
109 * @ORM\Column(name="created_at", type="datetime")
111 * @Groups({"entries_for_user", "export_all"})
118 * @ORM\Column(name="updated_at", type="datetime")
120 * @Groups({"entries_for_user", "export_all"})
127 * @ORM\Column(name="published_at", type="datetime", nullable=true)
129 * @Groups({"entries_for_user", "export_all"})
131 private $publishedAt;
136 * @ORM\Column(name="published_by", type="array", nullable=true)
138 * @Groups({"entries_for_user", "export_all"})
140 private $publishedBy;
143 * @ORM\OneToMany(targetEntity="Wallabag\AnnotationBundle\Entity\Annotation", mappedBy="entry", cascade={"persist", "remove"})
146 * @Groups({"entries_for_user", "export_all"})
148 private $annotations;
153 * @ORM\Column(name="mimetype", type="text", nullable=true)
155 * @Groups({"entries_for_user", "export_all"})
162 * @ORM\Column(name="language", type="text", nullable=true)
164 * @Groups({"entries_for_user", "export_all"})
171 * @ORM\Column(name="reading_time", type="integer", nullable=true)
173 * @Groups({"entries_for_user", "export_all"})
175 private $readingTime;
180 * @ORM\Column(name="domain_name", type="text", nullable=true)
182 * @Groups({"entries_for_user", "export_all"})
189 * @ORM\Column(name="preview_picture", type="text", nullable=true)
191 * @Groups({"entries_for_user", "export_all"})
193 private $previewPicture;
198 * @ORM\Column(name="http_status", type="string", length=3, nullable=true)
200 * @Groups({"entries_for_user", "export_all"})
207 * @ORM\Column(name="headers", type="array", nullable=true)
209 * @Groups({"entries_for_user", "export_all"})
216 * @ORM\Column(name="progress", type="integer", nullable=true)
218 * @Groups({"entries_for_user", "export_all"})
220 private $progress = 0;
225 * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="entries")
227 * @Groups({"export_all"})
232 * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"})
236 * @ORM\JoinColumn(name="entry_id", referencedColumnName="id", onDelete="cascade")
238 * inverseJoinColumns={
239 * @ORM\JoinColumn(name="tag_id", referencedColumnName="id", onDelete="cascade")
248 public function __construct(User
$user)
251 $this->tags
= new ArrayCollection();
259 public function getId()
267 * @param string $title
271 public function setTitle($title)
273 $this->title
= $title;
283 public function getTitle()
295 public function setUrl($url)
307 public function getUrl()
315 * @param bool $isArchived
319 public function setArchived($isArchived)
321 $this->isArchived
= $isArchived;
331 public function isArchived()
333 return $this->isArchived
;
338 * @SerializedName("is_archived")
339 * @Groups({"entries_for_user", "export_all"})
341 public function is_Archived()
343 return (int) $this->isArchived();
346 public function toggleArchive()
348 $this->isArchived
= $this->isArchived() ^
1;
356 * @param bool $isStarred
360 public function setStarred($isStarred)
362 $this->isStarred
= $isStarred;
372 public function isStarred()
374 return $this->isStarred
;
379 * @SerializedName("is_starred")
380 * @Groups({"entries_for_user", "export_all"})
382 public function is_Starred()
384 return (int) $this->isStarred();
387 public function toggleStar()
389 $this->isStarred
= $this->isStarred() ^
1;
397 * @param string $content
401 public function setContent($content)
403 $this->content
= $content;
413 public function getContent()
415 return $this->content
;
421 public function getUser()
428 * @SerializedName("user_name")
430 public function getUserName()
432 return $this->user
->getUserName();
437 * @SerializedName("user_email")
439 public function getUserEmail()
441 return $this->user
->getEmail();
446 * @SerializedName("user_id")
448 public function getUserId()
450 return $this->user
->getId();
455 * Only used when importing data from an other service.
457 * @param \DateTime $createdAt
461 public function setCreatedAt(\DateTime
$createdAt)
463 $this->createdAt
= $createdAt;
471 public function getCreatedAt()
473 return $this->createdAt
;
479 public function getUpdatedAt()
481 return $this->updatedAt
;
488 public function timestamps()
490 if (is_null($this->createdAt
)) {
491 $this->createdAt
= new \
DateTime();
494 $this->updatedAt
= new \
DateTime();
498 * @return ArrayCollection<Annotation>
500 public function getAnnotations()
502 return $this->annotations
;
506 * @param Annotation $annotation
508 public function setAnnotation(Annotation
$annotation)
510 $this->annotations
[] = $annotation;
516 public function getMimetype()
518 return $this->mimetype
;
522 * @param string $mimetype
524 public function setMimetype($mimetype)
526 $this->mimetype
= $mimetype;
532 public function getReadingTime()
534 return $this->readingTime
;
538 * @param int $readingTime
540 public function setReadingTime($readingTime)
542 $this->readingTime
= $readingTime;
548 public function getDomainName()
550 return $this->domainName
;
554 * @param string $domainName
556 public function setDomainName($domainName)
558 $this->domainName
= $domainName;
562 * @return ArrayCollection
564 public function getTags()
571 * @SerializedName("tags")
572 * @Groups({"entries_for_user", "export_all"})
574 public function getSerializedTags()
577 foreach ($this->tags
as $tag) {
578 $data[] = $tag->getLabel();
587 public function addTag(Tag
$tag)
589 if ($this->tags
->contains($tag)) {
593 // check if tag already exist but has not yet be persisted
594 // it seems that the previous condition with `contains()` doesn't check that case
595 foreach ($this->tags
as $existingTag) {
596 if ($existingTag->getLabel() === $tag->getLabel()) {
601 $this->tags
->add($tag);
602 $tag->addEntry($this);
605 public function removeTag(Tag
$tag)
607 if (!$this->tags
->contains($tag)) {
611 $this->tags
->removeElement($tag);
612 $tag->removeEntry($this);
616 * Set previewPicture.
618 * @param string $previewPicture
622 public function setPreviewPicture($previewPicture)
624 $this->previewPicture
= $previewPicture;
630 * Get previewPicture.
634 public function getPreviewPicture()
636 return $this->previewPicture
;
642 * @param string $language
646 public function setLanguage($language)
648 $this->language
= $language;
658 public function getLanguage()
660 return $this->language
;
666 public function getUid()
676 public function setUid($uid)
683 public function generateUid()
685 if (null === $this->uid
) {
686 // @see http://blog.kevingomez.fr/til/2015/07/26/why-is-uniqid-slow/ for true parameter
687 $this->uid
= uniqid('', true);
691 public function cleanUid()
697 * Used in the entries filter so it's more explicit for the end user than the uid.
698 * Also used in the API.
701 * @SerializedName("is_public")
702 * @Groups({"entries_for_user"})
706 public function isPublic()
708 return null !== $this->uid
;
714 public function getHttpStatus()
716 return $this->httpStatus
;
720 * @param string $httpStatus
724 public function setHttpStatus($httpStatus)
726 $this->httpStatus
= $httpStatus;
734 public function getPublishedAt()
736 return $this->publishedAt
;
740 * @param \Datetime $publishedAt
744 public function setPublishedAt(\Datetime
$publishedAt)
746 $this->publishedAt
= $publishedAt;
754 public function getPublishedBy()
756 return $this->publishedBy
;
760 * @param array $publishedBy
764 public function setPublishedBy($publishedBy)
766 $this->publishedBy
= $publishedBy;
774 * @param int $progress
778 public function setProgress($progress)
780 $this->progress
= $progress;
788 public function getHeaders()
790 return $this->headers
;
794 * @param array $headers
798 public function setHeaders($headers)
800 $this->headers
= $headers;
810 public function getProgress()
812 return $this->progress
;