From a9694da557bce894fce7848465c4c2395bfbfdeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Sun, 27 Feb 2022 02:38:08 +0100 Subject: [PATCH] add workflow on evaluationdocument in UI --- .../vuejs/_components/AddAsyncUpload.vue | 3 +- .../Normalizer/StoredObjectDenormalizer.php | 10 ++- .../EntityWorkflow/ListWorkflowModal.vue | 9 ++- .../EntityWorkflow/PickWorkflow.vue | 6 +- .../Resources/views/Workflow/delete.html.twig | 7 +- .../AccompanyingPeriodWork.php | 5 +- .../AccompanyingPeriodWorkEvaluation.php | 11 ++- ...companyingPeriodWorkEvaluationDocument.php | 42 ++++++++++- .../components/FormEvaluation.vue | 43 ++++++++--- .../vuejs/AccompanyingCourseWorkEdit/store.js | 19 +++-- ...nyingPeriodWorkEvaluationDocumentVoter.php | 29 +++++--- ...anyingPeriodWorkEvaluationDenormalizer.php | 25 ++----- ...PeriodWorkEvaluationDocumentNormalizer.php | 71 +++++++++++++++++++ ...mpanyingPeriodWorkEvaluationNormalizer.php | 9 +++ .../AccompanyingPeriodWorkNormalizer.php | 15 ++++ ...dWorkEvaluationDocumentWorkflowHandler.php | 6 +- 16 files changed, 244 insertions(+), 66 deletions(-) create mode 100644 src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationDocumentNormalizer.php diff --git a/src/Bundle/ChillDocStoreBundle/Resources/public/vuejs/_components/AddAsyncUpload.vue b/src/Bundle/ChillDocStoreBundle/Resources/public/vuejs/_components/AddAsyncUpload.vue index e931f1b68..ebd2ab4b4 100644 --- a/src/Bundle/ChillDocStoreBundle/Resources/public/vuejs/_components/AddAsyncUpload.vue +++ b/src/Bundle/ChillDocStoreBundle/Resources/public/vuejs/_components/AddAsyncUpload.vue @@ -144,6 +144,7 @@ export default { this.$toast.open({message: v }); } } else { + console.error(error); this.$toast.open({message: 'An error occurred'}); } }); @@ -153,4 +154,4 @@ export default { } } } - \ No newline at end of file + diff --git a/src/Bundle/ChillDocStoreBundle/Serializer/Normalizer/StoredObjectDenormalizer.php b/src/Bundle/ChillDocStoreBundle/Serializer/Normalizer/StoredObjectDenormalizer.php index 762aed7fb..1c32b3d03 100644 --- a/src/Bundle/ChillDocStoreBundle/Serializer/Normalizer/StoredObjectDenormalizer.php +++ b/src/Bundle/ChillDocStoreBundle/Serializer/Normalizer/StoredObjectDenormalizer.php @@ -13,13 +13,15 @@ namespace Chill\DocStoreBundle\Serializer\Normalizer; use Chill\DocStoreBundle\Entity\StoredObject; use Chill\DocStoreBundle\Repository\StoredObjectRepository; -use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; +use Symfony\Component\Serializer\Normalizer\ObjectToPopulateTrait; use function array_key_exists; use function is_array; class StoredObjectDenormalizer implements DenormalizerInterface { + use ObjectToPopulateTrait; + private StoredObjectRepository $storedObjectRepository; public function __construct(StoredObjectRepository $storedObjectRepository) @@ -29,8 +31,10 @@ class StoredObjectDenormalizer implements DenormalizerInterface public function denormalize($data, $type, $format = null, array $context = []) { - if (array_key_exists(AbstractNormalizer::OBJECT_TO_POPULATE, $context)) { - return $context[AbstractNormalizer::OBJECT_TO_POPULATE]; + $object = $this->extractObjectToPopulate(StoredObject::class, $context); + + if (null !== $object) { + return $object; } return $this->storedObjectRepository->find($data['id']); diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/EntityWorkflow/ListWorkflowModal.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/EntityWorkflow/ListWorkflowModal.vue index 2e4125c1a..151bc06c7 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/EntityWorkflow/ListWorkflowModal.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/EntityWorkflow/ListWorkflowModal.vue @@ -12,6 +12,8 @@ :relatedEntityClass="this.relatedEntityClass" :relatedEntityId="this.relatedEntityId" :workflowsAvailables="workflowsAvailables" + :preventDefaultMoveToGenerate="this.$props.preventDefaultMoveToGenerate" + :goToGenerateWorkflowPayload="this.goToGenerateWorkflowPayload" @go-to-generate-workflow="goToGenerateWorkflow" > @@ -36,6 +38,7 @@ :relatedEntityId="this.relatedEntityId" :workflowsAvailables="workflowsAvailables" :preventDefaultMoveToGenerate="this.$props.preventDefaultMoveToGenerate" + :goToGenerateWorkflowPayload="this.goToGenerateWorkflowPayload" @go-to-generate-workflow="this.goToGenerateWorkflow" > @@ -83,6 +86,10 @@ export default { required: false, default: false, }, + goToGenerateWorkflowPayload: { + required: false, + default: {} + }, }, data() { return { @@ -105,7 +112,7 @@ export default { this.modal.showModal = true; }, goToGenerateWorkflow(data) { - console.log('go to generate workflow intercepted'); + console.log('go to generate workflow intercepted', data); this.$emit('goToGenerateWorkflow', data); } }, diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/EntityWorkflow/PickWorkflow.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/EntityWorkflow/PickWorkflow.vue index 826917fbb..9ed1ef6cc 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/EntityWorkflow/PickWorkflow.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/EntityWorkflow/PickWorkflow.vue @@ -37,6 +37,10 @@ export default { required: false, default: false, }, + goToGenerateWorkflowPayload: { + required: false, + default: {} + }, }, emits: ['goToGenerateWorkflow'], methods: { @@ -51,7 +55,7 @@ export default { window.location.assign(this.makeLink(workflowName)); } - this.$emit('goToGenerateWorkflow', {event, workflowName, link: this.makeLink(workflowName)}); + this.$emit('goToGenerateWorkflow', {event, workflowName, link: this.makeLink(workflowName), payload: this.goToGenerateWorkflowPayload}); } } } diff --git a/src/Bundle/ChillMainBundle/Resources/views/Workflow/delete.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Workflow/delete.html.twig index 964e61c27..64da4ea76 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Workflow/delete.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Workflow/delete.html.twig @@ -4,14 +4,9 @@ {% block display_content %}

- {{ 'workflow_'|trans }} + {{ handler.entityTitle(entityWorkflow) }}

- {% include handler.templateTitle(entityWorkflow) with handler.templateTitleData(entityWorkflow)|merge({ - 'description': true, - 'add_classes': 'ms-3 h3' - }) %} - {% include handler.template(entityWorkflow) with handler.templateData(entityWorkflow)|merge({ 'display_action': false }) %} diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php index b7e8d1c5d..ed00c8611 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php @@ -250,10 +250,7 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues return $this->accompanyingPeriod; } - /** - * @return Collection - */ - public function getAccompanyingPeriodWorkEvaluations() + public function getAccompanyingPeriodWorkEvaluations(): Collection { return $this->accompanyingPeriodWorkEvaluations; } diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWorkEvaluation.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWorkEvaluation.php index 247c7aace..07c9f526c 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWorkEvaluation.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWorkEvaluation.php @@ -67,13 +67,17 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU private ?User $createdBy = null; /** + * **Note on deserialization/denormalization**: denormalization of documents is handled by. + * + * @see{Chill\PersonBundle\Serializer\Normalizer\AccompanyingPeriodWorkEvaluationDenormalizer} + * * @ORM\OneToMany( * targetEntity=AccompanyingPeriodWorkEvaluationDocument::class, * mappedBy="accompanyingPeriodWorkEvaluation", - * cascade={"remove", "persist"} + * cascade={"remove", "persist"}, + * orphanRemoval=true * ) - * @Serializer\Groups({"read", "write"}) - * @Serializer\Groups({"accompanying_period_work_evaluation:create"}) + * @Serializer\Groups({"read"}) */ private Collection $documents; @@ -262,6 +266,7 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU public function removeDocument(AccompanyingPeriodWorkEvaluationDocument $document): self { $this->documents->removeElement($document); + $document->setAccompanyingPeriodWorkEvaluation(null); return $this; } diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWorkEvaluationDocument.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWorkEvaluationDocument.php index faae0f4c3..b31225df1 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWorkEvaluationDocument.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWorkEvaluationDocument.php @@ -41,6 +41,7 @@ class AccompanyingPeriodWorkEvaluationDocument implements \Chill\MainBundle\Doct /** * @ORM\Column(type="date_immutable", nullable=true, options={"default": null}) * @Serializer\Groups({"read"}) + * @Serializer\Groups({"accompanying_period_work_evaluation:create"}) */ private ?\DateTimeImmutable $createdAt = null; @@ -49,6 +50,7 @@ class AccompanyingPeriodWorkEvaluationDocument implements \Chill\MainBundle\Doct * targetEntity=User::class * ) * @Serializer\Groups({"read"}) + * @Serializer\Groups({"accompanying_period_work_evaluation:create"}) */ private ?User $createdBy = null; @@ -60,13 +62,28 @@ class AccompanyingPeriodWorkEvaluationDocument implements \Chill\MainBundle\Doct * @internal the default name exceeds 64 characters, we must set manually: * @ORM\SequenceGenerator(sequenceName="chill_person_social_work_eval_doc_id_seq", allocationSize=1, initialValue=1000) * @Serializer\Groups({"read"}) + * @Serializer\Groups({"accompanying_period_work_evaluation:create"}) */ private ?int $id = null; + /** + * This is a workaround for client, to allow them to assign arbitrary data + * dedicated to their job. + * + * This data is not persisted into database, but will appears on the data + * normalized during the same request (like PUT/PATCH request) + * + * @Serializer\Groups({"read"}) + * @Serializer\Groups({"write"}) + * @Serializer\Groups({"accompanying_period_work_evaluation:create"}) + * + * @var mixed + */ + private $key; + /** * @ORM\ManyToOne( * targetEntity=StoredObject::class, - * cascade={"remove"}, * ) * @Serializer\Groups({"read"}) * @Serializer\Groups({"write"}) @@ -79,6 +96,7 @@ class AccompanyingPeriodWorkEvaluationDocument implements \Chill\MainBundle\Doct * targetEntity=DocGeneratorTemplate::class * ) * @Serializer\Groups({"read"}) + * @Serializer\Groups({"accompanying_period_work_evaluation:create"}) */ private ?DocGeneratorTemplate $template = null; @@ -93,6 +111,7 @@ class AccompanyingPeriodWorkEvaluationDocument implements \Chill\MainBundle\Doct /** * @ORM\Column(type="date_immutable", nullable=true, options={"default": null}) * @Serializer\Groups({"read"}) + * @Serializer\Groups({"accompanying_period_work_evaluation:create"}) */ private ?\DateTimeImmutable $updatedAt = null; @@ -101,6 +120,7 @@ class AccompanyingPeriodWorkEvaluationDocument implements \Chill\MainBundle\Doct * targetEntity=User::class * ) * @Serializer\Groups({"read"}) + * @Serializer\Groups({"accompanying_period_work_evaluation:create"}) */ private ?User $updatedBy = null; @@ -127,6 +147,14 @@ class AccompanyingPeriodWorkEvaluationDocument implements \Chill\MainBundle\Doct return $this->id; } + /** + * @return mixed + */ + public function getKey() + { + return $this->key; + } + public function getStoredObject(): ?StoredObject { return $this->storedObject; @@ -186,6 +214,18 @@ class AccompanyingPeriodWorkEvaluationDocument implements \Chill\MainBundle\Doct return $this; } + /** + * @param mixed $key + * + * @return AccompanyingPeriodWorkEvaluationDocument + */ + public function setKey($key) + { + $this->key = $key; + + return $this; + } + public function setStoredObject(?StoredObject $storedObject): AccompanyingPeriodWorkEvaluationDocument { $this->storedObject = $storedObject; diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/components/FormEvaluation.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/components/FormEvaluation.vue index dfa739551..b077cfefa 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/components/FormEvaluation.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/components/FormEvaluation.vue @@ -65,7 +65,7 @@
{{ $t('Documents') }} :
-
+
@@ -86,13 +86,23 @@
@@ -142,6 +152,8 @@ import { mapGetters, mapState } from 'vuex'; import PickTemplate from 'ChillDocGeneratorAssets/vuejs/_components/PickTemplate.vue'; import {buildLink} from 'ChillDocGeneratorAssets/lib/document-generator'; import AddAsyncUpload from 'ChillDocStoreAssets/vuejs/_components/AddAsyncUpload.vue'; +import ListWorkflowModal from 'ChillMainAssets/vuejs/_components/EntityWorkflow/ListWorkflowModal.vue'; +import {buildLinkCreate} from 'ChillMainAssets/lib/entity-workflow/api.js'; const i18n = { messages: { @@ -175,7 +187,8 @@ export default { components: { ckeditor: CKEditor.component, PickTemplate, - AddAsyncUpload + AddAsyncUpload, + ListWorkflowModal, }, i18n, data() { @@ -189,9 +202,6 @@ export default { } } }, - mounted() { - console.log(this.evaluation) - }, computed: { ...mapState([ 'isPosting' @@ -279,7 +289,18 @@ export default { if (window.confirm("Êtes-vous sûr·e de vouloir supprimer le document qui a pour titre \"" + document.title +"\" ?")) { this.$store.commit('removeDocument', {key: this.evaluation.key, document: document}); } - } + }, + goToGenerateWorkflowEvaluationDocument({event, link, workflowName, payload}) { + const callback = (data) => { + let evaluation = data.accompanyingPeriodWorkEvaluations.find(e => e.key === this.evaluation.key); + let updatedDocument = evaluation.documents.find(d => d.key === payload.doc.key); + window.location.assign(buildLinkCreate(workflowName, + 'Chill\\PersonBundle\\Entity\\AccompanyingPeriod\\AccompanyingPeriodWorkEvaluationDocument', updatedDocument.id)); + }; + + return this.$store.dispatch('submit', callback) + .catch(e => { console.log(e); throw e; }); + }, }, } diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js index 89c6c8811..7f96843e5 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js @@ -131,6 +131,11 @@ const store = createStore({ endDate: e.endDate !== null ? ISOToDatetime(e.endDate.datetime) : null, maxDate: e.maxDate !== null ? ISOToDatetime(e.maxDate.datetime) : null, warningInterval: e.warningInterval !== null ? intervalISOToDays(e.warningInterval) : null, + documents: e.documents.map((d, dindex) => { + return Object.assign(d, { + key: index + }); + }), }); return k; @@ -199,16 +204,22 @@ const store = createStore({ found.results = found.results.filter(r => r.id !== result.id); }, addDocument(state, payload) { - state.evaluationsPicked.find(e => e.key === payload.key).documents.push(payload.document); + let evaluation = state.evaluationsPicked.find(e => e.key === payload.key); + evaluation.documents.push(Object.assign( + payload.document, { + key: evaluation.documents.length + 1, + workflows_availables: state.work.workflows_availables_evaluation_documents, + workflows: [], + })); }, - removeDocument(state, payload) { - let evaluations = state.evaluationsPicked.find(e => e.key === payload.key); + removeDocument(state, {key, document}) { + let evaluations = state.evaluationsPicked.find(e => e.key === key); if (evaluations === undefined) { return; } - evaluations.documents = evaluations.documents.filter(d => d.id !== payload.document.id); + evaluations.documents = evaluations.documents.filter(d => d.key !== document.key); }, addEvaluation(state, evaluation) { let e = { diff --git a/src/Bundle/ChillPersonBundle/Security/Authorization/AccompanyingPeriodWorkEvaluationDocumentVoter.php b/src/Bundle/ChillPersonBundle/Security/Authorization/AccompanyingPeriodWorkEvaluationDocumentVoter.php index b3b6dab56..7ce259714 100644 --- a/src/Bundle/ChillPersonBundle/Security/Authorization/AccompanyingPeriodWorkEvaluationDocumentVoter.php +++ b/src/Bundle/ChillPersonBundle/Security/Authorization/AccompanyingPeriodWorkEvaluationDocumentVoter.php @@ -1,14 +1,24 @@ accessDecisionManager->decide($token, [AccompanyingPeriodWorkEvaluationVoter::SEE], - $subject->getAccompanyingPeriodWorkEvaluation()); + return $this->accessDecisionManager->decide( + $token, + [AccompanyingPeriodWorkEvaluationVoter::SEE], + $subject->getAccompanyingPeriodWorkEvaluation() + ); default: - throw new \UnexpectedValueException("The attribute $attribute is not supported"); + throw new UnexpectedValueException("The attribute {$attribute} is not supported"); } } - - } diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationDenormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationDenormalizer.php index 12bd254c5..4680d9fa7 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationDenormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationDenormalizer.php @@ -23,7 +23,6 @@ use Symfony\Component\Serializer\Normalizer\ObjectToPopulateTrait; use function array_key_exists; use function array_merge; -use function in_array; use function is_array; /** @@ -33,6 +32,7 @@ use function is_array; class AccompanyingPeriodWorkEvaluationDenormalizer implements ContextAwareDenormalizerInterface, DenormalizerAwareInterface { use DenormalizerAwareTrait; + use ObjectToPopulateTrait; private EntityManagerInterface $em; @@ -54,9 +54,7 @@ class AccompanyingPeriodWorkEvaluationDenormalizer implements ContextAwareDenorm ['skip' => self::class] )); - //if (in_array('accompanying_period_work:edit', $context['groups'] ?? [], true)) { - $this->handleEvaluationCollection($data, $evaluation, $format, $context); - //} + $this->handleDocumentCollection($data, $evaluation, $format, $context); return $evaluation; } @@ -70,7 +68,7 @@ class AccompanyingPeriodWorkEvaluationDenormalizer implements ContextAwareDenorm && 'accompanying_period_work_evaluation' === $data['type']; } - private function handleEvaluationCollection(array $data, AccompanyingPeriodWorkEvaluation $evaluation, string $format, array $context) + private function handleDocumentCollection(array $data, AccompanyingPeriodWorkEvaluation $evaluation, string $format, array $context) { $dataById = []; $dataWithoutId = []; @@ -82,29 +80,21 @@ class AccompanyingPeriodWorkEvaluationDenormalizer implements ContextAwareDenorm $dataWithoutId[] = $e; } } - dump($dataById); - dump($dataWithoutId); - dump($evaluation); //partition the separate kept documents and removed one [$kept, $removed] = $evaluation->getDocuments() ->partition( static fn (int $key, AccompanyingPeriodWorkEvaluationDocument $a) => array_key_exists($a->getId(), $dataById) ); - //$kept = $evaluation->getDocuments(); - dump($kept); - dump($removed); + // remove the document from evaluation foreach ($removed as $r) { - dump($r); $evaluation->removeDocument($r); } + // handle the documents kept foreach ($kept as $k) { - dump($k); // Cannot iterate over $kept which is a PersistentCollection - $evaluation->removeDocument($k); - dump($evaluation); - $document = $this->denormalizer->denormalize( + $this->denormalizer->denormalize( $dataById[$k->getId()], AccompanyingPeriodWorkEvaluationDocument::class, $format, @@ -116,12 +106,9 @@ class AccompanyingPeriodWorkEvaluationDenormalizer implements ContextAwareDenorm ] ) ); - - $evaluation->addDocument($document); } // create new document foreach ($dataWithoutId as $newData) { - dump($newData); $document = $this->denormalizer->denormalize( $newData, AccompanyingPeriodWorkEvaluationDocument::class, diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationDocumentNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationDocumentNormalizer.php new file mode 100644 index 000000000..cf3033e65 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationDocumentNormalizer.php @@ -0,0 +1,71 @@ +entityWorkflowRepository = $entityWorkflowRepository; + $this->metadataExtractor = $metadataExtractor; + $this->registry = $registry; + } + + public function normalize($object, ?string $format = null, array $context = []): array + { + $initial = $this->normalizer->normalize($object, $format, array_merge($context, [ + self::SKIP => spl_object_hash($object), + ])); + + $initial['workflows_availables'] = $this->metadataExtractor->availableWorkflowFor( + AccompanyingPeriodWorkEvaluationDocument::class, + $object->getId() + ); + + $workflows = $this->entityWorkflowRepository->findBy([ + 'relatedEntityClass' => AccompanyingPeriodWorkEvaluationDocument::class, + 'relatedEntityId' => $object->getId(), + ]); + $initial['workflows'] = $this->normalizer->normalize($workflows, 'json', $context); + + return $initial; + } + + public function supportsNormalization($data, ?string $format = null, array $context = []) + { + return $data instanceof AccompanyingPeriodWorkEvaluationDocument + && 'json' === $format + && ( + !array_key_exists(self::SKIP, $context) + || spl_object_hash($data) !== $context[self::SKIP] + ); + } +} diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationNormalizer.php index 1e4649dd7..fc9b6003a 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationNormalizer.php @@ -49,6 +49,15 @@ class AccompanyingPeriodWorkEvaluationNormalizer implements ContextAwareNormaliz [self::IGNORE_EVALUATION => spl_object_hash($object)] )); + // due to bug: https://api-platform.com/docs/core/serialization/#collection-relation + // and also: https://github.com/symfony/symfony/issues/36965 + // we have to rewrite the documents as a collection + $initial['documents'] = $this->normalizer->normalize( + $object->getDocuments()->getValues(), + $format, + $context + ); + // then, we add normalization for things which are not into the entity $initial['workflows_availables'] = $this->metadataExtractor->availableWorkflowFor( diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkNormalizer.php index 25f45d9df..4a110125e 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkNormalizer.php @@ -16,6 +16,7 @@ use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository; use Chill\MainBundle\Workflow\Helper\MetadataExtractor; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation; +use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocument; use Symfony\Component\Serializer\Exception\ExceptionInterface; use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; @@ -56,6 +57,15 @@ class AccompanyingPeriodWorkNormalizer implements ContextAwareNormalizerInterfac [self::IGNORE_WORK => spl_object_hash($object)] )); + // due to bug: https://api-platform.com/docs/core/serialization/#collection-relation + // and also: https://github.com/symfony/symfony/issues/36965 + // we have to rewrite the evaluations as a collection + $initial['accompanyingPeriodWorkEvaluations'] = $this->normalizer->normalize( + $object->getAccompanyingPeriodWorkEvaluations()->getValues(), + $format, + $context + ); + // then, we add normalization for things which are not into the entity $initial['workflows_availables'] = $this->metadataExtractor->availableWorkflowFor( @@ -67,10 +77,15 @@ class AccompanyingPeriodWorkNormalizer implements ContextAwareNormalizerInterfac AccompanyingPeriodWorkEvaluation::class ); + $initial['workflows_availables_evaluation_documents'] = $this->metadataExtractor->availableWorkflowFor( + AccompanyingPeriodWorkEvaluationDocument::class + ); + $workflows = $this->entityWorkflowRepository->findBy([ 'relatedEntityClass' => AccompanyingPeriodWork::class, 'relatedEntityId' => $object->getId(), ]); + $initial['workflows'] = $this->normalizer->normalize($workflows, 'json', $context); return $initial; diff --git a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php index 32c71b9f0..eac460ee5 100644 --- a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php +++ b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php @@ -17,7 +17,6 @@ use Chill\MainBundle\Workflow\EntityWorkflowHandlerInterface; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocument; use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocumentRepository; use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodWorkEvaluationDocumentVoter; -use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodWorkEvaluationVoter; use Symfony\Contracts\Translation\TranslatorInterface; class AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler implements EntityWorkflowHandlerInterface @@ -40,10 +39,11 @@ class AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler implements EntityW public function getEntityData(EntityWorkflow $entityWorkflow, array $options = []): array { - $evaluation = $this->getRelatedEntity($entityWorkflow); + $doc = $this->getRelatedEntity($entityWorkflow); return [ - 'persons' => $evaluation->getAccompanyingPeriodWork()->getPersons(), + 'persons' => $doc->getAccompanyingPeriodWorkEvaluation() + ->getAccompanyingPeriodWork()->getPersons(), ]; }