]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace Wallabag\CoreBundle\Entity; | |
4 | ||
5 | use Doctrine\Common\Collections\ArrayCollection; | |
6 | use Doctrine\ORM\Mapping as ORM; | |
7 | use Symfony\Component\Validator\Constraints as Assert; | |
8 | use Hateoas\Configuration\Annotation as Hateoas; | |
9 | use JMS\Serializer\Annotation\Groups; | |
10 | use JMS\Serializer\Annotation\XmlRoot; | |
11 | use Wallabag\UserBundle\Entity\User; | |
12 | ||
13 | /** | |
14 | * Entry. | |
15 | * | |
16 | * @XmlRoot("entry") | |
17 | * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\EntryRepository") | |
18 | * @ORM\Table(name="`entry`") | |
19 | * @ORM\HasLifecycleCallbacks() | |
20 | * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())") | |
21 | */ | |
22 | class Entry | |
23 | { | |
24 | /** @Serializer\XmlAttribute */ | |
25 | /** | |
26 | * @var int | |
27 | * | |
28 | * @ORM\Column(name="id", type="integer") | |
29 | * @ORM\Id | |
30 | * @ORM\GeneratedValue(strategy="AUTO") | |
31 | * | |
32 | * @Groups({"entries_for_user", "export_all"}) | |
33 | */ | |
34 | private $id; | |
35 | ||
36 | /** | |
37 | * @var string | |
38 | * | |
39 | * @ORM\Column(name="title", type="text", nullable=true) | |
40 | * | |
41 | * @Groups({"entries_for_user", "export_all"}) | |
42 | */ | |
43 | private $title; | |
44 | ||
45 | /** | |
46 | * @var string | |
47 | * | |
48 | * @Assert\NotBlank() | |
49 | * @ORM\Column(name="url", type="text", nullable=true) | |
50 | * | |
51 | * @Groups({"entries_for_user", "export_all"}) | |
52 | */ | |
53 | private $url; | |
54 | ||
55 | /** | |
56 | * @var bool | |
57 | * | |
58 | * @ORM\Column(name="is_archived", type="boolean") | |
59 | * | |
60 | * @Groups({"entries_for_user", "export_all"}) | |
61 | */ | |
62 | private $isArchived = false; | |
63 | ||
64 | /** | |
65 | * @var bool | |
66 | * | |
67 | * @ORM\Column(name="is_starred", type="boolean") | |
68 | * | |
69 | * @Groups({"entries_for_user", "export_all"}) | |
70 | */ | |
71 | private $isStarred = false; | |
72 | ||
73 | /** | |
74 | * @var string | |
75 | * | |
76 | * @ORM\Column(name="content", type="text", nullable=true) | |
77 | * | |
78 | * @Groups({"entries_for_user", "export_all"}) | |
79 | */ | |
80 | private $content; | |
81 | ||
82 | /** | |
83 | * @var date | |
84 | * | |
85 | * @ORM\Column(name="created_at", type="datetime") | |
86 | * | |
87 | * @Groups({"export_all"}) | |
88 | */ | |
89 | private $createdAt; | |
90 | ||
91 | /** | |
92 | * @var date | |
93 | * | |
94 | * @ORM\Column(name="updated_at", type="datetime") | |
95 | * | |
96 | * @Groups({"export_all"}) | |
97 | */ | |
98 | private $updatedAt; | |
99 | ||
100 | /** | |
101 | * @var string | |
102 | * | |
103 | * @ORM\Column(name="comments", type="text", nullable=true) | |
104 | * | |
105 | * @Groups({"export_all"}) | |
106 | */ | |
107 | private $comments; | |
108 | ||
109 | /** | |
110 | * @var string | |
111 | * | |
112 | * @ORM\Column(name="mimetype", type="text", nullable=true) | |
113 | * | |
114 | * @Groups({"entries_for_user", "export_all"}) | |
115 | */ | |
116 | private $mimetype; | |
117 | ||
118 | /** | |
119 | * @var string | |
120 | * | |
121 | * @ORM\Column(name="language", type="text", nullable=true) | |
122 | * | |
123 | * @Groups({"entries_for_user", "export_all"}) | |
124 | */ | |
125 | private $language; | |
126 | ||
127 | /** | |
128 | * @var int | |
129 | * | |
130 | * @ORM\Column(name="reading_time", type="integer", nullable=true) | |
131 | * | |
132 | * @Groups({"entries_for_user", "export_all"}) | |
133 | */ | |
134 | private $readingTime; | |
135 | ||
136 | /** | |
137 | * @var string | |
138 | * | |
139 | * @ORM\Column(name="domain_name", type="text", nullable=true) | |
140 | * | |
141 | * @Groups({"entries_for_user", "export_all"}) | |
142 | */ | |
143 | private $domainName; | |
144 | ||
145 | /** | |
146 | * @var string | |
147 | * | |
148 | * @ORM\Column(name="preview_picture", type="text", nullable=true) | |
149 | * | |
150 | * @Groups({"entries_for_user", "export_all"}) | |
151 | */ | |
152 | private $previewPicture; | |
153 | ||
154 | /** | |
155 | * @var bool | |
156 | * | |
157 | * @ORM\Column(name="is_public", type="boolean", nullable=true, options={"default" = false}) | |
158 | * | |
159 | * @Groups({"export_all"}) | |
160 | */ | |
161 | private $isPublic; | |
162 | ||
163 | /** | |
164 | * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="entries") | |
165 | * | |
166 | * @Groups({"export_all"}) | |
167 | */ | |
168 | private $user; | |
169 | ||
170 | /** | |
171 | * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"}) | |
172 | * @ORM\JoinTable | |
173 | * | |
174 | * @Groups({"entries_for_user", "export_all"}) | |
175 | */ | |
176 | private $tags; | |
177 | ||
178 | /* | |
179 | * @param User $user | |
180 | */ | |
181 | public function __construct(\Wallabag\UserBundle\Entity\User $user) | |
182 | { | |
183 | $this->user = $user; | |
184 | $this->tags = new ArrayCollection(); | |
185 | } | |
186 | ||
187 | /** | |
188 | * Get id. | |
189 | * | |
190 | * @return int | |
191 | */ | |
192 | public function getId() | |
193 | { | |
194 | return $this->id; | |
195 | } | |
196 | ||
197 | /** | |
198 | * Set title. | |
199 | * | |
200 | * @param string $title | |
201 | * | |
202 | * @return Entry | |
203 | */ | |
204 | public function setTitle($title) | |
205 | { | |
206 | $this->title = $title; | |
207 | ||
208 | return $this; | |
209 | } | |
210 | ||
211 | /** | |
212 | * Get title. | |
213 | * | |
214 | * @return string | |
215 | */ | |
216 | public function getTitle() | |
217 | { | |
218 | return $this->title; | |
219 | } | |
220 | ||
221 | /** | |
222 | * Set url. | |
223 | * | |
224 | * @param string $url | |
225 | * | |
226 | * @return Entry | |
227 | */ | |
228 | public function setUrl($url) | |
229 | { | |
230 | $this->url = $url; | |
231 | ||
232 | return $this; | |
233 | } | |
234 | ||
235 | /** | |
236 | * Get url. | |
237 | * | |
238 | * @return string | |
239 | */ | |
240 | public function getUrl() | |
241 | { | |
242 | return $this->url; | |
243 | } | |
244 | ||
245 | /** | |
246 | * Set isArchived. | |
247 | * | |
248 | * @param string $isArchived | |
249 | * | |
250 | * @return Entry | |
251 | */ | |
252 | public function setArchived($isArchived) | |
253 | { | |
254 | $this->isArchived = $isArchived; | |
255 | ||
256 | return $this; | |
257 | } | |
258 | ||
259 | /** | |
260 | * Get isArchived. | |
261 | * | |
262 | * @return string | |
263 | */ | |
264 | public function isArchived() | |
265 | { | |
266 | return $this->isArchived; | |
267 | } | |
268 | ||
269 | public function toggleArchive() | |
270 | { | |
271 | $this->isArchived = $this->isArchived() ^ 1; | |
272 | ||
273 | return $this; | |
274 | } | |
275 | ||
276 | /** | |
277 | * Set isStarred. | |
278 | * | |
279 | * @param string $isStarred | |
280 | * | |
281 | * @return Entry | |
282 | */ | |
283 | public function setStarred($isStarred) | |
284 | { | |
285 | $this->isStarred = $isStarred; | |
286 | ||
287 | return $this; | |
288 | } | |
289 | ||
290 | /** | |
291 | * Get isStarred. | |
292 | * | |
293 | * @return string | |
294 | */ | |
295 | public function isStarred() | |
296 | { | |
297 | return $this->isStarred; | |
298 | } | |
299 | ||
300 | public function toggleStar() | |
301 | { | |
302 | $this->isStarred = $this->isStarred() ^ 1; | |
303 | ||
304 | return $this; | |
305 | } | |
306 | ||
307 | /** | |
308 | * Set content. | |
309 | * | |
310 | * @param string $content | |
311 | * | |
312 | * @return Entry | |
313 | */ | |
314 | public function setContent($content) | |
315 | { | |
316 | $this->content = $content; | |
317 | ||
318 | return $this; | |
319 | } | |
320 | ||
321 | /** | |
322 | * Get content. | |
323 | * | |
324 | * @return string | |
325 | */ | |
326 | public function getContent() | |
327 | { | |
328 | return $this->content; | |
329 | } | |
330 | ||
331 | /** | |
332 | * @return User | |
333 | */ | |
334 | public function getUser() | |
335 | { | |
336 | return $this->user; | |
337 | } | |
338 | ||
339 | /** | |
340 | * @return string | |
341 | */ | |
342 | public function getCreatedAt() | |
343 | { | |
344 | return $this->createdAt; | |
345 | } | |
346 | ||
347 | /** | |
348 | * @return string | |
349 | */ | |
350 | public function getUpdatedAt() | |
351 | { | |
352 | return $this->updatedAt; | |
353 | } | |
354 | ||
355 | /** | |
356 | * @ORM\PrePersist | |
357 | * @ORM\PreUpdate | |
358 | */ | |
359 | public function timestamps() | |
360 | { | |
361 | if (is_null($this->createdAt)) { | |
362 | $this->createdAt = new \DateTime(); | |
363 | } | |
364 | ||
365 | $this->updatedAt = new \DateTime(); | |
366 | } | |
367 | ||
368 | /** | |
369 | * @return string | |
370 | */ | |
371 | public function getComments() | |
372 | { | |
373 | return $this->comments; | |
374 | } | |
375 | ||
376 | /** | |
377 | * @param string $comments | |
378 | */ | |
379 | public function setComments($comments) | |
380 | { | |
381 | $this->comments = $comments; | |
382 | } | |
383 | ||
384 | /** | |
385 | * @return string | |
386 | */ | |
387 | public function getMimetype() | |
388 | { | |
389 | return $this->mimetype; | |
390 | } | |
391 | ||
392 | /** | |
393 | * @param string $mimetype | |
394 | */ | |
395 | public function setMimetype($mimetype) | |
396 | { | |
397 | $this->mimetype = $mimetype; | |
398 | } | |
399 | ||
400 | /** | |
401 | * @return int | |
402 | */ | |
403 | public function getReadingTime() | |
404 | { | |
405 | return $this->readingTime; | |
406 | } | |
407 | ||
408 | /** | |
409 | * @param int $readingTime | |
410 | */ | |
411 | public function setReadingTime($readingTime) | |
412 | { | |
413 | $this->readingTime = $readingTime; | |
414 | } | |
415 | ||
416 | /** | |
417 | * @return string | |
418 | */ | |
419 | public function getDomainName() | |
420 | { | |
421 | return $this->domainName; | |
422 | } | |
423 | ||
424 | /** | |
425 | * @param string $domainName | |
426 | */ | |
427 | public function setDomainName($domainName) | |
428 | { | |
429 | $this->domainName = $domainName; | |
430 | } | |
431 | ||
432 | /** | |
433 | * @return bool | |
434 | */ | |
435 | public function isPublic() | |
436 | { | |
437 | return $this->isPublic; | |
438 | } | |
439 | ||
440 | /** | |
441 | * @param bool $isPublic | |
442 | */ | |
443 | public function setIsPublic($isPublic) | |
444 | { | |
445 | $this->isPublic = $isPublic; | |
446 | } | |
447 | ||
448 | /** | |
449 | * @return ArrayCollection<Tag> | |
450 | */ | |
451 | public function getTags() | |
452 | { | |
453 | return $this->tags; | |
454 | } | |
455 | ||
456 | /** | |
457 | * @param Tag $tag | |
458 | */ | |
459 | public function addTag(Tag $tag) | |
460 | { | |
461 | $this->tags[] = $tag; | |
462 | $tag->addEntry($this); | |
463 | } | |
464 | ||
465 | public function removeTag(Tag $tag) | |
466 | { | |
467 | $this->tags->removeElement($tag); | |
468 | } | |
469 | ||
470 | /** | |
471 | * Set previewPicture. | |
472 | * | |
473 | * @param string $previewPicture | |
474 | * | |
475 | * @return Entry | |
476 | */ | |
477 | public function setPreviewPicture($previewPicture) | |
478 | { | |
479 | $this->previewPicture = $previewPicture; | |
480 | ||
481 | return $this; | |
482 | } | |
483 | ||
484 | /** | |
485 | * Get previewPicture. | |
486 | * | |
487 | * @return string | |
488 | */ | |
489 | public function getPreviewPicture() | |
490 | { | |
491 | return $this->previewPicture; | |
492 | } | |
493 | ||
494 | /** | |
495 | * Set language. | |
496 | * | |
497 | * @param string $language | |
498 | * | |
499 | * @return Entry | |
500 | */ | |
501 | public function setLanguage($language) | |
502 | { | |
503 | $this->language = $language; | |
504 | ||
505 | return $this; | |
506 | } | |
507 | ||
508 | /** | |
509 | * Get language. | |
510 | * | |
511 | * @return string | |
512 | */ | |
513 | public function getLanguage() | |
514 | { | |
515 | return $this->language; | |
516 | } | |
517 | } |