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="http_status", type="string", length=3, nullable=true)
200 * @Groups({"entries_for_user", "export_all"})
207 * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="entries")
209 * @Groups({"export_all"})
214 * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"})
218 * @ORM\JoinColumn(name="entry_id", referencedColumnName="id", onDelete="cascade")
220 * inverseJoinColumns={
221 * @ORM\JoinColumn(name="tag_id", referencedColumnName="id", onDelete="cascade")
230 public function __construct(User
$user)
233 $this->tags
= new ArrayCollection();
241 public function getId()
249 * @param string $title
253 public function setTitle($title)
255 $this->title
= $title;
265 public function getTitle()
277 public function setUrl($url)
289 public function getUrl()
297 * @param bool $isArchived
301 public function setArchived($isArchived)
303 $this->isArchived
= $isArchived;
313 public function isArchived()
315 return $this->isArchived
;
320 * @SerializedName("is_archived")
321 * @Groups({"entries_for_user", "export_all"})
323 public function is_Archived()
325 return (int) $this->isArchived();
328 public function toggleArchive()
330 $this->isArchived
= $this->isArchived() ^
1;
338 * @param bool $isStarred
342 public function setStarred($isStarred)
344 $this->isStarred
= $isStarred;
354 public function isStarred()
356 return $this->isStarred
;
361 * @SerializedName("is_starred")
362 * @Groups({"entries_for_user", "export_all"})
364 public function is_Starred()
366 return (int) $this->isStarred();
369 public function toggleStar()
371 $this->isStarred
= $this->isStarred() ^
1;
379 * @param string $content
383 public function setContent($content)
385 $this->content
= $content;
395 public function getContent()
397 return $this->content
;
403 public function getUser()
410 * @SerializedName("user_name")
412 public function getUserName()
414 return $this->user
->getUserName();
419 * @SerializedName("user_email")
421 public function getUserEmail()
423 return $this->user
->getEmail();
428 * @SerializedName("user_id")
430 public function getUserId()
432 return $this->user
->getId();
437 * Only used when importing data from an other service.
439 * @param \DateTime $createdAt
443 public function setCreatedAt(\DateTime
$createdAt)
445 $this->createdAt
= $createdAt;
453 public function getCreatedAt()
455 return $this->createdAt
;
461 public function getUpdatedAt()
463 return $this->updatedAt
;
470 public function timestamps()
472 if (is_null($this->createdAt
)) {
473 $this->createdAt
= new \
DateTime();
476 $this->updatedAt
= new \
DateTime();
480 * @return ArrayCollection<Annotation>
482 public function getAnnotations()
484 return $this->annotations
;
488 * @param Annotation $annotation
490 public function setAnnotation(Annotation
$annotation)
492 $this->annotations
[] = $annotation;
498 public function getMimetype()
500 return $this->mimetype
;
504 * @param string $mimetype
506 public function setMimetype($mimetype)
508 $this->mimetype
= $mimetype;
514 public function getReadingTime()
516 return $this->readingTime
;
520 * @param int $readingTime
522 public function setReadingTime($readingTime)
524 $this->readingTime
= $readingTime;
530 public function getDomainName()
532 return $this->domainName
;
536 * @param string $domainName
538 public function setDomainName($domainName)
540 $this->domainName
= $domainName;
544 * @return ArrayCollection<Tag>
546 public function getTags()
553 * @SerializedName("tags")
554 * @Groups({"entries_for_user", "export_all"})
556 public function getSerializedTags()
559 foreach ($this->tags
as $tag) {
560 $data[] = $tag->getLabel();
569 public function addTag(Tag
$tag)
571 if ($this->tags
->contains($tag)) {
575 // check if tag already exist but has not yet be persisted
576 // it seems that the previous condition with `contains()` doesn't check that case
577 foreach ($this->tags
as $existingTag) {
578 if ($existingTag->getLabel() === $tag->getLabel()) {
583 $this->tags
->add($tag);
584 $tag->addEntry($this);
587 public function removeTag(Tag
$tag)
589 if (!$this->tags
->contains($tag)) {
593 $this->tags
->removeElement($tag);
594 $tag->removeEntry($this);
598 * Set previewPicture.
600 * @param string $previewPicture
604 public function setPreviewPicture($previewPicture)
606 $this->previewPicture
= $previewPicture;
612 * Get previewPicture.
616 public function getPreviewPicture()
618 return $this->previewPicture
;
624 * @param string $language
628 public function setLanguage($language)
630 $this->language
= $language;
640 public function getLanguage()
642 return $this->language
;
648 public function getUid()
658 public function setUid($uid)
665 public function generateUid()
667 if (null === $this->uid
) {
668 // @see http://blog.kevingomez.fr/til/2015/07/26/why-is-uniqid-slow/ for true parameter
669 $this->uid
= uniqid('', true);
673 public function cleanUid()
681 public function getHttpStatus()
683 return $this->httpStatus
;
687 * @param int $httpStatus
691 public function setHttpStatus($httpStatus)
693 $this->httpStatus
= $httpStatus;
701 public function getPublishedAt()
703 return $this->publishedAt
;
707 * @param \Datetime $publishedAt
711 public function setPublishedAt(\Datetime
$publishedAt)
713 $this->publishedAt
= $publishedAt;
721 public function getPublishedBy()
723 return $this->publishedBy
;
727 * @param string $publishedBy
731 public function setPublishedBy($publishedBy)
733 $this->publishedBy
= $publishedBy;