Browse Source

sort stops; get all routes

tags/v1.0.0
Robin Thoni 7 years ago
parent
commit
760e5a7f3a

+ 33
- 1
app/Business/RoutesBusiness.php View File

@@ -9,6 +9,8 @@
9 9
 namespace App\Business;
10 10
 
11 11
 use App\DataAccess\RoutesDataAccess;
12
+use App\Dbo\RoutesDbo;
13
+use Luticate\Utils\Dbo\LuPaginatedDbo;
12 14
 
13 15
 class RoutesBusiness
14 16
 {
@@ -16,9 +18,39 @@ class RoutesBusiness
16 18
     {
17 19
         return new RoutesDataAccess();
18 20
     }
21
+    public static function containsRouteId(array $routes, string $id)
22
+    {
23
+        /**
24
+         * @var $routes RoutesDbo[]
25
+         */
26
+        foreach ($routes as $route) {
27
+            if ($route->getId() == $id) {
28
+                return true;
29
+            }
30
+        }
31
+        return false;
32
+    }
19 33
 
20 34
     public static function getAll()
21 35
     {
22
-        return static::getDataAccess()->getAll();
36
+        $config = MiscBusiness::getConfig();
37
+        $dbos = [];
38
+        foreach ($config["scheduleTypes"] as $scheduleType) {
39
+            $scheduleDbos = static::getDataAccess()->getAll($scheduleType["resourceId"], $scheduleType["type"]);
40
+            foreach ($scheduleDbos as $scheduleDbo) {
41
+                if (!static::containsRouteId($dbos, $scheduleDbo->getId())) {
42
+                    $dbos[] = $scheduleDbo;
43
+                }
44
+            }
45
+        }
46
+        usort($dbos, function ($dbo1, $dbo2)
47
+        {
48
+            /**
49
+             * @var $dbo1 RoutesDbo
50
+             * @var $dbo2 RoutesDbo
51
+             */
52
+            return intval($dbo1->getId()) > intval($dbo2->getId());
53
+        });
54
+        return new LuPaginatedDbo(count($dbos), $dbos);
23 55
     }
24 56
 }

+ 5
- 1
app/Business/StopsBusiness.php View File

@@ -61,7 +61,11 @@ class StopsBusiness
61 61
         }
62 62
         usort($dbos, function ($dbo1, $dbo2)
63 63
         {
64
-            return $dbo1->getId() > $dbo2->getId();
64
+            /**
65
+             * @var $dbo1 StopsDbo
66
+             * @var $dbo2 StopsDbo
67
+             */
68
+            return intval($dbo1->getId()) > intval($dbo2->getId());
65 69
         });
66 70
         return new LuPaginatedDbo(count($dbos), $dbos);
67 71
     }

+ 18
- 4
app/DataAccess/RoutesDataAccess.php View File

@@ -8,16 +8,30 @@
8 8
 
9 9
 namespace App\DataAccess;
10 10
 
11
+use App\Dbo\RoutesDbo;
11 12
 use GuzzleHttp\Client;
12 13
 use Luticate\Utils\Controller\LuticateApplication;
13
-use Luticate\Utils\Dbo\LuPaginatedDbo;
14 14
 
15 15
 class RoutesDataAccess
16 16
 {
17
-    public static function getAll()
17
+    public static function getAll(string $resourceId, string $type)
18 18
     {
19 19
         $client = new Client();
20
-        $response = $client->request("GET", LuticateApplication::getInstance()->getSetting("API_ENTRYPOINT") . "");
21
-        return new LuPaginatedDbo();
20
+        $entrypoint = LuticateApplication::getInstance()->getSetting("API_ENTRYPOINT");
21
+        $response = $client->request("GET", $entrypoint . "transit/${resourceId}/${type}/routes.json");
22
+        $data = json_decode($response->getBody(), true);
23
+        /**
24
+         * @var $dbos RoutesDbo[]
25
+         */
26
+        $dbos = [];
27
+        foreach ($data["data"] as $route) {
28
+            $dbo = new RoutesDbo();
29
+            $dbo->setId($route["id"]);
30
+            $dbo->setName($route["name"]);
31
+            $dbo->setBgColor($route["color"]);
32
+            $dbo->setFgColor($route["text_color"]);
33
+            $dbos[] = $dbo;
34
+        }
35
+        return $dbos;
22 36
     }
23 37
 }

+ 2
- 3
app/DataAccess/StopsDataAccess.php View File

@@ -8,15 +8,14 @@
8 8
 
9 9
 namespace App\DataAccess;
10 10
 
11
-
12
-use App\Business\MiscBusiness;
11
+use App\Dbo\RoutesDbo;
13 12
 use App\Dbo\StopsDbo;
14 13
 use GuzzleHttp\Client;
15 14
 use Luticate\Utils\Controller\LuticateApplication;
16
-use Luticate\Utils\Dbo\LuPaginatedDbo;
17 15
 
18 16
 class StopsDataAccess
19 17
 {
18
+
20 19
     public static function getAll(string $resourceId, string $type)
21 20
     {
22 21
         $client = new Client();

+ 101
- 0
app/Dbo/RoutesDbo.php View File

@@ -0,0 +1,101 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 9/30/16
6
+ * Time: 11:16 PM
7
+ */
8
+
9
+namespace App\Dbo;
10
+
11
+
12
+use Luticate\Utils\Dbo\LuDbo;
13
+
14
+class RoutesDbo extends LuDbo
15
+{
16
+    /**
17
+     * @var $_id string
18
+     */
19
+    protected $_id;
20
+
21
+    /**
22
+     * @var $_name string
23
+     */
24
+    protected $_name;
25
+
26
+    /**
27
+     * @var $_bgColor string
28
+     */
29
+    protected $_bgColor;
30
+
31
+    /**
32
+     * @var $_fgColor string
33
+     */
34
+    protected $_fgColor;
35
+
36
+    /**
37
+     * @return string
38
+     */
39
+    public function getId(): string
40
+    {
41
+        return $this->_id;
42
+    }
43
+
44
+    /**
45
+     * @param string $id
46
+     */
47
+    public function setId(string $id)
48
+    {
49
+        $this->_id = $id;
50
+    }
51
+
52
+    /**
53
+     * @return string
54
+     */
55
+    public function getName(): string
56
+    {
57
+        return $this->_name;
58
+    }
59
+
60
+    /**
61
+     * @param string $name
62
+     */
63
+    public function setName(string $name)
64
+    {
65
+        $this->_name = $name;
66
+    }
67
+
68
+    /**
69
+     * @return string
70
+     */
71
+    public function getBgColor(): string
72
+    {
73
+        return $this->_bgColor;
74
+    }
75
+
76
+    /**
77
+     * @param string $bgColor
78
+     */
79
+    public function setBgColor(string $bgColor)
80
+    {
81
+        $this->_bgColor = $bgColor;
82
+    }
83
+
84
+    /**
85
+     * @return string
86
+     */
87
+    public function getFgColor(): string
88
+    {
89
+        return $this->_fgColor;
90
+    }
91
+
92
+    /**
93
+     * @param string $fgColor
94
+     */
95
+    public function setFgColor(string $fgColor)
96
+    {
97
+        $this->_fgColor = $fgColor;
98
+    }
99
+
100
+
101
+}

Loading…
Cancel
Save