Move admin dashboard and associated twig templates
Display staff supervisor on user list Add method to assign staff supervisor and associated form, twig template, entity, and logic
This commit is contained in:
parent
f2f2c3e662
commit
bc83c8bfec
@ -2,8 +2,12 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Supervision;
|
||||
use App\Entity\User;
|
||||
use App\Form\EditUserFormType;
|
||||
use App\Form\SupervisorFormType;
|
||||
use App\Form\UserFormType;
|
||||
use App\Repository\UserRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@ -26,6 +30,7 @@ class AdminController extends AbstractController
|
||||
'user_dashboard' => 'nav-link text-dark',
|
||||
'profile' => 'nav-link text-dark',
|
||||
'user_list' => 'nav-link text-dark',
|
||||
'staff_dashboard' => 'nav-link text-dark',
|
||||
];
|
||||
}
|
||||
|
||||
@ -36,7 +41,7 @@ class AdminController extends AbstractController
|
||||
$this->navLinks['admin_dashboard'] = 'nav-link text-white active bg-gradient-dark';
|
||||
|
||||
return $this->render(
|
||||
'internal/admin-dashboard.html.twig',
|
||||
'internal/admin/admin-dashboard.html.twig',
|
||||
array_merge(
|
||||
$this->navLinks,
|
||||
[
|
||||
@ -54,7 +59,16 @@ class AdminController extends AbstractController
|
||||
{
|
||||
$this->denyAccessUnlessGranted('ROLE_ADMIN');
|
||||
|
||||
$users = $user->getCompany()->getUsers();
|
||||
/** @var UserRepository $repo */
|
||||
$repo = $this->entityManager->getRepository(User::class);
|
||||
$users = $repo->getCompanyUsers($user->getCompany());
|
||||
|
||||
/** @var SupervisionRepository $supRepo */
|
||||
$supRepo = $this->entityManager->getRepository(Supervision::class);
|
||||
foreach ($users as $idx => $user) {
|
||||
$supervisor = $supRepo->getSupervisorByWorker($user);
|
||||
$users[$idx]->setSupervisor($supervisor);
|
||||
}
|
||||
|
||||
$this->navLinks['user_list'] = 'nav-link text-white active bg-gradient-dark';
|
||||
|
||||
@ -129,10 +143,13 @@ class AdminController extends AbstractController
|
||||
#[Route('/edit-user/{id}', name: 'app_edit_user')]
|
||||
public function editUser(string $id, Request $request, #[CurrentUser()] User $admin): Response
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->entityManager->getRepository(User::class)->find($id);
|
||||
$form = $this->createForm(UserFormType::class, $user);
|
||||
/** @var UserRepository $userRepo */
|
||||
$userRepo = $this->entityManager->getRepository(User::class);
|
||||
|
||||
/** @var User $user */
|
||||
$user = $userRepo->find($id);
|
||||
|
||||
$form = $this->createForm(EditUserFormType::class, $user);
|
||||
$form->handleRequest($request);
|
||||
|
||||
$this->navLinks['user_list'] = 'nav-link text-white active bg-gradient-dark';
|
||||
@ -166,4 +183,46 @@ class AdminController extends AbstractController
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[Route('/assign-supervisor/{id}', name: 'app_assign_supervisor')]
|
||||
public function assignSupervisor(string $id, Request $request, #[CurrentUser()] User $admin): Response
|
||||
{
|
||||
/** @var UserRepository $userRepo */
|
||||
$userRepo = $this->entityManager->getRepository(User::class);
|
||||
|
||||
/** @var User $user */
|
||||
$user = $userRepo->find($id);
|
||||
|
||||
$form = $this->createForm(SupervisorFormType::class);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$supervisor = $form->get('supervisor')->getData();
|
||||
|
||||
$sup = new Supervision();
|
||||
$sup->setSupervisor($supervisor);
|
||||
$sup->setWorker($user);
|
||||
|
||||
$this->entityManager->persist($sup);
|
||||
$this->entityManager->flush();
|
||||
|
||||
return $this->redirectToRoute('app_list_users');
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'internal/admin/assign-supervisor.html.twig',
|
||||
array_merge(
|
||||
$this->navLinks,
|
||||
[
|
||||
'breadcrumbs' => [
|
||||
'Assign Supervisor'
|
||||
],
|
||||
'data' => $user,
|
||||
'form' => $form,
|
||||
'supervisors' => $userRepo->getCaseManagers($admin->getCompany()),
|
||||
'notifications' => $admin->retrieveUnreadNotifications(),
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user