diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Entity/Entry.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Entity/Entry.php | 169 |
1 files changed, 126 insertions, 43 deletions
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index 7276b437..61d01bdc 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php | |||
@@ -5,14 +5,15 @@ namespace Wallabag\CoreBundle\Entity; | |||
5 | use Doctrine\Common\Collections\ArrayCollection; | 5 | use Doctrine\Common\Collections\ArrayCollection; |
6 | use Doctrine\ORM\Mapping as ORM; | 6 | use Doctrine\ORM\Mapping as ORM; |
7 | use Hateoas\Configuration\Annotation as Hateoas; | 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; | 8 | use JMS\Serializer\Annotation\Exclude; |
11 | use JMS\Serializer\Annotation\VirtualProperty; | 9 | use JMS\Serializer\Annotation\Groups; |
12 | use JMS\Serializer\Annotation\SerializedName; | 10 | use JMS\Serializer\Annotation\SerializedName; |
11 | use JMS\Serializer\Annotation\VirtualProperty; | ||
12 | use JMS\Serializer\Annotation\XmlRoot; | ||
13 | use Symfony\Component\Validator\Constraints as Assert; | 13 | use Symfony\Component\Validator\Constraints as Assert; |
14 | use Wallabag\UserBundle\Entity\User; | ||
15 | use Wallabag\AnnotationBundle\Entity\Annotation; | 14 | use Wallabag\AnnotationBundle\Entity\Annotation; |
15 | use Wallabag\CoreBundle\Helper\EntityTimestampsTrait; | ||
16 | use Wallabag\UserBundle\Entity\User; | ||
16 | 17 | ||
17 | /** | 18 | /** |
18 | * Entry. | 19 | * Entry. |
@@ -32,6 +33,8 @@ use Wallabag\AnnotationBundle\Entity\Annotation; | |||
32 | */ | 33 | */ |
33 | class Entry | 34 | class Entry |
34 | { | 35 | { |
36 | use EntityTimestampsTrait; | ||
37 | |||
35 | /** @Serializer\XmlAttribute */ | 38 | /** @Serializer\XmlAttribute */ |
36 | /** | 39 | /** |
37 | * @var int | 40 | * @var int |
@@ -122,6 +125,24 @@ 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 | /** | ||
125 | * @ORM\OneToMany(targetEntity="Wallabag\AnnotationBundle\Entity\Annotation", mappedBy="entry", cascade={"persist", "remove"}) | 146 | * @ORM\OneToMany(targetEntity="Wallabag\AnnotationBundle\Entity\Annotation", mappedBy="entry", cascade={"persist", "remove"}) |
126 | * @ORM\JoinTable | 147 | * @ORM\JoinTable |
127 | * | 148 | * |
@@ -175,22 +196,22 @@ class Entry | |||
175 | private $previewPicture; | 196 | private $previewPicture; |
176 | 197 | ||
177 | /** | 198 | /** |
178 | * @var bool | 199 | * @var string |
179 | * | 200 | * |
180 | * @ORM\Column(name="is_public", type="boolean", nullable=true, options={"default" = false}) | 201 | * @ORM\Column(name="http_status", type="string", length=3, nullable=true) |
181 | * | 202 | * |
182 | * @Groups({"export_all"}) | 203 | * @Groups({"entries_for_user", "export_all"}) |
183 | */ | 204 | */ |
184 | private $isPublic; | 205 | private $httpStatus; |
185 | 206 | ||
186 | /** | 207 | /** |
187 | * @var string | 208 | * @var array |
188 | * | 209 | * |
189 | * @ORM\Column(name="http_status", type="string", length=3, nullable=true) | 210 | * @ORM\Column(name="headers", type="array", nullable=true) |
190 | * | 211 | * |
191 | * @Groups({"entries_for_user", "export_all"}) | 212 | * @Groups({"entries_for_user", "export_all"}) |
192 | */ | 213 | */ |
193 | private $httpStatus; | 214 | private $headers; |
194 | 215 | ||
195 | /** | 216 | /** |
196 | * @Exclude | 217 | * @Exclude |
@@ -455,19 +476,6 @@ class Entry | |||
455 | } | 476 | } |
456 | 477 | ||
457 | /** | 478 | /** |
458 | * @ORM\PrePersist | ||
459 | * @ORM\PreUpdate | ||
460 | */ | ||
461 | public function timestamps() | ||
462 | { | ||
463 | if (is_null($this->createdAt)) { | ||
464 | $this->createdAt = new \DateTime(); | ||
465 | } | ||
466 | |||
467 | $this->updatedAt = new \DateTime(); | ||
468 | } | ||
469 | |||
470 | /** | ||
471 | * @return ArrayCollection<Annotation> | 479 | * @return ArrayCollection<Annotation> |
472 | */ | 480 | */ |
473 | public function getAnnotations() | 481 | public function getAnnotations() |
@@ -532,23 +540,7 @@ class Entry | |||
532 | } | 540 | } |
533 | 541 | ||
534 | /** | 542 | /** |
535 | * @return bool | 543 | * @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 | */ | 544 | */ |
553 | public function getTags() | 545 | public function getTags() |
554 | { | 546 | { |
@@ -591,6 +583,11 @@ class Entry | |||
591 | $tag->addEntry($this); | 583 | $tag->addEntry($this); |
592 | } | 584 | } |
593 | 585 | ||
586 | /** | ||
587 | * Remove the given tag from the entry (if the tag is associated). | ||
588 | * | ||
589 | * @param Tag $tag | ||
590 | */ | ||
594 | public function removeTag(Tag $tag) | 591 | public function removeTag(Tag $tag) |
595 | { | 592 | { |
596 | if (!$this->tags->contains($tag)) { | 593 | if (!$this->tags->contains($tag)) { |
@@ -602,6 +599,17 @@ class Entry | |||
602 | } | 599 | } |
603 | 600 | ||
604 | /** | 601 | /** |
602 | * Remove all assigned tags from the entry. | ||
603 | */ | ||
604 | public function removeAllTags() | ||
605 | { | ||
606 | foreach ($this->tags as $tag) { | ||
607 | $this->tags->removeElement($tag); | ||
608 | $tag->removeEntry($this); | ||
609 | } | ||
610 | } | ||
611 | |||
612 | /** | ||
605 | * Set previewPicture. | 613 | * Set previewPicture. |
606 | * | 614 | * |
607 | * @param string $previewPicture | 615 | * @param string $previewPicture |
@@ -683,7 +691,22 @@ class Entry | |||
683 | } | 691 | } |
684 | 692 | ||
685 | /** | 693 | /** |
686 | * @return int | 694 | * Used in the entries filter so it's more explicit for the end user than the uid. |
695 | * Also used in the API. | ||
696 | * | ||
697 | * @VirtualProperty | ||
698 | * @SerializedName("is_public") | ||
699 | * @Groups({"entries_for_user"}) | ||
700 | * | ||
701 | * @return bool | ||
702 | */ | ||
703 | public function isPublic() | ||
704 | { | ||
705 | return null !== $this->uid; | ||
706 | } | ||
707 | |||
708 | /** | ||
709 | * @return string | ||
687 | */ | 710 | */ |
688 | public function getHttpStatus() | 711 | public function getHttpStatus() |
689 | { | 712 | { |
@@ -691,7 +714,7 @@ class Entry | |||
691 | } | 714 | } |
692 | 715 | ||
693 | /** | 716 | /** |
694 | * @param int $httpStatus | 717 | * @param string $httpStatus |
695 | * | 718 | * |
696 | * @return Entry | 719 | * @return Entry |
697 | */ | 720 | */ |
@@ -701,4 +724,64 @@ class Entry | |||
701 | 724 | ||
702 | return $this; | 725 | return $this; |
703 | } | 726 | } |
727 | |||
728 | /** | ||
729 | * @return \Datetime | ||
730 | */ | ||
731 | public function getPublishedAt() | ||
732 | { | ||
733 | return $this->publishedAt; | ||
734 | } | ||
735 | |||
736 | /** | ||
737 | * @param \Datetime $publishedAt | ||
738 | * | ||
739 | * @return Entry | ||
740 | */ | ||
741 | public function setPublishedAt(\Datetime $publishedAt) | ||
742 | { | ||
743 | $this->publishedAt = $publishedAt; | ||
744 | |||
745 | return $this; | ||
746 | } | ||
747 | |||
748 | /** | ||
749 | * @return array | ||
750 | */ | ||
751 | public function getPublishedBy() | ||
752 | { | ||
753 | return $this->publishedBy; | ||
754 | } | ||
755 | |||
756 | /** | ||
757 | * @param array $publishedBy | ||
758 | * | ||
759 | * @return Entry | ||
760 | */ | ||
761 | public function setPublishedBy($publishedBy) | ||
762 | { | ||
763 | $this->publishedBy = $publishedBy; | ||
764 | |||
765 | return $this; | ||
766 | } | ||
767 | |||
768 | /** | ||
769 | * @return array | ||
770 | */ | ||
771 | public function getHeaders() | ||
772 | { | ||
773 | return $this->headers; | ||
774 | } | ||
775 | |||
776 | /** | ||
777 | * @param array $headers | ||
778 | * | ||
779 | * @return Entry | ||
780 | */ | ||
781 | public function setHeaders($headers) | ||
782 | { | ||
783 | $this->headers = $headers; | ||
784 | |||
785 | return $this; | ||
786 | } | ||
704 | } | 787 | } |