From 0c902b93c49557db1ef55be510afc3d7bb4e1aa5 Mon Sep 17 00:00:00 2001 From: Ryan Prather Date: Sun, 22 Dec 2024 01:18:32 +0000 Subject: [PATCH] not sure what I did here --- src/Controller/CaseController.php | 81 ++++++++++++++++++---- src/Entity/MemberCase.php | 111 ++++++++++++++++++++++++++++++ src/Entity/Note.php | 11 ++- 3 files changed, 186 insertions(+), 17 deletions(-) diff --git a/src/Controller/CaseController.php b/src/Controller/CaseController.php index b7c69ea..9dd4b60 100644 --- a/src/Controller/CaseController.php +++ b/src/Controller/CaseController.php @@ -3,9 +3,11 @@ namespace App\Controller; use App\Entity\MemberCase; +use App\Entity\Messages; use App\Entity\ReferralSource; use App\Entity\User; use App\Entity\UserCase; +use App\Factory\MessageFactory; use App\Form\MemberCaseFormType; use App\Form\UserCaseFormType; use App\Libs\Breadcrumb; @@ -19,6 +21,15 @@ use Symfony\Component\Security\Http\Attribute\CurrentUser; class CaseController extends AbstractController { + /** + * Variable to store unread notification messages + * + * @var array + */ + private array $msgs; + + private int $notificationCount; + public function __construct( private EntityManagerInterface $entityManager, private array $navLinks = [] @@ -27,32 +38,59 @@ class CaseController extends AbstractController $this->navLinks['case_list'] = NavList::PRESENT_LINK; } + #[Route('/my-cases', name: 'app_my_cases')] + public function myCases(#[CurrentUser()] User $user): Response + { + $this->navLinks['my_cases'] = NavList::PRESENT_LINK; + $this->navLinks['case_list'] = 'nav-link text-dark'; + $ucs = $this->entityManager->getRepository(UserCase::class)->findBy(['user' => $user]); + $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user); + $this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user); + + $cases = []; + foreach ($ucs as $uc) { + /** @var UserCase $uc */ + $cases[] = $uc->getMemberCase(); + } + + return $this->render( + 'internal/cases/my-cases.html.twig', + array_merge( + $this->navLinks, + [ + 'breadcrumbs' => [ + new Breadcrumb($this->generateUrl('app_my_cases'), 'List Cases') + ], + 'notifications' => $this->msgs, + 'cases' => $cases, + 'notificationCount' => $this->notificationCount, + ] + ) + ); + } + #[Route('/list-cases', name: 'app_list_cases')] public function listCases(#[CurrentUser()] User $user): Response { - if($this->isGranted('ROLE_ADMIN')) { - $cases = $this->entityManager->getRepository(MemberCase::class)->findAll(); - } else { - $ucs = $this->entityManager->getRepository(UserCase::class)->findBy(['user' => $user]); - $cases = []; - foreach ($ucs as $uc) { - /** @var UserCase $uc */ - $cases[] = $uc->getMemberCase(); - } - } + $this->denyAccessUnlessGranted('ROLE_ADMIN'); + + $cases = $this->entityManager->getRepository(MemberCase::class)->findAll(); $workers = $this->entityManager->getRepository(User::class)->getCaseWorkers(); + $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user); + $this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user); return $this->render( - 'internal/cases/list-cases.html.twig', + 'internal/admin/cases/list-cases.html.twig', array_merge( $this->navLinks, [ 'breadcrumbs' => [ new Breadcrumb($this->generateUrl('app_list_cases'), 'List Cases') ], - 'notifications' => $user->retrieveUnreadNotifications(), + 'notifications' => $this->msgs, 'cases' => $cases, 'workers' => $workers, + 'notificationCount' => $this->notificationCount, ] ) ); @@ -62,6 +100,8 @@ class CaseController extends AbstractController public function addCase(Request $request, #[CurrentUser()] User $admin): Response { $this->denyAccessUnlessGranted('ROLE_ADMIN'); + $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($admin); + $this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($admin); $case = new MemberCase(); $form = $this->createForm(MemberCaseFormType::class, $case); @@ -89,7 +129,8 @@ class CaseController extends AbstractController new Breadcrumb($this->generateUrl('app_list_cases'), 'List Cases'), new Breadcrumb($this->generateUrl('app_add_case'), 'Add Case') ], - 'notifications' => $admin->retrieveUnreadNotifications(), + 'notifications' => $this->msgs, + 'notificationCount' => $this->notificationCount, 'form' => $form, 'sources' => $this->entityManager->getRepository(ReferralSource::class)->retrieveOrderedList(), ] @@ -101,6 +142,8 @@ class CaseController extends AbstractController public function editCase(Request $request, #[CurrentUser()] User $admin, string $id): Response { $this->denyAccessUnlessGranted('ROLE_ADMIN'); + $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($admin); + $this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($admin); $case = $this->entityManager->getRepository(MemberCase::class)->find($id); $form = $this->createForm(MemberCaseFormType::class, $case); @@ -126,7 +169,8 @@ class CaseController extends AbstractController new Breadcrumb($this->generateUrl('app_list_cases'), 'List Cases'), new Breadcrumb($this->generateUrl('app_edit_case', ['id' => $id]), 'Edit Case') ], - 'notifications' => $admin->retrieveUnreadNotifications(), + 'notifications' => $this->msgs, + 'notificationCount' => $this->notificationCount, 'form' => $form, 'case' => $case, 'sources' => $this->entityManager->getRepository(ReferralSource::class)->retrieveOrderedList(), @@ -139,6 +183,8 @@ class CaseController extends AbstractController public function assignCase(string $id, Request $request, #[CurrentUser()] User $admin): Response { $this->denyAccessUnlessGranted('ROLE_ADMIN'); + $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($admin); + $this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($admin); $caseWorkers = $this->entityManager->getRepository(User::class)->getCaseWorkers(); $case = $this->entityManager->getRepository(MemberCase::class)->find($id); @@ -159,7 +205,10 @@ class CaseController extends AbstractController $this->entityManager->flush(); } + $msg = MessageFactory::createNewCase($admin, $user); + $this->entityManager->persist($uc); + $this->entityManager->persist($msg); $this->entityManager->flush(); $this->addFlash('success', 'Case assigned successfully'); @@ -177,7 +226,9 @@ class CaseController extends AbstractController new Breadcrumb($this->generateUrl('app_list_cases'), 'List Cases'), new Breadcrumb($this->generateUrl('app_assign_case', ['id' => $id]), 'Assign User') ], - 'notifications' => $admin->retrieveUnreadNotifications(), + 'notifications' => $this->msgs, + 'notificationCount' => $this->notificationCount, + 'case' => $case, 'form' => $form, 'id' => $id, 'caseWorkers' => $caseWorkers, diff --git a/src/Entity/MemberCase.php b/src/Entity/MemberCase.php index 90445c9..48309e0 100644 --- a/src/Entity/MemberCase.php +++ b/src/Entity/MemberCase.php @@ -91,10 +91,31 @@ class MemberCase #[ORM\OneToMany(targetEntity: Referral::class, mappedBy: 'memberCase', orphanRemoval: true)] private Collection $referrals; + /** + * @var Collection + */ + #[ORM\OneToMany(targetEntity: MonthlyCaseNote::class, mappedBy: 'memberCase')] + private Collection $monthlyCaseNotes; + + /** + * @var Collection + */ + #[ORM\OneToMany(targetEntity: Member::class, mappedBy: 'memberCase', orphanRemoval: true)] + private Collection $members; + + /** + * @var Collection + */ + #[ORM\OneToMany(targetEntity: StaffNote::class, mappedBy: 'memberCase')] + private Collection $staffNotes; + public function __construct() { $this->userCases = new ArrayCollection(); $this->referrals = new ArrayCollection(); + $this->monthlyCaseNotes = new ArrayCollection(); + $this->members = new ArrayCollection(); + $this->staffNotes = new ArrayCollection(); } public function getId(): ?Uuid @@ -394,4 +415,94 @@ class MemberCase return $this; } + + /** + * @return Collection + */ + public function getMonthlyCaseNotes(): Collection + { + return $this->monthlyCaseNotes; + } + + public function addMonthlyCaseNote(MonthlyCaseNote $monthlyCaseNote): static + { + if (!$this->monthlyCaseNotes->contains($monthlyCaseNote)) { + $this->monthlyCaseNotes->add($monthlyCaseNote); + $monthlyCaseNote->setMemberCase($this); + } + + return $this; + } + + public function removeMonthlyCaseNote(MonthlyCaseNote $monthlyCaseNote): static + { + if ($this->monthlyCaseNotes->removeElement($monthlyCaseNote)) { + // set the owning side to null (unless already changed) + if ($monthlyCaseNote->getMemberCase() === $this) { + $monthlyCaseNote->setMemberCase(null); + } + } + + return $this; + } + + /** + * @return Collection + */ + public function getMembers(): Collection + { + return $this->members; + } + + public function addMember(Member $member): static + { + if (!$this->members->contains($member)) { + $this->members->add($member); + $member->setCaseId($this); + } + + return $this; + } + + public function removeMember(Member $member): static + { + if ($this->members->removeElement($member)) { + // set the owning side to null (unless already changed) + if ($member->getCaseId() === $this) { + $member->setCaseId(null); + } + } + + return $this; + } + + /** + * @return Collection + */ + public function getStaffNotes(): Collection + { + return $this->staffNotes; + } + + public function addStaffNote(StaffNote $staffNote): static + { + if (!$this->staffNotes->contains($staffNote)) { + $this->staffNotes->add($staffNote); + $staffNote->setMemberCase($this); + } + + return $this; + } + + public function removeStaffNote(StaffNote $staffNote): static + { + if ($this->staffNotes->removeElement($staffNote)) { + // set the owning side to null (unless already changed) + if ($staffNote->getMemberCase() === $this) { + $staffNote->setMemberCase(null); + } + } + + return $this; + } } diff --git a/src/Entity/Note.php b/src/Entity/Note.php index 48b9a1b..0fabaa0 100644 --- a/src/Entity/Note.php +++ b/src/Entity/Note.php @@ -140,6 +140,13 @@ class Note return $this; } + public function setMembers(?array $members): static + { + $this->members = $members; + + return $this; + } + public function getLocation(): ?NoteLocation { return $this->location; @@ -166,10 +173,10 @@ class Note /** * Method to calculate the number of minutes used for a visit rounded to the nearest 15 min increment - * + * * @param int $precision * The number of minutes to round the time to defaulted to 15 - * + * * @return int * The number of minutes calculated */