aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Entity/Entry.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/CoreBundle/Entity/Entry.php')
-rw-r--r--src/Wallabag/CoreBundle/Entity/Entry.php206
1 files changed, 168 insertions, 38 deletions
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php
index 7276b437..cfb8db75 100644
--- a/src/Wallabag/CoreBundle/Entity/Entry.php
+++ b/src/Wallabag/CoreBundle/Entity/Entry.php
@@ -5,14 +5,15 @@ namespace Wallabag\CoreBundle\Entity;
5use Doctrine\Common\Collections\ArrayCollection; 5use Doctrine\Common\Collections\ArrayCollection;
6use Doctrine\ORM\Mapping as ORM; 6use Doctrine\ORM\Mapping as ORM;
7use Hateoas\Configuration\Annotation as Hateoas; 7use Hateoas\Configuration\Annotation as Hateoas;
8use JMS\Serializer\Annotation\Groups;
9use JMS\Serializer\Annotation\XmlRoot;
10use JMS\Serializer\Annotation\Exclude; 8use JMS\Serializer\Annotation\Exclude;
11use JMS\Serializer\Annotation\VirtualProperty; 9use JMS\Serializer\Annotation\Groups;
12use JMS\Serializer\Annotation\SerializedName; 10use JMS\Serializer\Annotation\SerializedName;
11use JMS\Serializer\Annotation\VirtualProperty;
12use JMS\Serializer\Annotation\XmlRoot;
13use Symfony\Component\Validator\Constraints as Assert; 13use Symfony\Component\Validator\Constraints as Assert;
14use Wallabag\UserBundle\Entity\User;
15use Wallabag\AnnotationBundle\Entity\Annotation; 14use Wallabag\AnnotationBundle\Entity\Annotation;
15use Wallabag\CoreBundle\Helper\EntityTimestampsTrait;
16use Wallabag\UserBundle\Entity\User;
16 17
17/** 18/**
18 * Entry. 19 * Entry.
@@ -32,6 +33,8 @@ use Wallabag\AnnotationBundle\Entity\Annotation;
32 */ 33 */
33class Entry 34class Entry
34{ 35{
36 use EntityTimestampsTrait;
37
35 /** @Serializer\XmlAttribute */ 38 /** @Serializer\XmlAttribute */
36 /** 39 /**
37 * @var int 40 * @var int
@@ -122,6 +125,33 @@ class Entry
122 private $updatedAt; 125 private $updatedAt;
123 126
124 /** 127 /**
128 * @var \DateTime
129 *
130 * @ORM\Column(name="published_at", type="datetime", nullable=true)
131 *
132 * @Groups({"entries_for_user", "export_all"})
133 */
134 private $publishedAt;
135
136 /**
137 * @var array
138 *
139 * @ORM\Column(name="published_by", type="array", nullable=true)
140 *
141 * @Groups({"entries_for_user", "export_all"})
142 */
143 private $publishedBy;
144
145 /**
146 * @var \DateTime
147 *
148 * @ORM\Column(name="starred_at", type="datetime", nullable=true)
149 *
150 * @Groups({"entries_for_user", "export_all"})
151 */
152 private $starredAt = null;
153
154 /**
125 * @ORM\OneToMany(targetEntity="Wallabag\AnnotationBundle\Entity\Annotation", mappedBy="entry", cascade={"persist", "remove"}) 155 * @ORM\OneToMany(targetEntity="Wallabag\AnnotationBundle\Entity\Annotation", mappedBy="entry", cascade={"persist", "remove"})
126 * @ORM\JoinTable 156 * @ORM\JoinTable
127 * 157 *
@@ -150,11 +180,11 @@ class Entry
150 /** 180 /**
151 * @var int 181 * @var int
152 * 182 *
153 * @ORM\Column(name="reading_time", type="integer", nullable=true) 183 * @ORM\Column(name="reading_time", type="integer", nullable=false)
154 * 184 *
155 * @Groups({"entries_for_user", "export_all"}) 185 * @Groups({"entries_for_user", "export_all"})
156 */ 186 */
157 private $readingTime; 187 private $readingTime = 0;
158 188
159 /** 189 /**
160 * @var string 190 * @var string
@@ -175,22 +205,22 @@ class Entry
175 private $previewPicture; 205 private $previewPicture;
176 206
177 /** 207 /**
178 * @var bool 208 * @var string
179 * 209 *
180 * @ORM\Column(name="is_public", type="boolean", nullable=true, options={"default" = false}) 210 * @ORM\Column(name="http_status", type="string", length=3, nullable=true)
181 * 211 *
182 * @Groups({"export_all"}) 212 * @Groups({"entries_for_user", "export_all"})
183 */ 213 */
184 private $isPublic; 214 private $httpStatus;
185 215
186 /** 216 /**
187 * @var string 217 * @var array
188 * 218 *
189 * @ORM\Column(name="http_status", type="string", length=3, nullable=true) 219 * @ORM\Column(name="headers", type="array", nullable=true)
190 * 220 *
191 * @Groups({"entries_for_user", "export_all"}) 221 * @Groups({"entries_for_user", "export_all"})
192 */ 222 */
193 private $httpStatus; 223 private $headers;
194 224
195 /** 225 /**
196 * @Exclude 226 * @Exclude
@@ -455,16 +485,41 @@ class Entry
455 } 485 }
456 486
457 /** 487 /**
458 * @ORM\PrePersist 488 * @return \DateTime|null
459 * @ORM\PreUpdate
460 */ 489 */
461 public function timestamps() 490 public function getStarredAt()
462 { 491 {
463 if (is_null($this->createdAt)) { 492 return $this->starredAt;
464 $this->createdAt = new \DateTime(); 493 }
494
495 /**
496 * @param \DateTime|null $starredAt
497 *
498 * @return Entry
499 */
500 public function setStarredAt($starredAt = null)
501 {
502 $this->starredAt = $starredAt;
503
504 return $this;
505 }
506
507 /**
508 * update isStarred and starred_at fields.
509 *
510 * @param bool $isStarred
511 *
512 * @return Entry
513 */
514 public function updateStar($isStarred = false)
515 {
516 $this->setStarred($isStarred);
517 $this->setStarredAt(null);
518 if ($this->isStarred()) {
519 $this->setStarredAt(new \DateTime());
465 } 520 }
466 521
467 $this->updatedAt = new \DateTime(); 522 return $this;
468 } 523 }
469 524
470 /** 525 /**
@@ -532,23 +587,7 @@ class Entry
532 } 587 }
533 588
534 /** 589 /**
535 * @return bool 590 * @return ArrayCollection
536 */
537 public function isPublic()
538 {
539 return $this->isPublic;
540 }
541
542 /**
543 * @param bool $isPublic
544 */
545 public function setIsPublic($isPublic)
546 {
547 $this->isPublic = $isPublic;
548 }
549
550 /**
551 * @return ArrayCollection<Tag>
552 */ 591 */
553 public function getTags() 592 public function getTags()
554 { 593 {
@@ -591,6 +630,11 @@ class Entry
591 $tag->addEntry($this); 630 $tag->addEntry($this);
592 } 631 }
593 632
633 /**
634 * Remove the given tag from the entry (if the tag is associated).
635 *
636 * @param Tag $tag
637 */
594 public function removeTag(Tag $tag) 638 public function removeTag(Tag $tag)
595 { 639 {
596 if (!$this->tags->contains($tag)) { 640 if (!$this->tags->contains($tag)) {
@@ -602,6 +646,17 @@ class Entry
602 } 646 }
603 647
604 /** 648 /**
649 * Remove all assigned tags from the entry.
650 */
651 public function removeAllTags()
652 {
653 foreach ($this->tags as $tag) {
654 $this->tags->removeElement($tag);
655 $tag->removeEntry($this);
656 }
657 }
658
659 /**
605 * Set previewPicture. 660 * Set previewPicture.
606 * 661 *
607 * @param string $previewPicture 662 * @param string $previewPicture
@@ -683,7 +738,22 @@ class Entry
683 } 738 }
684 739
685 /** 740 /**
686 * @return int 741 * Used in the entries filter so it's more explicit for the end user than the uid.
742 * Also used in the API.
743 *
744 * @VirtualProperty
745 * @SerializedName("is_public")
746 * @Groups({"entries_for_user"})
747 *
748 * @return bool
749 */
750 public function isPublic()
751 {
752 return null !== $this->uid;
753 }
754
755 /**
756 * @return string
687 */ 757 */
688 public function getHttpStatus() 758 public function getHttpStatus()
689 { 759 {
@@ -691,7 +761,7 @@ class Entry
691 } 761 }
692 762
693 /** 763 /**
694 * @param int $httpStatus 764 * @param string $httpStatus
695 * 765 *
696 * @return Entry 766 * @return Entry
697 */ 767 */
@@ -701,4 +771,64 @@ class Entry
701 771
702 return $this; 772 return $this;
703 } 773 }
774
775 /**
776 * @return \Datetime
777 */
778 public function getPublishedAt()
779 {
780 return $this->publishedAt;
781 }
782
783 /**
784 * @param \Datetime $publishedAt
785 *
786 * @return Entry
787 */
788 public function setPublishedAt(\Datetime $publishedAt)
789 {
790 $this->publishedAt = $publishedAt;
791
792 return $this;
793 }
794
795 /**
796 * @return array
797 */
798 public function getPublishedBy()
799 {
800 return $this->publishedBy;
801 }
802
803 /**
804 * @param array $publishedBy
805 *
806 * @return Entry
807 */
808 public function setPublishedBy($publishedBy)
809 {
810 $this->publishedBy = $publishedBy;
811
812 return $this;
813 }
814
815 /**
816 * @return array
817 */
818 public function getHeaders()
819 {
820 return $this->headers;
821 }
822
823 /**
824 * @param array $headers
825 *
826 * @return Entry
827 */
828 public function setHeaders($headers)
829 {
830 $this->headers = $headers;
831
832 return $this;
833 }
704} 834}