]>
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; |
b84a8055 | 7 | use Symfony\Component\Validator\Constraints as Assert; |
0f006880 | 8 | use Hateoas\Configuration\Annotation as Hateoas; |
268e9e72 | 9 | use JMS\Serializer\Annotation\Groups; |
0f006880 | 10 | use JMS\Serializer\Annotation\XmlRoot; |
1210dae1 | 11 | use Wallabag\UserBundle\Entity\User; |
9d50517c NL |
12 | |
13 | /** | |
4346a860 | 14 | * Entry. |
9d50517c | 15 | * |
0f006880 | 16 | * @XmlRoot("entry") |
be463487 | 17 | * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\EntryRepository") |
bd0f3d32 | 18 | * @ORM\Table(name="`entry`") |
34d15eb4 | 19 | * @ORM\HasLifecycleCallbacks() |
0f006880 | 20 | * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())") |
9d50517c | 21 | */ |
be463487 | 22 | class Entry |
9d50517c | 23 | { |
0f006880 | 24 | /** @Serializer\XmlAttribute */ |
9d50517c | 25 | /** |
4346a860 | 26 | * @var int |
9d50517c | 27 | * |
be463487 | 28 | * @ORM\Column(name="id", type="integer") |
9d50517c | 29 | * @ORM\Id |
34d15eb4 | 30 | * @ORM\GeneratedValue(strategy="AUTO") |
5b7da076 TC |
31 | * |
32 | * @Groups({"entries_for_user", "export_all"}) | |
9d50517c | 33 | */ |
be463487 | 34 | private $id; |
9d50517c NL |
35 | |
36 | /** | |
37 | * @var string | |
38 | * | |
39 | * @ORM\Column(name="title", type="text", nullable=true) | |
5b7da076 TC |
40 | * |
41 | * @Groups({"entries_for_user", "export_all"}) | |
9d50517c NL |
42 | */ |
43 | private $title; | |
44 | ||
45 | /** | |
46 | * @var string | |
47 | * | |
b84a8055 | 48 | * @Assert\NotBlank() |
9d50517c | 49 | * @ORM\Column(name="url", type="text", nullable=true) |
5b7da076 TC |
50 | * |
51 | * @Groups({"entries_for_user", "export_all"}) | |
9d50517c NL |
52 | */ |
53 | private $url; | |
54 | ||
55 | /** | |
4346a860 | 56 | * @var bool |
9d50517c | 57 | * |
be463487 | 58 | * @ORM\Column(name="is_archived", type="boolean") |
5b7da076 TC |
59 | * |
60 | * @Groups({"entries_for_user", "export_all"}) | |
9d50517c | 61 | */ |
905ae369 | 62 | private $isArchived = false; |
9d50517c NL |
63 | |
64 | /** | |
4346a860 | 65 | * @var bool |
9d50517c | 66 | * |
be463487 | 67 | * @ORM\Column(name="is_starred", type="boolean") |
5b7da076 TC |
68 | * |
69 | * @Groups({"entries_for_user", "export_all"}) | |
9d50517c | 70 | */ |
905ae369 | 71 | private $isStarred = false; |
9d50517c | 72 | |
9d50517c NL |
73 | /** |
74 | * @var string | |
75 | * | |
eacaf7f8 | 76 | * @ORM\Column(name="content", type="text", nullable=true) |
5b7da076 TC |
77 | * |
78 | * @Groups({"entries_for_user", "export_all"}) | |
9d50517c | 79 | */ |
eacaf7f8 | 80 | private $content; |
9d50517c | 81 | |
34d15eb4 NL |
82 | /** |
83 | * @var date | |
84 | * | |
be463487 | 85 | * @ORM\Column(name="created_at", type="datetime") |
5b7da076 TC |
86 | * |
87 | * @Groups({"export_all"}) | |
34d15eb4 NL |
88 | */ |
89 | private $createdAt; | |
90 | ||
91 | /** | |
92 | * @var date | |
93 | * | |
be463487 | 94 | * @ORM\Column(name="updated_at", type="datetime") |
5b7da076 TC |
95 | * |
96 | * @Groups({"export_all"}) | |
34d15eb4 NL |
97 | */ |
98 | private $updatedAt; | |
99 | ||
34d15eb4 NL |
100 | /** |
101 | * @var string | |
102 | * | |
103 | * @ORM\Column(name="comments", type="text", nullable=true) | |
5b7da076 TC |
104 | * |
105 | * @Groups({"export_all"}) | |
34d15eb4 NL |
106 | */ |
107 | private $comments; | |
108 | ||
109 | /** | |
110 | * @var string | |
111 | * | |
112 | * @ORM\Column(name="mimetype", type="text", nullable=true) | |
5b7da076 TC |
113 | * |
114 | * @Groups({"entries_for_user", "export_all"}) | |
34d15eb4 NL |
115 | */ |
116 | private $mimetype; | |
117 | ||
98f0929f JB |
118 | /** |
119 | * @var string | |
120 | * | |
121 | * @ORM\Column(name="language", type="text", nullable=true) | |
5b7da076 TC |
122 | * |
123 | * @Groups({"entries_for_user", "export_all"}) | |
98f0929f JB |
124 | */ |
125 | private $language; | |
126 | ||
34d15eb4 | 127 | /** |
4346a860 | 128 | * @var int |
34d15eb4 | 129 | * |
26864574 | 130 | * @ORM\Column(name="reading_time", type="integer", nullable=true) |
5b7da076 TC |
131 | * |
132 | * @Groups({"entries_for_user", "export_all"}) | |
34d15eb4 NL |
133 | */ |
134 | private $readingTime; | |
135 | ||
136 | /** | |
137 | * @var string | |
138 | * | |
139 | * @ORM\Column(name="domain_name", type="text", nullable=true) | |
5b7da076 TC |
140 | * |
141 | * @Groups({"entries_for_user", "export_all"}) | |
34d15eb4 NL |
142 | */ |
143 | private $domainName; | |
144 | ||
fad31615 JB |
145 | /** |
146 | * @var string | |
147 | * | |
148 | * @ORM\Column(name="preview_picture", type="text", nullable=true) | |
5b7da076 TC |
149 | * |
150 | * @Groups({"entries_for_user", "export_all"}) | |
fad31615 JB |
151 | */ |
152 | private $previewPicture; | |
153 | ||
34d15eb4 | 154 | /** |
4346a860 | 155 | * @var bool |
34d15eb4 NL |
156 | * |
157 | * @ORM\Column(name="is_public", type="boolean", nullable=true, options={"default" = false}) | |
5b7da076 TC |
158 | * |
159 | * @Groups({"export_all"}) | |
34d15eb4 NL |
160 | */ |
161 | private $isPublic; | |
162 | ||
5f09650e | 163 | /** |
1210dae1 | 164 | * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="entries") |
5b7da076 TC |
165 | * |
166 | * @Groups({"export_all"}) | |
5f09650e NL |
167 | */ |
168 | private $user; | |
169 | ||
0a018fe0 | 170 | /** |
46bbd8d3 | 171 | * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"}) |
164bd801 | 172 | * @ORM\JoinTable |
5b7da076 TC |
173 | * |
174 | * @Groups({"entries_for_user", "export_all"}) | |
0a018fe0 NL |
175 | */ |
176 | private $tags; | |
177 | ||
5f09650e NL |
178 | /* |
179 | * @param User $user | |
180 | */ | |
0a878469 | 181 | public function __construct(\Wallabag\UserBundle\Entity\User $user) |
5f09650e NL |
182 | { |
183 | $this->user = $user; | |
0a018fe0 | 184 | $this->tags = new ArrayCollection(); |
5f09650e NL |
185 | } |
186 | ||
9d50517c | 187 | /** |
4346a860 | 188 | * Get id. |
9d50517c | 189 | * |
4346a860 | 190 | * @return int |
9d50517c NL |
191 | */ |
192 | public function getId() | |
193 | { | |
194 | return $this->id; | |
195 | } | |
196 | ||
197 | /** | |
4346a860 JB |
198 | * Set title. |
199 | * | |
200 | * @param string $title | |
9d50517c | 201 | * |
be463487 | 202 | * @return Entry |
9d50517c NL |
203 | */ |
204 | public function setTitle($title) | |
205 | { | |
206 | $this->title = $title; | |
207 | ||
208 | return $this; | |
209 | } | |
210 | ||
211 | /** | |
4346a860 | 212 | * Get title. |
9d50517c | 213 | * |
7df80cb3 | 214 | * @return string |
9d50517c NL |
215 | */ |
216 | public function getTitle() | |
217 | { | |
218 | return $this->title; | |
219 | } | |
220 | ||
221 | /** | |
4346a860 JB |
222 | * Set url. |
223 | * | |
224 | * @param string $url | |
9d50517c | 225 | * |
be463487 | 226 | * @return Entry |
9d50517c NL |
227 | */ |
228 | public function setUrl($url) | |
229 | { | |
230 | $this->url = $url; | |
231 | ||
232 | return $this; | |
233 | } | |
234 | ||
235 | /** | |
4346a860 | 236 | * Get url. |
9d50517c | 237 | * |
7df80cb3 | 238 | * @return string |
9d50517c NL |
239 | */ |
240 | public function getUrl() | |
241 | { | |
242 | return $this->url; | |
243 | } | |
244 | ||
245 | /** | |
4346a860 JB |
246 | * Set isArchived. |
247 | * | |
8eedc8cf | 248 | * @param bool $isArchived |
9d50517c | 249 | * |
be463487 | 250 | * @return Entry |
9d50517c | 251 | */ |
905ae369 | 252 | public function setArchived($isArchived) |
9d50517c | 253 | { |
905ae369 | 254 | $this->isArchived = $isArchived; |
9d50517c NL |
255 | |
256 | return $this; | |
257 | } | |
258 | ||
259 | /** | |
4346a860 | 260 | * Get isArchived. |
9d50517c | 261 | * |
8eedc8cf | 262 | * @return bool |
9d50517c | 263 | */ |
905ae369 | 264 | public function isArchived() |
9d50517c | 265 | { |
905ae369 | 266 | return $this->isArchived; |
9d50517c NL |
267 | } |
268 | ||
163eae0b NL |
269 | public function toggleArchive() |
270 | { | |
905ae369 | 271 | $this->isArchived = $this->isArchived() ^ 1; |
7df80cb3 | 272 | |
163eae0b NL |
273 | return $this; |
274 | } | |
275 | ||
9d50517c | 276 | /** |
4346a860 JB |
277 | * Set isStarred. |
278 | * | |
8eedc8cf | 279 | * @param bool $isStarred |
9d50517c | 280 | * |
be463487 | 281 | * @return Entry |
9d50517c | 282 | */ |
905ae369 | 283 | public function setStarred($isStarred) |
9d50517c | 284 | { |
905ae369 | 285 | $this->isStarred = $isStarred; |
9d50517c NL |
286 | |
287 | return $this; | |
288 | } | |
289 | ||
290 | /** | |
4346a860 | 291 | * Get isStarred. |
9d50517c | 292 | * |
8eedc8cf | 293 | * @return bool |
9d50517c | 294 | */ |
905ae369 | 295 | public function isStarred() |
9d50517c | 296 | { |
905ae369 | 297 | return $this->isStarred; |
9d50517c NL |
298 | } |
299 | ||
163eae0b NL |
300 | public function toggleStar() |
301 | { | |
905ae369 | 302 | $this->isStarred = $this->isStarred() ^ 1; |
163eae0b NL |
303 | |
304 | return $this; | |
305 | } | |
306 | ||
9d50517c | 307 | /** |
4346a860 JB |
308 | * Set content. |
309 | * | |
310 | * @param string $content | |
9d50517c | 311 | * |
be463487 | 312 | * @return Entry |
9d50517c NL |
313 | */ |
314 | public function setContent($content) | |
315 | { | |
316 | $this->content = $content; | |
317 | ||
318 | return $this; | |
319 | } | |
320 | ||
321 | /** | |
4346a860 | 322 | * Get content. |
9d50517c | 323 | * |
7df80cb3 | 324 | * @return string |
9d50517c NL |
325 | */ |
326 | public function getContent() | |
327 | { | |
328 | return $this->content; | |
329 | } | |
330 | ||
331 | /** | |
5f09650e | 332 | * @return User |
9d50517c | 333 | */ |
5f09650e | 334 | public function getUser() |
9d50517c | 335 | { |
5f09650e | 336 | return $this->user; |
9d50517c | 337 | } |
42a90646 | 338 | |
34d15eb4 | 339 | /** |
2f69eb4a | 340 | * @return string |
34d15eb4 NL |
341 | */ |
342 | public function getCreatedAt() | |
343 | { | |
344 | return $this->createdAt; | |
345 | } | |
346 | ||
34d15eb4 NL |
347 | /** |
348 | * @return string | |
349 | */ | |
350 | public function getUpdatedAt() | |
351 | { | |
352 | return $this->updatedAt; | |
353 | } | |
354 | ||
355 | /** | |
be463487 | 356 | * @ORM\PrePersist |
34d15eb4 NL |
357 | * @ORM\PreUpdate |
358 | */ | |
be463487 | 359 | public function timestamps() |
34d15eb4 | 360 | { |
be463487 NL |
361 | if (is_null($this->createdAt)) { |
362 | $this->createdAt = new \DateTime(); | |
363 | } | |
364 | ||
34d15eb4 NL |
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 | /** | |
4346a860 | 433 | * @return bool |
34d15eb4 | 434 | */ |
2c093b03 | 435 | public function isPublic() |
34d15eb4 NL |
436 | { |
437 | return $this->isPublic; | |
438 | } | |
439 | ||
440 | /** | |
4346a860 | 441 | * @param bool $isPublic |
34d15eb4 | 442 | */ |
82d6d9cb | 443 | public function setIsPublic($isPublic) |
34d15eb4 NL |
444 | { |
445 | $this->isPublic = $isPublic; | |
446 | } | |
0a018fe0 NL |
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 | { | |
625acf33 KG |
461 | if ($this->tags->contains($tag)) { |
462 | return; | |
463 | } | |
464 | ||
fc031e57 JB |
465 | // check if tag already exist but has not yet be persisted |
466 | // it seems that the previous condition with `contains()` doesn't check that case | |
467 | foreach ($this->tags as $existingTag) { | |
fc732227 | 468 | if ($existingTag->getLabel() === $tag->getLabel()) { |
fc031e57 JB |
469 | return; |
470 | } | |
471 | } | |
472 | ||
0a018fe0 | 473 | $this->tags[] = $tag; |
46bbd8d3 | 474 | $tag->addEntry($this); |
0a018fe0 | 475 | } |
092ca707 NL |
476 | |
477 | public function removeTag(Tag $tag) | |
478 | { | |
479 | $this->tags->removeElement($tag); | |
480 | } | |
fad31615 JB |
481 | |
482 | /** | |
a1413a3d | 483 | * Set previewPicture. |
fad31615 JB |
484 | * |
485 | * @param string $previewPicture | |
486 | * | |
487 | * @return Entry | |
488 | */ | |
489 | public function setPreviewPicture($previewPicture) | |
490 | { | |
491 | $this->previewPicture = $previewPicture; | |
492 | ||
493 | return $this; | |
494 | } | |
495 | ||
496 | /** | |
a1413a3d | 497 | * Get previewPicture. |
fad31615 JB |
498 | * |
499 | * @return string | |
500 | */ | |
501 | public function getPreviewPicture() | |
502 | { | |
503 | return $this->previewPicture; | |
504 | } | |
98f0929f JB |
505 | |
506 | /** | |
507 | * Set language. | |
508 | * | |
509 | * @param string $language | |
510 | * | |
511 | * @return Entry | |
512 | */ | |
513 | public function setLanguage($language) | |
514 | { | |
515 | $this->language = $language; | |
516 | ||
517 | return $this; | |
518 | } | |
519 | ||
520 | /** | |
521 | * Get language. | |
522 | * | |
523 | * @return string | |
524 | */ | |
525 | public function getLanguage() | |
526 | { | |
527 | return $this->language; | |
528 | } | |
9d50517c | 529 | } |