]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/CoreBundle/Entity/Entry.php
manage assets through npm
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Entity / Entry.php
CommitLineData
9d50517c
NL
1<?php
2
ad4d1caa 3namespace Wallabag\CoreBundle\Entity;
9d50517c 4
0a018fe0 5use Doctrine\Common\Collections\ArrayCollection;
9d50517c 6use Doctrine\ORM\Mapping as ORM;
0f006880 7use Hateoas\Configuration\Annotation as Hateoas;
268e9e72 8use JMS\Serializer\Annotation\Groups;
0f006880 9use JMS\Serializer\Annotation\XmlRoot;
7d1fdab2
TC
10use JMS\Serializer\Annotation\Exclude;
11use JMS\Serializer\Annotation\VirtualProperty;
12use JMS\Serializer\Annotation\SerializedName;
619cc453 13use Symfony\Component\Validator\Constraints as Assert;
1210dae1 14use Wallabag\UserBundle\Entity\User;
4dc87223 15use 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 26class 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 /**
5ecdfcd0
TC
180 * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"})
181 * @ORM\JoinTable(
182 * name="entry_tag",
183 * joinColumns={
184 * @ORM\JoinColumn(name="entry_id", referencedColumnName="id")
185 * },
186 * inverseJoinColumns={
187 * @ORM\JoinColumn(name="tag_id", referencedColumnName="id")
188 * }
189 * )
5b7da076
TC
190 *
191 * @Groups({"entries_for_user", "export_all"})
0a018fe0
NL
192 */
193 private $tags;
194
5f09650e
NL
195 /*
196 * @param User $user
197 */
5d6f6f56 198 public function __construct(User $user)
5f09650e
NL
199 {
200 $this->user = $user;
0a018fe0 201 $this->tags = new ArrayCollection();
5f09650e
NL
202 }
203
9d50517c 204 /**
4346a860 205 * Get id.
9d50517c 206 *
4346a860 207 * @return int
9d50517c
NL
208 */
209 public function getId()
210 {
211 return $this->id;
212 }
213
214 /**
4346a860
JB
215 * Set title.
216 *
217 * @param string $title
9d50517c 218 *
be463487 219 * @return Entry
9d50517c
NL
220 */
221 public function setTitle($title)
222 {
223 $this->title = $title;
224
225 return $this;
226 }
227
228 /**
4346a860 229 * Get title.
9d50517c 230 *
7df80cb3 231 * @return string
9d50517c
NL
232 */
233 public function getTitle()
234 {
235 return $this->title;
236 }
237
238 /**
4346a860
JB
239 * Set url.
240 *
241 * @param string $url
9d50517c 242 *
be463487 243 * @return Entry
9d50517c
NL
244 */
245 public function setUrl($url)
246 {
247 $this->url = $url;
248
249 return $this;
250 }
251
252 /**
4346a860 253 * Get url.
9d50517c 254 *
7df80cb3 255 * @return string
9d50517c
NL
256 */
257 public function getUrl()
258 {
259 return $this->url;
260 }
261
262 /**
4346a860
JB
263 * Set isArchived.
264 *
8eedc8cf 265 * @param bool $isArchived
9d50517c 266 *
be463487 267 * @return Entry
9d50517c 268 */
905ae369 269 public function setArchived($isArchived)
9d50517c 270 {
905ae369 271 $this->isArchived = $isArchived;
9d50517c
NL
272
273 return $this;
274 }
275
276 /**
4346a860 277 * Get isArchived.
9d50517c 278 *
8eedc8cf 279 * @return bool
9d50517c 280 */
905ae369 281 public function isArchived()
9d50517c 282 {
905ae369 283 return $this->isArchived;
9d50517c
NL
284 }
285
189ef634
TC
286 /**
287 * @VirtualProperty
288 * @SerializedName("is_archived")
289 * @Groups({"entries_for_user", "export_all"})
290 */
291 public function is_Archived()
292 {
293 return (int) $this->isArchived();
294 }
295
163eae0b
NL
296 public function toggleArchive()
297 {
905ae369 298 $this->isArchived = $this->isArchived() ^ 1;
7df80cb3 299
163eae0b
NL
300 return $this;
301 }
302
9d50517c 303 /**
4346a860
JB
304 * Set isStarred.
305 *
8eedc8cf 306 * @param bool $isStarred
9d50517c 307 *
be463487 308 * @return Entry
9d50517c 309 */
905ae369 310 public function setStarred($isStarred)
9d50517c 311 {
905ae369 312 $this->isStarred = $isStarred;
9d50517c
NL
313
314 return $this;
315 }
316
317 /**
4346a860 318 * Get isStarred.
9d50517c 319 *
8eedc8cf 320 * @return bool
9d50517c 321 */
905ae369 322 public function isStarred()
9d50517c 323 {
905ae369 324 return $this->isStarred;
9d50517c
NL
325 }
326
189ef634
TC
327 /**
328 * @VirtualProperty
329 * @SerializedName("is_starred")
330 * @Groups({"entries_for_user", "export_all"})
331 */
332 public function is_Starred()
333 {
334 return (int) $this->isStarred();
335 }
336
163eae0b
NL
337 public function toggleStar()
338 {
905ae369 339 $this->isStarred = $this->isStarred() ^ 1;
163eae0b
NL
340
341 return $this;
342 }
343
9d50517c 344 /**
4346a860
JB
345 * Set content.
346 *
347 * @param string $content
9d50517c 348 *
be463487 349 * @return Entry
9d50517c
NL
350 */
351 public function setContent($content)
352 {
353 $this->content = $content;
354
355 return $this;
356 }
357
358 /**
4346a860 359 * Get content.
9d50517c 360 *
7df80cb3 361 * @return string
9d50517c
NL
362 */
363 public function getContent()
364 {
365 return $this->content;
366 }
367
368 /**
5f09650e 369 * @return User
9d50517c 370 */
5f09650e 371 public function getUser()
9d50517c 372 {
5f09650e 373 return $this->user;
9d50517c 374 }
42a90646 375
7d1fdab2
TC
376 /**
377 * @VirtualProperty
378 * @SerializedName("user_name")
379 */
380 public function getUserName()
381 {
382 return $this->user->getUserName();
383 }
384
385 /**
386 * @VirtualProperty
387 * @SerializedName("user_email")
388 */
389 public function getUserEmail()
390 {
391 return $this->user->getEmail();
392 }
393
394 /**
395 * @VirtualProperty
396 * @SerializedName("user_id")
397 */
398 public function getUserId()
399 {
400 return $this->user->getId();
401 }
402
34d15eb4 403 /**
2f69eb4a 404 * @return string
34d15eb4
NL
405 */
406 public function getCreatedAt()
407 {
408 return $this->createdAt;
409 }
410
34d15eb4
NL
411 /**
412 * @return string
413 */
414 public function getUpdatedAt()
415 {
416 return $this->updatedAt;
417 }
418
419 /**
be463487 420 * @ORM\PrePersist
34d15eb4
NL
421 * @ORM\PreUpdate
422 */
be463487 423 public function timestamps()
34d15eb4 424 {
be463487
NL
425 if (is_null($this->createdAt)) {
426 $this->createdAt = new \DateTime();
427 }
428
34d15eb4
NL
429 $this->updatedAt = new \DateTime();
430 }
431
432 /**
4dc87223 433 * @return ArrayCollection<Annotation>
34d15eb4 434 */
4dc87223 435 public function getAnnotations()
34d15eb4 436 {
4dc87223 437 return $this->annotations;
34d15eb4
NL
438 }
439
440 /**
4dc87223 441 * @param Annotation $annotation
34d15eb4 442 */
4dc87223 443 public function setAnnotation(Annotation $annotation)
34d15eb4 444 {
4dc87223 445 $this->annotations[] = $annotation;
34d15eb4
NL
446 }
447
448 /**
449 * @return string
450 */
451 public function getMimetype()
452 {
453 return $this->mimetype;
454 }
455
456 /**
457 * @param string $mimetype
458 */
459 public function setMimetype($mimetype)
460 {
461 $this->mimetype = $mimetype;
462 }
463
464 /**
465 * @return int
466 */
467 public function getReadingTime()
468 {
469 return $this->readingTime;
470 }
471
472 /**
473 * @param int $readingTime
474 */
475 public function setReadingTime($readingTime)
476 {
477 $this->readingTime = $readingTime;
478 }
479
480 /**
481 * @return string
482 */
483 public function getDomainName()
484 {
485 return $this->domainName;
486 }
487
488 /**
489 * @param string $domainName
490 */
491 public function setDomainName($domainName)
492 {
493 $this->domainName = $domainName;
494 }
495
496 /**
4346a860 497 * @return bool
34d15eb4 498 */
2c093b03 499 public function isPublic()
34d15eb4
NL
500 {
501 return $this->isPublic;
502 }
503
504 /**
4346a860 505 * @param bool $isPublic
34d15eb4 506 */
82d6d9cb 507 public function setIsPublic($isPublic)
34d15eb4
NL
508 {
509 $this->isPublic = $isPublic;
510 }
0a018fe0
NL
511
512 /**
513 * @return ArrayCollection<Tag>
514 */
515 public function getTags()
516 {
517 return $this->tags;
518 }
519
520 /**
521 * @param Tag $tag
522 */
523 public function addTag(Tag $tag)
524 {
625acf33
KG
525 if ($this->tags->contains($tag)) {
526 return;
527 }
528
fc031e57
JB
529 // check if tag already exist but has not yet be persisted
530 // it seems that the previous condition with `contains()` doesn't check that case
531 foreach ($this->tags as $existingTag) {
fc732227 532 if ($existingTag->getLabel() === $tag->getLabel()) {
fc031e57
JB
533 return;
534 }
535 }
536
5ecdfcd0 537 $this->tags->add($tag);
46bbd8d3 538 $tag->addEntry($this);
0a018fe0 539 }
092ca707
NL
540
541 public function removeTag(Tag $tag)
542 {
5ecdfcd0
TC
543 if (!$this->tags->contains($tag)) {
544 return;
545 }
546
092ca707 547 $this->tags->removeElement($tag);
5ecdfcd0 548 $tag->removeEntry($this);
092ca707 549 }
fad31615
JB
550
551 /**
a1413a3d 552 * Set previewPicture.
fad31615
JB
553 *
554 * @param string $previewPicture
555 *
556 * @return Entry
557 */
558 public function setPreviewPicture($previewPicture)
559 {
560 $this->previewPicture = $previewPicture;
561
562 return $this;
563 }
564
565 /**
a1413a3d 566 * Get previewPicture.
fad31615
JB
567 *
568 * @return string
569 */
570 public function getPreviewPicture()
571 {
572 return $this->previewPicture;
573 }
98f0929f
JB
574
575 /**
576 * Set language.
577 *
578 * @param string $language
579 *
580 * @return Entry
581 */
582 public function setLanguage($language)
583 {
584 $this->language = $language;
585
586 return $this;
587 }
588
589 /**
590 * Get language.
591 *
592 * @return string
593 */
594 public function getLanguage()
595 {
596 return $this->language;
597 }
9d50517c 598}