diff --git a/src/Controller/CaseController.php b/src/Controller/CaseController.php index 8b714ba..b7c69ea 100644 --- a/src/Controller/CaseController.php +++ b/src/Controller/CaseController.php @@ -2,7 +2,6 @@ namespace App\Controller; -use Exception; use App\Entity\MemberCase; use App\Entity\ReferralSource; use App\Entity\User; @@ -25,16 +24,22 @@ class CaseController extends AbstractController private array $navLinks = [] ) { $this->navLinks = NavList::LIST; + $this->navLinks['case_list'] = NavList::PRESENT_LINK; } #[Route('/list-cases', name: 'app_list_cases')] public function listCases(#[CurrentUser()] User $user): Response { - $this->denyAccessUnlessGranted('ROLE_ADMIN'); - - $this->navLinks['case_list'] = 'nav-link text-white active bg-gradient-dark'; - - $cases = $this->entityManager->getRepository(MemberCase::class)->findAll(); + if($this->isGranted('ROLE_ADMIN')) { + $cases = $this->entityManager->getRepository(MemberCase::class)->findAll(); + } else { + $ucs = $this->entityManager->getRepository(UserCase::class)->findBy(['user' => $user]); + $cases = []; + foreach ($ucs as $uc) { + /** @var UserCase $uc */ + $cases[] = $uc->getMemberCase(); + } + } $workers = $this->entityManager->getRepository(User::class)->getCaseWorkers(); return $this->render( @@ -58,8 +63,6 @@ class CaseController extends AbstractController { $this->denyAccessUnlessGranted('ROLE_ADMIN'); - $this->navLinks['case_list'] = 'nav-link text-white active bg-gradient-dark'; - $case = new MemberCase(); $form = $this->createForm(MemberCaseFormType::class, $case); @@ -98,7 +101,6 @@ class CaseController extends AbstractController public function editCase(Request $request, #[CurrentUser()] User $admin, string $id): Response { $this->denyAccessUnlessGranted('ROLE_ADMIN'); - $this->navLinks['case_list'] = 'nav-link text-white active bg-gradient-dark'; $case = $this->entityManager->getRepository(MemberCase::class)->find($id); $form = $this->createForm(MemberCaseFormType::class, $case); @@ -137,7 +139,6 @@ class CaseController extends AbstractController public function assignCase(string $id, Request $request, #[CurrentUser()] User $admin): Response { $this->denyAccessUnlessGranted('ROLE_ADMIN'); - $this->navLinks['case_list'] = 'nav-link text-white active bg-gradient-dark'; $caseWorkers = $this->entityManager->getRepository(User::class)->getCaseWorkers(); $case = $this->entityManager->getRepository(MemberCase::class)->find($id);