serializer = $serializer; $this->dispatcher = $dispatcher; $this->validator = $validator; $this->workRepository = $workRepository; $this->registry = $registry; $this->translator = $translator; } /** * @Route("/{_locale}/parcours/{accompanying_period_id}/close", name="chill_person_accompanying_course_close") * @ParamConverter("accompanyingCourse", options={"id": "accompanying_period_id"}) */ public function closeAction(AccompanyingPeriod $accompanyingCourse, Request $request): Response { $this->denyAccessUnlessGranted(AccompanyingPeriodVoter::EDIT, $accompanyingCourse); $form = $this->createForm(AccompanyingCourseType::class, $accompanyingCourse, [ 'validation_groups' => [AccompanyingPeriod::STEP_CLOSED], ]); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $em = $this->getDoctrine()->getManager(); $workflow = $this->registry->get($accompanyingCourse); if ($workflow->can($accompanyingCourse, 'close')) { $workflow->apply($accompanyingCourse, 'close'); $em->flush(); return $this->redirectToRoute('chill_person_accompanying_course_index', [ 'accompanying_period_id' => $accompanyingCourse->getId(), ]); } /** @var ConstraintViolationListInterface $errors */ $errors = $this->validator->validate($accompanyingCourse, null, [$accompanyingCourse::STEP_CLOSED]); $this->addFlash('error', $this->translator->trans('It is not possible to close this course')); foreach ($errors as $e) { /** @var ConstraintViolationInterface $e */ $this->addFlash('error', $e->getMessage()); } } return $this->render('@ChillPerson/AccompanyingCourse/close.html.twig', [ 'form' => $form->createView(), 'accompanyingCourse' => $accompanyingCourse, ]); } /** * Edit page of Accompanying Course section. * * the page edit all blocks managed by vuejs component * * @Route("/{_locale}/parcours/{accompanying_period_id}/edit", name="chill_person_accompanying_course_edit") * @ParamConverter("accompanyingCourse", options={"id": "accompanying_period_id"}) */ public function editAction(AccompanyingPeriod $accompanyingCourse): Response { $this->denyAccessUnlessGranted(AccompanyingPeriodVoter::SEE, $accompanyingCourse); return $this->render('@ChillPerson/AccompanyingCourse/edit.html.twig', [ 'accompanyingCourse' => $accompanyingCourse, ]); } /** * History page of Accompanying Course section. * * the page show anti chronologic history with all actions, title of page is 'Accompanying Course History' * * @Route("/{_locale}/parcours/{accompanying_period_id}/history", name="chill_person_accompanying_course_history") * @ParamConverter("accompanyingCourse", options={"id": "accompanying_period_id"}) */ public function historyAction(AccompanyingPeriod $accompanyingCourse): Response { $this->denyAccessUnlessGranted(AccompanyingPeriodVoter::SEE, $accompanyingCourse); return $this->render('@ChillPerson/AccompanyingCourse/history.html.twig', [ 'accompanyingCourse' => $accompanyingCourse, ]); } /** * Homepage of Accompanying Course section. * * @Route("/{_locale}/parcours/{accompanying_period_id}", name="chill_person_accompanying_course_index") * @ParamConverter("accompanyingCourse", options={"id": "accompanying_period_id"}) */ public function indexAction(AccompanyingPeriod $accompanyingCourse): Response { $this->denyAccessUnlessGranted(AccompanyingPeriodVoter::SEE, $accompanyingCourse); // compute some warnings // get persons without household $withoutHousehold = []; foreach ($accompanyingCourse->getParticipations() as $p) { if (false === $p->getPerson()->isSharingHousehold()) { $withoutHousehold[] = $p->getPerson(); } } $activities = $this->getDoctrine()->getManager()->getRepository(Activity::class)->findBy( ['accompanyingPeriod' => $accompanyingCourse], ['date' => 'DESC'], ); $works = $this->workRepository->findByAccompanyingPeriod( $accompanyingCourse, ['startDate' => 'DESC', 'endDate' => 'DESC'], 3 ); return $this->render('@ChillPerson/AccompanyingCourse/index.html.twig', [ 'accompanyingCourse' => $accompanyingCourse, 'withoutHousehold' => $withoutHousehold, 'participationsByHousehold' => $accompanyingCourse->actualParticipationsByHousehold(), 'works' => $works, 'activities' => $activities, ]); } /** * @Route("/{_locale}/person/parcours/new", name="chill_person_accompanying_course_new") */ public function newAction(Request $request): Response { $period = new AccompanyingPeriod(); $em = $this->getDoctrine()->getManager(); if ($request->query->has('person_id')) { $personIds = $request->query->get('person_id'); if (false === is_array($personIds)) { throw new BadRequestException('person_id parameter should be an array'); } foreach ($personIds as $personId) { $person = $em->getRepository(Person::class)->find($personId); if (null !== $person) { $period->addPerson($person); } } } $this->denyAccessUnlessGranted(AccompanyingPeriodVoter::CREATE, $period); $em->persist($period); $em->flush(); return $this->redirectToRoute('chill_person_accompanying_course_edit', [ 'accompanying_period_id' => $period->getId(), ]); } }