added a way (beta... still need work) to change the sort order.
This commit is contained in:
31
class.php
31
class.php
@@ -102,6 +102,37 @@ class ps4 {
|
||||
|
||||
}
|
||||
|
||||
function games_reorder($games,$orderby="last_played_desc") {
|
||||
function totaltime_asc($a,$b) {
|
||||
return ($a["game_total_time"] <= $b["game_total_time"]) ? -1 : 1;
|
||||
}
|
||||
function totaltime_desc($a,$b) {
|
||||
return ($a["game_total_time"] >= $b["game_total_time"]) ? -1 : 1;
|
||||
}
|
||||
|
||||
|
||||
function firstplayed_asc($a,$b) {
|
||||
return ($a["game_played_first"] <= $b["game_played_first"]) ? -1 : 1;
|
||||
}
|
||||
function firstplayed_desc($a,$b) {
|
||||
return ($a["game_played_first"] >= $b["game_played_first"]) ? -1 : 1;
|
||||
}
|
||||
|
||||
function lastplayed_asc($a,$b) {
|
||||
if ($a["game_played_last"] == -1) { $a["game_played_last"] = (round(microtime(true) * 1000)); }
|
||||
if ($b["game_played_last"] == -1) { $b["game_played_last"] = (round(microtime(true) * 1000)); }
|
||||
return ($a["game_played_last"] <= $b["game_played_last"]) ? -1 : 1;
|
||||
}
|
||||
function lastplayed_desc($a,$b) {
|
||||
if ($a["game_played_last"] == -1) { $a["game_played_last"] = (round(microtime(true) * 1000)); }
|
||||
if ($b["game_played_last"] == -1) { $b["game_played_last"] = (round(microtime(true) * 1000)); }
|
||||
return ($a["game_played_last"] >= $b["game_played_last"]) ? -1 : 1;
|
||||
}
|
||||
|
||||
usort($games, $orderby);
|
||||
return $games;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -4,6 +4,8 @@ ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
$orderby = isset($_GET['orderby']) ? $_GET['orderby'] : "lastplayed_desc";
|
||||
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
@@ -14,7 +16,7 @@ error_reporting(E_ALL);
|
||||
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
$( document ).ready(function(){
|
||||
$("#page").load('page.php');
|
||||
$("#page").load('page.php?orderby=<?php echo $orderby ?>');
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
|
||||
14
page.php
14
page.php
@@ -5,17 +5,22 @@ $ps4 = new ps4();
|
||||
|
||||
$sql = "SELECT * FROM game_time";
|
||||
$result = $ps4->mysql_conn($sql);
|
||||
|
||||
$orderby = $_GET['orderby'];
|
||||
|
||||
?>
|
||||
|
||||
<strong>Last Updated : </strong> <?php echo date(DATE_RFC2822) ?><br/><br/>
|
||||
|
||||
Order by (<?php echo $orderby; ?>) : Total Time <a href="index.php?orderby=totaltime_asc">ASC</a> <a href="index.php?orderby=totaltime_desc">DESC</a> - First Played <a href="index.php?orderby=firstplayed_asc">ASC</a> <a href="index.php?orderby=firstplayed_desc">DESC</a> - Last Played <a href="index.php?orderby=lastplayed_asc">ASC</a> <a href="index.php?orderby=lastplayed_desc">DESC</a>
|
||||
<br/><br/>
|
||||
|
||||
<?php
|
||||
if ($result->num_rows > 0) {
|
||||
// output data of each row
|
||||
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
|
||||
|
||||
$games[$row["game_id"]]["game_id"] = $row["game_id"];
|
||||
$games[$row["game_id"]]["game_name"] = $row["game_name"];
|
||||
isset($games[$row["game_id"]]["game_total_time"]) ?: $games[$row["game_id"]]["game_total_time"] = 0;
|
||||
@@ -39,11 +44,14 @@ if ($result->num_rows > 0) {
|
||||
}
|
||||
}
|
||||
|
||||
$currentid = "";
|
||||
// reorder
|
||||
sort($games);
|
||||
$games = $ps4->games_reorder($games, $orderby);
|
||||
|
||||
foreach ($games as $key => $value) {
|
||||
echo "<div class=\"game\">";
|
||||
echo "<div class=\"thumbnail\">";
|
||||
echo "<img src=\"".$ps4->thumbnailurl($key)."\" border=0 weight=\"80px\" height=\"80px\" onclick=\"thumbnailupdateurl('". $games[$key]["game_id"] ."', '". $games[$key]["game_name"] ."');\">";
|
||||
echo "<img src=\"".$ps4->thumbnailurl($games[$key]["game_id"])."\" border=0 weight=\"80px\" height=\"80px\" onclick=\"thumbnailupdateurl('". $games[$key]["game_id"] ."', '". $games[$key]["game_name"] ."');\">";
|
||||
echo "</div>";
|
||||
echo "<div class=\"info\">";
|
||||
echo "<strong>". $games[$key]["game_name"] ."</strong> (". $games[$key]["game_id"] .")";
|
||||
|
||||
Reference in New Issue
Block a user