Add V3 api Export
This is an experimental feature
This commit is contained in:
parent
7eea3d2fe5
commit
01581a61d7
1 changed files with 23 additions and 0 deletions
|
@ -14,6 +14,7 @@ class PostHandler
|
||||||
private $dao;
|
private $dao;
|
||||||
private $uploadBaseDir = '../uploaded_images/';
|
private $uploadBaseDir = '../uploaded_images/';
|
||||||
private $stockFile = "../data/stock-v2.json";
|
private $stockFile = "../data/stock-v2.json";
|
||||||
|
private $stockFileV3 = "../data/stock-v3.json";
|
||||||
private $imageBaseUrl = "https://etud.insa-toulouse.fr/~proximo/uploaded_images/";
|
private $imageBaseUrl = "https://etud.insa-toulouse.fr/~proximo/uploaded_images/";
|
||||||
|
|
||||||
private $responseArray = array(
|
private $responseArray = array(
|
||||||
|
@ -64,6 +65,7 @@ class PostHandler
|
||||||
public function write_json()
|
public function write_json()
|
||||||
{
|
{
|
||||||
$result = 0;
|
$result = 0;
|
||||||
|
// V2
|
||||||
$fp = fopen($this->stockFile, "w");
|
$fp = fopen($this->stockFile, "w");
|
||||||
$array = array(
|
$array = array(
|
||||||
"types" => $this->dao->get_categories(),
|
"types" => $this->dao->get_categories(),
|
||||||
|
@ -71,6 +73,14 @@ class PostHandler
|
||||||
);
|
);
|
||||||
fwrite($fp, json_encode($array));
|
fwrite($fp, json_encode($array));
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
|
// V3
|
||||||
|
$fp = fopen($this->stockFileV3, "w");
|
||||||
|
$array = array(
|
||||||
|
"types" => $this->dao->get_categories(),
|
||||||
|
"articles" => $this->get_articles_json_list_V3(),
|
||||||
|
);
|
||||||
|
fwrite($fp, json_encode($array));
|
||||||
|
fclose($fp);
|
||||||
|
|
||||||
$this->responseArray["data"] = $result;
|
$this->responseArray["data"] = $result;
|
||||||
return $this->responseArray;
|
return $this->responseArray;
|
||||||
|
@ -89,6 +99,19 @@ class PostHandler
|
||||||
return $formatted_articles;
|
return $formatted_articles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function get_articles_json_list_V3()
|
||||||
|
{
|
||||||
|
$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()
|
private function save_image()
|
||||||
{
|
{
|
||||||
$success = true;
|
$success = true;
|
||||||
|
|
Loading…
Reference in a new issue