Create a PickUserGroupOrUserDynamicType

- add necessary vue component to render usergroup within the component AddPersons;
- add necessary normalization and denormalization process for matching the selected usergroup with entities in database
This commit is contained in:
2024-09-26 15:10:34 +02:00
parent 9e69c97250
commit 82cd77678b
12 changed files with 340 additions and 8 deletions

View File

@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
/*
* 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.
*/
namespace Chill\MainBundle\Serializer\Normalizer;
use Chill\MainBundle\Entity\UserGroup;
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
class UserGroupDenormalizer implements DenormalizerInterface
{
public function __construct(private readonly UserGroupRepositoryInterface $userGroupRepository) {}
public function denormalize($data, string $type, ?string $format = null, array $context = []): ?UserGroup
{
return $this->userGroupRepository->find($data['id']);
}
public function supportsDenormalization($data, string $type, ?string $format = null): bool
{
return UserGroup::class === $type
&& 'json' === $format
&& is_array($data)
&& array_key_exists('id', $data)
&& 'user_group' === ($data['type'] ?? false)
&& 2 === count(array_keys($data))
;
}
}

View File

@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
/*
* 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.
*/
namespace Chill\MainBundle\Serializer\Normalizer;
use Chill\MainBundle\Entity\UserGroup;
use Chill\MainBundle\Templating\Entity\UserGroupRenderInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
class UserGroupNormalizer implements NormalizerInterface
{
public function __construct(private readonly UserGroupRenderInterface $userGroupRender) {}
public function normalize($object, ?string $format = null, array $context = [])
{
/* @var UserGroup $object */
return [
'type' => 'user_group',
'id' => $object->getId(),
'label' => $object->getLabel(),
'backgroundColor' => $object->getBackgroundColor(),
'foregroundColor' => $object->getForegroundColor(),
'excludeKey' => $object->getExcludeKey(),
'text' => $this->userGroupRender->renderString($object, []),
];
}
public function supportsNormalization($data, ?string $format = null)
{
return $data instanceof UserGroup;
}
}