mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
Merge remote-tracking branch 'origin/master' into calendar/synchro-msgraph
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<?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\Embeddable\PrivateCommentEmbeddable;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
|
||||
class PrivateCommentEmbeddableNormalizer implements NormalizerInterface, DenormalizerInterface
|
||||
{
|
||||
private Security $security;
|
||||
|
||||
public function __construct(Security $security)
|
||||
{
|
||||
$this->security = $security;
|
||||
}
|
||||
|
||||
public function denormalize($data, string $type, ?string $format = null, array $context = []): PrivateCommentEmbeddable
|
||||
{
|
||||
$comment = new PrivateCommentEmbeddable();
|
||||
|
||||
if (null === $data) {
|
||||
return $comment;
|
||||
}
|
||||
|
||||
$comment->setCommentForUser($this->security->getUser(), $data);
|
||||
|
||||
return $comment;
|
||||
}
|
||||
|
||||
public function normalize($object, $format = null, array $context = []): string
|
||||
{
|
||||
return $object->getCommentForUser($this->security->getUser());
|
||||
}
|
||||
|
||||
public function supportsDenormalization($data, string $type, ?string $format = null): bool
|
||||
{
|
||||
return PrivateCommentEmbeddable::class === $type;
|
||||
}
|
||||
|
||||
public function supportsNormalization($data, ?string $format = null): bool
|
||||
{
|
||||
return $data instanceof PrivateCommentEmbeddable;
|
||||
}
|
||||
}
|
@@ -12,6 +12,7 @@ declare(strict_types=1);
|
||||
namespace Chill\MainBundle\Serializer\Normalizer;
|
||||
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Entity\Civility;
|
||||
use Chill\MainBundle\Entity\Location;
|
||||
use Chill\MainBundle\Entity\Scope;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
@@ -41,9 +42,9 @@ class UserNormalizer implements ContextAwareNormalizerInterface, NormalizerAware
|
||||
$this->userRender = $userRender;
|
||||
}
|
||||
|
||||
public function normalize($user, $format = null, array $context = [])
|
||||
public function normalize($object, $format = null, array $context = [])
|
||||
{
|
||||
/** @var User $user */
|
||||
/** @var User $object */
|
||||
$userJobContext = array_merge(
|
||||
$context,
|
||||
['docgen:expects' => UserJob::class, 'groups' => 'docgen:read']
|
||||
@@ -60,9 +61,14 @@ class UserNormalizer implements ContextAwareNormalizerInterface, NormalizerAware
|
||||
$context,
|
||||
['docgen:expects' => Location::class, 'groups' => 'docgen:read']
|
||||
);
|
||||
$civilityContext = array_merge(
|
||||
$context,
|
||||
['docgen:expects' => Civility::class, 'groups' => 'docgen:read']
|
||||
);
|
||||
|
||||
if (null === $user && 'docgen' === $format) {
|
||||
if (null === $object && 'docgen' === $format) {
|
||||
return array_merge(self::NULL_USER, [
|
||||
'civility' => $this->normalizer->normalize(null, $format, $civilityContext),
|
||||
'user_job' => $this->normalizer->normalize(null, $format, $userJobContext),
|
||||
'main_center' => $this->normalizer->normalize(null, $format, $centerContext),
|
||||
'main_scope' => $this->normalizer->normalize(null, $format, $scopeContext),
|
||||
@@ -73,19 +79,20 @@ class UserNormalizer implements ContextAwareNormalizerInterface, NormalizerAware
|
||||
|
||||
$data = [
|
||||
'type' => 'user',
|
||||
'id' => $user->getId(),
|
||||
'username' => $user->getUsername(),
|
||||
'text' => $this->userRender->renderString($user, []),
|
||||
'label' => $user->getLabel(),
|
||||
'email' => (string) $user->getEmail(),
|
||||
'user_job' => $this->normalizer->normalize($user->getUserJob(), $format, $userJobContext),
|
||||
'main_center' => $this->normalizer->normalize($user->getMainCenter(), $format, $centerContext),
|
||||
'main_scope' => $this->normalizer->normalize($user->getMainScope(), $format, $scopeContext),
|
||||
'id' => $object->getId(),
|
||||
'username' => $object->getUsername(),
|
||||
'text' => $this->userRender->renderString($object, []),
|
||||
'label' => $object->getLabel(),
|
||||
'email' => (string) $object->getEmail(),
|
||||
'user_job' => $this->normalizer->normalize($object->getUserJob(), $format, $userJobContext),
|
||||
'main_center' => $this->normalizer->normalize($object->getMainCenter(), $format, $centerContext),
|
||||
'main_scope' => $this->normalizer->normalize($object->getMainScope(), $format, $scopeContext),
|
||||
];
|
||||
|
||||
if ('docgen' === $format) {
|
||||
$data['current_location'] = $this->normalizer->normalize($user->getCurrentLocation(), $format, $locationContext);
|
||||
$data['main_location'] = $this->normalizer->normalize($user->getMainLocation(), $format, $locationContext);
|
||||
$data['civility'] = $this->normalizer->normalize($object->getCivility(), $format, $civilityContext);
|
||||
$data['current_location'] = $this->normalizer->normalize($object->getCurrentLocation(), $format, $locationContext);
|
||||
$data['main_location'] = $this->normalizer->normalize($object->getMainLocation(), $format, $locationContext);
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
Reference in New Issue
Block a user