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