Feature: [docgen][stored object] handler for request generator and required fixes

This commit is contained in:
Julien Fastré 2023-02-14 23:26:00 +01:00
parent 55918bcafb
commit 91d21ba939
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
18 changed files with 307 additions and 110 deletions

View File

@ -206,6 +206,16 @@ class ActivityContext implements
return $options['mainPerson'] || $options['person1'] || $options['person2']; 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 * @param Activity $entity
*/ */

View File

@ -146,6 +146,16 @@ class ListActivitiesByAccompanyingPeriodContext implements
return $this->accompanyingPeriodContext->hasPublicForm($template, $entity); 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 public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void
{ {
$this->accompanyingPeriodContext->storeGenerated($template, $storedObject, $entity, $contextGenerationData); $this->accompanyingPeriodContext->storeGenerated($template, $storedObject, $entity, $contextGenerationData);

View File

@ -226,6 +226,16 @@ final class CalendarContext implements CalendarContextInterface
return true; 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 * @param array{mainPerson?: Person, thirdParty?: ThirdParty, title: string} $contextGenerationData
*/ */

View File

@ -56,6 +56,10 @@ interface CalendarContextInterface extends DocGeneratorContextWithPublicFormInte
*/ */
public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool; 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 * @param Calendar $entity
*/ */

View File

@ -23,6 +23,9 @@ interface DocGeneratorContextWithPublicFormInterface extends DocGeneratorContext
*/ */
public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void; public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void;
/**
* Fill the form with initial data
*/
public function getFormData(DocGeneratorTemplate $template, $entity): array; public function getFormData(DocGeneratorTemplate $template, $entity): array;
/** /**
@ -31,4 +34,14 @@ interface DocGeneratorContextWithPublicFormInterface extends DocGeneratorContext
* @param mixed $entity * @param mixed $entity
*/ */
public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool; 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;
} }

View File

@ -16,30 +16,28 @@ use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithPublicFormInterface;
use Chill\DocGeneratorBundle\Context\Exception\ContextNotFoundException; use Chill\DocGeneratorBundle\Context\Exception\ContextNotFoundException;
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate; use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
use Chill\DocGeneratorBundle\GeneratorDriver\DriverInterface; use Chill\DocGeneratorBundle\GeneratorDriver\DriverInterface;
use Chill\DocGeneratorBundle\GeneratorDriver\Exception\TemplateException;
use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository; 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\Entity\StoredObject;
use Chill\DocStoreBundle\Service\StoredObjectManagerInterface; use Chill\DocStoreBundle\Service\StoredObjectManagerInterface;
use Chill\MainBundle\Pagination\PaginatorFactory; use Chill\MainBundle\Pagination\PaginatorFactory;
use Chill\MainBundle\Serializer\Model\Collection; use Chill\MainBundle\Serializer\Model\Collection;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Exception;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\FileType; use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
// TODO à mettre dans services // TODO à mettre dans services
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Contracts\HttpClient\HttpClientInterface; use Symfony\Contracts\HttpClient\HttpClientInterface;
use Throwable;
use function strlen; use function strlen;
final class DocGeneratorTemplateController extends AbstractController final class DocGeneratorTemplateController extends AbstractController
@ -54,17 +52,24 @@ final class DocGeneratorTemplateController extends AbstractController
private EntityManagerInterface $entityManager; private EntityManagerInterface $entityManager;
private GeneratorInterface $generator;
private LoggerInterface $logger; private LoggerInterface $logger;
private MessageBusInterface $messageBus;
private PaginatorFactory $paginatorFactory; private PaginatorFactory $paginatorFactory;
private StoredObjectManagerInterface $storedObjectManager; private StoredObjectManagerInterface $storedObjectManager;
public function __construct( public function __construct(
ContextManager $contextManager, ContextManager $contextManager,
DocGeneratorTemplateRepository $docGeneratorTemplateRepository, DocGeneratorTemplateRepository $docGeneratorTemplateRepository,
DriverInterface $driver, DriverInterface $driver,
GeneratorInterface $generator,
LoggerInterface $logger, LoggerInterface $logger,
MessageBusInterface $messageBus,
PaginatorFactory $paginatorFactory, PaginatorFactory $paginatorFactory,
HttpClientInterface $client, HttpClientInterface $client,
StoredObjectManagerInterface $storedObjectManager, StoredObjectManagerInterface $storedObjectManager,
@ -73,7 +78,9 @@ final class DocGeneratorTemplateController extends AbstractController
$this->contextManager = $contextManager; $this->contextManager = $contextManager;
$this->docGeneratorTemplateRepository = $docGeneratorTemplateRepository; $this->docGeneratorTemplateRepository = $docGeneratorTemplateRepository;
$this->driver = $driver; $this->driver = $driver;
$this->generator = $generator;
$this->logger = $logger; $this->logger = $logger;
$this->messageBus = $messageBus;
$this->paginatorFactory = $paginatorFactory; $this->paginatorFactory = $paginatorFactory;
$this->client = $client; $this->client = $client;
$this->storedObjectManager = $storedObjectManager; $this->storedObjectManager = $storedObjectManager;
@ -259,99 +266,72 @@ final class DocGeneratorTemplateController extends AbstractController
} }
} }
$document = $template->getFile(); // transform context generation data
$contextGenerationDataSanitized = array_merge(
if ($isTest && ($contextGenerationData['test_file'] instanceof File)) { $contextGenerationData,
$dataDecrypted = file_get_contents($contextGenerationData['test_file']->getPathname()); $context instanceof DocGeneratorContextWithPublicFormInterface ?
} else { $context->publicFormTransform($template, $entity, $contextGenerationData)
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()) { if ($isTest && isset($form) && $form['show_data']->getData()) {
return $this->render('@ChillDocGenerator/Generator/debug_value.html.twig', [ return $this->render('@ChillDocGenerator/Generator/debug_value.html.twig', [
'datas' => json_encode($context->getData($template, $entity, $contextGenerationData), JSON_PRETTY_PRINT) 'datas' => json_encode($context->getData($template, $entity, $contextGenerationData), JSON_PRETTY_PRINT)
]); ]);
} } elseif ($isTest) {
$generated = $this->generator->generateDocFromTemplate(
try { $template,
$generatedResource = $this $entityClassName,
->driver $entityId,
->generateFromString( $contextGenerationDataSanitized,
$dataDecrypted, null,
$template->getFile()->getType(), true,
$context->getData($template, $entity, $contextGenerationData), isset($form) ? $form['test_file']->getData() : null
$template->getFile()->getFilename()
);
} catch (TemplateException $e) {
return new Response(
implode("\n", $e->getErrors()),
400,
[
'Content-Type' => 'text/plain',
]
); );
}
if ($isTest) {
return new Response( return new Response(
$generatedResource, $generated,
Response::HTTP_OK, Response::HTTP_OK,
[ [
'Content-Transfer-Encoding', 'binary', 'Content-Transfer-Encoding', 'binary',
'Content-Type' => 'application/vnd.oasis.opendocument.text', 'Content-Type' => 'application/vnd.oasis.opendocument.text',
'Content-Disposition' => 'attachment; filename="generated.odt"', 'Content-Disposition' => 'attachment; filename="generated.odt"',
'Content-Length' => strlen($generatedResource), 'Content-Length' => strlen($generated),
], ],
); );
} }
/** @var StoredObject $storedObject */ // this is not a test
$storedObject = (new ObjectNormalizer()) // we prepare the object to store the document
->denormalize( $storedObject = (new StoredObject())
[ ->setStatus(StoredObject::STATUS_PENDING)
'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); $this->entityManager->persist($storedObject);
try { // we store the generated document
$context $context
->storeGenerated( ->storeGenerated(
$template, $template,
$storedObject, $storedObject,
$entity, $entity,
$contextGenerationData $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->entityManager->flush();
$this->messageBus->dispatch(
new RequestGenerationMessage(
$this->getUser(),
$template,
$entityId,
$entityClassName,
$storedObject,
$contextGenerationDataSanitized,
)
);
return $this return $this
->redirectToRoute( ->redirectToRoute(
'chill_wopi_file_edit', 'chill_wopi_file_edit',

View File

@ -3,6 +3,7 @@
namespace Chill\DocGeneratorBundle\Service\Generator; namespace Chill\DocGeneratorBundle\Service\Generator;
use Chill\DocGeneratorBundle\Context\ContextManagerInterface; use Chill\DocGeneratorBundle\Context\ContextManagerInterface;
use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithPublicFormInterface;
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate; use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
use Chill\DocGeneratorBundle\GeneratorDriver\DriverInterface; use Chill\DocGeneratorBundle\GeneratorDriver\DriverInterface;
use Chill\DocGeneratorBundle\GeneratorDriver\Exception\TemplateException; use Chill\DocGeneratorBundle\GeneratorDriver\Exception\TemplateException;
@ -12,7 +13,7 @@ use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\File\File; use Symfony\Component\HttpFoundation\File\File;
class Generator class Generator implements GeneratorInterface
{ {
private ContextManagerInterface $contextManager; private ContextManagerInterface $contextManager;
@ -50,6 +51,7 @@ class Generator
DocGeneratorTemplate $template, DocGeneratorTemplate $template,
string $entityClassName, string $entityClassName,
int $entityId, int $entityId,
array $contextGenerationData,
?StoredObject $destinationStoredObject = null, ?StoredObject $destinationStoredObject = null,
bool $isTest = false, bool $isTest = false,
?File $testFile = null ?File $testFile = null
@ -59,7 +61,6 @@ class Generator
} }
$context = $this->contextManager->getContextByDocGeneratorTemplate($template); $context = $this->contextManager->getContextByDocGeneratorTemplate($template);
$contextGenerationData = ['test_file' => $testFile];
$entity = $this $entity = $this
->entityManager ->entityManager
@ -70,6 +71,13 @@ class Generator
throw new RelatedEntityNotFoundException($entityClassName, $entityId); throw new RelatedEntityNotFoundException($entityClassName, $entityId);
} }
$contextGenerationData = array_merge(
$contextGenerationData,
$context instanceof DocGeneratorContextWithPublicFormInterface ?
$context->publicFormReverseTransform($template, $entity, $contextGenerationData)
: []
);
if ($isTest && ($testFile instanceof File)) { if ($isTest && ($testFile instanceof File)) {
$dataDecrypted = file_get_contents($testFile->getPathname()); $dataDecrypted = file_get_contents($testFile->getPathname());
} else { } else {
@ -102,29 +110,6 @@ class Generator
$this->storedObjectManager->write($destinationStoredObject, $generatedResource); $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(); $this->entityManager->flush();
return null; return null;

View File

@ -0,0 +1,28 @@
<?php
namespace Chill\DocGeneratorBundle\Service\Generator;
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
use Chill\DocStoreBundle\Entity\StoredObject;
use Symfony\Component\HttpFoundation\File\File;
interface GeneratorInterface
{
/**
* @template T of File|null
* @template B of bool
* @param B $isTest
* @param (B is true ? T : null) $testFile
* @psalm-return (B is true ? string : null)
* @throws \Symfony\Component\Serializer\Exception\ExceptionInterface|\Throwable
*/
public function generateDocFromTemplate(
DocGeneratorTemplate $template,
string $entityClassName,
int $entityId,
array $contextGenerationData,
?StoredObject $destinationStoredObject = null,
bool $isTest = false,
?File $testFile = null
): ?string;
}

View File

@ -0,0 +1,50 @@
<?php
namespace Chill\DocGeneratorBundle\Service\Messenger;
use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository;
use Chill\DocGeneratorBundle\Service\Generator\Generator;
use Chill\DocStoreBundle\Repository\StoredObjectRepository;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
/**
* Handle the request of document generation
*/
class RequestGenerationHandler implements MessageHandlerInterface
{
private StoredObjectRepository $storedObjectRepository;
private DocGeneratorTemplateRepository $docGeneratorTemplateRepository;
private Generator $generator;
public function __construct(
StoredObjectRepository $storedObjectRepository,
DocGeneratorTemplateRepository $docGeneratorTemplateRepository,
Generator $generator
) {
$this->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
);
}
}

View File

@ -3,6 +3,7 @@
namespace Chill\DocGeneratorBundle\Service\Messenger; namespace Chill\DocGeneratorBundle\Service\Messenger;
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate; use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
use Chill\DocStoreBundle\Entity\StoredObject;
use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\User;
class RequestGenerationMessage class RequestGenerationMessage
@ -15,12 +16,24 @@ class RequestGenerationMessage
private string $entityClassName; private string $entityClassName;
public function __construct(User $creator, DocGeneratorTemplate $template, int $entityId, string $entityClassName) private int $destinationStoredObjectId;
{
private array $contextGenerationData;
public function __construct(
User $creator,
DocGeneratorTemplate $template,
int $entityId,
string $entityClassName,
StoredObject $destinationStoredObject,
array $contextGenerationData
) {
$this->creatorId = $creator->getId(); $this->creatorId = $creator->getId();
$this->templateId = $template->getId(); $this->templateId = $template->getId();
$this->entityId = $entityId; $this->entityId = $entityId;
$this->entityClassName = $entityClassName; $this->entityClassName = $entityClassName;
$this->destinationStoredObjectId = $destinationStoredObject->getId();
$this->contextGenerationData = $contextGenerationData;
} }
public function getCreatorId(): int public function getCreatorId(): int
@ -28,6 +41,11 @@ class RequestGenerationMessage
return $this->creatorId; return $this->creatorId;
} }
public function getDestinationStoredObjectId(): int
{
return $this->destinationStoredObjectId;
}
public function getTemplateId(): int public function getTemplateId(): int
{ {
return $this->templateId; return $this->templateId;
@ -42,4 +60,9 @@ class RequestGenerationMessage
{ {
return $this->entityClassName; return $this->entityClassName;
} }
public function getContextGenerationData(): array
{
return $this->contextGenerationData;
}
} }

View File

@ -20,10 +20,14 @@ services:
resource: '../Serializer/Normalizer/' resource: '../Serializer/Normalizer/'
tags: tags:
- { name: 'serializer.normalizer', priority: -152 } - { name: 'serializer.normalizer', priority: -152 }
Chill\DocGeneratorBundle\Serializer\Normalizer\CollectionDocGenNormalizer: Chill\DocGeneratorBundle\Serializer\Normalizer\CollectionDocGenNormalizer:
tags: tags:
- { name: 'serializer.normalizer', priority: -126 } - { name: 'serializer.normalizer', priority: -126 }
Chill\DocGeneratorBundle\Service\Context\:
resource: "../Service/Context"
Chill\DocGeneratorBundle\Controller\: Chill\DocGeneratorBundle\Controller\:
resource: "../Controller" resource: "../Controller"
autowire: true autowire: true
@ -34,18 +38,20 @@ services:
autowire: true autowire: true
autoconfigure: true autoconfigure: true
Chill\DocGeneratorBundle\Service\Context\:
resource: "../Service/Context/"
autowire: true
autoconfigure: true
Chill\DocGeneratorBundle\GeneratorDriver\: Chill\DocGeneratorBundle\GeneratorDriver\:
resource: "../GeneratorDriver/" resource: "../GeneratorDriver/"
autowire: true autowire: true
autoconfigure: 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\Driver\RelatorioDriver: '@Chill\DocGeneratorBundle\Driver\DriverInterface'
Chill\DocGeneratorBundle\Context\ContextManager: Chill\DocGeneratorBundle\Context\ContextManager:
arguments: arguments:
$contexts: !tagged_iterator { tag: chill_docgen.context, default_index_method: getKey } $contexts: !tagged_iterator { tag: chill_docgen.context, default_index_method: getKey }
Chill\DocGeneratorBundle\Context\ContextManagerInterface: '@Chill\DocGeneratorBundle\Context\ContextManager'

View File

@ -118,7 +118,7 @@ final class PhonenumberHelper implements PhoneNumberHelperInterface
* Return true if the phonenumber is a landline or voip phone. Return always true * Return true if the phonenumber is a landline or voip phone. Return always true
* if the validation is not configured. * if the validation is not configured.
* *
* @param string $phonenumber * @param string|PhoneNumber $phonenumber
*/ */
public function isValidPhonenumberAny($phonenumber): bool 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 * Return true if the phonenumber is a landline or voip phone. Return always true
* if the validation is not configured. * if the validation is not configured.
* *
* @param string $phonenumber * @param string|PhoneNumber $phonenumber
*/ */
public function isValidPhonenumberLandOrVoip($phonenumber): bool 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 * REturn true if the phonenumber is a mobile phone. Return always true
* if the validation is not configured. * if the validation is not configured.
* *
* @param string $phonenumber * @param string|PhoneNumber $phonenumber
*/ */
public function isValidPhonenumberMobile($phonenumber): bool public function isValidPhonenumberMobile($phonenumber): bool
{ {
@ -182,6 +182,10 @@ final class PhonenumberHelper implements PhoneNumberHelperInterface
return null; return null;
} }
if ($phonenumber instanceof PhoneNumber) {
$phonenumber = (string) $phonenumber;
}
// filter only number // filter only number
$filtered = preg_replace('/[^0-9]/', '', $phonenumber); $filtered = preg_replace('/[^0-9]/', '', $phonenumber);

View File

@ -256,6 +256,16 @@ class AccompanyingPeriodContext implements
return $options['mainPerson'] || $options['person1'] || $options['person2']; 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 * @param AccompanyingPeriod $entity
*/ */

View File

@ -109,6 +109,8 @@ class AccompanyingPeriodWorkContext
return $this->periodContext->hasPublicForm($template, $entity); return $this->periodContext->hasPublicForm($template, $entity);
} }
public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void
{ {
// TODO: Implement storeGenerated() method. // TODO: Implement storeGenerated() method.

View File

@ -174,6 +174,16 @@ class AccompanyingPeriodWorkEvaluationContext implements
->hasPublicForm($template, $entity->getAccompanyingPeriodWork()); ->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 public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void
{ {
$doc = new AccompanyingPeriodWorkEvaluationDocument(); $doc = new AccompanyingPeriodWorkEvaluationDocument();

View File

@ -21,11 +21,13 @@ use Chill\DocStoreBundle\Repository\DocumentCategoryRepository;
use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter; use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter;
use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Form\Type\ScopePickerType; use Chill\MainBundle\Form\Type\ScopePickerType;
use Chill\MainBundle\Repository\ScopeRepositoryInterface;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper; use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface; use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface; use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Repository\PersonRepository;
use DateTime; use DateTime;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
@ -55,6 +57,8 @@ final class PersonContext implements PersonContextInterface
private NormalizerInterface $normalizer; private NormalizerInterface $normalizer;
private ScopeRepositoryInterface $scopeRepository;
private Security $security; private Security $security;
private bool $showScopes; private bool $showScopes;
@ -71,6 +75,7 @@ final class PersonContext implements PersonContextInterface
EntityManagerInterface $em, EntityManagerInterface $em,
NormalizerInterface $normalizer, NormalizerInterface $normalizer,
ParameterBagInterface $parameterBag, ParameterBagInterface $parameterBag,
ScopeRepositoryInterface $scopeRepository,
Security $security, Security $security,
TranslatorInterface $translator, TranslatorInterface $translator,
TranslatableStringHelperInterface $translatableStringHelper TranslatableStringHelperInterface $translatableStringHelper
@ -81,6 +86,7 @@ final class PersonContext implements PersonContextInterface
$this->documentCategoryRepository = $documentCategoryRepository; $this->documentCategoryRepository = $documentCategoryRepository;
$this->em = $em; $this->em = $em;
$this->normalizer = $normalizer; $this->normalizer = $normalizer;
$this->scopeRepository = $scopeRepository;
$this->security = $security; $this->security = $security;
$this->showScopes = $parameterBag->get('chill_main')['acl']['form_show_scopes']; $this->showScopes = $parameterBag->get('chill_main')['acl']['form_show_scopes'];
$this->translator = $translator; $this->translator = $translator;
@ -211,6 +217,38 @@ final class PersonContext implements PersonContextInterface
return true; 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 * @param Person $entity
*/ */

View File

@ -48,6 +48,10 @@ interface PersonContextInterface extends DocGeneratorContextWithAdminFormInterfa
*/ */
public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool; 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 * @param Person $entity
*/ */

View File

@ -123,6 +123,16 @@ class PersonContextWithThirdParty implements DocGeneratorContextWithAdminFormInt
return true; 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 public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void
{ {
$this->personContext->storeGenerated($template, $storedObject, $entity, $contextGenerationData); $this->personContext->storeGenerated($template, $storedObject, $entity, $contextGenerationData);