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