bug fixes

This commit is contained in:
Dorian Zedler 2019-07-16 17:42:33 +02:00
parent 2ed780c537
commit 8fd802e000
2 changed files with 37 additions and 3 deletions

View file

@ -42,6 +42,9 @@ class BlueWeather
}
// -------------------
// - user management -
// -------------------
/**
* Function to login users
@ -85,6 +88,30 @@ class BlueWeather
return $token_hash;
}
/**
* Function to check if a session token exists and get the corresponding user
*
* @param string $session session token
*
* @return int (-1: does not exist; x>0: userId)
*/
public function checkSession($session)
{
$sql = "SELECT * FROM `sessions`
WHERE`session`=\"".$this->_con->real_escape_string($session)."\"";
$result = $this->_con->query($sql);
if (!$result->num_rows > 0) {
return -1;
}
// only one row will be returned
$data = $result->fetch_assoc();
return($data['userId']);
}
// --------------------
// - getter functions -
// --------------------
@ -182,7 +209,7 @@ class BlueWeather
}
}
if (isset($maxVals) && $maxVals > 0 && count($measvalues) > $maxVals) {
if (isset($maxVals) && $maxVals > 0) {
// build the new measvalues array with respect to maxVals for each sensor
$finalMeasvals = array();
@ -198,6 +225,10 @@ class BlueWeather
array_push($rawMeasvalsOfThisSensor, $measvalue);
}
}
if (count($rawMeasvalsOfThisSensor) <= $maxVals) {
continue;
}
// always sum up the same amount of values to get a new array
// which doesn't have more than $maxVals values

View file

@ -7,7 +7,8 @@
*
* @param locId
* @param range (range[from]: from UNIX time; range[to]: to UNIX time)
* @param maxVals (maximum measvals to be transmitted; if more are present in the timespan, the avarage will be calculated)
* @param maxVals (maximum measvals to be transmitted; if more are present
* in the timespan, the avarage will be calculated)
*
* @category Tools
* @package BlueWeather
@ -26,7 +27,9 @@ $blueweather = new BlueWeather($config);
if (isset($_GET['locId'])) {
// get data of given location
$data = $blueweather->getLocationData($_GET['locId'], $_GET['range'], $_GET['maxVals']);
$data = $blueweather->getLocationData(
$_GET['locId'], $_GET['range'], $_GET['maxVals']
);
} else {
$data = $blueweather->getAllLocations();
}