<?php
namespace App\Controller;
use App\Repository\ExpertRepository;
use App\Repository\SpecieRepository;
use App\Repository\SpecieAreaRepository;
use App\Repository\GeneralSkillRepository;
use App\Repository\ExpertAreaSpecieRepository;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class DefaultController extends AbstractController
{
/**
* @Route("/", name="accueil")
*/
public function index(ExpertRepository $expertRepository, ExpertAreaSpecieRepository $expertAreaSpecieRepository, SpecieAreaRepository $specieAreaRepository, SpecieRepository $specieRepository, GeneralSkillRepository $generalSkillRepository)
{
$entitiesExperts = $expertRepository->findAll();
$nbCountries = $expertRepository->getNbCountries();
$entitiesSpecies = $specieRepository->findAll();
$entitiesGeneralSkills = $generalSkillRepository->findAll();
$entitiesSpecieArea = $specieAreaRepository->findAll();
$datas=$expertRepository->getCountByCountry();
$dataCountries=$this->generateGraphe("Country","pie","chartContainer1",$datas);
// $datas=array();
// foreach ($entitiesGeneralSkills as $entity) $datas[$entity->getLibelle()]=0;
// foreach ($entitiesExperts as $entity)
// {
// foreach ($entity->getGeneralSkill() as $gs) $datas[$gs->getLibelle()]++;
// }
# $dataGS=$this->generateGrapheByTab("pie","chartContainer2",$datas);
$datas=$expertAreaSpecieRepository->getCountBy("specie");
$dataGS=$this->generateGraphe("Specie","pie","chartContainer2",$datas);
return $this->render('index.html.twig', [
'entitiesExperts' => $entitiesExperts,
'entitiesSpecies' => $entitiesSpecies,
'entitiesGeneralSkills' => $entitiesGeneralSkills,
'nbCountries' => $nbCountries,
'entitiesSpecieArea' => $entitiesSpecieArea,
'dataCountries' => $dataCountries,
'dataGS' => $dataGS,
]);
}
public function generateGraphe($champ,$type,$container,$datas)
{
$color="";
$color="'#82C46C','#791CF8','#9D3E0C','#111111','#3361FF','#BBAE98','#79F8F8','#33FF96','#83A697','#FDEE00','#EF9B0F','#FF33F3','#E73E01'";
$data='<div style="width: 100%; display: inline-block;margin-right: 50px;"><canvas style="background-color: #ffffff;" id="'.$container.'" class="chartjs"></canvas></div>
<script>
new Chart(
document.getElementById("'.$container.'"),
{
type:"'.$type.'",
data:
{
labels:[';
foreach($datas as $ligne)
{
$func = "get" . $champ;
if ($ligne[0]->{$func}()=="") $data.="'NA',";
else $data.="'".$ligne[0]->{$func}()."',";
}
$data.='],
datasets:
[
{
"label":"",
"data":[';
foreach($datas as $ligne) $data.= "'".$ligne["nb"]. "',";
$data.='],
"fill":false,
"backgroundColor":['.$color.'],
"borderColor":['.$color.'],
"borderWidth":1
}
]
},
options:
{
scales:
{
yAxes:
[
{
ticks:
{
beginAtZero:true
}
}
]
}
}
}
);
</script>';
return $data;
}
public function generateGrapheByTab($type,$container,$datas)
{
$color="";
$color="'#82C46C','#791CF8','#9D3E0C','#BBAE98','#79F8F8','#83A697','#FDEE00','#EF9B0F','#E73E01'";
$data='<div style="width: 100%; display: inline-block;margin-right: 50px;"><canvas style="background-color: #ffffff;" id="'.$container.'" class="chartjs"></canvas></div>
<script>
new Chart(
document.getElementById("'.$container.'"),
{
type:"'.$type.'",
data:
{
labels:[';
foreach($datas as $key=>$val) $data.="'$key',";
$data.='],
datasets:
[
{
"label":"",
"data":[';
foreach($datas as $val) $data.= "'$val',";
$data.='],
"fill":false,
"backgroundColor":['.$color.'],
"borderColor":['.$color.'],
"borderWidth":1
}
]
},
options:
{
scales:
{
yAxes:
[
{
ticks:
{
beginAtZero:true
}
}
]
}
}
}
);
</script>';
return $data;
}
}