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"})
71 * @ORM\Column(name="given_url", type="text", nullable=true)
73 * @Groups({"entries_for_user", "export_all"})
81 * @ORM\Column(name="url", type="text", nullable=true)
83 * @Groups({"entries_for_user", "export_all"})
92 * @ORM\Column(name="is_archived", type="boolean")
94 * @Groups({"entries_for_user", "export_all"})
96 private $isArchived = false;
103 * @ORM\Column(name="is_starred", type="boolean")
105 * @Groups({"entries_for_user", "export_all"})
107 private $isStarred = false;
112 * @ORM\Column(name="content", type="text", nullable=true)
114 * @Groups({"entries_for_user", "export_all"})
121 * @ORM\Column(name="created_at", type="datetime")
123 * @Groups({"entries_for_user", "export_all"})
130 * @ORM\Column(name="updated_at", type="datetime")
132 * @Groups({"entries_for_user", "export_all"})
139 * @ORM\Column(name="published_at", type="datetime", nullable=true)
141 * @Groups({"entries_for_user", "export_all"})
143 private $publishedAt;
148 * @ORM\Column(name="published_by", type="array", nullable=true)
150 * @Groups({"entries_for_user", "export_all"})
152 private $publishedBy;
157 * @ORM\Column(name="starred_at", type="datetime", nullable=true)
159 * @Groups({"entries_for_user", "export_all"})
161 private $starredAt = null;
164 * @ORM\OneToMany(targetEntity="Wallabag\AnnotationBundle\Entity\Annotation", mappedBy="entry", cascade={"persist", "remove"})
167 * @Groups({"entries_for_user", "export_all"})
169 private $annotations;
174 * @ORM\Column(name="mimetype", type="text", nullable=true)
176 * @Groups({"entries_for_user", "export_all"})
183 * @ORM\Column(name="language", type="text", nullable=true)
185 * @Groups({"entries_for_user", "export_all"})
192 * @ORM\Column(name="reading_time", type="integer", nullable=false)
194 * @Groups({"entries_for_user", "export_all"})
196 private $readingTime = 0;
201 * @ORM\Column(name="domain_name", type="text", nullable=true)
203 * @Groups({"entries_for_user", "export_all"})
210 * @ORM\Column(name="preview_picture", type="text", nullable=true)
212 * @Groups({"entries_for_user", "export_all"})
214 private $previewPicture;
219 * @ORM\Column(name="http_status", type="string", length=3, nullable=true)
221 * @Groups({"entries_for_user", "export_all"})
228 * @ORM\Column(name="headers", type="array", nullable=true)
230 * @Groups({"entries_for_user", "export_all"})
237 * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="entries")
239 * @Groups({"export_all"})
244 * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"})
248 * @ORM\JoinColumn(name="entry_id", referencedColumnName="id", onDelete="cascade")
250 * inverseJoinColumns={
251 * @ORM\JoinColumn(name="tag_id", referencedColumnName="id", onDelete="cascade")
260 * @ORM\Column(name="origin_url", type="text", nullable=true)
262 * @Groups({"entries_for_user", "export_all"})
269 public function __construct(User
$user)
272 $this->tags
= new ArrayCollection();
280 public function getId()
288 * @param string $title
292 public function setTitle($title)
294 $this->title
= $title;
304 public function getTitle()
312 * @param string $givenUrl
316 public function setGivenUrl($givenUrl)
318 $this->givenUrl
= $givenUrl;
328 public function getGivenUrl()
330 return $this->givenUrl
;
340 public function setUrl($url)
352 public function getUrl()
360 * @param bool $isArchived
364 public function setArchived($isArchived)
366 $this->isArchived
= $isArchived;
376 public function isArchived()
378 return $this->isArchived
;
383 * @SerializedName("is_archived")
384 * @Groups({"entries_for_user", "export_all"})
386 public function is_Archived()
388 return (int) $this->isArchived();
391 public function toggleArchive()
393 $this->isArchived
= $this->isArchived() ^
1;
401 * @param bool $isStarred
405 public function setStarred($isStarred)
407 $this->isStarred
= $isStarred;
417 public function isStarred()
419 return $this->isStarred
;
424 * @SerializedName("is_starred")
425 * @Groups({"entries_for_user", "export_all"})
427 public function is_Starred()
429 return (int) $this->isStarred();
432 public function toggleStar()
434 $this->isStarred
= $this->isStarred() ^
1;
442 * @param string $content
446 public function setContent($content)
448 $this->content
= $content;
458 public function getContent()
460 return $this->content
;
466 public function getUser()
473 * @SerializedName("user_name")
475 public function getUserName()
477 return $this->user
->getUserName();
482 * @SerializedName("user_email")
484 public function getUserEmail()
486 return $this->user
->getEmail();
491 * @SerializedName("user_id")
493 public function getUserId()
495 return $this->user
->getId();
500 * Only used when importing data from an other service.
502 * @param \DateTime $createdAt
506 public function setCreatedAt(\DateTime
$createdAt)
508 $this->createdAt
= $createdAt;
516 public function getCreatedAt()
518 return $this->createdAt
;
524 public function getUpdatedAt()
526 return $this->updatedAt
;
530 * @return \DateTime|null
532 public function getStarredAt()
534 return $this->starredAt
;
538 * @param \DateTime|null $starredAt
542 public function setStarredAt($starredAt = null)
544 $this->starredAt
= $starredAt;
550 * update isStarred and starred_at fields.
552 * @param bool $isStarred
556 public function updateStar($isStarred = false)
558 $this->setStarred($isStarred);
559 $this->setStarredAt(null);
560 if ($this->isStarred()) {
561 $this->setStarredAt(new \
DateTime());
568 * @return ArrayCollection<Annotation>
570 public function getAnnotations()
572 return $this->annotations
;
576 * @param Annotation $annotation
578 public function setAnnotation(Annotation
$annotation)
580 $this->annotations
[] = $annotation;
586 public function getMimetype()
588 return $this->mimetype
;
592 * @param string $mimetype
594 public function setMimetype($mimetype)
596 $this->mimetype
= $mimetype;
602 public function getReadingTime()
604 return $this->readingTime
;
608 * @param int $readingTime
610 public function setReadingTime($readingTime)
612 $this->readingTime
= $readingTime;
618 public function getDomainName()
620 return $this->domainName
;
624 * @param string $domainName
626 public function setDomainName($domainName)
628 $this->domainName
= $domainName;
632 * @return ArrayCollection
634 public function getTags()
641 * @SerializedName("tags")
642 * @Groups({"entries_for_user", "export_all"})
644 public function getSerializedTags()
647 foreach ($this->tags
as $tag) {
648 $data[] = $tag->getLabel();
657 public function addTag(Tag
$tag)
659 if ($this->tags
->contains($tag)) {
663 // check if tag already exist but has not yet be persisted
664 // it seems that the previous condition with `contains()` doesn't check that case
665 foreach ($this->tags
as $existingTag) {
666 if ($existingTag->getLabel() === $tag->getLabel()) {
671 $this->tags
->add($tag);
672 $tag->addEntry($this);
676 * Remove the given tag from the entry (if the tag is associated).
680 public function removeTag(Tag
$tag)
682 if (!$this->tags
->contains($tag)) {
686 $this->tags
->removeElement($tag);
687 $tag->removeEntry($this);
691 * Remove all assigned tags from the entry.
693 public function removeAllTags()
695 foreach ($this->tags
as $tag) {
696 $this->tags
->removeElement($tag);
697 $tag->removeEntry($this);
702 * Set previewPicture.
704 * @param string $previewPicture
708 public function setPreviewPicture($previewPicture)
710 $this->previewPicture
= $previewPicture;
716 * Get previewPicture.
720 public function getPreviewPicture()
722 return $this->previewPicture
;
728 * @param string $language
732 public function setLanguage($language)
734 $this->language
= $language;
744 public function getLanguage()
746 return $this->language
;
752 public function getUid()
762 public function setUid($uid)
769 public function generateUid()
771 if (null === $this->uid
) {
772 // @see http://blog.kevingomez.fr/til/2015/07/26/why-is-uniqid-slow/ for true parameter
773 $this->uid
= uniqid('', true);
777 public function cleanUid()
783 * Used in the entries filter so it's more explicit for the end user than the uid.
784 * Also used in the API.
787 * @SerializedName("is_public")
788 * @Groups({"entries_for_user"})
792 public function isPublic()
794 return null !== $this->uid
;
800 public function getHttpStatus()
802 return $this->httpStatus
;
806 * @param string $httpStatus
810 public function setHttpStatus($httpStatus)
812 $this->httpStatus
= $httpStatus;
820 public function getPublishedAt()
822 return $this->publishedAt
;
826 * @param \Datetime $publishedAt
830 public function setPublishedAt(\Datetime
$publishedAt)
832 $this->publishedAt
= $publishedAt;
840 public function getPublishedBy()
842 return $this->publishedBy
;
846 * @param array $publishedBy
850 public function setPublishedBy($publishedBy)
852 $this->publishedBy
= $publishedBy;
860 public function getHeaders()
862 return $this->headers
;
866 * @param array $headers
870 public function setHeaders($headers)
872 $this->headers
= $headers;
880 * @param string $originUrl
884 public function setOriginUrl($originUrl)
886 $this->originUrl
= $originUrl;
896 public function getOriginUrl()
898 return $this->originUrl
;