Browse Source

added settings backup/restore

tags/v1.0.0^0
Robin Thoni 7 years ago
parent
commit
3f2d5ac5e0

+ 32
- 0
app/Business/UsersSettingsBusiness.php View File

@@ -0,0 +1,32 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 10/3/16
6
+ * Time: 6:05 PM
7
+ */
8
+
9
+namespace App\Business;
10
+
11
+
12
+use App\DataAccess\UsersSettingsDataAccess;
13
+use Luticate\Utils\Business\LuBusiness;
14
+
15
+class UsersSettingsBusiness extends LuBusiness
16
+{
17
+    public static function getDataAccess()
18
+    {
19
+        return new UsersSettingsDataAccess();
20
+    }
21
+
22
+    public static function put(string $settings, string $id)
23
+    {
24
+        return static::getDataAccess()->put($settings, $id);
25
+    }
26
+
27
+    public static function get(string $id)
28
+    {
29
+        return static::getDataAccess()->get($id);
30
+    }
31
+
32
+}

+ 46
- 0
app/Controller/UsersSettingsController.php View File

@@ -0,0 +1,46 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 10/3/16
6
+ * Time: 6:07 PM
7
+ */
8
+
9
+namespace App\Controller;
10
+
11
+
12
+use App\Business\UsersSettingsBusiness;
13
+use Luticate\Utils\Dbo\LuStringDbo;
14
+
15
+class UsersSettingsController
16
+{
17
+    public function getBusiness()
18
+    {
19
+        return new UsersSettingsBusiness();
20
+    }
21
+
22
+    /**
23
+     * Set the encrypted settings to be saved
24
+     * @param LuStringDbo $settings The encrypted settings
25
+     * @param LuStringDbo $id The user facebook id
26
+     * @trim
27
+     * @min 1
28
+     * @return bool
29
+     */
30
+    public function put(LuStringDbo $settings, LuStringDbo $id)
31
+    {
32
+        return static::getBusiness()->put($settings->getString(), $id->getString());
33
+    }
34
+
35
+    /**
36
+     * Get the previously saved encrypted settings
37
+     * @param LuStringDbo $id The user facebook id
38
+     * @trim
39
+     * @min 1
40
+     * @return string
41
+     */
42
+    public function get(LuStringDbo $id)
43
+    {
44
+        return static::getBusiness()->get($id->getString());
45
+    }
46
+}

+ 45
- 0
app/DataAccess/UsersSettingsDataAccess.php View File

@@ -0,0 +1,45 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 10/3/16
6
+ * Time: 6:05 PM
7
+ */
8
+
9
+namespace App\DataAccess;
10
+
11
+
12
+use Luticate\Utils\Controller\LuticateApplication;
13
+
14
+class UsersSettingsDataAccess
15
+{
16
+    public static function getDir()
17
+    {
18
+        $dir = LuticateApplication::getInstance()->getSetting("USERS_SETTING_DIR");
19
+        return __DIR__ . "/../../${dir}/";
20
+    }
21
+
22
+    public static function getFilePath(string $id)
23
+    {
24
+        $dir = static::getDir();
25
+        $filename = preg_replace("([^a-zA-Z0-9])", '_', $id);
26
+        return $dir . $filename;
27
+    }
28
+
29
+    public static function put(string $settings, string $id)
30
+    {
31
+        $filePath = self::getFilePath($id);
32
+        file_put_contents($filePath, $settings);
33
+        return true;
34
+    }
35
+
36
+    public static function get(string $id)
37
+    {
38
+        $filePath = self::getFilePath($id);
39
+        if (file_exists($filePath)) {
40
+            $settings = file_get_contents($filePath);
41
+            return $settings;
42
+        }
43
+        return null;
44
+    }
45
+}

+ 4
- 1
app/routes.php View File

@@ -14,4 +14,7 @@ $route->get("/routes", "Routes", "getAll");
14 14
 
15 15
 $route->get("/stops", "Stops", "getAll");
16 16
 
17
-$route->post("/schedules/multiple", "Schedules", "getMultiple");
17
+$route->post("/schedules/multiple", "Schedules", "getMultiple");
18
+
19
+$route->post("/users/settings", "UsersSettings", "put");
20
+$route->get("/users/settings", "UsersSettings", "get");

+ 2
- 1
config.json View File

@@ -8,6 +8,7 @@
8 8
   ],
9 9
   "settings": {
10 10
     "API_ENTRYPOINT": "http://horaires.sts.saguenay.ca/api/",
11
-    "API_CONFIG_WEBPAGE": "http://horaires.sts.saguenay.ca/"
11
+    "API_CONFIG_WEBPAGE": "http://horaires.sts.saguenay.ca/",
12
+    "USERS_SETTING_DIR": "storage/usersSettings"
12 13
   }
13 14
 }

+ 2
- 0
storage/usersSettings/.gitignore View File

@@ -0,0 +1,2 @@
1
+*
2
+!.gitignore

Loading…
Cancel
Save