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"})
62 * @ORM\Column(name="is_archived", type="boolean")
64 * @Groups({"entries_for_user", "export_all"})
66 private $isArchived = false;
71 * @ORM\Column(name="is_starred", type="boolean")
73 * @Groups({"entries_for_user", "export_all"})
75 private $isStarred = false;
80 * @ORM\Column(name="content", type="text", nullable=true)
82 * @Groups({"entries_for_user", "export_all"})
89 * @ORM\Column(name="created_at", type="datetime")
91 * @Groups({"export_all"})
98 * @ORM\Column(name="updated_at", type="datetime")
100 * @Groups({"export_all"})
105 * @ORM\OneToMany(targetEntity="Wallabag\AnnotationBundle\Entity\Annotation", mappedBy="entry", cascade={"persist", "remove"})
108 * @Groups({"entries_for_user", "export_all"})
110 private $annotations;
115 * @ORM\Column(name="mimetype", type="text", nullable=true)
117 * @Groups({"entries_for_user", "export_all"})
124 * @ORM\Column(name="language", type="text", nullable=true)
126 * @Groups({"entries_for_user", "export_all"})
133 * @ORM\Column(name="reading_time", type="integer", nullable=true)
135 * @Groups({"entries_for_user", "export_all"})
137 private $readingTime;
142 * @ORM\Column(name="domain_name", type="text", nullable=true)
144 * @Groups({"entries_for_user", "export_all"})
151 * @ORM\Column(name="preview_picture", type="text", nullable=true)
153 * @Groups({"entries_for_user", "export_all"})
155 private $previewPicture;
160 * @ORM\Column(name="is_public", type="boolean", nullable=true, options={"default" = false})
162 * @Groups({"export_all"})
169 * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="entries")
171 * @Groups({"export_all"})
176 * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist", "remove"})
179 * @Groups({"entries_for_user", "export_all"})
186 public function __construct(\Wallabag\UserBundle\Entity\User
$user)
189 $this->tags
= new ArrayCollection();
197 public function getId()
205 * @param string $title
209 public function setTitle($title)
211 $this->title
= $title;
221 public function getTitle()
233 public function setUrl($url)
245 public function getUrl()
253 * @param bool $isArchived
257 public function setArchived($isArchived)
259 $this->isArchived
= $isArchived;
269 public function isArchived()
271 return $this->isArchived
;
274 public function toggleArchive()
276 $this->isArchived
= $this->isArchived() ^
1;
284 * @param bool $isStarred
288 public function setStarred($isStarred)
290 $this->isStarred
= $isStarred;
300 public function isStarred()
302 return $this->isStarred
;
305 public function toggleStar()
307 $this->isStarred
= $this->isStarred() ^
1;
315 * @param string $content
319 public function setContent($content)
321 $this->content
= $content;
331 public function getContent()
333 return $this->content
;
339 public function getUser()
346 * @SerializedName("user_name")
348 public function getUserName()
350 return $this->user
->getUserName();
355 * @SerializedName("user_email")
357 public function getUserEmail()
359 return $this->user
->getEmail();
364 * @SerializedName("user_id")
366 public function getUserId()
368 return $this->user
->getId();
374 public function getCreatedAt()
376 return $this->createdAt
;
382 public function getUpdatedAt()
384 return $this->updatedAt
;
391 public function timestamps()
393 if (is_null($this->createdAt
)) {
394 $this->createdAt
= new \
DateTime();
397 $this->updatedAt
= new \
DateTime();
401 * @return ArrayCollection<Annotation>
403 public function getAnnotations()
405 return $this->annotations
;
409 * @param Annotation $annotation
411 public function setAnnotation(Annotation
$annotation)
413 $this->annotations
[] = $annotation;
419 public function getMimetype()
421 return $this->mimetype
;
425 * @param string $mimetype
427 public function setMimetype($mimetype)
429 $this->mimetype
= $mimetype;
435 public function getReadingTime()
437 return $this->readingTime
;
441 * @param int $readingTime
443 public function setReadingTime($readingTime)
445 $this->readingTime
= $readingTime;
451 public function getDomainName()
453 return $this->domainName
;
457 * @param string $domainName
459 public function setDomainName($domainName)
461 $this->domainName
= $domainName;
467 public function isPublic()
469 return $this->isPublic
;
473 * @param bool $isPublic
475 public function setIsPublic($isPublic)
477 $this->isPublic
= $isPublic;
481 * @return ArrayCollection<Tag>
483 public function getTags()
491 public function addTag(Tag
$tag)
493 if ($this->tags
->contains($tag)) {
497 // check if tag already exist but has not yet be persisted
498 // it seems that the previous condition with `contains()` doesn't check that case
499 foreach ($this->tags
as $existingTag) {
500 if ($existingTag->getLabel() === $tag->getLabel()) {
505 $this->tags
[] = $tag;
506 $tag->addEntry($this);
509 public function removeTag(Tag
$tag)
511 $this->tags
->removeElement($tag);
515 * Set previewPicture.
517 * @param string $previewPicture
521 public function setPreviewPicture($previewPicture)
523 $this->previewPicture
= $previewPicture;
529 * Get previewPicture.
533 public function getPreviewPicture()
535 return $this->previewPicture
;
541 * @param string $language
545 public function setLanguage($language)
547 $this->language
= $language;
557 public function getLanguage()
559 return $this->language
;