]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/CoreBundle/Controller/EntryController.php
Set progress
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Controller / EntryController.php
CommitLineData
9d50517c
NL
1<?php
2
ad4d1caa 3namespace Wallabag\CoreBundle\Controller;
9d50517c 4
619cc453 5use Pagerfanta\Adapter\DoctrineORMAdapter;
671a2b88 6use Pagerfanta\Exception\OutOfRangeCurrentPageException;
9d50517c
NL
7use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
8use Symfony\Bundle\FrameworkBundle\Controller\Controller;
46a54f5d 9use Symfony\Component\HttpFoundation\JsonResponse;
163eae0b 10use Symfony\Component\HttpFoundation\Request;
46a54f5d 11use Symfony\Component\HttpFoundation\Response;
2863bf2a 12use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
be463487 13use Wallabag\CoreBundle\Entity\Entry;
b0b893ea 14use Wallabag\CoreBundle\Form\Type\EntryFilterType;
619cc453
JB
15use Wallabag\CoreBundle\Form\Type\EditEntryType;
16use Wallabag\CoreBundle\Form\Type\NewEntryType;
222e09f1 17use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
e0597476
JB
18use Wallabag\CoreBundle\Event\EntrySavedEvent;
19use Wallabag\CoreBundle\Event\EntryDeletedEvent;
ee122a75 20use Wallabag\CoreBundle\Form\Type\SearchEntryType;
9d50517c
NL
21
22class EntryController extends Controller
23{
ee122a75
NL
24 /**
25 * @param Request $request
26 * @param int $page
27 *
21e7ccef
JB
28 * @Route("/search/{page}", name="search", defaults={"page" = 1})
29 *
30 * Default parameter for page is hardcoded (in duplication of the defaults from the Route)
31 * because this controller is also called inside the layout template without any page as argument
ee122a75
NL
32 *
33 * @return \Symfony\Component\HttpFoundation\Response
34 */
21e7ccef 35 public function searchFormAction(Request $request, $page = 1, $currentRoute = null)
ee122a75 36 {
21e7ccef
JB
37 // fallback to retrieve currentRoute from query parameter instead of injected one (when using inside a template)
38 if (null === $currentRoute && $request->query->has('currentRoute')) {
39 $currentRoute = $request->query->get('currentRoute');
40 }
41
ee122a75
NL
42 $form = $this->createForm(SearchEntryType::class);
43
44 $form->handleRequest($request);
45
21e7ccef 46 if ($form->isSubmitted() && $form->isValid()) {
ee122a75
NL
47 return $this->showEntries('search', $request, $page);
48 }
49
50 return $this->render('WallabagCoreBundle:Entry:search_form.html.twig', [
51 'form' => $form->createView(),
49b042df 52 'currentRoute' => $currentRoute,
ee122a75
NL
53 ]);
54 }
55
880a0e1c 56 /**
59b97fae 57 * Fetch content and update entry.
7aba665e 58 * In case it fails, $entry->getContent will return an error message.
59b97fae
JB
59 *
60 * @param Entry $entry
61 * @param string $prefixMessage Should be the translation key: entry_saved or entry_reloaded
880a0e1c 62 */
59b97fae 63 private function updateEntry(Entry $entry, $prefixMessage = 'entry_saved')
880a0e1c 64 {
59b97fae
JB
65 $message = 'flashes.entry.notice.'.$prefixMessage;
66
880a0e1c 67 try {
7aba665e 68 $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl());
880a0e1c 69 } catch (\Exception $e) {
39ba51ca
JB
70 $this->get('logger')->error('Error while saving an entry', [
71 'exception' => $e,
72 'entry' => $entry,
73 ]);
74
59b97fae 75 $message = 'flashes.entry.notice.'.$prefixMessage.'_failed';
880a0e1c
NL
76 }
77
59b97fae 78 $this->get('session')->getFlashBag()->add('notice', $message);
880a0e1c
NL
79 }
80
b84a8055 81 /**
3d2b2d62
J
82 * @param Request $request
83 *
053b9568 84 * @Route("/new-entry", name="new_entry")
3d2b2d62 85 *
b84a8055
NL
86 * @return \Symfony\Component\HttpFoundation\Response
87 */
053b9568 88 public function addEntryFormAction(Request $request)
b84a8055 89 {
3b815d2d 90 $entry = new Entry($this->getUser());
b84a8055 91
5c895a7f 92 $form = $this->createForm(NewEntryType::class, $entry);
b84a8055
NL
93
94 $form->handleRequest($request);
95
21e7ccef 96 if ($form->isSubmitted() && $form->isValid()) {
b00a89e0 97 $existingEntry = $this->checkIfEntryAlreadyExists($entry);
dda57bb9 98
5a4bbcc9 99 if (false !== $existingEntry) {
dda57bb9
NL
100 $this->get('session')->getFlashBag()->add(
101 'notice',
4094ea47 102 $this->get('translator')->trans('flashes.entry.notice.entry_already_saved', ['%date%' => $existingEntry->getCreatedAt()->format('d-m-Y')])
dda57bb9
NL
103 );
104
4094ea47 105 return $this->redirect($this->generateUrl('view', ['id' => $existingEntry->getId()]));
dda57bb9
NL
106 }
107
59b97fae 108 $this->updateEntry($entry);
39ba51ca 109
59b97fae
JB
110 $em = $this->getDoctrine()->getManager();
111 $em->persist($entry);
112 $em->flush();
b84a8055 113
e0597476
JB
114 // entry saved, dispatch event about it!
115 $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
116
b84a8055
NL
117 return $this->redirect($this->generateUrl('homepage'));
118 }
119
4094ea47 120 return $this->render('WallabagCoreBundle:Entry:new_form.html.twig', [
b84a8055 121 'form' => $form->createView(),
4094ea47 122 ]);
b84a8055
NL
123 }
124
880a0e1c
NL
125 /**
126 * @param Request $request
127 *
128 * @Route("/bookmarklet", name="bookmarklet")
129 *
130 * @return \Symfony\Component\HttpFoundation\Response
131 */
5f8a7857 132 public function addEntryViaBookmarkletAction(Request $request)
880a0e1c
NL
133 {
134 $entry = new Entry($this->getUser());
135 $entry->setUrl($request->get('url'));
f652f41d 136
b00a89e0 137 if (false === $this->checkIfEntryAlreadyExists($entry)) {
f652f41d 138 $this->updateEntry($entry);
59b97fae
JB
139
140 $em = $this->getDoctrine()->getManager();
141 $em->persist($entry);
142 $em->flush();
e0597476
JB
143
144 // entry saved, dispatch event about it!
145 $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
f652f41d 146 }
880a0e1c
NL
147
148 return $this->redirect($this->generateUrl('homepage'));
149 }
150
053b9568 151 /**
053b9568
NL
152 * @Route("/new", name="new")
153 *
154 * @return \Symfony\Component\HttpFoundation\Response
155 */
4d0ec0e7 156 public function addEntryAction()
053b9568
NL
157 {
158 return $this->render('WallabagCoreBundle:Entry:new.html.twig');
159 }
160
82d6d9cb
JB
161 /**
162 * Edit an entry content.
163 *
164 * @param Request $request
165 * @param Entry $entry
166 *
167 * @Route("/edit/{id}", requirements={"id" = "\d+"}, name="edit")
168 *
169 * @return \Symfony\Component\HttpFoundation\Response
170 */
171 public function editEntryAction(Request $request, Entry $entry)
172 {
173 $this->checkUserAction($entry);
174
5c895a7f 175 $form = $this->createForm(EditEntryType::class, $entry);
82d6d9cb
JB
176
177 $form->handleRequest($request);
178
21e7ccef 179 if ($form->isSubmitted() && $form->isValid()) {
82d6d9cb
JB
180 $em = $this->getDoctrine()->getManager();
181 $em->persist($entry);
182 $em->flush();
183
184 $this->get('session')->getFlashBag()->add(
185 'notice',
4204a06b 186 'flashes.entry.notice.entry_updated'
82d6d9cb
JB
187 );
188
4094ea47 189 return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
82d6d9cb
JB
190 }
191
4094ea47 192 return $this->render('WallabagCoreBundle:Entry:edit.html.twig', [
82d6d9cb 193 'form' => $form->createView(),
4094ea47 194 ]);
82d6d9cb
JB
195 }
196
89659c9e
NL
197 /**
198 * Shows all entries for current user.
199 *
200 * @param Request $request
201 * @param int $page
202 *
203 * @Route("/all/list/{page}", name="all", defaults={"page" = "1"})
204 *
205 * @return \Symfony\Component\HttpFoundation\Response
206 */
207 public function showAllAction(Request $request, $page)
208 {
2b7a4889 209 return $this->showEntries('all', $request, $page);
89659c9e
NL
210 }
211
9d50517c 212 /**
4346a860 213 * Shows unread entries for current user.
163eae0b 214 *
26864574
NL
215 * @param Request $request
216 * @param int $page
217 *
9fb6ac83 218 * @Route("/unread/list/{page}", name="unread", defaults={"page" = "1"})
3d2b2d62 219 *
163eae0b 220 * @return \Symfony\Component\HttpFoundation\Response
9d50517c 221 */
26864574 222 public function showUnreadAction(Request $request, $page)
9d50517c 223 {
5c072d2b 224 // load the quickstart if no entry in database
273b6f06 225 if ($page == 1 && $this->get('wallabag_core.entry_repository')->countAllEntriesByUser($this->getUser()->getId()) == 0) {
5c072d2b
NL
226 return $this->redirect($this->generateUrl('quickstart'));
227 }
228
0ab7404f 229 return $this->showEntries('unread', $request, $page);
9d50517c 230 }
bd9f0815
NL
231
232 /**
4346a860 233 * Shows read entries for current user.
163eae0b 234 *
26864574
NL
235 * @param Request $request
236 * @param int $page
237 *
9fb6ac83 238 * @Route("/archive/list/{page}", name="archive", defaults={"page" = "1"})
3d2b2d62 239 *
163eae0b 240 * @return \Symfony\Component\HttpFoundation\Response
bd9f0815 241 */
26864574 242 public function showArchiveAction(Request $request, $page)
bd9f0815 243 {
0ab7404f
JB
244 return $this->showEntries('archive', $request, $page);
245 }
246
247 /**
248 * Shows starred entries for current user.
249 *
250 * @param Request $request
251 * @param int $page
252 *
253 * @Route("/starred/list/{page}", name="starred", defaults={"page" = "1"})
254 *
255 * @return \Symfony\Component\HttpFoundation\Response
256 */
257 public function showStarredAction(Request $request, $page)
258 {
259 return $this->showEntries('starred', $request, $page);
260 }
26864574 261
0ab7404f
JB
262 /**
263 * Global method to retrieve entries depending on the given type
264 * It returns the response to be send.
265 *
266 * @param string $type Entries type: unread, starred or archive
267 * @param Request $request
268 * @param int $page
269 *
270 * @return \Symfony\Component\HttpFoundation\Response
271 */
272 private function showEntries($type, Request $request, $page)
273 {
5c072d2b 274 $repository = $this->get('wallabag_core.entry_repository');
ee122a75 275 $searchTerm = (isset($request->get('search_entry')['term']) ? $request->get('search_entry')['term'] : '');
6ad8aabb 276 $currentRoute = (!is_null($request->query->get('currentRoute')) ? $request->query->get('currentRoute') : '');
0ab7404f
JB
277
278 switch ($type) {
ee122a75 279 case 'search':
49b042df 280 $qb = $repository->getBuilderForSearchByUser($this->getUser()->getId(), $searchTerm, $currentRoute);
ee122a75
NL
281
282 break;
b6520f0b
NL
283 case 'untagged':
284 $qb = $repository->getBuilderForUntaggedByUser($this->getUser()->getId());
285
286 break;
0ab7404f
JB
287 case 'starred':
288 $qb = $repository->getBuilderForStarredByUser($this->getUser()->getId());
289 break;
290
291 case 'archive':
292 $qb = $repository->getBuilderForArchiveByUser($this->getUser()->getId());
293 break;
294
295 case 'unread':
296 $qb = $repository->getBuilderForUnreadByUser($this->getUser()->getId());
297 break;
298
2b7a4889
NL
299 case 'all':
300 $qb = $repository->getBuilderForAllByUser($this->getUser()->getId());
301 break;
302
0ab7404f
JB
303 default:
304 throw new \InvalidArgumentException(sprintf('Type "%s" is not implemented.', $type));
305 }
306
1d76102a 307 $form = $this->createForm(EntryFilterType::class);
9fb6ac83 308
26864574
NL
309 if ($request->query->has($form->getName())) {
310 // manually bind values from the request
311 $form->submit($request->query->get($form->getName()));
312
313 // build the query from the given form object
0ab7404f 314 $this->get('lexik_form_filter.query_builder_updater')->addFilterConditions($form, $qb);
26864574
NL
315 }
316
9deac0c5 317 $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false);
26864574 318
53da8ad8 319 $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries')->prepare($pagerAdapter);
891456ba 320
671a2b88
ML
321 try {
322 $entries->setCurrentPage($page);
323 } catch (OutOfRangeCurrentPageException $e) {
324 if ($page > 1) {
4094ea47 325 return $this->redirect($this->generateUrl($type, ['page' => $entries->getNbPages()]), 302);
671a2b88
ML
326 }
327 }
bd9f0815
NL
328
329 return $this->render(
ee122a75 330 'WallabagCoreBundle:Entry:entries.html.twig', [
8ce32af6
JB
331 'form' => $form->createView(),
332 'entries' => $entries,
333 'currentPage' => $page,
ee122a75 334 'searchTerm' => $searchTerm,
4094ea47 335 ]
bd9f0815 336 );
bd9f0815
NL
337 }
338
339 /**
4346a860 340 * Shows entry content.
163eae0b 341 *
3d2b2d62
J
342 * @param Entry $entry
343 *
bd9f0815 344 * @Route("/view/{id}", requirements={"id" = "\d+"}, name="view")
3d2b2d62 345 *
163eae0b 346 * @return \Symfony\Component\HttpFoundation\Response
bd9f0815 347 */
be463487 348 public function viewAction(Entry $entry)
bd9f0815 349 {
3d2b2d62
J
350 $this->checkUserAction($entry);
351
bd9f0815 352 return $this->render(
ad4d1caa 353 'WallabagCoreBundle:Entry:entry.html.twig',
4094ea47 354 ['entry' => $entry]
bd9f0815 355 );
163eae0b
NL
356 }
357
831b02aa
JB
358 /**
359 * Reload an entry.
360 * Refetch content from the website and make it readable again.
361 *
362 * @param Entry $entry
363 *
364 * @Route("/reload/{id}", requirements={"id" = "\d+"}, name="reload_entry")
365 *
366 * @return \Symfony\Component\HttpFoundation\RedirectResponse
367 */
368 public function reloadAction(Entry $entry)
369 {
370 $this->checkUserAction($entry);
371
59b97fae 372 $this->updateEntry($entry, 'entry_reloaded');
831b02aa 373
2297d60f
JB
374 // if refreshing entry failed, don't save it
375 if ($this->getParameter('wallabag_core.fetching_error_message') === $entry->getContent()) {
376 $bag = $this->get('session')->getFlashBag();
377 $bag->clear();
378 $bag->add('notice', 'flashes.entry.notice.entry_reloaded_failed');
379
380 return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
381 }
382
59b97fae
JB
383 $em = $this->getDoctrine()->getManager();
384 $em->persist($entry);
385 $em->flush();
831b02aa 386
e0597476
JB
387 // entry saved, dispatch event about it!
388 $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
389
4094ea47 390 return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
831b02aa
JB
391 }
392
163eae0b 393 /**
4346a860 394 * Changes read status for an entry.
163eae0b 395 *
3d2b2d62
J
396 * @param Request $request
397 * @param Entry $entry
398 *
163eae0b 399 * @Route("/archive/{id}", requirements={"id" = "\d+"}, name="archive_entry")
3d2b2d62 400 *
163eae0b
NL
401 * @return \Symfony\Component\HttpFoundation\RedirectResponse
402 */
be463487 403 public function toggleArchiveAction(Request $request, Entry $entry)
163eae0b 404 {
3d2b2d62
J
405 $this->checkUserAction($entry);
406
163eae0b
NL
407 $entry->toggleArchive();
408 $this->getDoctrine()->getManager()->flush();
409
4204a06b
JB
410 $message = 'flashes.entry.notice.entry_unarchived';
411 if ($entry->isArchived()) {
412 $message = 'flashes.entry.notice.entry_archived';
413 }
414
163eae0b
NL
415 $this->get('session')->getFlashBag()->add(
416 'notice',
4204a06b 417 $message
163eae0b
NL
418 );
419
af497a64
NL
420 $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer'));
421
422 return $this->redirect($redirectUrl);
163eae0b
NL
423 }
424
425 /**
eecd7e40 426 * Changes starred status for an entry.
163eae0b 427 *
3d2b2d62
J
428 * @param Request $request
429 * @param Entry $entry
430 *
163eae0b 431 * @Route("/star/{id}", requirements={"id" = "\d+"}, name="star_entry")
3d2b2d62 432 *
163eae0b
NL
433 * @return \Symfony\Component\HttpFoundation\RedirectResponse
434 */
be463487 435 public function toggleStarAction(Request $request, Entry $entry)
163eae0b 436 {
3d2b2d62
J
437 $this->checkUserAction($entry);
438
163eae0b
NL
439 $entry->toggleStar();
440 $this->getDoctrine()->getManager()->flush();
441
4204a06b
JB
442 $message = 'flashes.entry.notice.entry_unstarred';
443 if ($entry->isStarred()) {
444 $message = 'flashes.entry.notice.entry_starred';
445 }
446
163eae0b
NL
447 $this->get('session')->getFlashBag()->add(
448 'notice',
4204a06b 449 $message
163eae0b
NL
450 );
451
af497a64
NL
452 $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer'));
453
454 return $this->redirect($redirectUrl);
163eae0b
NL
455 }
456
457 /**
2863bf2a 458 * Deletes entry and redirect to the homepage or the last viewed page.
163eae0b 459 *
16a3d04c 460 * @param Entry $entry
3d2b2d62 461 *
163eae0b 462 * @Route("/delete/{id}", requirements={"id" = "\d+"}, name="delete_entry")
3d2b2d62 463 *
163eae0b
NL
464 * @return \Symfony\Component\HttpFoundation\RedirectResponse
465 */
18d5f454 466 public function deleteEntryAction(Request $request, Entry $entry)
163eae0b 467 {
3d2b2d62
J
468 $this->checkUserAction($entry);
469
2863bf2a
JB
470 // generates the view url for this entry to check for redirection later
471 // to avoid redirecting to the deleted entry. Ugh.
472 $url = $this->generateUrl(
473 'view',
4094ea47 474 ['id' => $entry->getId()],
ce0e9ec3 475 UrlGeneratorInterface::ABSOLUTE_PATH
2863bf2a
JB
476 );
477
e0597476
JB
478 // entry deleted, dispatch event about it!
479 $this->get('event_dispatcher')->dispatch(EntryDeletedEvent::NAME, new EntryDeletedEvent($entry));
480
1d147791
NL
481 $em = $this->getDoctrine()->getManager();
482 $em->remove($entry);
483 $em->flush();
163eae0b
NL
484
485 $this->get('session')->getFlashBag()->add(
486 'notice',
4204a06b 487 'flashes.entry.notice.entry_deleted'
163eae0b 488 );
bd9f0815 489
ce0e9ec3
JB
490 // don't redirect user to the deleted entry (check that the referer doesn't end with the same url)
491 $referer = $request->headers->get('referer');
492 $to = (1 !== preg_match('#'.$url.'$#i', $referer) ? $referer : null);
af497a64
NL
493
494 $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($to);
495
496 return $this->redirect($redirectUrl);
bd9f0815 497 }
3d2b2d62
J
498
499 /**
4346a860 500 * Check if the logged user can manage the given entry.
3d2b2d62
J
501 *
502 * @param Entry $entry
503 */
504 private function checkUserAction(Entry $entry)
505 {
f1be7af4 506 if (null === $this->getUser() || $this->getUser()->getId() != $entry->getUser()->getId()) {
82d6d9cb 507 throw $this->createAccessDeniedException('You can not access this entry.');
3d2b2d62
J
508 }
509 }
b00a89e0
NL
510
511 /**
512 * Check for existing entry, if it exists, redirect to it with a message.
513 *
4094ea47 514 * @param Entry $entry
b00a89e0 515 *
4094ea47 516 * @return Entry|bool
b00a89e0 517 */
4094ea47 518 private function checkIfEntryAlreadyExists(Entry $entry)
b00a89e0
NL
519 {
520 return $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId());
f3d0cb91
NL
521 }
522
f1be7af4
NL
523 /**
524 * Get public URL for entry (and generate it if necessary).
525 *
526 * @param Entry $entry
527 *
528 * @Route("/share/{id}", requirements={"id" = "\d+"}, name="share")
529 *
530 * @return \Symfony\Component\HttpFoundation\Response
531 */
532 public function shareAction(Entry $entry)
533 {
534 $this->checkUserAction($entry);
535
7239082a
NL
536 if (null === $entry->getUid()) {
537 $entry->generateUid();
eddda878
JB
538
539 $em = $this->getDoctrine()->getManager();
540 $em->persist($entry);
541 $em->flush();
f1be7af4
NL
542 }
543
544 return $this->redirect($this->generateUrl('share_entry', [
7239082a 545 'uid' => $entry->getUid(),
f1be7af4
NL
546 ]));
547 }
548
549 /**
550 * Disable public sharing for an entry.
551 *
552 * @param Entry $entry
553 *
554 * @Route("/share/delete/{id}", requirements={"id" = "\d+"}, name="delete_share")
555 *
556 * @return \Symfony\Component\HttpFoundation\Response
557 */
558 public function deleteShareAction(Entry $entry)
559 {
560 $this->checkUserAction($entry);
561
7239082a 562 $entry->cleanUid();
eddda878 563
f1be7af4
NL
564 $em = $this->getDoctrine()->getManager();
565 $em->persist($entry);
566 $em->flush();
567
568 return $this->redirect($this->generateUrl('view', [
569 'id' => $entry->getId(),
570 ]));
571 }
572
d0545b6b 573 /**
eddda878 574 * Ability to view a content publicly.
f3d0cb91
NL
575 *
576 * @param Entry $entry
577 *
7239082a 578 * @Route("/share/{uid}", requirements={"uid" = ".+"}, name="share_entry")
eddda878 579 * @Cache(maxage="25200", smaxage="25200", public=true)
f3d0cb91
NL
580 *
581 * @return \Symfony\Component\HttpFoundation\Response
582 */
d0545b6b 583 public function shareEntryAction(Entry $entry)
f3d0cb91 584 {
eddda878
JB
585 if (!$this->get('craue_config')->get('share_public')) {
586 throw $this->createAccessDeniedException('Sharing an entry is disabled for this user.');
587 }
588
f3d0cb91 589 return $this->render(
2ff9991a 590 '@WallabagCore/themes/common/Entry/share.html.twig',
eddda878 591 ['entry' => $entry]
f3d0cb91
NL
592 );
593 }
b6520f0b
NL
594
595 /**
596 * Shows untagged articles for current user.
597 *
598 * @param Request $request
599 * @param int $page
600 *
601 * @Route("/untagged/list/{page}", name="untagged", defaults={"page" = "1"})
602 *
603 * @return \Symfony\Component\HttpFoundation\Response
604 */
605 public function showUntaggedEntriesAction(Request $request, $page)
606 {
607 return $this->showEntries('untagged', $request, $page);
608 }
46a54f5d 609
46a54f5d
TC
610 /**
611 * Set the progress of an entry.
612 *
613 * @param Entry $entry
614 * @param int $progress
615 *
5fe9aadc 616 * @Route("/progress/{entry}/{progress}", name="set_progress")
46a54f5d
TC
617 *
618 * @return JsonResponse
619 */
5fe9aadc 620 public function setEntriesProgressAction(Entry $entry, $progress = 0)
46a54f5d
TC
621 {
622 $this->checkUserAction($entry);
623 $response = new JsonResponse();
624
5fe9aadc
TC
625 $progress = (int) $progress;
626 if ($progress >= 0 && $progress <= 100) {
627 $em = $this->getDoctrine()->getManager();
628
629 $entry->setProgress($progress);
630
631 $this->get('logger')->info('Set progress to ' . $progress);
632
633 $em->persist($entry);
634 $em->flush();
635
636 $response->setStatusCode(Response::HTTP_OK);
46a54f5d
TC
637 }
638
639 return $response;
640 }
9d50517c 641}