41 lines
1.1 KiB
PHP
41 lines
1.1 KiB
PHP
<?php
|
|
namespace App\Form\Handler;
|
|
|
|
use App\Entity\Patient;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\Form\FormInterface;
|
|
|
|
class PatientHandler extends AbstractController
|
|
{
|
|
private $entityManager;
|
|
|
|
public function __construct(EntityManagerInterface $entityManager)
|
|
{
|
|
$this->entityManager = $entityManager;
|
|
}
|
|
|
|
public function new(FormInterface $form, Request $request): bool
|
|
{
|
|
$form->handleRequest($request);
|
|
if ($form->isSubmitted() && $form->isValid()) {
|
|
$patient = $form->getData();
|
|
$this->entityManager->persist($patient);
|
|
$this->entityManager->flush();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function edit(FormInterface $form, Request $request): bool
|
|
{
|
|
$form->handleRequest($request);
|
|
if ($form->isSubmitted() && $form->isValid()) {
|
|
$this->entityManager->flush();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|