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