ninegitea/src/Controller/ScrumController.php

926 lines
39 KiB
PHP
Raw Normal View History

2021-07-20 13:04:47 +02:00
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
2021-07-20 13:04:47 +02:00
use Symfony\Component\Form\FormError;
use App\Entity\Scrum as Entity;
use App\Entity\Scrumissue as Scrumissue;
use App\Form\ScrumType as Form;
use App\Service\giteaService;
class ScrumController extends AbstractController
{
private $data = "scrum";
private $route = "app_scrum";
private $render = "Scrum/";
private $entity = "App:Scrum";
private $giteaservice;
2021-07-20 13:04:47 +02:00
public function __construct(giteaService $giteaservice) { $this->giteaservice = $giteaservice; }
public function list(Request $request)
{
$em = $this->getDoctrine()->getManager();
2022-06-29 11:50:27 +02:00
$scrums = $em->getRepository($this->entity)->findByUser($this->getUser());
2022-01-22 11:18:42 +01:00
2024-02-15 22:36:10 +01:00
$this->giteaservice->needrefresh();
2022-01-22 11:18:42 +01:00
$giteacategorys=[];
$gitearepos=[];
foreach($scrums as $key => $scrum) {
if(!in_array($scrum->getCategory(),$giteacategorys))
array_push($giteacategorys,$scrum->getCategory());
$gitearepo=$this->giteaservice->getRepo($scrum->getGiteajson()["id"]);
2022-02-03 17:26:35 +01:00
if($gitearepo) {
if($gitearepo->updated_at!=$scrum->getGiteajson()["updated_at"]||$gitearepo->open_issues_count!=$scrum->getGiteajson()["open_issues_count"]) {
$scrum->setGiteajson(json_decode(json_encode($gitearepo), true));
$em->persist($scrum);
$em->flush();
}
2022-01-22 11:18:42 +01:00
2022-02-03 17:26:35 +01:00
array_push($gitearepos,$gitearepo);
2022-01-22 11:18:42 +01:00
}
2022-01-13 20:24:04 +01:00
}
2022-01-22 11:18:42 +01:00
sort($giteacategorys);
$filtercategorys = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filtercategorys",0);
$filterrepos = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filterrepos",0);
2021-07-20 13:04:47 +02:00
return $this->render($this->render.'list.html.twig',[
2022-01-22 11:18:42 +01:00
$this->data."s" => $scrums,
"giteacategorys" => $giteacategorys,
"gitearepos" => $gitearepos,
"filtercategorys" => $filtercategorys,
"filterrepos" => $filterrepos,
"useheader" => true,
"usesidebar" => false,
2021-07-20 13:04:47 +02:00
]);
}
public function submit(Request $request)
{
// Initialisation de l'enregistrement
$em = $this->getDoctrine()->getManager();
$data = new Entity();
// Récupérer les repos de gitea
$gitearepos=$this->giteaservice->getRepos();
// Création du formulaire
$form = $this->createForm(Form::class,$data,array("mode"=>"submit","gitearepos"=>$gitearepos));
// Récupération des data du formulaire
$form->handleRequest($request);
// Sur erreur
$this->getErrorForm(null,$form,$request,$data,"submit");
// Sur validation
if ($form->get('submit')->isClicked() && $form->isValid()) {
$data = $form->getData();
$gitearepo=$this->giteaservice->getRepo($data->getGiteaid());
$data->setGiteaname($gitearepo->full_name);
$data->setGiteajson(json_decode(json_encode($gitearepo), true));
$em->persist($data);
$em->flush();
// Retour à la liste
return $this->redirectToRoute($this->route);
}
// Affichage du formulaire
return $this->render($this->render.'edit.html.twig', [
'useheader' => true,
'usesidebar' => false,
'maxwidth' => true,
$this->data => $data,
'mode' => 'submit',
'form' => $form->createView()
]);
}
public function update($id,Request $request)
{
// Initialisation de l'enregistrement
$em = $this->getDoctrine()->getManager();
$data=$em->getRepository($this->entity)->find($id);
// Récupérer les repos de gitea
$gitearepos=$this->giteaservice->getRepos();
// Création du formulaire
$form = $this->createForm(Form::class,$data,array("mode"=>"update","gitearepos"=>$gitearepos));
// Récupération des data du formulaire
$form->handleRequest($request);
// Sur erreur
$this->getErrorForm(null,$form,$request,$data,"update");
// Sur validation
if ($form->get('submit')->isClicked() && $form->isValid()) {
$data = $form->getData();
$gitearepo=$this->giteaservice->getRepo($data->getGiteaid());
$data->setGiteaname($gitearepo->full_name);
$data->setGiteajson(json_decode(json_encode($gitearepo), true));
$em->persist($data);
$em->flush();
// Retour à la liste
return $this->redirectToRoute($this->route);
}
// Affichage du formulaire
return $this->render($this->render.'edit.html.twig', [
'useheader' => true,
'usesidebar' => false,
'maxwidth' => true,
$this->data => $data,
'mode' => 'update',
'form' => $form->createView()
]);
}
public function delete($id,Request $request)
{
// Initialisation de l'enregistrement
$em = $this->getDoctrine()->getManager();
$data=$em->getRepository($this->entity)->find($id);
// Controle avant suppression
$error=false;
if($id<0) $error=true;
if($error)
return $this->redirectToRoute($this->route."_update",["id"=>$id]);
else {
$em->remove($data);
$em->flush();
// Retour à la liste
return $this->redirectToRoute($this->route);
}
}
public function view($id,Request $request)
{
// Initialisation de l'enregistrement
$em = $this->getDoctrine()->getManager();
$data=$em->getRepository($this->entity)->find($id);
if(!$data) return $this->redirectToRoute($this->route);
2022-01-13 21:13:38 +01:00
2023-11-07 17:03:54 +01:00
$forcereload=false;
if($request->get("forcereload")) $forcereload=$request->get("forcereload");
// Mise à jour des issues par rapport à gitea
2023-11-07 17:03:54 +01:00
$em->getRepository("App:Scrum")->getGitea($data,$giteaassignees,$giteacolumns,$giteamilestones,$giteateams,$giteaprioritys,$giteatypes,$gitealabels,$forcereload);
// Création du tableau des issues
$issues=$data->getScrumissues();
$tbissues=[];
$tbcols=[];
$tbjals=[];
$tbsprs=[];
$tbestim=[];
$viewclosed = $this->get('session')->get("viewclosed");
foreach($issues as $issue) {
// bypass closed
if($viewclosed=="false"&&$issue->getGiteastate()=="closed") continue;
// Ids
$idcol=$issue->getScrumcolumn()->getId();
$idjal=($issue->getGiteamilestone()?$issue->getGiteamilestone():-100);
$idspr=($issue->getScrumsprint()?$issue->getScrumsprint()->getId():-100);
// Roworders
$rowcol=$issue->getScrumcolumn()->getRowid();
$rowjal=($issue->getGiteaMilestonename()?$issue->getGiteaMilestonename():-100);
$rowspr=($issue->getScrumsprint()?$issue->getScrumsprint()->getRowid():-100);
// Names
$nmcol=$issue->getScrumcolumn()->getName();
$nmjal=($issue->getGiteaMilestonename()?$issue->getGiteaMilestonename():"Aucun");
$nmspr=($issue->getScrumsprint()?$issue->getScrumsprint()->getName():"Aucun");
// Idgiteas
$gicol=$issue->getScrumcolumn()->getGiteaid();
$gijal=$issue->getGiteaMilestone();
// Liste des colonnes/jalons/sprint avec des issues
if(!in_array($idcol,$tbcols)) array_push($tbcols,$idcol);
if(!in_array($idcol."|".$idjal,$tbjals)) array_push($tbjals,$idcol."|".$idjal);
if(!in_array($idcol."|".$idjal."|".$idspr,$tbsprs)) array_push($tbsprs,$idcol."|".$idjal."|".$idspr);
// Initialisation du tableau des estimations
if(!array_key_exists($idjal,$tbestim)) {
$tbestim[$idjal] = [
"rowjal" => $rowjal,
"idjal" => $idjal,
"nmjal" => $nmjal,
"gijal" => $gijal,
"nbjrs" => 0,
"sprints" => []
];
}
if(!array_key_exists($idspr,$tbestim[$idjal]["sprints"])) {
$tbestim[$idjal]["sprints"][$idspr] = [
"rowspr" => $rowspr,
"idspr" => $idspr,
"nmspr" => $nmspr,
"nbjrs" => 0,
];
}
// Initialisation du tableau des colonnes
if(!array_key_exists($idcol,$tbissues)) {
$tbissues[$idcol]=[
"rowcol" => $rowcol,
"idcol" => $idcol,
"nmcol" => $nmcol,
"gicol" => $gicol,
"nbjrs" => 0,
"jalons" => [],
];
}
// Initialisation du tableau des jalons de la colonne encours
if(!array_key_exists($idjal,$tbissues[$idcol]["jalons"])) {
$tbissues[$idcol]["jalons"][$idjal] = [
"rowjal" => $rowjal,
"idjal" => $idjal,
"nmjal" => $nmjal,
"gijal" => $gijal,
"nbjrs" => 0,
"sprints" => [],
];
}
// Initialisation du tableau des sprint de la colonne/jalon encours
if(!array_key_exists($idspr,$tbissues[$idcol]["jalons"][$idjal]["sprints"])) {
$tbissues[$idcol]["jalons"][$idjal]["sprints"][$idspr] = [
"rowspr" => $rowspr,
"idspr" => $idspr,
"nmspr" => $nmspr,
"nbjrs" => 0,
"issues" => [],
];
}
// On cumule les estimations
$tbissues[$idcol]["nbjrs"]+=$issue->getWeight();
$tbissues[$idcol]["jalons"][$idjal]["nbjrs"]+=$issue->getWeight();
$tbissues[$idcol]["jalons"][$idjal]["sprints"][$idspr]["nbjrs"]+=$issue->getWeight();
$tbestim[$idjal]["nbjrs"]+=$issue->getWeight();
$tbestim[$idjal]["sprints"][$idspr]["nbjrs"]+=$issue->getWeight();
// On sauvegarde l'issue
array_push($tbissues[$idcol]["jalons"][$idjal]["sprints"][$idspr]["issues"],$issue);
}
// On ajoute les colonnes sans issues
$columns=$data->getScrumcolumns();
foreach($columns as $column) {
if(!in_array($column->getId(),$tbcols)) {
$tbissues[$column->getId()] = [
"rowcol" => $column->getRowid(),
"idcol" => $column->getId(),
"nmcol" => $column->getName(),
"gicol" => $column->getGiteaid(),
"nbjrs" => 0,
"jalons" => [],
];
}
// On ajoute les jalons sans issues
foreach($giteamilestones as $milestone) {
if(!in_array($column->getId()."|".$milestone->id,$tbjals)) {
$tbissues[$column->getId()]["jalons"][$milestone->id] = [
"rowjal" => $milestone->title,
"idjal" => $milestone->id,
"nmjal" => $milestone->title,
"gijal" => $milestone->id,
"nbjrs" => 0,
"sprints" => [],
];
}
}
// On ajoute le jalon aucun si sans issue
if(!in_array($column->getId()."|-100",$tbjals)) {
$tbissues[$column->getId()]["jalons"][-100] = [
"rowjal" => -100,
"idjal" => -100,
"nmjal" => "Aucun",
"gijal" => null,
"nbjrs" => 0,
"sprints" => [],
];
}
// On ajoutes les sprints sans issues
foreach($tbissues[$column->getId()]["jalons"] as $jalon) {
$sprints=$em->getRepository("App:Scrumsprint")->findBy(["scrum"=>$data,"giteamilestone"=>$jalon["idjal"]]);
foreach($sprints as $sprint) {
if(!in_array($column->getId()."|".$jalon["idjal"]."|".$sprint->getId(),$tbsprs)) {
$tbissues[$column->getId()]["jalons"][$jalon["idjal"]]["sprints"][$sprint->getId()] = [
"rowspr" => $sprint->getRowid(),
"idspr" => $sprint->getId(),
"nmspr" => $sprint->getName(),
"nbjrs" => 0,
"issues" => [],
];
}
}
// On ajoute les sprint aucun sans issue
if(!in_array($column->getId()."|".$jalon["idjal"]."|-100",$tbsprs)) {
$tbissues[$column->getId()]["jalons"][$jalon["idjal"]]["sprints"][-100] = [
"rowspr" => -100,
"idspr" => -100,
"nmspr" => "Aucun",
"nbjrs" => 0,
"issues" => [],
];
}
}
}
// Tri des issues par colonne/jalon/sprint/issue
$rowcol = array_column($tbissues, 'rowcol');
array_multisort($rowcol, SORT_ASC, $tbissues);
foreach($tbissues as $keycol=>$column) {
$rowjal = array_column($tbissues[$keycol]["jalons"], 'rowjal');
array_multisort($rowjal, SORT_DESC, $tbissues[$keycol]["jalons"]);
foreach($tbissues[$keycol]["jalons"] as $keyjal=>$jalon) {
$rowspr = array_column($tbissues[$keycol]["jalons"][$keyjal]["sprints"], 'rowspr');
array_multisort($rowspr, SORT_DESC, $tbissues[$keycol]["jalons"][$keyjal]["sprints"]);
}
}
2022-01-11 13:39:51 +01:00
// Préférences utilisateur
$filtermilestones = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filtermilestones",$id);
$filtersprints = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filtersprints",$id);
2022-01-28 16:54:46 +01:00
$filterteams = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filterteams",$id);
2022-02-03 17:26:35 +01:00
$filterprioritys = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filterprioritys",$id);
2023-08-30 11:15:33 +02:00
$filtertypes = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filtertypes",$id);
2022-01-11 13:39:51 +01:00
$filterlabels = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filterlabels",$id);
$filterassignees = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filterassignees",$id);
2022-06-29 11:50:27 +02:00
$filterexcludes = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filterexcludes",$id);
2022-01-28 16:54:46 +01:00
$showfilters = $em->getRepository("App:User")->getUserpreference($this->getUser(),"showfilters",$id);
2021-07-20 13:04:47 +02:00
return $this->render($this->render.'view.html.twig', [
'useheader' => true,
2022-01-13 21:13:38 +01:00
'usesidebar' => false,
'usetitle' => $data->getName(),
2022-01-11 13:39:51 +01:00
'giteaassignees' => $giteaassignees,
'giteacolumns' => $giteacolumns,
2021-07-20 13:04:47 +02:00
'giteamilestones' => $giteamilestones,
'sprints' => $data->getScrumsprints(),
2022-01-28 16:54:46 +01:00
'giteateams' => $giteateams,
2022-02-03 17:26:35 +01:00
'giteaprioritys' => $giteaprioritys,
2023-08-30 11:15:33 +02:00
'giteatypes' => $giteatypes,
2022-01-11 13:39:51 +01:00
'gitealabels' => $gitealabels,
'filtermilestones' => $filtermilestones,
'filtersprints' => $filtersprints,
2022-01-28 16:54:46 +01:00
'filterteams' => $filterteams,
2022-02-03 17:26:35 +01:00
'filterprioritys' => $filterprioritys,
2023-08-30 11:15:33 +02:00
'filtertypes' => $filtertypes,
2022-01-11 13:39:51 +01:00
'filterlabels' => $filterlabels,
'filterassignees' => $filterassignees,
2022-06-29 11:50:27 +02:00
'filterexcludes' => $filterexcludes,
2022-02-03 17:26:35 +01:00
'showfilters' => $showfilters,
'tbissues' => $tbissues,
'tbestim' => $tbestim,
2022-01-28 16:54:46 +01:00
$this->data => $data,
]);
}
public function table($id, Request $request)
2022-01-28 16:54:46 +01:00
{
$em = $this->getDoctrine()->getManager();
$fgcsv = $request->get("fgcsv");
// Récupérer les repos de gitea
$scrum=$em->getRepository("App:Scrum")->findOneBy(["id"=>$id]);
$gitearepos=[];
$giteamilestones=[];
$giteacolumns=[];
$giteateams=[];
$giteaprioritys=[];
$giteatypes=[];
$gitealabels=[];
$giteaassignees=$em->getRepository("App:User")->findBy([],["username"=>"ASC"]);
$viewclosed = $request->getSession()->get("viewclosed");
$gitearepo=$this->giteaservice->getRepo($scrum->getGiteajson()["id"]);
if($gitearepo->updated_at!=$scrum->getGiteajson()["updated_at"]||$gitearepo->open_issues_count!=$scrum->getGiteajson()["open_issues_count"]) {
$scrum->setGiteajson(json_decode(json_encode($gitearepo), true));
$em->persist($scrum);
$em->flush();
}
$giteamilestones=$this->giteaservice->getMilestones($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],"?state=".($viewclosed=="true"?"all":"open"));
$giteaissues=$this->giteaservice->getIssues($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],"?state=".($viewclosed=="true"?"all":"open"));
$json=$scrum->getGiteajson();
$json["issues"]=$giteaissues;
foreach($json["issues"] as $key => $giteaissue) {
$issue=$em->getRepository("App:Scrumissue")->findOneBy(["giteaid"=>$giteaissue->id]);
if($issue) {
$json["issues"][$key]->weight=$issue->getWeight();
$json["issues"][$key]->issueid=$issue->getId();
$json["issues"][$key]->scrumid=$issue->getScrum()->getId();
$json["issues"][$key]->sprintid=($issue->getScrumsprint()?$issue->getScrumsprint()->getId():-100);
$json["issues"][$key]->sprintname=($issue->getScrumsprint()?$issue->getScrumsprint()->getName():"Aucun");
}
else {
$json["issues"][$key]->weight=0;
$json["issues"][$key]->issueid=0;
$json["issues"][$key]->scrumid=0;
$json["issues"][$key]->sprintid=-100;
$json["issues"][$key]->sprintname="Aucun";
}
}
$tmp=[];
foreach($scrum->getScrumcolumns() as $column) {
array_push($tmp,$column->getGiteaid());
if(!in_array($column->getGiteajson()["name"],$giteacolumns))
array_push($giteacolumns,$column->getGiteajson()["name"]);
}
$json["columns"]=$tmp;
array_push($gitearepos,$json);
foreach($scrum->getScrumteams() as $team) {
if(!in_array($team->getGiteajson()["name"],$giteateams))
array_push($giteateams,$team->getGiteajson()["name"]);
}
foreach($scrum->getScrumprioritys() as $priority) {
if(!in_array($priority->getGiteajson()["name"],$giteaprioritys))
array_push($giteaprioritys,$priority->getGiteajson()["name"]);
}
foreach($scrum->getScrumtypes() as $type) {
if(!in_array($type->getGiteajson()["name"],$giteatypes))
array_push($giteatypes,$type->getGiteajson()["name"]);
}
foreach($giteaissues as $giteaissue) {
foreach($giteaissue->labels as $label) {
if(!in_array($label->name,$gitealabels))
array_push($gitealabels,$label->name);
}
}
$keysort = array_column($giteamilestones, 'title');
array_multisort($keysort, SORT_DESC, $giteamilestones);
sort($giteacolumns);
sort($giteateams);
sort($giteaprioritys);
sort($giteatypes);
sort($gitealabels);
2022-02-03 17:26:35 +01:00
// Préférences utilisateur
$filtercategorys = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filtercategorys",$id);
$filterrepos = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filterrepos",$id);
2022-02-03 17:26:35 +01:00
$filtermilestones = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filtermilestones",$id);
$filtersprints = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filtersprints",$id);
$filtercolumns = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filtercolumns",$id);
2022-02-03 17:26:35 +01:00
$filterteams = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filterteams",$id);
$filterprioritys = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filterprioritys",$id);
$filtertypes = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filtertypes",$id);
$filterlabels = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filterlabels",$id);
$filterassignees = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filterassignees",$id);
$filterexcludes = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filterexcludes",$id);
2022-02-03 17:26:35 +01:00
$showfilters = $em->getRepository("App:User")->getUserpreference($this->getUser(),"showfilters",$id);
2022-01-28 16:54:46 +01:00
if($fgcsv) {
$dir = $this->appKernel->getProjectDir() . '/uploads/issues/';
$file = "issues-".$id.".csv";
$fs = new Filesystem();
$fs->mkdir($dir);
$csvh = fopen($dir.$file, 'w');
$d = ';'; // this is the default but i like to be explicit
$e = '"'; // this is the default but i like to be explicit
$tmp=["Projet","Jalon","Type","Id","Titre","Statut","Label"];
fputcsv($csvh, $tmp, $d, $e);
foreach($gitearepos as $gitearepo) {
foreach($gitearepo["issues"] as $giteaissue) {
$statut="";
$type="";
$labels="";
foreach($giteaissue->labels as $label) {
if(in_array($label->id,$gitearepo["columns"]))
$statut=$label->name;
elseif(in_array($label->name,$giteatypes))
$type=$label->name;
else
$labels=$labels.($labels!=""?"\n":"").$label->name;
2022-01-28 16:54:46 +01:00
}
$tmp=[
$gitearepo["name"],
(isset($giteaissue->milestone->title)?$giteaissue->milestone->title:""),
$type,
$giteaissue->number,
$giteaissue->title,
$statut,
$labels
];
fputcsv($csvh, $tmp, $d, $e);
2022-01-28 16:54:46 +01:00
}
}
fclose($csvh);
2022-01-28 16:54:46 +01:00
$response = new BinaryFileResponse($dir.$file);
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);
return $response;
}
return $this->render($this->render.'table.html.twig',[
"useheader" => true,
"usesidebar" => false,
"id" => $id,
"gitearepos" => $gitearepos,
"giteamilestones" => $giteamilestones,
"sprints" => $scrum->getScrumsprints(),
"giteacolumns" => $giteacolumns,
"giteateams" => $giteateams,
"giteaprioritys" => $giteaprioritys,
"giteatypes" => $giteatypes,
"gitealabels" => $gitealabels,
"giteaassignees" => $giteaassignees,
"filtercategorys" => $filtercategorys,
"filterrepos" => $filterrepos,
"filtermilestones" => $filtermilestones,
"filtersprints" => $filtersprints,
"filtercolumns" => $filtercolumns,
"filterteams" => $filterteams,
"filterprioritys" => $filterprioritys,
"filtertypes" => $filtertypes,
"filterlabels" => $filterlabels,
"filterexcludes" => $filterexcludes,
"filterassignees" => $filterassignees,
"showfilters" => $showfilters,
]);
}
2022-02-03 17:26:35 +01:00
public function stat($id,Request $request)
{
// Initialisation de l'enregistrement
$em = $this->getDoctrine()->getManager();
$data=$em->getRepository($this->entity)->find($id);
if(!$data) return $this->redirectToRoute($this->route);
2022-02-03 17:26:35 +01:00
$em->getRepository("App:Scrum")->getGitea($data,$giteaassignees,$giteacolumns,$giteamilestones,$giteateams,$giteaprioritys,$giteatypes,$gitealabels);
2022-01-28 16:54:46 +01:00
// Préférences utilisateur
$filtermilestones = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filtermilestones",$id);
$filtersprints = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filtersprints",$id);
$showfilters = $em->getRepository("App:User")->getUserpreference($this->getUser(),"showfilters",$id);
2023-08-24 13:22:38 +02:00
// Création du tableau des issues
$issues=$data->getScrumissues();
$tbissues=[];
$tbcols=[];
$tbjals=[];
$tbsprs=[];
$tbestim=[];
$viewclosed = $this->get('session')->get("viewclosed");
foreach($issues as $issue) {
// bypass closed
if($viewclosed=="false"&&$issue->getGiteastate()=="closed") continue;
// Ids
$idcol=$issue->getScrumcolumn()->getId();
$idjal=($issue->getGiteamilestone()?$issue->getGiteamilestone():-100);
$idspr=($issue->getScrumsprint()?$issue->getScrumsprint()->getId():-100);
// Roworders
$rowcol=$issue->getScrumcolumn()->getRowid();
$rowjal=($issue->getGiteaMilestonename()?$issue->getGiteaMilestonename():-100);
$rowspr=($issue->getScrumsprint()?$issue->getScrumsprint()->getRowid():-100);
// Names
$nmcol=$issue->getScrumcolumn()->getName();
$nmjal=($issue->getGiteaMilestonename()?$issue->getGiteaMilestonename():"Aucun");
$nmspr=($issue->getScrumsprint()?$issue->getScrumsprint()->getName():"Aucun");
if(!array_key_exists($idjal,$tbestim)) {
$tbestim[$idjal] = [
"rowjal" => $rowjal,
"idjal" => $idjal,
"nmjal" => $nmjal,
"nbjrs" => 0,
"columns" => [],
"sprints" => [],
];
2022-01-28 16:54:46 +01:00
}
2023-08-24 13:22:38 +02:00
if(!array_key_exists($idspr,$tbestim[$idjal]["sprints"])) {
$tbestim[$idjal]["sprints"][$idspr] = [
"rowspr" => $rowspr,
"idspr" => $idspr,
"nmspr" => $nmspr,
"nbjrs" => 0,
"columns" => [],
];
}
if(!array_key_exists($idcol,$tbestim[$idjal]["columns"])) {
$tbestim[$idjal]["columns"][$idcol] = [
"rowcol" => $rowcol,
"idcol" => $idcol,
"nmcol" => $nmcol,
"color" => $issue->getScrumcolumn()->getGiteajson()["color"],
"nbjrs" => 0,
];
}
if(!array_key_exists($idcol,$tbestim[$idjal]["sprints"][$idspr]["columns"])) {
$tbestim[$idjal]["sprints"][$idspr]["columns"][$idcol] = [
"rowcol" => $rowcol,
"idcol" => $idcol,
"nmcol" => $nmcol,
"color" => $issue->getScrumcolumn()->getGiteajson()["color"],
"nbjrs" => 0,
];
}
// On cumule les estimations
$tbestim[$idjal]["nbjrs"]+=$issue->getWeight();
$tbestim[$idjal]["columns"][$idcol]["nbjrs"]+=$issue->getWeight();
$tbestim[$idjal]["sprints"][$idspr]["nbjrs"]+=$issue->getWeight();
$tbestim[$idjal]["sprints"][$idspr]["columns"][$idcol]["nbjrs"]+=$issue->getWeight();
}
2022-01-28 16:54:46 +01:00
return $this->render($this->render.'stat.html.twig', [
'useheader' => true,
'usesidebar' => false,
'usetitle' => $data->getName(),
'giteamilestones' => $giteamilestones,
2022-02-03 17:26:35 +01:00
'filtermilestones' => $filtermilestones,
'showfilters' => $showfilters,
2021-07-20 13:04:47 +02:00
$this->data => $data,
'tbestim' => $tbestim,
2021-07-20 13:04:47 +02:00
]);
}
public function info($id,Request $request)
{
$em = $this->getDoctrine()->getManager();
2023-11-07 17:03:54 +01:00
$viewclosed = $request->getSession()->get("viewclosed");
// Rechercher du scrum en cours
$scrum=$em->getRepository("App:Scrum")->find($id);
if(!$scrum) return new JsonResponse(['message' => 'No Issue'], 403);
2023-11-07 17:03:54 +01:00
$giteaissues=$this->giteaservice->getIssues($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],"?state=".($viewclosed=="true"?"all":"open"));
$weights=[];
foreach($giteaissues as $giteaissue) {
$scrumissue=$em->getRepository("App:Scrumissue")->findOneBy(["scrum"=>$scrum,"giteaid"=>$giteaissue->id]);
if($scrumissue) {
if($giteaissue->milestone) $milestoneid=$giteaissue->milestone->id;
else $milestoneid=-100;
if(!array_key_exists($milestoneid,$weights)) $weights[$milestoneid]=0;
$weights[$milestoneid]=$weights[$milestoneid]+$scrumissue->getWeight();
}
}
$output=[];
$output["weights"]=$weights;
return new JsonResponse($output);
}
private function consolidateScrum($scrum,$giteamilestones,&$tbissues,&$tbestim) {
$em = $this->getDoctrine()->getManager();
$issues=$scrum->getScrumissues();
$tbissues=[];
$tbestim=[];
$tbcols=[];
$tbjals=[];
$tbsprs=[];
$viewclosed = $this->get('session')->get("viewclosed");
foreach($issues as $issue) {
// bypass closed
if($viewclosed=="false"&&$issue->getGiteastate()=="closed") continue;
// Ids
$idcol=$issue->getScrumcolumn()->getId();
$idjal=($issue->getGiteamilestone()?$issue->getGiteamilestone():-100);
$idspr=($issue->getScrumsprint()?$issue->getScrumsprint()->getId():-100);
// Roworders
$rowcol=$issue->getScrumcolumn()->getRowid();
$rowjal=($issue->getGiteaMilestonename()?$issue->getGiteaMilestonename():-100);
$rowspr=($issue->getScrumsprint()?$issue->getScrumsprint()->getRowid():-100);
// Names
$nmcol=$issue->getScrumcolumn()->getName();
$nmjal=($issue->getGiteaMilestonename()?$issue->getGiteaMilestonename():"Aucun");
$nmspr=($issue->getScrumsprint()?$issue->getScrumsprint()->getName():"Aucun");
// Idgiteas
$gicol=$issue->getScrumcolumn()->getGiteaid();
$gijal=$issue->getGiteaMilestone();
// Liste des colonnes/jalons/sprint avec des issues
if(!in_array($idcol,$tbcols)) array_push($tbcols,$idcol);
if(!in_array($idcol."|".$idjal,$tbjals)) array_push($tbjals,$idcol."|".$idjal);
if(!in_array($idcol."|".$idjal."|".$idspr,$tbsprs)) array_push($tbsprs,$idcol."|".$idjal."|".$idspr);
// Initialisation du tableau des estimations
if(!array_key_exists($idjal,$tbestim)) {
$tbestim[$idjal] = [
"rowjal" => $rowjal,
"idjal" => $idjal,
"nmjal" => $nmjal,
"gijal" => $gijal,
"nbjrs" => 0,
"sprints" => []
];
}
if(!array_key_exists($idspr,$tbestim[$idjal]["sprints"])) {
$tbestim[$idjal]["sprints"][$idspr] = [
"rowspr" => $rowspr,
"idspr" => $idspr,
"nmspr" => $nmspr,
"nbjrs" => 0,
];
}
// Initialisation du tableau des colonnes
if(!array_key_exists($idcol,$tbissues)) {
$tbissues[$idcol]=[
"rowcol" => $rowcol,
"idcol" => $idcol,
"nmcol" => $nmcol,
"gicol" => $gicol,
"nbjrs" => 0,
"jalons" => [],
];
}
// Initialisation du tableau des jalons de la colonne encours
if(!array_key_exists($idjal,$tbissues[$idcol]["jalons"])) {
$tbissues[$idcol]["jalons"][$idjal] = [
"rowjal" => $rowjal,
"idjal" => $idjal,
"nmjal" => $nmjal,
"gijal" => $gijal,
"nbjrs" => 0,
"sprints" => [],
];
}
// Initialisation du tableau des sprint de la colonne/jalon encours
if(!array_key_exists($idspr,$tbissues[$idcol]["jalons"][$idjal]["sprints"])) {
$tbissues[$idcol]["jalons"][$idjal]["sprints"][$idspr] = [
"rowspr" => $rowspr,
"idspr" => $idspr,
"nmspr" => $nmspr,
"nbjrs" => 0,
"issues" => [],
];
}
// On cumule les estimations
$tbissues[$idcol]["nbjrs"]+=$issue->getWeight();
$tbissues[$idcol]["jalons"][$idjal]["nbjrs"]+=$issue->getWeight();
$tbissues[$idcol]["jalons"][$idjal]["sprints"][$idspr]["nbjrs"]+=$issue->getWeight();
$tbestim[$idjal]["nbjrs"]+=$issue->getWeight();
$tbestim[$idjal]["sprints"][$idspr]["nbjrs"]+=$issue->getWeight();
// On sauvegarde l'issue
array_push($tbissues[$idcol]["jalons"][$idjal]["sprints"][$idspr]["issues"],$issue);
}
// On ajoute les colonnes sans issues
$columns=$scrum->getScrumcolumns();
foreach($columns as $column) {
if(!in_array($column->getId(),$tbcols)) {
$tbissues[$column->getId()] = [
"rowcol" => $column->getRowid(),
"idcol" => $column->getId(),
"nmcol" => $column->getName(),
"gicol" => $column->getGiteaid(),
"nbjrs" => 0,
"jalons" => [],
];
}
// On ajoute les jalons sans issues
foreach($giteamilestones as $milestone) {
if(!in_array($column->getId()."|".$milestone->id,$tbjals)) {
$tbissues[$column->getId()]["jalons"][$milestone->id] = [
"rowjal" => $milestone->title,
"idjal" => $milestone->id,
"nmjal" => $milestone->title,
"gijal" => $milestone->id,
"nbjrs" => 0,
"sprints" => [],
];
}
}
// On ajoute le jalon aucun si sans issue
if(!in_array($column->getId()."|-100",$tbjals)) {
$tbissues[$column->getId()]["jalons"][-100] = [
"rowjal" => -100,
"idjal" => -100,
"nmjal" => "Aucun",
"gijal" => null,
"nbjrs" => 0,
"sprints" => [],
];
}
// On ajoutes les sprints sans issues
foreach($tbissues[$column->getId()]["jalons"] as $jalon) {
$sprints=$em->getRepository("App:Scrumsprint")->findBy(["scrum"=>$scrum,"giteamilestone"=>$jalon["idjal"]]);
foreach($sprints as $sprint) {
if(!in_array($column->getId()."|".$jalon["idjal"]."|".$sprint->getId(),$tbsprs)) {
$tbissues[$column->getId()]["jalons"][$jalon["idjal"]]["sprints"][$sprint->getId()] = [
"rowspr" => $sprint->getRowid(),
"idspr" => $sprint->getId(),
"nmspr" => $sprint->getName(),
"nbjrs" => 0,
"issues" => [],
];
}
}
// On ajoute les sprint aucun sans issue
if(!in_array($column->getId()."|".$jalon["idjal"]."|-100",$tbsprs)) {
$tbissues[$column->getId()]["jalons"][$jalon["idjal"]]["sprints"][-100] = [
"rowspr" => -100,
"idspr" => -100,
"nmspr" => "Aucun",
"nbjrs" => 0,
"issues" => [],
];
}
}
}
// Tri des issues par colonne/jalon/sprint/issue
$rowcol = array_column($tbissues, 'rowcol');
array_multisort($rowcol, SORT_ASC, $tbissues);
foreach($tbissues as $keycol=>$column) {
$rowjal = array_column($tbissues[$keycol]["jalons"], 'rowjal');
array_multisort($rowjal, SORT_DESC, $tbissues[$keycol]["jalons"]);
foreach($tbissues[$keycol]["jalons"] as $keyjal=>$jalon) {
$rowspr = array_column($tbissues[$keycol]["jalons"][$keyjal]["sprints"], 'rowspr');
array_multisort($rowspr, SORT_DESC, $tbissues[$keycol]["jalons"][$keyjal]["sprints"]);
}
}
}
2021-07-20 13:04:47 +02:00
protected function getErrorForm($id,$form,$request,$data,$mode) {
if ($form->get('submit')->isClicked()&&$mode=="delete") {
}
if ($form->get('submit')->isClicked() && $mode=="submit") {
}
if ($form->get('submit')->isClicked() && ($mode=="submit" || $mode=="update")) {
}
if ($form->get('submit')->isClicked() && !$form->isValid()) {
$this->get('session')->getFlashBag()->clear();
$errors = $form->getErrors();
foreach( $errors as $error ) {
$request->getSession()->getFlashBag()->add("error", $error->getMessage());
}
}
}
}