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