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;
92 * @ORM\Column(name="archived_at", type="datetime", nullable=true)
94 * @Groups({"entries_for_user", "export_all"})
96 private $archivedAt = null;
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()
316 public function setUrl($url)
328 public function getUrl()
336 * @param bool $isArchived
340 public function setArchived($isArchived)
342 $this->isArchived
= $isArchived;
348 * update isArchived and archive_at fields.
350 * @param bool $isArchived
354 public function updateArchived($isArchived = false)
356 $this->setArchived($isArchived);
357 $this->setArchivedAt(null);
358 if ($this->isArchived()) {
359 $this->setArchivedAt(new \
DateTime());
366 * @return \DateTime|null
368 public function getArchivedAt()
370 return $this->archivedAt
;
374 * @param \DateTime|null $archivedAt
378 public function setArchivedAt($archivedAt = null)
380 $this->archivedAt
= $archivedAt;
390 public function isArchived()
392 return $this->isArchived
;
397 * @SerializedName("is_archived")
398 * @Groups({"entries_for_user", "export_all"})
400 public function is_Archived()
402 return (int) $this->isArchived();
405 public function toggleArchive()
407 $this->updateArchived($this->isArchived() ^
1);
415 * @param bool $isStarred
419 public function setStarred($isStarred)
421 $this->isStarred
= $isStarred;
431 public function isStarred()
433 return $this->isStarred
;
438 * @SerializedName("is_starred")
439 * @Groups({"entries_for_user", "export_all"})
441 public function is_Starred()
443 return (int) $this->isStarred();
446 public function toggleStar()
448 $this->isStarred
= $this->isStarred() ^
1;
456 * @param string $content
460 public function setContent($content)
462 $this->content
= $content;
472 public function getContent()
474 return $this->content
;
480 public function getUser()
487 * @SerializedName("user_name")
489 public function getUserName()
491 return $this->user
->getUserName();
496 * @SerializedName("user_email")
498 public function getUserEmail()
500 return $this->user
->getEmail();
505 * @SerializedName("user_id")
507 public function getUserId()
509 return $this->user
->getId();
514 * Only used when importing data from an other service.
516 * @param \DateTime $createdAt
520 public function setCreatedAt(\DateTime
$createdAt)
522 $this->createdAt
= $createdAt;
530 public function getCreatedAt()
532 return $this->createdAt
;
538 public function getUpdatedAt()
540 return $this->updatedAt
;
544 * @return \DateTime|null
546 public function getStarredAt()
548 return $this->starredAt
;
552 * @param \DateTime|null $starredAt
556 public function setStarredAt($starredAt = null)
558 $this->starredAt
= $starredAt;
564 * update isStarred and starred_at fields.
566 * @param bool $isStarred
570 public function updateStar($isStarred = false)
572 $this->setStarred($isStarred);
573 $this->setStarredAt(null);
574 if ($this->isStarred()) {
575 $this->setStarredAt(new \
DateTime());
582 * @return ArrayCollection<Annotation>
584 public function getAnnotations()
586 return $this->annotations
;
590 * @param Annotation $annotation
592 public function setAnnotation(Annotation
$annotation)
594 $this->annotations
[] = $annotation;
600 public function getMimetype()
602 return $this->mimetype
;
606 * @param string $mimetype
608 public function setMimetype($mimetype)
610 $this->mimetype
= $mimetype;
616 public function getReadingTime()
618 return $this->readingTime
;
622 * @param int $readingTime
624 public function setReadingTime($readingTime)
626 $this->readingTime
= $readingTime;
632 public function getDomainName()
634 return $this->domainName
;
638 * @param string $domainName
640 public function setDomainName($domainName)
642 $this->domainName
= $domainName;
646 * @return ArrayCollection
648 public function getTags()
655 * @SerializedName("tags")
656 * @Groups({"entries_for_user", "export_all"})
658 public function getSerializedTags()
661 foreach ($this->tags
as $tag) {
662 $data[] = $tag->getLabel();
671 public function addTag(Tag
$tag)
673 if ($this->tags
->contains($tag)) {
677 // check if tag already exist but has not yet be persisted
678 // it seems that the previous condition with `contains()` doesn't check that case
679 foreach ($this->tags
as $existingTag) {
680 if ($existingTag->getLabel() === $tag->getLabel()) {
685 $this->tags
->add($tag);
686 $tag->addEntry($this);
690 * Remove the given tag from the entry (if the tag is associated).
694 public function removeTag(Tag
$tag)
696 if (!$this->tags
->contains($tag)) {
700 $this->tags
->removeElement($tag);
701 $tag->removeEntry($this);
705 * Remove all assigned tags from the entry.
707 public function removeAllTags()
709 foreach ($this->tags
as $tag) {
710 $this->tags
->removeElement($tag);
711 $tag->removeEntry($this);
716 * Set previewPicture.
718 * @param string $previewPicture
722 public function setPreviewPicture($previewPicture)
724 $this->previewPicture
= $previewPicture;
730 * Get previewPicture.
734 public function getPreviewPicture()
736 return $this->previewPicture
;
742 * @param string $language
746 public function setLanguage($language)
748 $this->language
= $language;
758 public function getLanguage()
760 return $this->language
;
766 public function getUid()
776 public function setUid($uid)
783 public function generateUid()
785 if (null === $this->uid
) {
786 // @see http://blog.kevingomez.fr/til/2015/07/26/why-is-uniqid-slow/ for true parameter
787 $this->uid
= uniqid('', true);
791 public function cleanUid()
797 * Used in the entries filter so it's more explicit for the end user than the uid.
798 * Also used in the API.
801 * @SerializedName("is_public")
802 * @Groups({"entries_for_user"})
806 public function isPublic()
808 return null !== $this->uid
;
814 public function getHttpStatus()
816 return $this->httpStatus
;
820 * @param string $httpStatus
824 public function setHttpStatus($httpStatus)
826 $this->httpStatus
= $httpStatus;
834 public function getPublishedAt()
836 return $this->publishedAt
;
840 * @param \Datetime $publishedAt
844 public function setPublishedAt(\Datetime
$publishedAt)
846 $this->publishedAt
= $publishedAt;
854 public function getPublishedBy()
856 return $this->publishedBy
;
860 * @param array $publishedBy
864 public function setPublishedBy($publishedBy)
866 $this->publishedBy
= $publishedBy;
874 public function getHeaders()
876 return $this->headers
;
880 * @param array $headers
884 public function setHeaders($headers)
886 $this->headers
= $headers;
894 * @param string $originUrl
898 public function setOriginUrl($originUrl)
900 $this->originUrl
= $originUrl;
910 public function getOriginUrl()
912 return $this->originUrl
;