diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWorkEvaluationDocument.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWorkEvaluationDocument.php index b9b52f899..e4a15fccc 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWorkEvaluationDocument.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWorkEvaluationDocument.php @@ -61,7 +61,7 @@ class AccompanyingPeriodWorkEvaluationDocument implements \Chill\MainBundle\Doct * @ORM\SequenceGenerator(sequenceName="chill_person_social_work_eval_doc_id_seq", allocationSize=1, initialValue=1000) * @Serializer\Groups({"read"}) */ - private ?int $id; + private ?int $id = null; /** * @ORM\ManyToOne( diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationDenormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationDenormalizer.php index 93bf39be7..7278ee0da 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationDenormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationDenormalizer.php @@ -11,7 +11,6 @@ declare(strict_types=1); namespace Chill\PersonBundle\Serializer\Normalizer; -use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocument; use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository; @@ -51,18 +50,16 @@ class AccompanyingPeriodWorkEvaluationDenormalizer implements ContextAwareDenorm public function denormalize($data, $type, $format = null, array $context = []) { - $work = $this->denormalizer->denormalize($data, $type, $format, array_merge( + $evaluation = $this->denormalizer->denormalize($data, $type, $format, array_merge( $context, ['skip' => self::class] )); - dump($work); - dump($data); - dump($type); + //if (in_array('accompanying_period_work:edit', $context['groups'] ?? [], true)) { - $this->handleEvaluationCollection($data, $work, $format, $context); + $this->handleEvaluationCollection($data, $evaluation, $format, $context); //} - return $work; + return $evaluation; } public function supportsDenormalization($data, $type, $format = null, array $context = []): bool @@ -90,21 +87,23 @@ class AccompanyingPeriodWorkEvaluationDenormalizer implements ContextAwareDenorm dump($dataWithoutId); dump($evaluation); - // partition the separate kept documents and removed one + //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); // remove the document from evaluation foreach ($removed as $r) { $evaluation->removeDocument($r); } // handle the documents kept foreach ($kept as $k) { - $this->denormalizer->denormalize( + dump($k);// Cannot iterate over $kept which is a PersistentCollection + $evaluation->removeDocument($k); + dump($evaluation); + $document = $this->denormalizer->denormalize( $dataById[$k->getId()], AccompanyingPeriodWorkEvaluationDocument::class, $format, @@ -116,6 +115,8 @@ class AccompanyingPeriodWorkEvaluationDenormalizer implements ContextAwareDenorm ] ) ); + + $evaluation->addDocument($document); } // create new document foreach ($dataWithoutId as $newData) {