]>
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 | ||
68 | /** | |
69 | * @var string | |
70 | * | |
b84a8055 | 71 | * @Assert\NotBlank() |
9d50517c | 72 | * @ORM\Column(name="url", type="text", nullable=true) |
5b7da076 TC |
73 | * |
74 | * @Groups({"entries_for_user", "export_all"}) | |
9d50517c NL |
75 | */ |
76 | private $url; | |
77 | ||
78 | /** | |
4346a860 | 79 | * @var bool |
9d50517c | 80 | * |
189ef634 TC |
81 | * @Exclude |
82 | * | |
be463487 | 83 | * @ORM\Column(name="is_archived", type="boolean") |
5b7da076 TC |
84 | * |
85 | * @Groups({"entries_for_user", "export_all"}) | |
9d50517c | 86 | */ |
905ae369 | 87 | private $isArchived = false; |
9d50517c | 88 | |
7975395d SV |
89 | /** |
90 | * @var \DateTime | |
91 | * | |
92 | * @ORM\Column(name="archived_at", type="datetime", nullable=true) | |
93 | * | |
94 | * @Groups({"entries_for_user", "export_all"}) | |
95 | */ | |
96 | private $archivedAt = null; | |
97 | ||
9d50517c | 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 | ||
309 | /** | |
4346a860 JB |
310 | * Set url. |
311 | * | |
312 | * @param string $url | |
9d50517c | 313 | * |
be463487 | 314 | * @return Entry |
9d50517c NL |
315 | */ |
316 | public function setUrl($url) | |
317 | { | |
318 | $this->url = $url; | |
319 | ||
320 | return $this; | |
321 | } | |
322 | ||
323 | /** | |
4346a860 | 324 | * Get url. |
9d50517c | 325 | * |
7df80cb3 | 326 | * @return string |
9d50517c NL |
327 | */ |
328 | public function getUrl() | |
329 | { | |
330 | return $this->url; | |
331 | } | |
332 | ||
333 | /** | |
4346a860 JB |
334 | * Set isArchived. |
335 | * | |
8eedc8cf | 336 | * @param bool $isArchived |
9d50517c | 337 | * |
be463487 | 338 | * @return Entry |
9d50517c | 339 | */ |
905ae369 | 340 | public function setArchived($isArchived) |
9d50517c | 341 | { |
905ae369 | 342 | $this->isArchived = $isArchived; |
9d50517c NL |
343 | |
344 | return $this; | |
345 | } | |
346 | ||
7975395d SV |
347 | /** |
348 | * update isArchived and archive_at fields. | |
349 | * | |
350 | * @param bool $isArchived | |
351 | * | |
352 | * @return Entry | |
353 | */ | |
354 | public function updateArchived($isArchived = false) | |
355 | { | |
356 | $this->setArchived($isArchived); | |
357 | $this->setArchivedAt(null); | |
358 | if ($this->isArchived()) { | |
359 | $this->setArchivedAt(new \DateTime()); | |
360 | } | |
361 | ||
362 | return $this; | |
363 | } | |
364 | ||
365 | /** | |
366 | * @return \DateTime|null | |
367 | */ | |
368 | public function getArchivedAt() | |
369 | { | |
370 | return $this->archivedAt; | |
371 | } | |
372 | ||
373 | /** | |
374 | * @param \DateTime|null $archivedAt | |
375 | * | |
376 | * @return Entry | |
377 | */ | |
378 | public function setArchivedAt($archivedAt = null) | |
379 | { | |
380 | $this->archivedAt = $archivedAt; | |
381 | ||
382 | return $this; | |
383 | } | |
384 | ||
9d50517c | 385 | /** |
4346a860 | 386 | * Get isArchived. |
9d50517c | 387 | * |
8eedc8cf | 388 | * @return bool |
9d50517c | 389 | */ |
905ae369 | 390 | public function isArchived() |
9d50517c | 391 | { |
905ae369 | 392 | return $this->isArchived; |
9d50517c NL |
393 | } |
394 | ||
189ef634 TC |
395 | /** |
396 | * @VirtualProperty | |
397 | * @SerializedName("is_archived") | |
398 | * @Groups({"entries_for_user", "export_all"}) | |
399 | */ | |
400 | public function is_Archived() | |
401 | { | |
402 | return (int) $this->isArchived(); | |
403 | } | |
404 | ||
163eae0b NL |
405 | public function toggleArchive() |
406 | { | |
7975395d | 407 | $this->updateArchived($this->isArchived() ^ 1); |
7df80cb3 | 408 | |
163eae0b NL |
409 | return $this; |
410 | } | |
411 | ||
9d50517c | 412 | /** |
4346a860 JB |
413 | * Set isStarred. |
414 | * | |
8eedc8cf | 415 | * @param bool $isStarred |
9d50517c | 416 | * |
be463487 | 417 | * @return Entry |
9d50517c | 418 | */ |
905ae369 | 419 | public function setStarred($isStarred) |
9d50517c | 420 | { |
905ae369 | 421 | $this->isStarred = $isStarred; |
9d50517c NL |
422 | |
423 | return $this; | |
424 | } | |
425 | ||
426 | /** | |
4346a860 | 427 | * Get isStarred. |
9d50517c | 428 | * |
8eedc8cf | 429 | * @return bool |
9d50517c | 430 | */ |
905ae369 | 431 | public function isStarred() |
9d50517c | 432 | { |
905ae369 | 433 | return $this->isStarred; |
9d50517c NL |
434 | } |
435 | ||
189ef634 TC |
436 | /** |
437 | * @VirtualProperty | |
438 | * @SerializedName("is_starred") | |
439 | * @Groups({"entries_for_user", "export_all"}) | |
440 | */ | |
441 | public function is_Starred() | |
442 | { | |
443 | return (int) $this->isStarred(); | |
444 | } | |
445 | ||
163eae0b NL |
446 | public function toggleStar() |
447 | { | |
905ae369 | 448 | $this->isStarred = $this->isStarred() ^ 1; |
163eae0b NL |
449 | |
450 | return $this; | |
451 | } | |
452 | ||
9d50517c | 453 | /** |
4346a860 JB |
454 | * Set content. |
455 | * | |
456 | * @param string $content | |
9d50517c | 457 | * |
be463487 | 458 | * @return Entry |
9d50517c NL |
459 | */ |
460 | public function setContent($content) | |
461 | { | |
462 | $this->content = $content; | |
463 | ||
464 | return $this; | |
465 | } | |
466 | ||
467 | /** | |
4346a860 | 468 | * Get content. |
9d50517c | 469 | * |
7df80cb3 | 470 | * @return string |
9d50517c NL |
471 | */ |
472 | public function getContent() | |
473 | { | |
474 | return $this->content; | |
475 | } | |
476 | ||
477 | /** | |
5f09650e | 478 | * @return User |
9d50517c | 479 | */ |
5f09650e | 480 | public function getUser() |
9d50517c | 481 | { |
5f09650e | 482 | return $this->user; |
9d50517c | 483 | } |
42a90646 | 484 | |
7d1fdab2 TC |
485 | /** |
486 | * @VirtualProperty | |
487 | * @SerializedName("user_name") | |
488 | */ | |
489 | public function getUserName() | |
490 | { | |
491 | return $this->user->getUserName(); | |
492 | } | |
493 | ||
494 | /** | |
495 | * @VirtualProperty | |
496 | * @SerializedName("user_email") | |
497 | */ | |
498 | public function getUserEmail() | |
499 | { | |
500 | return $this->user->getEmail(); | |
501 | } | |
502 | ||
503 | /** | |
504 | * @VirtualProperty | |
505 | * @SerializedName("user_id") | |
506 | */ | |
507 | public function getUserId() | |
508 | { | |
509 | return $this->user->getId(); | |
510 | } | |
511 | ||
34d15eb4 | 512 | /** |
6d65c0a8 JB |
513 | * Set created_at. |
514 | * Only used when importing data from an other service. | |
515 | * | |
8664069e | 516 | * @param \DateTime $createdAt |
6d65c0a8 JB |
517 | * |
518 | * @return Entry | |
519 | */ | |
520 | public function setCreatedAt(\DateTime $createdAt) | |
521 | { | |
522 | $this->createdAt = $createdAt; | |
523 | ||
524 | return $this; | |
525 | } | |
526 | ||
527 | /** | |
8664069e | 528 | * @return \DateTime |
34d15eb4 NL |
529 | */ |
530 | public function getCreatedAt() | |
531 | { | |
532 | return $this->createdAt; | |
533 | } | |
534 | ||
34d15eb4 | 535 | /** |
8664069e | 536 | * @return \DateTime |
34d15eb4 NL |
537 | */ |
538 | public function getUpdatedAt() | |
539 | { | |
540 | return $this->updatedAt; | |
541 | } | |
542 | ||
a991c46e F |
543 | /** |
544 | * @return \DateTime|null | |
545 | */ | |
546 | public function getStarredAt() | |
547 | { | |
548 | return $this->starredAt; | |
549 | } | |
550 | ||
551 | /** | |
552 | * @param \DateTime|null $starredAt | |
553 | * | |
554 | * @return Entry | |
555 | */ | |
556 | public function setStarredAt($starredAt = null) | |
557 | { | |
558 | $this->starredAt = $starredAt; | |
559 | ||
560 | return $this; | |
561 | } | |
562 | ||
563 | /** | |
564 | * update isStarred and starred_at fields. | |
565 | * | |
566 | * @param bool $isStarred | |
567 | * | |
568 | * @return Entry | |
569 | */ | |
570 | public function updateStar($isStarred = false) | |
571 | { | |
572 | $this->setStarred($isStarred); | |
573 | $this->setStarredAt(null); | |
574 | if ($this->isStarred()) { | |
575 | $this->setStarredAt(new \DateTime()); | |
576 | } | |
577 | ||
578 | return $this; | |
579 | } | |
580 | ||
34d15eb4 | 581 | /** |
4dc87223 | 582 | * @return ArrayCollection<Annotation> |
34d15eb4 | 583 | */ |
4dc87223 | 584 | public function getAnnotations() |
34d15eb4 | 585 | { |
4dc87223 | 586 | return $this->annotations; |
34d15eb4 NL |
587 | } |
588 | ||
589 | /** | |
4dc87223 | 590 | * @param Annotation $annotation |
34d15eb4 | 591 | */ |
4dc87223 | 592 | public function setAnnotation(Annotation $annotation) |
34d15eb4 | 593 | { |
4dc87223 | 594 | $this->annotations[] = $annotation; |
34d15eb4 NL |
595 | } |
596 | ||
597 | /** | |
598 | * @return string | |
599 | */ | |
600 | public function getMimetype() | |
601 | { | |
602 | return $this->mimetype; | |
603 | } | |
604 | ||
605 | /** | |
606 | * @param string $mimetype | |
607 | */ | |
608 | public function setMimetype($mimetype) | |
609 | { | |
610 | $this->mimetype = $mimetype; | |
611 | } | |
612 | ||
613 | /** | |
614 | * @return int | |
615 | */ | |
616 | public function getReadingTime() | |
617 | { | |
618 | return $this->readingTime; | |
619 | } | |
620 | ||
621 | /** | |
622 | * @param int $readingTime | |
623 | */ | |
624 | public function setReadingTime($readingTime) | |
625 | { | |
626 | $this->readingTime = $readingTime; | |
627 | } | |
628 | ||
629 | /** | |
630 | * @return string | |
631 | */ | |
632 | public function getDomainName() | |
633 | { | |
634 | return $this->domainName; | |
635 | } | |
636 | ||
637 | /** | |
638 | * @param string $domainName | |
639 | */ | |
640 | public function setDomainName($domainName) | |
641 | { | |
642 | $this->domainName = $domainName; | |
643 | } | |
644 | ||
0a018fe0 | 645 | /** |
4ec53ab7 | 646 | * @return ArrayCollection |
0a018fe0 NL |
647 | */ |
648 | public function getTags() | |
649 | { | |
650 | return $this->tags; | |
651 | } | |
652 | ||
b0458874 JB |
653 | /** |
654 | * @VirtualProperty | |
655 | * @SerializedName("tags") | |
656 | * @Groups({"entries_for_user", "export_all"}) | |
657 | */ | |
658 | public function getSerializedTags() | |
659 | { | |
660 | $data = []; | |
661 | foreach ($this->tags as $tag) { | |
662 | $data[] = $tag->getLabel(); | |
663 | } | |
664 | ||
665 | return $data; | |
666 | } | |
667 | ||
0a018fe0 NL |
668 | /** |
669 | * @param Tag $tag | |
670 | */ | |
671 | public function addTag(Tag $tag) | |
672 | { | |
625acf33 KG |
673 | if ($this->tags->contains($tag)) { |
674 | return; | |
675 | } | |
676 | ||
fc031e57 JB |
677 | // check if tag already exist but has not yet be persisted |
678 | // it seems that the previous condition with `contains()` doesn't check that case | |
679 | foreach ($this->tags as $existingTag) { | |
fc732227 | 680 | if ($existingTag->getLabel() === $tag->getLabel()) { |
fc031e57 JB |
681 | return; |
682 | } | |
683 | } | |
684 | ||
e42b13bc | 685 | $this->tags->add($tag); |
46bbd8d3 | 686 | $tag->addEntry($this); |
0a018fe0 | 687 | } |
092ca707 | 688 | |
a05b6115 JB |
689 | /** |
690 | * Remove the given tag from the entry (if the tag is associated). | |
691 | * | |
692 | * @param Tag $tag | |
693 | */ | |
092ca707 NL |
694 | public function removeTag(Tag $tag) |
695 | { | |
e42b13bc JB |
696 | if (!$this->tags->contains($tag)) { |
697 | return; | |
698 | } | |
699 | ||
092ca707 | 700 | $this->tags->removeElement($tag); |
e42b13bc | 701 | $tag->removeEntry($this); |
092ca707 | 702 | } |
fad31615 | 703 | |
a05b6115 JB |
704 | /** |
705 | * Remove all assigned tags from the entry. | |
706 | */ | |
707 | public function removeAllTags() | |
708 | { | |
709 | foreach ($this->tags as $tag) { | |
710 | $this->tags->removeElement($tag); | |
711 | $tag->removeEntry($this); | |
712 | } | |
713 | } | |
714 | ||
fad31615 | 715 | /** |
a1413a3d | 716 | * Set previewPicture. |
fad31615 JB |
717 | * |
718 | * @param string $previewPicture | |
719 | * | |
720 | * @return Entry | |
721 | */ | |
722 | public function setPreviewPicture($previewPicture) | |
723 | { | |
724 | $this->previewPicture = $previewPicture; | |
725 | ||
726 | return $this; | |
727 | } | |
728 | ||
729 | /** | |
a1413a3d | 730 | * Get previewPicture. |
fad31615 JB |
731 | * |
732 | * @return string | |
733 | */ | |
734 | public function getPreviewPicture() | |
735 | { | |
736 | return $this->previewPicture; | |
737 | } | |
98f0929f JB |
738 | |
739 | /** | |
740 | * Set language. | |
741 | * | |
742 | * @param string $language | |
743 | * | |
744 | * @return Entry | |
745 | */ | |
746 | public function setLanguage($language) | |
747 | { | |
748 | $this->language = $language; | |
749 | ||
750 | return $this; | |
751 | } | |
752 | ||
753 | /** | |
754 | * Get language. | |
755 | * | |
756 | * @return string | |
757 | */ | |
758 | public function getLanguage() | |
759 | { | |
760 | return $this->language; | |
761 | } | |
f3d0cb91 NL |
762 | |
763 | /** | |
78b3c31d | 764 | * @return string |
f3d0cb91 | 765 | */ |
7239082a | 766 | public function getUid() |
f3d0cb91 | 767 | { |
7239082a | 768 | return $this->uid; |
f3d0cb91 NL |
769 | } |
770 | ||
771 | /** | |
7239082a | 772 | * @param string $uid |
f3d0cb91 NL |
773 | * |
774 | * @return Entry | |
775 | */ | |
7239082a | 776 | public function setUid($uid) |
f3d0cb91 | 777 | { |
7239082a | 778 | $this->uid = $uid; |
f3d0cb91 NL |
779 | |
780 | return $this; | |
781 | } | |
782 | ||
7239082a | 783 | public function generateUid() |
f3d0cb91 | 784 | { |
7239082a | 785 | if (null === $this->uid) { |
a7e2218e | 786 | // @see http://blog.kevingomez.fr/til/2015/07/26/why-is-uniqid-slow/ for true parameter |
7239082a | 787 | $this->uid = uniqid('', true); |
f3d0cb91 NL |
788 | } |
789 | } | |
f1be7af4 | 790 | |
7239082a | 791 | public function cleanUid() |
f1be7af4 | 792 | { |
7239082a | 793 | $this->uid = null; |
f1be7af4 | 794 | } |
10b35097 | 795 | |
e8911f7c JB |
796 | /** |
797 | * Used in the entries filter so it's more explicit for the end user than the uid. | |
a9c6577f | 798 | * Also used in the API. |
e8911f7c | 799 | * |
1112e547 JB |
800 | * @VirtualProperty |
801 | * @SerializedName("is_public") | |
802 | * @Groups({"entries_for_user"}) | |
803 | * | |
e8911f7c JB |
804 | * @return bool |
805 | */ | |
806 | public function isPublic() | |
807 | { | |
808 | return null !== $this->uid; | |
809 | } | |
810 | ||
10b35097 | 811 | /** |
5fe65bae | 812 | * @return string |
10b35097 NL |
813 | */ |
814 | public function getHttpStatus() | |
815 | { | |
816 | return $this->httpStatus; | |
817 | } | |
818 | ||
819 | /** | |
5fe65bae | 820 | * @param string $httpStatus |
10b35097 NL |
821 | * |
822 | * @return Entry | |
823 | */ | |
824 | public function setHttpStatus($httpStatus) | |
825 | { | |
826 | $this->httpStatus = $httpStatus; | |
827 | ||
828 | return $this; | |
829 | } | |
5e9009ce NL |
830 | |
831 | /** | |
832 | * @return \Datetime | |
833 | */ | |
834 | public function getPublishedAt() | |
835 | { | |
836 | return $this->publishedAt; | |
837 | } | |
838 | ||
839 | /** | |
840 | * @param \Datetime $publishedAt | |
841 | * | |
842 | * @return Entry | |
843 | */ | |
844 | public function setPublishedAt(\Datetime $publishedAt) | |
845 | { | |
846 | $this->publishedAt = $publishedAt; | |
847 | ||
848 | return $this; | |
849 | } | |
7b0b3622 NL |
850 | |
851 | /** | |
dda6a6ad | 852 | * @return array |
7b0b3622 NL |
853 | */ |
854 | public function getPublishedBy() | |
855 | { | |
856 | return $this->publishedBy; | |
857 | } | |
858 | ||
859 | /** | |
1517d577 | 860 | * @param array $publishedBy |
7b0b3622 NL |
861 | * |
862 | * @return Entry | |
863 | */ | |
864 | public function setPublishedBy($publishedBy) | |
865 | { | |
866 | $this->publishedBy = $publishedBy; | |
867 | ||
868 | return $this; | |
869 | } | |
dda6a6ad NL |
870 | |
871 | /** | |
872 | * @return array | |
873 | */ | |
874 | public function getHeaders() | |
875 | { | |
876 | return $this->headers; | |
877 | } | |
878 | ||
879 | /** | |
1517d577 | 880 | * @param array $headers |
dda6a6ad NL |
881 | * |
882 | * @return Entry | |
883 | */ | |
884 | public function setHeaders($headers) | |
885 | { | |
886 | $this->headers = $headers; | |
887 | ||
888 | return $this; | |
889 | } | |
eae8138b | 890 | |
e0ef1a1c KD |
891 | /** |
892 | * Set origin url. | |
893 | * | |
894 | * @param string $originUrl | |
895 | * | |
896 | * @return Entry | |
897 | */ | |
898 | public function setOriginUrl($originUrl) | |
899 | { | |
900 | $this->originUrl = $originUrl; | |
901 | ||
902 | return $this; | |
903 | } | |
eae8138b | 904 | |
e0ef1a1c KD |
905 | /** |
906 | * Get origin url. | |
907 | * | |
908 | * @return string | |
909 | */ | |
910 | public function getOriginUrl() | |
911 | { | |
912 | return $this->originUrl; | |
913 | } | |
9d50517c | 914 | } |