]>
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; |
7d1fdab2 | 8 | use JMS\Serializer\Annotation\Exclude; |
f808b016 | 9 | use JMS\Serializer\Annotation\Groups; |
7d1fdab2 | 10 | use JMS\Serializer\Annotation\SerializedName; |
f808b016 JB |
11 | use JMS\Serializer\Annotation\VirtualProperty; |
12 | use JMS\Serializer\Annotation\XmlRoot; | |
619cc453 | 13 | use Symfony\Component\Validator\Constraints as Assert; |
4dc87223 | 14 | use Wallabag\AnnotationBundle\Entity\Annotation; |
927c9e79 | 15 | use Wallabag\CoreBundle\Helper\EntityTimestampsTrait; |
f808b016 | 16 | use Wallabag\UserBundle\Entity\User; |
9d50517c NL |
17 | |
18 | /** | |
4346a860 | 19 | * Entry. |
9d50517c | 20 | * |
0f006880 | 21 | * @XmlRoot("entry") |
be463487 | 22 | * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\EntryRepository") |
7e9c1d65 JB |
23 | * @ORM\Table( |
24 | * name="`entry`", | |
25 | * options={"collate"="utf8mb4_unicode_ci", "charset"="utf8mb4"}, | |
81375151 NL |
26 | * indexes={ |
27 | * @ORM\Index(name="created_at", columns={"created_at"}), | |
7239082a | 28 | * @ORM\Index(name="uid", columns={"uid"}) |
81375151 | 29 | * } |
7e9c1d65 | 30 | * ) |
34d15eb4 | 31 | * @ORM\HasLifecycleCallbacks() |
0f006880 | 32 | * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())") |
9d50517c | 33 | */ |
be463487 | 34 | class Entry |
9d50517c | 35 | { |
927c9e79 JB |
36 | use EntityTimestampsTrait; |
37 | ||
0f006880 | 38 | /** @Serializer\XmlAttribute */ |
9d50517c | 39 | /** |
4346a860 | 40 | * @var int |
9d50517c | 41 | * |
be463487 | 42 | * @ORM\Column(name="id", type="integer") |
9d50517c | 43 | * @ORM\Id |
34d15eb4 | 44 | * @ORM\GeneratedValue(strategy="AUTO") |
5b7da076 TC |
45 | * |
46 | * @Groups({"entries_for_user", "export_all"}) | |
9d50517c | 47 | */ |
be463487 | 48 | private $id; |
9d50517c | 49 | |
f3d0cb91 | 50 | /** |
78b3c31d | 51 | * @var string |
f3d0cb91 | 52 | * |
7239082a | 53 | * @ORM\Column(name="uid", type="string", length=23, nullable=true) |
f3d0cb91 NL |
54 | * |
55 | * @Groups({"entries_for_user", "export_all"}) | |
56 | */ | |
7239082a | 57 | private $uid; |
f3d0cb91 | 58 | |
9d50517c NL |
59 | /** |
60 | * @var string | |
61 | * | |
62 | * @ORM\Column(name="title", type="text", nullable=true) | |
5b7da076 TC |
63 | * |
64 | * @Groups({"entries_for_user", "export_all"}) | |
9d50517c NL |
65 | */ |
66 | private $title; | |
67 | ||
c1c0f099 NL |
68 | /** |
69 | * @var string | |
70 | * | |
71 | * @ORM\Column(name="given_url", type="text", nullable=true) | |
72 | * | |
73 | * @Groups({"entries_for_user", "export_all"}) | |
74 | */ | |
75 | private $givenUrl; | |
76 | ||
9d50517c NL |
77 | /** |
78 | * @var string | |
79 | * | |
b84a8055 | 80 | * @Assert\NotBlank() |
9d50517c | 81 | * @ORM\Column(name="url", type="text", nullable=true) |
5b7da076 TC |
82 | * |
83 | * @Groups({"entries_for_user", "export_all"}) | |
9d50517c NL |
84 | */ |
85 | private $url; | |
86 | ||
87 | /** | |
4346a860 | 88 | * @var bool |
9d50517c | 89 | * |
189ef634 TC |
90 | * @Exclude |
91 | * | |
be463487 | 92 | * @ORM\Column(name="is_archived", type="boolean") |
5b7da076 TC |
93 | * |
94 | * @Groups({"entries_for_user", "export_all"}) | |
9d50517c | 95 | */ |
905ae369 | 96 | private $isArchived = false; |
9d50517c NL |
97 | |
98 | /** | |
4346a860 | 99 | * @var bool |
9d50517c | 100 | * |
189ef634 TC |
101 | * @Exclude |
102 | * | |
be463487 | 103 | * @ORM\Column(name="is_starred", type="boolean") |
5b7da076 TC |
104 | * |
105 | * @Groups({"entries_for_user", "export_all"}) | |
9d50517c | 106 | */ |
905ae369 | 107 | private $isStarred = false; |
9d50517c | 108 | |
9d50517c NL |
109 | /** |
110 | * @var string | |
111 | * | |
eacaf7f8 | 112 | * @ORM\Column(name="content", type="text", nullable=true) |
5b7da076 TC |
113 | * |
114 | * @Groups({"entries_for_user", "export_all"}) | |
9d50517c | 115 | */ |
eacaf7f8 | 116 | private $content; |
9d50517c | 117 | |
34d15eb4 | 118 | /** |
8664069e | 119 | * @var \DateTime |
34d15eb4 | 120 | * |
be463487 | 121 | * @ORM\Column(name="created_at", type="datetime") |
5b7da076 | 122 | * |
9401696f | 123 | * @Groups({"entries_for_user", "export_all"}) |
34d15eb4 NL |
124 | */ |
125 | private $createdAt; | |
126 | ||
127 | /** | |
8664069e | 128 | * @var \DateTime |
34d15eb4 | 129 | * |
be463487 | 130 | * @ORM\Column(name="updated_at", type="datetime") |
5b7da076 | 131 | * |
9401696f | 132 | * @Groups({"entries_for_user", "export_all"}) |
34d15eb4 NL |
133 | */ |
134 | private $updatedAt; | |
135 | ||
5e9009ce NL |
136 | /** |
137 | * @var \DateTime | |
138 | * | |
139 | * @ORM\Column(name="published_at", type="datetime", nullable=true) | |
140 | * | |
141 | * @Groups({"entries_for_user", "export_all"}) | |
142 | */ | |
143 | private $publishedAt; | |
144 | ||
7b0b3622 NL |
145 | /** |
146 | * @var array | |
147 | * | |
1517d577 | 148 | * @ORM\Column(name="published_by", type="array", nullable=true) |
7b0b3622 NL |
149 | * |
150 | * @Groups({"entries_for_user", "export_all"}) | |
151 | */ | |
152 | private $publishedBy; | |
153 | ||
a991c46e F |
154 | /** |
155 | * @var \DateTime | |
156 | * | |
157 | * @ORM\Column(name="starred_at", type="datetime", nullable=true) | |
158 | * | |
159 | * @Groups({"entries_for_user", "export_all"}) | |
160 | */ | |
161 | private $starredAt = null; | |
162 | ||
34d15eb4 | 163 | /** |
4dc87223 | 164 | * @ORM\OneToMany(targetEntity="Wallabag\AnnotationBundle\Entity\Annotation", mappedBy="entry", cascade={"persist", "remove"}) |
f38e03dc | 165 | * @ORM\JoinTable |
5b7da076 | 166 | * |
f38e03dc | 167 | * @Groups({"entries_for_user", "export_all"}) |
34d15eb4 | 168 | */ |
4dc87223 | 169 | private $annotations; |
34d15eb4 NL |
170 | |
171 | /** | |
172 | * @var string | |
173 | * | |
174 | * @ORM\Column(name="mimetype", type="text", nullable=true) | |
5b7da076 TC |
175 | * |
176 | * @Groups({"entries_for_user", "export_all"}) | |
34d15eb4 NL |
177 | */ |
178 | private $mimetype; | |
179 | ||
98f0929f JB |
180 | /** |
181 | * @var string | |
182 | * | |
183 | * @ORM\Column(name="language", type="text", nullable=true) | |
5b7da076 TC |
184 | * |
185 | * @Groups({"entries_for_user", "export_all"}) | |
98f0929f JB |
186 | */ |
187 | private $language; | |
188 | ||
34d15eb4 | 189 | /** |
4346a860 | 190 | * @var int |
34d15eb4 | 191 | * |
88bac4a3 | 192 | * @ORM\Column(name="reading_time", type="integer", nullable=false) |
5b7da076 TC |
193 | * |
194 | * @Groups({"entries_for_user", "export_all"}) | |
34d15eb4 | 195 | */ |
88bac4a3 | 196 | private $readingTime = 0; |
34d15eb4 NL |
197 | |
198 | /** | |
199 | * @var string | |
200 | * | |
201 | * @ORM\Column(name="domain_name", type="text", nullable=true) | |
5b7da076 TC |
202 | * |
203 | * @Groups({"entries_for_user", "export_all"}) | |
34d15eb4 NL |
204 | */ |
205 | private $domainName; | |
206 | ||
fad31615 JB |
207 | /** |
208 | * @var string | |
209 | * | |
210 | * @ORM\Column(name="preview_picture", type="text", nullable=true) | |
5b7da076 TC |
211 | * |
212 | * @Groups({"entries_for_user", "export_all"}) | |
fad31615 JB |
213 | */ |
214 | private $previewPicture; | |
215 | ||
10b35097 | 216 | /** |
e10e6ab3 | 217 | * @var string |
10b35097 | 218 | * |
3ef75cc4 | 219 | * @ORM\Column(name="http_status", type="string", length=3, nullable=true) |
10b35097 NL |
220 | * |
221 | * @Groups({"entries_for_user", "export_all"}) | |
222 | */ | |
223 | private $httpStatus; | |
224 | ||
dda6a6ad NL |
225 | /** |
226 | * @var array | |
227 | * | |
1517d577 | 228 | * @ORM\Column(name="headers", type="array", nullable=true) |
dda6a6ad NL |
229 | * |
230 | * @Groups({"entries_for_user", "export_all"}) | |
231 | */ | |
232 | private $headers; | |
233 | ||
5f09650e | 234 | /** |
7d1fdab2 TC |
235 | * @Exclude |
236 | * | |
1210dae1 | 237 | * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="entries") |
5b7da076 TC |
238 | * |
239 | * @Groups({"export_all"}) | |
5f09650e NL |
240 | */ |
241 | private $user; | |
242 | ||
0a018fe0 | 243 | /** |
af95c09c | 244 | * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"}) |
e42b13bc JB |
245 | * @ORM\JoinTable( |
246 | * name="entry_tag", | |
247 | * joinColumns={ | |
206bade5 | 248 | * @ORM\JoinColumn(name="entry_id", referencedColumnName="id", onDelete="cascade") |
e42b13bc JB |
249 | * }, |
250 | * inverseJoinColumns={ | |
206bade5 | 251 | * @ORM\JoinColumn(name="tag_id", referencedColumnName="id", onDelete="cascade") |
e42b13bc JB |
252 | * } |
253 | * ) | |
0a018fe0 NL |
254 | */ |
255 | private $tags; | |
256 | ||
e0ef1a1c KD |
257 | /** |
258 | * @var string | |
259 | * | |
260 | * @ORM\Column(name="origin_url", type="text", nullable=true) | |
261 | * | |
262 | * @Groups({"entries_for_user", "export_all"}) | |
263 | */ | |
264 | private $originUrl; | |
265 | ||
5f09650e NL |
266 | /* |
267 | * @param User $user | |
268 | */ | |
5d6f6f56 | 269 | public function __construct(User $user) |
5f09650e NL |
270 | { |
271 | $this->user = $user; | |
0a018fe0 | 272 | $this->tags = new ArrayCollection(); |
5f09650e NL |
273 | } |
274 | ||
9d50517c | 275 | /** |
4346a860 | 276 | * Get id. |
9d50517c | 277 | * |
4346a860 | 278 | * @return int |
9d50517c NL |
279 | */ |
280 | public function getId() | |
281 | { | |
282 | return $this->id; | |
283 | } | |
284 | ||
285 | /** | |
4346a860 JB |
286 | * Set title. |
287 | * | |
288 | * @param string $title | |
9d50517c | 289 | * |
be463487 | 290 | * @return Entry |
9d50517c NL |
291 | */ |
292 | public function setTitle($title) | |
293 | { | |
294 | $this->title = $title; | |
295 | ||
296 | return $this; | |
297 | } | |
298 | ||
299 | /** | |
4346a860 | 300 | * Get title. |
9d50517c | 301 | * |
7df80cb3 | 302 | * @return string |
9d50517c NL |
303 | */ |
304 | public function getTitle() | |
305 | { | |
306 | return $this->title; | |
307 | } | |
308 | ||
c1c0f099 NL |
309 | /** |
310 | * Set given url. | |
311 | * | |
312 | * @param string $givenUrl | |
313 | * | |
314 | * @return Entry | |
315 | */ | |
316 | public function setGivenUrl($givenUrl) | |
317 | { | |
318 | $this->givenUrl = $givenUrl; | |
319 | ||
320 | return $this; | |
321 | } | |
322 | ||
323 | /** | |
324 | * Get given Url. | |
325 | * | |
326 | * @return string | |
327 | */ | |
328 | public function getGivenUrl() | |
329 | { | |
330 | return $this->givenUrl; | |
331 | } | |
332 | ||
9d50517c | 333 | /** |
4346a860 JB |
334 | * Set url. |
335 | * | |
336 | * @param string $url | |
9d50517c | 337 | * |
be463487 | 338 | * @return Entry |
9d50517c NL |
339 | */ |
340 | public function setUrl($url) | |
341 | { | |
342 | $this->url = $url; | |
343 | ||
344 | return $this; | |
345 | } | |
346 | ||
347 | /** | |
4346a860 | 348 | * Get url. |
9d50517c | 349 | * |
7df80cb3 | 350 | * @return string |
9d50517c NL |
351 | */ |
352 | public function getUrl() | |
353 | { | |
354 | return $this->url; | |
355 | } | |
356 | ||
357 | /** | |
4346a860 JB |
358 | * Set isArchived. |
359 | * | |
8eedc8cf | 360 | * @param bool $isArchived |
9d50517c | 361 | * |
be463487 | 362 | * @return Entry |
9d50517c | 363 | */ |
905ae369 | 364 | public function setArchived($isArchived) |
9d50517c | 365 | { |
905ae369 | 366 | $this->isArchived = $isArchived; |
9d50517c NL |
367 | |
368 | return $this; | |
369 | } | |
370 | ||
371 | /** | |
4346a860 | 372 | * Get isArchived. |
9d50517c | 373 | * |
8eedc8cf | 374 | * @return bool |
9d50517c | 375 | */ |
905ae369 | 376 | public function isArchived() |
9d50517c | 377 | { |
905ae369 | 378 | return $this->isArchived; |
9d50517c NL |
379 | } |
380 | ||
189ef634 TC |
381 | /** |
382 | * @VirtualProperty | |
383 | * @SerializedName("is_archived") | |
384 | * @Groups({"entries_for_user", "export_all"}) | |
385 | */ | |
386 | public function is_Archived() | |
387 | { | |
388 | return (int) $this->isArchived(); | |
389 | } | |
390 | ||
163eae0b NL |
391 | public function toggleArchive() |
392 | { | |
905ae369 | 393 | $this->isArchived = $this->isArchived() ^ 1; |
7df80cb3 | 394 | |
163eae0b NL |
395 | return $this; |
396 | } | |
397 | ||
9d50517c | 398 | /** |
4346a860 JB |
399 | * Set isStarred. |
400 | * | |
8eedc8cf | 401 | * @param bool $isStarred |
9d50517c | 402 | * |
be463487 | 403 | * @return Entry |
9d50517c | 404 | */ |
905ae369 | 405 | public function setStarred($isStarred) |
9d50517c | 406 | { |
905ae369 | 407 | $this->isStarred = $isStarred; |
9d50517c NL |
408 | |
409 | return $this; | |
410 | } | |
411 | ||
412 | /** | |
4346a860 | 413 | * Get isStarred. |
9d50517c | 414 | * |
8eedc8cf | 415 | * @return bool |
9d50517c | 416 | */ |
905ae369 | 417 | public function isStarred() |
9d50517c | 418 | { |
905ae369 | 419 | return $this->isStarred; |
9d50517c NL |
420 | } |
421 | ||
189ef634 TC |
422 | /** |
423 | * @VirtualProperty | |
424 | * @SerializedName("is_starred") | |
425 | * @Groups({"entries_for_user", "export_all"}) | |
426 | */ | |
427 | public function is_Starred() | |
428 | { | |
429 | return (int) $this->isStarred(); | |
430 | } | |
431 | ||
163eae0b NL |
432 | public function toggleStar() |
433 | { | |
905ae369 | 434 | $this->isStarred = $this->isStarred() ^ 1; |
163eae0b NL |
435 | |
436 | return $this; | |
437 | } | |
438 | ||
9d50517c | 439 | /** |
4346a860 JB |
440 | * Set content. |
441 | * | |
442 | * @param string $content | |
9d50517c | 443 | * |
be463487 | 444 | * @return Entry |
9d50517c NL |
445 | */ |
446 | public function setContent($content) | |
447 | { | |
448 | $this->content = $content; | |
449 | ||
450 | return $this; | |
451 | } | |
452 | ||
453 | /** | |
4346a860 | 454 | * Get content. |
9d50517c | 455 | * |
7df80cb3 | 456 | * @return string |
9d50517c NL |
457 | */ |
458 | public function getContent() | |
459 | { | |
460 | return $this->content; | |
461 | } | |
462 | ||
463 | /** | |
5f09650e | 464 | * @return User |
9d50517c | 465 | */ |
5f09650e | 466 | public function getUser() |
9d50517c | 467 | { |
5f09650e | 468 | return $this->user; |
9d50517c | 469 | } |
42a90646 | 470 | |
7d1fdab2 TC |
471 | /** |
472 | * @VirtualProperty | |
473 | * @SerializedName("user_name") | |
474 | */ | |
475 | public function getUserName() | |
476 | { | |
477 | return $this->user->getUserName(); | |
478 | } | |
479 | ||
480 | /** | |
481 | * @VirtualProperty | |
482 | * @SerializedName("user_email") | |
483 | */ | |
484 | public function getUserEmail() | |
485 | { | |
486 | return $this->user->getEmail(); | |
487 | } | |
488 | ||
489 | /** | |
490 | * @VirtualProperty | |
491 | * @SerializedName("user_id") | |
492 | */ | |
493 | public function getUserId() | |
494 | { | |
495 | return $this->user->getId(); | |
496 | } | |
497 | ||
34d15eb4 | 498 | /** |
6d65c0a8 JB |
499 | * Set created_at. |
500 | * Only used when importing data from an other service. | |
501 | * | |
8664069e | 502 | * @param \DateTime $createdAt |
6d65c0a8 JB |
503 | * |
504 | * @return Entry | |
505 | */ | |
506 | public function setCreatedAt(\DateTime $createdAt) | |
507 | { | |
508 | $this->createdAt = $createdAt; | |
509 | ||
510 | return $this; | |
511 | } | |
512 | ||
513 | /** | |
8664069e | 514 | * @return \DateTime |
34d15eb4 NL |
515 | */ |
516 | public function getCreatedAt() | |
517 | { | |
518 | return $this->createdAt; | |
519 | } | |
520 | ||
34d15eb4 | 521 | /** |
8664069e | 522 | * @return \DateTime |
34d15eb4 NL |
523 | */ |
524 | public function getUpdatedAt() | |
525 | { | |
526 | return $this->updatedAt; | |
527 | } | |
528 | ||
a991c46e F |
529 | /** |
530 | * @return \DateTime|null | |
531 | */ | |
532 | public function getStarredAt() | |
533 | { | |
534 | return $this->starredAt; | |
535 | } | |
536 | ||
537 | /** | |
538 | * @param \DateTime|null $starredAt | |
539 | * | |
540 | * @return Entry | |
541 | */ | |
542 | public function setStarredAt($starredAt = null) | |
543 | { | |
544 | $this->starredAt = $starredAt; | |
545 | ||
546 | return $this; | |
547 | } | |
548 | ||
549 | /** | |
550 | * update isStarred and starred_at fields. | |
551 | * | |
552 | * @param bool $isStarred | |
553 | * | |
554 | * @return Entry | |
555 | */ | |
556 | public function updateStar($isStarred = false) | |
557 | { | |
558 | $this->setStarred($isStarred); | |
559 | $this->setStarredAt(null); | |
560 | if ($this->isStarred()) { | |
561 | $this->setStarredAt(new \DateTime()); | |
562 | } | |
563 | ||
564 | return $this; | |
565 | } | |
566 | ||
34d15eb4 | 567 | /** |
4dc87223 | 568 | * @return ArrayCollection<Annotation> |
34d15eb4 | 569 | */ |
4dc87223 | 570 | public function getAnnotations() |
34d15eb4 | 571 | { |
4dc87223 | 572 | return $this->annotations; |
34d15eb4 NL |
573 | } |
574 | ||
575 | /** | |
4dc87223 | 576 | * @param Annotation $annotation |
34d15eb4 | 577 | */ |
4dc87223 | 578 | public function setAnnotation(Annotation $annotation) |
34d15eb4 | 579 | { |
4dc87223 | 580 | $this->annotations[] = $annotation; |
34d15eb4 NL |
581 | } |
582 | ||
583 | /** | |
584 | * @return string | |
585 | */ | |
586 | public function getMimetype() | |
587 | { | |
588 | return $this->mimetype; | |
589 | } | |
590 | ||
591 | /** | |
592 | * @param string $mimetype | |
593 | */ | |
594 | public function setMimetype($mimetype) | |
595 | { | |
596 | $this->mimetype = $mimetype; | |
597 | } | |
598 | ||
599 | /** | |
600 | * @return int | |
601 | */ | |
602 | public function getReadingTime() | |
603 | { | |
604 | return $this->readingTime; | |
605 | } | |
606 | ||
607 | /** | |
608 | * @param int $readingTime | |
609 | */ | |
610 | public function setReadingTime($readingTime) | |
611 | { | |
612 | $this->readingTime = $readingTime; | |
613 | } | |
614 | ||
615 | /** | |
616 | * @return string | |
617 | */ | |
618 | public function getDomainName() | |
619 | { | |
620 | return $this->domainName; | |
621 | } | |
622 | ||
623 | /** | |
624 | * @param string $domainName | |
625 | */ | |
626 | public function setDomainName($domainName) | |
627 | { | |
628 | $this->domainName = $domainName; | |
629 | } | |
630 | ||
0a018fe0 | 631 | /** |
4ec53ab7 | 632 | * @return ArrayCollection |
0a018fe0 NL |
633 | */ |
634 | public function getTags() | |
635 | { | |
636 | return $this->tags; | |
637 | } | |
638 | ||
b0458874 JB |
639 | /** |
640 | * @VirtualProperty | |
641 | * @SerializedName("tags") | |
642 | * @Groups({"entries_for_user", "export_all"}) | |
643 | */ | |
644 | public function getSerializedTags() | |
645 | { | |
646 | $data = []; | |
647 | foreach ($this->tags as $tag) { | |
648 | $data[] = $tag->getLabel(); | |
649 | } | |
650 | ||
651 | return $data; | |
652 | } | |
653 | ||
0a018fe0 NL |
654 | /** |
655 | * @param Tag $tag | |
656 | */ | |
657 | public function addTag(Tag $tag) | |
658 | { | |
625acf33 KG |
659 | if ($this->tags->contains($tag)) { |
660 | return; | |
661 | } | |
662 | ||
fc031e57 JB |
663 | // check if tag already exist but has not yet be persisted |
664 | // it seems that the previous condition with `contains()` doesn't check that case | |
665 | foreach ($this->tags as $existingTag) { | |
fc732227 | 666 | if ($existingTag->getLabel() === $tag->getLabel()) { |
fc031e57 JB |
667 | return; |
668 | } | |
669 | } | |
670 | ||
e42b13bc | 671 | $this->tags->add($tag); |
46bbd8d3 | 672 | $tag->addEntry($this); |
0a018fe0 | 673 | } |
092ca707 | 674 | |
a05b6115 JB |
675 | /** |
676 | * Remove the given tag from the entry (if the tag is associated). | |
677 | * | |
678 | * @param Tag $tag | |
679 | */ | |
092ca707 NL |
680 | public function removeTag(Tag $tag) |
681 | { | |
e42b13bc JB |
682 | if (!$this->tags->contains($tag)) { |
683 | return; | |
684 | } | |
685 | ||
092ca707 | 686 | $this->tags->removeElement($tag); |
e42b13bc | 687 | $tag->removeEntry($this); |
092ca707 | 688 | } |
fad31615 | 689 | |
a05b6115 JB |
690 | /** |
691 | * Remove all assigned tags from the entry. | |
692 | */ | |
693 | public function removeAllTags() | |
694 | { | |
695 | foreach ($this->tags as $tag) { | |
696 | $this->tags->removeElement($tag); | |
697 | $tag->removeEntry($this); | |
698 | } | |
699 | } | |
700 | ||
fad31615 | 701 | /** |
a1413a3d | 702 | * Set previewPicture. |
fad31615 JB |
703 | * |
704 | * @param string $previewPicture | |
705 | * | |
706 | * @return Entry | |
707 | */ | |
708 | public function setPreviewPicture($previewPicture) | |
709 | { | |
710 | $this->previewPicture = $previewPicture; | |
711 | ||
712 | return $this; | |
713 | } | |
714 | ||
715 | /** | |
a1413a3d | 716 | * Get previewPicture. |
fad31615 JB |
717 | * |
718 | * @return string | |
719 | */ | |
720 | public function getPreviewPicture() | |
721 | { | |
722 | return $this->previewPicture; | |
723 | } | |
98f0929f JB |
724 | |
725 | /** | |
726 | * Set language. | |
727 | * | |
728 | * @param string $language | |
729 | * | |
730 | * @return Entry | |
731 | */ | |
732 | public function setLanguage($language) | |
733 | { | |
734 | $this->language = $language; | |
735 | ||
736 | return $this; | |
737 | } | |
738 | ||
739 | /** | |
740 | * Get language. | |
741 | * | |
742 | * @return string | |
743 | */ | |
744 | public function getLanguage() | |
745 | { | |
746 | return $this->language; | |
747 | } | |
f3d0cb91 NL |
748 | |
749 | /** | |
78b3c31d | 750 | * @return string |
f3d0cb91 | 751 | */ |
7239082a | 752 | public function getUid() |
f3d0cb91 | 753 | { |
7239082a | 754 | return $this->uid; |
f3d0cb91 NL |
755 | } |
756 | ||
757 | /** | |
7239082a | 758 | * @param string $uid |
f3d0cb91 NL |
759 | * |
760 | * @return Entry | |
761 | */ | |
7239082a | 762 | public function setUid($uid) |
f3d0cb91 | 763 | { |
7239082a | 764 | $this->uid = $uid; |
f3d0cb91 NL |
765 | |
766 | return $this; | |
767 | } | |
768 | ||
7239082a | 769 | public function generateUid() |
f3d0cb91 | 770 | { |
7239082a | 771 | if (null === $this->uid) { |
a7e2218e | 772 | // @see http://blog.kevingomez.fr/til/2015/07/26/why-is-uniqid-slow/ for true parameter |
7239082a | 773 | $this->uid = uniqid('', true); |
f3d0cb91 NL |
774 | } |
775 | } | |
f1be7af4 | 776 | |
7239082a | 777 | public function cleanUid() |
f1be7af4 | 778 | { |
7239082a | 779 | $this->uid = null; |
f1be7af4 | 780 | } |
10b35097 | 781 | |
e8911f7c JB |
782 | /** |
783 | * Used in the entries filter so it's more explicit for the end user than the uid. | |
a9c6577f | 784 | * Also used in the API. |
e8911f7c | 785 | * |
1112e547 JB |
786 | * @VirtualProperty |
787 | * @SerializedName("is_public") | |
788 | * @Groups({"entries_for_user"}) | |
789 | * | |
e8911f7c JB |
790 | * @return bool |
791 | */ | |
792 | public function isPublic() | |
793 | { | |
794 | return null !== $this->uid; | |
795 | } | |
796 | ||
10b35097 | 797 | /** |
5fe65bae | 798 | * @return string |
10b35097 NL |
799 | */ |
800 | public function getHttpStatus() | |
801 | { | |
802 | return $this->httpStatus; | |
803 | } | |
804 | ||
805 | /** | |
5fe65bae | 806 | * @param string $httpStatus |
10b35097 NL |
807 | * |
808 | * @return Entry | |
809 | */ | |
810 | public function setHttpStatus($httpStatus) | |
811 | { | |
812 | $this->httpStatus = $httpStatus; | |
813 | ||
814 | return $this; | |
815 | } | |
5e9009ce NL |
816 | |
817 | /** | |
818 | * @return \Datetime | |
819 | */ | |
820 | public function getPublishedAt() | |
821 | { | |
822 | return $this->publishedAt; | |
823 | } | |
824 | ||
825 | /** | |
826 | * @param \Datetime $publishedAt | |
827 | * | |
828 | * @return Entry | |
829 | */ | |
830 | public function setPublishedAt(\Datetime $publishedAt) | |
831 | { | |
832 | $this->publishedAt = $publishedAt; | |
833 | ||
834 | return $this; | |
835 | } | |
7b0b3622 NL |
836 | |
837 | /** | |
dda6a6ad | 838 | * @return array |
7b0b3622 NL |
839 | */ |
840 | public function getPublishedBy() | |
841 | { | |
842 | return $this->publishedBy; | |
843 | } | |
844 | ||
845 | /** | |
1517d577 | 846 | * @param array $publishedBy |
7b0b3622 NL |
847 | * |
848 | * @return Entry | |
849 | */ | |
850 | public function setPublishedBy($publishedBy) | |
851 | { | |
852 | $this->publishedBy = $publishedBy; | |
853 | ||
854 | return $this; | |
855 | } | |
dda6a6ad NL |
856 | |
857 | /** | |
858 | * @return array | |
859 | */ | |
860 | public function getHeaders() | |
861 | { | |
862 | return $this->headers; | |
863 | } | |
864 | ||
865 | /** | |
1517d577 | 866 | * @param array $headers |
dda6a6ad NL |
867 | * |
868 | * @return Entry | |
869 | */ | |
870 | public function setHeaders($headers) | |
871 | { | |
872 | $this->headers = $headers; | |
873 | ||
874 | return $this; | |
875 | } | |
eae8138b | 876 | |
e0ef1a1c KD |
877 | /** |
878 | * Set origin url. | |
879 | * | |
880 | * @param string $originUrl | |
881 | * | |
882 | * @return Entry | |
883 | */ | |
884 | public function setOriginUrl($originUrl) | |
885 | { | |
886 | $this->originUrl = $originUrl; | |
887 | ||
888 | return $this; | |
889 | } | |
eae8138b | 890 | |
e0ef1a1c KD |
891 | /** |
892 | * Get origin url. | |
893 | * | |
894 | * @return string | |
895 | */ | |
896 | public function getOriginUrl() | |
897 | { | |
898 | return $this->originUrl; | |
899 | } | |
9d50517c | 900 | } |