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;
|
2022-09-21 11:05:17 +02:00
|
|
|
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";
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
$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");
|
|
|
|
|
|
|
|
$em->getRepository("App:Scrum")->getGitea($data,$giteaassignees,$giteacolumns,$giteamilestones,$giteateams,$giteaprioritys,$giteatypes,$gitealabels,$forcereload);
|
2022-02-03 17:26:35 +01:00
|
|
|
|
2022-01-11 13:39:51 +01:00
|
|
|
// Préférences utilisateur
|
|
|
|
$filtermilestones = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filtermilestones",$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,
|
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,
|
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,
|
2022-01-28 16:54:46 +01:00
|
|
|
$this->data => $data,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2023-12-18 12:11:31 +01:00
|
|
|
|
2023-08-30 11:15:33 +02:00
|
|
|
$em->getRepository("App:Scrum")->getGitea($data,$giteaassignees,$giteacolumns,$giteamilestones,$giteateams,$giteaprioritys,$giteatypes,$gitealabels);
|
2022-02-03 17:26:35 +01:00
|
|
|
|
|
|
|
// Préférences utilisateur
|
|
|
|
$filtermilestones = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filtermilestones",$id);
|
|
|
|
$filterteams = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filterteams",$id);
|
|
|
|
$showfilters = $em->getRepository("App:User")->getUserpreference($this->getUser(),"showfilters",$id);
|
2022-01-28 16:54:46 +01:00
|
|
|
|
|
|
|
$tbstat=[];
|
|
|
|
foreach($data->getScrumIssues() as $issue) {
|
|
|
|
|
|
|
|
$labels=$issue->getGiteajson()["labels"];
|
2022-02-03 17:26:35 +01:00
|
|
|
$haveteams=true;
|
|
|
|
if($filterteams) {
|
|
|
|
$haveteams=false;
|
|
|
|
foreach($filterteams as $filterteam) {
|
|
|
|
foreach($labels as $label) {
|
|
|
|
if($label["id"]==$filterteam) {
|
|
|
|
$haveteams=true;
|
|
|
|
}
|
2022-01-28 16:54:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-03 17:26:35 +01:00
|
|
|
if($haveteams) {
|
|
|
|
$idmilestone=($issue->getGiteamilestone()?$issue->getGiteamilestone():-100);
|
|
|
|
$lbmilestone=($issue->getGiteamilestone()?$issue->getGiteamilestonename():"Aucun");
|
|
|
|
if(!array_key_exists($idmilestone,$tbstat)) {
|
|
|
|
$tbstat[$idmilestone]=["id"=>$idmilestone,"name"=>$lbmilestone,"stat"=>[]];
|
|
|
|
}
|
|
|
|
|
2023-12-18 12:11:31 +01:00
|
|
|
if(!$issue->getScrumcolumn()) $ordercolumns=0;
|
|
|
|
else $ordercolumns=array_search($issue->getScrumcolumn()->getGiteaid(),$giteacolumns);
|
|
|
|
|
2023-08-24 13:22:38 +02:00
|
|
|
//$ordercolumns=$issue->getScrumcolumn()->getId();
|
|
|
|
if(!array_key_exists($ordercolumns,$tbstat[$idmilestone]["stat"])) {
|
|
|
|
$tbstat[$idmilestone]["stat"][$ordercolumns]=[
|
2022-02-03 17:26:35 +01:00
|
|
|
"id"=>$issue->getScrumcolumn()->getId(),
|
|
|
|
"label"=>$issue->getScrumcolumn()->getName(),
|
|
|
|
"total"=>0,
|
|
|
|
"color"=>"#".$issue->getScrumcolumn()->getGiteajson()["color"],
|
|
|
|
"labels"=>[],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach($labels as $label) {
|
2023-12-18 12:11:31 +01:00
|
|
|
if($ordercolumns!=$label["id"]) {
|
2023-08-24 13:22:38 +02:00
|
|
|
if(!array_key_exists($label["id"],$tbstat[$idmilestone]["stat"][$ordercolumns]["labels"])) {
|
|
|
|
$tbstat[$idmilestone]["stat"][$ordercolumns]["labels"][$label["id"]] = [
|
2022-02-03 17:26:35 +01:00
|
|
|
"id"=>$label["id"],
|
|
|
|
"label"=>$label["name"],
|
|
|
|
"total"=>0,
|
|
|
|
"color"=>"#".$label["color"],
|
|
|
|
];
|
|
|
|
}
|
2023-08-24 13:22:38 +02:00
|
|
|
$tbstat[$idmilestone]["stat"][$ordercolumns]["labels"][$label["id"]]["total"]+=$issue->getWeight();
|
2022-02-03 17:26:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-24 13:22:38 +02:00
|
|
|
$tbstat[$idmilestone]["stat"][$ordercolumns]["total"]+=$issue->getWeight();
|
2022-02-03 17:26:35 +01:00
|
|
|
}
|
2022-01-28 16:54:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach($tbstat as $k1=>$milestone) {
|
2023-08-24 13:22:38 +02:00
|
|
|
$tmp=$tbstat[$k1]["stat"];
|
|
|
|
ksort($tmp);
|
|
|
|
$tbstat[$k1]["stat"]=$tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach($tbstat as $k1=>$milestone) {
|
|
|
|
foreach($tbstat[$k1]["stat"] as $k2=>$statut) {
|
2022-01-28 16:54:46 +01:00
|
|
|
$keysort = array_column($tbstat[$k1]["stat"][$k2]["labels"], 'label');
|
|
|
|
array_multisort($keysort, SORT_ASC, $tbstat[$k1]["stat"][$k2]["labels"]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-24 13:22:38 +02:00
|
|
|
|
2022-01-28 16:54:46 +01:00
|
|
|
return $this->render($this->render.'stat.html.twig', [
|
|
|
|
'useheader' => true,
|
|
|
|
'usesidebar' => false,
|
|
|
|
'usetitle' => $data->getName(),
|
|
|
|
'giteaassignees' => $giteaassignees,
|
|
|
|
'giteacolumns' => $giteacolumns,
|
|
|
|
'giteamilestones' => $giteamilestones,
|
|
|
|
'giteateams' => $giteateams,
|
2022-02-03 17:26:35 +01:00
|
|
|
'giteaprioritys' => $giteaprioritys,
|
2023-08-30 11:15:33 +02:00
|
|
|
'giteatypes' => $giteatypes,
|
2022-01-28 16:54:46 +01:00
|
|
|
'gitealabels' => $gitealabels,
|
2022-02-03 17:26:35 +01:00
|
|
|
'filtermilestones' => $filtermilestones,
|
|
|
|
'filterteams' => $filterteams,
|
|
|
|
'showfilters' => $showfilters,
|
2021-07-20 13:04:47 +02:00
|
|
|
$this->data => $data,
|
2022-01-28 16:54:46 +01:00
|
|
|
'tbstat' => $tbstat,
|
2021-07-20 13:04:47 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-09-21 11:05:17 +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");
|
2022-09-21 11:05:17 +02:00
|
|
|
|
|
|
|
// 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"));
|
2022-09-21 11:05:17 +02:00
|
|
|
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|