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