$userId = backpack_user()->id;
$unload = $request->unload;
+ /*cache()->forget('queue_editor'.$fluidbookId);*/
+ /*cache()->forget('connexion'.$fluidbookId);*/
+
/* Reset
*
*/
if(!cache()->has('queue_editor'.$fluidbookId)) {
- $entries = [$token];
+ $entries = [["token" => $token, "date" => now()]];
cache(['queue_editor'.$fluidbookId => $entries]);
} else {
$queueEditor = cache()->get('queue_editor'.$fluidbookId); // on récupère la liste des onglets
- $key = array_search($token, $queueEditor);
+ $key = key(array_filter($queueEditor, function($n) use($token) { return $n["token"] === $token; }));
- if ((int)$unload === 1) {
+ if ((int)$unload === 1 && $key) {
unset($queueEditor[$key]); // on supprime l'onglet de la liste au chargement ou à sa fermeture
}
if(!$key) {
- $queueEditor[] = $token;
+ $queueEditor[] = ["token" => $token, "date" => now()];
+ } else {
+ $queueEditor[$key]["date"] = now();
}
- $queueEditor = array_unique($queueEditor);
+ $queueEditor = array_filter($queueEditor, function($n) {
+ return strtotime($n["date"]) > strtotime(now())-20;
+ });
+
+ //$queueEditor = array_unique($queueEditor);
cache(['queue_editor'.$fluidbookId => $queueEditor]);
}
// réinitialiser la connexion courante quand on clique sur "déconnecter l'utilisateur"
if($request->clear) {
- $key = array_search($token, $queueEditor);
+ $key = key(array_filter($queueEditor, function($n) use($token) { return $n["token"] === $token; }));
$queueEditor = array_slice($queueEditor, $key, 1);
- $queueEditor = array_merge([$token],$queueEditor);
+ $queueEditor = array_merge($queueEditor[$key],$queueEditor);
cache(['queue_editor'.$fluidbookId => $queueEditor]);
cache(['connexion' . $fluidbookId => ['id' => $userId, 'token' => $token, 'f_id' => $fluidbookId]]);
}
$user = User::withoutGlobalScopes()->find($connexionExist['id']);
$user = $user->firstname.' '.$user->lastname;
- if(current($queueEditor) !== $token) {
+ if(current($queueEditor)["token"] !== $token) {
return json_encode(["queueEditor"=>$queueEditor,"token"=>$token,"status"=>"unavailable","infos_connection"=>array_merge(["user" => $user],$connexionExist)]);
} else {
return json_encode(["queueEditor"=>$queueEditor,"status"=>"available",$connexionExist]);