mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 18:43:49 +00:00
add workflow on evaluationdocument in UI
This commit is contained in:
@@ -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,
|
||||
|
Reference in New Issue
Block a user