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"},
25 * indexes={@ORM\Index(name="created_at", columns={"created_at"})},
26 * indexes={@ORM\Index(name="uuid", columns={"uuid"})}
28 * @ORM\HasLifecycleCallbacks()
29 * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())")
33 /** @Serializer\XmlAttribute */
37 * @ORM\Column(name="id", type="integer")
39 * @ORM\GeneratedValue(strategy="AUTO")
41 * @Groups({"entries_for_user", "export_all"})
48 * @ORM\Column(name="uuid", type="text", nullable=true)
50 * @Groups({"entries_for_user", "export_all"})
57 * @ORM\Column(name="title", type="text", nullable=true)
59 * @Groups({"entries_for_user", "export_all"})
67 * @ORM\Column(name="url", type="text", nullable=true)
69 * @Groups({"entries_for_user", "export_all"})
78 * @ORM\Column(name="is_archived", type="boolean")
80 * @Groups({"entries_for_user", "export_all"})
82 private $isArchived = false;
89 * @ORM\Column(name="is_starred", type="boolean")
91 * @Groups({"entries_for_user", "export_all"})
93 private $isStarred = false;
98 * @ORM\Column(name="content", type="text", nullable=true)
100 * @Groups({"entries_for_user", "export_all"})
107 * @ORM\Column(name="created_at", type="datetime")
109 * @Groups({"entries_for_user", "export_all"})
116 * @ORM\Column(name="updated_at", type="datetime")
118 * @Groups({"entries_for_user", "export_all"})
123 * @ORM\OneToMany(targetEntity="Wallabag\AnnotationBundle\Entity\Annotation", mappedBy="entry", cascade={"persist", "remove"})
126 * @Groups({"entries_for_user", "export_all"})
128 private $annotations;
133 * @ORM\Column(name="mimetype", type="text", nullable=true)
135 * @Groups({"entries_for_user", "export_all"})
142 * @ORM\Column(name="language", type="text", nullable=true)
144 * @Groups({"entries_for_user", "export_all"})
151 * @ORM\Column(name="reading_time", type="integer", nullable=true)
153 * @Groups({"entries_for_user", "export_all"})
155 private $readingTime;
160 * @ORM\Column(name="domain_name", type="text", nullable=true)
162 * @Groups({"entries_for_user", "export_all"})
169 * @ORM\Column(name="preview_picture", type="text", nullable=true)
171 * @Groups({"entries_for_user", "export_all"})
173 private $previewPicture;
178 * @ORM\Column(name="is_public", type="boolean", nullable=true, options={"default" = false})
180 * @Groups({"export_all"})
187 * @ORM\Column(name="http_status", type="string", length=3, nullable=true)
189 * @Groups({"entries_for_user", "export_all"})
196 * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="entries")
198 * @Groups({"export_all"})
203 * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"})
207 * @ORM\JoinColumn(name="entry_id", referencedColumnName="id", onDelete="cascade")
209 * inverseJoinColumns={
210 * @ORM\JoinColumn(name="tag_id", referencedColumnName="id", onDelete="cascade")
219 public function __construct(User
$user)
222 $this->tags
= new ArrayCollection();
230 public function getId()
238 * @param string $title
242 public function setTitle($title)
244 $this->title
= $title;
254 public function getTitle()
266 public function setUrl($url)
278 public function getUrl()
286 * @param bool $isArchived
290 public function setArchived($isArchived)
292 $this->isArchived
= $isArchived;
302 public function isArchived()
304 return $this->isArchived
;
309 * @SerializedName("is_archived")
310 * @Groups({"entries_for_user", "export_all"})
312 public function is_Archived()
314 return (int) $this->isArchived();
317 public function toggleArchive()
319 $this->isArchived
= $this->isArchived() ^
1;
327 * @param bool $isStarred
331 public function setStarred($isStarred)
333 $this->isStarred
= $isStarred;
343 public function isStarred()
345 return $this->isStarred
;
350 * @SerializedName("is_starred")
351 * @Groups({"entries_for_user", "export_all"})
353 public function is_Starred()
355 return (int) $this->isStarred();
358 public function toggleStar()
360 $this->isStarred
= $this->isStarred() ^
1;
368 * @param string $content
372 public function setContent($content)
374 $this->content
= $content;
384 public function getContent()
386 return $this->content
;
392 public function getUser()
399 * @SerializedName("user_name")
401 public function getUserName()
403 return $this->user
->getUserName();
408 * @SerializedName("user_email")
410 public function getUserEmail()
412 return $this->user
->getEmail();
417 * @SerializedName("user_id")
419 public function getUserId()
421 return $this->user
->getId();
426 * Only used when importing data from an other service.
428 * @param \DateTime $createdAt
432 public function setCreatedAt(\DateTime
$createdAt)
434 $this->createdAt
= $createdAt;
442 public function getCreatedAt()
444 return $this->createdAt
;
450 public function getUpdatedAt()
452 return $this->updatedAt
;
459 public function timestamps()
461 if (is_null($this->createdAt
)) {
462 $this->createdAt
= new \
DateTime();
465 $this->updatedAt
= new \
DateTime();
469 * @return ArrayCollection<Annotation>
471 public function getAnnotations()
473 return $this->annotations
;
477 * @param Annotation $annotation
479 public function setAnnotation(Annotation
$annotation)
481 $this->annotations
[] = $annotation;
487 public function getMimetype()
489 return $this->mimetype
;
493 * @param string $mimetype
495 public function setMimetype($mimetype)
497 $this->mimetype
= $mimetype;
503 public function getReadingTime()
505 return $this->readingTime
;
509 * @param int $readingTime
511 public function setReadingTime($readingTime)
513 $this->readingTime
= $readingTime;
519 public function getDomainName()
521 return $this->domainName
;
525 * @param string $domainName
527 public function setDomainName($domainName)
529 $this->domainName
= $domainName;
535 public function isPublic()
537 return $this->isPublic
;
541 * @param bool $isPublic
543 public function setIsPublic($isPublic)
545 $this->isPublic
= $isPublic;
549 * @return ArrayCollection<Tag>
551 public function getTags()
558 * @SerializedName("tags")
559 * @Groups({"entries_for_user", "export_all"})
561 public function getSerializedTags()
564 foreach ($this->tags
as $tag) {
565 $data[] = $tag->getLabel();
574 public function addTag(Tag
$tag)
576 if ($this->tags
->contains($tag)) {
580 // check if tag already exist but has not yet be persisted
581 // it seems that the previous condition with `contains()` doesn't check that case
582 foreach ($this->tags
as $existingTag) {
583 if ($existingTag->getLabel() === $tag->getLabel()) {
588 $this->tags
->add($tag);
589 $tag->addEntry($this);
592 public function removeTag(Tag
$tag)
594 if (!$this->tags
->contains($tag)) {
598 $this->tags
->removeElement($tag);
599 $tag->removeEntry($this);
603 * Set previewPicture.
605 * @param string $previewPicture
609 public function setPreviewPicture($previewPicture)
611 $this->previewPicture
= $previewPicture;
617 * Get previewPicture.
621 public function getPreviewPicture()
623 return $this->previewPicture
;
629 * @param string $language
633 public function setLanguage($language)
635 $this->language
= $language;
645 public function getLanguage()
647 return $this->language
;
653 public function getUuid()
659 * @param string $uuid
663 public function setUuid($uuid)
670 public function generateUuid()
672 if (null === $this->uuid
) {
673 // @see http://blog.kevingomez.fr/til/2015/07/26/why-is-uniqid-slow/ for true parameter
674 $this->uuid
= uniqid('', true);
678 public function cleanUuid()
686 public function getHttpStatus()
688 return $this->httpStatus
;
692 * @param int $httpStatus
696 public function setHttpStatus($httpStatus)
698 $this->httpStatus
= $httpStatus;