ninegitea/src/ninegitea-1.0/src/Controller/ScrumController.php

321 lines
13 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\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
2022-02-03 17:26:35 +01:00
$em->getRepository("App:Scrum")->getGitea($data,$giteaassignees,$giteacolumns,$giteamilestones,$giteateams,$giteaprioritys,$gitealabels);
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);
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,
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,
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);
2022-02-03 17:26:35 +01:00
$em->getRepository("App:Scrum")->getGitea($data,$giteaassignees,$giteacolumns,$giteamilestones,$giteateams,$giteaprioritys,$gitealabels);
// 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"=>[]];
}
if(!array_key_exists($issue->getScrumcolumn()->getId(),$tbstat[$idmilestone]["stat"])) {
$tbstat[$idmilestone]["stat"][$issue->getScrumcolumn()->getId()]=[
"id"=>$issue->getScrumcolumn()->getId(),
"label"=>$issue->getScrumcolumn()->getName(),
"total"=>0,
"color"=>"#".$issue->getScrumcolumn()->getGiteajson()["color"],
"labels"=>[],
];
}
foreach($labels as $label) {
if($issue->getScrumcolumn()->getGiteaid()!=$label["id"]) {
if(!array_key_exists($label["id"],$tbstat[$idmilestone]["stat"][$issue->getScrumcolumn()->getId()]["labels"])) {
$tbstat[$idmilestone]["stat"][$issue->getScrumcolumn()->getId()]["labels"][$label["id"]] = [
"id"=>$label["id"],
"label"=>$label["name"],
"total"=>0,
"color"=>"#".$label["color"],
];
}
$tbstat[$idmilestone]["stat"][$issue->getScrumcolumn()->getId()]["labels"][$label["id"]]["total"]++;
}
}
$tbstat[$idmilestone]["stat"][$issue->getScrumcolumn()->getId()]["total"]++;
}
2022-01-28 16:54:46 +01:00
}
foreach($tbstat as $k1=>$milestone) {
foreach($milestone["stat"] as $k2=>$statut) {
$keysort = array_column($tbstat[$k1]["stat"][$k2]["labels"], 'label');
array_multisort($keysort, SORT_ASC, $tbstat[$k1]["stat"][$k2]["labels"]);
}
}
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,
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
]);
}
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());
}
}
}
}