From 24e4cf0fb209156e46b3dbe26b190df8006f61e4 Mon Sep 17 00:00:00 2001
From: Maximilian Giller <m.giller@tu-bs.de>
Date: Fri, 4 Feb 2022 23:12:40 +0100
Subject: [PATCH] Simplified objects to array, so that objects can be accessed
 more easily

---
 README.md             | 34 +++++++++++++++++-----------------
 datasets/datasets.php | 14 ++++++++------
 2 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/README.md b/README.md
index f9c05cc..7a847eb 100644
--- a/README.md
+++ b/README.md
@@ -24,19 +24,19 @@ To run the project run `npm run watch`. This starts a parcel instance which auto
 
 ```json
 {
-    "spaces": {
-        "1": {
+    "spaces": [
+        {
             "space_id": "1",
             "name": "AuD",
             "description": "Algorithmen und Datenstrukturen"
         },
-        "6": {
+        {
             "space_id": "6",
             "name": "Sample",
             "description": "Such wow samples"
         },
         ... more spaces
-    }
+    ]
 }
 ```
 
@@ -44,13 +44,13 @@ To run the project run `npm run watch`. This starts a parcel instance which auto
 
 ```json
 {
-    "spaces": {
-        "1": {
+    "spaces": [
+        {
             "space_id": "1",
             "name": "AuD",
             "description": "Algorithmen und Datenstrukturen",
-            "nodes": {
-                "1": {
+            "nodes": [
+                {
                     "node_id": "1",
                     "space_id": "1",
                     "title": "Sortieren",
@@ -63,32 +63,32 @@ To run the project run `npm run watch`. This starts a parcel instance which auto
                         "name": "Vorlesung",
                         "color": "85D0AB"
                     },
-                    "references": {
-                        "35": {
+                    "references": [
+                        {
                             "node_id": "1",
                             "reference_id": "35",
                             "url": "https://tu-bs.de/reference.html"
                         },
                         ... more references
-                    }
+                    ]
                 },
                 ... more nodes
-            },
-            "links": {
-                "9": {
+            ],
+            "links": [
+                {
                     "link_id": "9",
                     "source_node_id": "1",
                     "target_node_id": "10"
                 },
-                "75": {
+                {
                     "link_id": "75",
                     "source_node_id": "65",
                     "target_node_id": "89"
                 },
                 ... more links
-            }
+            ]
         },
         ... more spaces
-    }
+    ]
 }
 ```
diff --git a/datasets/datasets.php b/datasets/datasets.php
index fab0d1a..ef660cd 100644
--- a/datasets/datasets.php
+++ b/datasets/datasets.php
@@ -34,8 +34,10 @@ function kg_get_space()
 
     // Construct payload and insert graph data
     $spaces = ks_spaces_to_array(array($space));
-    $spaces[$space_id]["nodes"] = $nodes;
-    $spaces[$space_id]["links"] = $links;
+    
+    // Assuming that there is only one space in the list, add nodes and links
+    $spaces[0]["nodes"] = $nodes;
+    $spaces[0]["links"] = $links;
 
     $payload = array("spaces" => $spaces);
     echo json_encode($payload);
@@ -53,7 +55,7 @@ function ks_construct_links($raw_links) {
             "target_node_id" => $link->target_node_id
         );
 
-        $array_links[$array_link["link_id"]] = $array_link;
+        $array_links[] = $array_link;
     }
 
     return $array_links;
@@ -81,7 +83,7 @@ function ks_construct_nodes($raw_nodes) {
             "references" => $array_references,
         );
 
-        $array_nodes[$array_node["node_id"]] = $array_node;
+        $array_nodes[] = $array_node;
     }
 
     return $array_nodes;
@@ -106,7 +108,7 @@ function ks_get_references_to_node($node_id)
             "url" => $raw_reference->url
         );
 
-        $array_references[$array_reference["reference_id"]] = $array_reference;
+        $array_references[] = $array_reference;
     }
 
     return $array_references;
@@ -259,7 +261,7 @@ function ks_spaces_to_array($spaces)
             "description" => $space->description
         );
 
-        $array[$space_id] = $array_space;
+        $array[] = $array_space;
     }
 
     return $array;
-- 
GitLab