diff --git a/src/Bundle/ChillMainBundle/Controller/NotificationController.php b/src/Bundle/ChillMainBundle/Controller/NotificationController.php index d717f01eb..c6ecdd873 100644 --- a/src/Bundle/ChillMainBundle/Controller/NotificationController.php +++ b/src/Bundle/ChillMainBundle/Controller/NotificationController.php @@ -20,6 +20,7 @@ use Chill\MainBundle\Notification\Exception\NotificationHandlerNotFound; use Chill\MainBundle\Notification\NotificationHandlerManager; use Chill\MainBundle\Pagination\PaginatorFactory; use Chill\MainBundle\Repository\NotificationRepository; +use Chill\MainBundle\Repository\UserRepository; use Chill\MainBundle\Security\Authorization\NotificationVoter; use Doctrine\ORM\EntityManagerInterface; use Psr\Log\LoggerInterface; @@ -29,6 +30,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Security\Core\Security; use Symfony\Contracts\Translation\TranslatorInterface; @@ -55,6 +57,8 @@ class NotificationController extends AbstractController private TranslatorInterface $translator; + private UserRepository $userRepository; + public function __construct( EntityManagerInterface $em, LoggerInterface $chillLogger, @@ -63,7 +67,8 @@ class NotificationController extends AbstractController NotificationRepository $notificationRepository, NotificationHandlerManager $notificationHandlerManager, PaginatorFactory $paginatorFactory, - TranslatorInterface $translator + TranslatorInterface $translator, + UserRepository $userRepository ) { $this->em = $em; $this->logger = $logger; @@ -73,6 +78,7 @@ class NotificationController extends AbstractController $this->notificationHandlerManager = $notificationHandlerManager; $this->paginatorFactory = $paginatorFactory; $this->translator = $translator; + $this->userRepository = $userRepository; } /** @@ -100,6 +106,15 @@ class NotificationController extends AbstractController ->setRelatedEntityId($request->query->getInt('entityId')) ->setSender($this->security->getUser()); + if ($request->query->has('tos')) { + foreach ($request->query->get('tos') as $toId) { + if (null === $to = $this->userRepository->find($toId)) { + throw new NotFoundHttpException("user with id {$toId} is not found"); + } + $notification->addAddressee($to); + } + } + try { $handler = $this->notificationHandlerManager->getHandler($notification); } catch (NotificationHandlerNotFound $e) { diff --git a/src/Bundle/ChillMainBundle/Serializer/Normalizer/UserNormalizer.php b/src/Bundle/ChillMainBundle/Serializer/Normalizer/UserNormalizer.php index eba8fc7bc..8ffc8533c 100644 --- a/src/Bundle/ChillMainBundle/Serializer/Normalizer/UserNormalizer.php +++ b/src/Bundle/ChillMainBundle/Serializer/Normalizer/UserNormalizer.php @@ -42,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'] @@ -66,7 +66,7 @@ class UserNormalizer implements ContextAwareNormalizerInterface, NormalizerAware ['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), @@ -79,20 +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['civility'] = $this->normalizer->normalize($user->getCivility(), $format, $civilityContext); - $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; diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index e8108bcce..da1709f48 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -978,6 +978,11 @@ class AccompanyingPeriod implements return null !== $this->userPrevious; } + public function hasUser(): bool + { + return null !== $this->user; + } + public function isChangedUser(): bool { return $this->userIsChanged && $this->user !== $this->userPrevious; diff --git a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig index 8e0a46efc..a9d51393d 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig @@ -210,10 +210,28 @@ {% endif %} -