From 8fc7bef7f207c9b573b056b1f0f0b2e840044385 Mon Sep 17 00:00:00 2001 From: overflowerror Date: Sun, 28 Jul 2024 00:03:17 +0200 Subject: [PATCH] feat: Show random mobs in UI --- html/index.php | 19 +++++++++++++++++++ html/styles/main.css | 22 ++++++++++++++++++++++ lib/rating.php | 18 ++++++++++++++++++ migrations/0001_mobsMatchesAndRating.sql | 22 +++++++++++++++++++++- view/fragments/mob.php | 6 ++++++ view/fragments/mobSelection.php | 13 +++++++++++++ view/layout.php | 14 ++++++++++++++ 7 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 html/index.php create mode 100644 html/styles/main.css create mode 100644 lib/rating.php create mode 100644 view/fragments/mob.php create mode 100644 view/fragments/mobSelection.php create mode 100644 view/layout.php diff --git a/html/index.php b/html/index.php new file mode 100644 index 0000000..6c5033d --- /dev/null +++ b/html/index.php @@ -0,0 +1,19 @@ +query("SELECT * FROM mm_mobs WHERE enabled = true"); + $result = $result->fetchAll(PDO::FETCH_ASSOC); + return $result[array_rand($result)]; +} + +function getEloForMob(int $mob): int { + global $pdo; + $query = $pdo->prepare("SELECT * FROM mm_current_rating WHERE mob = ?"); + $query->execute([$mob]); + $result = $query->fetch(PDO::FETCH_ASSOC); + return $result["rating"]; +} \ No newline at end of file diff --git a/migrations/0001_mobsMatchesAndRating.sql b/migrations/0001_mobsMatchesAndRating.sql index e6bf2f3..ed8c6a6 100644 --- a/migrations/0001_mobsMatchesAndRating.sql +++ b/migrations/0001_mobsMatchesAndRating.sql @@ -112,4 +112,24 @@ SELECT mob, last_update FROM rating; - +CREATE VIEW mm_current_rating(mob, rating, last_update) AS +SELECT mob, + rating, + last_update +FROM mm_rating +WHERE last_update = ( + ( + SELECT max(matches_with_default.id) AS max + FROM ( + SELECT + mm_matches_of_mob.id, + mm_matches_of_mob.mob + FROM mm_matches_of_mob + UNION + SELECT + 0, + mm_rating.mob + ) matches_with_default + WHERE matches_with_default.mob = mm_rating.mob + ) +); diff --git a/view/fragments/mob.php b/view/fragments/mob.php new file mode 100644 index 0000000..22d2905 --- /dev/null +++ b/view/fragments/mob.php @@ -0,0 +1,6 @@ +
+ ">
+
+
+
+
\ No newline at end of file diff --git a/view/fragments/mobSelection.php b/view/fragments/mobSelection.php new file mode 100644 index 0000000..9bc2af5 --- /dev/null +++ b/view/fragments/mobSelection.php @@ -0,0 +1,13 @@ +
+ +
+ OR +
+ +
diff --git a/view/layout.php b/view/layout.php new file mode 100644 index 0000000..77e287a --- /dev/null +++ b/view/layout.php @@ -0,0 +1,14 @@ + + + + <?php echo $title ?? ""; ?> + + + + + +