src/Controller/Backend/CertifiedPatientRecordController.php line 10

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Backend;
  3. use Sonata\AdminBundle\Controller\CRUDController as Controller;
  4. use Symfony\Component\HttpFoundation\RedirectResponse;
  5. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. class CertifiedPatientRecordController extends Controller
  8. {
  9.     private $entityManager;
  10.     public function __construct(EntityManagerInterface $entityManager)
  11.     {
  12.         $this->entityManager $entityManager;
  13.     }
  14.     public function authorizeAction(string $id)
  15.     {
  16.         $object $this->admin->getSubject();
  17.         if (!$object) {
  18.             throw new NotFoundHttpException(sprintf('unable to find the object with id: %s'$id));
  19.         }
  20.         if ($object->isAllChecked()) {
  21.             $object->setAuthorized(true);
  22.             $this->entityManager->persist($object);
  23.             $this->entityManager->flush();
  24.         }
  25.         return new RedirectResponse($this->admin->generateUrl('list'));
  26.     }
  27. }