From 2d7b7e6d129eb02427f0f3581b53994d9ce96edb Mon Sep 17 00:00:00 2001 From: Ryan Prather Date: Fri, 10 Jan 2025 12:44:37 +0000 Subject: [PATCH] remove notificationCount, convert to Libs::getMessages method, change datetime creation to add company timezone, remove CaseController::showCaseNotes --- src/Controller/AdminController.php | 28 +++----- src/Controller/CaseController.php | 108 +++++++++++++++++++---------- 2 files changed, 80 insertions(+), 56 deletions(-) diff --git a/src/Controller/AdminController.php b/src/Controller/AdminController.php index 538c7c4..498c32f 100644 --- a/src/Controller/AdminController.php +++ b/src/Controller/AdminController.php @@ -2,17 +2,21 @@ namespace App\Controller; +use App\Entity\CompanyDocument; use App\Entity\Messages; use App\Entity\Supervision; use App\Entity\User; use App\Factory\MessageFactory; +use App\Form\CompanyDocumentFormType; use App\Form\EditUserFormType; use App\Form\SupervisorFormType; use App\Form\UserFormType; use App\Libs\Breadcrumb; use App\Libs\NavList; +use App\Libs\Libs; use App\Repository\UserRepository; use DateTime; +use DateTimeZone; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; @@ -28,8 +32,6 @@ class AdminController extends AbstractController { private array $msgs; - private int $notificationCount = 0; - public function __construct( private readonly EntityManagerInterface $entityManager, private readonly UserPasswordHasherInterface $userPasswordHasher, @@ -43,8 +45,7 @@ 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); + $this->msgs = Libs::getMessages($user, $this->entityManager); return $this->render( 'internal/admin/admin-dashboard.html.twig', @@ -55,7 +56,6 @@ class AdminController extends AbstractController new Breadcrumb($this->generateUrl('app_admin_dashboard'), 'Admin Dashboard') ], 'notifications' => $this->msgs, - 'notificationCount' => $this->notificationCount, ] ) ); @@ -65,8 +65,7 @@ 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); + $this->msgs = Libs::getMessages($user, $this->entityManager); /** @var UserRepository $repo */ $repo = $this->entityManager->getRepository(User::class); @@ -91,7 +90,6 @@ class AdminController extends AbstractController ], 'users' => $users, 'notifications' => $this->msgs, - 'notificationCount' => $this->notificationCount, ] ) ); @@ -104,8 +102,7 @@ class AdminController extends AbstractController SluggerInterface $slugger ): Response { $this->denyAccessUnlessGranted('ROLE_ADMIN'); - $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($admin); - $this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($admin); + $this->msgs = Libs::getMessages($admin, $this->entityManager); $user = new User(); $form = $this->createForm(UserFormType::class, $user); @@ -146,7 +143,7 @@ class AdminController extends AbstractController ->setRate($form->get('rate')->getData()) ->setLevel($form->get('level')->getData()) ->setCompany($admin->getCompany()) - ->setPasswordChanged(new DateTime()) + ->setPasswordChanged(new DateTime('now', new DateTimeZone($_ENV['COMPANY_TIMEZONE']))) ; if ($form->get('imageName')->getData()) { @@ -187,7 +184,6 @@ class AdminController extends AbstractController ], 'form' => $form, 'notifications' => $this->msgs, - 'notificationCount' => $this->notificationCount, ] ) ); @@ -198,8 +194,7 @@ 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); + $this->msgs = Libs::getMessages($admin, $this->entityManager); /** @var User $user */ $user = $userRepo->find($id); @@ -237,7 +232,6 @@ class AdminController extends AbstractController 'data' => $user, 'form' => $form, 'notifications' => $this->msgs, - 'notificationCount' => $this->notificationCount, ] ) ); @@ -248,8 +242,7 @@ 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); + $this->msgs = Libs::getMessages($admin, $this->entityManager); /** @var User $user */ $user = $userRepo->find($id); @@ -294,7 +287,6 @@ class AdminController extends AbstractController 'form' => $form, 'supervisors' => $userRepo->getCaseManagers($admin->getCompany()), 'notifications' => $this->msgs, - 'notificationCount' => $this->notificationCount, ] ) ); diff --git a/src/Controller/CaseController.php b/src/Controller/CaseController.php index 7f39bf6..6c07ef8 100644 --- a/src/Controller/CaseController.php +++ b/src/Controller/CaseController.php @@ -2,14 +2,18 @@ namespace App\Controller; +use App\Entity\CaseDocument; use App\Entity\CaseLocation; +use App\Entity\CompanyDocument; use App\Entity\Location; +use App\Entity\Member; 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\CaseDocumentFormType; use App\Form\LocationFormType; use App\Form\MemberCaseFormType; use App\Form\UserCaseFormType; @@ -32,8 +36,6 @@ class CaseController extends AbstractController */ private array $msgs; - private int $notificationCount; - public function __construct( private EntityManagerInterface $entityManager, private array $navLinks = [] @@ -49,9 +51,8 @@ class CaseController extends AbstractController $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); - + $this->msgs = Libs::getMessages($user, $this->entityManager); + $cases = []; foreach ($ucs as $uc) { /** @var UserCase $uc */ @@ -72,7 +73,6 @@ class CaseController extends AbstractController ], 'notifications' => $this->msgs, 'cases' => $cases, - 'notificationCount' => $this->notificationCount, ] ) ); @@ -85,8 +85,7 @@ class CaseController extends AbstractController $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); + $this->msgs = Libs::getMessages($user, $this->entityManager); return $this->render( 'internal/admin/cases/list-cases.html.twig', @@ -99,24 +98,24 @@ class CaseController extends AbstractController 'notifications' => $this->msgs, 'cases' => $cases, 'workers' => $workers, - 'notificationCount' => $this->notificationCount, ] ) ); } #[Route('/case/{caseId}', name: 'app_view_case')] - public function showCase(Request $request, string $caseId): Response + public function showCase(Request $request, #[CurrentUser()] User $user, string $caseId): Response { if (!$this->isGranted('IS_AUTHENTICATED_FULLY')) { return $this->redirectToRoute('app_login'); } $case = $this->entityManager->getRepository(MemberCase::class)->find($caseId); + $caseDocs = $this->entityManager->getRepository(CaseDocument::class)->getDocumentsByCase($case); + $compDocs = $this->entityManager->getRepository(CompanyDocument::class)->findBy(['company' => $user->getCompany()]); $sources = $this->entityManager->getRepository(ReferralSource::class)->findAll(); $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($this->getUser()); - $this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($this->getUser()); return $this->render( 'internal/cases/view-case.html.twig', @@ -124,13 +123,14 @@ class CaseController extends AbstractController $this->navLinks, [ 'case' => $case, + 'caseDocs' => $caseDocs, + 'compDocs' => $compDocs, 'sources' => $sources, 'breadcrumbs' => [ new Breadcrumb($this->generateUrl('app_list_cases'), 'List Cases'), new Breadcrumb($this->generateUrl('app_view_case', ['caseId' => $case->getId()]), 'View Case') ], 'notifications' => $this->msgs, - 'notificationCount' => $this->notificationCount, ] ) ); @@ -141,10 +141,10 @@ class CaseController extends AbstractController { $this->denyAccessUnlessGranted('ROLE_ADMIN'); $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($admin); - $this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($admin); + $companyDocs = $this->entityManager->getRepository(CompanyDocument::class)->findBy(['company' => $admin->getCompany()]); $case = new MemberCase(); - $form = $this->createForm(MemberCaseFormType::class, $case); + $form = $this->createForm(MemberCaseFormType::class, $case, ['docs' => $companyDocs]); $form->handleRequest($request); @@ -170,9 +170,9 @@ class CaseController extends AbstractController new Breadcrumb($this->generateUrl('app_add_case'), 'Add Case') ], 'notifications' => $this->msgs, - 'notificationCount' => $this->notificationCount, 'form' => $form, 'sources' => $this->entityManager->getRepository(ReferralSource::class)->retrieveOrderedList(), + 'docs' => $companyDocs, ] ) ); @@ -183,7 +183,6 @@ class CaseController extends AbstractController { $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); @@ -210,7 +209,6 @@ class CaseController extends AbstractController new Breadcrumb($this->generateUrl('app_edit_case', ['id' => $id]), 'Edit Case') ], 'notifications' => $this->msgs, - 'notificationCount' => $this->notificationCount, 'form' => $form, 'case' => $case, 'sources' => $this->entityManager->getRepository(ReferralSource::class)->retrieveOrderedList(), @@ -224,7 +222,6 @@ class CaseController extends AbstractController { $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); @@ -267,7 +264,6 @@ class CaseController extends AbstractController new Breadcrumb($this->generateUrl('app_assign_case', ['id' => $id]), 'Assign User') ], 'notifications' => $this->msgs, - 'notificationCount' => $this->notificationCount, 'case' => $case, 'form' => $form, 'id' => $id, @@ -278,13 +274,6 @@ class CaseController extends AbstractController ); } - #[Route('/case-notes/{id}', name: 'app_case_notes')] - public function showCaseNotes(Request $request, string $id): Response - { - $case = $this->entityManager->getRepository(MemberCase::class)->find($id); - return new Response(); - } - #[Route('/addresses/list', name: 'app_list_case_addresses')] public function listCaseAddresses(Request $request, #[CurrentUser()] User $user): Response { @@ -292,9 +281,8 @@ class CaseController extends AbstractController $this->navLinks['case_list'] = 'nav-link text-dark'; $addresses = $this->entityManager->getRepository(Location::class)->getUserLocations($user); - $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user); - $this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user); - + $this->msgs = Libs::getMessages($user, $this->entityManager); + $ucs = $this->entityManager->getRepository(UserCase::class)->findBy(['user' => $user]); $cases = []; foreach ($ucs as $uc) { @@ -313,7 +301,6 @@ class CaseController extends AbstractController new Breadcrumb($this->generateUrl('app_list_case_addresses'), 'List Case Addresses') ], 'notifications' => $this->msgs, - 'notificationCount' => $this->notificationCount, 'addresses' => $addresses, 'cases' => $cases, ] @@ -327,8 +314,8 @@ class CaseController extends AbstractController $this->navLinks['case_itinerary'] = NavList::PRESENT_LINK; $this->navLinks['case_list'] = 'nav-link text-dark'; - $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user); - $this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user); + $this->msgs = Libs::getMessages($user, $this->entityManager); + $ucs = $this->entityManager->getRepository(UserCase::class)->findBy(['user' => $user]); $cases = []; @@ -379,7 +366,6 @@ class CaseController extends AbstractController new Breadcrumb($this->generateUrl('app_case_add_address'), 'Add Case Address') ], 'notifications' => $this->msgs, - 'notificationCount' => $this->notificationCount, 'form' => $form, 'cases' => $cases, ] @@ -394,7 +380,6 @@ class CaseController extends AbstractController $this->navLinks['case_list'] = 'nav-link text-dark'; $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($this->getUser()); - $this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($this->getUser()); $ucs = $this->entityManager->getRepository(UserCase::class)->findBy(['user' => $this->getUser()]); $lcs = $this->entityManager->getRepository(CaseLocation::class)->findBy(['location' => $id]); @@ -440,12 +425,61 @@ class CaseController extends AbstractController 'inCases' => $inCases, 'form' => $form, 'notifications' => $this->msgs, - 'notificationCount' => $this->notificationCount, ] ) ); } + #[Route('/assign-case-doc/{caseId}/{memberId}', name: 'app_assign_case_documents')] + public function assignCaseDocument(string $caseId, string $memberId, Request $request, #[CurrentUser()] User $user): Response + { + $this->msgs = Libs::getMessages($user, $this->entityManager); + $case = $this->entityManager->getRepository(MemberCase::class)->find($caseId); + $member = $this->entityManager->getRepository(Member::class)->find($memberId); + $companyDocs = $this->entityManager->getRepository(CompanyDocument::class)->findBy(['company' => $user->getCompany()]); + + $form = $this->createForm(CaseDocumentFormType::class, null, ['docs' => $companyDocs]); + + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $docs = $form['document']->getData(); + dd($docs); + + $this->entityManager->persist($cd); + $this->entityManager->flush(); + + $this->redirectToRoute('app_case_members', ['id' => $caseId]); + } + + return $this->render( + 'internal/cases/members/assign-document.html.twig', + array_merge( + $this->navLinks, + [ + 'notifications' => $this->msgs, + 'breadcrumbs' => [ + new Breadcrumb($this->generateUrl('app_dashboard'), 'Dashboard'), + new Breadcrumb($this->generateUrl('app_list_cases'), 'List Cases'), + new Breadcrumb($this->generateUrl('app_case_members', ['id' => $caseId]), 'Case Members') + ], + 'form' => $form, + 'case' => $case, + 'member' => $member, + 'docs' => $companyDocs, + ] + ) + ); + + return new Response(); + } + + #[Route('/sign-case-doc/{caseId}/{docId}/{memberId}', name: 'app_display_case_document')] + public function displayCaseDocument(string $caseId, string $docId, Request $request, #[CurrentUser()] User $user): Response + { + return new Response(); + } + #[Route('/api/filter-address-by-case/{caseId}', name: 'ajax_filter_address_by_case')] public function filterAddressByCase(string $caseId, Request $request): Response { @@ -487,9 +521,7 @@ class CaseController extends AbstractController foreach ($ucs as $uc) { $ret[] = $uc->getMemberCase(); } - - dump($ret); - die; + return $this->json($ret); } }