-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReading.php
51 lines (44 loc) · 1.6 KB
/
Reading.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
<?php
class Reading {
public $id;
public $flight;
public $time;
public $altitude;
public $temperature;
public $barometric_pressure;
public $humidity;
public function __construct($data) {
$this->flight = $data[0];
$this->time = $data[1];
$this->altitude = $data[2];
$this->temperature = $data[3];
$this->barometric_pressure = $data[4];
$this->humidity = $data[5];
}
public function save($link, $line) {
//data valdation
$errors = array();
if (!strtotime($this->time)) $errors[] = 'Timestamp';
if (!ctype_digit($this->altitude)) $errors[] = 'Altitude';
if (!is_numeric($this->temperature)) $errors[] = 'Temperature';
if (!ctype_digit($this->barometric_pressure)) $errors[] = 'Barometric Pressure';
if (!is_numeric($this->humidity)) $errors[] = 'Humidity';
if (empty($errors)) {
//putting the values together
$values = "0, ";
$values .= $this->flight.", ";
$values .= "'".$this->time."', ";
$values .= $this->altitude.", ";
$values .= $this->temperature.", ";
$values .= $this->barometric_pressure.", ";
$values .= $this->humidity;
// executing the insertion
if (mysqli_query($link, "INSERT into reading VALUES (".$values.")")) {
return true;
}
} else {
echo "Errors in the line ". $line. ", feilds: ".implode(', ', $errors).EOL;
return false;
}
}
}