src/EventSubscriber/Money/WidgetSubscriber.php line 44

Open in your IDE?
  1. <?php
  2. /*
  3.  * @since 1.0.0
  4.  * @copyright Copyright (C) 2020 ArtMedia. All rights reserved.
  5.  * @website http://artmedia.biz.pl
  6.  * @author Arkadiusz Tobiasz
  7.  * @email kontakt@artmedia.biz.pl
  8.  */
  9. namespace App\EventSubscriber\Money;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. use App\Events\Core\DashboardWidgetAddEvent;
  12. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  13. use App\Entity\User;
  14. use App\Settings\SettingsManager;
  15. use Doctrine\ORM\EntityManagerInterface;
  16. use App\Entity\Money\Payout;
  17. use Twig\Environment;
  18. class WidgetSubscriber implements EventSubscriberInterface
  19. {
  20.     private $em;
  21.     private $securityChecker;
  22.     private $twig;
  23.     public function __construct(
  24.         Environment $twig,
  25.         EntityManagerInterface $em,
  26.         AuthorizationCheckerInterface $securityChecker null
  27.     ) {
  28.         $this->securityChecker $securityChecker;
  29.         $this->em $em;
  30.         $this->twig $twig;
  31.     }
  32.     public static function getSubscribedEvents(): array
  33.     {
  34.         return [
  35.             DashboardWidgetAddEvent::NAME => 'onDashboardWidgetAddEvent',
  36.         ];
  37.     }
  38.     public function onDashboardWidgetAddEvent(DashboardWidgetAddEvent $event): void
  39.     {
  40.         $user $event->getUser();
  41.         if (!$user) {
  42.             return;
  43.         }
  44.         if(!in_array(User::ROLE_ADMIN$user->getRoles()))
  45.         {
  46.             if (null === $this->securityChecker) {
  47.                 return;
  48.             }
  49.             if (!$this->securityChecker->isGranted('ROLE_MODERATOR_PERMISSION'SettingsManager::ADMIN_PAYOUTS)) {
  50.                 return;
  51.             }
  52.         }
  53.         
  54.         $payouts $this->em->getRepository(Payout::class)->findBy([
  55.             'status' => Payout::STATUS_WAITING
  56.         ], [
  57.             'createdAt' => 'ASC'
  58.         ]);
  59.         $event->addWidget(
  60.             'payouts',
  61.             $this->twig->render('money/widget/waiting_payouts.html.twig', [
  62.                 'payouts' => $payouts,
  63.             ]),
  64.             'top',
  65.             1
  66.         );
  67.     }
  68. }