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="http_status", type="string", length=3, nullable=true)
182 * @Groups({"entries_for_user", "export_all"})
189 * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="entries")
191 * @Groups({"export_all"})
196 * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"})
200 * @ORM\JoinColumn(name="entry_id", referencedColumnName="id", onDelete="cascade")
202 * inverseJoinColumns={
203 * @ORM\JoinColumn(name="tag_id", referencedColumnName="id", onDelete="cascade")
212 public function __construct(User
$user)
215 $this->tags
= new ArrayCollection();
223 public function getId()
231 * @param string $title
235 public function setTitle($title)
237 $this->title
= $title;
247 public function getTitle()
259 public function setUrl($url)
271 public function getUrl()
279 * @param bool $isArchived
283 public function setArchived($isArchived)
285 $this->isArchived
= $isArchived;
295 public function isArchived()
297 return $this->isArchived
;
302 * @SerializedName("is_archived")
303 * @Groups({"entries_for_user", "export_all"})
305 public function is_Archived()
307 return (int) $this->isArchived();
310 public function toggleArchive()
312 $this->isArchived
= $this->isArchived() ^
1;
320 * @param bool $isStarred
324 public function setStarred($isStarred)
326 $this->isStarred
= $isStarred;
336 public function isStarred()
338 return $this->isStarred
;
343 * @SerializedName("is_starred")
344 * @Groups({"entries_for_user", "export_all"})
346 public function is_Starred()
348 return (int) $this->isStarred();
351 public function toggleStar()
353 $this->isStarred
= $this->isStarred() ^
1;
361 * @param string $content
365 public function setContent($content)
367 $this->content
= $content;
377 public function getContent()
379 return $this->content
;
385 public function getUser()
392 * @SerializedName("user_name")
394 public function getUserName()
396 return $this->user
->getUserName();
401 * @SerializedName("user_email")
403 public function getUserEmail()
405 return $this->user
->getEmail();
410 * @SerializedName("user_id")
412 public function getUserId()
414 return $this->user
->getId();
419 * Only used when importing data from an other service.
421 * @param \DateTime $createdAt
425 public function setCreatedAt(\DateTime
$createdAt)
427 $this->createdAt
= $createdAt;
435 public function getCreatedAt()
437 return $this->createdAt
;
443 public function getUpdatedAt()
445 return $this->updatedAt
;
452 public function timestamps()
454 if (is_null($this->createdAt
)) {
455 $this->createdAt
= new \
DateTime();
458 $this->updatedAt
= new \
DateTime();
462 * @return ArrayCollection<Annotation>
464 public function getAnnotations()
466 return $this->annotations
;
470 * @param Annotation $annotation
472 public function setAnnotation(Annotation
$annotation)
474 $this->annotations
[] = $annotation;
480 public function getMimetype()
482 return $this->mimetype
;
486 * @param string $mimetype
488 public function setMimetype($mimetype)
490 $this->mimetype
= $mimetype;
496 public function getReadingTime()
498 return $this->readingTime
;
502 * @param int $readingTime
504 public function setReadingTime($readingTime)
506 $this->readingTime
= $readingTime;
512 public function getDomainName()
514 return $this->domainName
;
518 * @param string $domainName
520 public function setDomainName($domainName)
522 $this->domainName
= $domainName;
526 * @return ArrayCollection<Tag>
528 public function getTags()
535 * @SerializedName("tags")
536 * @Groups({"entries_for_user", "export_all"})
538 public function getSerializedTags()
541 foreach ($this->tags
as $tag) {
542 $data[] = $tag->getLabel();
551 public function addTag(Tag
$tag)
553 if ($this->tags
->contains($tag)) {
557 // check if tag already exist but has not yet be persisted
558 // it seems that the previous condition with `contains()` doesn't check that case
559 foreach ($this->tags
as $existingTag) {
560 if ($existingTag->getLabel() === $tag->getLabel()) {
565 $this->tags
->add($tag);
566 $tag->addEntry($this);
569 public function removeTag(Tag
$tag)
571 if (!$this->tags
->contains($tag)) {
575 $this->tags
->removeElement($tag);
576 $tag->removeEntry($this);
580 * Set previewPicture.
582 * @param string $previewPicture
586 public function setPreviewPicture($previewPicture)
588 $this->previewPicture
= $previewPicture;
594 * Get previewPicture.
598 public function getPreviewPicture()
600 return $this->previewPicture
;
606 * @param string $language
610 public function setLanguage($language)
612 $this->language
= $language;
622 public function getLanguage()
624 return $this->language
;
630 public function getUid()
640 public function setUid($uid)
647 public function generateUid()
649 if (null === $this->uid
) {
650 // @see http://blog.kevingomez.fr/til/2015/07/26/why-is-uniqid-slow/ for true parameter
651 $this->uid
= uniqid('', true);
655 public function cleanUid()
663 public function getHttpStatus()
665 return $this->httpStatus
;
669 * @param int $httpStatus
673 public function setHttpStatus($httpStatus)
675 $this->httpStatus
= $httpStatus;