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
     private $dao;
14
     private $dao;
15
     private $uploadBaseDir = '../uploaded_images/';
15
     private $uploadBaseDir = '../uploaded_images/';
16
     private $stockFile = "../data/stock-v2.json";
16
     private $stockFile = "../data/stock-v2.json";
17
+    private $stockFileV3 = "../data/stock-v3.json";
17
     private $imageBaseUrl = "https://etud.insa-toulouse.fr/~proximo/uploaded_images/";
18
     private $imageBaseUrl = "https://etud.insa-toulouse.fr/~proximo/uploaded_images/";
18
 
19
 
19
     private $responseArray = array(
20
     private $responseArray = array(
64
     public function write_json()
65
     public function write_json()
65
     {
66
     {
66
         $result = 0;
67
         $result = 0;
68
+        // V2
67
         $fp = fopen($this->stockFile, "w");
69
         $fp = fopen($this->stockFile, "w");
68
         $array = array(
70
         $array = array(
69
             "types" => $this->dao->get_categories(),
71
             "types" => $this->dao->get_categories(),
71
         );
73
         );
72
         fwrite($fp, json_encode($array));
74
         fwrite($fp, json_encode($array));
73
         fclose($fp);
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
         $this->responseArray["data"] = $result;
85
         $this->responseArray["data"] = $result;
76
         return $this->responseArray;
86
         return $this->responseArray;
89
         return $formatted_articles;
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
     private function save_image()
115
     private function save_image()
93
     {
116
     {
94
         $success = true;
117
         $success = true;

Loading…
Cancel
Save