diff --git a/ChillMainBundle.php b/ChillMainBundle.php index 579908ea4..7f82c70c1 100644 --- a/ChillMainBundle.php +++ b/ChillMainBundle.php @@ -10,6 +10,7 @@ use Chill\MainBundle\DependencyInjection\TimelineCompilerClass; use Chill\MainBundle\DependencyInjection\RoleProvidersCompilerPass; use Chill\MainBundle\DependencyInjection\CompilerPass\ExportsCompilerPass; use Chill\MainBundle\DependencyInjection\CompilerPass\WidgetsCompilerPass; +use Chill\MainBundle\DependencyInjection\CompilerPass\NotificationCounterCompilerPass; class ChillMainBundle extends Bundle @@ -23,5 +24,6 @@ class ChillMainBundle extends Bundle $container->addCompilerPass(new RoleProvidersCompilerPass()); $container->addCompilerPass(new ExportsCompilerPass()); $container->addCompilerPass(new WidgetsCompilerPass()); + $container->addCompilerPass(new NotificationCounterCompilerPass()); } } diff --git a/Controller/UIController.php b/Controller/UIController.php new file mode 100644 index 000000000..07b3694f8 --- /dev/null +++ b/Controller/UIController.php @@ -0,0 +1,39 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +namespace Chill\MainBundle\Controller; + +use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Chill\MainBundle\Templating\UI\CountNotificationUser; + +/** + * + * + * @author Julien Fastré + */ +class UIController extends Controller +{ + public function showNotificationUserCounterAction( + CountNotificationUser $counter + ) { + $nb = $counter->getSumNotification($this->getUser()); + + return $this->render('ChillMainBundle:UI:notification_user_counter.html.twig', [ + 'nb' => $nb + ]); + } +} diff --git a/DependencyInjection/ChillMainExtension.php b/DependencyInjection/ChillMainExtension.php index 2bd1b3f25..dd0b7c119 100644 --- a/DependencyInjection/ChillMainExtension.php +++ b/DependencyInjection/ChillMainExtension.php @@ -93,7 +93,8 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface, $loader->load('services/export.yml'); $loader->load('services/form.yml'); $loader->load('services/validator.yml'); - + $loader->load('services/widget.yml'); + $loader->load('services/controller.yml'); } public function getConfiguration(array $config, ContainerBuilder $container) diff --git a/DependencyInjection/CompilerPass/NotificationCounterCompilerPass.php b/DependencyInjection/CompilerPass/NotificationCounterCompilerPass.php new file mode 100644 index 000000000..065743332 --- /dev/null +++ b/DependencyInjection/CompilerPass/NotificationCounterCompilerPass.php @@ -0,0 +1,46 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +namespace Chill\MainBundle\DependencyInjection\CompilerPass; + +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Chill\MainBundle\Templating\UI\CountNotificationUser; +use Symfony\Component\DependencyInjection\Reference; + +/** + * + * + * @author Julien Fastré + */ +class NotificationCounterCompilerPass implements CompilerPassInterface +{ + public function process(ContainerBuilder $container) + { + if (!$container->hasDefinition(CountNotificationUser::class)) { + throw new \LogicException("The service ".CountNotificationUser::class." " + . "should be defined"); + } + + $notificationCounterDefinition = $container->getDefinition(CountNotificationUser::class); + + foreach ($container->findTaggedServiceIds('chill_main.count_notification.user') as $id => $tags) { + $notificationCounterDefinition + ->addMethodCall('addNotificationCounter', [new Reference($id)]); + } + } +} diff --git a/Resources/config/services/controller.yml b/Resources/config/services/controller.yml new file mode 100644 index 000000000..6f5bbd751 --- /dev/null +++ b/Resources/config/services/controller.yml @@ -0,0 +1,4 @@ +services: + Chill\MainBundle\Controller\: + resource: '../../../Controller' + tags: ['controller.service_arguments'] diff --git a/Resources/config/services/widget.yml b/Resources/config/services/widget.yml new file mode 100644 index 000000000..53f29da5b --- /dev/null +++ b/Resources/config/services/widget.yml @@ -0,0 +1,2 @@ +services: + Chill\MainBundle\Templating\UI\CountNotificationUser: ~ diff --git a/Resources/views/Menu/user.html.twig b/Resources/views/Menu/user.html.twig index ffd05bc04..243d2d279 100644 --- a/Resources/views/Menu/user.html.twig +++ b/Resources/views/Menu/user.html.twig @@ -20,7 +20,7 @@