remove notificationCount, convert to Libs::getMessages method, change datetime creation to add company timezone, remove CaseController::showCaseNotes

This commit is contained in:
Ryan Prather 2025-01-10 12:44:37 +00:00
parent 604f693c45
commit 2d7b7e6d12
2 changed files with 80 additions and 56 deletions

View File

@ -2,17 +2,21 @@
namespace App\Controller; namespace App\Controller;
use App\Entity\CompanyDocument;
use App\Entity\Messages; use App\Entity\Messages;
use App\Entity\Supervision; use App\Entity\Supervision;
use App\Entity\User; use App\Entity\User;
use App\Factory\MessageFactory; use App\Factory\MessageFactory;
use App\Form\CompanyDocumentFormType;
use App\Form\EditUserFormType; use App\Form\EditUserFormType;
use App\Form\SupervisorFormType; use App\Form\SupervisorFormType;
use App\Form\UserFormType; use App\Form\UserFormType;
use App\Libs\Breadcrumb; use App\Libs\Breadcrumb;
use App\Libs\NavList; use App\Libs\NavList;
use App\Libs\Libs;
use App\Repository\UserRepository; use App\Repository\UserRepository;
use DateTime; use DateTime;
use DateTimeZone;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@ -28,8 +32,6 @@ class AdminController extends AbstractController
{ {
private array $msgs; private array $msgs;
private int $notificationCount = 0;
public function __construct( public function __construct(
private readonly EntityManagerInterface $entityManager, private readonly EntityManagerInterface $entityManager,
private readonly UserPasswordHasherInterface $userPasswordHasher, private readonly UserPasswordHasherInterface $userPasswordHasher,
@ -43,8 +45,7 @@ class AdminController extends AbstractController
{ {
$this->denyAccessUnlessGranted('ROLE_ADMIN'); $this->denyAccessUnlessGranted('ROLE_ADMIN');
$this->navLinks['admin_dashboard'] = NavList::PRESENT_LINK; $this->navLinks['admin_dashboard'] = NavList::PRESENT_LINK;
$this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user); $this->msgs = Libs::getMessages($user, $this->entityManager);
$this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user);
return $this->render( return $this->render(
'internal/admin/admin-dashboard.html.twig', 'internal/admin/admin-dashboard.html.twig',
@ -55,7 +56,6 @@ class AdminController extends AbstractController
new Breadcrumb($this->generateUrl('app_admin_dashboard'), 'Admin Dashboard') new Breadcrumb($this->generateUrl('app_admin_dashboard'), 'Admin Dashboard')
], ],
'notifications' => $this->msgs, 'notifications' => $this->msgs,
'notificationCount' => $this->notificationCount,
] ]
) )
); );
@ -65,8 +65,7 @@ class AdminController extends AbstractController
public function listUsers(#[CurrentUser()] User $user): Response public function listUsers(#[CurrentUser()] User $user): Response
{ {
$this->denyAccessUnlessGranted('ROLE_ADMIN'); $this->denyAccessUnlessGranted('ROLE_ADMIN');
$this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user); $this->msgs = Libs::getMessages($user, $this->entityManager);
$this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user);
/** @var UserRepository $repo */ /** @var UserRepository $repo */
$repo = $this->entityManager->getRepository(User::class); $repo = $this->entityManager->getRepository(User::class);
@ -91,7 +90,6 @@ class AdminController extends AbstractController
], ],
'users' => $users, 'users' => $users,
'notifications' => $this->msgs, 'notifications' => $this->msgs,
'notificationCount' => $this->notificationCount,
] ]
) )
); );
@ -104,8 +102,7 @@ class AdminController extends AbstractController
SluggerInterface $slugger SluggerInterface $slugger
): Response { ): Response {
$this->denyAccessUnlessGranted('ROLE_ADMIN'); $this->denyAccessUnlessGranted('ROLE_ADMIN');
$this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($admin); $this->msgs = Libs::getMessages($admin, $this->entityManager);
$this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($admin);
$user = new User(); $user = new User();
$form = $this->createForm(UserFormType::class, $user); $form = $this->createForm(UserFormType::class, $user);
@ -146,7 +143,7 @@ class AdminController extends AbstractController
->setRate($form->get('rate')->getData()) ->setRate($form->get('rate')->getData())
->setLevel($form->get('level')->getData()) ->setLevel($form->get('level')->getData())
->setCompany($admin->getCompany()) ->setCompany($admin->getCompany())
->setPasswordChanged(new DateTime()) ->setPasswordChanged(new DateTime('now', new DateTimeZone($_ENV['COMPANY_TIMEZONE'])))
; ;
if ($form->get('imageName')->getData()) { if ($form->get('imageName')->getData()) {
@ -187,7 +184,6 @@ class AdminController extends AbstractController
], ],
'form' => $form, 'form' => $form,
'notifications' => $this->msgs, 'notifications' => $this->msgs,
'notificationCount' => $this->notificationCount,
] ]
) )
); );
@ -198,8 +194,7 @@ class AdminController extends AbstractController
{ {
/** @var UserRepository $userRepo */ /** @var UserRepository $userRepo */
$userRepo = $this->entityManager->getRepository(User::class); $userRepo = $this->entityManager->getRepository(User::class);
$this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($admin); $this->msgs = Libs::getMessages($admin, $this->entityManager);
$this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($admin);
/** @var User $user */ /** @var User $user */
$user = $userRepo->find($id); $user = $userRepo->find($id);
@ -237,7 +232,6 @@ class AdminController extends AbstractController
'data' => $user, 'data' => $user,
'form' => $form, 'form' => $form,
'notifications' => $this->msgs, 'notifications' => $this->msgs,
'notificationCount' => $this->notificationCount,
] ]
) )
); );
@ -248,8 +242,7 @@ class AdminController extends AbstractController
{ {
/** @var UserRepository $userRepo */ /** @var UserRepository $userRepo */
$userRepo = $this->entityManager->getRepository(User::class); $userRepo = $this->entityManager->getRepository(User::class);
$this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($admin); $this->msgs = Libs::getMessages($admin, $this->entityManager);
$this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($admin);
/** @var User $user */ /** @var User $user */
$user = $userRepo->find($id); $user = $userRepo->find($id);
@ -294,7 +287,6 @@ class AdminController extends AbstractController
'form' => $form, 'form' => $form,
'supervisors' => $userRepo->getCaseManagers($admin->getCompany()), 'supervisors' => $userRepo->getCaseManagers($admin->getCompany()),
'notifications' => $this->msgs, 'notifications' => $this->msgs,
'notificationCount' => $this->notificationCount,
] ]
) )
); );

View File

@ -2,14 +2,18 @@
namespace App\Controller; namespace App\Controller;
use App\Entity\CaseDocument;
use App\Entity\CaseLocation; use App\Entity\CaseLocation;
use App\Entity\CompanyDocument;
use App\Entity\Location; use App\Entity\Location;
use App\Entity\Member;
use App\Entity\MemberCase; use App\Entity\MemberCase;
use App\Entity\Messages; use App\Entity\Messages;
use App\Entity\ReferralSource; use App\Entity\ReferralSource;
use App\Entity\User; use App\Entity\User;
use App\Entity\UserCase; use App\Entity\UserCase;
use App\Factory\MessageFactory; use App\Factory\MessageFactory;
use App\Form\CaseDocumentFormType;
use App\Form\LocationFormType; use App\Form\LocationFormType;
use App\Form\MemberCaseFormType; use App\Form\MemberCaseFormType;
use App\Form\UserCaseFormType; use App\Form\UserCaseFormType;
@ -32,8 +36,6 @@ class CaseController extends AbstractController
*/ */
private array $msgs; private array $msgs;
private int $notificationCount;
public function __construct( public function __construct(
private EntityManagerInterface $entityManager, private EntityManagerInterface $entityManager,
private array $navLinks = [] private array $navLinks = []
@ -49,9 +51,8 @@ class CaseController extends AbstractController
$this->navLinks['case_list'] = 'nav-link text-dark'; $this->navLinks['case_list'] = 'nav-link text-dark';
$ucs = $this->entityManager->getRepository(UserCase::class)->findBy(['user' => $user]); $ucs = $this->entityManager->getRepository(UserCase::class)->findBy(['user' => $user]);
$this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user); $this->msgs = Libs::getMessages($user, $this->entityManager);
$this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user);
$cases = []; $cases = [];
foreach ($ucs as $uc) { foreach ($ucs as $uc) {
/** @var UserCase $uc */ /** @var UserCase $uc */
@ -72,7 +73,6 @@ class CaseController extends AbstractController
], ],
'notifications' => $this->msgs, 'notifications' => $this->msgs,
'cases' => $cases, 'cases' => $cases,
'notificationCount' => $this->notificationCount,
] ]
) )
); );
@ -85,8 +85,7 @@ class CaseController extends AbstractController
$cases = $this->entityManager->getRepository(MemberCase::class)->findAll(); $cases = $this->entityManager->getRepository(MemberCase::class)->findAll();
$workers = $this->entityManager->getRepository(User::class)->getCaseWorkers(); $workers = $this->entityManager->getRepository(User::class)->getCaseWorkers();
$this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user); $this->msgs = Libs::getMessages($user, $this->entityManager);
$this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user);
return $this->render( return $this->render(
'internal/admin/cases/list-cases.html.twig', 'internal/admin/cases/list-cases.html.twig',
@ -99,24 +98,24 @@ class CaseController extends AbstractController
'notifications' => $this->msgs, 'notifications' => $this->msgs,
'cases' => $cases, 'cases' => $cases,
'workers' => $workers, 'workers' => $workers,
'notificationCount' => $this->notificationCount,
] ]
) )
); );
} }
#[Route('/case/{caseId}', name: 'app_view_case')] #[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')) { if (!$this->isGranted('IS_AUTHENTICATED_FULLY')) {
return $this->redirectToRoute('app_login'); return $this->redirectToRoute('app_login');
} }
$case = $this->entityManager->getRepository(MemberCase::class)->find($caseId); $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(); $sources = $this->entityManager->getRepository(ReferralSource::class)->findAll();
$this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($this->getUser()); $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($this->getUser());
$this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($this->getUser());
return $this->render( return $this->render(
'internal/cases/view-case.html.twig', 'internal/cases/view-case.html.twig',
@ -124,13 +123,14 @@ class CaseController extends AbstractController
$this->navLinks, $this->navLinks,
[ [
'case' => $case, 'case' => $case,
'caseDocs' => $caseDocs,
'compDocs' => $compDocs,
'sources' => $sources, 'sources' => $sources,
'breadcrumbs' => [ 'breadcrumbs' => [
new Breadcrumb($this->generateUrl('app_list_cases'), 'List Cases'), new Breadcrumb($this->generateUrl('app_list_cases'), 'List Cases'),
new Breadcrumb($this->generateUrl('app_view_case', ['caseId' => $case->getId()]), 'View Case') new Breadcrumb($this->generateUrl('app_view_case', ['caseId' => $case->getId()]), 'View Case')
], ],
'notifications' => $this->msgs, 'notifications' => $this->msgs,
'notificationCount' => $this->notificationCount,
] ]
) )
); );
@ -141,10 +141,10 @@ class CaseController extends AbstractController
{ {
$this->denyAccessUnlessGranted('ROLE_ADMIN'); $this->denyAccessUnlessGranted('ROLE_ADMIN');
$this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($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(); $case = new MemberCase();
$form = $this->createForm(MemberCaseFormType::class, $case); $form = $this->createForm(MemberCaseFormType::class, $case, ['docs' => $companyDocs]);
$form->handleRequest($request); $form->handleRequest($request);
@ -170,9 +170,9 @@ class CaseController extends AbstractController
new Breadcrumb($this->generateUrl('app_add_case'), 'Add Case') new Breadcrumb($this->generateUrl('app_add_case'), 'Add Case')
], ],
'notifications' => $this->msgs, 'notifications' => $this->msgs,
'notificationCount' => $this->notificationCount,
'form' => $form, 'form' => $form,
'sources' => $this->entityManager->getRepository(ReferralSource::class)->retrieveOrderedList(), 'sources' => $this->entityManager->getRepository(ReferralSource::class)->retrieveOrderedList(),
'docs' => $companyDocs,
] ]
) )
); );
@ -183,7 +183,6 @@ class CaseController extends AbstractController
{ {
$this->denyAccessUnlessGranted('ROLE_ADMIN'); $this->denyAccessUnlessGranted('ROLE_ADMIN');
$this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($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); $case = $this->entityManager->getRepository(MemberCase::class)->find($id);
$form = $this->createForm(MemberCaseFormType::class, $case); $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') new Breadcrumb($this->generateUrl('app_edit_case', ['id' => $id]), 'Edit Case')
], ],
'notifications' => $this->msgs, 'notifications' => $this->msgs,
'notificationCount' => $this->notificationCount,
'form' => $form, 'form' => $form,
'case' => $case, 'case' => $case,
'sources' => $this->entityManager->getRepository(ReferralSource::class)->retrieveOrderedList(), 'sources' => $this->entityManager->getRepository(ReferralSource::class)->retrieveOrderedList(),
@ -224,7 +222,6 @@ class CaseController extends AbstractController
{ {
$this->denyAccessUnlessGranted('ROLE_ADMIN'); $this->denyAccessUnlessGranted('ROLE_ADMIN');
$this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($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(); $caseWorkers = $this->entityManager->getRepository(User::class)->getCaseWorkers();
$case = $this->entityManager->getRepository(MemberCase::class)->find($id); $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') new Breadcrumb($this->generateUrl('app_assign_case', ['id' => $id]), 'Assign User')
], ],
'notifications' => $this->msgs, 'notifications' => $this->msgs,
'notificationCount' => $this->notificationCount,
'case' => $case, 'case' => $case,
'form' => $form, 'form' => $form,
'id' => $id, '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')] #[Route('/addresses/list', name: 'app_list_case_addresses')]
public function listCaseAddresses(Request $request, #[CurrentUser()] User $user): Response 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'; $this->navLinks['case_list'] = 'nav-link text-dark';
$addresses = $this->entityManager->getRepository(Location::class)->getUserLocations($user); $addresses = $this->entityManager->getRepository(Location::class)->getUserLocations($user);
$this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user); $this->msgs = Libs::getMessages($user, $this->entityManager);
$this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user);
$ucs = $this->entityManager->getRepository(UserCase::class)->findBy(['user' => $user]); $ucs = $this->entityManager->getRepository(UserCase::class)->findBy(['user' => $user]);
$cases = []; $cases = [];
foreach ($ucs as $uc) { foreach ($ucs as $uc) {
@ -313,7 +301,6 @@ class CaseController extends AbstractController
new Breadcrumb($this->generateUrl('app_list_case_addresses'), 'List Case Addresses') new Breadcrumb($this->generateUrl('app_list_case_addresses'), 'List Case Addresses')
], ],
'notifications' => $this->msgs, 'notifications' => $this->msgs,
'notificationCount' => $this->notificationCount,
'addresses' => $addresses, 'addresses' => $addresses,
'cases' => $cases, 'cases' => $cases,
] ]
@ -327,8 +314,8 @@ class CaseController extends AbstractController
$this->navLinks['case_itinerary'] = NavList::PRESENT_LINK; $this->navLinks['case_itinerary'] = NavList::PRESENT_LINK;
$this->navLinks['case_list'] = 'nav-link text-dark'; $this->navLinks['case_list'] = 'nav-link text-dark';
$this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user); $this->msgs = Libs::getMessages($user, $this->entityManager);
$this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user);
$ucs = $this->entityManager->getRepository(UserCase::class)->findBy(['user' => $user]); $ucs = $this->entityManager->getRepository(UserCase::class)->findBy(['user' => $user]);
$cases = []; $cases = [];
@ -379,7 +366,6 @@ class CaseController extends AbstractController
new Breadcrumb($this->generateUrl('app_case_add_address'), 'Add Case Address') new Breadcrumb($this->generateUrl('app_case_add_address'), 'Add Case Address')
], ],
'notifications' => $this->msgs, 'notifications' => $this->msgs,
'notificationCount' => $this->notificationCount,
'form' => $form, 'form' => $form,
'cases' => $cases, 'cases' => $cases,
] ]
@ -394,7 +380,6 @@ class CaseController extends AbstractController
$this->navLinks['case_list'] = 'nav-link text-dark'; $this->navLinks['case_list'] = 'nav-link text-dark';
$this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($this->getUser()); $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()]); $ucs = $this->entityManager->getRepository(UserCase::class)->findBy(['user' => $this->getUser()]);
$lcs = $this->entityManager->getRepository(CaseLocation::class)->findBy(['location' => $id]); $lcs = $this->entityManager->getRepository(CaseLocation::class)->findBy(['location' => $id]);
@ -440,12 +425,61 @@ class CaseController extends AbstractController
'inCases' => $inCases, 'inCases' => $inCases,
'form' => $form, 'form' => $form,
'notifications' => $this->msgs, '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')] #[Route('/api/filter-address-by-case/{caseId}', name: 'ajax_filter_address_by_case')]
public function filterAddressByCase(string $caseId, Request $request): Response public function filterAddressByCase(string $caseId, Request $request): Response
{ {
@ -487,9 +521,7 @@ class CaseController extends AbstractController
foreach ($ucs as $uc) { foreach ($ucs as $uc) {
$ret[] = $uc->getMemberCase(); $ret[] = $uc->getMemberCase();
} }
dump($ret);
die;
return $this->json($ret); return $this->json($ret);
} }
} }