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")
22 * @ORM\Table(name="`entry`")
23 * @ORM\HasLifecycleCallbacks()
24 * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())")
28 /** @Serializer\XmlAttribute */
32 * @ORM\Column(name="id", type="integer")
34 * @ORM\GeneratedValue(strategy="AUTO")
36 * @Groups({"entries_for_user", "export_all"})
43 * @ORM\Column(name="uuid", type="text", nullable=true)
45 * @Groups({"entries_for_user", "export_all"})
52 * @ORM\Column(name="title", type="text", nullable=true)
54 * @Groups({"entries_for_user", "export_all"})
62 * @ORM\Column(name="url", type="text", nullable=true)
64 * @Groups({"entries_for_user", "export_all"})
73 * @ORM\Column(name="is_archived", type="boolean")
75 * @Groups({"entries_for_user", "export_all"})
77 private $isArchived = false;
84 * @ORM\Column(name="is_starred", type="boolean")
86 * @Groups({"entries_for_user", "export_all"})
88 private $isStarred = false;
93 * @ORM\Column(name="content", type="text", nullable=true)
95 * @Groups({"entries_for_user", "export_all"})
102 * @ORM\Column(name="created_at", type="datetime")
104 * @Groups({"entries_for_user", "export_all"})
111 * @ORM\Column(name="updated_at", type="datetime")
113 * @Groups({"entries_for_user", "export_all"})
118 * @ORM\OneToMany(targetEntity="Wallabag\AnnotationBundle\Entity\Annotation", mappedBy="entry", cascade={"persist", "remove"})
121 * @Groups({"entries_for_user", "export_all"})
123 private $annotations;
128 * @ORM\Column(name="mimetype", type="text", nullable=true)
130 * @Groups({"entries_for_user", "export_all"})
137 * @ORM\Column(name="language", type="text", nullable=true)
139 * @Groups({"entries_for_user", "export_all"})
146 * @ORM\Column(name="reading_time", type="integer", nullable=true)
148 * @Groups({"entries_for_user", "export_all"})
150 private $readingTime;
155 * @ORM\Column(name="domain_name", type="text", nullable=true)
157 * @Groups({"entries_for_user", "export_all"})
164 * @ORM\Column(name="preview_picture", type="text", nullable=true)
166 * @Groups({"entries_for_user", "export_all"})
168 private $previewPicture;
173 * @ORM\Column(name="is_public", type="boolean", nullable=true, options={"default" = false})
175 * @Groups({"export_all"})
182 * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="entries")
184 * @Groups({"export_all"})
189 * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"})
193 * @ORM\JoinColumn(name="entry_id", referencedColumnName="id")
195 * inverseJoinColumns={
196 * @ORM\JoinColumn(name="tag_id", referencedColumnName="id")
205 public function __construct(User
$user)
208 $this->tags
= new ArrayCollection();
216 public function getId()
224 * @param string $title
228 public function setTitle($title)
230 $this->title
= $title;
240 public function getTitle()
252 public function setUrl($url)
264 public function getUrl()
272 * @param bool $isArchived
276 public function setArchived($isArchived)
278 $this->isArchived
= $isArchived;
288 public function isArchived()
290 return $this->isArchived
;
295 * @SerializedName("is_archived")
296 * @Groups({"entries_for_user", "export_all"})
298 public function is_Archived()
300 return (int) $this->isArchived();
303 public function toggleArchive()
305 $this->isArchived
= $this->isArchived() ^
1;
313 * @param bool $isStarred
317 public function setStarred($isStarred)
319 $this->isStarred
= $isStarred;
329 public function isStarred()
331 return $this->isStarred
;
336 * @SerializedName("is_starred")
337 * @Groups({"entries_for_user", "export_all"})
339 public function is_Starred()
341 return (int) $this->isStarred();
344 public function toggleStar()
346 $this->isStarred
= $this->isStarred() ^
1;
354 * @param string $content
358 public function setContent($content)
360 $this->content
= $content;
370 public function getContent()
372 return $this->content
;
378 public function getUser()
385 * @SerializedName("user_name")
387 public function getUserName()
389 return $this->user
->getUserName();
394 * @SerializedName("user_email")
396 public function getUserEmail()
398 return $this->user
->getEmail();
403 * @SerializedName("user_id")
405 public function getUserId()
407 return $this->user
->getId();
412 * Only used when importing data from an other service.
414 * @param \DateTime $createdAt
418 public function setCreatedAt(\DateTime
$createdAt)
420 $this->createdAt
= $createdAt;
428 public function getCreatedAt()
430 return $this->createdAt
;
436 public function getUpdatedAt()
438 return $this->updatedAt
;
445 public function timestamps()
447 if (is_null($this->createdAt
)) {
448 $this->createdAt
= new \
DateTime();
451 $this->updatedAt
= new \
DateTime();
455 * @return ArrayCollection<Annotation>
457 public function getAnnotations()
459 return $this->annotations
;
463 * @param Annotation $annotation
465 public function setAnnotation(Annotation
$annotation)
467 $this->annotations
[] = $annotation;
473 public function getMimetype()
475 return $this->mimetype
;
479 * @param string $mimetype
481 public function setMimetype($mimetype)
483 $this->mimetype
= $mimetype;
489 public function getReadingTime()
491 return $this->readingTime
;
495 * @param int $readingTime
497 public function setReadingTime($readingTime)
499 $this->readingTime
= $readingTime;
505 public function getDomainName()
507 return $this->domainName
;
511 * @param string $domainName
513 public function setDomainName($domainName)
515 $this->domainName
= $domainName;
521 public function isPublic()
523 return $this->isPublic
;
527 * @param bool $isPublic
529 public function setIsPublic($isPublic)
531 $this->isPublic
= $isPublic;
535 * @return ArrayCollection<Tag>
537 public function getTags()
544 * @SerializedName("tags")
545 * @Groups({"entries_for_user", "export_all"})
547 public function getSerializedTags()
550 foreach ($this->tags
as $tag) {
551 $data[] = $tag->getLabel();
560 public function addTag(Tag
$tag)
562 if ($this->tags
->contains($tag)) {
566 // check if tag already exist but has not yet be persisted
567 // it seems that the previous condition with `contains()` doesn't check that case
568 foreach ($this->tags
as $existingTag) {
569 if ($existingTag->getLabel() === $tag->getLabel()) {
574 $this->tags
->add($tag);
575 $tag->addEntry($this);
578 public function removeTag(Tag
$tag)
580 if (!$this->tags
->contains($tag)) {
584 $this->tags
->removeElement($tag);
585 $tag->removeEntry($this);
589 * Set previewPicture.
591 * @param string $previewPicture
595 public function setPreviewPicture($previewPicture)
597 $this->previewPicture
= $previewPicture;
603 * Get previewPicture.
607 public function getPreviewPicture()
609 return $this->previewPicture
;
615 * @param string $language
619 public function setLanguage($language)
621 $this->language
= $language;
631 public function getLanguage()
633 return $this->language
;
639 public function getUuid()
645 * @param string $uuid
649 public function setUuid($uuid)
656 public function generateUuid()
658 if (null === $this->uuid
) {
659 // @see http://blog.kevingomez.fr/til/2015/07/26/why-is-uniqid-slow/ for true parameter
660 $this->uuid
= uniqid('', true);
664 public function cleanUuid()