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="title", type="text", nullable=true)
45 * @Groups({"entries_for_user", "export_all"})
53 * @ORM\Column(name="url", type="text", nullable=true)
55 * @Groups({"entries_for_user", "export_all"})
64 * @ORM\Column(name="is_archived", type="boolean")
66 * @Groups({"entries_for_user", "export_all"})
68 private $isArchived = false;
75 * @ORM\Column(name="is_starred", type="boolean")
77 * @Groups({"entries_for_user", "export_all"})
79 private $isStarred = false;
84 * @ORM\Column(name="content", type="text", nullable=true)
86 * @Groups({"entries_for_user", "export_all"})
93 * @ORM\Column(name="created_at", type="datetime")
95 * @Groups({"export_all"})
102 * @ORM\Column(name="updated_at", type="datetime")
104 * @Groups({"export_all"})
109 * @ORM\OneToMany(targetEntity="Wallabag\AnnotationBundle\Entity\Annotation", mappedBy="entry", cascade={"persist", "remove"})
112 * @Groups({"entries_for_user", "export_all"})
114 private $annotations;
119 * @ORM\Column(name="mimetype", type="text", nullable=true)
121 * @Groups({"entries_for_user", "export_all"})
128 * @ORM\Column(name="language", type="text", nullable=true)
130 * @Groups({"entries_for_user", "export_all"})
137 * @ORM\Column(name="reading_time", type="integer", nullable=true)
139 * @Groups({"entries_for_user", "export_all"})
141 private $readingTime;
146 * @ORM\Column(name="domain_name", type="text", nullable=true)
148 * @Groups({"entries_for_user", "export_all"})
155 * @ORM\Column(name="preview_picture", type="text", nullable=true)
157 * @Groups({"entries_for_user", "export_all"})
159 private $previewPicture;
164 * @ORM\Column(name="is_public", type="boolean", nullable=true, options={"default" = false})
166 * @Groups({"export_all"})
173 * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="entries")
175 * @Groups({"export_all"})
180 * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"})
184 * @ORM\JoinColumn(name="entry_id", referencedColumnName="id")
186 * inverseJoinColumns={
187 * @ORM\JoinColumn(name="tag_id", referencedColumnName="id")
191 * @Groups({"entries_for_user", "export_all"})
198 public function __construct(User
$user)
201 $this->tags
= new ArrayCollection();
209 public function getId()
217 * @param string $title
221 public function setTitle($title)
223 $this->title
= $title;
233 public function getTitle()
245 public function setUrl($url)
257 public function getUrl()
265 * @param bool $isArchived
269 public function setArchived($isArchived)
271 $this->isArchived
= $isArchived;
281 public function isArchived()
283 return $this->isArchived
;
288 * @SerializedName("is_archived")
289 * @Groups({"entries_for_user", "export_all"})
291 public function is_Archived()
293 return (int) $this->isArchived();
296 public function toggleArchive()
298 $this->isArchived
= $this->isArchived() ^
1;
306 * @param bool $isStarred
310 public function setStarred($isStarred)
312 $this->isStarred
= $isStarred;
322 public function isStarred()
324 return $this->isStarred
;
329 * @SerializedName("is_starred")
330 * @Groups({"entries_for_user", "export_all"})
332 public function is_Starred()
334 return (int) $this->isStarred();
337 public function toggleStar()
339 $this->isStarred
= $this->isStarred() ^
1;
347 * @param string $content
351 public function setContent($content)
353 $this->content
= $content;
363 public function getContent()
365 return $this->content
;
371 public function getUser()
378 * @SerializedName("user_name")
380 public function getUserName()
382 return $this->user
->getUserName();
387 * @SerializedName("user_email")
389 public function getUserEmail()
391 return $this->user
->getEmail();
396 * @SerializedName("user_id")
398 public function getUserId()
400 return $this->user
->getId();
406 public function getCreatedAt()
408 return $this->createdAt
;
414 public function getUpdatedAt()
416 return $this->updatedAt
;
423 public function timestamps()
425 if (is_null($this->createdAt
)) {
426 $this->createdAt
= new \
DateTime();
429 $this->updatedAt
= new \
DateTime();
433 * @return ArrayCollection<Annotation>
435 public function getAnnotations()
437 return $this->annotations
;
441 * @param Annotation $annotation
443 public function setAnnotation(Annotation
$annotation)
445 $this->annotations
[] = $annotation;
451 public function getMimetype()
453 return $this->mimetype
;
457 * @param string $mimetype
459 public function setMimetype($mimetype)
461 $this->mimetype
= $mimetype;
467 public function getReadingTime()
469 return $this->readingTime
;
473 * @param int $readingTime
475 public function setReadingTime($readingTime)
477 $this->readingTime
= $readingTime;
483 public function getDomainName()
485 return $this->domainName
;
489 * @param string $domainName
491 public function setDomainName($domainName)
493 $this->domainName
= $domainName;
499 public function isPublic()
501 return $this->isPublic
;
505 * @param bool $isPublic
507 public function setIsPublic($isPublic)
509 $this->isPublic
= $isPublic;
513 * @return ArrayCollection<Tag>
515 public function getTags()
523 public function addTag(Tag
$tag)
525 if ($this->tags
->contains($tag)) {
529 // check if tag already exist but has not yet be persisted
530 // it seems that the previous condition with `contains()` doesn't check that case
531 foreach ($this->tags
as $existingTag) {
532 if ($existingTag->getLabel() === $tag->getLabel()) {
537 $this->tags
->add($tag);
538 $tag->addEntry($this);
541 public function removeTag(Tag
$tag)
543 if (!$this->tags
->contains($tag)) {
547 $this->tags
->removeElement($tag);
548 $tag->removeEntry($this);
552 * Set previewPicture.
554 * @param string $previewPicture
558 public function setPreviewPicture($previewPicture)
560 $this->previewPicture
= $previewPicture;
566 * Get previewPicture.
570 public function getPreviewPicture()
572 return $this->previewPicture
;
578 * @param string $language
582 public function setLanguage($language)
584 $this->language
= $language;
594 public function getLanguage()
596 return $this->language
;