From f20608082a1dd0329e37111668dfa47397f9e334 Mon Sep 17 00:00:00 2001 From: tim Date: Thu, 6 Apr 2023 21:18:57 +0200 Subject: [PATCH] Remove my snips from public snips Remove home button and redirect to snip_index --- src/Controller/HomeController.php | 5 +---- src/Controller/SnipController.php | 2 +- src/Repository/SnipRepository.php | 4 +++- templates/base/navbar.html.twig | 4 ---- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index 6f017e8..3a8587f 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -11,9 +11,6 @@ class HomeController extends AbstractController #[Route('/', name: 'home')] public function home(): Response { -// return $this->redirectToRoute('task_view'); - return $this->render('simple.html.twig', [ - 'text' => 'Welcome!' - ]); + return $this->redirectToRoute('snip_index'); } } \ No newline at end of file diff --git a/src/Controller/SnipController.php b/src/Controller/SnipController.php index 642957e..3646702 100644 --- a/src/Controller/SnipController.php +++ b/src/Controller/SnipController.php @@ -37,7 +37,7 @@ class SnipController extends AbstractController public function public(): Response { return $this->render('snip/index.html.twig', [ - 'snips' => $this->repository->findPublic(), + 'snips' => $this->repository->findPublic($this->getUser()), 'title' => 'Public Snips' ]); } diff --git a/src/Repository/SnipRepository.php b/src/Repository/SnipRepository.php index da6d1a7..c412ca5 100644 --- a/src/Repository/SnipRepository.php +++ b/src/Repository/SnipRepository.php @@ -50,11 +50,13 @@ class SnipRepository extends ServiceEntityRepository return $qb->getQuery()->getResult(); } - public function findPublic(): array + public function findPublic(User $user): array { $qb = $this->createQueryBuilder('s'); $qb->where('s.public = :public') + ->andWhere('s.createdBy != :user') ->setParameter('public', true) + ->setParameter('user', $user) ->orderBy('s.createdAt', 'DESC'); return $qb->getQuery()->getResult(); diff --git a/templates/base/navbar.html.twig b/templates/base/navbar.html.twig index 866ec72..1c187eb 100644 --- a/templates/base/navbar.html.twig +++ b/templates/base/navbar.html.twig @@ -8,10 +8,6 @@