diff --git a/src/Bundle/ChillActivityBundle/DataFixtures/ORM/LoadActivityNotifications.php b/src/Bundle/ChillActivityBundle/DataFixtures/ORM/LoadActivityNotifications.php index 7835a0db4..9ef67a7ac 100644 --- a/src/Bundle/ChillActivityBundle/DataFixtures/ORM/LoadActivityNotifications.php +++ b/src/Bundle/ChillActivityBundle/DataFixtures/ORM/LoadActivityNotifications.php @@ -22,6 +22,7 @@ class LoadActivityNotifications extends AbstractFixture implements DependentFixt 'entityRef' => 'activity_gerard depardieu', 'sender' => 'center a_social', 'addressees' => [ + 'center a_social', 'center a_administrative', 'center a_direction', 'multi_center' diff --git a/src/Bundle/ChillActivityBundle/Notification/ActivityNotificationRenderer.php b/src/Bundle/ChillActivityBundle/Notification/ActivityNotificationRenderer.php new file mode 100644 index 000000000..1836f599b --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Notification/ActivityNotificationRenderer.php @@ -0,0 +1,24 @@ +getRelatedEntityClass() == Activity::class; + } + + public function getTemplate() + { + return '@ChillActivity/Activity/showInNotification.html.twig'; + } + + public function getTemplateData(Notification $notification) + { + return ['notification' => $notification]; + } +} diff --git a/src/Bundle/ChillActivityBundle/Resources/views/Activity/showInNotification.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/Activity/showInNotification.html.twig new file mode 100644 index 000000000..5128e9a64 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Resources/views/Activity/showInNotification.html.twig @@ -0,0 +1,4 @@ + +{{ dump(notification) }} + +Go to Activity diff --git a/src/Bundle/ChillActivityBundle/config/services.yaml b/src/Bundle/ChillActivityBundle/config/services.yaml index 411ad1b5a..86168101a 100644 --- a/src/Bundle/ChillActivityBundle/config/services.yaml +++ b/src/Bundle/ChillActivityBundle/config/services.yaml @@ -1,4 +1,4 @@ -services: +services: chill.activity.security.authorization.activity_voter: class: Chill\ActivityBundle\Security\Authorization\ActivityVoter arguments: @@ -6,7 +6,7 @@ services: tags: - { name: security.voter } - { name: chill.role } - + chill.activity.security.authorization.activity_stats_voter: class: Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter arguments: @@ -14,8 +14,8 @@ services: tags: - { name: security.voter } - { name: chill.role } - - + + chill.activity.timeline: class: Chill\ActivityBundle\Timeline\TimelineActivityProvider arguments: @@ -33,3 +33,8 @@ services: autoconfigure: true resource: '../Menu/' tags: ['chill.menu_builder'] + + Chill\ActivityBundle\Notification\: + autowire: true + autoconfigure: true + resource: '../Notification' diff --git a/src/Bundle/ChillMainBundle/Controller/NotificationController.php b/src/Bundle/ChillMainBundle/Controller/NotificationController.php new file mode 100644 index 000000000..c76e19d9e --- /dev/null +++ b/src/Bundle/ChillMainBundle/Controller/NotificationController.php @@ -0,0 +1,59 @@ +security = $security; + } + + + /** + * @Route("/show", name="chill_main_notification_show") + */ + public function showAction( + NotificationRepository $notificationRepository, NotificationRenderer $notificationRenderer, + PaginatorFactory $paginatorFactory) + { + $currentUser = $this->security->getUser(); + + $notificationsNbr = $notificationRepository->countAllForAttendee(($currentUser)); + $paginator = $paginatorFactory->create($notificationsNbr); + + $notifications = $notificationRepository->findAllForAttendee( + $currentUser, + $limit=$paginator->getItemsPerPage(), + $offset= $paginator->getCurrentPage()->getFirstItemNumber()); + + $templateData = array(); + foreach ($notifications as $notification) { + $data = [ + 'template' => $notificationRenderer->getTemplate($notification), + 'template_data' => $notificationRenderer->getTemplateData($notification), + 'notification' => $notification + ]; + $templateData[] = $data; + } + + return $this->render('@ChillMain/Notification/show.html.twig', [ + 'datas' => $templateData, + 'notifications' => $notifications, + 'paginator' => $paginator, + ]); + } +} diff --git a/src/Bundle/ChillMainBundle/Notification/NotificationRenderer.php b/src/Bundle/ChillMainBundle/Notification/NotificationRenderer.php new file mode 100644 index 000000000..d6f383b73 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Notification/NotificationRenderer.php @@ -0,0 +1,44 @@ +renderers[] = $accompanyingPeriodNotificationRenderer; + $this->renderers[] = $activityNotificationRenderer; + } + + private function getRenderer(Notification $notification) + { + foreach ($this->renderers as $renderer) { + if($renderer->supports($notification)) { + return $renderer; + } + } + + throw new \Exception('No renderer for '. $notification); + } + + public function getTemplate(Notification $notification) + { + return $this->getRenderer($notification)->getTemplate(); + } + + public function getTemplateData(Notification $notification) + { + return $this->getRenderer($notification)->getTemplateData($notification); + } +} diff --git a/src/Bundle/ChillMainBundle/Repository/NotificationRepository.php b/src/Bundle/ChillMainBundle/Repository/NotificationRepository.php index 844459f8b..5ffda75dc 100644 --- a/src/Bundle/ChillMainBundle/Repository/NotificationRepository.php +++ b/src/Bundle/ChillMainBundle/Repository/NotificationRepository.php @@ -23,6 +23,8 @@ use Chill\MainBundle\Entity\Notification; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; use Doctrine\Persistence\ObjectRepository; +use Chill\MainBundle\Entity\User; +use Doctrine\ORM\Query; final class NotificationRepository implements ObjectRepository { @@ -59,8 +61,54 @@ final class NotificationRepository implements ObjectRepository return $this->repository->findBy($criteria, $orderBy, $limit, $offset); } + private function queryAllForAttendee(User $addressee, bool $countQuery=False): Query + { + $qb = $this->repository->createQueryBuilder('n'); + + $select = 'n'; + if($countQuery) { + $select = 'count(n)'; + } + + $qb + ->select($select) + ->join('n.addressees', 'a') + ->where('a = :addressee') + ->setParameter('addressee', $addressee); + + return $qb->getQuery(); + } + + /** + * @return int + */ + public function countAllForAttendee(User $addressee): int // TODO passer à attendees avec S + { + $query = $this->queryAllForAttendee($addressee, $countQuery=True); + + return $query->getSingleScalarResult(); + } + + + /** + * @return Notification[] + */ + public function findAllForAttendee(User $addressee, $limit = null, $offset = null): array // TODO passer à attendees avec S + { + $query = $this->queryAllForAttendee($addressee); + + if($limit) { + $query = $query->setMaxResults($limit); + } + + if($offset) { + $query = $query->setFirstResult($offset); + } + + return $query->getResult(); + } + public function getClassName() { return Notification::class; } - } diff --git a/src/Bundle/ChillMainBundle/Resources/views/Notification/show.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Notification/show.html.twig new file mode 100644 index 000000000..34aeee049 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Resources/views/Notification/show.html.twig @@ -0,0 +1,42 @@ +{% extends "@ChillMain/layout.html.twig" %} + +{% block content %} +
+
+

{{ "Notifications list" | trans }}

+ + + {%for data in datas %} + {% set notification = data.notification %} + +
+
{{ 'Message'|trans }}
+
{{ notification.message }}
+
+ +
+
{{ 'Date'|trans }}
+
{{ notification.date | date('long') }}
+
+ + +
+
{{ 'Sender'|trans }}
+
{{ notification.sender }}
+
+ +
+
{{ 'Addressees'|trans }}
+
{{ notification.addressees |join(', ') }}
+
+ +
+
{{ 'Entity'|trans }}
+
+ {% include data.template with data.template_data %} +
+
+ {% endfor %} +
+
+{% endblock content %} diff --git a/src/Bundle/ChillMainBundle/config/routes.yaml b/src/Bundle/ChillMainBundle/config/routes.yaml index 240a44590..697ec8ec0 100644 --- a/src/Bundle/ChillMainBundle/config/routes.yaml +++ b/src/Bundle/ChillMainBundle/config/routes.yaml @@ -34,6 +34,10 @@ chill_password_recover: resource: "@ChillMainBundle/config/routes/password_recover.yaml" prefix: "public/{_locale}/password" +chill_main_notification: + resource: "@ChillMainBundle/config/routes/notification.yaml" + prefix: "{_locale}/notification" + chill_crud: resource: "@ChillMainBundle" type: CRUD diff --git a/src/Bundle/ChillMainBundle/config/routes/notification.yaml b/src/Bundle/ChillMainBundle/config/routes/notification.yaml new file mode 100644 index 000000000..e69de29bb diff --git a/src/Bundle/ChillMainBundle/config/services/controller.yaml b/src/Bundle/ChillMainBundle/config/services/controller.yaml index 6021e3d72..11a9bc274 100644 --- a/src/Bundle/ChillMainBundle/config/services/controller.yaml +++ b/src/Bundle/ChillMainBundle/config/services/controller.yaml @@ -33,3 +33,8 @@ services: $logger: '@Psr\Log\LoggerInterface' $validator: '@Symfony\Component\Validator\Validator\ValidatorInterface' tags: ['controller.service_arguments'] + + Chill\MainBundle\Controller\NotificationController: + arguments: + $security: '@Symfony\Component\Security\Core\Security' + tags: ['controller.service_arguments'] diff --git a/src/Bundle/ChillMainBundle/config/services/notification.yaml b/src/Bundle/ChillMainBundle/config/services/notification.yaml index fa4fa15c6..c8d970c5d 100644 --- a/src/Bundle/ChillMainBundle/config/services/notification.yaml +++ b/src/Bundle/ChillMainBundle/config/services/notification.yaml @@ -4,7 +4,11 @@ services: $logger: '@Psr\Log\LoggerInterface' $twig: '@Twig\Environment' $mailer: '@swiftmailer.mailer.default' - # $mailerTransporter: '@swiftmailer.transport' + # $mailerTransporter: '@swiftmailer.transport' $router: '@Symfony\Component\Routing\RouterInterface' $translator: '@Symfony\Component\Translation\TranslatorInterface' $routeParameters: '%chill_main.notifications%' + + Chill\MainBundle\Notification\NotificationRenderer: + autoconfigure: true + autowire: true diff --git a/src/Bundle/ChillMainBundle/config/services/pagination.yaml b/src/Bundle/ChillMainBundle/config/services/pagination.yaml index f6282a39f..e85352728 100644 --- a/src/Bundle/ChillMainBundle/config/services/pagination.yaml +++ b/src/Bundle/ChillMainBundle/config/services/pagination.yaml @@ -2,13 +2,15 @@ services: chill_main.paginator_factory: class: Chill\MainBundle\Pagination\PaginatorFactory public: true + autowire: true + autoconfigure: true arguments: - "@request_stack" - "@router" - "%chill_main.pagination.item_per_page%" Chill\MainBundle\Pagination\PaginatorFactory: '@chill_main.paginator_factory' - + chill_main.paginator.twig_extensions: class: Chill\MainBundle\Pagination\ChillPaginationTwig tags: diff --git a/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadAccompanyingPeriodNotifications.php b/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadAccompanyingPeriodNotifications.php new file mode 100644 index 000000000..d1c6f4da7 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadAccompanyingPeriodNotifications.php @@ -0,0 +1,39 @@ + 'Hello !', + 'entityClass' => AccompanyingPeriod::class, + 'entityRef' => LoadAccompanyingPeriod::ACCOMPANYING_PERIOD, + 'sender' => 'center a_social', + 'addressees' => [ + 'center a_social', + 'center a_administrative', + 'center a_direction', + 'multi_center' + ], + ] + ]; + + public function getDependencies() + { + return [ + LoadAccompanyingPeriod::class, + ]; + } +} diff --git a/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php b/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php index 03b05bbc8..1b22018a2 100644 --- a/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php +++ b/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php @@ -74,6 +74,7 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac $loader->load('services/form.yaml'); $loader->load('services/alt_names.yaml'); $loader->load('services/household.yaml'); + $loader->load('services/notification.yaml'); // We can get rid of this file when the service 'chill.person.repository.person' is no more used. // We should use the PersonRepository service instead of a custom service name. $loader->load('services/repository.yaml'); diff --git a/src/Bundle/ChillPersonBundle/Notification/AccompanyingPeriodNotificationRenderer.php b/src/Bundle/ChillPersonBundle/Notification/AccompanyingPeriodNotificationRenderer.php new file mode 100644 index 000000000..ca76fbd5c --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Notification/AccompanyingPeriodNotificationRenderer.php @@ -0,0 +1,24 @@ +getRelatedEntityClass() == AccompanyingPeriod::class; + } + + public function getTemplate() + { + return 'ChillPersonBundle:AccompanyingPeriod:showInNotification.html.twig'; + } + + public function getTemplateData(Notification $notification) + { + return ['notification' => $notification]; + } +} diff --git a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingPeriod/showInNotification.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingPeriod/showInNotification.html.twig new file mode 100644 index 000000000..d92de8cba --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingPeriod/showInNotification.html.twig @@ -0,0 +1,3 @@ + + Go to Acc. period. + diff --git a/src/Bundle/ChillPersonBundle/config/services/notification.yaml b/src/Bundle/ChillPersonBundle/config/services/notification.yaml new file mode 100644 index 000000000..58187defb --- /dev/null +++ b/src/Bundle/ChillPersonBundle/config/services/notification.yaml @@ -0,0 +1,3 @@ +services: + Chill\PersonBundle\Notification\AccompanyingPeriodNotificationRenderer: + autowire: true