mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-02 13:03:50 +00:00
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:
@@ -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))
|
||||
;
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user