Compare commits

..

No commits in common. "e180def44b250a551d3ba25c318f5ad724a43922" and "e82f63a3e1214e1a1f564e45a5759da2c88d95d2" have entirely different histories.

3 changed files with 2 additions and 755 deletions

View File

@ -8,7 +8,6 @@ framework:
session: session:
name: '%env(APP_ALIAS)%' name: '%env(APP_ALIAS)%'
handler_id: null handler_id: null
gc_probability: null
cookie_secure: auto cookie_secure: auto
cookie_samesite: lax cookie_samesite: lax

View File

@ -83,14 +83,11 @@ class BreakdayCommand extends Command
foreach($users as $user) { foreach($users as $user) {
if(!$user->hasRole("ROLE_USER")) continue; if(!$user->hasRole("ROLE_USER")) continue;
$mini=new \Datetime('2022-03-07 00:00');
$start=new \Datetime('00:00'); $start=new \Datetime('00:00');
$start->modify("monday this week"); $start->modify("monday this week");
$end=new \Datetime('00:00'); $end=new \Datetime('00:00');
$end->modify("last day of this month"); $end->modify("last day of this month");
$end->modify("next sunday"); $end->modify("next sunday");
$start->modify("previous month");
if($start<$mini) $start=clone $mini;
$response=$this->api("POST",$url."/getBreakdays",json_encode(["key"=>$key,"username"=>$user->getUsername()])); $response=$this->api("POST",$url."/getBreakdays",json_encode(["key"=>$key,"username"=>$user->getUsername()]));

View File

@ -14,82 +14,6 @@ class RestController extends AbstractFOSRestController
private $output=[]; private $output=[];
private $cpt; private $cpt;
/**
* Status timer
*
*
* @FOSRest\Post("/rest/status")
* @SWG\Response(
* response=200,
* description="Status Timer"
* )
* )
* @SWG\Parameter(
* name="key",
* in="formData",
* required=true,
* description="User APIKey",
* type="string"
* )
*/
public function status(Request $request) {
set_time_limit(0);
ini_set('memory_limit', '1024M');
// Initalisation Manager
$em = $this->getDoctrine()->getManager();
// Récupération des parametres
$key=$request->get("key");
// Rechercher l'utilisateur associé à la clé
$user = $em->getRepository("App:User")->findOneBy(["apikey"=>$key]);
if(!$user) {
$view = $this->view("API Key inconnue", 403);
return $this->handleView($view);
}
$datenow=new \DateTime("now");
$datenow->setTime( $datenow->format("H"), $datenow->format("i"), 0 );
// On recherche le dernier pointage de la journée
$data = $em->getRepository("App:Tallyday")->findOneBy(["user"=>$user,"dateof"=>$datenow],["datestart"=>"DESC"]);
if(!$data) {
$status="notimer";
$datestatus=null;
}
elseif($data->getDateend()) {
$status="stopped";
$datestatus=$data->getDateend();
} else {
$status="started";
$datestatus=$data->getDatestart();
}
$datas = $em->getRepository("App:Tallyday")->findTallyday($user,clone $datenow);
$e = new \DateTime('00:00');
$f = clone $e;
foreach($datas as $data) {
$e->add($data->getTimeday());
}
$interval = $f->diff($e);
$timeday = (($interval->days*24) + $interval->h).":".sprintf("%02s",$interval->i);
$output = [
"status" => $status,
"datestatus" => ($datestatus?$datestatus->format("Y/m/d H:i"):""),
"timeday" => $timeday,
"capitaltime" => $em->getRepository("App:Tallyday")->getCapitaltime($user),
];
$view = $this->view($output, 200);
return $this->handleView($view);
}
/** /**
* Start / Stop timer * Start / Stop timer
* *
@ -137,198 +61,11 @@ class RestController extends AbstractFOSRestController
if(!$data||$data->getDateend()) { if(!$data||$data->getDateend()) {
$data = new Tallyday(); $data = new Tallyday();
$data->setDateof(new \DateTime("now")); $data->setDateof(new \DateTime("now"));
$data->setUser($user); $data->setUser($this->getUser());
$data->setValidateuser(false); $data->setValidateuser(false);
$data->setValidatemaster(false); $data->setValidatemaster(false);
$data->setIsbreakday(false); $data->setIsbreakday(false);
$data->setDatestart($datenow); $data->setDatestart($datenow);
$status="started";
}
// Sinon c'est que l'on ferme un creneau
elseif($data) {
$data->setDateend($datenow);
$status="stopped";
}
// Sinon pas normal
else {
$view = $this->view("Incohérence dans vos créneaux horaires", 404);
return $this->handleView($view);
}
// On vérifie quand meme la cohérance des crénaux
if(!$em->getRepository("App:Tallyday")->vefifTallytime($data)) {
$view = $this->view("Incohérence dans vos créneaux horaires", 404);
return $this->handleView($view);
}
// C'est ok on fluh
$em->persist($data);
$em->flush();
// Calcul du temps de la journée
$datas = $em->getRepository("App:Tallyday")->findTallyday($user,clone $datenow);
$e = new \DateTime('00:00');
$f = clone $e;
foreach($datas as $data) {
$e->add($data->getTimeday());
}
$interval = $f->diff($e);
$timeday = (($interval->days*24) + $interval->h).":".sprintf("%02s",$interval->i);
$output = [
"status" => $status,
"datestatus" => $datenow->format("Y/m/d H:I"),
"timeday" => $timeday,
"capitaltime" => $em->getRepository("App:Tallyday")->getCapitaltime($user),
];
$view = $this->view($output, 200);
return $this->handleView($view);
}
/**
* Start timer
*
*
* @FOSRest\Post("/rest/clockin")
* @SWG\Response(
* response=200,
* description="Start Timer"
* )
* )
* @SWG\Parameter(
* name="key",
* in="formData",
* required=true,
* description="User APIKey",
* type="string"
* )
*/
public function clockin(Request $request) {
set_time_limit(0);
ini_set('memory_limit', '1024M');
// Initalisation Manager
$em = $this->getDoctrine()->getManager();
// Récupération des parametres
$key=$request->get("key");
// Rechercher l'utilisateur associé à la clé
$user = $em->getRepository("App:User")->findOneBy(["apikey"=>$key]);
if(!$user) {
$view = $this->view("API Key inconnue", 403);
return $this->handleView($view);
}
$datenow=new \DateTime("now");
$datenow->setTime ( $datenow->format("H"), $datenow->format("i"), 0 );
// On recherche le dernier pointage de la journée
$data = $em->getRepository("App:Tallyday")->findOneBy(["user"=>$user,"dateof"=>$datenow],["datestart"=>"DESC"]);
// Si pas d'entrée ou si la dernière entrée à une date de fin, c'est que l'on ouvre un créneau
if(!$data||$data->getDateend()) {
$data = new Tallyday();
$data->setDateof(new \DateTime("now"));
$data->setUser($user);
$data->setValidateuser(false);
$data->setValidatemaster(false);
$data->setIsbreakday(false);
$data->setDatestart($datenow);
}
// Sinon pas normal
else {
$view = $this->view("Incohérence dans vos créneaux horaires pour débuter un créneau", 404);
return $this->handleView($view);
}
// On vérifie quand meme la cohérance des crénaux
if(!$em->getRepository("App:Tallyday")->vefifTallytime($data)) {
$view = $this->view("Incohérence dans vos créneaux horaires", 404);
return $this->handleView($view);
}
// C'est ok on fluh
$em->persist($data);
$em->flush();
// Calcul du temps de la journée
$datas = $em->getRepository("App:Tallyday")->findTallyday($user,clone $datenow);
$e = new \DateTime('00:00');
$f = clone $e;
foreach($datas as $data) {
$e->add($data->getTimeday());
}
$interval = $f->diff($e);
$timeday = (($interval->days*24) + $interval->h).":".sprintf("%02s",$interval->i);
$output = [
"status" => "started",
"datestatus" => $datenow->format("Y/m/d H:I"),
"timeday" => $timeday,
"capitaltime" => $em->getRepository("App:Tallyday")->getCapitaltime($user),
];
$view = $this->view($output, 200);
return $this->handleView($view);
}
/**
* Stop timer
*
*
* @FOSRest\Post("/rest/clockout")
* @SWG\Response(
* response=200,
* description="Stop Timer"
* )
* )
* @SWG\Parameter(
* name="key",
* in="formData",
* required=true,
* description="User APIKey",
* type="string"
* )
*/
public function clockout(Request $request) {
set_time_limit(0);
ini_set('memory_limit', '1024M');
// Initalisation Manager
$em = $this->getDoctrine()->getManager();
// Récupération des parametres
$key=$request->get("key");
// Rechercher l'utilisateur associé à la clé
$user = $em->getRepository("App:User")->findOneBy(["apikey"=>$key]);
if(!$user) {
$view = $this->view("API Key inconnue", 403);
return $this->handleView($view);
}
$datenow=new \DateTime("now");
$datenow->setTime ( $datenow->format("H"), $datenow->format("i"), 0 );
// On recherche le dernier pointage de la journée
$data = $em->getRepository("App:Tallyday")->findOneBy(["user"=>$user,"dateof"=>$datenow],["datestart"=>"DESC"]);
// Si pas d'entrée ou si la dernière entrée à une date de fin, c'est que l'on ouvre un créneau
if(!$data||$data->getDateend()) {
$view = $this->view("Incohérence dans vos créneaux horaires pour fermer un créneau", 404);
return $this->handleView($view);
} }
// Sinon c'est que l'on ferme un creneau // Sinon c'est que l'on ferme un creneau
@ -338,7 +75,7 @@ class RestController extends AbstractFOSRestController
// Sinon pas normal // Sinon pas normal
else { else {
$view = $this->view("Incohérence dans vos créneaux horaires pour fermer un créneau", 404); $view = $this->view("Incohérence dans vos créneaux horaires", 404);
return $this->handleView($view); return $this->handleView($view);
} }
@ -360,13 +97,10 @@ class RestController extends AbstractFOSRestController
foreach($datas as $data) { foreach($datas as $data) {
$e->add($data->getTimeday()); $e->add($data->getTimeday());
} }
$interval = $f->diff($e); $interval = $f->diff($e);
$timeday = (($interval->days*24) + $interval->h).":".sprintf("%02s",$interval->i); $timeday = (($interval->days*24) + $interval->h).":".sprintf("%02s",$interval->i);
$output = [ $output = [
"status" => "stopped",
"datestatus" => $datenow->format("Y/m/d H:I"),
"timeday" => $timeday, "timeday" => $timeday,
"capitaltime" => $em->getRepository("App:Tallyday")->getCapitaltime($user), "capitaltime" => $em->getRepository("App:Tallyday")->getCapitaltime($user),
]; ];
@ -375,489 +109,6 @@ class RestController extends AbstractFOSRestController
return $this->handleView($view); return $this->handleView($view);
} }
/**
* Add timer
*
*
* @FOSRest\Post("/rest/addtimer")
* @SWG\Response(
* response=200,
* description="Add Timer"
* )
* )
* @SWG\Parameter(
* name="key",
* in="formData",
* required=true,
* description="User APIKey",
* type="string"
* )
*
* @SWG\Parameter(
* name="start",
* in="formData",
* required=true,
* description="Date start format YYYY-MM-DD H:I",
* type="string"
* )
*
* @SWG\Parameter(
* name="end",
* in="formData",
* required=false,
* description="Date end format YYYY-MM-DD H:I",
* type="string"
* )
*/
public function addtimer(Request $request) {
set_time_limit(0);
ini_set('memory_limit', '1024M');
// Initalisation Manager
$em = $this->getDoctrine()->getManager();
// Récupération des parametres
$key=$request->get("key");
$start=new \DateTime($request->get("start"));
$end=$request->get("end");
if(!is_null($end)) $end=new \DateTime($end);
// Rechercher l'utilisateur associé à la clé
$user = $em->getRepository("App:User")->findOneBy(["apikey"=>$key]);
if(!$user) {
$view = $this->view("API Key inconnue", 403);
return $this->handleView($view);
}
// Creation du timer
$dateof=clone $start;
$dateof->setTime(0,0);
$data = new Tallyday();
$data->setDateof($dateof);
$data->setUser($user);
$data->setValidateuser(false);
$data->setValidatemaster(false);
$data->setIsbreakday(false);
$data->setDatestart($start);
$data->setDateend($end);
// Pas normal = on ne peut créer une donnée sur une journée déjà validé par l'utilisateur
$isvalideuser= $em->getRepository("App:Tallyday")->findOneBy(["user"=>$user,"dateof"=>$dateof,"validateuser"=>true]);
if($isvalideuser) {
$view = $this->view("Impossible de créer un créneau sur une journée validée", 404);
return $this->handleView($view);
}
// Pas normal = on ne peut créer une donnée sur une journée déjà validé par master
$isvalidemaster= $em->getRepository("App:Tallyday")->findOneBy(["user"=>$user,"dateof"=>$dateof,"validatemaster"=>true]);
if($isvalidemaster) {
$view = $this->view("Impossible de créer un créneau sur une journée validée", 404);
return $this->handleView($view);
}
// On vérifie quand meme la cohérance des crénaux
if(!$em->getRepository("App:Tallyday")->vefifTallytime($data)) {
$view = $this->view("Incohérence dans vos créneaux horaires", 404);
return $this->handleView($view);
}
// C'est ok on flush
$em->persist($data);
$em->flush();
// Calcul du temps de la journée
$datas = $em->getRepository("App:Tallyday")->findTallyday($user,clone $dateof);
$e = new \DateTime('00:00');
$f = clone $e;
foreach($datas as $data) {
$e->add($data->getTimeday());
}
$interval = $f->diff($e);
$timeday = (($interval->days*24) + $interval->h).":".sprintf("%02s",$interval->i);
$output = [
"status" => "added",
"timeday" => $timeday,
"capitaltime" => $em->getRepository("App:Tallyday")->getCapitaltime($user),
];
$view = $this->view($output, 200);
return $this->handleView($view);
}
/**
* Delete timer
*
*
* @FOSRest\Post("/rest/deletetimer")
* @SWG\Response(
* response=200,
* description="Delete Timer"
* )
* )
* @SWG\Parameter(
* name="key",
* in="formData",
* required=true,
* description="User APIKey",
* type="string"
* )
*
* @SWG\Parameter(
* name="start",
* in="formData",
* required=true,
* description="Date start format YYYY-MM-DD H:I",
* type="string"
* )
*/
public function deletetimer(Request $request) {
set_time_limit(0);
ini_set('memory_limit', '1024M');
// Initalisation Manager
$em = $this->getDoctrine()->getManager();
// Récupération des parametres
$key=$request->get("key");
$start=new \DateTime($request->get("start"));
// Rechercher l'utilisateur associé à la clé
$user = $em->getRepository("App:User")->findOneBy(["apikey"=>$key]);
if(!$user) {
$view = $this->view("API Key inconnue", 403);
return $this->handleView($view);
}
// Recherche du timer
$dateof=clone $start;
$dateof->setTime(0,0);
$data= $em->getRepository("App:Tallyday")->findOneBy(["user"=>$user,"datestart"=>$start]);
// Pas normal = on ne peut créer une donnée sur une journée déjà validé par l'utilisateur
$isvalideuser= $em->getRepository("App:Tallyday")->findOneBy(["user"=>$user,"dateof"=>$dateof,"validateuser"=>true]);
if($isvalideuser) {
$view = $this->view("Impossible de supprimer un créneau sur une journée validée", 404);
return $this->handleView($view);
}
// Pas normal = on ne peut créer une donnée sur une journée déjà validé par master
$isvalidemaster= $em->getRepository("App:Tallyday")->findOneBy(["user"=>$user,"dateof"=>$dateof,"validatemaster"=>true]);
if($isvalidemaster) {
$view = $this->view("Impossible de supprimer un créneau sur une journée validée", 404);
return $this->handleView($view);
}
// Aucun créneau à supprimer
if(!$data) {
$view = $this->view("Aucun créneau à supprimer à cette heure", 404);
return $this->handleView($view);
}
// Suppression
$em->remove($data);
$em->flush();
// Calcul du temps de la journée
$datas = $em->getRepository("App:Tallyday")->findTallyday($user,clone $dateof);
$e = new \DateTime('00:00');
$f = clone $e;
foreach($datas as $data) {
$e->add($data->getTimeday());
}
$interval = $f->diff($e);
$timeday = (($interval->days*24) + $interval->h).":".sprintf("%02s",$interval->i);
$output = [
"status" => "deleted",
"timeday" => $timeday,
"capitaltime" => $em->getRepository("App:Tallyday")->getCapitaltime($user),
];
$view = $this->view($output, 200);
return $this->handleView($view);
}
/**
* Validate day
*
*
* @FOSRest\Post("/rest/validate")
* @SWG\Response(
* response=200,
* description="Validate Date"
* )
* )
* @SWG\Parameter(
* name="key",
* in="formData",
* required=true,
* description="User APIKey",
* type="string"
* )
*
* @SWG\Parameter(
* name="dateof",
* in="formData",
* required=true,
* description="Date to validate format YYYY-MM-DD",
* type="string"
* )
*/
public function validate(Request $request) {
set_time_limit(0);
ini_set('memory_limit', '1024M');
// Initalisation Manager
$em = $this->getDoctrine()->getManager();
// Récupération des parametres
$key=$request->get("key");
$dateof=new \DateTime($request->get("dateof"));
$dateof->setTime(0,0);
// Rechercher l'utilisateur associé à la clé
$user = $em->getRepository("App:User")->findOneBy(["apikey"=>$key]);
if(!$user) {
$view = $this->view("API Key inconnue", 403);
return $this->handleView($view);
}
// Récupérer la premier validation master
$firstvalidate= $em->getRepository("App:Tallyday")->findOneBy(["user"=>$user,"validatemaster"=>true],["dateof"=>"ASC"]);
// Pas normal
if($firstvalidate && $firstvalidate->getDateof() > $dateof) {
$view = $this->view("Impossible de valider un chef de projet a déjà validé des créneaux avec une date supérieure", 404);
return $this->handleView($view);
}
// Récupérer les créneaux
$datas = $em->getRepository("App:Tallyday")->findTallyday($user,clone $dateof);
// Si aucun enregistrement on initialise le pointage sur la journée à vide
if(!$datas) {
$data = new Tallyday();
$data->setUser($user());
$data->setDateof($dateof);
$data->setValidateuser(true);
$data->setValidatemaster(false);
$data->setIsbreakday(false);
$em->persist($data);
$em->flush();
}
foreach($datas as $data) {
if($data->getDatestart()&&!$data->getDateend()) {
$view = $this->view("Impossible de valider, il vous manque des dates de fin", 404);
return $this->handleView($view);
}
// Validation
$data->setValidateuser(true);
$em->persist($data);
}
$em->flush();
// Calcul du temps de la journée
$datas = $em->getRepository("App:Tallyday")->findTallyday($user,clone $dateof);
$e = new \DateTime('00:00');
$f = clone $e;
foreach($datas as $data) {
$e->add($data->getTimeday());
}
$interval = $f->diff($e);
$timeday = (($interval->days*24) + $interval->h).":".sprintf("%02s",$interval->i);
$output = [
"status" => "validate",
"timeday" => $timeday,
"capitaltime" => $em->getRepository("App:Tallyday")->getCapitaltime($user),
];
$view = $this->view($output, 200);
return $this->handleView($view);
}
/**
* Devalidate day
*
*
* @FOSRest\Post("/rest/devalidate")
* @SWG\Response(
* response=200,
* description="Devalidate Date"
* )
* )
* @SWG\Parameter(
* name="key",
* in="formData",
* required=true,
* description="User APIKey",
* type="string"
* )
*
* @SWG\Parameter(
* name="dateof",
* in="formData",
* required=true,
* description="Date to validate format YYYY-MM-DD",
* type="string"
* )
*/
public function devalidate(Request $request) {
set_time_limit(0);
ini_set('memory_limit', '1024M');
// Initalisation Manager
$em = $this->getDoctrine()->getManager();
// Récupération des parametres
$key=$request->get("key");
$dateof=new \DateTime($request->get("dateof"));
$dateof->setTime(0,0);
// Rechercher l'utilisateur associé à la clé
$user = $em->getRepository("App:User")->findOneBy(["apikey"=>$key]);
if(!$user) {
$view = $this->view("API Key inconnue", 403);
return $this->handleView($view);
}
$datas = $em->getRepository("App:Tallyday")->findTallyday($user,clone $dateof);
// Pas normal = on ne peut pas dévalider qqchose qui n'existe pas
if(!$datas) {
$view = $this->view("Impossible de devalider, pas de créneaux validés à cette date", 404);
return $this->handleView($view);
}
// Pas normal = l'utilisateur ne peut pas dévalider une validation master
foreach($datas as $data) {
if($data->getValidatemaster()) {
$view = $this->view("Impossible de devalider, la journée a été validé par un chef de projet", 404);
return $this->handleView($view);
}
}
// Devalidation
foreach($datas as $data) {
if($data->getDatestart()&&$data->getDateend()) {
// Dévalidation
$data->setValidateuser(false);
$em->persist($data);
$em->flush();
}
else {
$em->remove($data);
$em->flush();
}
}
// Calcul du temps de la journée
$datas = $em->getRepository("App:Tallyday")->findTallyday($user,clone $dateof);
$e = new \DateTime('00:00');
$f = clone $e;
foreach($datas as $data) {
$e->add($data->getTimeday());
}
$interval = $f->diff($e);
$timeday = (($interval->days*24) + $interval->h).":".sprintf("%02s",$interval->i);
$output = [
"status" => "devalidate",
"timeday" => $timeday,
"capitaltime" => $em->getRepository("App:Tallyday")->getCapitaltime($user),
];
$view = $this->view($output, 200);
return $this->handleView($view);
}
/**
* Show timers
*
*
* @FOSRest\Post("/rest/showtimers")
* @SWG\Response(
* response=200,
* description="Show timers"
* )
* )
* @SWG\Parameter(
* name="key",
* in="formData",
* required=true,
* description="User APIKey",
* type="string"
* )
*
* @SWG\Parameter(
* name="dateof",
* in="formData",
* required=true,
* description="Date to show format YYYY-MM-DD",
* type="string"
* )
*/
public function showtimers(Request $request) {
set_time_limit(0);
ini_set('memory_limit', '1024M');
// Initalisation Manager
$em = $this->getDoctrine()->getManager();
// Récupération des parametres
$key=$request->get("key");
$dateof=new \DateTime($request->get("dateof"));
$dateof->setTime(0,0);
// Rechercher l'utilisateur associé à la clé
$user = $em->getRepository("App:User")->findOneBy(["apikey"=>$key]);
if(!$user) {
$view = $this->view("API Key inconnue", 403);
return $this->handleView($view);
}
// Calcul du temps de la journée
$datas = $em->getRepository("App:Tallyday")->findTallyday($user,clone $dateof);
$e = new \DateTime('00:00');
$f = clone $e;
$timers=[];
foreach($datas as $data) {
$isvalideuser=$data->getValidateuser();
$isvalidemaster=$data->getValidatemaster();
array_push($timers,["start"=>$data->getDatestart(),"end"=>$data->getDateend()]);
$e->add($data->getTimeday());
}
$interval = $f->diff($e);
$timeday = (($interval->days*24) + $interval->h).":".sprintf("%02s",$interval->i);
$output = [
"isvalidateuser" => $isvalideuser,
"isvalidatemaster" => $isvalidemaster,
"timers" => $timers,
"capitaltime" => $em->getRepository("App:Tallyday")->getCapitaltime($user),
];
$view = $this->view($output, 200);
return $this->handleView($view);
}
} }