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