Compare commits
No commits in common. "3297d18348105b28de97355bf8567b7c63b4b5d2" and "1e2e0134ba1bc71b1045954ec8520499a899e06c" have entirely different histories.
3297d18348
...
1e2e0134ba
2 changed files with 34 additions and 16 deletions
|
|
@ -1,7 +1,9 @@
|
||||||
$('#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: {
|
||||||
|
|
@ -23,7 +25,7 @@ $('#uploadButton').on('click', function () {
|
||||||
self.setType("green");
|
self.setType("green");
|
||||||
} else {
|
} else {
|
||||||
self.setTitle("Erreur");
|
self.setTitle("Erreur");
|
||||||
self.setContent('Une erreur est survenue, merci de réessayer plus tard.<br/><br/>' + response["message"]);
|
self.setContent('Une erreur est survenue, merci de réessayer plus tard.');
|
||||||
self.setType("red");
|
self.setType("red");
|
||||||
}
|
}
|
||||||
}).fail(() => {
|
}).fail(() => {
|
||||||
|
|
|
||||||
|
|
@ -64,19 +64,15 @@ class PostHandler
|
||||||
public function write_json()
|
public function write_json()
|
||||||
{
|
{
|
||||||
$result = 0;
|
$result = 0;
|
||||||
|
$fp = fopen($this->stockFile, "w");
|
||||||
$array = array(
|
$array = array(
|
||||||
"types" => $this->dao->get_categories(),
|
"types" => $this->dao->get_categories(),
|
||||||
"articles" => $this->get_articles_json_list(),
|
"articles" => $this->get_articles_json_list(),
|
||||||
);
|
);
|
||||||
$fp = fopen($this->stockFile, "w");
|
fwrite($fp, json_encode($array));
|
||||||
if ($fp) {
|
fclose($fp);
|
||||||
fwrite($fp, json_encode($array));
|
|
||||||
fclose($fp);
|
|
||||||
$this->responseArray["data"] = $result;
|
|
||||||
} else {
|
|
||||||
$this->setFileErrorResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
$this->responseArray["data"] = $result;
|
||||||
return $this->responseArray;
|
return $this->responseArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,11 +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;
|
||||||
|
|
@ -225,12 +247,6 @@ class PostHandler
|
||||||
$this->responseArray["message"] = "Error: Data processing error";
|
$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)
|
private function get_action($inputData)
|
||||||
{
|
{
|
||||||
if (!in_array($inputData["action"], $this->valid_actions))
|
if (!in_array($inputData["action"], $this->valid_actions))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue