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\Column(name="http_status", type="text", nullable=true)
188 * @Groups({"entries_for_user", "export_all"})
195 * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="entries")
197 * @Groups({"export_all"})
202 * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"})
206 * @ORM\JoinColumn(name="entry_id", referencedColumnName="id", onDelete="cascade")
208 * inverseJoinColumns={
209 * @ORM\JoinColumn(name="tag_id", referencedColumnName="id", onDelete="cascade")
218 public function __construct(User
$user)
221 $this->tags
= new ArrayCollection();
229 public function getId()
237 * @param string $title
241 public function setTitle($title)
243 $this->title
= $title;
253 public function getTitle()
265 public function setUrl($url)
277 public function getUrl()
285 * @param bool $isArchived
289 public function setArchived($isArchived)
291 $this->isArchived
= $isArchived;
301 public function isArchived()
303 return $this->isArchived
;
308 * @SerializedName("is_archived")
309 * @Groups({"entries_for_user", "export_all"})
311 public function is_Archived()
313 return (int) $this->isArchived();
316 public function toggleArchive()
318 $this->isArchived
= $this->isArchived() ^
1;
326 * @param bool $isStarred
330 public function setStarred($isStarred)
332 $this->isStarred
= $isStarred;
342 public function isStarred()
344 return $this->isStarred
;
349 * @SerializedName("is_starred")
350 * @Groups({"entries_for_user", "export_all"})
352 public function is_Starred()
354 return (int) $this->isStarred();
357 public function toggleStar()
359 $this->isStarred
= $this->isStarred() ^
1;
367 * @param string $content
371 public function setContent($content)
373 $this->content
= $content;
383 public function getContent()
385 return $this->content
;
391 public function getUser()
398 * @SerializedName("user_name")
400 public function getUserName()
402 return $this->user
->getUserName();
407 * @SerializedName("user_email")
409 public function getUserEmail()
411 return $this->user
->getEmail();
416 * @SerializedName("user_id")
418 public function getUserId()
420 return $this->user
->getId();
425 * Only used when importing data from an other service.
427 * @param \DateTime $createdAt
431 public function setCreatedAt(\DateTime
$createdAt)
433 $this->createdAt
= $createdAt;
441 public function getCreatedAt()
443 return $this->createdAt
;
449 public function getUpdatedAt()
451 return $this->updatedAt
;
458 public function timestamps()
460 if (is_null($this->createdAt
)) {
461 $this->createdAt
= new \
DateTime();
464 $this->updatedAt
= new \
DateTime();
468 * @return ArrayCollection<Annotation>
470 public function getAnnotations()
472 return $this->annotations
;
476 * @param Annotation $annotation
478 public function setAnnotation(Annotation
$annotation)
480 $this->annotations
[] = $annotation;
486 public function getMimetype()
488 return $this->mimetype
;
492 * @param string $mimetype
494 public function setMimetype($mimetype)
496 $this->mimetype
= $mimetype;
502 public function getReadingTime()
504 return $this->readingTime
;
508 * @param int $readingTime
510 public function setReadingTime($readingTime)
512 $this->readingTime
= $readingTime;
518 public function getDomainName()
520 return $this->domainName
;
524 * @param string $domainName
526 public function setDomainName($domainName)
528 $this->domainName
= $domainName;
534 public function isPublic()
536 return $this->isPublic
;
540 * @param bool $isPublic
542 public function setIsPublic($isPublic)
544 $this->isPublic
= $isPublic;
548 * @return ArrayCollection<Tag>
550 public function getTags()
557 * @SerializedName("tags")
558 * @Groups({"entries_for_user", "export_all"})
560 public function getSerializedTags()
563 foreach ($this->tags
as $tag) {
564 $data[] = $tag->getLabel();
573 public function addTag(Tag
$tag)
575 if ($this->tags
->contains($tag)) {
579 // check if tag already exist but has not yet be persisted
580 // it seems that the previous condition with `contains()` doesn't check that case
581 foreach ($this->tags
as $existingTag) {
582 if ($existingTag->getLabel() === $tag->getLabel()) {
587 $this->tags
->add($tag);
588 $tag->addEntry($this);
591 public function removeTag(Tag
$tag)
593 if (!$this->tags
->contains($tag)) {
597 $this->tags
->removeElement($tag);
598 $tag->removeEntry($this);
602 * Set previewPicture.
604 * @param string $previewPicture
608 public function setPreviewPicture($previewPicture)
610 $this->previewPicture
= $previewPicture;
616 * Get previewPicture.
620 public function getPreviewPicture()
622 return $this->previewPicture
;
628 * @param string $language
632 public function setLanguage($language)
634 $this->language
= $language;
644 public function getLanguage()
646 return $this->language
;
652 public function getUuid()
658 * @param string $uuid
662 public function setUuid($uuid)
669 public function generateUuid()
671 if (null === $this->uuid
) {
672 // @see http://blog.kevingomez.fr/til/2015/07/26/why-is-uniqid-slow/ for true parameter
673 $this->uuid
= uniqid('', true);
677 public function cleanUuid()
685 public function getHttpStatus()
687 return $this->httpStatus
;
691 * @param int $httpStatus
695 public function setHttpStatus($httpStatus)
697 $this->httpStatus
= $httpStatus;