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\Groups
;
9 use JMS\Serializer\Annotation\XmlRoot
;
10 use JMS\Serializer\Annotation\Exclude
;
11 use JMS\Serializer\Annotation\VirtualProperty
;
12 use JMS\Serializer\Annotation\SerializedName
;
13 use Symfony\Component\Validator\Constraints
as Assert
;
14 use Wallabag\UserBundle\Entity\User
;
15 use Wallabag\AnnotationBundle\Entity\Annotation
;
21 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\EntryRepository")
24 * options={"collate"="utf8mb4_unicode_ci", "charset"="utf8mb4"},
26 * @ORM\Index(name="created_at", columns={"created_at"}),
27 * @ORM\Index(name="uid", columns={"uid"})
30 * @ORM\HasLifecycleCallbacks()
31 * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())")
35 /** @Serializer\XmlAttribute */
39 * @ORM\Column(name="id", type="integer")
41 * @ORM\GeneratedValue(strategy="AUTO")
43 * @Groups({"entries_for_user", "export_all"})
50 * @ORM\Column(name="uid", type="string", length=23, nullable=true)
52 * @Groups({"entries_for_user", "export_all"})
59 * @ORM\Column(name="title", type="text", nullable=true)
61 * @Groups({"entries_for_user", "export_all"})
69 * @ORM\Column(name="url", type="text", nullable=true)
71 * @Groups({"entries_for_user", "export_all"})
80 * @ORM\Column(name="is_archived", type="boolean")
82 * @Groups({"entries_for_user", "export_all"})
84 private $isArchived = false;
91 * @ORM\Column(name="is_starred", type="boolean")
93 * @Groups({"entries_for_user", "export_all"})
95 private $isStarred = false;
100 * @ORM\Column(name="content", type="text", nullable=true)
102 * @Groups({"entries_for_user", "export_all"})
109 * @ORM\Column(name="created_at", type="datetime")
111 * @Groups({"entries_for_user", "export_all"})
118 * @ORM\Column(name="updated_at", type="datetime")
120 * @Groups({"entries_for_user", "export_all"})
127 * @ORM\Column(name="published_at", type="datetime", nullable=true)
129 * @Groups({"entries_for_user", "export_all"})
131 private $publishedAt;
136 * @ORM\Column(name="published_by", type="array", nullable=true)
138 * @Groups({"entries_for_user", "export_all"})
140 private $publishedBy;
143 * @ORM\OneToMany(targetEntity="Wallabag\AnnotationBundle\Entity\Annotation", mappedBy="entry", cascade={"persist", "remove"})
146 * @Groups({"entries_for_user", "export_all"})
148 private $annotations;
153 * @ORM\Column(name="mimetype", type="text", nullable=true)
155 * @Groups({"entries_for_user", "export_all"})
162 * @ORM\Column(name="language", type="text", nullable=true)
164 * @Groups({"entries_for_user", "export_all"})
171 * @ORM\Column(name="reading_time", type="integer", nullable=true)
173 * @Groups({"entries_for_user", "export_all"})
175 private $readingTime;
180 * @ORM\Column(name="domain_name", type="text", nullable=true)
182 * @Groups({"entries_for_user", "export_all"})
189 * @ORM\Column(name="preview_picture", type="text", nullable=true)
191 * @Groups({"entries_for_user", "export_all"})
193 private $previewPicture;
198 * @ORM\Column(name="http_status", type="string", length=3, nullable=true)
200 * @Groups({"entries_for_user", "export_all"})
207 * @ORM\Column(name="headers", type="array", nullable=true)
209 * @Groups({"entries_for_user", "export_all"})
216 * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="entries")
218 * @Groups({"export_all"})
223 * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"})
227 * @ORM\JoinColumn(name="entry_id", referencedColumnName="id", onDelete="cascade")
229 * inverseJoinColumns={
230 * @ORM\JoinColumn(name="tag_id", referencedColumnName="id", onDelete="cascade")
239 public function __construct(User
$user)
242 $this->tags
= new ArrayCollection();
250 public function getId()
258 * @param string $title
262 public function setTitle($title)
264 $this->title
= $title;
274 public function getTitle()
286 public function setUrl($url)
298 public function getUrl()
306 * @param bool $isArchived
310 public function setArchived($isArchived)
312 $this->isArchived
= $isArchived;
322 public function isArchived()
324 return $this->isArchived
;
329 * @SerializedName("is_archived")
330 * @Groups({"entries_for_user", "export_all"})
332 public function is_Archived()
334 return (int) $this->isArchived();
337 public function toggleArchive()
339 $this->isArchived
= $this->isArchived() ^
1;
347 * @param bool $isStarred
351 public function setStarred($isStarred)
353 $this->isStarred
= $isStarred;
363 public function isStarred()
365 return $this->isStarred
;
370 * @SerializedName("is_starred")
371 * @Groups({"entries_for_user", "export_all"})
373 public function is_Starred()
375 return (int) $this->isStarred();
378 public function toggleStar()
380 $this->isStarred
= $this->isStarred() ^
1;
388 * @param string $content
392 public function setContent($content)
394 $this->content
= $content;
404 public function getContent()
406 return $this->content
;
412 public function getUser()
419 * @SerializedName("user_name")
421 public function getUserName()
423 return $this->user
->getUserName();
428 * @SerializedName("user_email")
430 public function getUserEmail()
432 return $this->user
->getEmail();
437 * @SerializedName("user_id")
439 public function getUserId()
441 return $this->user
->getId();
446 * Only used when importing data from an other service.
448 * @param \DateTime $createdAt
452 public function setCreatedAt(\DateTime
$createdAt)
454 $this->createdAt
= $createdAt;
462 public function getCreatedAt()
464 return $this->createdAt
;
470 public function getUpdatedAt()
472 return $this->updatedAt
;
479 public function timestamps()
481 if (is_null($this->createdAt
)) {
482 $this->createdAt
= new \
DateTime();
485 $this->updatedAt
= new \
DateTime();
489 * @return ArrayCollection<Annotation>
491 public function getAnnotations()
493 return $this->annotations
;
497 * @param Annotation $annotation
499 public function setAnnotation(Annotation
$annotation)
501 $this->annotations
[] = $annotation;
507 public function getMimetype()
509 return $this->mimetype
;
513 * @param string $mimetype
515 public function setMimetype($mimetype)
517 $this->mimetype
= $mimetype;
523 public function getReadingTime()
525 return $this->readingTime
;
529 * @param int $readingTime
531 public function setReadingTime($readingTime)
533 $this->readingTime
= $readingTime;
539 public function getDomainName()
541 return $this->domainName
;
545 * @param string $domainName
547 public function setDomainName($domainName)
549 $this->domainName
= $domainName;
553 * @return ArrayCollection
555 public function getTags()
562 * @SerializedName("tags")
563 * @Groups({"entries_for_user", "export_all"})
565 public function getSerializedTags()
568 foreach ($this->tags
as $tag) {
569 $data[] = $tag->getLabel();
578 public function addTag(Tag
$tag)
580 if ($this->tags
->contains($tag)) {
584 // check if tag already exist but has not yet be persisted
585 // it seems that the previous condition with `contains()` doesn't check that case
586 foreach ($this->tags
as $existingTag) {
587 if ($existingTag->getLabel() === $tag->getLabel()) {
592 $this->tags
->add($tag);
593 $tag->addEntry($this);
596 public function removeTag(Tag
$tag)
598 if (!$this->tags
->contains($tag)) {
602 $this->tags
->removeElement($tag);
603 $tag->removeEntry($this);
607 * Set previewPicture.
609 * @param string $previewPicture
613 public function setPreviewPicture($previewPicture)
615 $this->previewPicture
= $previewPicture;
621 * Get previewPicture.
625 public function getPreviewPicture()
627 return $this->previewPicture
;
633 * @param string $language
637 public function setLanguage($language)
639 $this->language
= $language;
649 public function getLanguage()
651 return $this->language
;
657 public function getUid()
667 public function setUid($uid)
674 public function generateUid()
676 if (null === $this->uid
) {
677 // @see http://blog.kevingomez.fr/til/2015/07/26/why-is-uniqid-slow/ for true parameter
678 $this->uid
= uniqid('', true);
682 public function cleanUid()
688 * Used in the entries filter so it's more explicit for the end user than the uid.
692 public function isPublic()
694 return null !== $this->uid
;
700 public function getHttpStatus()
702 return $this->httpStatus
;
706 * @param string $httpStatus
710 public function setHttpStatus($httpStatus)
712 $this->httpStatus
= $httpStatus;
720 public function getPublishedAt()
722 return $this->publishedAt
;
726 * @param \Datetime $publishedAt
730 public function setPublishedAt(\Datetime
$publishedAt)
732 $this->publishedAt
= $publishedAt;
740 public function getPublishedBy()
742 return $this->publishedBy
;
746 * @param array $publishedBy
750 public function setPublishedBy($publishedBy)
752 $this->publishedBy
= $publishedBy;
760 public function getHeaders()
762 return $this->headers
;
766 * @param array $headers
770 public function setHeaders($headers)
772 $this->headers
= $headers;