Fix: last position of given user shown incorrectly

This commit is contained in:
Bartek Fabiszewski 2017-04-09 14:03:13 +02:00
parent 4e76aab584
commit 53043c0057

View File

@ -77,24 +77,32 @@ class uPosition {
return $positionId; return $positionId;
} }
public function getLast() { public function getLast($userId = NULL) {
$query = "SELECT p.id, p.time, p.user_id, p.track_id, if (!empty($userId)) {
p.latitude, p.longitude, p.altitude, p.speed, p.bearing, p.accuracy, p.provider, $where = "WHERE p.user_id = ?";
p.comment, p.image_id, u.login, t.name $params = [ 'i', $userId ];
FROM positions p } else {
LEFT JOIN users u ON (p.user_id = u.id) $where = "";
LEFT JOIN tracks t ON (p.track_id = t.id) $params = NULL;
ORDER BY p.time DESC LIMIT 1"; }
$this->loadWithQuery($query); $query = "SELECT p.id, p.time, p.user_id, p.track_id,
p.latitude, p.longitude, p.altitude, p.speed, p.bearing, p.accuracy, p.provider,
p.comment, p.image_id, u.login, t.name
FROM positions p
LEFT JOIN users u ON (p.user_id = u.id)
LEFT JOIN tracks t ON (p.track_id = t.id)
$where
ORDER BY p.time DESC LIMIT 1";
$this->loadWithQuery($query, $params);
} }
public function getAll($userId = NULL, $trackId = NULL) { public function getAll($userId = NULL, $trackId = NULL) {
$rules = []; $rules = [];
if (!empty($userId)) { if (!empty($userId)) {
$rules[] = "p.user_id='" . self::$db->real_escape_string($userId) ."'"; $rules[] = "p.user_id = '" . self::$db->real_escape_string($userId) ."'";
} }
if (!empty($trackId)) { if (!empty($trackId)) {
$rules[] = "p.track_id='" . self::$db->real_escape_string($trackId) ."'"; $rules[] = "p.track_id = '" . self::$db->real_escape_string($trackId) ."'";
} }
if (!empty($rules)) { if (!empty($rules)) {
$where = "WHERE " . implode(" AND ", $rules); $where = "WHERE " . implode(" AND ", $rules);