diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseWorkController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseWorkController.php index 739b14e2b..2dac6315b 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseWorkController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseWorkController.php @@ -11,7 +11,9 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Serializer\SerializerInterface; use Symfony\Component\Translation\TranslatorInterface; +use Symfony\Component\Form\Form; use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository; +use Symfony\Component\Form\Extension\Core\Type\SubmitType; class AccompanyingCourseWorkController extends AbstractController { @@ -106,4 +108,83 @@ class AccompanyingCourseWorkController extends AbstractController 'paginator' => $paginator ]); } + + + /** + * @Route( + * "{_locale}/person/accompanying-period/work/{id}/delete", + * name="chill_person_accompanying_period_work_delete", + * methods={"GET"} + * ) + */ + public function deleteWork(AccompanyingPeriodWork $work): Response + { + // TODO ACL + + $em = $this->getDoctrine()->getManager(); + dump($work); + // [$person, $accompanyingPeriod] = $this->getEntity($request); + + // /* @var $activity Activity */ + // $activity = $em->getRepository('ChillActivityBundle:Activity')->find($id); + + // if (!$activity) { + // throw $this->createNotFoundException('Unable to find Activity entity.'); + // } + + // TODO + // $this->denyAccessUnlessGranted('CHILL_ACTIVITY_DELETE', $activity); + + $form = $this->createDeleteForm($work->getId()); + + // if ($request->getMethod() === Request::METHOD_DELETE) { + // $form->handleRequest($request); + + // if ($form->isValid()) { + + // // $this->logger->notice("An activity has been removed", array( + // // 'by_user' => $this->getUser()->getUsername(), + // // 'activity_id' => $activity->getId(), + // // 'person_id' => $activity->getPerson() ? $activity->getPerson()->getId() : null, + // // 'comment' => $activity->getComment()->getComment(), + // // 'scope_id' => $activity->getScope() ? $activity->getScope()->getId() : null, + // // 'reasons_ids' => $activity->getReasons() + // // ->map(function ($ar) { return $ar->getId(); }) + // // ->toArray(), + // // 'type_id' => $activity->getType()->getId(), + // // 'duration' => $activity->getDurationTime() ? $activity->getDurationTime()->format('U') : null, + // // 'date' => $activity->getDate()->format('Y-m-d'), + // // 'attendee' => $activity->getAttendee() + // // )); //TODO + + // $em->remove($work); + // $em->flush(); + + // // $this->addFlash('success', $this->get('translator') + // // ->trans("The activity has been successfully removed.")); + + // // $params = $this->buildParamsToUrl($person, $accompanyingPeriod); + // // return $this->redirectToRoute('chill_activity_activity_list', $params); + // } + // } + + return $this->render('@ChillPerson/AccompanyingCourseWork/delete.html.twig', array( + 'work' => $work, + 'delete_form' => $form->createView() + )); + } + + private function createDeleteForm(int $id): Form + { + $params['id'] = $id; + + return $this->createFormBuilder() + ->setAction($this->generateUrl('chill_person_accompanying_period_work_delete', $params)) + ->setMethod('DELETE') + ->add('submit', SubmitType::class, array('label' => 'Delete')) + ->getForm() + ; + } + + }