personResourceRepository = $personResourceRepository; $this->personRepository = $personRepository; $this->em = $em; $this->translator = $translator; } public function listAction(Request $request, $person_id) { $personOwner = $this->personRepository->find($person_id); $this->denyAccessUnlessGranted(PersonVoter::SEE, $personOwner); $personResources = []; $personResources = $this->personResourceRepository->findBy(['personOwner' => $personOwner->getId()]); $form = $this->createForm(PersonResourceType::class); $form->handleRequest($request); if ($request->getMethod() === Request::METHOD_POST && $form->isValid()) { $this->denyAccessUnlessGranted(PersonVoter::CREATE, $personOwner); $personResource = new PersonResource(); $person = $form['person']->getData(); $thirdparty = $form['thirdparty']->getData(); $freetext = $form['freetext']->getData(); $comment = $form['comment']->getData(); $kind = $form['kind']->getData(); $personResource->setKind($kind); $personResource->setPerson($person); $personResource->setThirdParty($thirdparty); $personResource->setFreeText($freetext); $personResource->setComment($comment); $personResource->setPersonOwner($personOwner); $this->em->persist($personResource); $this->em->flush(); return $this->redirectToRoute('chill_person_resource_list', [ 'person_id' => $personOwner->getId(), ]); } return $this->render( 'ChillPersonBundle:PersonResource:list.html.twig', [ 'person' => $personOwner, 'personResources' => $personResources, 'form' => $form->createView() ] ); } public function editAction(Request $request, $resource_id, $person_id): Response { $resource = $this->personResourceRepository->find($resource_id); $personOwner = $this->personRepository->find($person_id); $this->denyAccessUnlessGranted(PersonVoter::UPDATE, $personOwner); if (null === $resource) { throw $this->createNotFoundException('Unable to find Resource entity.'); } $form = $this->createForm(PersonResourceType::class, $resource); $form->handleRequest($request); if($form->isSubmitted() && $form->isValid()) { $this->em->persist($resource); $this->em->flush(); return $this->redirectToRoute('chill_person_resource_list', [ 'person_id' => $personOwner->getId(), ]); } dump($resource); return $this->render( 'ChillPersonBundle:PersonResource:edit.html.twig', [ 'person' => $personOwner, 'resource' => $resource, 'form' => $form->createView(), 'action' => 'edit' ] ); } public function deleteAction(Request $request, $person_id, $resource_id): Response { $personOwner = $this->personRepository->find($person_id); $resource = $this->personResourceRepository->find($resource_id); $this->denyAccessUnlessGranted(PersonVoter::UPDATE, $personOwner); if (null === $resource) { throw $this->createNotFoundException('Unable to find Resource entity.'); } $form = $this->createFormBuilder() ->setAction($this->generateUrl('chill_person_resource_delete', [ 'resource_id' => $resource_id, 'person_id' => $person_id, ])) ->setMethod('DELETE') ->add('submit', SubmitType::class, ['label' => 'Delete']) ->getForm(); if($request->getMethod() === Request::METHOD_DELETE) { $form->handleRequest($request); if ($form->isValid()) { $this->em->remove($resource); $this->em->flush(); $this->addFlash('success', $this->translator ->trans('The resource has been successfully removed.')); return $this->redirectToRoute('chill_person_resource_list', [ 'person_id' => $personOwner->getId(), ]); } } return $this->render( 'ChillPersonBundle:PersonResource:delete.html.twig', [ 'person' => $personOwner, 'resource' => $resource, 'form' => $form->createView() ] ); } }