mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
70 lines
2.2 KiB
PHP
70 lines
2.2 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Chill\MainBundle\Serializer\Normalizer;
|
|
|
|
use Chill\MainBundle\Entity\Workflow\EntityWorkflowStep;
|
|
use Chill\MainBundle\Workflow\Helper\MetadataExtractor;
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
|
|
|
class EntitWorkflowStepNormalizer implements NormalizerAwareInterface, NormalizerInterface
|
|
{
|
|
use NormalizerAwareTrait;
|
|
|
|
private MetadataExtractor $metadataExtractor;
|
|
|
|
public function __construct(MetadataExtractor $metadataExtractor)
|
|
{
|
|
$this->metadataExtractor = $metadataExtractor;
|
|
}
|
|
|
|
/**
|
|
* @param EntityWorkflowStep $object
|
|
*/
|
|
public function normalize($object, ?string $format = null, array $context = []): array
|
|
{
|
|
$data = [
|
|
'type' => 'entity_workflow_step',
|
|
'id' => $object->getId(),
|
|
'comment' => $object->getComment(),
|
|
'currentStep' => $this->metadataExtractor->buildArrayPresentationForPlace($object->getEntityWorkflow(), $object),
|
|
'finalizeAfter' => $object->isFinalizeAfter(),
|
|
'isFreezed' => false,
|
|
'isFinalized' => false,
|
|
'previousId' => null,
|
|
'nextId' => null,
|
|
'by' => null,
|
|
'at' => null,
|
|
];
|
|
|
|
if (null !== $previous = $object->getPrevious()) {
|
|
$data['previousId'] = $previous->getId();
|
|
$data['isFreezed'] = $previous->isFreezeAfter();
|
|
$data['isFinalized'] = $previous->isFreezeAfter();
|
|
$data['by'] = $previous->getTransitionBy();
|
|
$data['at'] = $previous->getTransitionAt();
|
|
}
|
|
|
|
if (null !== $next = $object->getNext()) {
|
|
$data['nextId'] = $next->getId();
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
public function supportsNormalization($data, ?string $format = null): bool
|
|
{
|
|
return $data instanceof EntityWorkflowStep && 'json' === $format;
|
|
}
|
|
}
|