Merge branch 'master' into dist/envole/6/master

This commit is contained in:
Arnaud Fornerot 2021-03-10 16:45:35 +01:00
commit 9433a39649
1 changed files with 33 additions and 36 deletions

View File

@ -285,7 +285,7 @@ class ApiController extends Controller
$ret_str=$ret_str."<categorie>";
$ret_str=$ret_str."<nom>Mes Ressources</nom>";
$ret_str=$ret_str."<indice>-1</indice>";
$ret_str=$ret_str."<icone>fa-user-circle</icone>";
$ret_str=$ret_str."<icone>fa-star</icone>";
$ret_str=$ret_str."</categorie>";
}
@ -779,9 +779,9 @@ $api('$id',data);";
$debug = ob_get_clean();
//$debug=json_encode($request->query);
//return new Response(json_encode($output), 400);
if(is_null($token)||is_null($libelle)||is_null($icon)||is_null($favurl)||is_null($nom)||is_null($categorie)||is_null($callback)||is_null($action)||is_null($callbackid)){
$output["error"]="missing parameter : token - id - libelle - icon - favurl - nom - categorie - callback - action - callbackid";
return new Response(json_encode($output), 400);
}
$em = $this->getDoctrine()->getManager();
@ -789,15 +789,13 @@ $api('$id',data);";
$datasource = $em->getRepository('CadolesEdispatcherBundle:Datasource')->findOneBy(["token"=>$token]);
if (!$datasource) {
$output["error"]="no datasource session found for token = $token";
return new Response(json_encode($output), 400);
}
$login = $datasource->getUsername();
// Récupérer l'utilisateur
$user=$em->getRepository('CadolesCoreBundle:User')->findOneBy(["username"=>$login]);
if(!$user) {
$output["error"]="user not exist";
return new Response(json_encode($output), 400);
$output["error"]="user does not exist";
}
// chercher l'item
@ -805,8 +803,7 @@ $api('$id',data);";
if(!$item) {
$altitem=$em->getRepository('CadolesPortalBundle:Item')->findOneBy(["url"=>$favurl."?gestion_edispatcher=locale"]);
if(!$altitem) {
$output["error"]="item with url=$favurl(?gestion_edispatcher=locale) not exist";
return new Response(json_encode($output), 400);
$output["error"]="item with url=$favurl(?gestion_edispatcher=locale) not found";
} else {
$item = $altitem;
}
@ -814,11 +811,16 @@ $api('$id',data);";
$bookmark = $em->getRepository('CadolesPortalBundle:Bookmark')->findOneBy(["user"=>$user,"item"=>$item]);
$title="";
$subtitle="";
$output="";
if(!$bookmark) {
if ($action=="BOOKMARK_ADD") {
$subtitle="";
$message="";
if (isset($output["error"])) {
$message=$output["error"];
$success=0;
} else {
$output="";
if(!$bookmark) {
if ($action=="BOOKMARK_ADD") {
$bookmark = new Bookmark();
$bookmark->setTitle($item->getTitle());
$title=$item->getTitle();
@ -832,34 +834,30 @@ $api('$id',data);";
$bookmark->setUser($user);
$em->persist($bookmark);
$em->flush();
$success=1;
$output="<html><body>
<form id='form2submit' name='form2submit' method='POST' action='$callback'>
<input name='action' id='action' type='hidden' value='$action' />
<input name='message' id='message' type='hidden' value='$title : $subtitle a &eacute;t&eacute; ajout&eacute; &agrave; vos favoris' />
<input name='success' id='success' type='hidden' value='1' />
<input name='id' id='id' type='hidden' value='$id' />
<input name='callbackid' id='callbackid' type='hidden' value='$callbackid' />
</form>
<script>
document.form2submit.submit();
</script>
</body></html>
";
} else $success=0; // item pas en favori, mais ce n'est pas une demande d'ajout
} else {
if ($action=="BOOKMARK_DEL") {
$success=1;
$message="$title : $subtitle a &eacute;t&eacute; ajout&eacute; &agrave; vos favoris";
} else {
$success=0;
$message="item introuvable en favori mais action=DEL (retrait)";
}
} else {
if ($action=="BOOKMARK_DEL") {
$em->remove($bookmark);
$em->flush();
$success=1;
$success=1;
$message="item supprimé de vos favoris";
} else {
$success=0;
$message="item deja en favori mais action=ADD (ajout)";
}
}
}
$output="<html><body>
<form id='form2submit' name='form2submit' method='POST' action='$callback'>
<input name='action' id='action' type='hidden' value='$action' />
<input name='message' id='message' type='hidden' value='item supprimé de vos favoris' />
<input name='success' id='success' type='hidden' value='1' />
<input name='message' id='message' type='hidden' value='$message' />
<input name='success' id='success' type='hidden' value='$success' />
<input name='id' id='id' type='hidden' value='$id' />
<input name='callbackid' id='callbackid' type='hidden' value='$callbackid' />
</form>
@ -869,8 +867,7 @@ document.form2submit.submit();
</body></html>
";
} else $success=0; // item deja en favori mais demande d'ajout
}
$reponse = new Response();
$reponse->setContent($output);