diff --git a/src/Controller/AdminController.php b/src/Controller/AdminController.php index 5895196..c0fbeae 100644 --- a/src/Controller/AdminController.php +++ b/src/Controller/AdminController.php @@ -2,8 +2,10 @@ namespace App\Controller; +use App\Entity\Messages; use App\Entity\Supervision; use App\Entity\User; +use App\Factory\MessageFactory; use App\Form\EditUserFormType; use App\Form\SupervisorFormType; use App\Form\UserFormType; @@ -22,6 +24,10 @@ use Symfony\Component\Security\Http\Attribute\IsGranted; #[IsGranted('ROLE_ADMIN')] class AdminController extends AbstractController { + private array $msgs; + + private int $notificationCount = 0; + public function __construct( private readonly EntityManagerInterface $entityManager, private readonly UserPasswordHasherInterface $userPasswordHasher, @@ -35,6 +41,8 @@ class AdminController extends AbstractController { $this->denyAccessUnlessGranted('ROLE_ADMIN'); $this->navLinks['admin_dashboard'] = NavList::PRESENT_LINK; + $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user); + $this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user); return $this->render( 'internal/admin/admin-dashboard.html.twig', @@ -44,7 +52,8 @@ class AdminController extends AbstractController 'breadcrumbs' => [ new Breadcrumb($this->generateUrl('app_admin_dashboard'), 'Admin Dashboard') ], - 'notifications' => $user->retrieveUnreadNotifications(), + 'notifications' => $this->msgs, + 'notificationCount' => $this->notificationCount, ] ) ); @@ -54,6 +63,8 @@ class AdminController extends AbstractController public function listUsers(#[CurrentUser()] User $user): Response { $this->denyAccessUnlessGranted('ROLE_ADMIN'); + $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user); + $this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user); /** @var UserRepository $repo */ $repo = $this->entityManager->getRepository(User::class); @@ -77,7 +88,8 @@ class AdminController extends AbstractController new Breadcrumb($this->generateUrl('app_list_users'), 'List Users') ], 'users' => $users, - 'notifications' => $user->retrieveUnreadNotifications(), + 'notifications' => $this->msgs, + 'notificationCount' => $this->notificationCount, ] ) ); @@ -87,6 +99,8 @@ class AdminController extends AbstractController public function addUser(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); $user = new User(); $form = $this->createForm(UserFormType::class, $user); @@ -128,6 +142,10 @@ class AdminController extends AbstractController ->setLevel($form->get('level')->getData()) ->setCompany($admin->getCompany()); + + $msg = MessageFactory::createUser($admin, $user, 'Welcome', "Welcome to CM Tracker"); + + $this->entityManager->persist($msg); $this->entityManager->persist($user); $this->entityManager->flush(); @@ -148,7 +166,8 @@ class AdminController extends AbstractController new Breadcrumb($this->generateUrl('app_add_user'), 'Add User') ], 'form' => $form, - 'notifications' => $admin->retrieveUnreadNotifications(), + 'notifications' => $this->msgs, + 'notificationCount' => $this->notificationCount, ] ) ); @@ -159,6 +178,8 @@ class AdminController extends AbstractController { /** @var UserRepository $userRepo */ $userRepo = $this->entityManager->getRepository(User::class); + $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($admin); + $this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($admin); /** @var User $user */ $user = $userRepo->find($id); @@ -195,7 +216,8 @@ class AdminController extends AbstractController ], 'data' => $user, 'form' => $form, - 'notifications' => $admin->retrieveUnreadNotifications(), + 'notifications' => $this->msgs, + 'notificationCount' => $this->notificationCount, ] ) ); @@ -206,6 +228,8 @@ class AdminController extends AbstractController { /** @var UserRepository $userRepo */ $userRepo = $this->entityManager->getRepository(User::class); + $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($admin); + $this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($admin); /** @var User $user */ $user = $userRepo->find($id); @@ -226,7 +250,12 @@ class AdminController extends AbstractController $sup->setSupervisor($supervisor); $sup->setWorker($user); + $supMsg = MessageFactory::createUser($admin, $supervisor, 'New Case Worker', "You've been assigned a new case worker, {$user->getName()}"); + $userMsg = MessageFactory::createUser($admin, $user, 'New Staff Supervisor', "You've been assigned a new staff supervisor {$supervisor->getName()}"); + $this->entityManager->persist($sup); + $this->entityManager->persist($userMsg); + $this->entityManager->persist($supMsg); $this->entityManager->flush(); return $this->redirectToRoute('app_list_users'); @@ -244,7 +273,8 @@ class AdminController extends AbstractController 'user' => $user, 'form' => $form, 'supervisors' => $userRepo->getCaseManagers($admin->getCompany()), - 'notifications' => $admin->retrieveUnreadNotifications(), + 'notifications' => $this->msgs, + 'notificationCount' => $this->notificationCount, ] ) ); diff --git a/src/Controller/CommunityResourceController.php b/src/Controller/CommunityResourceController.php index 2b5d3a9..65cb444 100644 --- a/src/Controller/CommunityResourceController.php +++ b/src/Controller/CommunityResourceController.php @@ -3,6 +3,7 @@ namespace App\Controller; use App\Entity\CommunityResource; +use App\Entity\Messages; use App\Entity\User; use App\Form\ResourceFormType; use App\Libs\Breadcrumb; @@ -17,6 +18,15 @@ use Symfony\Component\Validator\Constraints\Regex; class CommunityResourceController extends AbstractController { + /** + * Variable to store unread notification messages + * + * @var array + */ + private array $msgs; + + private int $notificationCount; + public function __construct( private readonly EntityManagerInterface $entityManager, private array $navLinks = [] @@ -29,6 +39,8 @@ class CommunityResourceController extends AbstractController public function list(#[CurrentUser()] User $user): Response { $rsc = $this->entityManager->getRepository(CommunityResource::class)->findAll(); + $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user); + $this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user); return $this->render( 'internal/community_resource/list.html.twig', @@ -39,7 +51,8 @@ class CommunityResourceController extends AbstractController new Breadcrumb('#', 'Community Resources') ], 'resources' => $rsc, - 'notifications' => $user->retrieveUnreadNotifications(), + 'notifications' => $this->msgs, + 'notificationCount' => $this->notificationCount, ] ) ); @@ -55,6 +68,9 @@ class CommunityResourceController extends AbstractController #[Route('/resource/add', name: 'app_community_resource_add')] public function add(#[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 = $this->createForm(ResourceFormType::class); $form->handleRequest($request); @@ -63,6 +79,8 @@ class CommunityResourceController extends AbstractController $this->entityManager->persist($rsc); $this->entityManager->flush(); + $this->addFlash('success', 'Resource added successfully'); + return $this->redirectToRoute('app_community_resource'); } @@ -76,7 +94,8 @@ class CommunityResourceController extends AbstractController new Breadcrumb($this->generateUrl('app_community_resource'), 'List Resources'), new Breadcrumb('#', 'Add Resource') ], - 'notifications' => $user->retrieveUnreadNotifications(), + 'notifications' => $this->msgs, + 'notificationCount' => $this->notificationCount, ] ) ); @@ -86,6 +105,9 @@ class CommunityResourceController extends AbstractController #[Route('/resource/edit/{id}', name: 'app_community_resource_edit')] public function edit(string $id, #[CurrentUser()] User $user, Request $request): Response { + $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user); + $this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user); + $rsc = $this->entityManager->getRepository(CommunityResource::class)->find($id); $form = $this->createForm(ResourceFormType::class, $rsc); @@ -94,6 +116,8 @@ class CommunityResourceController extends AbstractController if ($form->isSubmitted() && $form->isValid()) { $this->entityManager->flush(); + $this->addFlash('success', 'Resource updated successfully'); + return $this->redirectToRoute('app_community_resource'); } @@ -107,7 +131,8 @@ class CommunityResourceController extends AbstractController new Breadcrumb($this->generateUrl('app_community_resource'), 'List Resources'), new Breadcrumb('#', 'Edit Resource') ], - 'notifications' => $user->retrieveUnreadNotifications(), + 'notifications' => $this->msgs, + 'notificationCount' => $this->notificationCount, ] ) ); diff --git a/src/Controller/DefaultController.php b/src/Controller/DefaultController.php index fdad894..a74632e 100644 --- a/src/Controller/DefaultController.php +++ b/src/Controller/DefaultController.php @@ -2,7 +2,9 @@ namespace App\Controller; +use App\Entity\Messages; use App\Entity\User; +use App\Libs\Breadcrumb; use App\Libs\NavList; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; @@ -14,6 +16,14 @@ use Symfony\Component\Security\Http\Attribute\CurrentUser; class DefaultController extends AbstractController { + /** + * Variable to store unread notification messages + * + * @var array + */ + private array $msgs; + + private int $notificationCount = 0; public function __construct( private readonly EntityManagerInterface $entityManager, @@ -27,6 +37,8 @@ class DefaultController extends AbstractController public function dashboard(Request $request, #[CurrentUser()] ?User $user): Response { $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY'); + $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user); + $this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user); if (!$user->getCompany()) { return $this->redirectToRoute('app_register_step', ['step' => RegistrationController::REGISTER_STEP_TWO]); @@ -40,9 +52,10 @@ class DefaultController extends AbstractController $this->navLinks, [ 'breadcrumbs' => [ - 'Dashboard' + new Breadcrumb('', 'Dashboard') ], - 'notifications' => $user->retrieveUnreadNotifications(), + 'notifications' => $this->msgs, + 'notificationCount' => $this->notificationCount, ] ) ); @@ -52,6 +65,8 @@ class DefaultController extends AbstractController public function profile(#[CurrentUser()] User $user): Response { $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY'); + $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user); + $this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user); $this->navLinks['profile'] = NavList::PRESENT_LINK; @@ -61,9 +76,10 @@ class DefaultController extends AbstractController $this->navLinks, [ 'breadcrumbs' => [ - 'Profile' + new Breadcrumb('', 'Profile') ], - 'notifications' => $user->retrieveUnreadNotifications(), + 'notifications' => $this->msgs, + 'notificationCount' => $this->notificationCount, ] ) ); diff --git a/src/Controller/MemberController.php b/src/Controller/MemberController.php index 593fdac..97f2ad3 100644 --- a/src/Controller/MemberController.php +++ b/src/Controller/MemberController.php @@ -5,6 +5,7 @@ namespace App\Controller; use App\Entity\Member; use App\Entity\User; use App\Entity\MemberCase; +use App\Entity\Messages; use App\Form\MemberFormType; use App\Libs\Breadcrumb; use App\Libs\NavList; @@ -17,6 +18,15 @@ use Symfony\Component\Security\Http\Attribute\CurrentUser; class MemberController 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 = [], @@ -28,6 +38,9 @@ class MemberController extends AbstractController #[Route('/list-members/{id}', name: 'app_case_members')] public function listMembers(Request $request, #[CurrentUser()] User $user, string $id): Response { + $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($id); $members = $this->entityManager->getRepository(Member::class)->getCaseMembersByName($case); @@ -40,9 +53,10 @@ class MemberController extends AbstractController new Breadcrumb($this->generateUrl('app_list_cases'), 'List Cases'), new Breadcrumb($this->generateUrl('app_case_members', ['id' => $id]), 'List Members'), ], - 'notifications' => $user->retrieveUnreadNotifications(), + 'notifications' => $this->msgs, 'case' => $case, 'members' => $members, + 'notificationCount' => $this->notificationCount, ] ) ); @@ -51,6 +65,9 @@ class MemberController extends AbstractController #[Route('/add-member/{id}', name: 'app_case_add_member')] public function addMember(Request $request, #[CurrentUser()] User $user, string $id): Response { + $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user); + $this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user); + /** @var MemberCase $case */ $case = $this->entityManager->getRepository(MemberCase::class)->find($id); @@ -110,9 +127,10 @@ class MemberController extends AbstractController new Breadcrumb($this->generateUrl('app_case_members', ['id' => $id]), 'List Members'), new Breadcrumb($this->generateUrl('app_case_add_member', ['id' => $id]), 'Add Member'), ], - 'notifications' => $user->retrieveUnreadNotifications(), + 'notifications' => $this->msgs, 'case' => $case, 'form' => $form->createView(), + 'notificationCount' => $this->notificationCount, ] ) ); @@ -121,6 +139,9 @@ class MemberController extends AbstractController #[Route('/case/{caseId}/edit-member/{memberId}', name: 'app_case_edit_member')] public function editMember(Request $request, #[CurrentUser()] User $user, string $caseId, string $memberId): Response { + $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user); + $this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user); + $member = $this->entityManager->getRepository(Member::class)->find($memberId); $form = $this->createForm(MemberFormType::class, $member); @@ -175,7 +196,8 @@ class MemberController extends AbstractController new Breadcrumb($this->generateUrl('app_case_members', ['id' => $caseId]), 'List Members'), new Breadcrumb($this->generateUrl('app_case_edit_member', ['caseId' => $caseId, 'memberId' => $memberId]), 'Edit Member'), ], - 'notifications' => $user->retrieveUnreadNotifications(), + 'notifications' => $this->msgs, + 'notificationCount' => $this->notificationCount, 'member' => $member, 'form' => $form->createView(), 'caseId' => $caseId, diff --git a/src/Controller/MessageController.php b/src/Controller/MessageController.php new file mode 100644 index 0000000..64241bc --- /dev/null +++ b/src/Controller/MessageController.php @@ -0,0 +1,30 @@ +entityManager->getRepository(Messages::class)->find($msgId); + $message->setReceived(new \DateTimeImmutable()); + $this->entityManager->flush(); + + return new JsonResponse(true, Response::HTTP_OK); + } +} diff --git a/src/Controller/NoteController.php b/src/Controller/NoteController.php index b4db534..322c948 100644 --- a/src/Controller/NoteController.php +++ b/src/Controller/NoteController.php @@ -3,6 +3,7 @@ namespace App\Controller; use App\Entity\Member; +use App\Entity\Messages; use App\Entity\Referral; use App\Entity\StandardNote; use App\Entity\User; @@ -24,6 +25,15 @@ use Symfony\Component\Security\Http\Attribute\CurrentUser; class NoteController 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 = [], @@ -35,6 +45,9 @@ class NoteController extends AbstractController #[Route('/list-notes/{id?null}', name: 'app_list_notes')] public function listNotes(#[CurrentUser()] User $user, ?string $id = null): 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 = []; @@ -71,9 +84,10 @@ class NoteController extends AbstractController 'breadcrumbs' => [ new Breadcrumb($this->generateUrl('app_list_notes'), 'List Notes') ], - 'notifications' => $user->retrieveUnreadNotifications(), + 'notifications' => $this->msgs, 'cases' => $cases, 'notes' => $notes, + 'notificationCount' => $this->notificationCount, ] ) ); @@ -85,8 +99,8 @@ class NoteController extends AbstractController /** @var Referral $referral */ $referral = $this->entityManager->getRepository(Referral::class)->find($id); $this->entityManager->getRepository(Referral::class)->populateNotes($referral); - - //dd($referral); + $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user); + $this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user); $members = $this->entityManager->getRepository(Member::class)->findBy(['caseId' => $referral->getMemberCase()]); $defaultMethod = NoteMethod::BILLABLE; @@ -128,23 +142,31 @@ class NoteController extends AbstractController 'breadcrumbs' => [ new Breadcrumb($this->generateUrl('app_list_notes'), 'List Notes') ], - 'notifications' => $user->retrieveUnreadNotifications(), + 'notifications' => $this->msgs, 'referral' => $referral, 'form' => $form, 'default_method' => $defaultMethod, 'default_location' => $defaultLocation, + 'notificationCount' => $this->notificationCount, ] ) ); } - #[Route('/edit-note', name: 'app_edit_note')] - public function editNote(): Response + #[Route('/edit-note/{noteId}', name: 'app_edit_note')] + public function editNote(string $noteId, #[CurrentUser()] User $user, Request $request): Response { + $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user); + $this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user); + return $this->render( 'internal/cases/notes/edit-note.html.twig', array_merge( $this->navLinks, + [ + 'notifications' => $this->msgs, + 'notificationCount' => $this->notificationCount, + ] ) ); } diff --git a/src/Controller/ReferralController.php b/src/Controller/ReferralController.php index 1340a3b..d5962da 100644 --- a/src/Controller/ReferralController.php +++ b/src/Controller/ReferralController.php @@ -3,8 +3,11 @@ namespace App\Controller; use App\Entity\MemberCase; +use App\Entity\Messages; use App\Entity\Referral; use App\Entity\User; +use App\Entity\UserCase; +use App\Factory\MessageFactory; use App\Form\ReferralFormType; use App\Libs\Breadcrumb; use App\Libs\NavList; @@ -17,6 +20,15 @@ use Symfony\Component\Security\Http\Attribute\CurrentUser; class ReferralController 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 = [] @@ -26,8 +38,11 @@ class ReferralController extends AbstractController } #[Route('/list-referrals/{id}', name: 'app_list_referrals')] - public function listReferrals(Request $request, #[CurrentUser()] User $user, string $id): Response + public function listReferrals(#[CurrentUser()] User $user, string $id): Response { + $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($id); $openReferrals = $this->entityManager->getRepository(Referral::class)->getActiveReferrals($case); $closedReferrals = $this->entityManager->getRepository(Referral::class)->getClosedReferrals($case); @@ -41,7 +56,8 @@ class ReferralController extends AbstractController new Breadcrumb($this->generateUrl('app_list_cases'), 'List Cases'), new Breadcrumb($this->generateUrl('app_list_referrals', ['id' => $case->getId()]), 'Referrals'), ], - 'notifications' => $user->retrieveUnreadNotifications(), + 'notifications' => $this->msgs, + 'notificationCount' => $this->notificationCount, 'case' => $case, 'openReferrals' => $openReferrals, 'closedReferrals' => $closedReferrals, @@ -53,7 +69,13 @@ class ReferralController extends AbstractController #[Route('/add-referral/{id}', name: 'app_case_add_referral')] public function addReferral(Request $request, #[CurrentUser()] User $user, string $id): 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); + $case = $this->entityManager->getRepository(MemberCase::class)->find($id); + /** @var UserCase $uc */ + $uc = $this->entityManager->getRepository(UserCase::class)->findBy(['memberCase' => $case]); $referral = new Referral(); $form = $this->createForm(ReferralFormType::class, $referral); @@ -64,6 +86,9 @@ class ReferralController extends AbstractController $referral = $form->getData(); $referral->setMemberCase($case); + $msg = MessageFactory::createReferral($user, $uc->getUser(), $case); + + $this->entityManager->persist($msg); $this->entityManager->persist($referral); $this->entityManager->flush(); @@ -80,7 +105,8 @@ class ReferralController extends AbstractController new Breadcrumb($this->generateUrl('app_list_referrals', ['id' => $case->getId()]), 'Referrals'), new Breadcrumb($this->generateUrl('app_case_add_referral', ['id' => $case->getId()]), 'Add Referral') ], - 'notifications' => $user->retrieveUnreadNotifications(), + 'notifications' => $this->msgs, + 'notificationCount' => $this->notificationCount, 'case' => $case, 'form' => $form, ] @@ -91,8 +117,14 @@ class ReferralController extends AbstractController #[Route('/case/{caseId}/edit-referral/{referralId}', name: 'app_case_edit_referral')] public function editReferral(Request $request, #[CurrentUser()] User $user, string $caseId, string $referralId): 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); + $referral = $this->entityManager->getRepository(Referral::class)->find($referralId); $case = $this->entityManager->getRepository(MemberCase::class)->find($caseId); + /** @var UserCase $uc */ + $uc = $this->entityManager->getRepository(UserCase::class)->findBy(['case' => $case]); $form = $this->createForm(ReferralFormType::class, $referral); $form->handleRequest($request); @@ -100,6 +132,9 @@ class ReferralController extends AbstractController if ($form->isSubmitted() && $form->isValid()) { $referral = $form->getData(); + $msg = MessageFactory::createReferral($user, $uc->getUser(), $case); + + $this->entityManager->persist($msg); $this->entityManager->flush(); return $this->redirectToRoute('app_list_referrals', ['id' => $case->getId()]); @@ -115,7 +150,8 @@ class ReferralController extends AbstractController new Breadcrumb($this->generateUrl('app_list_referrals', ['id' => $case->getId()]), 'Referrals'), new Breadcrumb($this->generateUrl('app_case_edit_referral', ['caseId' => $case->getId(), 'referralId' => $referral->getId()]), 'Edit Referral'), ], - 'notifications' => $user->retrieveUnreadNotifications(), + 'notifications' => $this->msgs, + 'notificationCount' => $this->notificationCount, 'case' => $case, 'form' => $form, 'referral' => $referral, diff --git a/src/Controller/ReferralSourceController.php b/src/Controller/ReferralSourceController.php index fffa199..e659db8 100644 --- a/src/Controller/ReferralSourceController.php +++ b/src/Controller/ReferralSourceController.php @@ -2,6 +2,7 @@ namespace App\Controller; +use App\Entity\Messages; use App\Entity\ReferralSource; use App\Entity\User; use App\Form\ReferralSourceFormType; @@ -16,6 +17,15 @@ use Symfony\Component\Security\Http\Attribute\CurrentUser; class ReferralSourceController extends AbstractController { + /** + * Variable to store unread notification messages + * + * @var array + */ + private array $msgs; + + private int $notificationCount; + public function __construct( private EntityManagerInterface $entityManager, private array $navList = [] @@ -28,6 +38,8 @@ class ReferralSourceController extends AbstractController public function listReferralSources(#[CurrentUser()] User $user): Response { $this->denyAccessUnlessGranted('ROLE_ADMIN'); + $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user); + $this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user); $sources = $this->entityManager->getRepository(ReferralSource::class)->retrieveOrderedList(); @@ -37,7 +49,8 @@ class ReferralSourceController extends AbstractController $this->navList, [ 'sources' => $sources, - 'notifications' => $user->retrieveUnreadNotifications(), + 'notifications' => $this->msgs, + 'notificationCount' => $this->notificationCount, 'breadcrumbs' => [ new Breadcrumb($this->generateUrl('app_referral_source'), 'Referral Sources') ] @@ -50,6 +63,8 @@ class ReferralSourceController extends AbstractController public function addSource(Request $request, #[CurrentUser()] User $user): Response { $this->denyAccessUnlessGranted('ROLE_ADMIN'); + $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user); + $this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user); $rs = new ReferralSource(); $form = $this->createForm(ReferralSourceFormType::class, $rs); @@ -73,7 +88,8 @@ class ReferralSourceController extends AbstractController $this->navList, [ 'form' => $form, - 'notifications' => $user->retrieveUnreadNotifications(), + 'notifications' => $this->msgs, + 'notificationCount' => $this->notificationCount, 'breadcrumbs' => [ new Breadcrumb($this->generateUrl('app_referral_source'), 'Referral Sources'), new Breadcrumb($this->generateUrl('app_add_source'), 'Add Source') @@ -87,6 +103,8 @@ class ReferralSourceController extends AbstractController public function editSource(Request $request, #[CurrentUser()] User $user, string $id): Response { $this->denyAccessUnlessGranted('ROLE_ADMIN'); + $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user); + $this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user); $rs = $this->entityManager->getRepository(ReferralSource::class)->find($id); @@ -111,7 +129,8 @@ class ReferralSourceController extends AbstractController [ 'form' => $form, 'rs' => $rs, - 'notifications' => $user->retrieveUnreadNotifications(), + 'notifications' => $this->msgs, + 'notificationCount' => $this->notificationCount, 'breadcrumbs' => [ new Breadcrumb($this->generateUrl('app_referral_source'), 'Referral Sources'), new Breadcrumb($this->generateUrl('app_edit_source', ['id' => $id]), 'Edit Source') diff --git a/src/Entity/Messages.php b/src/Entity/Messages.php new file mode 100644 index 0000000..906e35d --- /dev/null +++ b/src/Entity/Messages.php @@ -0,0 +1,144 @@ +id; + } + + public function getSent(): ?\DateTimeImmutable + { + return $this->sent; + } + + public function setSent(\DateTimeImmutable $sent): static + { + $this->sent = $sent; + + return $this; + } + + public function getReceived(): ?\DateTimeImmutable + { + return $this->received; + } + + public function setReceived(?\DateTimeImmutable $received): static + { + $this->received = $received; + + return $this; + } + + public function getRecipient(): ?User + { + return $this->recipient; + } + + public function setRecipient(?User $recipient): static + { + $this->recipient = $recipient; + + return $this; + } + + public function getType(): ?MessageType + { + return $this->type; + } + + public function setType(MessageType $type): static + { + $this->type = $type; + + return $this; + } + + public function getMessage(): ?string + { + return $this->message; + } + + public function setMessage(string $message): static + { + $this->message = $message; + + return $this; + } + + public function getTitle(): ?string + { + return $this->title; + } + + public function setTitle(string $title): static + { + $this->title = $title; + + return $this; + } + + public function getSender(): ?User + { + return $this->sender; + } + + public function setSender(?User $sender): static + { + $this->sender = $sender; + + return $this; + } + + public function toArray(): array + { + return [ + 'id' => $this->id->toHex(), + 'title' => $this->title, + 'sender' => $this->sender->getName(), + 'type' => $this->type->name, + 'date' => $this->sent, + 'message' => $this->message + ]; + } +} diff --git a/src/Enums/MessageType.php b/src/Enums/MessageType.php new file mode 100644 index 0000000..a8c4663 --- /dev/null +++ b/src/Enums/MessageType.php @@ -0,0 +1,17 @@ +setSent(new DateTimeImmutable()) + ->setType(MessageType::GENERAL) + ->setSender($sender) + ->setRecipient($recipient) + ->setMessage($message) + ->setTitle($title) + ; + + return $msg; + } + + public static function createCase(User $sender, User $recipient): Messages + { + $msg = new Messages(); + $msg->setSent(new DateTimeImmutable()) + ->setType(MessageType::CASE) + ->setSender($sender) + ->setRecipient($recipient) + ->setTitle('Case') + ->setMessage("{$sender->getName()} has updated a case") + ; + + return $msg; + } + + public static function createNewCase(User $sender, User $recipient): Messages + { + $msg = new Messages(); + $msg->setSent(new DateTimeImmutable()) + ->setType(MessageType::NEW_CASE) + ->setSender($sender) + ->setRecipient($recipient) + ->setTitle('New Case') + ->setMessage("You've been assigned a new case") + ; + + return $msg; + } + + public static function createStaffing(User $sender, User $recipient): Messages + { + $msg = new Messages(); + $msg->setSent(new DateTimeImmutable()) + ->setType(MessageType::STAFFING) + ->setSender($sender) + ->setRecipient($recipient) + ->setTitle('Staff Notes') + ->setMessage("Staff notes from {$sender->getName()} are ready for your review") + ; + + return $msg; + } + + public static function createBilling(User $sender, User $recipient): Messages + { + $msg = new Messages(); + $msg->setSent(new DateTimeImmutable()) + ->setType(MessageType::BILLING) + ->setSender($sender) + ->setRecipient($recipient) + ->setTitle('New Billing') + ->setMessage("{$sender->getName()} has published their timesheet") + ; + + return $msg; + } + + public static function createReminder(User $sender, User $recipient, string $title, string $message): Messages + { + $msg = new Messages(); + $msg->setSent(new DateTimeImmutable()) + ->setType(MessageType::REMINDER) + ->setSender($sender) + ->setRecipient($recipient) + ->setTitle($title) + ->setMessage($message) + ; + + return $msg; + } + + public static function createUser(User $sender, User $recipient, string $title, string $message): Messages + { + $msg = new Messages(); + $msg->setSent(new DateTimeImmutable()) + ->setType(MessageType::USER) + ->setSender($sender) + ->setRecipient($recipient) + ->setTitle($title) + ->setMessage($message) + ; + + return $msg; + } + + public static function createReferral(User $sender, User $recipient, MemberCase $case): Messages + { + $msg = new Messages(); + $msg->setSender($sender) + ->setRecipient($recipient) + ->setSent(new DateTimeImmutable()) + ->setType(MessageType::NEW_REFERRAL) + ->setTitle('New Referral') + ->setMessage("A referral has been added/updated to case {$case->getCaseName()}") + ; + + return $msg; + } +} \ No newline at end of file diff --git a/src/Repository/MessagesRepository.php b/src/Repository/MessagesRepository.php new file mode 100644 index 0000000..9def04b --- /dev/null +++ b/src/Repository/MessagesRepository.php @@ -0,0 +1,73 @@ + + */ +class MessagesRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Messages::class); + } + + public function getUnreadMessages(User $user): array + { + $query = $this->createQueryBuilder('m') + ->andWhere('m.recipient = :recipient') + ->andWhere('m.received IS NULL') + ->setParameter('recipient', $user->getId()->toBinary()) + ->orderBy('m.sent', 'ASC') + ->setMaxResults(5) + ->getQuery() + ->getResult() + ; + + return $query; + } + + public function getUnreadMessageCount(User $user): int + { + $query = $this->createQueryBuilder('m') + ->andWhere('m.recipient = :recipient') + ->andWhere('m.received IS NULL') + ->setParameter('recipient', $user->getId()->toBinary()) + ->select('COUNT(m)') + ->getQuery() + ->getSingleScalarResult() + ; + + return $query; + } + + // /** + // * @return Messages[] Returns an array of Messages objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('m') + // ->andWhere('m.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('m.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?Messages + // { + // return $this->createQueryBuilder('m') + // ->andWhere('m.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +} diff --git a/templates/internal/admin/cases/assign-case.html.twig b/templates/internal/admin/cases/assign-case.html.twig index 7ec3870..d1304d1 100644 --- a/templates/internal/admin/cases/assign-case.html.twig +++ b/templates/internal/admin/cases/assign-case.html.twig @@ -17,6 +17,7 @@

Assign Case Worker

+

{{ case.level.name|lower|capitalize }}

{{ form_start(form, {'attr': {'onsubmit': 'return validateAssignForm()'}}) }} @@ -38,7 +39,7 @@
   - +
diff --git a/templates/internal/libs/top-nav.html.twig b/templates/internal/libs/top-nav.html.twig index f5d3d10..2773c42 100644 --- a/templates/internal/libs/top-nav.html.twig +++ b/templates/internal/libs/top-nav.html.twig @@ -6,7 +6,7 @@
{% for label, messages in app.flashes %} {% for message in messages %} -
+
{{ message }}
{% endfor %} @@ -37,8 +37,9 @@ {% endif %}