mise en place de stats
This commit is contained in:
135
src/schedule-2.0/src/Controller/StatController.php
Executable file
135
src/schedule-2.0/src/Controller/StatController.php
Executable file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Form\FormError;
|
||||
use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
|
||||
use App\Entity\Service as Entity;
|
||||
use App\Form\ServiceType as Form;
|
||||
|
||||
class StatController extends AbstractController
|
||||
{
|
||||
private $knpSnappy;
|
||||
public function __construct(\Knp\Snappy\Pdf $knpSnappy) { $this->knpSnappy = $knpSnappy; }
|
||||
|
||||
public function view(Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$natures = $em->getRepository("App:Nature")->findAll();
|
||||
$tbnatures=[];
|
||||
foreach($natures as $nature) {
|
||||
$tbnatures[$nature->getId()]=[
|
||||
"id"=>$nature->getId(),
|
||||
"name"=>$nature->getName(),
|
||||
"totalmonth"=> 0,
|
||||
"totalservice"=> 0,
|
||||
"totalnature" => 0,
|
||||
];
|
||||
}
|
||||
|
||||
$services = $em->getRepository("App:Service")->findAll();
|
||||
$tbservices=[];
|
||||
foreach($services as $service) {
|
||||
$tbservices[$service->getId()] = [
|
||||
"id"=>$service->getId(),
|
||||
"name"=>$service->getName(),
|
||||
"natures"=>$tbnatures,
|
||||
];
|
||||
}
|
||||
|
||||
$tbmonths=[];
|
||||
$now=new \Datetime("now");
|
||||
//$now->add(new \DateInterval('P3M'));
|
||||
$yend= $now->format("Y");
|
||||
$ystart=$yend-2;
|
||||
for($i=$ystart;$i<=$yend;$i++) {
|
||||
for($j=1;$j<=12;$j++) {
|
||||
$id=$i.str_pad($j, 2, '0', STR_PAD_LEFT);
|
||||
$name=$i."-".str_pad($j, 2, '0', STR_PAD_LEFT);
|
||||
$tbmonths[$id]= [
|
||||
"id"=>$id,
|
||||
"name"=>$name,
|
||||
"services"=>$tbservices,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach($tbmonths as $keymonth => $month) {
|
||||
$start=new \Datetime($month["id"]."01");
|
||||
$end=new \Datetime($month["id"]."01");
|
||||
$end->add(new \DateInterval('P1M'));
|
||||
|
||||
$events = $em
|
||||
->createQueryBuilder('event')
|
||||
->select('SUM(event.duration) as somme')
|
||||
->from('App:Event','event')
|
||||
->andWhere('event.start >=:start')
|
||||
->andWhere('event.end <:end')
|
||||
->setParameter('start',$start)
|
||||
->setParameter('end',$end)
|
||||
->getQuery()->getResult();
|
||||
$totalmonth=($events[0]["somme"]?$events[0]["somme"]:0);
|
||||
|
||||
foreach($month["services"] as $keyservice => $service) {
|
||||
$events = $em
|
||||
->createQueryBuilder('event')
|
||||
->select('SUM(event.duration) as somme')
|
||||
->from('App:Event','event')
|
||||
->from('App:User','user')
|
||||
->andWhere('event.start >=:start')
|
||||
->andWhere('event.end <:end')
|
||||
->andWhere('event.user=user')
|
||||
->andWhere('user.service=:service')
|
||||
->setParameter('start',$start)
|
||||
->setParameter('end',$end)
|
||||
->setParameter('service',$service["id"])
|
||||
->getQuery()->getResult();
|
||||
$totalservice=($events[0]["somme"]?$events[0]["somme"]:0);
|
||||
|
||||
foreach($service["natures"] as $keynature => $nature) {
|
||||
$events = $em
|
||||
->createQueryBuilder('event')
|
||||
->select('SUM(event.duration) as somme')
|
||||
->from('App:Task','task')
|
||||
->from('App:Event','event')
|
||||
->from('App:User','user')
|
||||
->andWhere('task.nature=:nature')
|
||||
->andWhere('event.task=task')
|
||||
->andWhere('event.start >=:start')
|
||||
->andWhere('event.end <:end')
|
||||
->andWhere('event.user=user')
|
||||
->andWhere('user.service=:service')
|
||||
->setParameter('nature',$nature["id"])
|
||||
->setParameter('start',$start)
|
||||
->setParameter('end',$end)
|
||||
->setParameter('service',$service["id"])
|
||||
->getQuery()->getResult();
|
||||
|
||||
//echo $keymonth." ".$service["id"]." ".$service["name"]." ".$nature["name"]." = ".$events[0]["somme"]."<br>";
|
||||
|
||||
$tbmonths[$keymonth]["services"][$keyservice]["natures"][$keynature]["totalnature"]=($events[0]["somme"]?$events[0]["somme"]:0);
|
||||
$tbmonths[$keymonth]["services"][$keyservice]["natures"][$keynature]["totalmonth"]=$totalmonth;
|
||||
$tbmonths[$keymonth]["services"][$keyservice]["natures"][$keynature]["totalservice"]=$totalservice;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//return new JsonResponse($tbmonths);
|
||||
return $this->render('Stat/view.html.twig',[
|
||||
"useheader" => true,
|
||||
"usesidebar" => true,
|
||||
"tbmonths" => $tbmonths,
|
||||
"tbnatures" => $tbnatures,
|
||||
"tbservices" => $tbservices,
|
||||
]);
|
||||
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user