Completed initial CaseController functionality
This commit is contained in:
parent
065b1ac403
commit
518cd4811d
@ -3,10 +3,15 @@
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\MemberCase;
|
||||
use App\Entity\ReferralSource;
|
||||
use App\Entity\User;
|
||||
use App\Entity\UserCase;
|
||||
use App\Form\MemberCaseFormType;
|
||||
use App\Form\UserCaseFormType;
|
||||
use App\Libs\NavList;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\CurrentUser;
|
||||
@ -14,6 +19,7 @@ use Symfony\Component\Security\Http\Attribute\CurrentUser;
|
||||
class CaseController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private EntityManagerInterface $entityManager,
|
||||
private array $navLinks = []
|
||||
) {
|
||||
$this->navLinks = NavList::LIST;
|
||||
@ -26,8 +32,11 @@ class CaseController extends AbstractController
|
||||
|
||||
$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/case-list.html.twig',
|
||||
'internal/cases/list-cases.html.twig',
|
||||
array_merge(
|
||||
$this->navLinks,
|
||||
[
|
||||
@ -35,13 +44,15 @@ class CaseController extends AbstractController
|
||||
'List Cases'
|
||||
],
|
||||
'notifications' => $user->retrieveUnreadNotifications(),
|
||||
'cases' => $cases,
|
||||
'workers' => $workers,
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[Route('/add-case', name: 'app_case')]
|
||||
public function addCase(#[CurrentUser()] User $admin): Response
|
||||
#[Route('/add-case', name: 'app_add_case')]
|
||||
public function addCase(Request $request, #[CurrentUser()] User $admin): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted('ROLE_ADMIN');
|
||||
|
||||
@ -50,6 +61,17 @@ class CaseController extends AbstractController
|
||||
$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();
|
||||
|
||||
return $this->redirectToRoute('app_list_cases');
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'internal/admin/cases/add-case.html.twig',
|
||||
array_merge(
|
||||
@ -62,6 +84,94 @@ class CaseController extends AbstractController
|
||||
],
|
||||
'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->persist($case);
|
||||
$this->entityManager->flush();
|
||||
|
||||
return $this->redirectToRoute('app_list_cases');
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'internal/admin/cases/edit-case.html.twig',
|
||||
array_merge(
|
||||
$this->navLinks,
|
||||
[
|
||||
'title' => 'Edit Case',
|
||||
'breadcrumbs' => [
|
||||
'Case',
|
||||
'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()) {
|
||||
$uc = $form->getData();
|
||||
$uc->setMemberCase($case);
|
||||
$uc->setUser($form->get('user')->getData());
|
||||
|
||||
if (count($prevUc) > 0) {
|
||||
$this->entityManager->remove($prevUc[0]);
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
|
||||
$this->entityManager->persist($uc);
|
||||
$this->entityManager->flush();
|
||||
|
||||
return $this->redirectToRoute('app_list_cases');
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'internal/admin/cases/assign-case.html.twig',
|
||||
array_merge(
|
||||
$this->navLinks,
|
||||
[
|
||||
'title' => 'Assign Case',
|
||||
'breadcrumbs' => [
|
||||
'Case',
|
||||
'Assign Case'
|
||||
],
|
||||
'notifications' => $admin->retrieveUnreadNotifications(),
|
||||
'form' => $form,
|
||||
'id' => $id,
|
||||
'caseWorkers' => $caseWorkers,
|
||||
'assignedWorkerId' => (count($case->getUserCases()) > 0 ? $case->getUserCases()->first()->getUser()->getId() : null),
|
||||
]
|
||||
)
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user