From 3bde82608af566ee853b60122c15b9efc6d5a62d Mon Sep 17 00:00:00 2001 From: ta2edchimp Date: Thu, 8 Oct 2015 21:03:36 +0200 Subject: [PATCH 1/4] Implemented pagination of BattleReports Overview. Closes #86 --- classes/Battle.php | 30 ++++++++++++++++++++++++++ public/themes/default/index.html | 23 ++++++++++++++++++++ routes.php | 8 ++++++- views/index.php | 36 +++++++++++++++++++++++--------- 4 files changed, 86 insertions(+), 11 deletions(-) diff --git a/classes/Battle.php b/classes/Battle.php index 4959238..8e1e81c 100644 --- a/classes/Battle.php +++ b/classes/Battle.php @@ -738,6 +738,13 @@ public static function getList(array $options = array()) { $limit = " limit :limit"; $params["limit"] = intval($options["count"]); } + if (isset($options["page"]) && is_int($options["page"])) { + if (!isset($options["count"]) || empty($options["count"])) { + $params["limit"] = 10; + } + $limit = " limit :offset, :limit"; + $params["offset"] = (intval($options["page"]) - 1) * $params["limit"]; + } } $db = Db::getInstance(); @@ -772,6 +779,29 @@ public static function getList(array $options = array()) { } + public static function getBattlesCount(array $options = array()) { + + $battlesCount = 0; + + $onlyPublished = isset($options["onlyPublished"]) && is_bool($options["onlyPublished"]) ? $options["onlyPublished"] : true; + + $db = \Db::getInstance(); + + $result = $db->single( + "select count(battleReportID) as battlesCount " . + "from brBattles " . + "where brDeleteTime is NULL " . + ($onlyPublished ? "and brPublished = 1 " : "") + ); + + if ($result !== NULL && $result !== FALSE) { + $battlesCount = $result; + } + + return $battlesCount; + + } + public static function updateStats($battleReportID = 0) { if ($battleReportID <= 0) { return false; diff --git a/public/themes/default/index.html b/public/themes/default/index.html index 58f8f0a..a08fe5a 100644 --- a/public/themes/default/index.html +++ b/public/themes/default/index.html @@ -7,7 +7,11 @@

{{ BR_OWNER }}'s BattleReports

{% if battleList|length == 0 %}
+ {% if currentPage <= 1 %} No Battles stored in {{ BR_OWNER }}'s BattleReporter yet. + {% else %} + There are no Battles stored from this far ago ... + {% endif %}
{% else %} @@ -62,6 +66,25 @@

{{ BR_OWNER }}'s BattleReports

{% endif %} + {% if totalPages > 1 %} +
+ +
+ {% endif %} {% endblock %} {% block scripts %} diff --git a/routes.php b/routes.php index 0d97235..ca55839 100644 --- a/routes.php +++ b/routes.php @@ -18,8 +18,14 @@ * Default routings */ // Homepage -$app->get('/', function () use ($app, $db) { +$app->get('/(page/:currentPage)', function ($currentPage = 0) use ($app, $db) { + if (empty($currentPage) || !is_numeric($currentPage)) { + $currentPage = 1; + } else { + $currentPage = intval($currentPage); + } + include("views/index.php"); }); diff --git a/views/index.php b/views/index.php index 3185282..ef26a4c 100644 --- a/views/index.php +++ b/views/index.php @@ -1,10 +1,26 @@ !(User::isLoggedIn() && User::can("edit")) +)); + +$output["currentPage"] = $currentPage; +$output["totalPages"] = intval(floor($battlesCountTotal / 20) + 1); + $params = array(); $battleList = Battle::getList(array( + "page" => $currentPage, + "count" => 20, "onlyPublished" => !(User::isLoggedIn() && User::can("edit")) )); @@ -34,17 +50,17 @@ $output["battleList"] = $battleList; - $previewEfficiencyAvg = ($previewEfficiencyAvg * 100) / $previewBattlesTotal; + // $previewEfficiencyAvg = ($previewEfficiencyAvg * 100) / $previewBattlesTotal; - if ($previewISKdestroyed < 1000000000000) { - if ($previewISKdestroyed < 1000000000) { - $previewISKdestroyed = number_format($previewISKdestroyed / 1000000, 2, '.', ',') . " million"; - } else { - $previewISKdestroyed = number_format($previewISKdestroyed / 1000000000, 2, '.', ',') . " billion"; - } - } else { - $previewISKdestroyed = number_format($previewISKdestroyed / 1000000000000, 2, '.', ',') . " trillion"; - } + // if ($previewISKdestroyed < 1000000000000) { + // if ($previewISKdestroyed < 1000000000) { + // $previewISKdestroyed = number_format($previewISKdestroyed / 1000000, 2, '.', ',') . " million"; + // } else { + // $previewISKdestroyed = number_format($previewISKdestroyed / 1000000000, 2, '.', ',') . " billion"; + // } + // } else { + // $previewISKdestroyed = number_format($previewISKdestroyed / 1000000000000, 2, '.', ',') . " trillion"; + // } } From 00f0a5e57c2880099a03dd34ad5f0ba17e75e03e Mon Sep 17 00:00:00 2001 From: ta2edchimp Date: Thu, 8 Oct 2015 21:19:45 +0200 Subject: [PATCH 2/4] Change imageserver links. Closes #93 --- public/themes/default/base.html | 2 +- public/themes/default/components/brCombatant.html | 2 +- public/themes/default/components/brFootage.html | 2 +- public/themes/default/show.html | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/public/themes/default/base.html b/public/themes/default/base.html index c2b7019..ecf6df0 100644 --- a/public/themes/default/base.html +++ b/public/themes/default/base.html @@ -59,7 +59,7 @@