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\CoreBundle\Helper\UrlHasher
;
17 use Wallabag\UserBundle\Entity\User
;
23 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\EntryRepository")
26 * options={"collate"="utf8mb4_unicode_ci", "charset"="utf8mb4"},
28 * @ORM\Index(name="created_at", columns={"created_at"}),
29 * @ORM\Index(name="uid", columns={"uid"}),
30 * @ORM\Index(name="hashed_urls_user_id", columns={"user_id", "hashed_url", "hashed_given_url"}, options={"lengths"={null, 40, 40}})
33 * @ORM\HasLifecycleCallbacks()
34 * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())")
38 use EntityTimestampsTrait
;
40 /** @Serializer\XmlAttribute */
44 * @ORM\Column(name="id", type="integer")
46 * @ORM\GeneratedValue(strategy="AUTO")
48 * @Groups({"entries_for_user", "export_all"})
55 * @ORM\Column(name="uid", type="string", length=23, nullable=true)
57 * @Groups({"entries_for_user", "export_all"})
64 * @ORM\Column(name="title", type="text", nullable=true)
66 * @Groups({"entries_for_user", "export_all"})
71 * Define the url fetched by wallabag (the final url after potential redirections).
76 * @ORM\Column(name="url", type="text", nullable=true)
78 * @Groups({"entries_for_user", "export_all"})
85 * @ORM\Column(name="hashed_url", type="string", length=40, nullable=true)
90 * From where user retrieved/found the url (an other article, a twitter, or the given_url if non are provided).
94 * @ORM\Column(name="origin_url", type="text", nullable=true)
96 * @Groups({"entries_for_user", "export_all"})
101 * Define the url entered by the user (without redirections).
105 * @ORM\Column(name="given_url", type="text", nullable=true)
107 * @Groups({"entries_for_user", "export_all"})
114 * @ORM\Column(name="hashed_given_url", type="string", length=40, nullable=true)
116 private $hashedGivenUrl;
123 * @ORM\Column(name="is_archived", type="boolean")
125 * @Groups({"entries_for_user", "export_all"})
127 private $isArchived = false;
132 * @ORM\Column(name="archived_at", type="datetime", nullable=true)
134 * @Groups({"entries_for_user", "export_all"})
136 private $archivedAt = null;
143 * @ORM\Column(name="is_starred", type="boolean")
145 * @Groups({"entries_for_user", "export_all"})
147 private $isStarred = false;
152 * @ORM\Column(name="content", type="text", nullable=true)
154 * @Groups({"entries_for_user", "export_all"})
161 * @ORM\Column(name="created_at", type="datetime")
163 * @Groups({"entries_for_user", "export_all"})
170 * @ORM\Column(name="updated_at", type="datetime")
172 * @Groups({"entries_for_user", "export_all"})
179 * @ORM\Column(name="published_at", type="datetime", nullable=true)
181 * @Groups({"entries_for_user", "export_all"})
183 private $publishedAt;
188 * @ORM\Column(name="published_by", type="array", nullable=true)
190 * @Groups({"entries_for_user", "export_all"})
192 private $publishedBy;
197 * @ORM\Column(name="starred_at", type="datetime", nullable=true)
199 * @Groups({"entries_for_user", "export_all"})
201 private $starredAt = null;
204 * @ORM\OneToMany(targetEntity="Wallabag\AnnotationBundle\Entity\Annotation", mappedBy="entry", cascade={"persist", "remove"})
207 * @Groups({"entries_for_user", "export_all"})
209 private $annotations;
214 * @ORM\Column(name="mimetype", type="text", nullable=true)
216 * @Groups({"entries_for_user", "export_all"})
223 * @ORM\Column(name="language", type="text", nullable=true)
225 * @Groups({"entries_for_user", "export_all"})
232 * @ORM\Column(name="reading_time", type="integer", nullable=false)
234 * @Groups({"entries_for_user", "export_all"})
236 private $readingTime = 0;
241 * @ORM\Column(name="domain_name", type="text", nullable=true)
243 * @Groups({"entries_for_user", "export_all"})
250 * @ORM\Column(name="preview_picture", type="text", nullable=true)
252 * @Groups({"entries_for_user", "export_all"})
254 private $previewPicture;
259 * @ORM\Column(name="http_status", type="string", length=3, nullable=true)
261 * @Groups({"entries_for_user", "export_all"})
268 * @ORM\Column(name="headers", type="array", nullable=true)
270 * @Groups({"entries_for_user", "export_all"})
277 * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="entries")
279 * @Groups({"export_all"})
284 * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"})
288 * @ORM\JoinColumn(name="entry_id", referencedColumnName="id", onDelete="cascade")
290 * inverseJoinColumns={
291 * @ORM\JoinColumn(name="tag_id", referencedColumnName="id", onDelete="cascade")
300 public function __construct(User
$user)
303 $this->tags
= new ArrayCollection();
311 public function getId()
319 * @param string $title
323 public function setTitle($title)
325 $this->title
= $title;
335 public function getTitle()
347 public function setUrl($url)
350 $this->hashedUrl
= UrlHasher
::hashUrl($url);
360 public function getUrl()
368 * @param bool $isArchived
372 public function setArchived($isArchived)
374 $this->isArchived
= $isArchived;
380 * update isArchived and archive_at fields.
382 * @param bool $isArchived
386 public function updateArchived($isArchived = false)
388 $this->setArchived($isArchived);
389 $this->setArchivedAt(null);
390 if ($this->isArchived()) {
391 $this->setArchivedAt(new \
DateTime());
398 * @return \DateTime|null
400 public function getArchivedAt()
402 return $this->archivedAt
;
406 * @param \DateTime|null $archivedAt
410 public function setArchivedAt($archivedAt = null)
412 $this->archivedAt
= $archivedAt;
422 public function isArchived()
424 return $this->isArchived
;
429 * @SerializedName("is_archived")
430 * @Groups({"entries_for_user", "export_all"})
432 public function is_Archived()
434 return (int) $this->isArchived();
437 public function toggleArchive()
439 $this->updateArchived($this->isArchived() ^
1);
447 * @param bool $isStarred
451 public function setStarred($isStarred)
453 $this->isStarred
= $isStarred;
463 public function isStarred()
465 return $this->isStarred
;
470 * @SerializedName("is_starred")
471 * @Groups({"entries_for_user", "export_all"})
473 public function is_Starred()
475 return (int) $this->isStarred();
478 public function toggleStar()
480 $this->isStarred
= $this->isStarred() ^
1;
488 * @param string $content
492 public function setContent($content)
494 $this->content
= $content;
504 public function getContent()
506 return $this->content
;
512 public function getUser()
519 * @SerializedName("user_name")
521 public function getUserName()
523 return $this->user
->getUserName();
528 * @SerializedName("user_email")
530 public function getUserEmail()
532 return $this->user
->getEmail();
537 * @SerializedName("user_id")
539 public function getUserId()
541 return $this->user
->getId();
546 * Only used when importing data from an other service.
548 * @param \DateTime $createdAt
552 public function setCreatedAt(\DateTime
$createdAt)
554 $this->createdAt
= $createdAt;
562 public function getCreatedAt()
564 return $this->createdAt
;
570 public function getUpdatedAt()
572 return $this->updatedAt
;
576 * @return \DateTime|null
578 public function getStarredAt()
580 return $this->starredAt
;
584 * @param \DateTime|null $starredAt
588 public function setStarredAt($starredAt = null)
590 $this->starredAt
= $starredAt;
596 * update isStarred and starred_at fields.
598 * @param bool $isStarred
602 public function updateStar($isStarred = false)
604 $this->setStarred($isStarred);
605 $this->setStarredAt(null);
606 if ($this->isStarred()) {
607 $this->setStarredAt(new \
DateTime());
614 * @return ArrayCollection<Annotation>
616 public function getAnnotations()
618 return $this->annotations
;
622 * @param Annotation $annotation
624 public function setAnnotation(Annotation
$annotation)
626 $this->annotations
[] = $annotation;
632 public function getMimetype()
634 return $this->mimetype
;
638 * @param string $mimetype
640 public function setMimetype($mimetype)
642 $this->mimetype
= $mimetype;
648 public function getReadingTime()
650 return $this->readingTime
;
654 * @param int $readingTime
656 public function setReadingTime($readingTime)
658 $this->readingTime
= $readingTime;
664 public function getDomainName()
666 return $this->domainName
;
670 * @param string $domainName
672 public function setDomainName($domainName)
674 $this->domainName
= $domainName;
678 * @return ArrayCollection
680 public function getTags()
687 * @SerializedName("tags")
688 * @Groups({"entries_for_user", "export_all"})
690 public function getSerializedTags()
693 foreach ($this->tags
as $tag) {
694 $data[] = $tag->getLabel();
703 public function addTag(Tag
$tag)
705 if ($this->tags
->contains($tag)) {
709 // check if tag already exist but has not yet be persisted
710 // it seems that the previous condition with `contains()` doesn't check that case
711 foreach ($this->tags
as $existingTag) {
712 if ($existingTag->getLabel() === $tag->getLabel()) {
717 $this->tags
->add($tag);
718 $tag->addEntry($this);
722 * Remove the given tag from the entry (if the tag is associated).
726 public function removeTag(Tag
$tag)
728 if (!$this->tags
->contains($tag)) {
732 $this->tags
->removeElement($tag);
733 $tag->removeEntry($this);
737 * Remove all assigned tags from the entry.
739 public function removeAllTags()
741 foreach ($this->tags
as $tag) {
742 $this->tags
->removeElement($tag);
743 $tag->removeEntry($this);
748 * Set previewPicture.
750 * @param string $previewPicture
754 public function setPreviewPicture($previewPicture)
756 $this->previewPicture
= $previewPicture;
762 * Get previewPicture.
766 public function getPreviewPicture()
768 return $this->previewPicture
;
774 * @param string $language
778 public function setLanguage($language)
780 $this->language
= $language;
790 public function getLanguage()
792 return $this->language
;
798 public function getUid()
808 public function setUid($uid)
815 public function generateUid()
817 if (null === $this->uid
) {
818 // @see http://blog.kevingomez.fr/til/2015/07/26/why-is-uniqid-slow/ for true parameter
819 $this->uid
= uniqid('', true);
823 public function cleanUid()
829 * Used in the entries filter so it's more explicit for the end user than the uid.
830 * Also used in the API.
833 * @SerializedName("is_public")
834 * @Groups({"entries_for_user"})
838 public function isPublic()
840 return null !== $this->uid
;
846 public function getHttpStatus()
848 return $this->httpStatus
;
852 * @param string $httpStatus
856 public function setHttpStatus($httpStatus)
858 $this->httpStatus
= $httpStatus;
866 public function getPublishedAt()
868 return $this->publishedAt
;
872 * @param \Datetime $publishedAt
876 public function setPublishedAt(\Datetime
$publishedAt)
878 $this->publishedAt
= $publishedAt;
886 public function getPublishedBy()
888 return $this->publishedBy
;
892 * @param array $publishedBy
896 public function setPublishedBy($publishedBy)
898 $this->publishedBy
= $publishedBy;
906 public function getHeaders()
908 return $this->headers
;
912 * @param array $headers
916 public function setHeaders($headers)
918 $this->headers
= $headers;
926 * @param string $originUrl
930 public function setOriginUrl($originUrl)
932 $this->originUrl
= $originUrl;
942 public function getOriginUrl()
944 return $this->originUrl
;
950 * @param string $givenUrl
954 public function setGivenUrl($givenUrl)
956 $this->givenUrl
= $givenUrl;
957 $this->hashedGivenUrl
= UrlHasher
::hashUrl($givenUrl);
967 public function getGivenUrl()
969 return $this->givenUrl
;
975 public function getHashedUrl()
977 return $this->hashedUrl
;
981 * @param mixed $hashedUrl
985 public function setHashedUrl($hashedUrl)
987 $this->hashedUrl
= $hashedUrl;