<?php
namespace App\Controller\Projets;
use App\Entity\Notes\Categorie;
use App\Entity\Notes\Note;
use App\Entity\Projets\Etat;
use App\Entity\Projets\Priorite;
use App\Entity\Projets\Projet;
use App\Entity\Projets\Reference;
use App\Entity\Projets\Tache;
use App\Entity\Utilisateur\Contact;
use App\Entity\Utilisateur\Utilisateur;
use App\Form\Projets\SupprimerTacheType;
use App\Form\Projets\TacheType;
use App\Library\Datatable\Util\Datatable;
use App\Security\Voter\EntityVoter;
use App\Service\FO\Mailer;
use App\Service\Utilisateur\ColonneTableauService;
use Doctrine\ORM\EntityManagerInterface;
use JMS\Serializer\SerializerBuilder;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class TacheController extends AbstractController
{
/**
* @Route("", name="")
*/
public function agendaTacheAction(Request $request, $param = [], EntityManagerInterface $em)
{
//print_r($param);
$user = $this->getUser();
$get = $request->query->all();
$repo_categories_note = $em->getRepository(Categorie::class);
$categories = $repo_categories_note->findAll();
$date = new \Datetime();
$semaine = $date->format("W");
$repo_user = $em->getRepository(Utilisateur::class);
if (array_key_exists('equipiers', $param)) {
$equipiers = $repo_user->findBy(["id" => $param["equipiers"]]);
} else {
$equipiers = $repo_user->findAll();
}
//print_r($param);
return $this->render('Projets/Tache/agenda_tache_2.html.twig', ["parametres" => $param, "equipiers" => $equipiers, "semaine" => $semaine, "categories" => $categories]);
}
/**
* @Route("/tache/ajax/detail/{id}", name="dtc_tache_detail_ajax")
*/
public function detailAction(Request $request, Tache $tache)
{
$rendu = $this->renderView('Projets/Tache/detail_datatable.html.twig', ['tache' => $tache]);
return new JsonResponse(['rendu' => $rendu,]);
}
/**
* @Route("/tache/ajax/detail-interventions/{id}", name="dtc_tache_detail_interventions_ajax")
*/
public function detailInterventionsAction(Request $request, Tache $tache)
{
$rendu = $this->renderView('Projets/Tache/detail_interventions_datatable.html.twig', ['tache' => $tache]);
return new JsonResponse(['rendu' => $rendu,]);
}
/**
* @Route("/tache/ajax/sous-tache/{id}", name="dtc_tache_sous_tache_ajax")
*/
public function sousTacheAction(Request $request, Tache $tache)
{
$rendu = $this->renderView('Projets/Tache/sous_taches_datatable.html.twig', ['tache' => $tache]);
return new JsonResponse(['rendu' => $rendu,]);
}
/**
* @Route("/projet/tache/modal/nouveau", name="dtc_tache_ajouter_modal")
*/
public function ajouterModalAction(Request $request, EntityManagerInterface $em, TranslatorInterface $translator, ValidatorInterface $validator, Mailer $emailService)
{
$titre_modal = $translator->trans("Nouvelle tâche");
$user = $this->getUser();
$get = $request->query->all();
$idProjet = $request->query->get('projet');
$parentId = $request->query->get('parentId');
$type = $request->query->get('type');
if ($type == '') {
$type = 'tache';
}
$url = '#';
$url = $this->generateUrl('dtc_tache_liste', []);
$url = '';
$tache = new Tache;
if (array_key_exists('sujet', $get)) {
$tache->setLibelle($get["sujet"]);
}
/*
if (array_key_exists('contenu', $get)) {
$tache->setDescription($get["contenu"]);
}
*/
$tache->setUtilisateur($user);
$tache->setUtilisateur($user);
$tache->setResponsableInterne($user);
$tache->setRapporteurInterne($user);
if ($parentId != "") {
$parent = $em->getRepository(Tache::class)->find($parentId);
if (is_object($parent)) {
$tache->setParent($parent);
$tache->setProjet($parent->getProjet());
$url = $this->generateUrl('dtc_tache_modifier', ['id' => $parentId, 'tab' => "sousTaches"]);
}
}
if ($idProjet != "") {
$repo_projet = $em->getRepository(Projet::class);
$projet_objet = $repo_projet->find($idProjet);
if (is_object($projet_objet)) {
$tache->setProjet($projet_objet);
$url = $this->generateUrl('dtc_projet_modifier', ['id' => $idProjet, 'tab' => "taches"]);
}
}
if (array_key_exists('redirection', $get)) {
$url = $get["redirection"];
}
$form = $this->createForm(TacheType::class, $tache);
$errorsSup = [];
$errors = [];
$libelle = "";
$form->handleRequest($request);
if ($form->isSubmitted()) {
if ($form->isValid()) {
$em->persist($tache);
$em->flush();
if ($type == 'gantt') {
if (is_object($tache->getDateDebutRecalee())) {
$startDate = $tache->getDateDebutRecalee();
} else {
$startDate = $tache->getDateDebutPrevue();
}
if (is_object($tache->getParent())) {
$parent = $tache->getParent()->getId();
} else {
$parent = '';
}
$task = [];
if (is_object($startDate)) {
$task = [
'id' => $tache->getId(),
'text' => $tache->getLibelle(),
'start_date' => $startDate->format('d-m-Y H:i'),
'duration' => $tache->getNbHeuresAlloues(),
];
}
return new JsonResponse(
[
'rendu' => '',
'valide' => '1',
'url' => '',
'type' => $type,
'task' => $task,
'parent' => $parent
// 'libelle'=>$libelle,
// 'id_tache'=>$tache->getId()
],
200,
['Content-Type' => 'application/json']
);
} else {
if (is_object($tache->setResponsableInterne()) && $tache->setResponsableInterne()->getId() != $user->getId()) {
$em->refresh($tache);
$emailService->sendMailNouvelleTache($tache, $user);
} else {
}
return new JsonResponse(
['rendu' => '', 'valide' => '1', 'url' => $url, 'type' => $type, 'libelle' => $libelle, 'id_tache' => $tache->getId()]
);
}
} else {
$errors = $validator->validate($tache);
$rendu = $this->renderView(
'Projets/Tache/ajouter_modal.html.twig',
['form' => $form->createView(), 'errors' => $errors, 'errorsSup' => $errorsSup, 'tache' => $tache]
);
return new JsonResponse(['rendu' => $rendu, 'valide' => '0', 'url' => '', 'titre' => $titre_modal]);
}
} else {
}
$url = $this->generateUrl('dtc_tache_ajouter_modal', [
'projet' => $idProjet,
'parentId' => $parentId,
'type' => $type,
]);
$rendu = $this->renderView('Projets/Tache/ajouter_modal.html.twig', ['form' => $form->createView(), 'errors' => $errors, 'errorsSup' => $errorsSup, 'tache' => $tache]);
return new JsonResponse(['rendu' => $rendu, 'valide' => '0', 'url' => $url, 'titre' => $titre_modal]);
}
/**
* @Route("/projet/tache/nouveau", name="dtc_tache_ajouter")
*/
public function ajouterAction(Request $request, EntityManagerInterface $em, ValidatorInterface $validator)
{
$user = $this->getUser();
$tache = new Tache;
$tache->setUtilisateur($user);
//$tache->setUtilisateur($user);
//$form = $this->createForm(new TacheType, $tache);
$form = $this->createForm(TacheType::class, $tache);
$errors = "";
$form->handleRequest($request);
if ($form->isSubmitted()) {
if ($form->isValid()) {
$em->persist($tache);
$em->flush();
$this->addFlash(
'notice',
'Tache ajoutée avec succès !'
);
return $this->redirectToRoute('dtc_tache_liste');
} else {
$errors = $validator->validate($tache);
}
}
return $this->render('Projets/Tache/ajouter.html.twig', ['form' => $form->createView(), 'errors' => $errors]);
}
/**
* @Route("/projet/tache/modifier/{id}", name="dtc_tache_modifier")
*/
public function modifierAction(Request $request, Tache $tache, EntityManagerInterface $em, ValidatorInterface $validator, Mailer $emailService,
Datatable $datatable, TranslatorInterface $translator
) {
$user = $this->getUser();
$tache->setUtilisateur($user);
//$tache->setUtilisateur($user);
//$form = $this->createForm(new TacheType, $tache);
$get = $request->query->all();
if (array_key_exists('t', $get) && $get["t"] == 1) {
$repo_etat = $em->getRepository(Etat::class);
$etatTerminee = $repo_etat->find(4);
$dateJour = new \Datetime();
$tache->setEtat($etatTerminee);
$tache->setDateFinReelle($dateJour);
$tache->setPourcentage("100");
$em->persist($tache);
$em->flush();
$this->addFlash(
'notice',
'Tache marquée comme terminée réalisée avec succès !'
);
return $this->redirectToRoute('dtc_tache_modifier', ["id" => $tache->getId()]);
} elseif (array_key_exists('t', $get) && $get["t"] == 0) {
$repo_etat = $em->getRepository(Etat::class);
$etatEnCours = $repo_etat->find(3);
$dateJour = new \Datetime();
$tache->setEtat($etatEnCours);
$tache->setDateFinReelle(null);
//$tache->setPourcentage("100");
$em->persist($tache);
$em->flush();
$this->addFlash(
'notice',
'Tache marquée comme non terminée réalisée avec succès !'
);
return $this->redirectToRoute('dtc_tache_modifier', ["id" => $tache->getId()]);
}
$form = $this->createForm(TacheType::class, $tache);
$errors = "";
$form->handleRequest($request);
if ($form->isSubmitted()) {
$droit = $this->isGranted(EntityVoter::UPDATE, Tache::class);
if ( ! $droit) {
$em->refresh($tache);
return $this->redirectToRoute('dtc_tache_modifier', ["id" => $tache->getId()]);
}
if ($form->isValid()) {
if (is_object($tache->getEtat()) && $tache->getEtat()->getDernierEtat() && ! is_object($tache->getDateFinReelle())) {
$tache->setDateFinReelle(new \Datetime);
}
$em->persist($tache);
$em->flush();
$this->addFlash(
'notice',
'Tache modifiée avec succès !'
);
$emailService->sendMailModificationTache($tache, $user);
return $this->redirectToRoute('dtc_tache_modifier', ["id" => $tache->getId()]);
} else {
$errors = $validator->validate($tache);
}
}
$this->datatableInterventions($datatable, $translator, "tache", $tache);
return $this->render('Projets/Tache/ajouter.html.twig', ['form' => $form->createView(), 'errors' => $errors, 'tache' => $tache]);
}
/**
* @Route("/projet/tache/modal/modifier/{id}", name="dtc_tache_modifier_modal")
*/
public function modifierModalAction(Request $request, Tache $tache, EntityManagerInterface $em, TranslatorInterface $translator,
ValidatorInterface $validator, Mailer $emailService, Datatable $datatable
) {
$titre_modal = $translator->trans("Modifier la tâche");
$errorsSup = null;
$user = $this->getUser();
$tache->setUtilisateur($user);
$type = $request->query->get('type');
if ($type == '') {
$type = 'tache';
}
$get = $request->query->all();
$url = '#';
$url = $this->generateUrl('dtc_tache_liste', []);
if (array_key_exists('t', $get) && $get["t"] == 1) {
$repo_etat = $em->getRepository(Etat::class);
$etatTerminee = $repo_etat->find(4);
$dateJour = new \Datetime();
$tache->setEtat($etatTerminee);
$tache->setDateFinReelle($dateJour);
$tache->setPourcentage("100");
$em->persist($tache);
$em->flush();
$this->addFlash(
'notice',
'Tache marquée comme terminée réalisé avec succès !'
);
return $this->redirectToRoute('dtc_tache_modifier', ["id" => $tache->getId()]);
} elseif (array_key_exists('t', $get) && $get["t"] == 0) {
$repo_etat = $em->getRepository(Etat::class);
$etatEnCours = $repo_etat->find(3);
$dateJour = new \Datetime();
$tache->setEtat($etatEnCours);
$tache->setDateFinReelle(null);
//$tache->setPourcentage("100");
$em->persist($tache);
$em->flush();
$this->addFlash(
'notice',
'Tache marquée comme non terminée réalisé avec succès !'
);
return $this->redirectToRoute('dtc_tache_modifier', ["id" => $tache->getId()]);
}
$form = $this->createForm(TacheType::class, $tache);
$errors = "";
$form->handleRequest($request);
if ($form->isSubmitted()) {
$droit = $this->isGranted(EntityVoter::UPDATE, Tache::class);
if ( ! $droit) {
//return $this->redirectToRoute('dtc_tache_modifier_modal',array("id"=>$tache->getId()));
}
if ($form->isValid()) {
$em->persist($tache);
$em->flush();
/*
$this->addFlash(
'notice',
'Tache modifiée avec succès !'
);
*/
$emailService->sendMailModificationTache($tache, $user);
if ($type == 'gantt') {
if (is_object($tache->getDateDebutRecalee())) {
$startDate = $tache->getDateDebutRecalee();
} else {
$startDate = $tache->getDateDebutPrevue();
}
if (is_object($tache->getParent())) {
$parent = $tache->getParent()->getId();
} else {
$parent = '';
}
$task = [];
if (is_object($startDate)) {
$urlTmp = $this->generateUrl('dtc_tache_modifier_modal', ['id' => $tache->getId(), 'type' => 'gantt']);
$task = [
'id' => $tache->getId(),
//'text' => $tache->getLibelle(),
'text' => '<a class="open-modal-form" data-target="#blocModal" data-toggle="modal" data-link="'.$urlTmp.'" data-width="1100">'.$tache->getLibelle().'</a>',
'start_date' => $startDate->format('d-m-Y H:i'),
//'duration' => $tache->getNbHeuresAlloues(),
'duration' => $tache->getDuration(),
];
}
return new JsonResponse(
[
'rendu' => '',
'valide' => '1',
'url' => '',
'type' => $type,
'task' => $task,
'parent' => $parent
// 'libelle'=>$libelle,
// 'id_tache'=>$tache->getId()
]
);
} else {
if (is_object($tache->setResponsableInterne()) && $tache->setResponsableInterne()->getId() != $user->getId()) {
$em->refresh($tache);
$emailService->sendMailNouvelleTache($tache, $user);
} else {
}
return new JsonResponse(
[
'rendu' => '',
'valide' => '1',
'url' => $url,
'type' => $type,
//'libelle'=>$libelle,
'id_tache' => $tache->getId(),
]
);
}
} else {
$errors = $validator->validate($tache);
$rendu = $this->renderView(
'Projets/Tache/ajouter_modal.html.twig',
['form' => $form->createView(), 'errors' => $errors, 'errorsSup' => $errorsSup, 'tache' => $tache]
);
return new JsonResponse(['rendu' => $rendu, 'valide' => '0', 'url' => '', 'titre' => $titre_modal]);
}
}
$this->datatableInterventions($datatable, $translator, "tache", $tache);
//return $this->render('Projets/Tache/ajouter.html.twig', array('form' => $form->createView(),'errors'=>$errors,'tache'=>$tache));
/*
$url = $this->generateUrl('dtc_tache_modifier_modal', array(
'projet'=>$idProjet,
'parentId'=>$parentId,
'type'=>$type
));
*
*/
$rendu = $this->renderView('Projets/Tache/ajouter_modal.html.twig', ['form' => $form->createView(), 'errors' => $errors, 'errorsSup' => $errorsSup, 'tache' => $tache]);
return new JsonResponse(['rendu' => $rendu, 'valide' => '0', 'url' => '', 'titre' => $titre_modal]);
}
/**
* @Route("/mon-activite", name="dtc_tache_liste")
*/
public function listerAction(Request $request, $projetId = '', $parentId = '', $parametres = [], EntityManagerInterface $em, ColonneTableauService $serviceColonneTableau,
Datatable $datatable, TranslatorInterface $translator
) {
$param = $request->query->all();
$tableau_class_cellule[] = ["className" => "colonne_id", "targets" => [0], "visible" => false, "orderable" => false];
$tableau_class_cellule[] = ["className" => "colonne_id", "targets" => [1], "visible" => $serviceColonneTableau->getColonneUtilisateur(Tache::class, "id")];
$tableau_class_cellule[] = ["className" => "colonne_id", "targets" => [2], "visible" => $serviceColonneTableau->getColonneUtilisateur(Tache::class, "libelle")];
$tableau_class_cellule[] = ["className" => "colonne_id", "targets" => [3], "visible" => $serviceColonneTableau->getColonneUtilisateur(Tache::class, "projet")];
$tableau_class_cellule[] = ["className" => "colonne_id", "targets" => [4], "visible" => $serviceColonneTableau->getColonneUtilisateur(Tache::class, "date")];
$tableau_class_cellule[] = [
"className" => "colonne_id",
"targets" => [5],
"visible" => $serviceColonneTableau->getColonneUtilisateur(Tache::class, "dateDebutPrevue"),
];
$tableau_class_cellule[] = [
"className" => "colonne_id",
"targets" => [6],
"visible" => $serviceColonneTableau->getColonneUtilisateur(Tache::class, "dateFinPrevue"),
];
$tableau_class_cellule[] = [
"className" => "colonne_id",
"targets" => [7],
"visible" => $serviceColonneTableau->getColonneUtilisateur(Tache::class, "dateFinReelle"),
];
$tableau_class_cellule[] = [
"className" => "colonne_id",
"targets" => [8],
"visible" => $serviceColonneTableau->getColonneUtilisateur(Tache::class, "heuresAllouees"),
];
$tableau_class_cellule[] = ["className" => "colonne_id", "targets" => [9], "visible" => $serviceColonneTableau->getColonneUtilisateur(Tache::class, "etat")];
$tableau_class_cellule[] = [
"className" => "colonne_id",
"targets" => [10],
"visible" => $serviceColonneTableau->getColonneUtilisateur(Tache::class, "origine"),
];
$tableau_class_cellule[] = [
"className" => "colonne_id",
"targets" => [11],
"visible" => $serviceColonneTableau->getColonneUtilisateur(Tache::class, "priorite"),
];
$tableau_class_cellule[] = [
"className" => "colonne_id",
"targets" => [12],
"visible" => $serviceColonneTableau->getColonneUtilisateur(Tache::class, "avancement"),
];
$tableau_class_cellule[] = ["className" => "colonne_id", "targets" => [13], "visible" => $serviceColonneTableau->getColonneUtilisateur(Tache::class, "rapint")];
$tableau_class_cellule[] = [
"className" => "colonne_id",
"targets" => [14],
"visible" => $serviceColonneTableau->getColonneUtilisateur(Tache::class, "rapclient"),
];
$tableau_class_cellule[] = [
"className" => "colonne_id",
"targets" => [15],
"visible" => $serviceColonneTableau->getColonneUtilisateur(Tache::class, "respint"),
];
$tableau_class_cellule[] = [
"className" => "colonne_id",
"targets" => [16],
"visible" => $serviceColonneTableau->getColonneUtilisateur(Tache::class, "respclient"),
];
//$tableau_class_cellule[]=array("className"=>"colonne_id","targets"=>array(15),"visible"=>$serviceColonneTableau->getColonneUtilisateur(Tache::class,"dateLivraisonRelle"));
$repo_user = $em->getRepository(Utilisateur::class);
$repo_etat = $em->getRepository(Etat::class);
$equipiers = $repo_user->findAll();
$etats = $repo_etat->findAll();
$user = $this->getUser();
$param = $request->query->all();
$param = array_merge($param, $parametres);
if (array_key_exists('equipiers', $param)) {
$choix_equipiers = $param["equipiers"];
} elseif ($projetId != '' || $parentId != '') {
$choix_equipiers = [];
$param["equipiers"] = [];
} else {
$choix_equipiers = [$user->getId()];
$param["equipiers"] = $choix_equipiers;
}
//$choix_equipiers = array();
//$param["equipiers"] = array();
if (array_key_exists('filtre-etat', $param)) {
$choix_etats = $param["filtre-etat"];
} else {
//$choix_etats = array("1","2","3");
$choix_etats = ["1"];//en attente noogaa
$param["filtre-etat"] = $choix_etats;
$param["filtre-etat-masquer"] = true;
}
$this->datatable($request, $datatable, $translator, $projetId, $parentId);
$respExt = [];
if ($projetId != '') {
//$respExt = $em->getRepository('DTCUtilisateurBundle:Contact')->getContactByProjet($projetId);
$respExt = $em->getRepository(Contact::class)->getContactByClientProjet($projetId);
//var_dump('test');
//var_dump($respExt);
}
if ($parentId != '') {
$tacheTmp = $em->getRepository(Tache::class)->find($parentId);
if (is_object($tacheTmp) && is_object($tacheTmp->getProjet())) {
//$respExt = $em->getRepository('DTCUtilisateurBundle:Contact')->getContactByProjet($tacheTmp->getProjet()->getId());
$respExt = $em->getRepository(Contact::class)->getContactByClientProjet($tacheTmp->getProjet()->getId());
}
}
//$respExt = $em->getRepository('DTCUtilisateurBundle:Contact')->findAll();
//$rapExt = $em->getRepository('DTCUtilisateurBundle:Utilisateur')->findAll();
if ($parentId == '' && $projetId == '') {
return $this->render('Projets/Tache/lister.html.twig', [
'choix_etats' => $choix_etats,
'etats' => $etats,
'parametres' => $param,
"choix_equipiers" => $choix_equipiers,
"equipiers" => $equipiers,
'tableauClassColonne' => $tableau_class_cellule,
'parentId' => $parentId,
'projetId' => $projetId,
'filtres' => [
[
'titre' => 'Etat',
'entity' => 'etat',
'entities' => $em->getRepository(Etat::class)->findAll(),
],
[
'titre' => 'Origine',
'entity' => 'origine',
'entities' => $em->getRepository(Reference::class)->findAll(),
],
[
'titre' => 'Priorité',
'entity' => 'priorite',
'entities' => $em->getRepository(Priorite::class)->findAll(),
],
[
'titre' => 'Rap int',
'entity' => 'rapporteurInterne',
'entities' => $em->getRepository(Utilisateur::class)->findAll(),
],
[
'titre' => 'Rap client',
'entity' => 'rapporteurExterne',
'entities' => $respExt,
],
[
'titre' => 'Resp int',
'entity' => 'responsableInterne',
'entities' => $em->getRepository(Utilisateur::class)->findAll(),
],
[
'titre' => 'Resp client',
'entity' => 'responsableExterne',
'entities' => $respExt,
]
/*
'Etat' => $em->getRepository('DTCProjetsBundle:Etat')->findAll(),
'Origine' => $em->getRepository('DTCProjetsBundle:Reference')->findAll(),
'Priorité' => $em->getRepository('DTCProjetsBundle:Priorite')->findAll(),
*
*/
],
]);
} else {
return $this->render('Projets/Tache/datatable.html.twig', [
'choix_etats' => $choix_etats,
'etats' => $etats,
'parametres' => $param,
"choix_equipiers" => $choix_equipiers,
"equipiers" => $equipiers,
'tableauClassColonne' => $tableau_class_cellule,
'parentId' => $parentId,
'projetId' => $projetId,
'filtres' => [
[
'titre' => 'Etat',
'entity' => 'etat',
'entities' => $em->getRepository(Etat::class)->findAll(),
],
[
'titre' => 'Origine',
'entity' => 'origine',
'entities' => $em->getRepository(Reference::class)->findAll(),
],
[
'titre' => 'Priorité',
'entity' => 'priorite',
'entities' => $em->getRepository(Priorite::class)->findAll(),
],
/*
array(
'titre' => 'Equipier',
'entity' => 'equipier',
'entities' => $em->getRepository('DTCUtilisateurBundle:Utilisateur')->findAll()
)
*
*/
[
'titre' => 'Rap int',
'entity' => 'rapporteurInterne',
'entities' => $em->getRepository(Utilisateur::class)->findAll(),
],
[
'titre' => 'Rap ext',
'entity' => 'rapporteurExterne',
'entities' => $respExt,
],
[
'titre' => 'Resp int',
'entity' => 'responsableInterne',
'entities' => $em->getRepository(Utilisateur::class)->findAll(),
],
[
'titre' => 'Resp ext',
'entity' => 'responsableExterne',
'entities' => $respExt,
],
],
]);
}
}
/**
* set datatable configs
*
* @return \App\Library\Datatable\Util\Datatable
*/
private function datatable(Request $request, Datatable $datatable, TranslatorInterface $translator, $projetId = '', $parentId = '')//, $parametres=array())
{
$param = $request->query->all();
//$param = array_merge($param, $parametres);
$user = $this->getUser();
//print_r($param);
$choix_equipiers = [];
if (array_key_exists('equipiers', $param) && count($param["equipiers"])) {
$choix_equipiers[] = $param["equipiers"];
} elseif ($projetId != '' or $parentId != '') {
//afficher tous les equipiers par défaut
} else {
$choix_equipiers[] = $user->getId();
}
//var_dump($choix_equipiers);
$datatable->setEntity(Tache::class, "x")
->setFields(
[
"ID" => 'x.id',
$translator->trans("Libellé") => 'x.libelle',
$translator->trans("Projet") => 'p.libelle',
$translator->trans("Date de création") => 'x.date',
$translator->trans("Date début prévue") => 'x.dateDebutPrevue',
$translator->trans("Date fin") => 'x.dateFinPrevue',
$translator->trans("Date de fin réelle") => 'x.dateFinReelle',
$translator->trans("nb heures allouées") => 'x.nbHeuresAlloues',
$translator->trans("nb heures réalisées") => 'x.id',
$translator->trans("Etat") => 'e.libelle',
$translator->trans("Origine") => 'r.libelle',
//$translator->trans("Réf") => 'r.libelle',
$translator->trans("Priorité") => 'pr.libelle',
$translator->trans("Avancement") => 'x.pourcentage',
$translator->trans("Rap int") => 'ri.reference',
$translator->trans("Rap client") => 're.nom',
$translator->trans("Resp int") => 'rsi.reference',
$translator->trans("Resp client") => 'rse.nom',
//$translator->trans("Date Mail") => 'x.dateMail',
//$translator->trans("Fin Prévue") => 'x.dateFinPrevue',
//$translator->trans("Fin Réelle") => 'x.dateFinReelle',
"Actions" => 'x.id',
"_identifier_" => 'x.id',
]
)
->addJoin('x.etat', 'e', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
->addJoin('x.reference', 'r', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
->addJoin('x.projet', 'p', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
->addJoin('x.priorite', 'pr', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
->addJoin('x.rapporteurInterne', 'ri', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
->addJoin('x.rapporteurExterne', 're', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
->addJoin('x.responsableInterne', 'rsi', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
->addJoin('x.responsableExterne', 'rse', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
->setRenderers(
[
0 => [
'view' => 'FO/DataTable/avec_lien_edit_route.html.twig',
'params' => [
'edit_route' => 'dtc_tache_modifier',
],
],
1 => [
'view' => 'FO/DataTable/avec_lien_edit_route.html.twig',
'params' => [
'edit_route' => 'dtc_tache_modifier',
//'deplierSousTache' => true,
'filAriane' => 'parent',
],
],
2 => [
'view' => 'FO/DataTable/avec_lien_edit_route.html.twig',
'params' => [
'edit_route' => 'dtc_projet_modifier',
'typeDocument' => 'Projet',
],
],
3 => [
'view' => 'FO/DataTable/heure.html.twig',
],
4 => [
'view' => 'FO/DataTable/heure.html.twig',
],
5 => [
'view' => 'FO/DataTable/heure.html.twig',
],
6 => [
'view' => 'FO/DataTable/heure.html.twig',
],
8 => [
'view' => 'FO/DataTable/nb_heures_realisees_taches.html.twig',
],
9 => [
'view' => 'FO/DataTable/etat_projet.html.twig',
],
10 => [
'view' => 'FO/DataTable/reference_projet.html.twig',
],
11 => [
'view' => 'FO/DataTable/priorite_projet.html.twig',
],
12 => [
'view' => 'FO/DataTable/progress.html.twig',
],
13 => [
'view' => 'FO/DataTable/utilisateur.html.twig',
'params' => [],
],
14 => [
'view' => 'FO/DataTable/contact.html.twig',
'params' => [
'rapporteurExterne' => true,
],
],
15 => [
'view' => 'FO/DataTable/utilisateur_2.html.twig',
'params' => [
"type" => "responsableInterne",
],
],
16 => [
'view' => 'FO/DataTable/contact.html.twig',
'params' => [
'responsableExterne' => true,
],
],
/*
7 => array(
'view' => 'FO/DataTable/edit_texte.html.twig',
'params' => array(
'objet' => 'DTCProjetsBundle:Tache',
'champ' => 'setPourcentage',
),
),
*
*/
17 => [
'view' => 'FO/DataTable/actions_modal.html.twig',
'params' => [
//'edit_route' => 'dtc_tache_modifier',
'edit_route' => 'dtc_tache_modifier_modal',
'width_modal' => '1100',
'objet' => Tache::class,
'supprimer_route' => 'dtc_tache_supprimer',
'type' => 'projet',
//'deplierSousTache' => true,
'deplierTacheInterventions' => true,
'addTacheIntervention' => true,
],
],
]
)
//->setOrder("x.id", "desc")
//->setOrder("x.dateFinPrevue", "desc")
//->setOrder("x.dateDebutPrevue", "asc")
//->setOrder(array("x.dateDebutPrevue" => "asc", "pr.id"=>"ASC"))
->setSearch(true)
->setMultiple(
[
'delete' => [
'title' => $translator->trans('Non disponible'),
'route' => 'dtc_tache_liste',
],
]
);
$where = '';
$parameters = [];
if ($projetId != '' or $parentId != '') {
$datatable->setOrder("x.dateFinPrevue asc, pr.id", "asc");
//$datatable->addOrder("pr.id", "ASC");
} else {
$datatable->setOrder("x.dateDebutPrevue", "asc");
}
if (count($choix_equipiers) > 0 && array_key_exists('0', $choix_equipiers)) {
$where .= "x.responsableInterne in (:choix_equipiers) ";
$parameters["choix_equipiers"] = $choix_equipiers[0];
}
if (array_key_exists('parametres', $param)) {
/*
if(array_key_exists('etats', $param["parametres"]) and count($param["parametres"]["etats"]) > 0) {
if($where != "") $where .= " AND ";
$where .= "x.etat in (:choix_etats) ";
$parameters["choix_etats"]=$param["parametres"]["etats"];
}
*/
if (array_key_exists('filtre-etat', $param["parametres"]) and count($param["parametres"]["filtre-etat"]) > 0) {
if ($where != "") {
$where .= " AND ";
}
$where .= "x.etat in (:choix_etat) ";
$parameters["choix_etat"] = $param["parametres"]["filtre-etat"];
}
if (array_key_exists('filtre-origine', $param["parametres"]) and count($param["parametres"]["filtre-origine"]) > 0) {
if ($where != "") {
$where .= " AND ";
}
$where .= "x.reference in (:choix_origine) ";
$parameters["choix_origine"] = $param["parametres"]["filtre-origine"];
}
if (array_key_exists('filtre-priorite', $param["parametres"]) and count($param["parametres"]["filtre-priorite"]) > 0) {
if ($where != "") {
$where .= " AND ";
}
$where .= "x.priorite in (:choix_priorite) ";
$parameters["choix_priorite"] = $param["parametres"]["filtre-priorite"];
}
if (array_key_exists('filtre-responsableInterne', $param["parametres"]) and count($param["parametres"]["filtre-responsableInterne"]) > 0) {
if ($where != "") {
$where .= " AND ";
}
$where .= "x.responsableInterne in (:choix_responsableInterne) ";
$parameters["choix_responsableInterne"] = $param["parametres"]["filtre-responsableInterne"];
}
if (array_key_exists('filtre-responsableExterne', $param["parametres"]) and count($param["parametres"]["filtre-responsableExterne"]) > 0) {
if ($where != "") {
$where .= " AND ";
}
$where .= "x.responsableExterne in (:choix_responsableExterne) ";
$parameters["choix_responsableExterne"] = $param["parametres"]["filtre-responsableExterne"];
}
if (array_key_exists('filtre-rapporteurInterne', $param["parametres"]) and count($param["parametres"]["filtre-rapporteurInterne"]) > 0) {
if ($where != "") {
$where .= " AND ";
}
$where .= "x.rapporteurInterne in (:choix_rapporteurInterne) ";
$parameters["choix_rapporteurInterne"] = $param["parametres"]["filtre-rapporteurInterne"];
}
if (array_key_exists('filtre-rapporteurExterne', $param["parametres"]) and count($param["parametres"]["filtre-rapporteurExterne"]) > 0) {
if ($where != "") {
$where .= " AND ";
}
$where .= "x.rapporteurExterne in (:choix_rapporteurExterne) ";
$parameters["choix_rapporteurExterne"] = $param["parametres"]["filtre-rapporteurExterne"];
}
if (array_key_exists('date_debut', $param["parametres"]) and $param["parametres"]["date_debut"] != "") {
$param["parametres"]["date_debut"] = \DateTime::createFromFormat('d/m/Y', $param["parametres"]["date_debut"]);
$param["parametres"]["date_debut"]->setTime(00, 00, 00);
$parameters["date_debut"] = $param["parametres"]["date_debut"];
if ($where != "") {
$where .= " AND ";
}
$where .= "x.dateDebutPrevue >= :date_debut";
}
if (array_key_exists('date_fin', $param["parametres"]) and $param["parametres"]["date_fin"] != "") {
$param["parametres"]["date_fin"] = \DateTime::createFromFormat('d/m/Y', $param["parametres"]["date_fin"]);
$param["parametres"]["date_fin"]->setTime(23, 59, 59);
$parameters["date_fin"] = $param["parametres"]["date_fin"];
if ($where != "") {
$where .= " AND ";
}
$where .= "x.dateFinPrevue <= :date_fin";
}
}
if ($parentId != '') {
if (trim($where) != '') {
$where .= ' AND ';
}
$where .= 'x.parent = :parentId';
$parameters['parentId'] = $parentId;
} else {
//if(trim($where) != '') $where .= ' AND ';
//$where .= 'x.parent IS NULL';
}
if ($projetId != '') {
if (trim($where) != '') {
$where .= ' AND ';
}
$where .= 'x.projet = :projetId';
$parameters['projetId'] = $projetId;
}
if ($projetId == '' and $parentId == '') {
//Mon activité
if (trim($where) != '') {
$where .= ' AND ';
}
$where .= 'x.nbHeuresAlloues > 0';
}
//echo "<br/><br/>".$where."<br/><br/>";
//print_r($parameters);print_r($where);
if ($where != '') {
$datatable->setWhere($where, $parameters);
}
//$datatable->setSearchFields(array(0,1,2,3,4,5));
return $datatable;
}
/**
* Grid action
* @return Response
*/
/**
* @Route("/projet/tache/grid", name="dtc_tache_liste_grid")
*/
public function gridAction(Request $request, Datatable $datatable, TranslatorInterface $translator)
{
$parentId = $request->query->get('parentId');
$projetId = $request->query->get('projetId');
//$parametres = $request->query->get('parametres');
return $this->datatable($request, $datatable, $translator, $projetId, $parentId)->execute();
}
/**
* Grid action
* @return Response
*/
/**
* @Route("", name="")
*/
public function gridInterventionsAction(Request $request, $id, EntityManagerInterface $em, Datatable $datatable, TranslatorInterface $translator)
{
$type = $request->query->get('type');
if ($type == "projet") {
$repo = $em->getRepository(Projet::class);
$objet = $repo->find($id);
} else {
$repo = $em->getRepository(Tache::class);
$objet = $repo->find($id);
}
//echo "TYPE==>".$type;
return $this->datatableInterventions($datatable, $translator, $objet, $type)->execute();
}
/**
* set datatable configs
*
* @return \App\Library\Datatable\Util\Datatable
*/
private function datatableInterventions(Datatable $datatable, TranslatorInterface $translator, $objet, $type = "")
{
//echo "HYHYHYH";
/*
if($type == "projet") {
}
else {
}
*/
if (is_object($type)) {
$type = "tache";
}
$datatable
->setDatatableId('dta-interventions')
->setEntity(Note::class, "x")
->setFields(
[
"ID" => 'x.id',
$translator->trans("Libellé") => 'x.message',
$translator->trans("Début") => 'x.dateDebut',
$translator->trans("Fin") => 'x.dateFin',
$translator->trans("Utilisateur") => 'u.nom',
"Actions" => 'x.id',
"_identifier_" => 'x.id',
]
)
->addJoin('x.utilisateur', 'u', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
//->addJoin('x.reference', 'r', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
->setWhere(
'x.'.$type.' = :objet',
['objet' => $objet]
)
->setRenderers(
[
0 => [
'view' => 'FO/DataTable/avec_lien_edit_route.html.twig',
'params' => [
'edit_route' => 'dtc_projet_intervention_modifier',
],
],
1 => [
'view' => 'FO/DataTable/titre_note.html.twig',
'params' => [
'edit_route' => 'dtc_intervention_modifier',
'supprimer_route' => 'dtc_intervention_supprimer',
//'id' => $client->getId(),
'width_modal' => 900,
'type' => "liste",
'objet' => Note::class,
],
],
2 => [
'view' => 'FO/DataTable/heure.html.twig',
'params' => [//'edit_route' => 'dtc_projet_intervention_modifier'
],
],
3 => [
'view' => 'FO/DataTable/heure.html.twig',
'params' => [//'edit_route' => 'dtc_projet_intervention_modifier'
],
],
4 => [
'view' => 'FO/DataTable/utilisateur.html.twig',
'params' => [//'edit_route' => 'dtc_projet_intervention_modifier'
],
],
5 => [
'view' => 'FO/DataTable/actions_modal.html.twig',
'params' => [
'edit_route' => 'dtc_intervention_modifier',
'supprimer_route' => 'dtc_intervention_supprimer',
//'id' => $client->getId(),
'width_modal' => 900,
'type' => "liste",
'objet' => Note::class,
],
],
]
)
/*
->setMultiple(
array(
'delete' => array(
'title' => $translator->trans('Non disponible'),
'route' => 'dtc_tache_liste'
),
)
)
*
*/
->setOrder("x.id", "desc")
->setSearch(true);
$datatable->setSearchFields([1, 3]);
return $datatable;
}
/**
* @Route("/projet/tache/recherche", name="dtc_tache_recherche")
*/
public function rechercheAction(Request $request, EntityManagerInterface $em, TranslatorInterface $translator, PaginatorInterface $paginator)
{
$q = $request->query->get('q');
$projet = $request->query->get('projet');
$repo = $em->getRepository(Tache::class);
$results = $repo->getRechercheTache(trim($q), $projet);
$tabClient = [];
$pagination = $paginator->paginate(
$results, /* query NOT result */
$request->query->getInt('page', 1)/*page number*/,
10/*limit per page*/
);
$pagination_results = $pagination->getItems();
$option_placeholde = ["libelle" => $translator->trans("Sélectionnez"), "id" => ""];
if ($request->query->getInt('page', 1) == 1) {
array_unshift($pagination_results, $option_placeholde);
}
$pagination->setItems($pagination_results);
$serializer = SerializerBuilder::create()->build();
return JsonResponse::fromJsonString($serializer->serialize($pagination, 'json'));
}
/**
* @Route("/tache/supprimer/{objet}/{type}", name="dtc_tache_supprimer")
*/
public function supprimerAction(Request $request, Tache $objet, $type, EntityManagerInterface $em, TranslatorInterface $translator, ValidatorInterface $validator)
{
$titre_modal = $translator->trans("Demande de confirmation");
$user = $this->getUser();
$form = $this->createForm(SupprimerTacheType::class, $objet);
$errors = "";
$form->handleRequest($request);
if ($form->isSubmitted()) {
if ($form->isValid()) {
$em->remove($objet);
$em->flush();
$this->addFlash(
'notice',
'Tâche supprimée avec succès !'
);
$url = '';
if ($type == 'projet') {
$url = $this->generateUrl('dtc_projet_modifier', ['id' => $objet->getProjet()->getId(), 'tab' => 'taches']);
}
return new JsonResponse(['rendu' => '', 'valide' => '1', 'url' => $url]);
} else {
$errors = $validator->validate($objet);
$rendu = $this->renderView('FO/Supprimer/supprimer.html.twig', ['form' => $form->createView(), 'errors' => $errors, 'type' => $type, 'objet' => $objet]);
return new JsonResponse(['rendu' => $rendu, 'valide' => '0', 'url' => '', 'titre' => $titre_modal]);
}
}
if (count($objet->getInterventions()) > 0) {
$errors[] = ['message' => 'Vous ne pouvez pas supprimer une tâche pour laquelle des interventions ont été saisies!'];
}
if (count($objet->getEnfants()) > 0) {
$errors[] = ['message' => 'Vous ne pouvez pas supprimer une tâche pour laquelle des sous-tâches existent!'];
}
$rendu = $this->renderView('FO/Supprimer/supprimer.html.twig', ['form' => $form->createView(), 'errors' => $errors, 'type' => $type, 'objet' => $objet]);
return new JsonResponse(['rendu' => $rendu, 'valide' => '0', 'url' => '', 'titre' => $titre_modal]);
}
}