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;
134 * @ORM\OneToMany(targetEntity="Wallabag\AnnotationBundle\Entity\Annotation", mappedBy="entry", cascade={"persist", "remove"})
137 * @Groups({"entries_for_user", "export_all"})
139 private $annotations;
144 * @ORM\Column(name="mimetype", type="text", nullable=true)
146 * @Groups({"entries_for_user", "export_all"})
153 * @ORM\Column(name="language", type="text", nullable=true)
155 * @Groups({"entries_for_user", "export_all"})
162 * @ORM\Column(name="reading_time", type="integer", nullable=true)
164 * @Groups({"entries_for_user", "export_all"})
166 private $readingTime;
171 * @ORM\Column(name="domain_name", type="text", nullable=true)
173 * @Groups({"entries_for_user", "export_all"})
180 * @ORM\Column(name="preview_picture", type="text", nullable=true)
182 * @Groups({"entries_for_user", "export_all"})
184 private $previewPicture;
189 * @ORM\Column(name="is_public", type="boolean", nullable=true, options={"default" = false})
191 * @Groups({"export_all"})
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;
546 public function isPublic()
548 return $this->isPublic
;
552 * @param bool $isPublic
554 public function setIsPublic($isPublic)
556 $this->isPublic
= $isPublic;
560 * @return ArrayCollection<Tag>
562 public function getTags()
569 * @SerializedName("tags")
570 * @Groups({"entries_for_user", "export_all"})
572 public function getSerializedTags()
575 foreach ($this->tags
as $tag) {
576 $data[] = $tag->getLabel();
585 public function addTag(Tag
$tag)
587 if ($this->tags
->contains($tag)) {
591 // check if tag already exist but has not yet be persisted
592 // it seems that the previous condition with `contains()` doesn't check that case
593 foreach ($this->tags
as $existingTag) {
594 if ($existingTag->getLabel() === $tag->getLabel()) {
599 $this->tags
->add($tag);
600 $tag->addEntry($this);
603 public function removeTag(Tag
$tag)
605 if (!$this->tags
->contains($tag)) {
609 $this->tags
->removeElement($tag);
610 $tag->removeEntry($this);
614 * Set previewPicture.
616 * @param string $previewPicture
620 public function setPreviewPicture($previewPicture)
622 $this->previewPicture
= $previewPicture;
628 * Get previewPicture.
632 public function getPreviewPicture()
634 return $this->previewPicture
;
640 * @param string $language
644 public function setLanguage($language)
646 $this->language
= $language;
656 public function getLanguage()
658 return $this->language
;
664 public function getUid()
674 public function setUid($uid)
681 public function generateUid()
683 if (null === $this->uid
) {
684 // @see http://blog.kevingomez.fr/til/2015/07/26/why-is-uniqid-slow/ for true parameter
685 $this->uid
= uniqid('', true);
689 public function cleanUid()
697 public function getHttpStatus()
699 return $this->httpStatus
;
703 * @param int $httpStatus
707 public function setHttpStatus($httpStatus)
709 $this->httpStatus
= $httpStatus;
717 public function getPublishedAt()
719 return $this->publishedAt
;
723 * @param \Datetime $publishedAt
727 public function setPublishedAt(\Datetime
$publishedAt)
729 $this->publishedAt
= $publishedAt;