Merge branch 'master' into dist/eole/2.8.1/master
This commit is contained in:
commit
e180def44b
|
@ -8,6 +8,7 @@ framework:
|
|||
session:
|
||||
name: '%env(APP_ALIAS)%'
|
||||
handler_id: null
|
||||
gc_probability: null
|
||||
cookie_secure: auto
|
||||
cookie_samesite: lax
|
||||
|
||||
|
|
|
@ -83,12 +83,15 @@ class BreakdayCommand extends Command
|
|||
foreach($users as $user) {
|
||||
if(!$user->hasRole("ROLE_USER")) continue;
|
||||
|
||||
$mini=new \Datetime('2022-03-07 00:00');
|
||||
$start=new \Datetime('00:00');
|
||||
$start->modify("monday this week");
|
||||
$end=new \Datetime('00:00');
|
||||
$end->modify("last day of this month");
|
||||
$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()]));
|
||||
|
||||
if($response&&$response->code=="200") {
|
||||
|
|
|
@ -14,6 +14,82 @@ class RestController extends AbstractFOSRestController
|
|||
private $output=[];
|
||||
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
|
||||
*
|
||||
|
@ -61,16 +137,18 @@ class RestController extends AbstractFOSRestController
|
|||
if(!$data||$data->getDateend()) {
|
||||
$data = new Tallyday();
|
||||
$data->setDateof(new \DateTime("now"));
|
||||
$data->setUser($this->getUser());
|
||||
$data->setUser($user);
|
||||
$data->setValidateuser(false);
|
||||
$data->setValidatemaster(false);
|
||||
$data->setIsbreakday(false);
|
||||
$data->setDatestart($datenow);
|
||||
$status="started";
|
||||
}
|
||||
|
||||
// Sinon c'est que l'on ferme un creneau
|
||||
elseif($data) {
|
||||
$data->setDateend($datenow);
|
||||
$status="stopped";
|
||||
}
|
||||
|
||||
// Sinon pas normal
|
||||
|
@ -101,6 +179,8 @@ class RestController extends AbstractFOSRestController
|
|||
$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),
|
||||
];
|
||||
|
@ -109,6 +189,675 @@ class RestController extends AbstractFOSRestController
|
|||
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
|
||||
elseif($data) {
|
||||
$data->setDateend($datenow);
|
||||
}
|
||||
|
||||
// Sinon pas normal
|
||||
else {
|
||||
$view = $this->view("Incohérence dans vos créneaux horaires pour fermer 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" => "stopped",
|
||||
"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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue