-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_railroad.php
130 lines (115 loc) · 4.38 KB
/
db_railroad.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
include_once('database.php');
/* Railroad class */
class railroad extends database {
/* Class constructor.
* ARGUMENTS: None.
*/
public function __construct()
{
parent::__construct('localhost', 'root', '', 'railroad');
} /* End of 'railroad' constructor */
/* Add wagon event (arrival at station) function.
* ARGUMENTS:
* array with fields: $station_id, $train_in, $train_out, $wagon_id, $urgency, $date_in, $date_out, $is_full, $departure, $destination;
* RETURNS: None.
*/
public function addWagonEvent( $data ) {
parent::insertIntoTable('wagon_turnover', $data);
} /* End of 'addWagonEvent' function */
/* Add wagon events (arrival at station) function.
* ARGUMENTS:
* array with fields: $station_id, $train_in, $train_out, $wagon_id, $urgency, $date_in, $date_out, $is_full, $departure, $destination;
* RETURNS: None.
*/
public function addWagonEvents( $data ) {
parent::insertManyIntoTable('wagon_turnover', $data);
} /* End of 'addWagonEvent' function */
/* Add station ro RAILROAD base function.
* ARGUMENTS:
* - railroad database:
* database $db;
* - name, code, lon, lat:
* $name, $code, $lon, $lat;
* RETURNS: None.
*/
public function addStation( $name, $code, $lon, $lat )
{
/* Insert into STATIONS table */
$row = array('\'' . $name . '\'', $code, $lon, $lat);
parent::insertIntoTable('stations', $row);
} /* End of 'addStation' function */
/* Find station by coordinates in RAILROAD base function.
* ARGUMENTS:
* - coordinates:
* $lon, $lat;
* RETURNS:
* station info.
*/
public function findStationByCoordinate( $lon, $lat ) {
$q = parent::selectWhatFromTableWhere('stations', '*', 'longitude = ' . $lon . ' and altitude = ' . $lat);
return $q[0];
} /* End of 'findStation' function */
/* Find station by code in RAILROAD base function.
* ARGUMENTS:
* - code:
* $code;
* RETURNS:
* station info.
*/
public function findStationByCode( $code ) {
$q = parent::selectWhatFromTableWhere('stations', '*', 'code = ' . $code);
return $q[0];
} /* End of 'findStation' function */
/* Add path to RAILROAD base function.
* ARGUMENTS:
* - railroad database:
* database $db;
* - lon, lat of 1 and 2 stations:
* $lon1, $lat1, $lon2, $lat2;
* RETURNS: None.
*/
public function addPath( $lon1, $lat1, $lon2, $lat2 )
{
$code1 = parent::selectWhatFromTableWhere('stations', 'code, longitude, altitude', 'longitude = ' . $lon1 . ' AND altitude = ' . $lat1);
$code2 = parent::selectWhatFromTableWhere('stations', 'code, longitude, altitude', 'longitude = ' . $lon2 . ' AND altitude = ' . $lat2);
/* Insert into PATHS table */
$row = array($code1[0]['code'], $code1[0]['longitude'], $code1[0]['altitude'],
$code2[0]['code'], $code2[0]['longitude'], $code2[0]['altitude']);
parent::insertIntoTable('paths', $row);
} /* End of 'addStation' function */
/* Show station function.
* ARGUMENTS:
* - name, code, lon, lat:
* $name, $code, $lon, $lat;
* RETURNS: None.
*/
public function showStations( $data, $paths )
{
$len = count($data);
$dstr = '[';
for ($i = 0; $i < $len; $i++) {
$dstr = $dstr .
"{name: '" . $data[$i]['name'] . "', code: " . $data[$i]['code'] . ", lon: " . $data[$i]['longitude'] . ", lat: " . $data[$i]['altitude'] . "},\n";
}
$dstr = $dstr . ']';
$len = count($paths);
$pstr = '[';
for ($i = 0; $i < $len; $i++) {
$pstr = $pstr .
"{LonFrom: " . $paths[$i]['LonFrom'] . ", LatFrom: " . $paths[$i]['LatFrom'] .
", LonTo: " . $paths[$i]['LonTo'] . ", LatTo: " . $paths[$i]['LatTo'] . "},\n";
}
$pstr = $pstr . ']';
echo
'showStations(' . $dstr . ', ' . $pstr . ');';
} /* End of 'showStation' function */
/* Get all stations function.
* ARGUMENTS: None.
* RETURNS:
* (array) stations array.
*/
} /* End of 'railroad ' class */
/* Global variable - railroad database interface */
$GLOBALS['r'] = new railroad();
?>