src/EventSubscriber/TaskSubscriber.php line 42

Open in your IDE?
  1. <?php
  2. // src/EventSubscriber/TaskSubscriber.php
  3. namespace App\EventSubscriber;
  4. use App\Entity\Agent;
  5. use App\Entity\AgentPlanningAbsence;
  6. use App\Entity\Service;
  7. use App\Entity\Ucanss;
  8. use App\Repository\ClientRepository;
  9. use App\Repository\PortefeuilleCommercialRepository;
  10. use App\Repository\RequeteDeMabouleRepository;
  11. use App\Repository\ServiceRepository;
  12. use Doctrine\ORM\EntityManagerInterface;
  13. use KevinPapst\AdminLTEBundle\Event\TaskListEvent;
  14. use KevinPapst\AdminLTEBundle\Helper\Constants;
  15. use KevinPapst\AdminLTEBundle\Model\TaskModel;
  16. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  17. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  18. use Symfony\Component\Security\Core\Security;
  19. class TaskSubscriber implements EventSubscriberInterface
  20. {
  21.     private $portefeuilleCommercialRepository;
  22.     private $clientRepository;
  23.     public function __construct(PortefeuilleCommercialRepository $portefeuilleCommercialRepositoryClientRepository $clientRepositorySessionInterface $sessionSecurity $securityEntityManagerInterface $em)
  24.     {
  25.         $this->clientRepository =$clientRepository;
  26.         $this->portefeuilleCommercialRepository $portefeuilleCommercialRepository;
  27.         $this->security $security;
  28.         $this->session $session;
  29.         $this->em $em;
  30.     }
  31.     public static function getSubscribedEvents(): array
  32.     {
  33.         return [
  34.             TaskListEvent::class => ['onTasks'100],
  35.         ];
  36.     }
  37.     public function onTasks(TaskListEvent $event)
  38.     {
  39.         $event->setTotal(0);
  40.         $totalClient $this->clientRepository->count(['actif' => true'atelier' => false]);
  41.         $listeClient $this->portefeuilleCommercialRepository->findAllClientAssocieAUnCommercial();
  42.         $clientSansCommercial $this->clientRepository->findAllClientNotIn($listeClient);
  43.         $pourcentage 100;
  44.         if($totalClient != 0)
  45.             $pourcentage 100 - ((sizeof($clientSansCommercial) / $totalClient ) * 100);
  46.         if($clientSansCommercial 0){
  47.             if(sizeof($clientSansCommercial) == 1)
  48.                 $msgAbsValid "Vous avez ".sizeof($clientSansCommercial)." client sans commercial";
  49.             else
  50.                 $msgAbsValid "Vous avez ".sizeof($clientSansCommercial)." clients sans commercial";
  51.         }
  52.         else
  53.             $msgAbsValid "Aucun client sans commercial";
  54.         if(sizeof($clientSansCommercial) != 0) {
  55.             $task = new TaskModel();
  56.             $task
  57.                 ->setId(1)
  58.                 ->setTitle($msgAbsValid)
  59.                 ->setColor(Constants::COLOR_RED)
  60.                 ->setProgress($pourcentage)
  61.                 ->setRoute("clientSansCommercial")
  62.             ;
  63.             $event->addTask($task);
  64.         } else {
  65.             $task = new TaskModel();
  66.             $task
  67.                 ->setId(1)
  68.                 ->setTitle("Aucun client sans commercial")
  69.                 ->setColor(Constants::COLOR_GREEN)
  70.                 ->setProgress(100)
  71.                 ->setRoute("clientSansCommercial")
  72.             ;
  73.             $event->addTask($task);
  74.         }
  75.         /*
  76.          * You can also set the total number of tasks which could be different from those displayed in the navbar
  77.          * If no total is set, the total will be calculated on the number of tasks added to the event
  78.          */
  79. //        $event->setTotal(15);
  80.     }
  81. }