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\Exclude
;
9 use JMS\Serializer\Annotation\Groups
;
10 use JMS\Serializer\Annotation\SerializedName
;
11 use JMS\Serializer\Annotation\VirtualProperty
;
12 use JMS\Serializer\Annotation\XmlRoot
;
13 use Symfony\Component\Validator\Constraints
as Assert
;
14 use Wallabag\AnnotationBundle\Entity\Annotation
;
15 use Wallabag\CoreBundle\Helper\EntityTimestampsTrait
;
16 use Wallabag\UserBundle\Entity\User
;
22 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\EntryRepository")
25 * options={"collate"="utf8mb4_unicode_ci", "charset"="utf8mb4"},
27 * @ORM\Index(name="created_at", columns={"created_at"}),
28 * @ORM\Index(name="uid", columns={"uid"})
31 * @ORM\HasLifecycleCallbacks()
32 * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())")
36 use EntityTimestampsTrait
;
38 /** @Serializer\XmlAttribute */
42 * @ORM\Column(name="id", type="integer")
44 * @ORM\GeneratedValue(strategy="AUTO")
46 * @Groups({"entries_for_user", "export_all"})
53 * @ORM\Column(name="uid", type="string", length=23, nullable=true)
55 * @Groups({"entries_for_user", "export_all"})
62 * @ORM\Column(name="title", type="text", nullable=true)
64 * @Groups({"entries_for_user", "export_all"})
72 * @ORM\Column(name="url", type="text", nullable=true)
74 * @Groups({"entries_for_user", "export_all"})
83 * @ORM\Column(name="is_archived", type="boolean")
85 * @Groups({"entries_for_user", "export_all"})
87 private $isArchived = false;
94 * @ORM\Column(name="is_starred", type="boolean")
96 * @Groups({"entries_for_user", "export_all"})
98 private $isStarred = false;
103 * @ORM\Column(name="content", type="text", nullable=true)
105 * @Groups({"entries_for_user", "export_all"})
112 * @ORM\Column(name="created_at", type="datetime")
114 * @Groups({"entries_for_user", "export_all"})
121 * @ORM\Column(name="updated_at", type="datetime")
123 * @Groups({"entries_for_user", "export_all"})
130 * @ORM\Column(name="published_at", type="datetime", nullable=true)
132 * @Groups({"entries_for_user", "export_all"})
134 private $publishedAt;
139 * @ORM\Column(name="published_by", type="array", nullable=true)
141 * @Groups({"entries_for_user", "export_all"})
143 private $publishedBy;
148 * @ORM\Column(name="starred_at", type="datetime", nullable=true)
150 * @Groups({"entries_for_user", "export_all"})
152 private $starredAt = null;
155 * @ORM\OneToMany(targetEntity="Wallabag\AnnotationBundle\Entity\Annotation", mappedBy="entry", cascade={"persist", "remove"})
158 * @Groups({"entries_for_user", "export_all"})
160 private $annotations;
165 * @ORM\Column(name="mimetype", type="text", nullable=true)
167 * @Groups({"entries_for_user", "export_all"})
174 * @ORM\Column(name="language", type="text", nullable=true)
176 * @Groups({"entries_for_user", "export_all"})
183 * @ORM\Column(name="reading_time", type="integer", nullable=false)
185 * @Groups({"entries_for_user", "export_all"})
187 private $readingTime = 0;
192 * @ORM\Column(name="domain_name", type="text", nullable=true)
194 * @Groups({"entries_for_user", "export_all"})
201 * @ORM\Column(name="preview_picture", type="text", nullable=true)
203 * @Groups({"entries_for_user", "export_all"})
205 private $previewPicture;
210 * @ORM\Column(name="http_status", type="string", length=3, nullable=true)
212 * @Groups({"entries_for_user", "export_all"})
219 * @ORM\Column(name="headers", type="array", nullable=true)
221 * @Groups({"entries_for_user", "export_all"})
228 * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="entries")
230 * @Groups({"export_all"})
235 * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"})
239 * @ORM\JoinColumn(name="entry_id", referencedColumnName="id", onDelete="cascade")
241 * inverseJoinColumns={
242 * @ORM\JoinColumn(name="tag_id", referencedColumnName="id", onDelete="cascade")
251 * @ORM\Column(name="origin_url", type="text", nullable=true)
253 * @Groups({"entries_for_user", "export_all"})
260 public function __construct(User
$user)
263 $this->tags
= new ArrayCollection();
271 public function getId()
279 * @param string $title
283 public function setTitle($title)
285 $this->title
= $title;
295 public function getTitle()
307 public function setUrl($url)
319 public function getUrl()
327 * @param bool $isArchived
331 public function setArchived($isArchived)
333 $this->isArchived
= $isArchived;
343 public function isArchived()
345 return $this->isArchived
;
350 * @SerializedName("is_archived")
351 * @Groups({"entries_for_user", "export_all"})
353 public function is_Archived()
355 return (int) $this->isArchived();
358 public function toggleArchive()
360 $this->isArchived
= $this->isArchived() ^
1;
368 * @param bool $isStarred
372 public function setStarred($isStarred)
374 $this->isStarred
= $isStarred;
384 public function isStarred()
386 return $this->isStarred
;
391 * @SerializedName("is_starred")
392 * @Groups({"entries_for_user", "export_all"})
394 public function is_Starred()
396 return (int) $this->isStarred();
399 public function toggleStar()
401 $this->isStarred
= $this->isStarred() ^
1;
409 * @param string $content
413 public function setContent($content)
415 $this->content
= $content;
425 public function getContent()
427 return $this->content
;
433 public function getUser()
440 * @SerializedName("user_name")
442 public function getUserName()
444 return $this->user
->getUserName();
449 * @SerializedName("user_email")
451 public function getUserEmail()
453 return $this->user
->getEmail();
458 * @SerializedName("user_id")
460 public function getUserId()
462 return $this->user
->getId();
467 * Only used when importing data from an other service.
469 * @param \DateTime $createdAt
473 public function setCreatedAt(\DateTime
$createdAt)
475 $this->createdAt
= $createdAt;
483 public function getCreatedAt()
485 return $this->createdAt
;
491 public function getUpdatedAt()
493 return $this->updatedAt
;
497 * @return \DateTime|null
499 public function getStarredAt()
501 return $this->starredAt
;
505 * @param \DateTime|null $starredAt
509 public function setStarredAt($starredAt = null)
511 $this->starredAt
= $starredAt;
517 * update isStarred and starred_at fields.
519 * @param bool $isStarred
523 public function updateStar($isStarred = false)
525 $this->setStarred($isStarred);
526 $this->setStarredAt(null);
527 if ($this->isStarred()) {
528 $this->setStarredAt(new \
DateTime());
535 * @return ArrayCollection<Annotation>
537 public function getAnnotations()
539 return $this->annotations
;
543 * @param Annotation $annotation
545 public function setAnnotation(Annotation
$annotation)
547 $this->annotations
[] = $annotation;
553 public function getMimetype()
555 return $this->mimetype
;
559 * @param string $mimetype
561 public function setMimetype($mimetype)
563 $this->mimetype
= $mimetype;
569 public function getReadingTime()
571 return $this->readingTime
;
575 * @param int $readingTime
577 public function setReadingTime($readingTime)
579 $this->readingTime
= $readingTime;
585 public function getDomainName()
587 return $this->domainName
;
591 * @param string $domainName
593 public function setDomainName($domainName)
595 $this->domainName
= $domainName;
599 * @return ArrayCollection
601 public function getTags()
608 * @SerializedName("tags")
609 * @Groups({"entries_for_user", "export_all"})
611 public function getSerializedTags()
614 foreach ($this->tags
as $tag) {
615 $data[] = $tag->getLabel();
624 public function addTag(Tag
$tag)
626 if ($this->tags
->contains($tag)) {
630 // check if tag already exist but has not yet be persisted
631 // it seems that the previous condition with `contains()` doesn't check that case
632 foreach ($this->tags
as $existingTag) {
633 if ($existingTag->getLabel() === $tag->getLabel()) {
638 $this->tags
->add($tag);
639 $tag->addEntry($this);
643 * Remove the given tag from the entry (if the tag is associated).
647 public function removeTag(Tag
$tag)
649 if (!$this->tags
->contains($tag)) {
653 $this->tags
->removeElement($tag);
654 $tag->removeEntry($this);
658 * Remove all assigned tags from the entry.
660 public function removeAllTags()
662 foreach ($this->tags
as $tag) {
663 $this->tags
->removeElement($tag);
664 $tag->removeEntry($this);
669 * Set previewPicture.
671 * @param string $previewPicture
675 public function setPreviewPicture($previewPicture)
677 $this->previewPicture
= $previewPicture;
683 * Get previewPicture.
687 public function getPreviewPicture()
689 return $this->previewPicture
;
695 * @param string $language
699 public function setLanguage($language)
701 $this->language
= $language;
711 public function getLanguage()
713 return $this->language
;
719 public function getUid()
729 public function setUid($uid)
736 public function generateUid()
738 if (null === $this->uid
) {
739 // @see http://blog.kevingomez.fr/til/2015/07/26/why-is-uniqid-slow/ for true parameter
740 $this->uid
= uniqid('', true);
744 public function cleanUid()
750 * Used in the entries filter so it's more explicit for the end user than the uid.
751 * Also used in the API.
754 * @SerializedName("is_public")
755 * @Groups({"entries_for_user"})
759 public function isPublic()
761 return null !== $this->uid
;
767 public function getHttpStatus()
769 return $this->httpStatus
;
773 * @param string $httpStatus
777 public function setHttpStatus($httpStatus)
779 $this->httpStatus
= $httpStatus;
787 public function getPublishedAt()
789 return $this->publishedAt
;
793 * @param \Datetime $publishedAt
797 public function setPublishedAt(\Datetime
$publishedAt)
799 $this->publishedAt
= $publishedAt;
807 public function getPublishedBy()
809 return $this->publishedBy
;
813 * @param array $publishedBy
817 public function setPublishedBy($publishedBy)
819 $this->publishedBy
= $publishedBy;
827 public function getHeaders()
829 return $this->headers
;
833 * @param array $headers
837 public function setHeaders($headers)
839 $this->headers
= $headers;
847 * @param string $originUrl
851 public function setOriginUrl($originUrl)
853 $this->originUrl
= $originUrl;
863 public function getOriginUrl()
865 return $this->originUrl
;