🔒️ Port the help to PDO-based repositories

This commit is contained in:
Kazhnuz 2025-04-13 10:04:57 +02:00
parent ecc7ab1d3f
commit 6104131729
4 changed files with 56 additions and 18 deletions

View file

@ -25,10 +25,12 @@ function index() {
*/ */
function items() { function items() {
global $renderer; global $renderer;
$itemsquery = doquery("SELECT * FROM {{table}} ORDER BY id", "items"); global $itemRepository;
$items = []; $items = [];
while ($itemsrow = mysqli_fetch_array($itemsquery)) { $itemsrowList = $itemRepository->getAllInOrder();
foreach ($itemsrowList as $itemsrow) {
switch ($itemsrow["type"]) { switch ($itemsrow["type"]) {
case "1": case "1":
@ -86,25 +88,28 @@ function items() {
function levels() { function levels() {
global $renderer; global $renderer;
global $controlrow; global $controlrow;
global $spellRepository;
global $db;
$classes = ['class1', 'class2', 'class3']; $classes = ['class1', 'class2', 'class3'];
$spellsquery = doquery("SELECT * FROM {{table}} ORDER BY id", "spells");
$levelsData = []; $levelsData = [];
$spells = []; $spells = [];
while ($spellsrow = mysqli_fetch_array($spellsquery)) { $spellsrowList = $spellRepository->getAllInOrder();
foreach ($spellsrowList as $spellsrow) {
$spells[$spellsrow["id"]] = $spellsrow; $spells[$spellsrow["id"]] = $spellsrow;
} }
//FIXME: Will be improved when classes will have their own table
foreach ($classes as $index => $class) { foreach ($classes as $index => $class) {
$classIndex = $index + 1; $classIndex = $index + 1;
$levelquery = doquery("SELECT id,{$classIndex}_exp,{$classIndex}_hp,{$classIndex}_mp,{$classIndex}_tp,{$classIndex}_strength,{$classIndex}_dexterity,{$classIndex}_spells FROM {{table}} ORDER BY id", "levels");
//FIXME: Will be improved when classes will have their own table and levels will be handled by a formula
$levelquery = $db->doquery("levels", "SELECT id,{$classIndex}_exp,{$classIndex}_hp,{$classIndex}_mp,{$classIndex}_tp,{$classIndex}_strength,{$classIndex}_dexterity,{$classIndex}_spells FROM {{table}} ORDER BY id");
$levelsrowList = $levelquery->fetchAll(PDO::FETCH_ASSOC);
$levels = []; $levels = [];
while ($levelsrow = mysqli_fetch_array($levelquery)) { foreach ($levelsrowList as $levelsrow) {
$spell = ($levelsrow["{$classIndex}_spells"] != 0) ? $spells[$levelsrow["{$classIndex}_spells"]]["name"] : "<span class=\"light\">None</span>"; $spell = ($levelsrow["{$classIndex}_spells"] != 0) ? $spells[$levelsrow["{$classIndex}_spells"]]["name"] : "<span class=\"light\">None</span>";
if ($levelsrow["id"] < 100) { if ($levelsrow["id"] < 100) {
@ -136,10 +141,12 @@ function levels() {
*/ */
function monsters() { function monsters() {
global $renderer; global $renderer;
global $monsterRepository;
$monstersquery = doquery("SELECT * FROM {{table}} ORDER BY id", "monsters");
$monsters = []; $monsters = [];
while ($monstersrow = mysqli_fetch_array($monstersquery)) {
$monstersrowList = $monsterRepository->getAllInOrder();
foreach ($monstersrowList as $monstersrow) {
if ($monstersrow["immune"] == 0) { if ($monstersrow["immune"] == 0) {
$immune = "<span class=\"light\">None</span>"; $immune = "<span class=\"light\">None</span>";
} elseif ($monstersrow["immune"] == 1) { } elseif ($monstersrow["immune"] == 1) {
@ -168,23 +175,24 @@ function monsters() {
* List all spells for the help * List all spells for the help
*/ */
function spells() { function spells() {
global $spellRepository;
global $renderer; global $renderer;
$spellsquery = doquery("SELECT * FROM {{table}} ORDER BY id", "spells");
$spells = []; $spells = [];
while ($spellrow = mysqli_fetch_array($spellsquery)) { $spellrowList = $spellRepository->getAllInOrder();
foreach ($spellrowList as $spellrow) {
$type = match ($spellrow["type"]) { $type = match ($spellrow["type"]) {
"1" => "Heal", 1 => "Heal",
"2" => "Hurt", 2 => "Hurt",
"3" => "Sleep", 3 => "Sleep",
"4" => "+Damage (%)", 4 => "+Damage (%)",
"5" => "+Defense (%)", 5 => "+Defense (%)",
default => "Unknown", default => "Unknown",
}; };
$spells[] = [ $spells[] = [
'color' => $color,
'name' => $spellrow["name"], 'name' => $spellrow["name"],
'cost' => $spellrow["mp"], 'cost' => $spellrow["mp"],
'type' => $type, 'type' => $type,

View file

@ -0,0 +1,10 @@
<?php
/**
* Repository pour la table des objets du jeu
*/
class ItemRepository extends Repository {
public function __construct() {
parent::__construct('items');
}
}

View file

@ -0,0 +1,10 @@
<?php
/**
* Repository pour la table des monstres du jeu
*/
class MonsterRepository extends Repository {
public function __construct() {
parent::__construct('monsters');
}
}

View file

@ -0,0 +1,10 @@
<?php
/**
* Repository pour la table des sports du jeu
*/
class SpellRepository extends Repository {
public function __construct() {
parent::__construct('spells');
}
}