From 5a531ae17138e37e6b4f23ac776d991aeff8db81 Mon Sep 17 00:00:00 2001 From: Ryan Prather Date: Sun, 22 Dec 2024 01:15:15 +0000 Subject: [PATCH] Add staff notes functionality --- src/Controller/StaffController.php | 206 +++++++++++++++++- src/Entity/StaffNote.php | 101 +++++++++ src/Form/StaffNoteFormType.php | 38 ++++ src/Repository/StaffNoteRepository.php | 43 ++++ .../internal/staff/cases/my-cases.html.twig | 44 ++++ .../staff/cases/staff-cases.html.twig | 44 ++++ .../internal/staff/notes/add-note.html.twig | 56 +++++ .../internal/staff/notes/list-notes.html.twig | 60 +++++ .../internal/staff/staff-dashboard.html.twig | 35 +++ 9 files changed, 624 insertions(+), 3 deletions(-) create mode 100644 src/Entity/StaffNote.php create mode 100644 src/Form/StaffNoteFormType.php create mode 100644 src/Repository/StaffNoteRepository.php create mode 100644 templates/internal/staff/cases/my-cases.html.twig create mode 100644 templates/internal/staff/cases/staff-cases.html.twig create mode 100644 templates/internal/staff/notes/add-note.html.twig create mode 100644 templates/internal/staff/notes/list-notes.html.twig diff --git a/src/Controller/StaffController.php b/src/Controller/StaffController.php index 07c02c8..eeb3468 100644 --- a/src/Controller/StaffController.php +++ b/src/Controller/StaffController.php @@ -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 + */ + 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(); + } } diff --git a/src/Entity/StaffNote.php b/src/Entity/StaffNote.php new file mode 100644 index 0000000..f250593 --- /dev/null +++ b/src/Entity/StaffNote.php @@ -0,0 +1,101 @@ +id; + } + + public function getDate(): ?\DateTimeInterface + { + return $this->date; + } + + public function setDate(\DateTimeInterface $date): static + { + $this->date = $date; + + return $this; + } + + public function getMemberCase(): ?MemberCase + { + return $this->memberCase; + } + + public function setMemberCase(?MemberCase $memberCase): static + { + $this->memberCase = $memberCase; + + return $this; + } + + /** + * @return ReferralServiceType[] + */ + public function getServicesProvided(): array + { + return $this->servicesProvided; + } + + public function setServicesProvided(array $servicesProvided): static + { + $this->servicesProvided = $servicesProvided; + + return $this; + } + + public function getNote(): ?string + { + return $this->note; + } + + public function setNote(string $note): static + { + $this->note = $note; + + return $this; + } + + public function getRecommendations(): ?string + { + return $this->recommendations; + } + + public function setRecommendations(string $recommendations): static + { + $this->recommendations = $recommendations; + + return $this; + } +} diff --git a/src/Form/StaffNoteFormType.php b/src/Form/StaffNoteFormType.php new file mode 100644 index 0000000..ecc67dd --- /dev/null +++ b/src/Form/StaffNoteFormType.php @@ -0,0 +1,38 @@ +add('date', null, [ + 'widget' => 'single_text', + ]) + ->add('servicesProvided', EnumType::class, [ + 'class' => ReferralServiceType::class, + 'expanded' => true, + 'multiple' => true, + ]) + ->add('note', TextareaType::class) + ->add('recommendations') + ; + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => StaffNote::class, + ]); + } +} diff --git a/src/Repository/StaffNoteRepository.php b/src/Repository/StaffNoteRepository.php new file mode 100644 index 0000000..e801791 --- /dev/null +++ b/src/Repository/StaffNoteRepository.php @@ -0,0 +1,43 @@ + + */ +class StaffNoteRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, StaffNote::class); + } + + // /** + // * @return StaffNote[] Returns an array of StaffNote objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('s') + // ->andWhere('s.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('s.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?StaffNote + // { + // return $this->createQueryBuilder('s') + // ->andWhere('s.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +} diff --git a/templates/internal/staff/cases/my-cases.html.twig b/templates/internal/staff/cases/my-cases.html.twig new file mode 100644 index 0000000..9a1868c --- /dev/null +++ b/templates/internal/staff/cases/my-cases.html.twig @@ -0,0 +1,44 @@ +{% extends 'base.html.twig' %} + +{% block body %} + {{ block('nav', 'internal/libs/nav.html.twig') }} + +
+ {{ block('topnav', 'internal/libs/top-nav.html.twig') }} +
+
+
+

My Cases

+

+
+ {% for c in cases %} +
+
+
+
+
+

{{ c.caseName }}

+

+ +

+
+
+ weekend +
+
+
+
+ +
+
+ {% endfor %} +
+
+
+{% endblock %} diff --git a/templates/internal/staff/cases/staff-cases.html.twig b/templates/internal/staff/cases/staff-cases.html.twig new file mode 100644 index 0000000..f378d58 --- /dev/null +++ b/templates/internal/staff/cases/staff-cases.html.twig @@ -0,0 +1,44 @@ +{% extends 'base.html.twig' %} + +{% block body %} + {{ block('nav', 'internal/libs/nav.html.twig') }} + +
+ {{ block('topnav', 'internal/libs/top-nav.html.twig') }} +
+
+
+

Staff Cases

+

+
+ {% for c in cases %} +
+
+
+
+
+

{{ c.caseName }}

+

+ +

+
+
+ weekend +
+
+
+
+ +
+
+ {% endfor %} +
+
+
+{% endblock %} diff --git a/templates/internal/staff/notes/add-note.html.twig b/templates/internal/staff/notes/add-note.html.twig new file mode 100644 index 0000000..c7b0608 --- /dev/null +++ b/templates/internal/staff/notes/add-note.html.twig @@ -0,0 +1,56 @@ +{% extends 'base.html.twig' %} + +{% block body %} + {{ block('nav', 'internal/libs/nav.html.twig') }} + +
+ {{ block('topnav', 'internal/libs/top-nav.html.twig') }} + +
+ +
+
+

Case Info

+

+
+
+
+ {{ form_errors(form) }} + + {{ form_start(form) }} +
+
+
+ + +
+ +
+ {{ form_row(form.servicesProvided) }} +
+ +
+ + +
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+ {{ form_end(form) }} +
+
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/templates/internal/staff/notes/list-notes.html.twig b/templates/internal/staff/notes/list-notes.html.twig new file mode 100644 index 0000000..9a6de28 --- /dev/null +++ b/templates/internal/staff/notes/list-notes.html.twig @@ -0,0 +1,60 @@ +{% extends 'base.html.twig' %} + +{% block body %} + {{ block('nav', 'internal/libs/nav.html.twig') }} + +
+ {{ block('topnav', 'internal/libs/top-nav.html.twig') }} + +
+
+
+
+
+
+
+
{{ case.caseName }}
+
+ {% if app.user.id == staffId %} +
+ +
+ {% endif %} +
+
+
+
+ + + + + + + + + {% for n in staffNotes %} + + + + + {% endfor %} + +
Date
+
+
+
{{ n.date|date('F j, Y') }}
+
+
+
+ + edit + +
+
+
+
+
+
+
+
+{% endblock %} diff --git a/templates/internal/staff/staff-dashboard.html.twig b/templates/internal/staff/staff-dashboard.html.twig index 88cafe2..9fce4bc 100644 --- a/templates/internal/staff/staff-dashboard.html.twig +++ b/templates/internal/staff/staff-dashboard.html.twig @@ -5,5 +5,40 @@
{{ block('topnav', 'internal/libs/top-nav.html.twig') }} +
+
+
+

Staff Dashboard

+

+
+ {% for s in staff %} +
+
+
+
+
+

{{ s.name }}

+

+ +

+
+
+ weekend +
+
+
+
+ +
+
+ {% endfor %} +
+
{% endblock %}