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"})
125 * @ORM\OneToMany(targetEntity="Wallabag\AnnotationBundle\Entity\Annotation", mappedBy="entry", cascade={"persist", "remove"})
128 * @Groups({"entries_for_user", "export_all"})
130 private $annotations;
135 * @ORM\Column(name="mimetype", type="text", nullable=true)
137 * @Groups({"entries_for_user", "export_all"})
144 * @ORM\Column(name="language", type="text", nullable=true)
146 * @Groups({"entries_for_user", "export_all"})
153 * @ORM\Column(name="reading_time", type="integer", nullable=true)
155 * @Groups({"entries_for_user", "export_all"})
157 private $readingTime;
162 * @ORM\Column(name="domain_name", type="text", nullable=true)
164 * @Groups({"entries_for_user", "export_all"})
171 * @ORM\Column(name="preview_picture", type="text", nullable=true)
173 * @Groups({"entries_for_user", "export_all"})
175 private $previewPicture;
180 * @ORM\Column(name="is_public", type="boolean", nullable=true, options={"default" = false})
182 * @Groups({"export_all"})
189 * @ORM\Column(name="http_status", type="string", length=3, nullable=true)
191 * @Groups({"entries_for_user", "export_all"})
198 * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="entries")
200 * @Groups({"export_all"})
205 * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"})
209 * @ORM\JoinColumn(name="entry_id", referencedColumnName="id", onDelete="cascade")
211 * inverseJoinColumns={
212 * @ORM\JoinColumn(name="tag_id", referencedColumnName="id", onDelete="cascade")
221 public function __construct(User
$user)
224 $this->tags
= new ArrayCollection();
232 public function getId()
240 * @param string $title
244 public function setTitle($title)
246 $this->title
= $title;
256 public function getTitle()
268 public function setUrl($url)
280 public function getUrl()
288 * @param bool $isArchived
292 public function setArchived($isArchived)
294 $this->isArchived
= $isArchived;
304 public function isArchived()
306 return $this->isArchived
;
311 * @SerializedName("is_archived")
312 * @Groups({"entries_for_user", "export_all"})
314 public function is_Archived()
316 return (int) $this->isArchived();
319 public function toggleArchive()
321 $this->isArchived
= $this->isArchived() ^
1;
329 * @param bool $isStarred
333 public function setStarred($isStarred)
335 $this->isStarred
= $isStarred;
345 public function isStarred()
347 return $this->isStarred
;
352 * @SerializedName("is_starred")
353 * @Groups({"entries_for_user", "export_all"})
355 public function is_Starred()
357 return (int) $this->isStarred();
360 public function toggleStar()
362 $this->isStarred
= $this->isStarred() ^
1;
370 * @param string $content
374 public function setContent($content)
376 $this->content
= $content;
386 public function getContent()
388 return $this->content
;
394 public function getUser()
401 * @SerializedName("user_name")
403 public function getUserName()
405 return $this->user
->getUserName();
410 * @SerializedName("user_email")
412 public function getUserEmail()
414 return $this->user
->getEmail();
419 * @SerializedName("user_id")
421 public function getUserId()
423 return $this->user
->getId();
428 * Only used when importing data from an other service.
430 * @param \DateTime $createdAt
434 public function setCreatedAt(\DateTime
$createdAt)
436 $this->createdAt
= $createdAt;
444 public function getCreatedAt()
446 return $this->createdAt
;
452 public function getUpdatedAt()
454 return $this->updatedAt
;
461 public function timestamps()
463 if (is_null($this->createdAt
)) {
464 $this->createdAt
= new \
DateTime();
467 $this->updatedAt
= new \
DateTime();
471 * @return ArrayCollection<Annotation>
473 public function getAnnotations()
475 return $this->annotations
;
479 * @param Annotation $annotation
481 public function setAnnotation(Annotation
$annotation)
483 $this->annotations
[] = $annotation;
489 public function getMimetype()
491 return $this->mimetype
;
495 * @param string $mimetype
497 public function setMimetype($mimetype)
499 $this->mimetype
= $mimetype;
505 public function getReadingTime()
507 return $this->readingTime
;
511 * @param int $readingTime
513 public function setReadingTime($readingTime)
515 $this->readingTime
= $readingTime;
521 public function getDomainName()
523 return $this->domainName
;
527 * @param string $domainName
529 public function setDomainName($domainName)
531 $this->domainName
= $domainName;
537 public function isPublic()
539 return $this->isPublic
;
543 * @param bool $isPublic
545 public function setIsPublic($isPublic)
547 $this->isPublic
= $isPublic;
551 * @return ArrayCollection<Tag>
553 public function getTags()
560 * @SerializedName("tags")
561 * @Groups({"entries_for_user", "export_all"})
563 public function getSerializedTags()
566 foreach ($this->tags
as $tag) {
567 $data[] = $tag->getLabel();
576 public function addTag(Tag
$tag)
578 if ($this->tags
->contains($tag)) {
582 // check if tag already exist but has not yet be persisted
583 // it seems that the previous condition with `contains()` doesn't check that case
584 foreach ($this->tags
as $existingTag) {
585 if ($existingTag->getLabel() === $tag->getLabel()) {
590 $this->tags
->add($tag);
591 $tag->addEntry($this);
594 public function removeTag(Tag
$tag)
596 if (!$this->tags
->contains($tag)) {
600 $this->tags
->removeElement($tag);
601 $tag->removeEntry($this);
605 * Set previewPicture.
607 * @param string $previewPicture
611 public function setPreviewPicture($previewPicture)
613 $this->previewPicture
= $previewPicture;
619 * Get previewPicture.
623 public function getPreviewPicture()
625 return $this->previewPicture
;
631 * @param string $language
635 public function setLanguage($language)
637 $this->language
= $language;
647 public function getLanguage()
649 return $this->language
;
655 public function getUid()
665 public function setUid($uid)
672 public function generateUid()
674 if (null === $this->uid
) {
675 // @see http://blog.kevingomez.fr/til/2015/07/26/why-is-uniqid-slow/ for true parameter
676 $this->uid
= uniqid('', true);
680 public function cleanUid()
688 public function getHttpStatus()
690 return $this->httpStatus
;
694 * @param int $httpStatus
698 public function setHttpStatus($httpStatus)
700 $this->httpStatus
= $httpStatus;