diff --git a/src/Controller/CaseController.php b/src/Controller/CaseController.php index 6f99c1a..8b714ba 100644 --- a/src/Controller/CaseController.php +++ b/src/Controller/CaseController.php @@ -2,6 +2,7 @@ namespace App\Controller; +use Exception; use App\Entity\MemberCase; use App\Entity\ReferralSource; use App\Entity\User; @@ -140,8 +141,8 @@ class CaseController extends AbstractController $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); @@ -152,10 +153,6 @@ class CaseController extends AbstractController $uc->setMemberCase($case); $uc->setUser($user); - if(!$uc->checkLevel()) { - throw new Exception(''); - } - if (count($prevUc) > 0) { $this->entityManager->remove($prevUc[0]); $this->entityManager->flush(); @@ -177,7 +174,7 @@ class CaseController extends AbstractController 'title' => 'Assign Case', 'breadcrumbs' => [ new Breadcrumb($this->generateUrl('app_list_cases'), 'List Cases'), - new Breadcrumb($this->generateUrl('app_assign_case', ['id' => $id]), 'Assign Case') + new Breadcrumb($this->generateUrl('app_assign_case', ['id' => $id]), 'Assign User') ], 'notifications' => $admin->retrieveUnreadNotifications(), 'form' => $form, @@ -189,6 +186,33 @@ class CaseController extends AbstractController ); } + #[Route('/case-notes/{id}', name: 'app_case_notes')] + public function showCaseNotes(Request $request, string $id): Response + { + $case = $this->entityManager->getRepository(MemberCase::class)->find($id); + return new Response(); + } + + #[Route('/api/case/{caseId}/user/{userId}', name: 'ajax_case_user_level_check')] + public function checkUserCaseLevel(string $caseId, string $userId) : Response + { + $ret = true; + + $user = $this->entityManager->getRepository(User::class)->find($userId); + $case = $this->entityManager->getRepository(MemberCase::class)->find($caseId); + + $res = UserCase::checkLevel($user, $case); + + if (!$res) { + $ret = [ + 'userLevel' => ucwords(str_replace('_', ' ', strtolower($user->getLevel()->name))), + 'caseLevel' => ucwords(str_replace('_', ' ', strtolower($case->getLevel()->name))), + ]; + } + + return $this->json($ret); + } + #[Route('/api/filter-cases-by-user', name: 'ajax_filter_cases_by_user')] public function filterCasesByUser(Request $request): Response {