Add staff notes functionality

This commit is contained in:
2024-12-22 01:15:15 +00:00
parent 6b61d1a182
commit 5a531ae171
9 changed files with 624 additions and 3 deletions

View File

@@ -2,21 +2,35 @@
namespace App\Controller;
use App\Entity\MemberCase;
use App\Entity\Messages;
use App\Entity\StaffNote;
use App\Entity\Supervision;
use App\Entity\User;
use App\Entity\UserCase;
use App\Form\StaffNoteFormType;
use App\Libs\Breadcrumb;
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\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Attribute\CurrentUser;
class StaffController extends AbstractController
{
/**
* Variable to store unread notification messages
*
* @var array <int, Message>
*/
private array $msgs;
private int $notificationCount;
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly UserPasswordHasherInterface $userPasswordHasher,
private array $navLinks = []
) {
$this->navLinks = NavList::LIST;
@@ -26,17 +40,203 @@ class StaffController extends AbstractController
#[Route('/staff-dashboard', name: 'app_staff_dashboard')]
public function staffDashboard(#[CurrentUser()] User $user): Response
{
$this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user);
$this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user);
$sups = $this->entityManager->getRepository(Supervision::class)->findBy(['supervisor' => $user]);
$staff = [];
foreach ($sups as $sup) {
$staff[] = $sup->getWorker();
}
return $this->render(
'internal/staff/staff-dashboard.html.twig',
array_merge(
$this->navLinks,
[
'staff' => $staff,
'breadcrumbs' => [
new Breadcrumb('', 'Staff Dashboard')
],
'notifications' => $user->retrieveUnreadNotifications(),
'notifications' => $this->msgs,
'notificationCount' => $this->notificationCount,
]
)
);
}
#[Route('/staff/my-cases', name:'app_staff_my_cases')]
public function staffMyCases(#[CurrentUser()] User $user): Response
{
$this->denyAccessUnlessGranted('IS_FULLY_AUTHENTICATED');
$this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user);
$this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user);
$ucs = $this->entityManager->getRepository(UserCase::class)->findBy(['user' => $user]);
$cases = [];
$this->navLinks['staff_dashboard'] = 'nav-link text-dark';
$this->navLinks['staff_notes'] = NavList::PRESENT_LINK;
foreach ($ucs as $uc) {
$cases[] = $uc->getMemberCase();
}
return $this->render(
'internal/staff/cases/my-cases.html.twig',
array_merge(
$this->navLinks,
[
'cases' => $cases,
'user' => $user,
'breadcrumbs' => [
new Breadcrumb($this->generateUrl('app_staff_dashboard'), 'Staff Dashboard'),
new Breadcrumb('', 'Staff Cases')
],
'notifications' => $this->msgs,
'notificationCount' => $this->notificationCount,
]
)
);
}
#[Route('/staff/{staffId}', name: 'app_staff_cases')]
public function staffCases(string $staffId, #[CurrentUser()] User $user): Response
{
$this->denyAccessUnlessGranted(['ROLE_ADMIN', 'ROLE_CASE_MANAGER']);
$this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user);
$this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user);
$staff = $this->entityManager->getRepository(User::class)->find($staffId);
$ucs = $this->entityManager->getRepository(UserCase::class)->findBy(['user' => $staff]);
$cases = [];
foreach ($ucs as $case) {
/** @var UserCase $case */
$cases[] = $case->getMemberCase();
}
return $this->render(
'internal/staff/cases/staff-cases.html.twig',
array_merge(
$this->navLinks,
[
'staffId' => $staffId,
'cases' => $cases,
'breadcrumbs' => [
new Breadcrumb($this->generateUrl('app_staff_dashboard'), 'Staff Dashboard'),
new Breadcrumb('', 'Staff Cases')
],
'notifications' => $this->msgs,
'notificationCount' => $this->notificationCount,
]
)
);
}
#[Route('/staff/{staffId}/case/{caseId}/list-notes', name: 'app_staff_list_notes')]
public function staffListNotes(string $staffId, string $caseId, #[CurrentUser()] User $user): Response
{
$this->denyAccessUnlessGranted('IS_FULLY_AUTHENTICATED');
$this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user);
$this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user);
$staff = $this->entityManager->getRepository(User::class)->find($staffId);
$case = $this->entityManager->getRepository(MemberCase::class)->find($caseId);
$staffNotes = $this->entityManager->getRepository(StaffNote::class)->findBy(['memberCase' => $case]);
return $this->render(
'internal/staff/notes/list-notes.html.twig',
array_merge(
$this->navLinks,
[
'staffId' => $staffId,
'staff' => $staff,
'case' => $case,
'staffNotes' => $staffNotes,
'breadcrumbs' => [
new Breadcrumb($this->generateUrl('app_staff_dashboard'), 'Staff Dashboard'),
new Breadcrumb(
$this->generateUrl(
($staffId == $user->getId()->toHex() ? 'app_staff_my_cases' : 'app_staff_cases'),
['staffId' => $staffId]
),
($staffId == $user->getId()->toHex() ? 'My Cases' : 'Staff Cases')
),
new Breadcrumb('', 'List Notes')
],
'notifications' => $this->msgs,
'notificationCount' => $this->notificationCount,
]
)
);
}
#[Route('/staff/add-note/{caseId}', name: 'app_staff_add_note')]
public function addNote(string $caseId, #[CurrentUser()] User $user, Request $request): Response
{
$this->denyAccessUnlessGranted('IS_FULLY_AUTHENTICATED');
$this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user);
$this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user);
$case = $this->entityManager->getRepository(MemberCase::class)->find($caseId);
$form = $this->createForm(StaffNoteFormType::class);
$this->navLinks['staff_dashboard'] = 'nav-link text-dark';
$this->navLinks['staff_notes'] = NavList::PRESENT_LINK;
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$note = $form->getData();
$note->setMemberCase($case);
$this->entityManager->persist($note);
$this->entityManager->flush();
return $this->redirectToRoute('app_staff_list_notes', ['staffId' => $user->getId()->toHex(), 'caseId' => $caseId]);
}
return $this->render(
'internal/staff/notes/add-note.html.twig',
array_merge(
$this->navLinks,
[
'case' => $case,
'form' => $form,
'breadcrumbs' => [
new Breadcrumb($this->generateUrl('app_staff_dashboard'), 'Staff Dashboard'),
new Breadcrumb($this->generateUrl('app_staff_list_notes', ['staffId' => $user->getId()->toHex(), 'caseId' => $caseId]), 'My Cases'),
new Breadcrumb('', 'Add Note'),
],
'notifications' => $this->msgs,
'notificationCount' => $this->notificationCount,
]
)
);
}
#[Route('/staff/edit-note/{noteId}', name: 'app_staff_edit_note')]
public function editNote(string $noteId, #[CurrentUser()] User $user, Request $request): Response
{
$this->denyAccessUnlessGranted('IS_FULLY_AUTHENTICATED');
$this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user);
$this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user);
$note = $this->entityManager->getRepository(StaffNote::class)->find($noteId);
$case = $note->getMemberCase();
$form = $this->createForm(StaffNoteFormType::class, $note);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->entityManager->flush();
$this->addFlash('info', 'Staff notes updated');
$this->redirectToRoute('app_staff_list_note', ['staffId' => $user->getId()->toHex(), 'caseId' => $case->getId()->toHex()]);
}
return new Response();
}
}