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:
parent
844209d3e3
commit
e13dc0bf66
@ -2,10 +2,13 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\CompanyDocument;
|
||||
use App\Entity\Member;
|
||||
use App\Entity\User;
|
||||
use App\Entity\MemberCase;
|
||||
use App\Entity\MemberDocument;
|
||||
use App\Entity\Messages;
|
||||
use App\Entity\User;
|
||||
use App\Entity\UserCase;
|
||||
use App\Form\MemberFormType;
|
||||
use App\Libs\Breadcrumb;
|
||||
use App\Libs\Libs;
|
||||
@ -55,45 +58,48 @@ class MemberController extends AbstractController
|
||||
{
|
||||
/** @var MemberCase $case */
|
||||
$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();
|
||||
$form = $this->createForm(MemberFormType::class, $member);
|
||||
$form = $this->createForm(MemberFormType::class, $member, ['docs' => $docs]);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$member = $form->getData();
|
||||
$member->setCaseId($case)
|
||||
->setFirstName($form->get('firstName')->getData())
|
||||
->setLastName($form->get('lastName')->getData())
|
||||
->setDob($form->get('dob')->getData())
|
||||
->setGender($form->get('gender')->getData())
|
||||
->setRace($form->get('race')->getData())
|
||||
->setLanguage($form->get('language')->getData())
|
||||
->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())
|
||||
->setChild(($form->get('isChild') ? true : false))
|
||||
->setParent(($form->get('isParent') ? true : false))
|
||||
->setAdultChild(($form->get('isAdultChild') ? true : false))
|
||||
->setLegalGuardian(($form->get('isLegalGuardian') ? true : false))
|
||||
->setParentsLiveTogether(($form->get('parentsLiveTogether') ? true : false))
|
||||
->setDcsApproved(($form->get('dcsApproved') ? true : false))
|
||||
;
|
||||
|
||||
$this->entityManager->persist($member);
|
||||
$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(
|
||||
'success',
|
||||
'Member added successfully'
|
||||
@ -115,6 +121,7 @@ class MemberController extends AbstractController
|
||||
'notifications' => Libs::getMessages($user, $this->entityManager),
|
||||
'case' => $case,
|
||||
'form' => $form->createView(),
|
||||
'docs' => $docs,
|
||||
]
|
||||
)
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user