src/Controller/HomeController.php line 28
<?php
namespace App\Controller;
use App\Repository\CompanyRepository;
use App\Repository\GasStationRepository;
use App\Repository\HookRepository;
use App\Repository\ModuleRepository;
use App\Repository\ParameterRepository;
use App\Repository\VisitRepository;
use App\Repository\VoucherParamRepository;
use App\Repository\WidgetRepository;
use Doctrine\Persistence\ManagerRegistry;
use Exception;
use ReflectionException;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class HomeController extends AbstractController
{
/**
* @throws ReflectionException|TransportExceptionInterface
* @throws Exception
*/
#[Route('/', name: 'app_home')]
public function index(HookRepository $hookRepository, WidgetRepository $widgetRepository, ManagerRegistry $registry, ParameterRepository $parameterRepository, GasStationRepository $gasStationRepository, CompanyRepository $companyRepository, VisitRepository $visitRepository, VoucherParamRepository $voucherParamRepository): Response
{
if ($this->container->has('security.token_storage')) {
$current_user = $this->getUser();
if (!$current_user) {
return $this->redirectToRoute('app_login');
}
} else {
return $this->redirectToRoute('app_login');
}
$moduleRepo = new ModuleRepository($registry);
$header_widgets = $widgetRepository->findByHook($hookRepository->findOneBy([
'alias' => 'HEADER'
]));
$limit = intval($parameterRepository->findOneByAlias([
'alias' => 'RECENT_ACTIVITIES_LIMIT'
])->getValue());
$i = 0;
$recent_activities = [];
$tendance_globale = [
'data_target' => $gasStationRepository->getCount(null),
'companies' => $companyRepository->findAll(),
];
$ssr_score = [];
$minVoucherRate = $voucherParamRepository->getMinVoucherRate();
$enelp = $enelp_s = $enelp_rate = 0;
$reseau = $reseau_s = $reseau_rate = 0;
foreach ($visitRepository->findAll() as $visit) {
if ($visit->getGasStation()->getCompany()->getId() == 2) {
$enelp++;
$foundw = false;
foreach ($visit->getObservations() as $observation) {
if ($observation->getCarCount() > 0) {
if (count($observation->getObservationReps()) > 0) {
$observationRep = $observation->getObservationReps()[0];
if ($observationRep) {
if ((float)$observationRep->getRate() >= $minVoucherRate) {
$foundw = true;
}
}
}
}
}
if ($foundw)
$enelp_s++;
} else {
$reseau++;
$foundr = false;
foreach ($visit->getObservations() as $observation) {
if ($observation->getCarCount() > 0) {
if (count($observation->getObservationReps()) > 0) {
$observationRep = $observation->getObservationReps()[0];
if ($observationRep) {
if ((float)$observationRep->getRate() >= $minVoucherRate) {
$foundr = true;
}
}
}
}
}
if ($foundr)
$reseau_s++;
}
}
$reseau_rate = number_format((float)floatval(($reseau_s / $reseau) * 100), 2, '.', ' ');
$enelp_rate =number_format((float)floatval(($enelp_s / $enelp) * 100), 2, '.', ' ');
return $this->render('home/index.html.twig', [
'root_uri' => 'Accueil',
'title' => 'Tableau de bord',
'module_mod_menu' => $moduleRepo->findByParam("isModule"),
'dictionnary_mod_menu' => $moduleRepo->findByParam("isDictionnary"),
'parameter_mod_menu' => $moduleRepo->findByParam("isParameter"),
'user' => $current_user,
'user_role' => $current_user->getRole(),
'header_widgets' => $header_widgets,
'recent_activities' => $recent_activities,
'tendance_globale' => $tendance_globale,
'enelp' => $enelp,
'enelp_s' => $enelp_s,
'enelp_rate' => $enelp_rate,
'reseau' => $reseau,
'reseau_s' => $reseau_s,
'reseau_rate' => $reseau_rate,
]);
}
}