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")
200 * @Groups({"entries_for_user", "export_all"})
207 public function __construct(User
$user)
210 $this->tags
= new ArrayCollection();
218 public function getId()
226 * @param string $title
230 public function setTitle($title)
232 $this->title
= $title;
242 public function getTitle()
254 public function setUrl($url)
266 public function getUrl()
274 * @param bool $isArchived
278 public function setArchived($isArchived)
280 $this->isArchived
= $isArchived;
290 public function isArchived()
292 return $this->isArchived
;
297 * @SerializedName("is_archived")
298 * @Groups({"entries_for_user", "export_all"})
300 public function is_Archived()
302 return (int) $this->isArchived();
305 public function toggleArchive()
307 $this->isArchived
= $this->isArchived() ^
1;
315 * @param bool $isStarred
319 public function setStarred($isStarred)
321 $this->isStarred
= $isStarred;
331 public function isStarred()
333 return $this->isStarred
;
338 * @SerializedName("is_starred")
339 * @Groups({"entries_for_user", "export_all"})
341 public function is_Starred()
343 return (int) $this->isStarred();
346 public function toggleStar()
348 $this->isStarred
= $this->isStarred() ^
1;
356 * @param string $content
360 public function setContent($content)
362 $this->content
= $content;
372 public function getContent()
374 return $this->content
;
380 public function getUser()
387 * @SerializedName("user_name")
389 public function getUserName()
391 return $this->user
->getUserName();
396 * @SerializedName("user_email")
398 public function getUserEmail()
400 return $this->user
->getEmail();
405 * @SerializedName("user_id")
407 public function getUserId()
409 return $this->user
->getId();
414 * Only used when importing data from an other service.
416 * @param \DateTime $createdAt
420 public function setCreatedAt(\DateTime
$createdAt)
422 $this->createdAt
= $createdAt;
430 public function getCreatedAt()
432 return $this->createdAt
;
438 public function getUpdatedAt()
440 return $this->updatedAt
;
447 public function timestamps()
449 if (is_null($this->createdAt
)) {
450 $this->createdAt
= new \
DateTime();
453 $this->updatedAt
= new \
DateTime();
457 * @return ArrayCollection<Annotation>
459 public function getAnnotations()
461 return $this->annotations
;
465 * @param Annotation $annotation
467 public function setAnnotation(Annotation
$annotation)
469 $this->annotations
[] = $annotation;
475 public function getMimetype()
477 return $this->mimetype
;
481 * @param string $mimetype
483 public function setMimetype($mimetype)
485 $this->mimetype
= $mimetype;
491 public function getReadingTime()
493 return $this->readingTime
;
497 * @param int $readingTime
499 public function setReadingTime($readingTime)
501 $this->readingTime
= $readingTime;
507 public function getDomainName()
509 return $this->domainName
;
513 * @param string $domainName
515 public function setDomainName($domainName)
517 $this->domainName
= $domainName;
523 public function isPublic()
525 return $this->isPublic
;
529 * @param bool $isPublic
531 public function setIsPublic($isPublic)
533 $this->isPublic
= $isPublic;
537 * @return ArrayCollection<Tag>
539 public function getTags()
547 public function addTag(Tag
$tag)
549 if ($this->tags
->contains($tag)) {
553 // check if tag already exist but has not yet be persisted
554 // it seems that the previous condition with `contains()` doesn't check that case
555 foreach ($this->tags
as $existingTag) {
556 if ($existingTag->getLabel() === $tag->getLabel()) {
561 $this->tags
->add($tag);
562 $tag->addEntry($this);
565 public function removeTag(Tag
$tag)
567 if (!$this->tags
->contains($tag)) {
571 $this->tags
->removeElement($tag);
572 $tag->removeEntry($this);
576 * Set previewPicture.
578 * @param string $previewPicture
582 public function setPreviewPicture($previewPicture)
584 $this->previewPicture
= $previewPicture;
590 * Get previewPicture.
594 public function getPreviewPicture()
596 return $this->previewPicture
;
602 * @param string $language
606 public function setLanguage($language)
608 $this->language
= $language;
618 public function getLanguage()
620 return $this->language
;
626 public function getUuid()
632 * @param string $uuid
636 public function setUuid($uuid)
643 public function generateUuid()
645 if (null === $this->uuid
) {
646 // @see http://blog.kevingomez.fr/til/2015/07/26/why-is-uniqid-slow/ for true parameter
647 $this->uuid
= uniqid('', true);
651 public function cleanUuid()