Compare commits
10 commits
7eea3d2fe5
...
bfa1319b27
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bfa1319b27 | ||
|
|
6ba1459848 | ||
|
|
83cee48d36 | ||
|
|
2786d17e5d | ||
|
|
88aada72b1 | ||
|
|
384328739e | ||
|
|
862b6a4741 | ||
|
|
72b5fae35f | ||
|
|
5b37c48d36 | ||
|
|
01581a61d7 |
2 changed files with 55 additions and 27 deletions
|
|
@ -1,38 +1,41 @@
|
||||||
async function sendRequest() {
|
|
||||||
let response = await $.ajax({
|
|
||||||
type: "POST",
|
|
||||||
url: "write_json.php",
|
|
||||||
});
|
|
||||||
response = JSON.parse(response);
|
|
||||||
console.log(response);
|
|
||||||
return response["status"];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$('#uploadButton').on('click', function () {
|
$('#uploadButton').on('click', function () {
|
||||||
$.confirm({
|
$.confirm({
|
||||||
title: 'Confirmer',
|
title: 'Confirmer',
|
||||||
content: "Voulez vous vraiment mettre en ligne le stock actuel du Proximo ? Il sera visible depuis l'application CAMPUS.",
|
content: "Voulez vous vraiment mettre en ligne le stock actuel du Proximo ? Il sera visible depuis l'application CAMPUS." +
|
||||||
|
"<br/><br/><strong>NOUVEAUTÉ !</strong><br/>Le site va maintenant récupérer les informations nutritionelles sur le site OpenFoodFacts !" +
|
||||||
|
"<br><strong>La mise en ligne va donc prendre plus longtemps</strong>",
|
||||||
type: "orange",
|
type: "orange",
|
||||||
buttons: {
|
buttons: {
|
||||||
formSubmit: {
|
formSubmit: {
|
||||||
text: 'Confirmer',
|
text: 'Confirmer',
|
||||||
btnClass: "btn-warning",
|
btnClass: "btn-warning",
|
||||||
action: async function () {
|
action: function () {
|
||||||
let result = await sendRequest();
|
$.confirm({
|
||||||
if (result !== 0) {
|
columnClass: "small",
|
||||||
$.alert({
|
content: function () {
|
||||||
title: "Erreur",
|
let self = this;
|
||||||
content: "Une erreur est survenue, merci de réessayer plus tard.",
|
return $.ajax({
|
||||||
type: "red",
|
type: "POST",
|
||||||
})
|
url: "write_json.php",
|
||||||
|
}).done((data) => {
|
||||||
|
const response = JSON.parse(data);
|
||||||
|
if (response["status"] === 0) {
|
||||||
|
self.setTitle("Succès");
|
||||||
|
self.setContent('Le stock a bien été mis à jour.');
|
||||||
|
self.setType("green");
|
||||||
} else {
|
} else {
|
||||||
$.alert({
|
self.setTitle("Erreur");
|
||||||
title: "Succès",
|
self.setContent('Une erreur est survenue, merci de réessayer plus tard.');
|
||||||
content: "Le stock a bien été mis à jour.",
|
self.setType("red");
|
||||||
type: "green",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
}).fail(() => {
|
||||||
|
self.setTitle("Erreur");
|
||||||
|
self.setContent('Une erreur est survenue, merci de réessayer plus tard.');
|
||||||
|
self.setType("red");
|
||||||
|
});
|
||||||
|
},
|
||||||
|
type: "orange",
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
cancel: {
|
cancel: {
|
||||||
|
|
|
||||||
|
|
@ -83,12 +83,37 @@ class PostHandler
|
||||||
foreach ($articles as $article) {
|
foreach ($articles as $article) {
|
||||||
$article["type"] = $this->dao->get_categories_of_article($article["id"]);
|
$article["type"] = $this->dao->get_categories_of_article($article["id"]);
|
||||||
$article["image"] = $this->imageBaseUrl . $article["id"] . ".jpg";
|
$article["image"] = $this->imageBaseUrl . $article["id"] . ".jpg";
|
||||||
|
//EXPERIMENTAL
|
||||||
|
$product = $this->get_openfoodfacts_product($article["code"]);
|
||||||
|
if($product != null){
|
||||||
|
$article["nutri-score"] = $product["nutrition_grade_fr"];
|
||||||
|
if(!empty($product["ingredients_text_fr"])) $article["ingredients"] = $product["ingredients_text_fr"];
|
||||||
|
else $article["ingredients"] = $product["ingredients_text"];
|
||||||
|
if(!empty($product["generic_name_fr"])) $article["generic"] = $product["generic_name_fr"];
|
||||||
|
else $article["generic"] = $product["generic_name"];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$article["nutri-score"] = null;
|
||||||
|
$article["generic"] = null;
|
||||||
|
$article["ingredients"] = null;
|
||||||
|
}
|
||||||
array_push($formatted_articles, $article);
|
array_push($formatted_articles, $article);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $formatted_articles;
|
return $formatted_articles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function get_openfoodfacts_product($barcode)
|
||||||
|
{
|
||||||
|
$country = 'fr';
|
||||||
|
$productSlug = 'produit';
|
||||||
|
$url = 'https://{country}.openfoodfacts.org/api/v0/{product}/{scan}.json';
|
||||||
|
$url = str_replace(['{country}','{product}','{scan}'],[$country,$productSlug,$barcode],$url);
|
||||||
|
$result = json_decode(file_get_contents($url), true);
|
||||||
|
if ($result["status"] == 1) return $result["product"];
|
||||||
|
else return null;
|
||||||
|
}
|
||||||
|
|
||||||
private function save_image()
|
private function save_image()
|
||||||
{
|
{
|
||||||
$success = true;
|
$success = true;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue