From 758a4391877760b3c3ee1f286b71918d2021359d Mon Sep 17 00:00:00 2001 From: Ryan Prather Date: Sun, 5 Jan 2025 06:00:40 +0000 Subject: [PATCH] convert list-notes to not show anything by default but have a few filter fields to display what is needed, change add notes to use different member collection and tables, add filter method --- src/Controller/NoteController.php | 123 +++++++++++++++++++----------- 1 file changed, 79 insertions(+), 44 deletions(-) diff --git a/src/Controller/NoteController.php b/src/Controller/NoteController.php index 322c948..2160f36 100644 --- a/src/Controller/NoteController.php +++ b/src/Controller/NoteController.php @@ -3,12 +3,15 @@ namespace App\Controller; use App\Entity\Member; +use App\Entity\MemberCase; use App\Entity\Messages; use App\Entity\Referral; use App\Entity\StandardNote; +use App\Entity\StandardNoteMember; use App\Entity\User; use App\Entity\UserCase; use App\Entity\VisitNote; +use App\Entity\VisitNoteMembers; use App\Enums\NoteLocation; use App\Enums\NoteMethod; use App\Enums\ReferralServiceType; @@ -16,6 +19,8 @@ use App\Form\StandardNoteFormType; use App\Form\VisitNoteFormType; use App\Libs\Breadcrumb; use App\Libs\NavList; +use DateTime; +use DateTimeZone; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; @@ -42,39 +47,14 @@ class NoteController extends AbstractController $this->navLinks['case_notes'] = NavList::PRESENT_LINK; } - #[Route('/list-notes/{id?null}', name: 'app_list_notes')] - public function listNotes(#[CurrentUser()] User $user, ?string $id = null): Response + #[Route('/list-notes/', name: 'app_list_notes')] + public function listNotes(#[CurrentUser()] User $user, Request $request): Response { $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user); $this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user); /** @var UserCase[] $cases */ $cases = $this->entityManager->getRepository(UserCase::class)->findBy(['user' => $user]); - $referrals = []; - $notes = []; - - if ($id == 'null') { - $id = null; - } - - if ($id) { - $referrals[] = $this->entityManager->getRepository(Referral::class)->find($id); - } else { - foreach ($cases as $case) { - $referrals = array_merge( - $referrals, - $this->entityManager->getRepository(Referral::class)->findBy(['memberCase' => $case->getMemberCase()]) - ); - } - } - - foreach ($referrals as $referral) { - $notes = array_merge( - $notes, - $this->entityManager->getRepository(VisitNote::class)->getOrderedNotes($referral), - $this->entityManager->getRepository(StandardNote::class)->getOrderedNotes($referral), - ); - } return $this->render( 'internal/cases/notes/list-notes.html.twig', @@ -86,18 +66,17 @@ class NoteController extends AbstractController ], 'notifications' => $this->msgs, 'cases' => $cases, - 'notes' => $notes, 'notificationCount' => $this->notificationCount, ] ) ); } - #[Route('/add-note/{id?null}', name: 'app_add_note')] - public function addNote(#[CurrentUser()] User $user, Request $request, ?string $id = null): Response + #[Route('/add-note/{referralId}', name: 'app_add_note')] + public function addNote(#[CurrentUser()] User $user, Request $request, ?string $referralId = null): Response { /** @var Referral $referral */ - $referral = $this->entityManager->getRepository(Referral::class)->find($id); + $referral = $this->entityManager->getRepository(Referral::class)->find($referralId); $this->entityManager->getRepository(Referral::class)->populateNotes($referral); $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user); $this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user); @@ -108,8 +87,8 @@ class NoteController extends AbstractController $form = $this->createForm(StandardNoteFormType::class, null, ['members' => $members]); $template = 'internal/cases/notes/add-standard-note.html.twig'; - if ($id == 'null') { - $id = null; + if ($referralId == 'null') { + $referralId = null; } if ($referral->getServiceCode() == ReferralServiceType::VS_THBB) { @@ -153,19 +132,38 @@ class NoteController extends AbstractController ); } - #[Route('/edit-note/{noteId}', name: 'app_edit_note')] - public function editNote(string $noteId, #[CurrentUser()] User $user, Request $request): Response + #[Route('/edit-note/{noteType}/{noteId}', name: 'app_edit_note')] + public function editNote(string $noteId, string $noteType, #[CurrentUser()] User $user, Request $request): Response { $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user); $this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user); + $form = null; + + /** @var VisitNote|StandardNote $note */ + if ($noteType == 'visit') { + $note = $this->entityManager->getRepository(VisitNote::class)->find($noteId); + $members = $this->entityManager->getRepository(Member::class)->findBy(['memberCase' => $note->getReferral()->getMemberCase()]); + $form = $this->createForm(VisitNoteFormType::class, $note, ['members' => $members]); + } elseif ($noteType == 'standard') { + $note = $this->entityManager->getRepository(StandardNote::class)->find($noteId); + $members = $this->entityManager->getRepository(Member::class)->findBy(['memberCase' => $note->getReferral()->getMemberCase()]); + $form = $this->createForm(StandardNoteFormType::class, $note, ['members' => $members]); + } return $this->render( 'internal/cases/notes/edit-note.html.twig', array_merge( $this->navLinks, [ + 'breadcrumbs' => [ + new Breadcrumb($this->generateUrl('app_list_notes'), 'List Notes') + ], 'notifications' => $this->msgs, 'notificationCount' => $this->notificationCount, + 'note' => $note, + 'referral' => $note->getReferral(), + 'form' => $form, + 'noteType' => $noteType ] ) ); @@ -174,17 +172,54 @@ class NoteController extends AbstractController #[Route('/api/filter-notes', name: 'api_filter_notes')] public function filterNotes(#[CurrentUser()] User $user, Request $request): Response { - $startDate = $request->get('startDate'); - $endDate = $request->get('endDate'); - $referralId = $request->get('referralId'); + $startDate = null; + $endDate = null; $referral = null; - if ($referralId) { - $referral = $this->entityManager->getRepository(Referral::class)->find($referralId); + $case = null; + + if ($request->getPayload()->get('startDate')) { + $startDate = new DateTime($request->getPayload()->get('startDate'), new DateTimeZone('America/Indiana/Indianapolis')); } - return $this->json(array_merge( - $this->entityManager->getRepository(VisitNote::class)->filterNotes($user, $referral, $startDate, $endDate), - $this->entityManager->getRepository(StandardNote::class)->filterNotes($user, $referral, $startDate, $endDate), - )); + if ($request->getPayload()->get('endDate')) { + $endDate = new DateTime($request->getPayload()->get('endDate'), new DateTimeZone('America/Indiana/Indianapolis')); + } + + if ($request->getPayload()->get('referral')) { + $referral = $this->entityManager->getRepository(Referral::class)->find($request->getPayload()->get('referral')); + } + + if ($request->getPayload()->get('case')) { + $case = $this->entityManager->getRepository(MemberCase::class)->find($request->getPayload()->get('case')); + } + + $params = [ + 'startDate' => $startDate, + 'endDate' => $endDate, + 'referral' => $referral, + 'case' => $case, + ]; + + $notes = array_merge( + $this->entityManager->getRepository(VisitNote::class)->filterNotes($user, $params), + $this->entityManager->getRepository(StandardNote::class)->filterNotes($user, $params), + ); + + foreach ($notes as $idx => $note) { + /** @var VisitNote|StandardNote $note */ + + /** @var VisitNoteMember[]|StandardNoteMember[] $members */ + if ($note instanceof VisitNote) { + $members = $this->entityManager->getRepository(VisitNoteMembers::class)->findBy(['note' => $note]); + } elseif ($note instanceof StandardNote) { + $members = $this->entityManager->getRepository(StandardNoteMember::class)->findBy(['note' => $note]); + } else { + continue; + } + + $notes[$idx]->setMembers($members); + } + + return new Response(json_encode($notes, 0, 3)); } }