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