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", "remove"})
183 * @Groups({"entries_for_user", "export_all"})
190 public function __construct(User
$user)
193 $this->tags
= new ArrayCollection();
201 public function getId()
209 * @param string $title
213 public function setTitle($title)
215 $this->title
= $title;
225 public function getTitle()
237 public function setUrl($url)
249 public function getUrl()
257 * @param bool $isArchived
261 public function setArchived($isArchived)
263 $this->isArchived
= $isArchived;
273 public function isArchived()
275 return $this->isArchived
;
280 * @SerializedName("is_archived")
281 * @Groups({"entries_for_user", "export_all"})
283 public function is_Archived()
285 return (int) $this->isArchived();
288 public function toggleArchive()
290 $this->isArchived
= $this->isArchived() ^
1;
298 * @param bool $isStarred
302 public function setStarred($isStarred)
304 $this->isStarred
= $isStarred;
314 public function isStarred()
316 return $this->isStarred
;
321 * @SerializedName("is_starred")
322 * @Groups({"entries_for_user", "export_all"})
324 public function is_Starred()
326 return (int) $this->isStarred();
329 public function toggleStar()
331 $this->isStarred
= $this->isStarred() ^
1;
339 * @param string $content
343 public function setContent($content)
345 $this->content
= $content;
355 public function getContent()
357 return $this->content
;
363 public function getUser()
370 * @SerializedName("user_name")
372 public function getUserName()
374 return $this->user
->getUserName();
379 * @SerializedName("user_email")
381 public function getUserEmail()
383 return $this->user
->getEmail();
388 * @SerializedName("user_id")
390 public function getUserId()
392 return $this->user
->getId();
398 public function getCreatedAt()
400 return $this->createdAt
;
406 public function getUpdatedAt()
408 return $this->updatedAt
;
415 public function timestamps()
417 if (is_null($this->createdAt
)) {
418 $this->createdAt
= new \
DateTime();
421 $this->updatedAt
= new \
DateTime();
425 * @return ArrayCollection<Annotation>
427 public function getAnnotations()
429 return $this->annotations
;
433 * @param Annotation $annotation
435 public function setAnnotation(Annotation
$annotation)
437 $this->annotations
[] = $annotation;
443 public function getMimetype()
445 return $this->mimetype
;
449 * @param string $mimetype
451 public function setMimetype($mimetype)
453 $this->mimetype
= $mimetype;
459 public function getReadingTime()
461 return $this->readingTime
;
465 * @param int $readingTime
467 public function setReadingTime($readingTime)
469 $this->readingTime
= $readingTime;
475 public function getDomainName()
477 return $this->domainName
;
481 * @param string $domainName
483 public function setDomainName($domainName)
485 $this->domainName
= $domainName;
491 public function isPublic()
493 return $this->isPublic
;
497 * @param bool $isPublic
499 public function setIsPublic($isPublic)
501 $this->isPublic
= $isPublic;
505 * @return ArrayCollection<Tag>
507 public function getTags()
515 public function addTag(Tag
$tag)
517 if ($this->tags
->contains($tag)) {
521 // check if tag already exist but has not yet be persisted
522 // it seems that the previous condition with `contains()` doesn't check that case
523 foreach ($this->tags
as $existingTag) {
524 if ($existingTag->getLabel() === $tag->getLabel()) {
529 $this->tags
[] = $tag;
530 $tag->addEntry($this);
533 public function removeTag(Tag
$tag)
535 $this->tags
->removeElement($tag);
539 * Set previewPicture.
541 * @param string $previewPicture
545 public function setPreviewPicture($previewPicture)
547 $this->previewPicture
= $previewPicture;
553 * Get previewPicture.
557 public function getPreviewPicture()
559 return $this->previewPicture
;
565 * @param string $language
569 public function setLanguage($language)
571 $this->language
= $language;
581 public function getLanguage()
583 return $this->language
;