navLinks = NavList::LIST; } #[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(); $workers = $this->entityManager->getRepository(User::class)->getCaseWorkers(); return $this->render( 'internal/cases/list-cases.html.twig', array_merge( $this->navLinks, [ 'breadcrumbs' => [ new Breadcrumb($this->generateUrl('app_list_cases'), 'List Cases') ], 'notifications' => $user->retrieveUnreadNotifications(), 'cases' => $cases, 'workers' => $workers, ] ) ); } #[Route('/add-case', name: 'app_add_case')] public function addCase(Request $request, #[CurrentUser()] User $admin): Response { $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); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $case = $form->getData(); $this->entityManager->persist($case); $this->entityManager->flush(); $this->addFlash('success', 'Case added successfully'); return $this->redirectToRoute('app_list_cases'); } return $this->render( 'internal/admin/cases/add-case.html.twig', array_merge( $this->navLinks, [ 'title' => 'Add Case', 'breadcrumbs' => [ new Breadcrumb($this->generateUrl('app_list_cases'), 'List Cases'), new Breadcrumb($this->generateUrl('app_add_case'), 'Add Case') ], 'notifications' => $admin->retrieveUnreadNotifications(), 'form' => $form, 'sources' => $this->entityManager->getRepository(ReferralSource::class)->retrieveOrderedList(), ] ) ); } #[Route('/edit-case/{id}', name: 'app_edit_case')] 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); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $case = $form->getData(); $this->entityManager->flush(); $this->addFlash('success', 'Case updated successfully'); return $this->redirectToRoute('app_list_cases'); } return $this->render( 'internal/admin/cases/edit-case.html.twig', array_merge( $this->navLinks, [ 'title' => 'Edit Case', 'breadcrumbs' => [ new Breadcrumb($this->generateUrl('app_list_cases'), 'List Cases'), new Breadcrumb($this->generateUrl('app_edit_case', ['id' => $id]), 'Edit Case') ], 'notifications' => $admin->retrieveUnreadNotifications(), 'form' => $form, 'case' => $case, 'sources' => $this->entityManager->getRepository(ReferralSource::class)->retrieveOrderedList(), ] ) ); } #[Route('/assign-case/{id}', name: 'app_assign_case')] 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); $prevUc = $this->entityManager->getRepository(UserCase::class)->findBy(['memberCase' => $case]); $uc = new UserCase(); $form = $this->createForm(UserCaseFormType::class, $uc); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $user = $form->get('user')->getData(); $uc = $form->getData(); $uc->setMemberCase($case); $uc->setUser($user); if(!$uc->checkLevel()) { throw new Exception(''); } if (count($prevUc) > 0) { $this->entityManager->remove($prevUc[0]); $this->entityManager->flush(); } $this->entityManager->persist($uc); $this->entityManager->flush(); $this->addFlash('success', 'Case assigned successfully'); return $this->redirectToRoute('app_list_cases'); } return $this->render( 'internal/admin/cases/assign-case.html.twig', array_merge( $this->navLinks, [ 'title' => 'Assign Case', 'breadcrumbs' => [ new Breadcrumb($this->generateUrl('app_list_cases'), 'List Cases'), new Breadcrumb($this->generateUrl('app_assign_case', ['id' => $id]), 'Assign Case') ], 'notifications' => $admin->retrieveUnreadNotifications(), 'form' => $form, 'id' => $id, 'caseWorkers' => $caseWorkers, 'assignedWorkerId' => (count($case->getUserCases()) > 0 ? $case->getUserCases()->first()->getUser()->getId() : null), ] ) ); } #[Route('/api/filter-cases-by-user', name: 'ajax_filter_cases_by_user')] public function filterCasesByUser(Request $request): Response { /** @var User $user */ $user = $this->entityManager->getRepository(User::class)->find($request->query->get('userId')); /** @var UserCase[] $ucs */ $ucs = $this->entityManager->getRepository(UserCase::class)->findBy(['user' => $user]); $ret = []; foreach ($ucs as $uc) { $ret[] = $uc->getMemberCase(); } dump($ret); die; return $this->json($ret); } }