fix: MemberController

MemberDocument migration
* Migrate CaseDocument to MemberDocument
* Setup assigning a document to a case member when creating member
* Still need to fix member edit
This commit is contained in:
Ryan Prather 2025-01-21 14:20:57 -05:00
parent 844209d3e3
commit e13dc0bf66

View File

@ -2,10 +2,13 @@
namespace App\Controller; namespace App\Controller;
use App\Entity\CompanyDocument;
use App\Entity\Member; use App\Entity\Member;
use App\Entity\User;
use App\Entity\MemberCase; use App\Entity\MemberCase;
use App\Entity\MemberDocument;
use App\Entity\Messages; use App\Entity\Messages;
use App\Entity\User;
use App\Entity\UserCase;
use App\Form\MemberFormType; use App\Form\MemberFormType;
use App\Libs\Breadcrumb; use App\Libs\Breadcrumb;
use App\Libs\Libs; use App\Libs\Libs;
@ -55,45 +58,48 @@ class MemberController extends AbstractController
{ {
/** @var MemberCase $case */ /** @var MemberCase $case */
$case = $this->entityManager->getRepository(MemberCase::class)->find($id); $case = $this->entityManager->getRepository(MemberCase::class)->find($id);
/** @var UserCase $userCase */
$userCase = $this->entityManager->getRepository(UserCase::class)->findOneBy(['memberCase' => $case]);
/** @var User $caseWorker */
$caseWorker = $userCase->getUser();
/** @var array $docs<int, CompanyDocuments> */
$docs = $this->entityManager->getRepository(CompanyDocument::class)->findBy(['company' => $user->getCompany()], ['title' => 'ASC']);
$member = new Member(); $member = new Member();
$form = $this->createForm(MemberFormType::class, $member); $form = $this->createForm(MemberFormType::class, $member, ['docs' => $docs]);
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$member = $form->getData();
$member->setCaseId($case) $member->setCaseId($case)
->setFirstName($form->get('firstName')->getData()) ->setChild(($form->get('isChild') ? true : false))
->setLastName($form->get('lastName')->getData()) ->setParent(($form->get('isParent') ? true : false))
->setDob($form->get('dob')->getData()) ->setAdultChild(($form->get('isAdultChild') ? true : false))
->setGender($form->get('gender')->getData()) ->setLegalGuardian(($form->get('isLegalGuardian') ? true : false))
->setRace($form->get('race')->getData()) ->setParentsLiveTogether(($form->get('parentsLiveTogether') ? true : false))
->setLanguage($form->get('language')->getData()) ->setDcsApproved(($form->get('dcsApproved') ? true : false))
->setPersonalId($form->get('personalId')->getData())
->setEmergencyContact($form->get('emergencyContact')->getData())
->setEmail($form->get('email')->getData())
->setAddress($form->get('address')->getData())
->setCity($form->get('city')->getData())
->setState($form->get('state')->getData())
->setZip($form->get('zip')->getData())
->setPhone($form->get('phone')->getData())
->setRelationship($form->get('relationship')->getData())
->setDayPhone($form->get('dayPhone')->getData())
->setEveningPhone($form->get('eveningPhone')->getData())
->setCellPhone($form->get('cellPhone')->getData())
->setSchool($form->get('school')->getData())
->setMaritalStatus($form->get('maritalStatus')->getData())
->setChild($form->get('isChild')->getData())
->setParent($form->get('isParent')->getData())
->setAdultChild($form->get('isAdultChild')->getData())
->setLegalGuardian($form->get('isLegalGuardian')->getData())
->setParentsLiveTogether($form->get('parentsLiveTogether')->getData())
->setDcsApproved($form->get('dcsApproved')->getData())
; ;
$this->entityManager->persist($member); $this->entityManager->persist($member);
$this->entityManager->flush(); $this->entityManager->flush();
$selectedDocs = $form->get('docs');
foreach ($selectedDocs->getData() as $doc) {
$dbDoc = $this->entityManager->getRepository(CompanyDocument::class)->find($doc);
if (!$dbDoc) {
continue;
}
$md = new MemberDocument();
$md->setClient($member)
->setDocument($dbDoc)
->setCaseWorker($caseWorker)
;
$this->entityManager->persist($md);
$this->entityManager->flush();
}
$this->addFlash( $this->addFlash(
'success', 'success',
'Member added successfully' 'Member added successfully'
@ -115,6 +121,7 @@ class MemberController extends AbstractController
'notifications' => Libs::getMessages($user, $this->entityManager), 'notifications' => Libs::getMessages($user, $this->entityManager),
'case' => $case, 'case' => $case,
'form' => $form->createView(), 'form' => $form->createView(),
'docs' => $docs,
] ]
) )
); );