diff --git a/assets/js/index.js b/assets/js/index.js
index 94e0ff0..defc105 100644
--- a/assets/js/index.js
+++ b/assets/js/index.js
@@ -1,9 +1,7 @@
$('#uploadButton').on('click', function () {
$.confirm({
title: 'Confirmer',
- content: "Voulez vous vraiment mettre en ligne le stock actuel du Proximo ? Il sera visible depuis l'application CAMPUS." +
- "
NOUVEAUTÉ !
Le site va maintenant récupérer les informations nutritionelles sur le site OpenFoodFacts !" +
- "
La mise en ligne va donc prendre plus longtemps",
+ content: "Voulez vous vraiment mettre en ligne le stock actuel du Proximo ? Il sera visible depuis l'application CAMPUS.",
type: "orange",
buttons: {
formSubmit: {
diff --git a/classes/postHandler.php b/classes/postHandler.php
index f8a5c02..a80572d 100644
--- a/classes/postHandler.php
+++ b/classes/postHandler.php
@@ -64,15 +64,19 @@ class PostHandler
public function write_json()
{
$result = 0;
- $fp = fopen($this->stockFile, "w");
$array = array(
"types" => $this->dao->get_categories(),
"articles" => $this->get_articles_json_list(),
);
- fwrite($fp, json_encode($array));
- fclose($fp);
+ $fp = fopen($this->stockFile, "w");
+ if ($fp) {
+ fwrite($fp, json_encode($array));
+ fclose($fp);
+ $this->responseArray["data"] = $result;
+ } else {
+ $this->setFileErrorResponse();
+ }
- $this->responseArray["data"] = $result;
return $this->responseArray;
}
@@ -83,37 +87,11 @@ class PostHandler
foreach ($articles as $article) {
$article["type"] = $this->dao->get_categories_of_article($article["id"]);
$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);
}
-
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()
{
$success = true;
@@ -247,6 +225,12 @@ class PostHandler
$this->responseArray["message"] = "Error: Data processing error";
}
+ function setFileErrorResponse()
+ {
+ $this->responseArray["status"] = 5;
+ $this->responseArray["message"] = "Error: Could not open file";
+ }
+
private function get_action($inputData)
{
if (!in_array($inputData["action"], $this->valid_actions))