<?php
// src/EventSubscriber/TaskSubscriber.php
namespace App\EventSubscriber;
use App\Entity\Agent;
use App\Entity\AgentPlanningAbsence;
use App\Entity\Service;
use App\Entity\Ucanss;
use App\Repository\ClientRepository;
use App\Repository\PortefeuilleCommercialRepository;
use App\Repository\RequeteDeMabouleRepository;
use App\Repository\ServiceRepository;
use Doctrine\ORM\EntityManagerInterface;
use KevinPapst\AdminLTEBundle\Event\TaskListEvent;
use KevinPapst\AdminLTEBundle\Helper\Constants;
use KevinPapst\AdminLTEBundle\Model\TaskModel;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Core\Security;
class TaskSubscriber implements EventSubscriberInterface
{
private $portefeuilleCommercialRepository;
private $clientRepository;
public function __construct(PortefeuilleCommercialRepository $portefeuilleCommercialRepository, ClientRepository $clientRepository, SessionInterface $session, Security $security, EntityManagerInterface $em)
{
$this->clientRepository =$clientRepository;
$this->portefeuilleCommercialRepository = $portefeuilleCommercialRepository;
$this->security = $security;
$this->session = $session;
$this->em = $em;
}
public static function getSubscribedEvents(): array
{
return [
TaskListEvent::class => ['onTasks', 100],
];
}
public function onTasks(TaskListEvent $event)
{
$event->setTotal(0);
$totalClient = $this->clientRepository->count(['actif' => true, 'atelier' => false]);
$listeClient = $this->portefeuilleCommercialRepository->findAllClientAssocieAUnCommercial();
$clientSansCommercial = $this->clientRepository->findAllClientNotIn($listeClient);
$pourcentage = 100;
if($totalClient != 0)
$pourcentage = 100 - ((sizeof($clientSansCommercial) / $totalClient ) * 100);
if($clientSansCommercial > 0){
if(sizeof($clientSansCommercial) == 1)
$msgAbsValid = "Vous avez ".sizeof($clientSansCommercial)." client sans commercial";
else
$msgAbsValid = "Vous avez ".sizeof($clientSansCommercial)." clients sans commercial";
}
else
$msgAbsValid = "Aucun client sans commercial";
if(sizeof($clientSansCommercial) != 0) {
$task = new TaskModel();
$task
->setId(1)
->setTitle($msgAbsValid)
->setColor(Constants::COLOR_RED)
->setProgress($pourcentage)
->setRoute("clientSansCommercial")
;
$event->addTask($task);
} else {
$task = new TaskModel();
$task
->setId(1)
->setTitle("Aucun client sans commercial")
->setColor(Constants::COLOR_GREEN)
->setProgress(100)
->setRoute("clientSansCommercial")
;
$event->addTask($task);
}
/*
* You can also set the total number of tasks which could be different from those displayed in the navbar
* If no total is set, the total will be calculated on the number of tasks added to the event
*/
// $event->setTotal(15);
}
}