]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/AnnotationBundle/Entity/Annotation.php
Better encoding of the URI for the bookmarklet
[github/wallabag/wallabag.git] / src / Wallabag / AnnotationBundle / Entity / Annotation.php
1 <?php
2
3 namespace Wallabag\AnnotationBundle\Entity;
4
5 use Doctrine\ORM\Mapping as ORM;
6 use JMS\Serializer\Annotation\Exclude;
7 use JMS\Serializer\Annotation\ExclusionPolicy;
8 use JMS\Serializer\Annotation\Groups;
9 use JMS\Serializer\Annotation\SerializedName;
10 use JMS\Serializer\Annotation\VirtualProperty;
11 use Symfony\Component\Validator\Constraints as Assert;
12 use Wallabag\CoreBundle\Entity\Entry;
13 use Wallabag\CoreBundle\Helper\EntityTimestampsTrait;
14 use Wallabag\UserBundle\Entity\User;
15
16 /**
17 * Annotation.
18 *
19 * @ORM\Table(name="annotation")
20 * @ORM\Entity(repositoryClass="Wallabag\AnnotationBundle\Repository\AnnotationRepository")
21 * @ORM\HasLifecycleCallbacks()
22 * @ExclusionPolicy("none")
23 */
24 class Annotation
25 {
26 use EntityTimestampsTrait;
27
28 /**
29 * @var int
30 *
31 * @ORM\Column(name="id", type="integer")
32 * @ORM\Id
33 * @ORM\GeneratedValue(strategy="AUTO")
34 */
35 private $id;
36
37 /**
38 * @var string
39 *
40 * @ORM\Column(name="text", type="text")
41 *
42 * @Groups({"entries_for_user", "export_all"})
43 */
44 private $text;
45
46 /**
47 * @var \DateTime
48 *
49 * @ORM\Column(name="created_at", type="datetime")
50 */
51 private $createdAt;
52
53 /**
54 * @var \DateTime
55 *
56 * @ORM\Column(name="updated_at", type="datetime")
57 */
58 private $updatedAt;
59
60 /**
61 * @var string
62 *
63 * @Assert\Length(
64 * max = 10000,
65 * maxMessage = "validator.quote_length_too_high"
66 * )
67 * @ORM\Column(name="quote", type="text")
68 *
69 * @Groups({"entries_for_user", "export_all"})
70 */
71 private $quote;
72
73 /**
74 * @var array
75 *
76 * @ORM\Column(name="ranges", type="array")
77 *
78 * @Groups({"entries_for_user", "export_all"})
79 */
80 private $ranges;
81
82 /**
83 * @Exclude
84 *
85 * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User")
86 */
87 private $user;
88
89 /**
90 * @Exclude
91 *
92 * @ORM\ManyToOne(targetEntity="Wallabag\CoreBundle\Entity\Entry", inversedBy="annotations")
93 * @ORM\JoinColumn(name="entry_id", referencedColumnName="id", onDelete="cascade")
94 */
95 private $entry;
96
97 /*
98 * @param User $user
99 */
100 public function __construct(User $user)
101 {
102 $this->user = $user;
103 }
104
105 /**
106 * Get id.
107 *
108 * @return int
109 */
110 public function getId()
111 {
112 return $this->id;
113 }
114
115 /**
116 * Set text.
117 *
118 * @param string $text
119 *
120 * @return Annotation
121 */
122 public function setText($text)
123 {
124 $this->text = $text;
125
126 return $this;
127 }
128
129 /**
130 * Get text.
131 *
132 * @return string
133 */
134 public function getText()
135 {
136 return $this->text;
137 }
138
139 /**
140 * Get created.
141 *
142 * @return \DateTime
143 */
144 public function getCreatedAt()
145 {
146 return $this->createdAt;
147 }
148
149 /**
150 * Get updated.
151 *
152 * @return \DateTime
153 */
154 public function getUpdatedAt()
155 {
156 return $this->updatedAt;
157 }
158
159 /**
160 * Get quote.
161 *
162 * @return string
163 */
164 public function getQuote()
165 {
166 return $this->quote;
167 }
168
169 /**
170 * Set quote.
171 *
172 * @param string $quote
173 *
174 * @return Annotation
175 */
176 public function setQuote($quote)
177 {
178 $this->quote = $quote;
179
180 return $this;
181 }
182
183 /**
184 * Get ranges.
185 *
186 * @return array
187 */
188 public function getRanges()
189 {
190 return $this->ranges;
191 }
192
193 /**
194 * Set ranges.
195 *
196 * @param array $ranges
197 *
198 * @return Annotation
199 */
200 public function setRanges($ranges)
201 {
202 $this->ranges = $ranges;
203
204 return $this;
205 }
206
207 /**
208 * Set user.
209 *
210 * @param User $user
211 *
212 * @return Annotation
213 */
214 public function setUser($user)
215 {
216 $this->user = $user;
217
218 return $this;
219 }
220
221 /**
222 * Get user.
223 *
224 * @return User
225 */
226 public function getUser()
227 {
228 return $this->user;
229 }
230
231 /**
232 * @VirtualProperty
233 * @SerializedName("user")
234 */
235 public function getUserName()
236 {
237 return $this->user->getName();
238 }
239
240 /**
241 * Set entry.
242 *
243 * @param Entry $entry
244 *
245 * @return Annotation
246 */
247 public function setEntry($entry)
248 {
249 $this->entry = $entry;
250 $entry->setAnnotation($this);
251
252 return $this;
253 }
254
255 /**
256 * Get entry.
257 *
258 * @return Entry
259 */
260 public function getEntry()
261 {
262 return $this->entry;
263 }
264
265 /**
266 * @VirtualProperty
267 * @SerializedName("annotator_schema_version")
268 */
269 public function getVersion()
270 {
271 return 'v1.0';
272 }
273 }