fix error when using AccPeriodWorkEvaluationDenormalizer

This commit is contained in:
nobohan 2022-02-25 14:58:11 +01:00
parent aae360d6ab
commit 2ea5c4b0c7
2 changed files with 14 additions and 13 deletions

View File

@ -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(

View File

@ -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) {