dockerisation
This commit is contained in:
0
src/Controller/.gitignore
vendored
Normal file
0
src/Controller/.gitignore
vendored
Normal file
115
src/Controller/ConfigController.php
Executable file
115
src/Controller/ConfigController.php
Executable file
@ -0,0 +1,115 @@
|
||||
<?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\Config as Entity;
|
||||
use App\Form\ConfigType as Form;
|
||||
|
||||
class ConfigController extends AbstractController
|
||||
{
|
||||
private $data = "config";
|
||||
private $route = "app_config";
|
||||
private $render = "Config/";
|
||||
private $entity = "App:Config";
|
||||
|
||||
public function list()
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$datas = $em->getRepository($this->entity)->findBy(["visible"=>true]);
|
||||
|
||||
return $this->render($this->render.'list.html.twig',[
|
||||
$this->data."s" => $datas,
|
||||
"useheader" => true,
|
||||
"usesidebar" => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function listrender($category)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$datas = $em->getRepository($this->entity)->findBy(["visible"=>true,"category"=>$category]);
|
||||
|
||||
return $this->render($this->render.'render.html.twig',[
|
||||
$this->data."s" => $datas,
|
||||
"useheader" => true,
|
||||
"usesidebar" => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function update($id,Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
if(!$data->getValue())
|
||||
$data->setValue($this->get('session')->get($data->getId()));
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"update","id"=>$data->getId(),"type"=>$data->getType(),"required"=>$data->getRequired()));
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Sur erreur
|
||||
$this->getErrorForm($id,$form,$request,$data,"update");
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
$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' => true,
|
||||
$this->data => $data,
|
||||
'mode' => 'update',
|
||||
'form' => $form->createView()
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete($id,Request $request)
|
||||
{
|
||||
// Récupération de l'enregistrement courant
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$config=$em->getRepository($this->entity)->find($id);
|
||||
if(!$config->getRequired()) {
|
||||
$config->setValue("");
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist($config);
|
||||
$em->flush();
|
||||
}
|
||||
return $this->redirectToRoute('app_config');
|
||||
}
|
||||
|
||||
public function logo()
|
||||
{
|
||||
return $this->render($this->render.'logo.html.twig');
|
||||
}
|
||||
|
||||
protected function getErrorForm($id,$form,$request,$data) {
|
||||
if ($form->get('submit')->isClicked() && !$form->isValid()) {
|
||||
$this->get('session')->getFlashBag()->clear();
|
||||
$validator = $this->get('validator');
|
||||
$errors = $validator->validate($data);
|
||||
foreach( $errors as $error ) {
|
||||
$request->getSession()->getFlashBag()->add("error", $error->getMessage());
|
||||
}
|
||||
|
||||
$errors = $form->getErrors();
|
||||
foreach( $errors as $error ) {
|
||||
$request->getSession()->getFlashBag()->add("error", $error->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
114
src/Controller/CronController.php
Normal file
114
src/Controller/CronController.php
Normal file
@ -0,0 +1,114 @@
|
||||
<?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 Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Output\BufferedOutput;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
|
||||
use App\Entity\Cron as Entity;
|
||||
use App\Form\CronType as Form;
|
||||
|
||||
class CronController extends AbstractController
|
||||
{
|
||||
private $data = "cron";
|
||||
private $route = "app_cron";
|
||||
private $render = "Cron/";
|
||||
private $entity = "App:Cron";
|
||||
|
||||
public function list()
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$datas = $em->getRepository($this->entity)->findAll();
|
||||
|
||||
return $this->render($this->render.'list.html.twig',[
|
||||
$this->data."s" => $datas,
|
||||
"useheader" => true,
|
||||
"usesidebar" => true,
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public function update($id,Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"update"));
|
||||
|
||||
// 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();
|
||||
$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' => true,
|
||||
$this->data => $data,
|
||||
'mode' => 'update',
|
||||
'form' => $form->createView()
|
||||
]);
|
||||
}
|
||||
|
||||
public function log()
|
||||
{
|
||||
return $this->render($this->render.'logs.html.twig', [
|
||||
'useheader' => true,
|
||||
'usesidebar' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getlog(Request $request, $id)
|
||||
{
|
||||
|
||||
$path = $this->getParameter('kernel.project_dir');
|
||||
if($id=="dump")
|
||||
$file = $path . '/var/log/' . $this->getParameter("appName") . '.sql';
|
||||
else
|
||||
$file = $path . '/var/log/'.$id.'.log';
|
||||
|
||||
$response = new BinaryFileResponse($file);
|
||||
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
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() && !$form->isValid()) {
|
||||
$this->get('session')->getFlashBag()->clear();
|
||||
|
||||
$errors = $form->getErrors();
|
||||
foreach( $errors as $error ) {
|
||||
$request->getSession()->getFlashBag()->add("error", $error->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
241
src/Controller/CropController.php
Normal file
241
src/Controller/CropController.php
Normal file
@ -0,0 +1,241 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class CropController extends AbstractController
|
||||
{
|
||||
private $appKernel;
|
||||
|
||||
public function __construct(KernelInterface $appKernel)
|
||||
{
|
||||
$this->appKernel = $appKernel;
|
||||
}
|
||||
|
||||
// Etape 01 - Téléchargement de l'image
|
||||
public function crop01($type,$reportinput)
|
||||
{
|
||||
return $this->render('Crop/crop01.html.twig',[
|
||||
'useheader' => false,
|
||||
'usesidebar' => false,
|
||||
'type' => $type,
|
||||
'reportinput' => $reportinput
|
||||
]);
|
||||
}
|
||||
|
||||
// Etape 02 - Couper votre l'image
|
||||
public function crop02($type,$reportinput,Request $request)
|
||||
{
|
||||
// Récupération de l'image à cropper
|
||||
$file=$request->query->get('file');
|
||||
$large_image_location = "uploads/$type/$file";
|
||||
|
||||
// Récupérer les tailles de l'image
|
||||
$width = $this->getWidth($large_image_location);
|
||||
$height = $this->getHeight($large_image_location);
|
||||
|
||||
// Définir le pourcentage de réduction de l'image
|
||||
switch ($type) {
|
||||
case "illustration":
|
||||
$max_height=0;
|
||||
$ratio="1:1";
|
||||
break;
|
||||
|
||||
case "avatar":
|
||||
$max_height=900;
|
||||
$max_width=900;
|
||||
$ratio="1:1";
|
||||
break;
|
||||
|
||||
case "hero":
|
||||
$max_height=1600;
|
||||
$max_width=1600;
|
||||
$ratio="16:9";
|
||||
break;
|
||||
|
||||
case "image":
|
||||
$max_height=1600;
|
||||
$max_width=1600;
|
||||
$ratio="1:1";
|
||||
break;
|
||||
}
|
||||
|
||||
if($max_height>0) {
|
||||
$scale = $max_height/$height;
|
||||
if(($width*$scale)>$max_width) {
|
||||
$scale = $max_width/$width;
|
||||
}
|
||||
$this->resizeImage($large_image_location,$width,$height,$scale);
|
||||
}
|
||||
else $scale=1;
|
||||
|
||||
// Construction du formulaire
|
||||
$submited=false;
|
||||
$form = $this->createFormBuilder()
|
||||
->add('submit',SubmitType::class,array("label" => "Valider","attr" => array("class" => "btn btn-success")))
|
||||
->add('x',HiddenType::class)
|
||||
->add('y',HiddenType::class)
|
||||
->add('w',HiddenType::class)
|
||||
->add('h',HiddenType::class)
|
||||
->add('xs',HiddenType::class)
|
||||
->add('ys',HiddenType::class)
|
||||
->add('ws',HiddenType::class)
|
||||
->add('hs',HiddenType::class)
|
||||
->getForm();
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Sur validation on généère la miniature croppée
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
// Récupération des valeurs du formulaire
|
||||
$data = $form->getData();
|
||||
$thumb_image_location = "uploads/$type/thumb_".$file;
|
||||
$cropped = $this->resizeThumbnailImage($thumb_image_location, $large_image_location,$data["ws"],$data["hs"],$data["xs"],$data["ys"],$scale);
|
||||
$submited=true;
|
||||
}
|
||||
|
||||
return $this->render('Crop/crop02.html.twig', [
|
||||
'useheader' => false,
|
||||
'usesidebar' => false,
|
||||
'form' => $form->createView(),
|
||||
'type' => $type,
|
||||
'file' => $file,
|
||||
'ratio' => $ratio,
|
||||
"reportinput" => $reportinput,
|
||||
"submited" => $submited
|
||||
]);
|
||||
}
|
||||
|
||||
// Upload ckeditor
|
||||
public function ckupload(Request $request) {
|
||||
// Fichier temporaire uploadé
|
||||
$tmpfile = $request->files->get('upload');
|
||||
$extention = $tmpfile->getClientOriginalExtension();
|
||||
|
||||
// Répertoire de Destination
|
||||
$fs = new Filesystem();
|
||||
$rootdir = $this->appKernel->getProjectDir()."/public";
|
||||
$fs->mkdir($rootdir."/uploads/ckeditor");
|
||||
|
||||
// Fichier cible
|
||||
$targetName = uniqid().".".$extention;
|
||||
$targetFile = $rootdir."/uploads/ckeditor/".$targetName;
|
||||
$targetUrl = $this->getParameter('appAlias')."uploads/ckeditor/".$targetName;
|
||||
$message = "";
|
||||
|
||||
move_uploaded_file($tmpfile,$targetFile);
|
||||
|
||||
$output["uploaded"]=1;
|
||||
$output["fileName"]=$targetName;
|
||||
$output["url"]=$targetUrl;
|
||||
|
||||
return new Response(json_encode($output));
|
||||
}
|
||||
|
||||
// Calcul de la hauteur
|
||||
protected function getHeight($image) {
|
||||
$size = getimagesize($image);
|
||||
$height = $size[1];
|
||||
return $height;
|
||||
}
|
||||
|
||||
// Cacul de la largeur
|
||||
protected function getWidth($image) {
|
||||
$size = getimagesize($image);
|
||||
$width = $size[0];
|
||||
return $width;
|
||||
}
|
||||
|
||||
protected function resizeImage($image,$width,$height,$scale) {
|
||||
list($imagewidth, $imageheight, $imageType) = getimagesize($image);
|
||||
$imageType = image_type_to_mime_type($imageType);
|
||||
$newImageWidth = ceil($width * $scale);
|
||||
$newImageHeight = ceil($height * $scale);
|
||||
$newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
|
||||
switch($imageType) {
|
||||
case "image/gif":
|
||||
$source=imagecreatefromgif($image);
|
||||
break;
|
||||
case "image/pjpeg":
|
||||
case "image/jpeg":
|
||||
case "image/jpg":
|
||||
$source=imagecreatefromjpeg($image);
|
||||
break;
|
||||
case "image/png":
|
||||
case "image/x-png":
|
||||
$source=imagecreatefrompng($image);
|
||||
break;
|
||||
}
|
||||
imagecopyresampled($newImage,$source,0,0,0,0,$newImageWidth,$newImageHeight,$width,$height);
|
||||
|
||||
switch($imageType) {
|
||||
case "image/gif":
|
||||
imagegif($newImage,$image);
|
||||
break;
|
||||
case "image/pjpeg":
|
||||
case "image/jpeg":
|
||||
case "image/jpg":
|
||||
imagejpeg($newImage,$image,90);
|
||||
break;
|
||||
case "image/png":
|
||||
case "image/x-png":
|
||||
imagepng($newImage,$image);
|
||||
break;
|
||||
}
|
||||
|
||||
chmod($image, 0640);
|
||||
return $image;
|
||||
}
|
||||
|
||||
protected function resizeThumbnailImage($thumb_image_name, $image, $width, $height, $start_width, $start_height, $scale){
|
||||
$fs = new Filesystem();
|
||||
$fs->remove($thumb_image_name);
|
||||
|
||||
list($imagewidth, $imageheight, $imageType) = getimagesize($image);
|
||||
$imageType = image_type_to_mime_type($imageType);
|
||||
|
||||
$newImageWidth = ceil($width * $scale);
|
||||
$newImageHeight = ceil($height * $scale);
|
||||
$newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
|
||||
switch($imageType) {
|
||||
case "image/gif":
|
||||
$source=imagecreatefromgif($image);
|
||||
break;
|
||||
case "image/pjpeg":
|
||||
case "image/jpeg":
|
||||
case "image/jpg":
|
||||
$source=imagecreatefromjpeg($image);
|
||||
break;
|
||||
case "image/png":
|
||||
case "image/x-png":
|
||||
$source=imagecreatefrompng($image);
|
||||
break;
|
||||
}
|
||||
imagecopyresampled($newImage,$source,0,0,$start_width,$start_height,$newImageWidth,$newImageHeight,$width,$height);
|
||||
switch($imageType) {
|
||||
case "image/gif":
|
||||
imagegif($newImage,$thumb_image_name);
|
||||
break;
|
||||
case "image/pjpeg":
|
||||
case "image/jpeg":
|
||||
case "image/jpg":
|
||||
imagejpeg($newImage,$thumb_image_name,90);
|
||||
break;
|
||||
case "image/png":
|
||||
case "image/x-png":
|
||||
imagepng($newImage,$thumb_image_name);
|
||||
break;
|
||||
}
|
||||
chmod($thumb_image_name, 0640);
|
||||
return $thumb_image_name;
|
||||
}
|
||||
|
||||
}
|
187
src/Controller/GroupController.php
Executable file
187
src/Controller/GroupController.php
Executable file
@ -0,0 +1,187 @@
|
||||
<?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\Group as Entity;
|
||||
use App\Form\GroupType as Form;
|
||||
|
||||
class GroupController extends AbstractController
|
||||
{
|
||||
private $data = "group";
|
||||
private $route = "app_group";
|
||||
private $render = "Group/";
|
||||
private $entity = "App:Group";
|
||||
|
||||
public function list(Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$datas = $em->getRepository($this->entity)->findAll();
|
||||
|
||||
return $this->render($this->render.'list.html.twig',[
|
||||
$this->data."s" => $datas,
|
||||
"useheader" => true,
|
||||
"usesidebar" => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function submit(Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data = new Entity();
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"submit"));
|
||||
|
||||
// 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();
|
||||
$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' => 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);
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"update"));
|
||||
|
||||
// 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();
|
||||
$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' => 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 select(Request $request)
|
||||
{
|
||||
// S'assurer que c'est un appel ajax
|
||||
if (!$request->isXmlHttpRequest()) {
|
||||
return new JsonResponse(array('message' => 'Interdit'), 400);
|
||||
}
|
||||
|
||||
$output=array();
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$page_limit=$request->query->get('page_limit');
|
||||
$q=$request->query->get('q');
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
if($this->getUser()->Hasrole("ROLE_ADMIN")) {
|
||||
$qb->select('table')->from($this->entity,'table')
|
||||
->where('table.name LIKE :value')
|
||||
->setParameter("value", "%".$q."%")
|
||||
->orderBy('table.name');
|
||||
}
|
||||
else {
|
||||
$qb->select('table')->from($this->entity,'table')
|
||||
->where('table.name LIKE :value')
|
||||
->andwhere(":user MEMBER OF table.users")
|
||||
->setParameter("value", "%".$q."%")
|
||||
->setParameter("user",$this->getUser())
|
||||
->orderBy('table.name');
|
||||
}
|
||||
|
||||
$datas=$qb->setFirstResult(0)->setMaxResults($page_limit)->getQuery()->getResult();
|
||||
foreach($datas as $data) {
|
||||
array_push($output,array("id"=>$data->getId(),"text"=>$data->getName()));
|
||||
}
|
||||
|
||||
$ret_string["results"]=$output;
|
||||
$response = new Response(json_encode($ret_string));
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
return $response;
|
||||
}
|
||||
|
||||
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")) {
|
||||
// On s'assure que le label ne contient pas des caractères speciaux
|
||||
$string = preg_replace('~[^ éèêôöàïî\'@a-zA-Z0-9._-]~', '', $data->getName());
|
||||
if($string!=$data->getName())
|
||||
{
|
||||
$form->addError(new FormError('Caractères interdit dans ce label'));
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
50
src/Controller/HomeController.php
Executable file
50
src/Controller/HomeController.php
Executable file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
class HomeController extends AbstractController
|
||||
{
|
||||
public function home()
|
||||
{
|
||||
return $this->redirectToRoute("app_scrum");
|
||||
}
|
||||
|
||||
public function admin()
|
||||
{
|
||||
return $this->render('Home/admin.html.twig',[
|
||||
"useheader" => true,
|
||||
"usesidebar" => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function upload(Request $request,$access=null) {
|
||||
// Fichier temporaire uploadé
|
||||
$tmpfile = $request->files->get('upload');
|
||||
$extention = $tmpfile->getClientOriginalExtension();
|
||||
|
||||
// Répertoire de Destination
|
||||
$fs = new Filesystem();
|
||||
$rootdir = $this->getParameter('kernel.project_dir') . '/public';
|
||||
$fs->mkdir($rootdir."/uploads/ckeditor");
|
||||
|
||||
// Fichier cible
|
||||
$targetName = uniqid().".".$extention;
|
||||
$targetFile = $rootdir."/uploads/ckeditor/".$targetName;
|
||||
$targetUrl = $this->getParameter('appAlias')."uploads/ckeditor/".$targetName;
|
||||
$message = "";
|
||||
|
||||
move_uploaded_file($tmpfile,$targetFile);
|
||||
|
||||
$output["uploaded"]=1;
|
||||
$output["fileName"]=$targetName;
|
||||
$output["url"]=$targetUrl;
|
||||
|
||||
return new Response(json_encode($output));
|
||||
}
|
||||
|
||||
}
|
212
src/Controller/IssueController.php
Executable file
212
src/Controller/IssueController.php
Executable file
@ -0,0 +1,212 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
|
||||
use App\Service\giteaService;
|
||||
|
||||
class IssueController extends AbstractController
|
||||
{
|
||||
private $appKernel;
|
||||
private $data = "issue";
|
||||
private $route = "app_issue";
|
||||
private $render = "Issue/";
|
||||
private $entity = "App:Issue";
|
||||
|
||||
public function __construct(KernelInterface $appKernel,giteaService $giteaservice) {
|
||||
$this->appKernel = $appKernel;
|
||||
$this->giteaservice = $giteaservice;
|
||||
}
|
||||
|
||||
public function list($id, Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$fgcsv = $request->get("fgcsv");
|
||||
|
||||
// Récupérer les repos de gitea
|
||||
if($id==0) $scrums=$em->getRepository("App:Scrum")->findBy([],["name"=>"ASC"]);
|
||||
else $scrums=$em->getRepository("App:Scrum")->findBy(["id"=>$id],["name"=>"ASC"]);
|
||||
|
||||
$giteacategorys=[];
|
||||
$gitearepos=[];
|
||||
$giteamilestones=[];
|
||||
$giteacolumns=[];
|
||||
$giteateams=[];
|
||||
$giteaprioritys=[];
|
||||
$giteatypes=[];
|
||||
$gitealabels=[];
|
||||
$giteaassignees=$em->getRepository("App:User")->findBy([],["username"=>"ASC"]);
|
||||
$viewclosed = $request->getSession()->get("viewclosed");
|
||||
|
||||
foreach($scrums as $key => $scrum) {
|
||||
if(!in_array($scrum->getCategory(),$giteacategorys))
|
||||
array_push($giteacategorys,$scrum->getCategory());
|
||||
|
||||
$gitearepo=$this->giteaservice->getRepo($scrum->getGiteajson()["id"]);
|
||||
if(!$gitearepo) die("Probleme de connexion avec gitea veuillez vous <a href='/ninegitea/logout'>reconnecter</a>");
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
if($gitearepo->open_issues_count>0) {
|
||||
$giteatmp=$this->giteaservice->getMilestones($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],"?state=".($viewclosed=="true"?"all":"open"));
|
||||
foreach($giteatmp as $key => $value) {
|
||||
$giteatmp[$key]->title = $scrum->getGiteajson()["full_name"]. " = ".$giteatmp[$key]->title;
|
||||
}
|
||||
array_push($giteatmp,["id"=>$scrum->getGiteajson()["full_name"],"title"=> $scrum->getGiteajson()["full_name"]. " = Aucun Jalon"]);
|
||||
$giteamilestones=array_merge($giteamilestones,$giteatmp);
|
||||
|
||||
$giteaissues=$this->giteaservice->getIssues($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],"?state=".($viewclosed=="true"?"all":"open"));
|
||||
$json=$scrum->getGiteajson();
|
||||
$json["issues"]=$giteaissues;
|
||||
$json["category"]=$scrum->getCategory();
|
||||
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();
|
||||
}
|
||||
else {
|
||||
$json["issues"][$key]->weight=0;
|
||||
$json["issues"][$key]->issueid=0;
|
||||
$json["issues"][$key]->scrumid=0;
|
||||
}
|
||||
}
|
||||
|
||||
$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);
|
||||
sort($giteacategorys);
|
||||
|
||||
// Préférences utilisateur
|
||||
$filtercategorys = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filtercategorys",$id);
|
||||
$filterrepos = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filterrepos",$id);
|
||||
$filtermilestones = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filtermilestones",$id);
|
||||
$filtercolumns = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filtercolumns",$id);
|
||||
$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);
|
||||
$showfilters = $em->getRepository("App:User")->getUserpreference($this->getUser(),"showfilters",$id);
|
||||
|
||||
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;
|
||||
}
|
||||
$tmp=[
|
||||
$gitearepo["name"],
|
||||
(isset($giteaissue->milestone->title)?$giteaissue->milestone->title:""),
|
||||
$type,
|
||||
$giteaissue->number,
|
||||
$giteaissue->title,
|
||||
$statut,
|
||||
$labels
|
||||
];
|
||||
fputcsv($csvh, $tmp, $d, $e);
|
||||
}
|
||||
}
|
||||
fclose($csvh);
|
||||
|
||||
$response = new BinaryFileResponse($dir.$file);
|
||||
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);
|
||||
return $response;
|
||||
}
|
||||
|
||||
return $this->render($this->render.'list.html.twig',[
|
||||
"useheader" => true,
|
||||
"usesidebar" => false,
|
||||
"id" => $id,
|
||||
"giteacategorys" => $giteacategorys,
|
||||
"gitearepos" => $gitearepos,
|
||||
"giteamilestones" => $giteamilestones,
|
||||
"giteacolumns" => $giteacolumns,
|
||||
"giteateams" => $giteateams,
|
||||
"giteaprioritys" => $giteaprioritys,
|
||||
"giteatypes" => $giteatypes,
|
||||
"gitealabels" => $gitealabels,
|
||||
"giteaassignees" => $giteaassignees,
|
||||
"filtercategorys" => $filtercategorys,
|
||||
"filterrepos" => $filterrepos,
|
||||
"filtermilestones" => $filtermilestones,
|
||||
"filtercolumns" => $filtercolumns,
|
||||
"filterteams" => $filterteams,
|
||||
"filterprioritys" => $filterprioritys,
|
||||
"filtertypes" => $filtertypes,
|
||||
"filterlabels" => $filterlabels,
|
||||
"filterexcludes" => $filterexcludes,
|
||||
"filterassignees" => $filterassignees,
|
||||
"showfilters" => $showfilters,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
137
src/Controller/ReportController.php
Executable file
137
src/Controller/ReportController.php
Executable file
@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
use App\Service\giteaService;
|
||||
|
||||
class ReportController extends AbstractController
|
||||
{
|
||||
public function __construct(KernelInterface $appKernel, giteaService $giteaservice) {
|
||||
$this->appKernel = $appKernel;
|
||||
$this->giteaservice = $giteaservice;
|
||||
}
|
||||
|
||||
public function list($id,Request $request)
|
||||
{
|
||||
set_time_limit(0);
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$scrum = $em->getRepository("App:Scrum")->find($id);
|
||||
$repoid = $scrum->getGiteaid();
|
||||
$repoowner = $scrum->getGiteajson()["owner"]["login"];
|
||||
$reponame = $scrum->getGiteajson()["name"];
|
||||
|
||||
$repo=$this->giteaservice->getRepo($repoid);
|
||||
$issues=$this->giteaservice->getIssues($repoowner,$reponame,"?state=all");
|
||||
|
||||
foreach($issues as $keyissue => $issue) {
|
||||
// On ne prend pas les pull request
|
||||
if(!is_null($issue->pull_request)) {
|
||||
unset($issues[$keyissue]);
|
||||
continue;
|
||||
}
|
||||
|
||||
//$issues[$keyissue]->body = $this->giteaservice->markdown("/".$scrum->getGiteajson()["full_name"],"comment",$issues[$keyissue]->body);
|
||||
//$issues[$keyissue]->comments=$this->giteaservice->getIssueComments($repoowner,$reponame,$issue->number);
|
||||
|
||||
/*
|
||||
Trop lourd
|
||||
foreach($issues[$keyissue]->comments as $keycomment => $comment) {
|
||||
$issues[$keyissue]->comments[$keycomment]->body=$this->giteaservice->markdown("/".$scrum->getGiteajson()["full_name"],"comment",$issues[$keyissue]->comments[$keycomment]->body);
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
Trop lourd
|
||||
$issues[$keyissue]->timelines=$this->giteaservice->getIssueTimelines($repoowner,$reponame,$issue->number);
|
||||
*/
|
||||
$issues[$keyissue]->timelines=[];
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render('Report/list.html.twig', [
|
||||
'useheader' => false,
|
||||
'usesidebar' => false,
|
||||
'maxwidth' => true,
|
||||
'repo' => $repo,
|
||||
'issues' => $issues,
|
||||
]);
|
||||
}
|
||||
|
||||
public function csv($id,Request $request)
|
||||
{
|
||||
set_time_limit(0);
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$scrum = $em->getRepository("App:Scrum")->find($id);
|
||||
$repoid = $scrum->getGiteaid();
|
||||
$repoowner = $scrum->getGiteajson()["owner"]["login"];
|
||||
$reponame = $scrum->getGiteajson()["name"];
|
||||
|
||||
$repo=$this->giteaservice->getRepo($repoid);
|
||||
$issues=$this->giteaservice->getIssues($repoowner,$reponame,"?state=all");
|
||||
|
||||
$fs = new Filesystem();
|
||||
$rootdir = $this->appKernel->getProjectDir();
|
||||
$destdir = $rootdir."/var/log/export.csv";
|
||||
|
||||
$csvh = fopen($destdir, 'w');
|
||||
$d = ';'; // this is the default but i like to be explicit
|
||||
$e = '"'; // this is the default but i like to be explicit
|
||||
|
||||
$tbcumul=[];
|
||||
|
||||
foreach($issues as $issue) {
|
||||
$monthsubmit=new \DateTime($issue->created_at);
|
||||
$monthsubmit=$monthsubmit->format("Ym");
|
||||
if(!array_key_exists($monthsubmit,$tbcumul))
|
||||
$tbcumul[$monthsubmit]=["month"=>$monthsubmit,"nbsubmit"=>0,"nbclose"=>0];
|
||||
$tbcumul[$monthsubmit]["nbsubmit"]=$tbcumul[$monthsubmit]["nbsubmit"]+1;
|
||||
|
||||
$monthclose=new \DateTime($issue->closed_at);
|
||||
$monthclose=$monthclose->format("Ym");
|
||||
if(!array_key_exists($monthclose,$tbcumul))
|
||||
$tbcumul[$monthclose]=["month"=>$monthclose,"nbsubmit"=>0,"nbclose"=>0];
|
||||
$tbcumul[$monthclose]["nbclose"]=$tbcumul[$monthclose]["nbclose"]+1;
|
||||
}
|
||||
|
||||
foreach($tbcumul as $cumul) {
|
||||
fputcsv($csvh, $cumul, $d, $e);
|
||||
}
|
||||
fclose($csvh);
|
||||
|
||||
$response = new BinaryFileResponse($destdir);
|
||||
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);
|
||||
|
||||
return $response;
|
||||
|
||||
}
|
||||
|
||||
public function test($id,Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$scrum = $em->getRepository("App:Scrum")->find($id);
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$scrum = $em->getRepository("App:Scrum")->find($id);
|
||||
$repoid = $scrum->getGiteaid();
|
||||
$repoowner = $scrum->getGiteajson()["owner"]["login"];
|
||||
$reponame = $scrum->getGiteajson()["name"];
|
||||
|
||||
$repo=$this->giteaservice->getRepo($repoid);
|
||||
dump($repo);
|
||||
dump($repoowner);
|
||||
$labels=$this->giteaservice->getorglabels($repoowner);
|
||||
|
||||
dump($labels);
|
||||
|
||||
|
||||
}
|
||||
}
|
367
src/Controller/ScrumController.php
Executable file
367
src/Controller/ScrumController.php
Executable file
@ -0,0 +1,367 @@
|
||||
<?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;
|
||||
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();
|
||||
$scrums = $em->getRepository($this->entity)->findByUser($this->getUser());
|
||||
|
||||
$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"]);
|
||||
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();
|
||||
}
|
||||
|
||||
array_push($gitearepos,$gitearepo);
|
||||
}
|
||||
}
|
||||
sort($giteacategorys);
|
||||
|
||||
$filtercategorys = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filtercategorys",0);
|
||||
$filterrepos = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filterrepos",0);
|
||||
|
||||
return $this->render($this->render.'list.html.twig',[
|
||||
$this->data."s" => $scrums,
|
||||
"giteacategorys" => $giteacategorys,
|
||||
"gitearepos" => $gitearepos,
|
||||
"filtercategorys" => $filtercategorys,
|
||||
"filterrepos" => $filterrepos,
|
||||
"useheader" => true,
|
||||
"usesidebar" => false,
|
||||
]);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
$forcereload=false;
|
||||
if($request->get("forcereload")) $forcereload=$request->get("forcereload");
|
||||
|
||||
$em->getRepository("App:Scrum")->getGitea($data,$giteaassignees,$giteacolumns,$giteamilestones,$giteateams,$giteaprioritys,$giteatypes,$gitealabels,$forcereload);
|
||||
|
||||
// Préférences utilisateur
|
||||
$filtermilestones = $em->getRepository("App:User")->getUserpreference($this->getUser(),"filtermilestones",$id);
|
||||
$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);
|
||||
$showfilters = $em->getRepository("App:User")->getUserpreference($this->getUser(),"showfilters",$id);
|
||||
|
||||
return $this->render($this->render.'view.html.twig', [
|
||||
'useheader' => true,
|
||||
'usesidebar' => false,
|
||||
'usetitle' => $data->getName(),
|
||||
'giteaassignees' => $giteaassignees,
|
||||
'giteacolumns' => $giteacolumns,
|
||||
'giteamilestones' => $giteamilestones,
|
||||
'giteateams' => $giteateams,
|
||||
'giteaprioritys' => $giteaprioritys,
|
||||
'giteatypes' => $giteatypes,
|
||||
'gitealabels' => $gitealabels,
|
||||
'filtermilestones' => $filtermilestones,
|
||||
'filterteams' => $filterteams,
|
||||
'filterprioritys' => $filterprioritys,
|
||||
'filtertypes' => $filtertypes,
|
||||
'filterlabels' => $filterlabels,
|
||||
'filterassignees' => $filterassignees,
|
||||
'filterexcludes' => $filterexcludes,
|
||||
'showfilters' => $showfilters,
|
||||
$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);
|
||||
|
||||
$em->getRepository("App:Scrum")->getGitea($data,$giteaassignees,$giteacolumns,$giteamilestones,$giteateams,$giteaprioritys,$giteatypes,$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);
|
||||
|
||||
$tbstat=[];
|
||||
foreach($data->getScrumIssues() as $issue) {
|
||||
|
||||
$labels=$issue->getGiteajson()["labels"];
|
||||
$haveteams=true;
|
||||
if($filterteams) {
|
||||
$haveteams=false;
|
||||
foreach($filterteams as $filterteam) {
|
||||
foreach($labels as $label) {
|
||||
if($label["id"]==$filterteam) {
|
||||
$haveteams=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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(!$issue->getScrumcolumn()) $ordercolumns=0;
|
||||
else $ordercolumns=array_search($issue->getScrumcolumn()->getGiteaid(),$giteacolumns);
|
||||
|
||||
//$ordercolumns=$issue->getScrumcolumn()->getId();
|
||||
if(!array_key_exists($ordercolumns,$tbstat[$idmilestone]["stat"])) {
|
||||
$tbstat[$idmilestone]["stat"][$ordercolumns]=[
|
||||
"id"=>$issue->getScrumcolumn()->getId(),
|
||||
"label"=>$issue->getScrumcolumn()->getName(),
|
||||
"total"=>0,
|
||||
"color"=>"#".$issue->getScrumcolumn()->getGiteajson()["color"],
|
||||
"labels"=>[],
|
||||
];
|
||||
}
|
||||
|
||||
foreach($labels as $label) {
|
||||
if($ordercolumns!=$label["id"]) {
|
||||
if(!array_key_exists($label["id"],$tbstat[$idmilestone]["stat"][$ordercolumns]["labels"])) {
|
||||
$tbstat[$idmilestone]["stat"][$ordercolumns]["labels"][$label["id"]] = [
|
||||
"id"=>$label["id"],
|
||||
"label"=>$label["name"],
|
||||
"total"=>0,
|
||||
"color"=>"#".$label["color"],
|
||||
];
|
||||
}
|
||||
$tbstat[$idmilestone]["stat"][$ordercolumns]["labels"][$label["id"]]["total"]+=$issue->getWeight();
|
||||
}
|
||||
}
|
||||
|
||||
$tbstat[$idmilestone]["stat"][$ordercolumns]["total"]+=$issue->getWeight();
|
||||
}
|
||||
}
|
||||
|
||||
foreach($tbstat as $k1=>$milestone) {
|
||||
$tmp=$tbstat[$k1]["stat"];
|
||||
ksort($tmp);
|
||||
$tbstat[$k1]["stat"]=$tmp;
|
||||
}
|
||||
|
||||
foreach($tbstat as $k1=>$milestone) {
|
||||
foreach($tbstat[$k1]["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,
|
||||
'giteaprioritys' => $giteaprioritys,
|
||||
'giteatypes' => $giteatypes,
|
||||
'gitealabels' => $gitealabels,
|
||||
'filtermilestones' => $filtermilestones,
|
||||
'filterteams' => $filterteams,
|
||||
'showfilters' => $showfilters,
|
||||
$this->data => $data,
|
||||
'tbstat' => $tbstat,
|
||||
]);
|
||||
}
|
||||
|
||||
public function info($id,Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$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);
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
200
src/Controller/ScrumcolumnController.php
Executable file
200
src/Controller/ScrumcolumnController.php
Executable file
@ -0,0 +1,200 @@
|
||||
<?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\Scrumcolumn as Entity;
|
||||
use App\Form\ScrumcolumnType as Form;
|
||||
|
||||
use App\Service\giteaService;
|
||||
|
||||
class ScrumcolumnController extends AbstractController
|
||||
{
|
||||
private $data = "scrumcolumn";
|
||||
private $route = "app_scrumcolumn";
|
||||
private $render = "Scrumcolumn/";
|
||||
private $entity = "App:Scrumcolumn";
|
||||
|
||||
public function __construct(giteaService $giteaservice) { $this->giteaservice = $giteaservice; }
|
||||
|
||||
public function submit($scrumid, Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$scrum=$em->getRepository("App:Scrum")->find($scrumid);
|
||||
$data = new Entity();
|
||||
$data->setScrum($scrum);
|
||||
|
||||
$last = $em->getRepository('App:Scrumcolumn')->findOneBy(["scrum"=>$scrum], ['rowid' => 'DESC']);
|
||||
if(!$last) $data->setRowid(0);
|
||||
else $data->setRowid($last->getRowid()+1);
|
||||
|
||||
// Récupérer les repos de gitea
|
||||
$gitealabels=$this->giteaservice->getLabels($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"]);
|
||||
if(!is_array($gitealabels)) die("Probleme de connexion avec gitea veuillez vous <a href='/ninegitea/logout'>reconnecter</a>");
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"submit","gitealabels"=>$gitealabels));
|
||||
|
||||
// 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();
|
||||
$gitealabel=$this->giteaservice->getLabel($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],$data->getGiteaid());
|
||||
$data->setGiteajson(json_decode(json_encode($gitealabel), true));
|
||||
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->render($this->render.'close.html.twig');
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'edit.html.twig', [
|
||||
'useheader' => false,
|
||||
'usesidebar' => false,
|
||||
$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);
|
||||
$scrum=$data->getScrum();
|
||||
|
||||
// Récupérer les repos de gitea
|
||||
$gitealabels=$this->giteaservice->getLabels($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"]);
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"submit","gitealabels"=>$gitealabels));
|
||||
|
||||
// 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();
|
||||
$gitealabel=$this->giteaservice->getLabel($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],$data->getGiteaid());
|
||||
$data->setGiteajson(json_decode(json_encode($gitealabel), true));
|
||||
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->render($this->render.'close.html.twig');
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'edit.html.twig', [
|
||||
'useheader' => false,
|
||||
'usesidebar' => false,
|
||||
$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->render($this->render.'close.html.twig');
|
||||
}
|
||||
}
|
||||
|
||||
public function select($scrumid, Request $request)
|
||||
{
|
||||
// S'assurer que c'est un appel ajax
|
||||
if (!$request->isXmlHttpRequest()) {
|
||||
return new JsonResponse(array('message' => 'Interdit'), 400);
|
||||
}
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$scrum=$em->getRepository("App:Scrum")->find($scrumid);
|
||||
|
||||
$scrumcolumns = $scrum->getScrumcolumns();
|
||||
$output=array();
|
||||
foreach($scrumcolumns as $scrumcolumn) {
|
||||
array_push($output,array("id"=>$scrumcolumn->getId(),"name"=>"<b>".$scrumcolumn->getName()."</b><br><small>liè au label gitea ".$scrumcolumn->getGiteajson()["name"]."</small>"));
|
||||
}
|
||||
|
||||
$response = new Response(json_encode($output));
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function order($scrumid, Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$scrumcolumnids=explode(",",$request->get('lstordered'));
|
||||
$i=1;
|
||||
foreach($scrumcolumnids as $id) {
|
||||
$scrumcolumn=$em->getRepository($this->entity)->find($id);
|
||||
if($scrumcolumn) {
|
||||
$scrumcolumn->setRowid($i);
|
||||
$em->persist($scrumcolumn);
|
||||
$em->flush();
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
$response = new Response();
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
return $response;
|
||||
}
|
||||
|
||||
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")) {
|
||||
// On s'assure que le label ne contient pas des caractères speciaux
|
||||
$string = preg_replace('~[^ éèêôöàïî\'@a-zA-Z0-9._-]~', '', $data->getName());
|
||||
if($string!=$data->getName())
|
||||
{
|
||||
$form->addError(new FormError('Caractères interdit dans ce label'));
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
192
src/Controller/ScrumissueController.php
Executable file
192
src/Controller/ScrumissueController.php
Executable file
@ -0,0 +1,192 @@
|
||||
<?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;
|
||||
use Symfony\Component\Form\FormError;
|
||||
|
||||
use App\Entity\Scrumissue as Entity;
|
||||
use App\Form\ScrumissueType as Form;
|
||||
|
||||
use App\Service\giteaService;
|
||||
|
||||
class ScrumissueController extends AbstractController
|
||||
{
|
||||
private $data = "Scrumissue";
|
||||
private $route = "app_Scrumissue";
|
||||
private $render = "Scrumissue/";
|
||||
private $entity = "App:Scrumissue";
|
||||
|
||||
public function __construct(giteaService $giteaservice) { $this->giteaservice = $giteaservice; }
|
||||
|
||||
public function change(Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$id=$request->get('id');
|
||||
$oldcolumn=$request->get('oldcolumn');
|
||||
$newcolumn=$request->get('newcolumn');
|
||||
$oldmilestone=$request->get('oldmilestone');
|
||||
$newmilestone=$request->get('newmilestone');
|
||||
|
||||
if($oldcolumn!=$newcolumn||$oldmilestone!=$newmilestone) {
|
||||
// Rechercher l'issue en cours
|
||||
$scrumissue=$em->getRepository("App:Scrumissue")->find($id);
|
||||
if(!$scrumissue) return new JsonResponse(['message' => 'No Issue'], 403);
|
||||
|
||||
// Récupérer la liste des labels de l'issue
|
||||
$gitealabels=$this->giteaservice->getIssuelabels($scrumissue->getScrum()->getGiteajson()["owner"]["login"],$scrumissue->getScrum()->getGiteajson()["name"],$scrumissue->getGiteanumber());
|
||||
if(!is_array($gitealabels)) return new JsonResponse(['message' => 'No API getIssuelabels'], 403);
|
||||
|
||||
// Remplacer l'ancien column par la nouvelle
|
||||
if($oldcolumn!=$newcolumn) {
|
||||
$newgitelabels=[];
|
||||
$haveold=false;
|
||||
foreach($gitealabels as $gitealabel) {
|
||||
if($gitealabel->id!=$oldcolumn) array_push($newgitelabels,$gitealabel->id);
|
||||
else $haveold=true;
|
||||
}
|
||||
if(!in_array($newcolumn,$newgitelabels)) array_push($newgitelabels,intval($newcolumn));
|
||||
|
||||
// Supprimer l'ancien label
|
||||
if($haveold) {
|
||||
$return=$this->giteaservice->deleteIssuelabel($scrumissue->getScrum()->getGiteajson()["owner"]["login"],$scrumissue->getScrum()->getGiteajson()["name"],$scrumissue->getGiteanumber(),$oldcolumn);
|
||||
if(!$return) return new JsonResponse(['message' => 'No API deleteIssuelabel'], 403);
|
||||
}
|
||||
|
||||
// Mettre à jour les labels
|
||||
$return=$this->giteaservice->putIssuelabels($scrumissue->getScrum()->getGiteajson()["owner"]["login"],$scrumissue->getScrum()->getGiteajson()["name"],$scrumissue->getGiteanumber(),$newgitelabels);
|
||||
if(!$return) return new JsonResponse(['message' => 'No API putIssuelabels'], 403);
|
||||
}
|
||||
|
||||
// Mettre à jour le milestone
|
||||
if($oldmilestone!=$newmilestone) {
|
||||
$patchs=["milestone"=>intval($newmilestone)];
|
||||
$return=$this->giteaservice->patchIssue($scrumissue->getScrum()->getGiteajson()["owner"]["login"],$scrumissue->getScrum()->getGiteajson()["name"],$scrumissue->getGiteanumber(),$patchs);
|
||||
if(!$return) return new JsonResponse(['message' => 'No API patchIssue'], 403);
|
||||
}
|
||||
|
||||
// Récupérer l'issue modifiée pour mettre à jour la date de modification gitea
|
||||
$giteaissue=$this->giteaservice->getIssue($scrumissue->getScrum()->getGiteajson()["owner"]["login"],$scrumissue->getScrum()->getGiteajson()["name"],$scrumissue->getGiteanumber());
|
||||
if(!$giteaissue) return new JsonResponse(['message' => 'No API getIssue'], 403);
|
||||
$updatedate=new \DateTime($giteaissue->updated_at);
|
||||
if($updatedate > $scrumissue->getScrum()->getUpdatedate()) {
|
||||
$scrumissue->getScrum()->setUpdatedate(new \DateTime($giteaissue->updated_at));
|
||||
$em->persist($scrumissue->getScrum());
|
||||
$em->flush();
|
||||
return new JsonResponse($updatedate->format("Ymd H:i:s"));
|
||||
}
|
||||
}
|
||||
return new JsonResponse(false);
|
||||
}
|
||||
|
||||
public function order(Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$id=$request->get('id');
|
||||
$lstordered=explode(",",$request->get('lstordered'));
|
||||
|
||||
$scrum=$em->getRepository("App:Scrum")->find($id);
|
||||
if(!$scrum) return new JsonResponse(['message' => 'No Scrum'], 403);
|
||||
|
||||
$order=0;
|
||||
foreach($lstordered as $item) {
|
||||
$scrumissue=$em->getRepository("App:Scrumissue")->find($item);
|
||||
if($scrumissue) {
|
||||
$scrumissue->setRowid($order);
|
||||
$order++;
|
||||
$em->persist($scrumissue);
|
||||
}
|
||||
}
|
||||
|
||||
$em->flush();
|
||||
|
||||
return new JsonResponse();
|
||||
}
|
||||
|
||||
public function info(Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$id=$request->get('id');
|
||||
|
||||
// Rechercher l'issue en cours
|
||||
$scrumissue=$em->getRepository("App:Scrumissue")->find($id);
|
||||
if(!$scrumissue) return new JsonResponse(['message' => 'No Issue'], 403);
|
||||
|
||||
$output=[];
|
||||
$output["weight"]=$scrumissue->getWeight();
|
||||
|
||||
return new JsonResponse($output);
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$id=$request->get('id');
|
||||
$weight=$request->get('weight');
|
||||
|
||||
// Rechercher l'issue en cours
|
||||
$scrumissue=$em->getRepository("App:Scrumissue")->find($id);
|
||||
if(!$scrumissue) return new JsonResponse(['message' => 'No Issue'], 403);
|
||||
|
||||
$scrumissue->setWeight($weight);
|
||||
$em->flush();
|
||||
|
||||
$giteaissues=$this->giteaservice->getIssues($scrumissue->getScrum()->getGiteajson()["owner"]["login"],$scrumissue->getScrum()->getGiteajson()["name"]);
|
||||
|
||||
$weights=[];
|
||||
foreach($giteaissues as $giteaissue) {
|
||||
$issue=$em->getRepository("App:Scrumissue")->findOneBy(["scrum"=>$scrumissue->getScrum(),"giteaid"=>$giteaissue->id]);
|
||||
if($issue) {
|
||||
if($giteaissue->milestone) $milestoneid=$giteaissue->milestone->id;
|
||||
else $milestoneid=-100;
|
||||
|
||||
if(!array_key_exists($milestoneid,$weights)) $weights[$milestoneid]=0;
|
||||
$weights[$milestoneid]=$weights[$milestoneid]+$issue->getWeight();
|
||||
}
|
||||
}
|
||||
return new JsonResponse($weights);
|
||||
}
|
||||
|
||||
public function ctrlchange(Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$id=$request->get('id');
|
||||
$lastupdate=new \DateTime($request->get('lastupdate'));
|
||||
|
||||
$scrum=$em->getRepository("App:Scrum")->find($id);
|
||||
if(!$scrum) return new JsonResponse(['message' => 'No Scrum'], 403);
|
||||
|
||||
$giteaissues=$this->giteaservice->getIssues($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"]);
|
||||
if(!is_array($giteaissues)) die("Probleme de connexion avec gitea veuillez vous <a href='/ninegitea/logout'>reconnecter</a>");
|
||||
|
||||
foreach($giteaissues as $giteaissue) {
|
||||
// On ne prend pas les pull request
|
||||
if(!is_null($giteaissue->pull_request))
|
||||
continue;
|
||||
|
||||
$scrumissue=$em->getRepository("App:Scrumissue")->findOneBy(["scrum"=>$scrum,"giteaid"=>$giteaissue->id]);
|
||||
|
||||
if(!$scrumissue)
|
||||
return new JsonResponse(true);
|
||||
|
||||
$fgissueupdated=false;
|
||||
$updatedate=new \DateTime(json_decode(json_encode($giteaissue), true)["updated_at"]);
|
||||
if($updatedate>$lastupdate) {
|
||||
$fgissueupdated=true;
|
||||
}
|
||||
|
||||
if($fgissueupdated)
|
||||
return new JsonResponse(true);
|
||||
}
|
||||
|
||||
return new JsonResponse(false);
|
||||
}
|
||||
}
|
194
src/Controller/ScrumpriorityController.php
Executable file
194
src/Controller/ScrumpriorityController.php
Executable file
@ -0,0 +1,194 @@
|
||||
<?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\Scrumpriority as Entity;
|
||||
use App\Form\ScrumpriorityType as Form;
|
||||
|
||||
use App\Service\giteaService;
|
||||
|
||||
class ScrumpriorityController extends AbstractController
|
||||
{
|
||||
private $data = "scrumpriority";
|
||||
private $route = "app_scrumpriority";
|
||||
private $render = "Scrumpriority/";
|
||||
private $entity = "App:Scrumpriority";
|
||||
|
||||
public function __construct(giteaService $giteaservice) { $this->giteaservice = $giteaservice; }
|
||||
|
||||
public function submit($scrumid, Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$scrum=$em->getRepository("App:Scrum")->find($scrumid);
|
||||
$data = new Entity();
|
||||
$data->setScrum($scrum);
|
||||
|
||||
$last = $em->getRepository('App:Scrumpriority')->findOneBy(["scrum"=>$scrum], ['rowid' => 'DESC']);
|
||||
if(!$last) $data->setRowid(0);
|
||||
else $data->setRowid($last->getRowid()+1);
|
||||
|
||||
// Récupérer les repos de gitea
|
||||
$gitealabels=$this->giteaservice->getLabels($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"]);
|
||||
if(!is_array($gitealabels)) die("Probleme de connexion avec gitea veuillez vous <a href='/ninegitea/logout'>reconnecter</a>");
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"submit","gitealabels"=>$gitealabels));
|
||||
|
||||
// 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();
|
||||
$gitealabel=$this->giteaservice->getLabel($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],$data->getGiteaid());
|
||||
$data->setGiteajson(json_decode(json_encode($gitealabel), true));
|
||||
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->render($this->render.'close.html.twig');
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'edit.html.twig', [
|
||||
'useheader' => false,
|
||||
'usesidebar' => false,
|
||||
$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);
|
||||
$scrum=$data->getScrum();
|
||||
|
||||
// Récupérer les repos de gitea
|
||||
$gitealabels=$this->giteaservice->getLabels($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"]);
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"submit","gitealabels"=>$gitealabels));
|
||||
|
||||
// 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();
|
||||
$gitealabel=$this->giteaservice->getLabel($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],$data->getGiteaid());
|
||||
$data->setGiteajson(json_decode(json_encode($gitealabel), true));
|
||||
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->render($this->render.'close.html.twig');
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'edit.html.twig', [
|
||||
'useheader' => false,
|
||||
'usesidebar' => false,
|
||||
$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->render($this->render.'close.html.twig');
|
||||
}
|
||||
}
|
||||
|
||||
public function select($scrumid, Request $request)
|
||||
{
|
||||
// S'assurer que c'est un appel ajax
|
||||
if (!$request->isXmlHttpRequest()) {
|
||||
return new JsonResponse(array('message' => 'Interdit'), 400);
|
||||
}
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$scrum=$em->getRepository("App:Scrum")->find($scrumid);
|
||||
|
||||
$scrumprioritys = $scrum->getScrumprioritys();
|
||||
$output=array();
|
||||
foreach($scrumprioritys as $scrumpriority) {
|
||||
array_push($output,array("id"=>$scrumpriority->getId(),"name"=>"<b>".$scrumpriority->getName()."</b><br><small>liè au label gitea ".$scrumpriority->getGiteajson()["name"]."</small>"));
|
||||
}
|
||||
|
||||
$response = new Response(json_encode($output));
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function order($scrumid, Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$scrumpriorityids=explode(",",$request->get('lstordered'));
|
||||
$i=1;
|
||||
foreach($scrumpriorityids as $id) {
|
||||
$scrumpriority=$em->getRepository($this->entity)->find($id);
|
||||
if($scrumpriority) {
|
||||
$scrumpriority->setRowid($i);
|
||||
$em->persist($scrumpriority);
|
||||
$em->flush();
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
$response = new Response();
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
return $response;
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
194
src/Controller/ScrumteamController.php
Executable file
194
src/Controller/ScrumteamController.php
Executable file
@ -0,0 +1,194 @@
|
||||
<?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\Scrumteam as Entity;
|
||||
use App\Form\ScrumteamType as Form;
|
||||
|
||||
use App\Service\giteaService;
|
||||
|
||||
class ScrumteamController extends AbstractController
|
||||
{
|
||||
private $data = "scrumteam";
|
||||
private $route = "app_scrumteam";
|
||||
private $render = "Scrumteam/";
|
||||
private $entity = "App:Scrumteam";
|
||||
|
||||
public function __construct(giteaService $giteaservice) { $this->giteaservice = $giteaservice; }
|
||||
|
||||
public function submit($scrumid, Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$scrum=$em->getRepository("App:Scrum")->find($scrumid);
|
||||
$data = new Entity();
|
||||
$data->setScrum($scrum);
|
||||
|
||||
$last = $em->getRepository('App:Scrumteam')->findOneBy(["scrum"=>$scrum], ['rowid' => 'DESC']);
|
||||
if(!$last) $data->setRowid(0);
|
||||
else $data->setRowid($last->getRowid()+1);
|
||||
|
||||
// Récupérer les repos de gitea
|
||||
$gitealabels=$this->giteaservice->getLabels($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"]);
|
||||
if(!is_array($gitealabels)) die("Probleme de connexion avec gitea veuillez vous <a href='/ninegitea/logout'>reconnecter</a>");
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"submit","gitealabels"=>$gitealabels));
|
||||
|
||||
// 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();
|
||||
$gitealabel=$this->giteaservice->getLabel($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],$data->getGiteaid());
|
||||
$data->setGiteajson(json_decode(json_encode($gitealabel), true));
|
||||
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->render($this->render.'close.html.twig');
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'edit.html.twig', [
|
||||
'useheader' => false,
|
||||
'usesidebar' => false,
|
||||
$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);
|
||||
$scrum=$data->getScrum();
|
||||
|
||||
// Récupérer les repos de gitea
|
||||
$gitealabels=$this->giteaservice->getLabels($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"]);
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"submit","gitealabels"=>$gitealabels));
|
||||
|
||||
// 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();
|
||||
$gitealabel=$this->giteaservice->getLabel($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],$data->getGiteaid());
|
||||
$data->setGiteajson(json_decode(json_encode($gitealabel), true));
|
||||
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->render($this->render.'close.html.twig');
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'edit.html.twig', [
|
||||
'useheader' => false,
|
||||
'usesidebar' => false,
|
||||
$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->render($this->render.'close.html.twig');
|
||||
}
|
||||
}
|
||||
|
||||
public function select($scrumid, Request $request)
|
||||
{
|
||||
// S'assurer que c'est un appel ajax
|
||||
if (!$request->isXmlHttpRequest()) {
|
||||
return new JsonResponse(array('message' => 'Interdit'), 400);
|
||||
}
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$scrum=$em->getRepository("App:Scrum")->find($scrumid);
|
||||
|
||||
$scrumteams = $scrum->getScrumteams();
|
||||
$output=array();
|
||||
foreach($scrumteams as $scrumteam) {
|
||||
array_push($output,array("id"=>$scrumteam->getId(),"name"=>"<b>".$scrumteam->getName()."</b><br><small>liè au label gitea ".$scrumteam->getGiteajson()["name"]."</small>"));
|
||||
}
|
||||
|
||||
$response = new Response(json_encode($output));
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function order($scrumid, Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$scrumteamids=explode(",",$request->get('lstordered'));
|
||||
$i=1;
|
||||
foreach($scrumteamids as $id) {
|
||||
$scrumteam=$em->getRepository($this->entity)->find($id);
|
||||
if($scrumteam) {
|
||||
$scrumteam->setRowid($i);
|
||||
$em->persist($scrumteam);
|
||||
$em->flush();
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
$response = new Response();
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
return $response;
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
194
src/Controller/ScrumtypeController.php
Executable file
194
src/Controller/ScrumtypeController.php
Executable file
@ -0,0 +1,194 @@
|
||||
<?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\Scrumtype as Entity;
|
||||
use App\Form\ScrumtypeType as Form;
|
||||
|
||||
use App\Service\giteaService;
|
||||
|
||||
class ScrumtypeController extends AbstractController
|
||||
{
|
||||
private $data = "scrumtype";
|
||||
private $route = "app_scrumtype";
|
||||
private $render = "Scrumtype/";
|
||||
private $entity = "App:Scrumtype";
|
||||
|
||||
public function __construct(giteaService $giteaservice) { $this->giteaservice = $giteaservice; }
|
||||
|
||||
public function submit($scrumid, Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$scrum=$em->getRepository("App:Scrum")->find($scrumid);
|
||||
$data = new Entity();
|
||||
$data->setScrum($scrum);
|
||||
|
||||
$last = $em->getRepository('App:Scrumtype')->findOneBy(["scrum"=>$scrum], ['rowid' => 'DESC']);
|
||||
if(!$last) $data->setRowid(0);
|
||||
else $data->setRowid($last->getRowid()+1);
|
||||
|
||||
// Récupérer les repos de gitea
|
||||
$gitealabels=$this->giteaservice->getLabels($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"]);
|
||||
if(!is_array($gitealabels)) die("Probleme de connexion avec gitea veuillez vous <a href='/ninegitea/logout'>reconnecter</a>");
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"submit","gitealabels"=>$gitealabels));
|
||||
|
||||
// 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();
|
||||
$gitealabel=$this->giteaservice->getLabel($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],$data->getGiteaid());
|
||||
$data->setGiteajson(json_decode(json_encode($gitealabel), true));
|
||||
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->render($this->render.'close.html.twig');
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'edit.html.twig', [
|
||||
'useheader' => false,
|
||||
'usesidebar' => false,
|
||||
$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);
|
||||
$scrum=$data->getScrum();
|
||||
|
||||
// Récupérer les repos de gitea
|
||||
$gitealabels=$this->giteaservice->getLabels($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"]);
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"submit","gitealabels"=>$gitealabels));
|
||||
|
||||
// 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();
|
||||
$gitealabel=$this->giteaservice->getLabel($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],$data->getGiteaid());
|
||||
$data->setGiteajson(json_decode(json_encode($gitealabel), true));
|
||||
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->render($this->render.'close.html.twig');
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'edit.html.twig', [
|
||||
'useheader' => false,
|
||||
'usesidebar' => false,
|
||||
$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->render($this->render.'close.html.twig');
|
||||
}
|
||||
}
|
||||
|
||||
public function select($scrumid, Request $request)
|
||||
{
|
||||
// S'assurer que c'est un appel ajax
|
||||
if (!$request->isXmlHttpRequest()) {
|
||||
return new JsonResponse(array('message' => 'Interdit'), 400);
|
||||
}
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$scrum=$em->getRepository("App:Scrum")->find($scrumid);
|
||||
|
||||
$scrumtypes = $scrum->getScrumtypes();
|
||||
$output=array();
|
||||
foreach($scrumtypes as $scrumtype) {
|
||||
array_push($output,array("id"=>$scrumtype->getId(),"name"=>"<b>".$scrumtype->getName()."</b><br><small>liè au label gitea ".$scrumtype->getGiteajson()["name"]."</small>"));
|
||||
}
|
||||
|
||||
$response = new Response(json_encode($output));
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function order($scrumid, Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$scrumtypeids=explode(",",$request->get('lstordered'));
|
||||
$i=1;
|
||||
foreach($scrumtypeids as $id) {
|
||||
$scrumtype=$em->getRepository($this->entity)->find($id);
|
||||
if($scrumtype) {
|
||||
$scrumtype->setRowid($i);
|
||||
$em->persist($scrumtype);
|
||||
$em->flush();
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
$response = new Response();
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
return $response;
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
264
src/Controller/SecurityController.php
Executable file
264
src/Controller/SecurityController.php
Executable file
@ -0,0 +1,264 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Entity\Group;
|
||||
use App\Service\ldapService as ldapService;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
||||
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use App\Service\giteaService;
|
||||
|
||||
class SecurityController extends AbstractController
|
||||
{
|
||||
public function __construct(giteaService $giteaservice) { $this->giteaservice = $giteaservice; }
|
||||
|
||||
public function login(Request $request, AuthenticationUtils $authenticationUtils)
|
||||
{
|
||||
|
||||
$auth_mode=$this->getParameter("appAuth");
|
||||
switch($auth_mode) {
|
||||
case "SQL":
|
||||
return $this->loginMYSQL($request,$authenticationUtils);
|
||||
break;
|
||||
|
||||
case "OAUTH":
|
||||
return $this->loginOAUTH($request,$authenticationUtils);
|
||||
break;
|
||||
|
||||
case "CAS":
|
||||
return $this->loginCAS($request,$authenticationUtils);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function loginMYSQL(Request $request, AuthenticationUtils $authenticationUtils) {
|
||||
return $this->render('Home/login.html.twig', array(
|
||||
'last_username' => $authenticationUtils->getLastUsername(),
|
||||
'error' => $authenticationUtils->getLastAuthenticationError(),
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
public function loginCAS(Request $request, AuthenticationUtils $authenticationUtils)
|
||||
{
|
||||
// Récupération de la cible de navigation
|
||||
$redirect = $this->get('session')->get("_security.main.target_path");
|
||||
|
||||
// Init Client CAS
|
||||
\phpCAS::client(CAS_VERSION_2_0, $this->getParameter('casHost'), intval($this->getParameter('casPort')), is_null($this->getParameter('casPath')) ? '' : $this->getParameter('casPath'), false);
|
||||
\phpCAS::setNoCasServerValidation();
|
||||
|
||||
|
||||
// Authentification
|
||||
\phpCAS::forceAuthentication();
|
||||
|
||||
// Récupération UID
|
||||
$username = \phpCAS::getUser();
|
||||
|
||||
// Récupération Attribut
|
||||
$attributes = \phpCAS::getAttributes();
|
||||
|
||||
// Init
|
||||
$email = "";
|
||||
$lastname = "";
|
||||
$firstname = "";
|
||||
|
||||
// Rechercher l'utilisateur
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
if(isset($attributes[$this->getParameter('casUsername')]))
|
||||
$username = $attributes[$this->getParameter('casUsername')];
|
||||
|
||||
if(isset($attributes[$this->getParameter('casEmail')]))
|
||||
$email = $attributes[$this->getParameter('casEmail')];
|
||||
|
||||
if(isset($attributes[$this->getParameter('casLastname')]))
|
||||
$lastname = $attributes[$this->getParameter('casLastname')];
|
||||
|
||||
if(isset($attributes[$this->getParameter('casFirstname')]))
|
||||
$firstname = $attributes[$this->getParameter('casFirstname')];
|
||||
|
||||
$user = $em->getRepository('App:User')->findOneBy(array("username"=>$username));
|
||||
$exists = $user ? true : false;
|
||||
|
||||
if (!$exists) {
|
||||
if(empty($email)) $email = $username."@nomail.com";
|
||||
|
||||
$user = new User();
|
||||
$key = Uuid::uuid4();
|
||||
|
||||
$user->setUsername($username);
|
||||
$user->setLastname($lastname);
|
||||
$user->setFirstname($firstname);
|
||||
$user->setEmail($email);
|
||||
$user->setApiKey($key);
|
||||
|
||||
$user->setPassword("CASPWD-".$username);
|
||||
$user->setSalt("CASPWD-".$username);
|
||||
|
||||
$em->persist($user);
|
||||
$em->flush();
|
||||
}
|
||||
else {
|
||||
if(isset($lastname)) $user->setLastname($lastname);
|
||||
if(isset($firstname)) $user->setFirstname($firstname);
|
||||
if(isset($email)) $user->setEmail($email);
|
||||
|
||||
$em->persist($user);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
// Sauvegarde des attributes en session
|
||||
$this->get('session')->set('attributes', $attributes);
|
||||
|
||||
// Autoconnexion
|
||||
// Récupérer le token de l'utilisateur
|
||||
$token = new UsernamePasswordToken($user, null, "main", $user->getRoles());
|
||||
$this->get("security.token_storage")->setToken($token);
|
||||
|
||||
// Simuler l'evenement de connexion
|
||||
$event = new InteractiveLoginEvent($request, $token);
|
||||
$dispatcher = new EventDispatcher();
|
||||
$dispatcher->dispatch($event);
|
||||
|
||||
// Redirection
|
||||
if($redirect)
|
||||
return $this->redirect($redirect);
|
||||
else
|
||||
return $this->redirect($this->generateUrl('app_home'));
|
||||
}
|
||||
|
||||
public function loginOAUTH() {
|
||||
/*
|
||||
OAUTH_CLIENTID=
|
||||
OAUTH_CLIENTSECRET=
|
||||
OAUTH_LOGINURL=https://forge.cadoles.com/login/oauth/authorize
|
||||
OAUTH_LOGOUTURL=https://forge.cadoles.com/user/logout
|
||||
OAUTH_TOKENURL=https://forge.cadoles.com/login/oauth/access_token
|
||||
*/
|
||||
// https://[YOUR-GITEA-URL]/login/oauth/authorize?client_id=CLIENT_ID&redirect_uri=REDIRECT_URI& response_type=code&state=STATE
|
||||
|
||||
$callback=$this->generateUrl('app_login_callback', array(), UrlGeneratorInterface::ABSOLUTE_URL);
|
||||
$this->get('session')->set('giteacallback', $callback);
|
||||
$url=$this->getParameter("oauthLoginurl")."?client_id=".$this->getParameter("oauthClientid")."&redirect_uri=".$callback."&response_type=code&state=STATE";
|
||||
return $this->redirect($url);
|
||||
}
|
||||
|
||||
public function callback(Request $request) {
|
||||
$this->get('session')->set('giteacode', $request->get("code"));
|
||||
$token=$this->giteaservice->gettoken();
|
||||
|
||||
// Rechercher l'utilisateur associé au token
|
||||
$giteauser=$this->giteaservice->getuser();
|
||||
if(!$giteauser) die("Problème d'accès avec GITEA - no user");
|
||||
|
||||
// Sauvegarde du user gitea en session
|
||||
$this->get('session')->set('giteauser', json_decode(json_encode($giteauser), true));
|
||||
|
||||
// Recherche du user gitea dans ninegitea
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$user = $em->getRepository('App:User')->findOneBy(array("username"=>$giteauser->login));
|
||||
$exists = $user ? true : false;
|
||||
|
||||
if (!$exists) {
|
||||
if(empty($giteauser->email)) $email = $giteauser->login."@nomail.com";
|
||||
|
||||
$user = new User();
|
||||
$key = Uuid::uuid4();
|
||||
|
||||
$user->setUsername($giteauser->login);
|
||||
$user->setEmail($giteauser->email);
|
||||
$user->setApiKey($key);
|
||||
$user->setRoles(["ROLE_USER"]);
|
||||
$user->setAvatar("noavatar.png");
|
||||
|
||||
$user->setPassword("OAUTH-".$giteauser->login);
|
||||
$user->setSalt("OAUTH-".$giteauser->login);
|
||||
|
||||
if(in_array($giteauser->login,$this->getParameter("appAdmins")))
|
||||
$user->setRoles(["ROLE_ADMIN"]);
|
||||
|
||||
$em->persist($user);
|
||||
$em->flush();
|
||||
}
|
||||
else {
|
||||
if(isset($email)) $user->setEmail($giteauser->email);
|
||||
if(in_array($giteauser->login,$this->getParameter("appAdmins")))
|
||||
$user->setRoles(["ROLE_ADMIN"]);
|
||||
|
||||
$em->persist($user);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
// Autoconnexion
|
||||
// Récupérer le token de l'utilisateur
|
||||
$token = new UsernamePasswordToken($user, null, "main", $user->getRoles());
|
||||
$this->get("security.token_storage")->setToken($token);
|
||||
|
||||
// Simuler l'evenement de connexion
|
||||
$event = new InteractiveLoginEvent($request, $token);
|
||||
$dispatcher = new EventDispatcher();
|
||||
$dispatcher->dispatch($event);
|
||||
|
||||
// Redirection
|
||||
$redirect = $this->get('session')->get("_security.main.target_path");
|
||||
if($redirect)
|
||||
return $this->redirect($redirect);
|
||||
else
|
||||
return $this->redirect($this->generateUrl('app_home'));
|
||||
|
||||
}
|
||||
|
||||
public function logout() {
|
||||
$auth_mode=$this->getParameter("appAuth");
|
||||
switch($auth_mode) {
|
||||
case "SQL":
|
||||
return $this->logoutMYSQL();
|
||||
break;
|
||||
|
||||
case "CAS":
|
||||
return $this->logoutCAS();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function logoutMYSQL() {
|
||||
$this->get('security.token_storage')->setToken(null);
|
||||
$this->get('session')->invalidate();
|
||||
|
||||
return $this->redirect($this->generateUrl("app_home"));
|
||||
}
|
||||
|
||||
public function logoutcas() {
|
||||
$this->get('security.token_storage')->setToken(null);
|
||||
$this->get('session')->invalidate();
|
||||
|
||||
// Init Client CAS
|
||||
\phpCAS::client(CAS_VERSION_2_0, $this->getParameter('casHost'), intval($this->getParameter('casPort')), is_null($this->getParameter('casPath')) ? '' : $this->getParameter('casPath'), false);
|
||||
\phpCAS::setNoCasServerValidation();
|
||||
|
||||
|
||||
// Logout
|
||||
$url=$this->generateUrl('app_home', array(), UrlGeneratorInterface::ABSOLUTE_URL);
|
||||
\phpCAS::logout(array("service"=>$url));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function casdebug() {
|
||||
$attributes = $this->get('session')->get('attributes');
|
||||
|
||||
return $this->render('Home/casdebug.html.twig',[
|
||||
"useheader" => true,
|
||||
"usesidebar" => false,
|
||||
"attributes" => $attributes,
|
||||
]);
|
||||
}
|
||||
}
|
43
src/Controller/SondeController.php
Normal file
43
src/Controller/SondeController.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
|
||||
class SondeController extends AbstractController
|
||||
{
|
||||
public function sonde()
|
||||
{
|
||||
// Debug sonde
|
||||
$fgdebug = ($this->getParameter("appEnv")!="PROD");
|
||||
|
||||
// Calcul du login
|
||||
$user=$this->getUser();
|
||||
if($user) $loginsonde=crypt($user->getUsername(),"dkywqZPYNHtWDnSxACjXVcIsFuaiQT");
|
||||
else $loginsonde="";
|
||||
|
||||
// Calcul du profil
|
||||
$profilsonde="visiteur";
|
||||
if($user) {
|
||||
$profilsonde="utilisateur";
|
||||
$attributes=$this->get('session')->get('attributes');
|
||||
if(isset($attributes["ENTPersonProfils"])) $profilsonde=$attributes["ENTPersonProfils"];
|
||||
}
|
||||
|
||||
// Calcul de la provenance
|
||||
$e = explode('.', $_SERVER["REMOTE_ADDR"]);
|
||||
$s = sizeof($e);
|
||||
if(($e[0]=="172"&&$e[1]=="30")||($e[0]=="172"&&$e[1]=="16")||($e[0]=="10"&&($e[1]=="77"||$e[1]=="93"||$e[1]=="94")))
|
||||
$provenancesonde='interne';
|
||||
else
|
||||
$provenancesonde='externe';
|
||||
|
||||
$url=$this->getParameter("sondeUrl");
|
||||
$app=$this->getParameter("appName");
|
||||
$urlsonde = $url."?appli=$app&profil=$profilsonde&login=$loginsonde&provenance=$provenancesonde&fgdebug=$fgdebug";
|
||||
|
||||
return $this->render('Sonde/sonde.html.twig',['urlsonde' => $urlsonde]);
|
||||
}
|
||||
|
||||
|
||||
}
|
67
src/Controller/ThemeController.php
Normal file
67
src/Controller/ThemeController.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?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 Symfony\Component\Finder\Finder;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
use App\Entity\Config as Entity;
|
||||
use App\Form\ConfigType as Form;
|
||||
|
||||
class ThemeController extends AbstractController
|
||||
{
|
||||
private $data = "config";
|
||||
private $route = "app_config";
|
||||
private $render = "Config/";
|
||||
private $entity = "App:Config";
|
||||
|
||||
public function list(Request $request)
|
||||
{
|
||||
$session=$this->get('session');
|
||||
$finder = new Finder();
|
||||
|
||||
$dir = $this->getParameter('kernel.project_dir')."/public/themes";
|
||||
$url=$this->getParameter('appAlias')."themes";
|
||||
|
||||
$finder->in($dir)->directories()->depth('== 0');
|
||||
$themes=[];
|
||||
$themes[""]["dir"]="";
|
||||
$themes[""]["url"]=$url;
|
||||
$themes[""]["name"]="Thème par défaut";
|
||||
|
||||
foreach ($finder as $file) {
|
||||
$key=$file->getRelativePathname();
|
||||
$themes[$key]["dir"]=$key;
|
||||
$themes[$key]["url"]=$url."/".$key;
|
||||
|
||||
$yml=Yaml::parseFile($dir.'/'.$key.'/info.yml');
|
||||
$themes[$key]["name"]=$yml["name"];
|
||||
}
|
||||
|
||||
$current=$session->get("apptheme");
|
||||
$currentheme=$themes[$current];
|
||||
unset($themes[$current]);
|
||||
|
||||
return $this->render('Theme/list.html.twig',[
|
||||
'useheader' => true,
|
||||
'usesidebar' => true,
|
||||
'currentheme' => $currentheme,
|
||||
'themes' => $themes
|
||||
]);
|
||||
}
|
||||
|
||||
public function select(Request $request,$name)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$config=$em->getRepository("App:Config")->findoneBy(["id"=>"apptheme"]);
|
||||
$config->setValue($name);
|
||||
|
||||
$em->persist($config);
|
||||
$em->flush();
|
||||
|
||||
return $this->redirectToRoute("app_theme");
|
||||
}
|
||||
}
|
224
src/Controller/UserController.php
Executable file
224
src/Controller/UserController.php
Executable file
@ -0,0 +1,224 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
use App\Entity\User as Entity;
|
||||
use App\Form\UserType as Form;
|
||||
|
||||
class UserController extends AbstractController
|
||||
{
|
||||
private $data = "user";
|
||||
private $route = "app_user";
|
||||
private $render = "User/";
|
||||
private $entity = "App:User";
|
||||
|
||||
public function list(Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$datas = $em->getRepository($this->entity)->findAll();
|
||||
|
||||
return $this->render($this->render.'list.html.twig',[
|
||||
$this->data."s" => $datas,
|
||||
"useheader" => true,
|
||||
"usesidebar" => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function update($id,Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
$oldpassword=$data->getPassword();
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"update"));
|
||||
|
||||
// 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();
|
||||
|
||||
// Si pas de changement de password on replace l'ancien
|
||||
if(!$data->getPassword()) {
|
||||
$data->setPassword($oldpassword);
|
||||
}
|
||||
|
||||
$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' => true,
|
||||
$this->data => $data,
|
||||
'mode' => 'update',
|
||||
'form' => $form->createView()
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete($id,Request $request)
|
||||
{
|
||||
// Uniquement possible si appMasteridentity = SQL
|
||||
if($this->getParameter("appMasteridentity") != "SQL") return $this->redirectToRoute($this->route);
|
||||
|
||||
// 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 profil(Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data=$this->getUser();
|
||||
$oldpassword=$data->getPassword();
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"profil"));
|
||||
|
||||
// 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();
|
||||
|
||||
// Si pas de changement de password on replace l'ancien
|
||||
if(!$data->getPassword()) {
|
||||
$data->setPassword($oldpassword);
|
||||
}
|
||||
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->redirectToRoute("app_home");
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'edit.html.twig', [
|
||||
'useheader' => true,
|
||||
'usesidebar' => false,
|
||||
'maxwidth' => true,
|
||||
$this->data => $data,
|
||||
'mode' => 'profil',
|
||||
'form' => $form->createView()
|
||||
]);
|
||||
}
|
||||
|
||||
public function select(Request $request)
|
||||
{
|
||||
// S'assurer que c'est un appel ajax
|
||||
if (!$request->isXmlHttpRequest()) {
|
||||
return new JsonResponse(array('message' => 'Interdit'), 400);
|
||||
}
|
||||
|
||||
$output=array();
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$page_limit=$request->query->get('page_limit');
|
||||
$q=$request->query->get('q');
|
||||
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb->select('table')->from($this->entity,'table')
|
||||
->where('table.username LIKE :value')
|
||||
->setParameter("value", "%".$q."%")
|
||||
->orderBy('table.username');
|
||||
|
||||
$datas=$qb->setFirstResult(0)->setMaxResults($page_limit)->getQuery()->getResult();
|
||||
foreach($datas as $data) {
|
||||
array_push($output,array("id"=>$data->getId(),"text"=>$data->getUsername()));
|
||||
}
|
||||
|
||||
$ret_string["results"]=$output;
|
||||
$response = new Response(json_encode($ret_string));
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function info(Request $request)
|
||||
{
|
||||
// S'assurer que c'est un appel ajax
|
||||
if (!$request->isXmlHttpRequest()) {
|
||||
return new JsonResponse(array('message' => 'Interdit'), 400);
|
||||
}
|
||||
|
||||
$output=array();
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$id=$request->get('id');
|
||||
|
||||
$user=$em->getRepository($this->entity)->find($id);
|
||||
$output=[];
|
||||
$output["id"] = $user->getId();
|
||||
$output["displayname"] = $user->getDisplayname();
|
||||
$output["email"] = $user->getEmail();
|
||||
|
||||
$response = new Response(json_encode($output));
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function preference(Request $request)
|
||||
{
|
||||
// S'assurer que c'est un appel ajax
|
||||
if (!$request->isXmlHttpRequest()) {
|
||||
return new JsonResponse(array('message' => 'Interdit'), 400);
|
||||
}
|
||||
|
||||
$key=$request->request->get('key');
|
||||
$id=$request->request->get('id');
|
||||
$value=$request->request->get('value');
|
||||
|
||||
$this->getDoctrine()->getManager()->getRepository("App:User")->setUserpreference($this->getUser(),$key,$id,$value);
|
||||
|
||||
return new Response();
|
||||
}
|
||||
|
||||
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() && !$form->isValid()) {
|
||||
$this->get('session')->getFlashBag()->clear();
|
||||
|
||||
$errors = $form->getErrors();
|
||||
foreach( $errors as $error ) {
|
||||
$request->getSession()->getFlashBag()->add("error", $error->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
13
src/Controller/WebsocketController.php
Normal file
13
src/Controller/WebsocketController.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
|
||||
class WebsocketController extends AbstractController
|
||||
{
|
||||
public function sample()
|
||||
{
|
||||
return $this->render('Websocket/sample.html.twig');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user