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="json_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="is_public", type="boolean", nullable=true, options={"default" = false})
200 * @Groups({"export_all"})
207 * @ORM\Column(name="http_status", type="string", length=3, 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;
555 public function isPublic()
557 return $this->isPublic
;
561 * @param bool $isPublic
563 public function setIsPublic($isPublic)
565 $this->isPublic
= $isPublic;
569 * @return ArrayCollection<Tag>
571 public function getTags()
578 * @SerializedName("tags")
579 * @Groups({"entries_for_user", "export_all"})
581 public function getSerializedTags()
584 foreach ($this->tags
as $tag) {
585 $data[] = $tag->getLabel();
594 public function addTag(Tag
$tag)
596 if ($this->tags
->contains($tag)) {
600 // check if tag already exist but has not yet be persisted
601 // it seems that the previous condition with `contains()` doesn't check that case
602 foreach ($this->tags
as $existingTag) {
603 if ($existingTag->getLabel() === $tag->getLabel()) {
608 $this->tags
->add($tag);
609 $tag->addEntry($this);
612 public function removeTag(Tag
$tag)
614 if (!$this->tags
->contains($tag)) {
618 $this->tags
->removeElement($tag);
619 $tag->removeEntry($this);
623 * Set previewPicture.
625 * @param string $previewPicture
629 public function setPreviewPicture($previewPicture)
631 $this->previewPicture
= $previewPicture;
637 * Get previewPicture.
641 public function getPreviewPicture()
643 return $this->previewPicture
;
649 * @param string $language
653 public function setLanguage($language)
655 $this->language
= $language;
665 public function getLanguage()
667 return $this->language
;
673 public function getUid()
683 public function setUid($uid)
690 public function generateUid()
692 if (null === $this->uid
) {
693 // @see http://blog.kevingomez.fr/til/2015/07/26/why-is-uniqid-slow/ for true parameter
694 $this->uid
= uniqid('', true);
698 public function cleanUid()
706 public function getHttpStatus()
708 return $this->httpStatus
;
712 * @param int $httpStatus
716 public function setHttpStatus($httpStatus)
718 $this->httpStatus
= $httpStatus;
726 public function getPublishedAt()
728 return $this->publishedAt
;
732 * @param \Datetime $publishedAt
736 public function setPublishedAt(\Datetime
$publishedAt)
738 $this->publishedAt
= $publishedAt;
746 public function getPublishedBy()
748 return $this->publishedBy
;
752 * @param string $publishedBy
756 public function setPublishedBy($publishedBy)
758 $this->publishedBy
= $publishedBy;