diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller/EntryController.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/EntryController.php | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index fafa49f1..f1376f43 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php | |||
@@ -4,11 +4,15 @@ namespace Wallabag\CoreBundle\Controller; | |||
4 | 4 | ||
5 | use Pagerfanta\Adapter\DoctrineORMAdapter; | 5 | use Pagerfanta\Adapter\DoctrineORMAdapter; |
6 | use Pagerfanta\Exception\OutOfRangeCurrentPageException; | 6 | use Pagerfanta\Exception\OutOfRangeCurrentPageException; |
7 | use Pagerfanta\Pagerfanta; | ||
7 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | 8 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
8 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 9 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
10 | use Symfony\Component\HttpFoundation\RedirectResponse; | ||
9 | use Symfony\Component\HttpFoundation\Request; | 11 | use Symfony\Component\HttpFoundation\Request; |
12 | use Symfony\Component\HttpFoundation\Response; | ||
10 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | 13 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
11 | use Wallabag\CoreBundle\Entity\Entry; | 14 | use Wallabag\CoreBundle\Entity\Entry; |
15 | use Wallabag\CoreBundle\Form\Type\EditGroupSharesType; | ||
12 | use Wallabag\CoreBundle\Form\Type\EntryFilterType; | 16 | use Wallabag\CoreBundle\Form\Type\EntryFilterType; |
13 | use Wallabag\CoreBundle\Form\Type\EditEntryType; | 17 | use Wallabag\CoreBundle\Form\Type\EditEntryType; |
14 | use Wallabag\CoreBundle\Form\Type\NewEntryType; | 18 | use Wallabag\CoreBundle\Form\Type\NewEntryType; |
@@ -16,6 +20,7 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache; | |||
16 | use Wallabag\CoreBundle\Event\EntrySavedEvent; | 20 | use Wallabag\CoreBundle\Event\EntrySavedEvent; |
17 | use Wallabag\CoreBundle\Event\EntryDeletedEvent; | 21 | use Wallabag\CoreBundle\Event\EntryDeletedEvent; |
18 | use Wallabag\CoreBundle\Form\Type\SearchEntryType; | 22 | use Wallabag\CoreBundle\Form\Type\SearchEntryType; |
23 | use Wallabag\GroupBundle\Entity\Group; | ||
19 | 24 | ||
20 | class EntryController extends Controller | 25 | class EntryController extends Controller |
21 | { | 26 | { |
@@ -604,4 +609,88 @@ class EntryController extends Controller | |||
604 | { | 609 | { |
605 | return $this->showEntries('untagged', $request, $page); | 610 | return $this->showEntries('untagged', $request, $page); |
606 | } | 611 | } |
612 | |||
613 | /** | ||
614 | * @Route("/group-articles/{group}/{page}", name="group-presentations", defaults={"page" = "1"}, requirements={"page": "\d+", "group": "\d+"}) | ||
615 | * | ||
616 | * @param Request $request | ||
617 | * @param Group $group | ||
618 | * @param int $page | ||
619 | * @return Response | ||
620 | */ | ||
621 | public function showGroupSharedTemplatesAction(Request $request, Group $group, int $page) | ||
622 | { | ||
623 | if (!$this->getUser()->inGroup($group)) { | ||
624 | throw $this->createAccessDeniedException(); | ||
625 | } | ||
626 | |||
627 | $repository = $this->get('wallabag_core.entry_repository'); | ||
628 | |||
629 | /** @var QueryBuilder $entries */ | ||
630 | $entries = $repository->findByGroup($group->getId()); | ||
631 | |||
632 | $pagerAdapter = new DoctrineORMAdapter($entries->getQuery(), true, false); | ||
633 | $pagerFanta = new Pagerfanta($pagerAdapter); | ||
634 | $pagerFanta->setMaxPerPage(9); | ||
635 | |||
636 | $form = $this->createForm(EntryFilterType::class); | ||
637 | |||
638 | if ($request->query->has($form->getName())) { | ||
639 | // manually bind values from the request | ||
640 | $form->submit($request->query->get($form->getName())); | ||
641 | |||
642 | // build the query from the given form object | ||
643 | $this->get('lexik_form_filter.query_builder_updater')->addFilterConditions($form, $qb); | ||
644 | } | ||
645 | |||
646 | $searchTerm = (isset($request->get('search_entry')['term']) ? $request->get('search_entry')['term'] : ''); | ||
647 | |||
648 | try { | ||
649 | $pagerFanta->setCurrentPage($page); | ||
650 | } catch (OutOfRangeCurrentPageException $e) { | ||
651 | if ($page > 1) { | ||
652 | return $this->redirect($this->generateUrl('group-presentations', [ | ||
653 | 'page' => $pagerFanta->getNbPages(), | ||
654 | 'group' => $group->getId() | ||
655 | ]), 302); | ||
656 | } | ||
657 | } | ||
658 | |||
659 | return $this->render('WallabagCoreBundle:Entry:entries.html.twig', [ | ||
660 | 'form' => $form->createView(), | ||
661 | 'entries' => $pagerFanta, | ||
662 | 'currentPage' => $page, | ||
663 | 'searchTerm' => $searchTerm, | ||
664 | ]); | ||
665 | } | ||
666 | |||
667 | /** | ||
668 | * | ||
669 | * @Route("/entry/group-shares/{entry}", name="group-shares-entry") | ||
670 | * | ||
671 | * @param Request $request | ||
672 | * @param Entry $entry | ||
673 | * @return Response | ||
674 | */ | ||
675 | public function groupShareAction(Request $request, Entry $entry) | ||
676 | { | ||
677 | $this->checkUserAction($entry); | ||
678 | |||
679 | $form = $this->createForm(EditGroupSharesType::class, $entry, ['groups' => $this->getUser()->getGroups()]); | ||
680 | |||
681 | $form->handleRequest($request); | ||
682 | |||
683 | if ($form->isSubmitted() && $form->isValid()) { | ||
684 | $em = $this->getDoctrine()->getManager(); | ||
685 | $em->persist($entry); | ||
686 | $em->flush(); | ||
687 | |||
688 | return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()])); | ||
689 | } | ||
690 | |||
691 | return $this->render('WallabagCoreBundle:Entry:_share_groups.html.twig', [ | ||
692 | 'form' => $form->createView(), | ||
693 | 'entry' => $entry, | ||
694 | ]); | ||
695 | } | ||
607 | } | 696 | } |