Remove open food facts

It was decided it should be implemented client-side
This commit is contained in:
Arnaud Vergnet 2020-09-09 15:27:39 +02:00
parent 1e2e0134ba
commit 37f0f57766
2 changed files with 15 additions and 33 deletions

View file

@ -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." +
"<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>",
content: "Voulez vous vraiment mettre en ligne le stock actuel du Proximo ? Il sera visible depuis l'application CAMPUS.",
type: "orange",
buttons: {
formSubmit: {

View file

@ -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))