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"}),
29 * @ORM\Index(name="hashed_url", columns={"hashed_url"})
32 * @ORM\HasLifecycleCallbacks()
33 * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())")
37 use EntityTimestampsTrait
;
39 /** @Serializer\XmlAttribute */
43 * @ORM\Column(name="id", type="integer")
45 * @ORM\GeneratedValue(strategy="AUTO")
47 * @Groups({"entries_for_user", "export_all"})
54 * @ORM\Column(name="uid", type="string", length=23, nullable=true)
56 * @Groups({"entries_for_user", "export_all"})
63 * @ORM\Column(name="title", type="text", nullable=true)
65 * @Groups({"entries_for_user", "export_all"})
73 * @ORM\Column(name="url", type="text", nullable=true)
75 * @Groups({"entries_for_user", "export_all"})
82 * @ORM\Column(name="hashed_url", type="string", length=32, nullable=true)
91 * @ORM\Column(name="is_archived", type="boolean")
93 * @Groups({"entries_for_user", "export_all"})
95 private $isArchived = false;
100 * @ORM\Column(name="archived_at", type="datetime", nullable=true)
102 * @Groups({"entries_for_user", "export_all"})
104 private $archivedAt = null;
111 * @ORM\Column(name="is_starred", type="boolean")
113 * @Groups({"entries_for_user", "export_all"})
115 private $isStarred = false;
120 * @ORM\Column(name="content", type="text", nullable=true)
122 * @Groups({"entries_for_user", "export_all"})
129 * @ORM\Column(name="created_at", type="datetime")
131 * @Groups({"entries_for_user", "export_all"})
138 * @ORM\Column(name="updated_at", type="datetime")
140 * @Groups({"entries_for_user", "export_all"})
147 * @ORM\Column(name="published_at", type="datetime", nullable=true)
149 * @Groups({"entries_for_user", "export_all"})
151 private $publishedAt;
156 * @ORM\Column(name="published_by", type="array", nullable=true)
158 * @Groups({"entries_for_user", "export_all"})
160 private $publishedBy;
165 * @ORM\Column(name="starred_at", type="datetime", nullable=true)
167 * @Groups({"entries_for_user", "export_all"})
169 private $starredAt = null;
172 * @ORM\OneToMany(targetEntity="Wallabag\AnnotationBundle\Entity\Annotation", mappedBy="entry", cascade={"persist", "remove"})
175 * @Groups({"entries_for_user", "export_all"})
177 private $annotations;
182 * @ORM\Column(name="mimetype", type="text", nullable=true)
184 * @Groups({"entries_for_user", "export_all"})
191 * @ORM\Column(name="language", type="text", nullable=true)
193 * @Groups({"entries_for_user", "export_all"})
200 * @ORM\Column(name="reading_time", type="integer", nullable=false)
202 * @Groups({"entries_for_user", "export_all"})
204 private $readingTime = 0;
209 * @ORM\Column(name="domain_name", type="text", nullable=true)
211 * @Groups({"entries_for_user", "export_all"})
218 * @ORM\Column(name="preview_picture", type="text", nullable=true)
220 * @Groups({"entries_for_user", "export_all"})
222 private $previewPicture;
227 * @ORM\Column(name="http_status", type="string", length=3, nullable=true)
229 * @Groups({"entries_for_user", "export_all"})
236 * @ORM\Column(name="headers", type="array", nullable=true)
238 * @Groups({"entries_for_user", "export_all"})
245 * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="entries")
247 * @Groups({"export_all"})
252 * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"})
256 * @ORM\JoinColumn(name="entry_id", referencedColumnName="id", onDelete="cascade")
258 * inverseJoinColumns={
259 * @ORM\JoinColumn(name="tag_id", referencedColumnName="id", onDelete="cascade")
268 * @ORM\Column(name="origin_url", type="text", nullable=true)
270 * @Groups({"entries_for_user", "export_all"})
277 public function __construct(User
$user)
280 $this->tags
= new ArrayCollection();
288 public function getId()
296 * @param string $title
300 public function setTitle($title)
302 $this->title
= $title;
312 public function getTitle()
324 public function setUrl($url)
336 public function getUrl()
344 * @param bool $isArchived
348 public function setArchived($isArchived)
350 $this->isArchived
= $isArchived;
356 * update isArchived and archive_at fields.
358 * @param bool $isArchived
362 public function updateArchived($isArchived = false)
364 $this->setArchived($isArchived);
365 $this->setArchivedAt(null);
366 if ($this->isArchived()) {
367 $this->setArchivedAt(new \
DateTime());
374 * @return \DateTime|null
376 public function getArchivedAt()
378 return $this->archivedAt
;
382 * @param \DateTime|null $archivedAt
386 public function setArchivedAt($archivedAt = null)
388 $this->archivedAt
= $archivedAt;
398 public function isArchived()
400 return $this->isArchived
;
405 * @SerializedName("is_archived")
406 * @Groups({"entries_for_user", "export_all"})
408 public function is_Archived()
410 return (int) $this->isArchived();
413 public function toggleArchive()
415 $this->updateArchived($this->isArchived() ^
1);
423 * @param bool $isStarred
427 public function setStarred($isStarred)
429 $this->isStarred
= $isStarred;
439 public function isStarred()
441 return $this->isStarred
;
446 * @SerializedName("is_starred")
447 * @Groups({"entries_for_user", "export_all"})
449 public function is_Starred()
451 return (int) $this->isStarred();
454 public function toggleStar()
456 $this->isStarred
= $this->isStarred() ^
1;
464 * @param string $content
468 public function setContent($content)
470 $this->content
= $content;
480 public function getContent()
482 return $this->content
;
488 public function getUser()
495 * @SerializedName("user_name")
497 public function getUserName()
499 return $this->user
->getUserName();
504 * @SerializedName("user_email")
506 public function getUserEmail()
508 return $this->user
->getEmail();
513 * @SerializedName("user_id")
515 public function getUserId()
517 return $this->user
->getId();
522 * Only used when importing data from an other service.
524 * @param \DateTime $createdAt
528 public function setCreatedAt(\DateTime
$createdAt)
530 $this->createdAt
= $createdAt;
538 public function getCreatedAt()
540 return $this->createdAt
;
546 public function getUpdatedAt()
548 return $this->updatedAt
;
552 * @return \DateTime|null
554 public function getStarredAt()
556 return $this->starredAt
;
560 * @param \DateTime|null $starredAt
564 public function setStarredAt($starredAt = null)
566 $this->starredAt
= $starredAt;
572 * update isStarred and starred_at fields.
574 * @param bool $isStarred
578 public function updateStar($isStarred = false)
580 $this->setStarred($isStarred);
581 $this->setStarredAt(null);
582 if ($this->isStarred()) {
583 $this->setStarredAt(new \
DateTime());
590 * @return ArrayCollection<Annotation>
592 public function getAnnotations()
594 return $this->annotations
;
598 * @param Annotation $annotation
600 public function setAnnotation(Annotation
$annotation)
602 $this->annotations
[] = $annotation;
608 public function getMimetype()
610 return $this->mimetype
;
614 * @param string $mimetype
616 public function setMimetype($mimetype)
618 $this->mimetype
= $mimetype;
624 public function getReadingTime()
626 return $this->readingTime
;
630 * @param int $readingTime
632 public function setReadingTime($readingTime)
634 $this->readingTime
= $readingTime;
640 public function getDomainName()
642 return $this->domainName
;
646 * @param string $domainName
648 public function setDomainName($domainName)
650 $this->domainName
= $domainName;
654 * @return ArrayCollection
656 public function getTags()
663 * @SerializedName("tags")
664 * @Groups({"entries_for_user", "export_all"})
666 public function getSerializedTags()
669 foreach ($this->tags
as $tag) {
670 $data[] = $tag->getLabel();
679 public function addTag(Tag
$tag)
681 if ($this->tags
->contains($tag)) {
685 // check if tag already exist but has not yet be persisted
686 // it seems that the previous condition with `contains()` doesn't check that case
687 foreach ($this->tags
as $existingTag) {
688 if ($existingTag->getLabel() === $tag->getLabel()) {
693 $this->tags
->add($tag);
694 $tag->addEntry($this);
698 * Remove the given tag from the entry (if the tag is associated).
702 public function removeTag(Tag
$tag)
704 if (!$this->tags
->contains($tag)) {
708 $this->tags
->removeElement($tag);
709 $tag->removeEntry($this);
713 * Remove all assigned tags from the entry.
715 public function removeAllTags()
717 foreach ($this->tags
as $tag) {
718 $this->tags
->removeElement($tag);
719 $tag->removeEntry($this);
724 * Set previewPicture.
726 * @param string $previewPicture
730 public function setPreviewPicture($previewPicture)
732 $this->previewPicture
= $previewPicture;
738 * Get previewPicture.
742 public function getPreviewPicture()
744 return $this->previewPicture
;
750 * @param string $language
754 public function setLanguage($language)
756 $this->language
= $language;
766 public function getLanguage()
768 return $this->language
;
774 public function getUid()
784 public function setUid($uid)
791 public function generateUid()
793 if (null === $this->uid
) {
794 // @see http://blog.kevingomez.fr/til/2015/07/26/why-is-uniqid-slow/ for true parameter
795 $this->uid
= uniqid('', true);
799 public function cleanUid()
805 * Used in the entries filter so it's more explicit for the end user than the uid.
806 * Also used in the API.
809 * @SerializedName("is_public")
810 * @Groups({"entries_for_user"})
814 public function isPublic()
816 return null !== $this->uid
;
822 public function getHttpStatus()
824 return $this->httpStatus
;
828 * @param string $httpStatus
832 public function setHttpStatus($httpStatus)
834 $this->httpStatus
= $httpStatus;
842 public function getPublishedAt()
844 return $this->publishedAt
;
848 * @param \Datetime $publishedAt
852 public function setPublishedAt(\Datetime
$publishedAt)
854 $this->publishedAt
= $publishedAt;
862 public function getPublishedBy()
864 return $this->publishedBy
;
868 * @param array $publishedBy
872 public function setPublishedBy($publishedBy)
874 $this->publishedBy
= $publishedBy;
882 public function getHeaders()
884 return $this->headers
;
888 * @param array $headers
892 public function setHeaders($headers)
894 $this->headers
= $headers;
902 * @param string $originUrl
906 public function setOriginUrl($originUrl)
908 $this->originUrl
= $originUrl;
918 public function getOriginUrl()
920 return $this->originUrl
;
926 public function getHashedUrl()
928 return $this->hashedUrl
;
932 * @param mixed $hashedUrl
936 public function setHashedUrl($hashedUrl)
938 $this->hashedUrl
= $hashedUrl;