getAccompanyingPeriodWorkEvaluation()->getAccompanyingPeriodWork(); if (!$this->security->isGranted(AccompanyingPeriodWorkVoter::UPDATE, $work)) { throw new AccessDeniedHttpException('not allowed to edit this accompanying period work'); } $duplicatedDocument = $this->duplicator->duplicate($document); $this->entityManager->persist($duplicatedDocument); $this->entityManager->persist($duplicatedDocument->getStoredObject()); $this->entityManager->flush(); return new JsonResponse( $this->serializer->serialize($duplicatedDocument, 'json', [AbstractNormalizer::GROUPS => ['read']]), json: true ); } /** * @ParamConverter("document", options={"id": "document_id"}) * @ParamConverter("evaluation", options={"id": "evaluation_id"}) */ #[Route('/api/1.0/person/accompanying-course-work-evaluation-document/{document_id}/evaluation/{evaluation_id}/duplicate', methods: ['POST'])] public function duplicateToEvaluationApi(AccompanyingPeriodWorkEvaluationDocument $document, AccompanyingPeriodWorkEvaluation $evaluation): Response { $work = $evaluation->getAccompanyingPeriodWork(); if (!$this->security->isGranted(AccompanyingPeriodWorkVoter::UPDATE, $work)) { throw new AccessDeniedHttpException('not allowed to edit this accompanying period work'); } $duplicatedDocument = $this->duplicator->duplicateToEvaluation($document, $evaluation); $this->entityManager->persist($duplicatedDocument); $this->entityManager->persist($duplicatedDocument->getStoredObject()); $this->entityManager->persist($evaluation); $this->entityManager->flush(); dump($duplicatedDocument); return new JsonResponse( $this->serializer->serialize($duplicatedDocument, 'json', [AbstractNormalizer::GROUPS => ['read']]), json: true ); } #[Route('/{_locale}/person/accompanying-course-work-evaluation-document/{id}/duplicate', name: 'chill_person_accompanying_period_work_evaluation_document_duplicate', methods: ['POST'])] public function duplicate(AccompanyingPeriodWorkEvaluationDocument $document): Response { $work = $document->getAccompanyingPeriodWorkEvaluation()->getAccompanyingPeriodWork(); if (!$this->security->isGranted(AccompanyingPeriodWorkVoter::UPDATE, $work)) { throw new AccessDeniedHttpException('not allowed to edit this accompanying period work'); } $duplicatedDocument = $this->duplicator->duplicate($document); $this->entityManager->persist($duplicatedDocument); $this->entityManager->persist($duplicatedDocument->getStoredObject()); $this->entityManager->flush(); return new RedirectResponse( $this->urlGenerator->forwardReturnPath( 'chill_person_accompanying_period_work_edit', ['id' => $work->getId(), 'doc_id' => $duplicatedDocument->getId()] ) ); } }