diff --git a/src/Bundle/ChillActivityBundle/Service/DocGenerator/ActivityContext.php b/src/Bundle/ChillActivityBundle/Service/DocGenerator/ActivityContext.php index f7f30713b..4e2970138 100644 --- a/src/Bundle/ChillActivityBundle/Service/DocGenerator/ActivityContext.php +++ b/src/Bundle/ChillActivityBundle/Service/DocGenerator/ActivityContext.php @@ -206,16 +206,6 @@ class ActivityContext implements return $options['mainPerson'] || $options['person1'] || $options['person2']; } - public function publicFormTransform(DocGeneratorTemplate $template, $entity, array $data): array - { - // TODO: Implement publicFormTransform() method. - } - - public function publicFormReverseTransform(DocGeneratorTemplate $template, $entity, array $data): array - { - // TODO: Implement publicFormReverseTransform() method. - } - /** * @param Activity $entity */ diff --git a/src/Bundle/ChillActivityBundle/Service/DocGenerator/ListActivitiesByAccompanyingPeriodContext.php b/src/Bundle/ChillActivityBundle/Service/DocGenerator/ListActivitiesByAccompanyingPeriodContext.php index 3621ed80b..3189307f9 100644 --- a/src/Bundle/ChillActivityBundle/Service/DocGenerator/ListActivitiesByAccompanyingPeriodContext.php +++ b/src/Bundle/ChillActivityBundle/Service/DocGenerator/ListActivitiesByAccompanyingPeriodContext.php @@ -146,16 +146,6 @@ class ListActivitiesByAccompanyingPeriodContext implements return $this->accompanyingPeriodContext->hasPublicForm($template, $entity); } - public function publicFormTransform(DocGeneratorTemplate $template, $entity, array $data): array - { - // TODO: Implement publicFormTransform() method. - } - - public function publicFormReverseTransform(DocGeneratorTemplate $template, $entity, array $data): array - { - // TODO: Implement publicFormReverseTransform() method. - } - public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void { $this->accompanyingPeriodContext->storeGenerated($template, $storedObject, $entity, $contextGenerationData); diff --git a/src/Bundle/ChillCalendarBundle/Service/DocGenerator/CalendarContext.php b/src/Bundle/ChillCalendarBundle/Service/DocGenerator/CalendarContext.php index e7be965a5..9ba9e36b4 100644 --- a/src/Bundle/ChillCalendarBundle/Service/DocGenerator/CalendarContext.php +++ b/src/Bundle/ChillCalendarBundle/Service/DocGenerator/CalendarContext.php @@ -226,16 +226,6 @@ final class CalendarContext implements CalendarContextInterface return true; } - public function publicFormTransform(DocGeneratorTemplate $template, $entity, array $data): array - { - // TODO: Implement publicFormTransform() method. - } - - public function publicFormReverseTransform(DocGeneratorTemplate $template, $entity, array $data): array - { - // TODO: Implement publicFormReverseTransform() method. - } - /** * @param array{mainPerson?: Person, thirdParty?: ThirdParty, title: string} $contextGenerationData */ diff --git a/src/Bundle/ChillCalendarBundle/Service/DocGenerator/CalendarContextInterface.php b/src/Bundle/ChillCalendarBundle/Service/DocGenerator/CalendarContextInterface.php index 692d6991e..d02cdc2c2 100644 --- a/src/Bundle/ChillCalendarBundle/Service/DocGenerator/CalendarContextInterface.php +++ b/src/Bundle/ChillCalendarBundle/Service/DocGenerator/CalendarContextInterface.php @@ -56,10 +56,6 @@ interface CalendarContextInterface extends DocGeneratorContextWithPublicFormInte */ public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool; - public function publicFormTransform(DocGeneratorTemplate $template, $entity, array $data): array; - - public function publicFormReverseTransform(DocGeneratorTemplate $template, $entity, array $data): array; - /** * @param Calendar $entity */ diff --git a/src/Bundle/ChillDocGeneratorBundle/Context/DocGeneratorContextWithPublicFormInterface.php b/src/Bundle/ChillDocGeneratorBundle/Context/DocGeneratorContextWithPublicFormInterface.php index 1ad3dfa51..f013c8435 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Context/DocGeneratorContextWithPublicFormInterface.php +++ b/src/Bundle/ChillDocGeneratorBundle/Context/DocGeneratorContextWithPublicFormInterface.php @@ -23,9 +23,6 @@ interface DocGeneratorContextWithPublicFormInterface extends DocGeneratorContext */ public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void; - /** - * Fill the form with initial data - */ public function getFormData(DocGeneratorTemplate $template, $entity): array; /** @@ -34,14 +31,4 @@ interface DocGeneratorContextWithPublicFormInterface extends DocGeneratorContext * @param mixed $entity */ public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool; - - /** - * Transform the data from the form into serializable data, storable into messenger's message - */ - public function publicFormTransform(DocGeneratorTemplate $template, $entity, array $data): array; - - /** - * Reverse the data from the messenger's message into data usable for doc's generation - */ - public function publicFormReverseTransform(DocGeneratorTemplate $template, $entity, array $data): array; } diff --git a/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php b/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php index ecb27c455..d618f758a 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php +++ b/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php @@ -16,28 +16,30 @@ use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithPublicFormInterface; use Chill\DocGeneratorBundle\Context\Exception\ContextNotFoundException; use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate; use Chill\DocGeneratorBundle\GeneratorDriver\DriverInterface; +use Chill\DocGeneratorBundle\GeneratorDriver\Exception\TemplateException; use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository; -use Chill\DocGeneratorBundle\Service\Generator\GeneratorInterface; -use Chill\DocGeneratorBundle\Service\Messenger\RequestGenerationMessage; use Chill\DocStoreBundle\Entity\StoredObject; use Chill\DocStoreBundle\Service\StoredObjectManagerInterface; use Chill\MainBundle\Pagination\PaginatorFactory; use Chill\MainBundle\Serializer\Model\Collection; use Doctrine\ORM\EntityManagerInterface; +use Exception; use Psr\Log\LoggerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\FileType; +use Symfony\Component\HttpFoundation\File\File; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; // TODO à mettre dans services use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; -use Symfony\Component\Messenger\MessageBusInterface; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; +use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; use Symfony\Contracts\HttpClient\HttpClientInterface; +use Throwable; use function strlen; final class DocGeneratorTemplateController extends AbstractController @@ -52,24 +54,17 @@ final class DocGeneratorTemplateController extends AbstractController private EntityManagerInterface $entityManager; - private GeneratorInterface $generator; - private LoggerInterface $logger; - private MessageBusInterface $messageBus; - private PaginatorFactory $paginatorFactory; private StoredObjectManagerInterface $storedObjectManager; - public function __construct( ContextManager $contextManager, DocGeneratorTemplateRepository $docGeneratorTemplateRepository, DriverInterface $driver, - GeneratorInterface $generator, LoggerInterface $logger, - MessageBusInterface $messageBus, PaginatorFactory $paginatorFactory, HttpClientInterface $client, StoredObjectManagerInterface $storedObjectManager, @@ -78,9 +73,7 @@ final class DocGeneratorTemplateController extends AbstractController $this->contextManager = $contextManager; $this->docGeneratorTemplateRepository = $docGeneratorTemplateRepository; $this->driver = $driver; - $this->generator = $generator; $this->logger = $logger; - $this->messageBus = $messageBus; $this->paginatorFactory = $paginatorFactory; $this->client = $client; $this->storedObjectManager = $storedObjectManager; @@ -266,72 +259,99 @@ final class DocGeneratorTemplateController extends AbstractController } } - // transform context generation data - $contextGenerationDataSanitized = array_merge( - $contextGenerationData, - $context instanceof DocGeneratorContextWithPublicFormInterface ? - $context->publicFormTransform($template, $entity, $contextGenerationData) - : [] - ); + $document = $template->getFile(); + + if ($isTest && ($contextGenerationData['test_file'] instanceof File)) { + $dataDecrypted = file_get_contents($contextGenerationData['test_file']->getPathname()); + } else { + try { + $dataDecrypted = $this->storedObjectManager->read($document); + } catch (Throwable $exception) { + throw $exception; + } + } - // if is test, render the data or generate the doc if ($isTest && isset($form) && $form['show_data']->getData()) { return $this->render('@ChillDocGenerator/Generator/debug_value.html.twig', [ 'datas' => json_encode($context->getData($template, $entity, $contextGenerationData), JSON_PRETTY_PRINT) ]); - } elseif ($isTest) { - $generated = $this->generator->generateDocFromTemplate( - $template, - $entityClassName, - $entityId, - $contextGenerationDataSanitized, - null, - true, - isset($form) ? $form['test_file']->getData() : null - ); + } + try { + $generatedResource = $this + ->driver + ->generateFromString( + $dataDecrypted, + $template->getFile()->getType(), + $context->getData($template, $entity, $contextGenerationData), + $template->getFile()->getFilename() + ); + } catch (TemplateException $e) { return new Response( - $generated, + implode("\n", $e->getErrors()), + 400, + [ + 'Content-Type' => 'text/plain', + ] + ); + } + + if ($isTest) { + return new Response( + $generatedResource, Response::HTTP_OK, [ 'Content-Transfer-Encoding', 'binary', 'Content-Type' => 'application/vnd.oasis.opendocument.text', 'Content-Disposition' => 'attachment; filename="generated.odt"', - 'Content-Length' => strlen($generated), + 'Content-Length' => strlen($generatedResource), ], ); } - // this is not a test - // we prepare the object to store the document - $storedObject = (new StoredObject()) - ->setStatus(StoredObject::STATUS_PENDING) - ; + /** @var StoredObject $storedObject */ + $storedObject = (new ObjectNormalizer()) + ->denormalize( + [ + 'type' => $template->getFile()->getType(), + 'filename' => sprintf('%s_odt', uniqid('doc_', true)), + ], + StoredObject::class + ); + + try { + $this->storedObjectManager->write($storedObject, $generatedResource); + } catch (Throwable $exception) { + throw $exception; + } $this->entityManager->persist($storedObject); - // we store the generated document - $context - ->storeGenerated( - $template, - $storedObject, - $entity, - $contextGenerationData - ); + try { + $context + ->storeGenerated( + $template, + $storedObject, + $entity, + $contextGenerationData + ); + } catch (Exception $e) { + $this + ->logger + ->error( + 'Unable to store the associated document to entity', + [ + 'entityClassName' => $entityClassName, + 'entityId' => $entityId, + 'contextKey' => $context->getName(), + ] + ); + + throw $e; + } $this->entityManager->flush(); - $this->messageBus->dispatch( - new RequestGenerationMessage( - $this->getUser(), - $template, - $entityId, - $entityClassName, - $storedObject, - $contextGenerationDataSanitized, - ) - ); - return $this ->redirectToRoute( 'chill_wopi_file_edit', diff --git a/src/Bundle/ChillDocGeneratorBundle/Service/Generator/Generator.php b/src/Bundle/ChillDocGeneratorBundle/Service/Generator/Generator.php index 376cfc268..755e608ba 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Service/Generator/Generator.php +++ b/src/Bundle/ChillDocGeneratorBundle/Service/Generator/Generator.php @@ -3,7 +3,6 @@ namespace Chill\DocGeneratorBundle\Service\Generator; use Chill\DocGeneratorBundle\Context\ContextManagerInterface; -use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithPublicFormInterface; use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate; use Chill\DocGeneratorBundle\GeneratorDriver\DriverInterface; use Chill\DocGeneratorBundle\GeneratorDriver\Exception\TemplateException; @@ -13,7 +12,7 @@ use Doctrine\ORM\EntityManagerInterface; use Psr\Log\LoggerInterface; use Symfony\Component\HttpFoundation\File\File; -class Generator implements GeneratorInterface +class Generator { private ContextManagerInterface $contextManager; @@ -51,7 +50,6 @@ class Generator implements GeneratorInterface DocGeneratorTemplate $template, string $entityClassName, int $entityId, - array $contextGenerationData, ?StoredObject $destinationStoredObject = null, bool $isTest = false, ?File $testFile = null @@ -61,6 +59,7 @@ class Generator implements GeneratorInterface } $context = $this->contextManager->getContextByDocGeneratorTemplate($template); + $contextGenerationData = ['test_file' => $testFile]; $entity = $this ->entityManager @@ -71,13 +70,6 @@ class Generator implements GeneratorInterface throw new RelatedEntityNotFoundException($entityClassName, $entityId); } - $contextGenerationData = array_merge( - $contextGenerationData, - $context instanceof DocGeneratorContextWithPublicFormInterface ? - $context->publicFormReverseTransform($template, $entity, $contextGenerationData) - : [] - ); - if ($isTest && ($testFile instanceof File)) { $dataDecrypted = file_get_contents($testFile->getPathname()); } else { @@ -110,6 +102,29 @@ class Generator implements GeneratorInterface $this->storedObjectManager->write($destinationStoredObject, $generatedResource); + try { + $context + ->storeGenerated( + $template, + $destinationStoredObject, + $entity, + $contextGenerationData + ); + } catch (\Exception $e) { + $this + ->logger + ->error( + 'Unable to store the associated document to entity', + [ + 'entityClassName' => $entityClassName, + 'entityId' => $entityId, + 'contextKey' => $context->getName(), + ] + ); + + throw $e; + } + $this->entityManager->flush(); return null; diff --git a/src/Bundle/ChillDocGeneratorBundle/Service/Generator/GeneratorInterface.php b/src/Bundle/ChillDocGeneratorBundle/Service/Generator/GeneratorInterface.php deleted file mode 100644 index c18dc3bc2..000000000 --- a/src/Bundle/ChillDocGeneratorBundle/Service/Generator/GeneratorInterface.php +++ /dev/null @@ -1,28 +0,0 @@ -storedObjectRepository = $storedObjectRepository; - $this->docGeneratorTemplateRepository = $docGeneratorTemplateRepository; - $this->generator = $generator; - } - - public function __invoke(RequestGenerationMessage $message) - { - if (null === $template = $this->docGeneratorTemplateRepository->find($message->getTemplateId())) { - throw new \RuntimeException('template not found: ' . $message->getTemplateId()); - } - - if (null === $destinationStoredObject = $this->storedObjectRepository->find($message->getDestinationStoredObjectId())) { - throw new \RuntimeException('destination stored object not found : ' . $message->getDestinationStoredObjectId()); - } - - $this->generator->generateDocFromTemplate( - $template, - $message->getEntityClassName(), - $message->getEntityId(), - $message->getContextGenerationData(), - $destinationStoredObject - ); - } - -} diff --git a/src/Bundle/ChillDocGeneratorBundle/Service/Messenger/RequestGenerationMessage.php b/src/Bundle/ChillDocGeneratorBundle/Service/Messenger/RequestGenerationMessage.php index 535e569d7..1489e2686 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Service/Messenger/RequestGenerationMessage.php +++ b/src/Bundle/ChillDocGeneratorBundle/Service/Messenger/RequestGenerationMessage.php @@ -3,7 +3,6 @@ namespace Chill\DocGeneratorBundle\Service\Messenger; use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate; -use Chill\DocStoreBundle\Entity\StoredObject; use Chill\MainBundle\Entity\User; class RequestGenerationMessage @@ -16,24 +15,12 @@ class RequestGenerationMessage private string $entityClassName; - private int $destinationStoredObjectId; - - private array $contextGenerationData; - - public function __construct( - User $creator, - DocGeneratorTemplate $template, - int $entityId, - string $entityClassName, - StoredObject $destinationStoredObject, - array $contextGenerationData - ) { + public function __construct(User $creator, DocGeneratorTemplate $template, int $entityId, string $entityClassName) + { $this->creatorId = $creator->getId(); $this->templateId = $template->getId(); $this->entityId = $entityId; $this->entityClassName = $entityClassName; - $this->destinationStoredObjectId = $destinationStoredObject->getId(); - $this->contextGenerationData = $contextGenerationData; } public function getCreatorId(): int @@ -41,11 +28,6 @@ class RequestGenerationMessage return $this->creatorId; } - public function getDestinationStoredObjectId(): int - { - return $this->destinationStoredObjectId; - } - public function getTemplateId(): int { return $this->templateId; @@ -60,9 +42,4 @@ class RequestGenerationMessage { return $this->entityClassName; } - - public function getContextGenerationData(): array - { - return $this->contextGenerationData; - } } diff --git a/src/Bundle/ChillDocGeneratorBundle/config/services.yaml b/src/Bundle/ChillDocGeneratorBundle/config/services.yaml index 5fef6fb22..5bdfe2a11 100644 --- a/src/Bundle/ChillDocGeneratorBundle/config/services.yaml +++ b/src/Bundle/ChillDocGeneratorBundle/config/services.yaml @@ -20,14 +20,10 @@ services: resource: '../Serializer/Normalizer/' tags: - { name: 'serializer.normalizer', priority: -152 } - Chill\DocGeneratorBundle\Serializer\Normalizer\CollectionDocGenNormalizer: tags: - { name: 'serializer.normalizer', priority: -126 } - Chill\DocGeneratorBundle\Service\Context\: - resource: "../Service/Context" - Chill\DocGeneratorBundle\Controller\: resource: "../Controller" autowire: true @@ -38,20 +34,18 @@ services: autowire: true autoconfigure: true + Chill\DocGeneratorBundle\Service\Context\: + resource: "../Service/Context/" + autowire: true + autoconfigure: true + Chill\DocGeneratorBundle\GeneratorDriver\: resource: "../GeneratorDriver/" autowire: true autoconfigure: true - Chill\DocGeneratorBundle\Service\Messenger\: - resource: "../Service/Messenger/" - - Chill\DocGeneratorBundle\Service\Generator\Generator: ~ - Chill\DocGeneratorBundle\Service\Generator\GeneratorInterface: '@Chill\DocGeneratorBundle\Service\Generator\Generator' - Chill\DocGeneratorBundle\Driver\RelatorioDriver: '@Chill\DocGeneratorBundle\Driver\DriverInterface' Chill\DocGeneratorBundle\Context\ContextManager: arguments: $contexts: !tagged_iterator { tag: chill_docgen.context, default_index_method: getKey } - Chill\DocGeneratorBundle\Context\ContextManagerInterface: '@Chill\DocGeneratorBundle\Context\ContextManager' diff --git a/src/Bundle/ChillMainBundle/Phonenumber/PhonenumberHelper.php b/src/Bundle/ChillMainBundle/Phonenumber/PhonenumberHelper.php index 94a09cafb..5b52f6819 100644 --- a/src/Bundle/ChillMainBundle/Phonenumber/PhonenumberHelper.php +++ b/src/Bundle/ChillMainBundle/Phonenumber/PhonenumberHelper.php @@ -118,7 +118,7 @@ final class PhonenumberHelper implements PhoneNumberHelperInterface * Return true if the phonenumber is a landline or voip phone. Return always true * if the validation is not configured. * - * @param string|PhoneNumber $phonenumber + * @param string $phonenumber */ public function isValidPhonenumberAny($phonenumber): bool { @@ -138,7 +138,7 @@ final class PhonenumberHelper implements PhoneNumberHelperInterface * Return true if the phonenumber is a landline or voip phone. Return always true * if the validation is not configured. * - * @param string|PhoneNumber $phonenumber + * @param string $phonenumber */ public function isValidPhonenumberLandOrVoip($phonenumber): bool { @@ -159,7 +159,7 @@ final class PhonenumberHelper implements PhoneNumberHelperInterface * REturn true if the phonenumber is a mobile phone. Return always true * if the validation is not configured. * - * @param string|PhoneNumber $phonenumber + * @param string $phonenumber */ public function isValidPhonenumberMobile($phonenumber): bool { @@ -182,10 +182,6 @@ final class PhonenumberHelper implements PhoneNumberHelperInterface return null; } - if ($phonenumber instanceof PhoneNumber) { - $phonenumber = (string) $phonenumber; - } - // filter only number $filtered = preg_replace('/[^0-9]/', '', $phonenumber); diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php index dac850446..23bfac56f 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php @@ -256,16 +256,6 @@ class AccompanyingPeriodContext implements return $options['mainPerson'] || $options['person1'] || $options['person2']; } - public function publicFormTransform(DocGeneratorTemplate $template, $entity, array $data): array - { - // TODO: Implement publicFormTransform() method. - } - - public function publicFormReverseTransform(DocGeneratorTemplate $template, $entity, array $data): array - { - // TODO: Implement publicFormReverseTransform() method. - } - /** * @param AccompanyingPeriod $entity */ diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkContext.php index d73d1aa7b..7e9280e5d 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkContext.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkContext.php @@ -109,8 +109,6 @@ class AccompanyingPeriodWorkContext return $this->periodContext->hasPublicForm($template, $entity); } - - public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void { // TODO: Implement storeGenerated() method. diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php index 3b9d958cb..4dd14faab 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php @@ -174,16 +174,6 @@ class AccompanyingPeriodWorkEvaluationContext implements ->hasPublicForm($template, $entity->getAccompanyingPeriodWork()); } - public function publicFormTransform(DocGeneratorTemplate $template, $entity, array $data): array - { - // TODO: Implement publicFormTransform() method. - } - - public function publicFormReverseTransform(DocGeneratorTemplate $template, $entity, array $data): array - { - // TODO: Implement publicFormReverseTransform() method. - } - public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void { $doc = new AccompanyingPeriodWorkEvaluationDocument(); diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php index 5f98f7798..af6c6e114 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php @@ -21,13 +21,11 @@ use Chill\DocStoreBundle\Repository\DocumentCategoryRepository; use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter; use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Form\Type\ScopePickerType; -use Chill\MainBundle\Repository\ScopeRepositoryInterface; use Chill\MainBundle\Security\Authorization\AuthorizationHelper; use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface; use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\PersonBundle\Entity\Person; -use Chill\PersonBundle\Repository\PersonRepository; use DateTime; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; @@ -57,8 +55,6 @@ final class PersonContext implements PersonContextInterface private NormalizerInterface $normalizer; - private ScopeRepositoryInterface $scopeRepository; - private Security $security; private bool $showScopes; @@ -75,7 +71,6 @@ final class PersonContext implements PersonContextInterface EntityManagerInterface $em, NormalizerInterface $normalizer, ParameterBagInterface $parameterBag, - ScopeRepositoryInterface $scopeRepository, Security $security, TranslatorInterface $translator, TranslatableStringHelperInterface $translatableStringHelper @@ -86,7 +81,6 @@ final class PersonContext implements PersonContextInterface $this->documentCategoryRepository = $documentCategoryRepository; $this->em = $em; $this->normalizer = $normalizer; - $this->scopeRepository = $scopeRepository; $this->security = $security; $this->showScopes = $parameterBag->get('chill_main')['acl']['form_show_scopes']; $this->translator = $translator; @@ -217,38 +211,6 @@ final class PersonContext implements PersonContextInterface return true; } - /** - * @param Person $entity - */ - public function publicFormTransform(DocGeneratorTemplate $template, $entity, array $data): array - { - $scope = $data['scope'] ?? null; - - return [ - 'title' => $data['title'] ?? '', - 'scope_id' => $scope instanceof Scope ? $scope->getId() : null, - ]; - } - - /** - * @param Person $entity - */ - public function publicFormReverseTransform(DocGeneratorTemplate $template, $entity, array $data): array - { - if (!isset($data['scope'])) { - $scope = null; - } else { - if (null === $scope = $this->scopeRepository->find($data['scope'])) { - throw new \UnexpectedValueException('scope not found'); - } - } - - return [ - 'title' => $data['title'] ?? '', - 'scope' => $scope, - ]; - } - /** * @param Person $entity */ diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContextInterface.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContextInterface.php index 782ed13db..58a6b5863 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContextInterface.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContextInterface.php @@ -48,10 +48,6 @@ interface PersonContextInterface extends DocGeneratorContextWithAdminFormInterfa */ public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool; - public function publicFormTransform(DocGeneratorTemplate $template, $entity, array $data): array; - - public function publicFormReverseTransform(DocGeneratorTemplate $template, $entity, array $data): array; - /** * @param Person $entity */ diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContextWithThirdParty.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContextWithThirdParty.php index b4fa6fb26..23d57c431 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContextWithThirdParty.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContextWithThirdParty.php @@ -123,16 +123,6 @@ class PersonContextWithThirdParty implements DocGeneratorContextWithAdminFormInt return true; } - public function publicFormTransform(DocGeneratorTemplate $template, $entity, array $data): array - { - // TODO: Implement publicFormTransform() method. - } - - public function publicFormReverseTransform(DocGeneratorTemplate $template, $entity, array $data): array - { - // TODO: Implement publicFormReverseTransform() method. - } - public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void { $this->personContext->storeGenerated($template, $storedObject, $entity, $contextGenerationData);