Fixed json generation to work with campus mobile app
This commit is contained in:
parent
7bfb239ec4
commit
d9e799a538
3 changed files with 28 additions and 2 deletions
|
@ -20,7 +20,6 @@ $('#uploadButton').on('click', function () {
|
|||
btnClass: "btn-warning",
|
||||
action: async function () {
|
||||
let result = await sendRequest();
|
||||
console.log(result);
|
||||
if (result !== 0) {
|
||||
$.alert({
|
||||
title: "Erreur",
|
||||
|
|
|
@ -35,6 +35,19 @@ class Dao
|
|||
return $cursor->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
public function get_categories_of_article($articleid)
|
||||
{
|
||||
$sql = 'SELECT category_id FROM article_categories WHERE article_id=?';
|
||||
$cursor = $this->conn->prepare($sql);
|
||||
$cursor->execute([$articleid]);
|
||||
$result = $cursor->fetchAll(PDO::FETCH_ASSOC);
|
||||
$final = [];
|
||||
foreach ($result as $row) {
|
||||
array_push($final, $row["category_id"]);
|
||||
}
|
||||
return $final;
|
||||
}
|
||||
|
||||
public function get_article_categories()
|
||||
{
|
||||
$sql = 'SELECT * FROM article_categories';
|
||||
|
|
|
@ -14,6 +14,7 @@ class PostHandler
|
|||
private $dao;
|
||||
private $uploadBaseDir = '../uploaded_images/';
|
||||
private $stockFile = "../data/stock-v2.json";
|
||||
private $imageBaseUrl = "https://etud.insa-toulouse.fr/~proximo/uploaded_images/";
|
||||
|
||||
private $responseArray = array(
|
||||
"status" => 0,
|
||||
|
@ -66,7 +67,7 @@ class PostHandler
|
|||
$fp = fopen($this->stockFile, "w");
|
||||
$array = array(
|
||||
"types" => $this->dao->get_categories(),
|
||||
"articles" => $this->dao->get_articles(),
|
||||
"articles" => $this->get_articles_json_list(),
|
||||
);
|
||||
fwrite($fp, json_encode($array));
|
||||
fclose($fp);
|
||||
|
@ -75,6 +76,19 @@ class PostHandler
|
|||
return $this->responseArray;
|
||||
}
|
||||
|
||||
public function get_articles_json_list()
|
||||
{
|
||||
$articles = $this->dao->get_articles();
|
||||
$formatted_articles = [];
|
||||
foreach ($articles as $article) {
|
||||
$article["type"] = $this->dao->get_categories_of_article($article["id"]);
|
||||
$article["image"] = $this->imageBaseUrl . $article["id"] . ".jpg";
|
||||
array_push($formatted_articles, $article);
|
||||
}
|
||||
|
||||
return $formatted_articles;
|
||||
}
|
||||
|
||||
private function save_image()
|
||||
{
|
||||
$success = true;
|
||||
|
|
Loading…
Reference in a new issue