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