fix: AdminController
ensure new users are active fix role assignments and remove unnecessary fields fix supervision assignment to update the record instead of deleting
This commit is contained in:
parent
2e77baae1b
commit
c04e255476
@ -136,6 +136,7 @@ class AdminController extends AbstractController
|
||||
->setRate($form->get('rate')->getData())
|
||||
->setLevel($form->get('level')->getData())
|
||||
->setCompany($admin->getCompany())
|
||||
->setActive(true)
|
||||
->setPasswordChanged(new DateTime('now', new DateTimeZone($_ENV['COMPANY_TIMEZONE'])))
|
||||
;
|
||||
|
||||
@ -197,15 +198,31 @@ class AdminController extends AbstractController
|
||||
$this->navLinks['user_list'] = NavList::PRESENT_LINK;
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$roles = ['ROLE_USER'];
|
||||
if ($form->get('caseWorker')->getData()) {
|
||||
$roles[] = 'ROLE_CASE_WORKER';
|
||||
}
|
||||
|
||||
if ($form->get('caseManager')->getData()) {
|
||||
$roles[] = 'ROLE_CASE_MANAGER';
|
||||
}
|
||||
|
||||
if ($form->get('therapist')->getData()) {
|
||||
$roles[] = 'ROLE_THERAPIST';
|
||||
}
|
||||
|
||||
if ($form->get('su')->getData()) {
|
||||
$roles[] = 'ROLE_ADMIN';
|
||||
}
|
||||
|
||||
$user->setName($form->get('name')->getData())
|
||||
->setEmail($form->get('email')->getData())
|
||||
->setCaseWorker($form->get('caseWorker')->getData())
|
||||
->setCaseManager($form->get('caseManager')->getData())
|
||||
->setTherapist($form->get('therapist')->getData())
|
||||
->setSu($form->get('su')->getData())
|
||||
->setRoles($roles)
|
||||
->setActive((bool) $form->get('active')->getData())
|
||||
->setRateType($form->get('rateType')->getData())
|
||||
->setRate($form->get('rate')->getData())
|
||||
->setLevel($form->get('level')->getData());
|
||||
->setLevel($form->get('level')->getData())
|
||||
;
|
||||
|
||||
$this->entityManager->flush();
|
||||
|
||||
@ -237,27 +254,32 @@ class AdminController extends AbstractController
|
||||
|
||||
/** @var User $user */
|
||||
$user = $userRepo->find($id);
|
||||
$prevSup = $this->entityManager->getRepository(Supervision::class)->findBy(['worker' => $user]);
|
||||
$prevSup = $this->entityManager->getRepository(Supervision::class)->findOneBy(['worker' => $user]);
|
||||
|
||||
$form = $this->createForm(SupervisorFormType::class);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
/** @var User $supervisor */
|
||||
$supervisor = $form->get('supervisor')->getData();
|
||||
|
||||
if (count($prevSup) > 0) {
|
||||
$this->entityManager->remove($prevSup[0]);
|
||||
if ($prevSup) {
|
||||
$prevSup->setSupervisor($supervisor);
|
||||
$this->entityManager->persist($prevSup);
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
$this->addFlash('success', "Supervisor updated for {$user->getName()}");
|
||||
} else {
|
||||
$sup = new Supervision();
|
||||
$sup->setWorker($user);
|
||||
$sup->setSupervisor($supervisor);
|
||||
|
||||
$sup = new Supervision();
|
||||
$sup->setSupervisor($supervisor);
|
||||
$sup->setWorker($user);
|
||||
$this->entityManager->persist($sup);
|
||||
$this->entityManager->flush();
|
||||
$this->addFlash('success', "Supervisor assigned to {$user->getName()}");
|
||||
}
|
||||
|
||||
$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();
|
||||
|
Loading…
Reference in New Issue
Block a user