Fix bug to delete previous supervision before applying new

This commit is contained in:
Ryan Prather 2024-12-07 22:52:05 -05:00
parent 2c623fd902
commit 09f9ef1ef5

View File

@ -205,6 +205,7 @@ class AdminController extends AbstractController
/** @var User $user */
$user = $userRepo->find($id);
$prevSup = $this->entityManager->getRepository(Supervision::class)->findBy(['user' => $user]);
$form = $this->createForm(SupervisorFormType::class);
$form->handleRequest($request);
@ -212,6 +213,11 @@ class AdminController extends AbstractController
if ($form->isSubmitted() && $form->isValid()) {
$supervisor = $form->get('supervisor')->getData();
if (count($prevSup) > 0) {
$this->entityManager->remove($prevSup[0]);
$this->entityManager->flush();
}
$sup = new Supervision();
$sup->setSupervisor($supervisor);
$sup->setWorker($user);