Browse Source

Add V3 api Export

This is an experimental feature
docjyJ 3 years ago
parent
commit
01581a61d7
1 changed files with 23 additions and 0 deletions
  1. 23
    0
      classes/postHandler.php

+ 23
- 0
classes/postHandler.php View File

@@ -14,6 +14,7 @@ class PostHandler
14 14
     private $dao;
15 15
     private $uploadBaseDir = '../uploaded_images/';
16 16
     private $stockFile = "../data/stock-v2.json";
17
+    private $stockFileV3 = "../data/stock-v3.json";
17 18
     private $imageBaseUrl = "https://etud.insa-toulouse.fr/~proximo/uploaded_images/";
18 19
 
19 20
     private $responseArray = array(
@@ -64,6 +65,7 @@ class PostHandler
64 65
     public function write_json()
65 66
     {
66 67
         $result = 0;
68
+        // V2
67 69
         $fp = fopen($this->stockFile, "w");
68 70
         $array = array(
69 71
             "types" => $this->dao->get_categories(),
@@ -71,6 +73,14 @@ class PostHandler
71 73
         );
72 74
         fwrite($fp, json_encode($array));
73 75
         fclose($fp);
76
+        // V3
77
+        $fp = fopen($this->stockFileV3, "w");
78
+        $array = array(
79
+            "types" => $this->dao->get_categories(),
80
+            "articles" => $this->get_articles_json_list_V3(),
81
+        );
82
+        fwrite($fp, json_encode($array));
83
+        fclose($fp);
74 84
 
75 85
         $this->responseArray["data"] = $result;
76 86
         return $this->responseArray;
@@ -89,6 +99,19 @@ class PostHandler
89 99
         return $formatted_articles;
90 100
     }
91 101
 
102
+    public function get_articles_json_list_V3()
103
+    {
104
+        $articles = $this->dao->get_articles();
105
+        $formatted_articles = [];
106
+        foreach ($articles as $article) {
107
+            $article["type"] = $this->dao->get_categories_of_article($article["id"]);
108
+            $article["image"] = $this->imageBaseUrl . $article["id"] . ".jpg";
109
+            array_push($formatted_articles, $article);
110
+        }
111
+
112
+        return $formatted_articles;
113
+    }
114
+
92 115
     private function save_image()
93 116
     {
94 117
         $success = true;

Loading…
Cancel
Save