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"})}
27 * @ORM\HasLifecycleCallbacks()
28 * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())")
32 /** @Serializer\XmlAttribute */
36 * @ORM\Column(name="id", type="integer")
38 * @ORM\GeneratedValue(strategy="AUTO")
40 * @Groups({"entries_for_user", "export_all"})
47 * @ORM\Column(name="uuid", type="text", nullable=true)
49 * @Groups({"entries_for_user", "export_all"})
56 * @ORM\Column(name="title", type="text", nullable=true)
58 * @Groups({"entries_for_user", "export_all"})
66 * @ORM\Column(name="url", type="text", nullable=true)
68 * @Groups({"entries_for_user", "export_all"})
77 * @ORM\Column(name="is_archived", type="boolean")
79 * @Groups({"entries_for_user", "export_all"})
81 private $isArchived = false;
88 * @ORM\Column(name="is_starred", type="boolean")
90 * @Groups({"entries_for_user", "export_all"})
92 private $isStarred = false;
97 * @ORM\Column(name="content", type="text", nullable=true)
99 * @Groups({"entries_for_user", "export_all"})
106 * @ORM\Column(name="created_at", type="datetime")
108 * @Groups({"entries_for_user", "export_all"})
115 * @ORM\Column(name="updated_at", type="datetime")
117 * @Groups({"entries_for_user", "export_all"})
122 * @ORM\OneToMany(targetEntity="Wallabag\AnnotationBundle\Entity\Annotation", mappedBy="entry", cascade={"persist", "remove"})
125 * @Groups({"entries_for_user", "export_all"})
127 private $annotations;
132 * @ORM\Column(name="mimetype", type="text", nullable=true)
134 * @Groups({"entries_for_user", "export_all"})
141 * @ORM\Column(name="language", type="text", nullable=true)
143 * @Groups({"entries_for_user", "export_all"})
150 * @ORM\Column(name="reading_time", type="integer", nullable=true)
152 * @Groups({"entries_for_user", "export_all"})
154 private $readingTime;
159 * @ORM\Column(name="domain_name", type="text", nullable=true)
161 * @Groups({"entries_for_user", "export_all"})
168 * @ORM\Column(name="preview_picture", type="text", nullable=true)
170 * @Groups({"entries_for_user", "export_all"})
172 private $previewPicture;
177 * @ORM\Column(name="is_public", type="boolean", nullable=true, options={"default" = false})
179 * @Groups({"export_all"})
186 * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="entries")
188 * @Groups({"export_all"})
193 * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"})
197 * @ORM\JoinColumn(name="entry_id", referencedColumnName="id", onDelete="cascade")
199 * inverseJoinColumns={
200 * @ORM\JoinColumn(name="tag_id", referencedColumnName="id", onDelete="cascade")
209 public function __construct(User
$user)
212 $this->tags
= new ArrayCollection();
220 public function getId()
228 * @param string $title
232 public function setTitle($title)
234 $this->title
= $title;
244 public function getTitle()
256 public function setUrl($url)
268 public function getUrl()
276 * @param bool $isArchived
280 public function setArchived($isArchived)
282 $this->isArchived
= $isArchived;
292 public function isArchived()
294 return $this->isArchived
;
299 * @SerializedName("is_archived")
300 * @Groups({"entries_for_user", "export_all"})
302 public function is_Archived()
304 return (int) $this->isArchived();
307 public function toggleArchive()
309 $this->isArchived
= $this->isArchived() ^
1;
317 * @param bool $isStarred
321 public function setStarred($isStarred)
323 $this->isStarred
= $isStarred;
333 public function isStarred()
335 return $this->isStarred
;
340 * @SerializedName("is_starred")
341 * @Groups({"entries_for_user", "export_all"})
343 public function is_Starred()
345 return (int) $this->isStarred();
348 public function toggleStar()
350 $this->isStarred
= $this->isStarred() ^
1;
358 * @param string $content
362 public function setContent($content)
364 $this->content
= $content;
374 public function getContent()
376 return $this->content
;
382 public function getUser()
389 * @SerializedName("user_name")
391 public function getUserName()
393 return $this->user
->getUserName();
398 * @SerializedName("user_email")
400 public function getUserEmail()
402 return $this->user
->getEmail();
407 * @SerializedName("user_id")
409 public function getUserId()
411 return $this->user
->getId();
416 * Only used when importing data from an other service.
418 * @param \DateTime $createdAt
422 public function setCreatedAt(\DateTime
$createdAt)
424 $this->createdAt
= $createdAt;
432 public function getCreatedAt()
434 return $this->createdAt
;
440 public function getUpdatedAt()
442 return $this->updatedAt
;
449 public function timestamps()
451 if (is_null($this->createdAt
)) {
452 $this->createdAt
= new \
DateTime();
455 $this->updatedAt
= new \
DateTime();
459 * @return ArrayCollection<Annotation>
461 public function getAnnotations()
463 return $this->annotations
;
467 * @param Annotation $annotation
469 public function setAnnotation(Annotation
$annotation)
471 $this->annotations
[] = $annotation;
477 public function getMimetype()
479 return $this->mimetype
;
483 * @param string $mimetype
485 public function setMimetype($mimetype)
487 $this->mimetype
= $mimetype;
493 public function getReadingTime()
495 return $this->readingTime
;
499 * @param int $readingTime
501 public function setReadingTime($readingTime)
503 $this->readingTime
= $readingTime;
509 public function getDomainName()
511 return $this->domainName
;
515 * @param string $domainName
517 public function setDomainName($domainName)
519 $this->domainName
= $domainName;
525 public function isPublic()
527 return $this->isPublic
;
531 * @param bool $isPublic
533 public function setIsPublic($isPublic)
535 $this->isPublic
= $isPublic;
539 * @return ArrayCollection<Tag>
541 public function getTags()
548 * @SerializedName("tags")
549 * @Groups({"entries_for_user", "export_all"})
551 public function getSerializedTags()
554 foreach ($this->tags
as $tag) {
555 $data[] = $tag->getLabel();
564 public function addTag(Tag
$tag)
566 if ($this->tags
->contains($tag)) {
570 // check if tag already exist but has not yet be persisted
571 // it seems that the previous condition with `contains()` doesn't check that case
572 foreach ($this->tags
as $existingTag) {
573 if ($existingTag->getLabel() === $tag->getLabel()) {
578 $this->tags
->add($tag);
579 $tag->addEntry($this);
582 public function removeTag(Tag
$tag)
584 if (!$this->tags
->contains($tag)) {
588 $this->tags
->removeElement($tag);
589 $tag->removeEntry($this);
593 * Set previewPicture.
595 * @param string $previewPicture
599 public function setPreviewPicture($previewPicture)
601 $this->previewPicture
= $previewPicture;
607 * Get previewPicture.
611 public function getPreviewPicture()
613 return $this->previewPicture
;
619 * @param string $language
623 public function setLanguage($language)
625 $this->language
= $language;
635 public function getLanguage()
637 return $this->language
;
643 public function getUuid()
649 * @param string $uuid
653 public function setUuid($uuid)
660 public function generateUuid()
662 if (null === $this->uuid
) {
663 // @see http://blog.kevingomez.fr/til/2015/07/26/why-is-uniqid-slow/ for true parameter
664 $this->uuid
= uniqid('', true);
668 public function cleanUuid()