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();
415 public function getCreatedAt()
417 return $this->createdAt
;
423 public function getUpdatedAt()
425 return $this->updatedAt
;
432 public function timestamps()
434 if (is_null($this->createdAt
)) {
435 $this->createdAt
= new \
DateTime();
438 $this->updatedAt
= new \
DateTime();
442 * @return ArrayCollection<Annotation>
444 public function getAnnotations()
446 return $this->annotations
;
450 * @param Annotation $annotation
452 public function setAnnotation(Annotation
$annotation)
454 $this->annotations
[] = $annotation;
460 public function getMimetype()
462 return $this->mimetype
;
466 * @param string $mimetype
468 public function setMimetype($mimetype)
470 $this->mimetype
= $mimetype;
476 public function getReadingTime()
478 return $this->readingTime
;
482 * @param int $readingTime
484 public function setReadingTime($readingTime)
486 $this->readingTime
= $readingTime;
492 public function getDomainName()
494 return $this->domainName
;
498 * @param string $domainName
500 public function setDomainName($domainName)
502 $this->domainName
= $domainName;
508 public function isPublic()
510 return $this->isPublic
;
514 * @param bool $isPublic
516 public function setIsPublic($isPublic)
518 $this->isPublic
= $isPublic;
522 * @return ArrayCollection<Tag>
524 public function getTags()
532 public function addTag(Tag
$tag)
534 if ($this->tags
->contains($tag)) {
538 // check if tag already exist but has not yet be persisted
539 // it seems that the previous condition with `contains()` doesn't check that case
540 foreach ($this->tags
as $existingTag) {
541 if ($existingTag->getLabel() === $tag->getLabel()) {
546 $this->tags
->add($tag);
547 $tag->addEntry($this);
550 public function removeTag(Tag
$tag)
552 if (!$this->tags
->contains($tag)) {
556 $this->tags
->removeElement($tag);
557 $tag->removeEntry($this);
561 * Set previewPicture.
563 * @param string $previewPicture
567 public function setPreviewPicture($previewPicture)
569 $this->previewPicture
= $previewPicture;
575 * Get previewPicture.
579 public function getPreviewPicture()
581 return $this->previewPicture
;
587 * @param string $language
591 public function setLanguage($language)
593 $this->language
= $language;
603 public function getLanguage()
605 return $this->language
;
611 public function getUuid()
617 * @param string $uuid
621 public function setUuid($uuid)
628 public function generateUuid()
630 if (null === $this->uuid
) {
631 // @see http://blog.kevingomez.fr/til/2015/07/26/why-is-uniqid-slow/ for true parameter
632 $this->uuid
= uniqid('', true);
636 public function cleanUuid()