Update Code
This commit is contained in:
parent
2786d17e5d
commit
83cee48d36
1 changed files with 17 additions and 10 deletions
|
@ -1,5 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once 'dao.php';
|
require_once 'dao.php';
|
||||||
|
|
||||||
class PostHandler
|
class PostHandler
|
||||||
|
@ -83,14 +82,21 @@ class PostHandler
|
||||||
$formatted_articles = [];
|
$formatted_articles = [];
|
||||||
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";
|
||||||
//EXPERIMENTAL
|
//EXPERIMENTAL
|
||||||
$response = $this->get_openfoodfacts_product($article["code"]);
|
$product = $this->get_openfoodfacts_product($article["code"]);
|
||||||
$product = $response["product"];
|
if($product != null){
|
||||||
$article["image"] = $product["image_front_url"] != "" ? $product["image_front_url"] : $this->imageBaseUrl . $article["id"] . ".jpg";
|
$article["nutri-score"] = $product["nutrition_grade_fr"];
|
||||||
$article["nutri-score"] = !empty($product["nutrition_grade_fr"]) ? $product["nutrition_grade_fr"] : null;
|
if(!empty($product["ingredients_text_fr"])) $article["ingredients"] = $product["ingredients_text_fr"];
|
||||||
$article["ingredients"] = !empty($product["ingredients_text_fr"]) ? $product["ingredients_text_fr"] : !empty($product["ingredients_text"]) ? $product["ingredients_text"] : null;
|
else $article["ingredients"] = $product["ingredients_text"];
|
||||||
$article["name"] = !empty($product["product_name_fr"]) ? $product["product_name_fr"] : !empty($product["product_name"]) ? $product["product_name"] : $article["name"];
|
if(!empty($product["generic_name_fr"])) $article["generic"] = $product["generic_name_fr"];
|
||||||
$article["description"] = !empty($product["generic_name_fr"]) ? $product["generic_name_fr"] : !empty($product["generic_name"]) ? $product["generic_name"] : $article["description"];
|
else $article["generic"] = $product["generic_name"];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$article["nutri-score"] = "";
|
||||||
|
$article["generic"] = "";
|
||||||
|
$article["ingredients"] = "";
|
||||||
|
}
|
||||||
array_push($formatted_articles, $article);
|
array_push($formatted_articles, $article);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,8 +108,9 @@ class PostHandler
|
||||||
$productSlug = 'produit';
|
$productSlug = 'produit';
|
||||||
$url = 'https://{country}.openfoodfacts.org/api/v0/{product}/{scan}.json';
|
$url = 'https://{country}.openfoodfacts.org/api/v0/{product}/{scan}.json';
|
||||||
$url = str_replace(['{country}','{product}','{scan}'],[$country,$productSlug,$barcode],$url);
|
$url = str_replace(['{country}','{product}','{scan}'],[$country,$productSlug,$barcode],$url);
|
||||||
$result = file_get_contents($url);
|
$result = json_decode(file_get_contents($url), true);
|
||||||
return json_decode($result, true);
|
if ($result["status"] == 1) return $result["product"];
|
||||||
|
else return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function save_image()
|
private function save_image()
|
||||||
|
|
Loading…
Reference in a new issue