Added messages, notifications, count, and supporting elements
This commit is contained in:
@ -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,
|
||||
]
|
||||
)
|
||||
);
|
||||
|
Reference in New Issue
Block a user