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