diff --git a/api/incidents.php b/api/incidents.php index b597062..28430fe 100644 --- a/api/incidents.php +++ b/api/incidents.php @@ -10,39 +10,10 @@ else{ if (isset($_GET['future']) && $_GET['future'] == true) { - $result = get_incidents(true); + $result = $constellation->get_incidents(true); }else{ - $result = get_incidents(); + $result = $constellation->get_incidents(); } echo json_encode($result); -} - -function get_incidents($future = false){ - global $mysqli; - $c = ($future)?">=":"<="; - $limit = (isset($_GET['limit'])?$_GET['limit']:5); - $offset = (isset($_GET['offset'])?$_GET['offset']:0); - $timestamp = (isset($_GET['timestamp']))?$_GET['timestamp']:time(); - $limit++; - $sql = $mysqli->prepare("SELECT *, status.id as status_id FROM status INNER JOIN users ON user_id=users.id WHERE `time` $c ? AND `end_time` $c ? OR (`time`<=? AND `end_time` $c ? ) ORDER BY `time` DESC LIMIT ? OFFSET ?"); - $sql->bind_param("iiiiii",$timestamp, $timestamp, $timestamp, $timestamp, $limit, $offset); - $sql->execute(); - $query = $sql->get_result(); - $array = []; - $limit--; - $more = false; - if ($query->num_rows>$limit){ - $more = true; - } - if ($query->num_rows){ - while(($result = $query->fetch_assoc()) && $limit-- > 0) - { - $array[] = new Incident($result); - } - } - return [ - "more" => $more, - "incidents" => $array - ]; } \ No newline at end of file diff --git a/classes/constellation.php b/classes/constellation.php index 3682f61..91f3790 100644 --- a/classes/constellation.php +++ b/classes/constellation.php @@ -23,23 +23,24 @@ class Constellation { $offset = 0; } + + $limit = (isset($_GET['limit'])?$_GET['limit']:5); + $offset = (isset($_GET['offset'])?$_GET['offset']:0); + $timestamp = (isset($_GET['timestamp']))?$_GET['timestamp']:time(); + + $incidents = $this->get_incidents($future, $offset, $limit, $timestamp); + $ajax = isset($_GET['ajax']); - $limit++; - $c = ($future)?">=":"<="; - $timestamp = (isset($_GET['timestamp'])&& !$future)?$_GET['timestamp']:time(); - $sql = $mysqli->prepare("SELECT *, status.id as status_id FROM status INNER JOIN users ON user_id=users.id WHERE `time` $c ? AND `end_time` $c ? OR (`time`<=? AND `end_time` $c ? ) ORDER BY `time` DESC LIMIT ? OFFSET ?"); - $sql->bind_param("iiiiii",$timestamp, $timestamp, $timestamp, $timestamp, $limit, $offset); - $sql->execute(); - $query = $sql->get_result(); - if ($future && $query->num_rows && !$ajax) + + if ($future && count($incidents["incidents"]) && !$ajax) { echo "