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;
146 * @ORM\OneToMany(targetEntity="Wallabag\AnnotationBundle\Entity\Annotation", mappedBy="entry", cascade={"persist", "remove"})
149 * @Groups({"entries_for_user", "export_all"})
151 private $annotations;
156 * @ORM\Column(name="mimetype", type="text", nullable=true)
158 * @Groups({"entries_for_user", "export_all"})
165 * @ORM\Column(name="language", type="text", nullable=true)
167 * @Groups({"entries_for_user", "export_all"})
174 * @ORM\Column(name="reading_time", type="integer", nullable=true)
176 * @Groups({"entries_for_user", "export_all"})
178 private $readingTime;
183 * @ORM\Column(name="domain_name", type="text", nullable=true)
185 * @Groups({"entries_for_user", "export_all"})
192 * @ORM\Column(name="preview_picture", type="text", nullable=true)
194 * @Groups({"entries_for_user", "export_all"})
196 private $previewPicture;
201 * @ORM\Column(name="http_status", type="string", length=3, nullable=true)
203 * @Groups({"entries_for_user", "export_all"})
210 * @ORM\Column(name="headers", type="array", nullable=true)
212 * @Groups({"entries_for_user", "export_all"})
219 * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="entries")
221 * @Groups({"export_all"})
226 * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"})
230 * @ORM\JoinColumn(name="entry_id", referencedColumnName="id", onDelete="cascade")
232 * inverseJoinColumns={
233 * @ORM\JoinColumn(name="tag_id", referencedColumnName="id", onDelete="cascade")
242 public function __construct(User
$user)
245 $this->tags
= new ArrayCollection();
253 public function getId()
261 * @param string $title
265 public function setTitle($title)
267 $this->title
= $title;
277 public function getTitle()
289 public function setUrl($url)
301 public function getUrl()
309 * @param bool $isArchived
313 public function setArchived($isArchived)
315 $this->isArchived
= $isArchived;
325 public function isArchived()
327 return $this->isArchived
;
332 * @SerializedName("is_archived")
333 * @Groups({"entries_for_user", "export_all"})
335 public function is_Archived()
337 return (int) $this->isArchived();
340 public function toggleArchive()
342 $this->isArchived
= $this->isArchived() ^
1;
350 * @param bool $isStarred
354 public function setStarred($isStarred)
356 $this->isStarred
= $isStarred;
366 public function isStarred()
368 return $this->isStarred
;
373 * @SerializedName("is_starred")
374 * @Groups({"entries_for_user", "export_all"})
376 public function is_Starred()
378 return (int) $this->isStarred();
381 public function toggleStar()
383 $this->isStarred
= $this->isStarred() ^
1;
391 * @param string $content
395 public function setContent($content)
397 $this->content
= $content;
407 public function getContent()
409 return $this->content
;
415 public function getUser()
422 * @SerializedName("user_name")
424 public function getUserName()
426 return $this->user
->getUserName();
431 * @SerializedName("user_email")
433 public function getUserEmail()
435 return $this->user
->getEmail();
440 * @SerializedName("user_id")
442 public function getUserId()
444 return $this->user
->getId();
449 * Only used when importing data from an other service.
451 * @param \DateTime $createdAt
455 public function setCreatedAt(\DateTime
$createdAt)
457 $this->createdAt
= $createdAt;
465 public function getCreatedAt()
467 return $this->createdAt
;
473 public function getUpdatedAt()
475 return $this->updatedAt
;
479 * @return ArrayCollection<Annotation>
481 public function getAnnotations()
483 return $this->annotations
;
487 * @param Annotation $annotation
489 public function setAnnotation(Annotation
$annotation)
491 $this->annotations
[] = $annotation;
497 public function getMimetype()
499 return $this->mimetype
;
503 * @param string $mimetype
505 public function setMimetype($mimetype)
507 $this->mimetype
= $mimetype;
513 public function getReadingTime()
515 return $this->readingTime
;
519 * @param int $readingTime
521 public function setReadingTime($readingTime)
523 $this->readingTime
= $readingTime;
529 public function getDomainName()
531 return $this->domainName
;
535 * @param string $domainName
537 public function setDomainName($domainName)
539 $this->domainName
= $domainName;
543 * @return ArrayCollection
545 public function getTags()
552 * @SerializedName("tags")
553 * @Groups({"entries_for_user", "export_all"})
555 public function getSerializedTags()
558 foreach ($this->tags
as $tag) {
559 $data[] = $tag->getLabel();
568 public function addTag(Tag
$tag)
570 if ($this->tags
->contains($tag)) {
574 // check if tag already exist but has not yet be persisted
575 // it seems that the previous condition with `contains()` doesn't check that case
576 foreach ($this->tags
as $existingTag) {
577 if ($existingTag->getLabel() === $tag->getLabel()) {
582 $this->tags
->add($tag);
583 $tag->addEntry($this);
587 * Remove the given tag from the entry (if the tag is associated).
591 public function removeTag(Tag
$tag)
593 if (!$this->tags
->contains($tag)) {
597 $this->tags
->removeElement($tag);
598 $tag->removeEntry($this);
602 * Remove all assigned tags from the entry.
604 public function removeAllTags()
606 foreach ($this->tags
as $tag) {
607 $this->tags
->removeElement($tag);
608 $tag->removeEntry($this);
613 * Set previewPicture.
615 * @param string $previewPicture
619 public function setPreviewPicture($previewPicture)
621 $this->previewPicture
= $previewPicture;
627 * Get previewPicture.
631 public function getPreviewPicture()
633 return $this->previewPicture
;
639 * @param string $language
643 public function setLanguage($language)
645 $this->language
= $language;
655 public function getLanguage()
657 return $this->language
;
663 public function getUid()
673 public function setUid($uid)
680 public function generateUid()
682 if (null === $this->uid
) {
683 // @see http://blog.kevingomez.fr/til/2015/07/26/why-is-uniqid-slow/ for true parameter
684 $this->uid
= uniqid('', true);
688 public function cleanUid()
694 * Used in the entries filter so it's more explicit for the end user than the uid.
695 * Also used in the API.
698 * @SerializedName("is_public")
699 * @Groups({"entries_for_user"})
703 public function isPublic()
705 return null !== $this->uid
;
711 public function getHttpStatus()
713 return $this->httpStatus
;
717 * @param string $httpStatus
721 public function setHttpStatus($httpStatus)
723 $this->httpStatus
= $httpStatus;
731 public function getPublishedAt()
733 return $this->publishedAt
;
737 * @param \Datetime $publishedAt
741 public function setPublishedAt(\Datetime
$publishedAt)
743 $this->publishedAt
= $publishedAt;
751 public function getPublishedBy()
753 return $this->publishedBy
;
757 * @param array $publishedBy
761 public function setPublishedBy($publishedBy)
763 $this->publishedBy
= $publishedBy;
771 public function getHeaders()
773 return $this->headers
;
777 * @param array $headers
781 public function setHeaders($headers)
783 $this->headers
= $headers;