diff --git a/controllers/site/help.php b/controllers/site/help.php
index 9c70f09..7803335 100644
--- a/controllers/site/help.php
+++ b/controllers/site/help.php
@@ -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"] : "None";
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 = "None";
} 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,
diff --git a/kernel/repositories/items.php b/kernel/repositories/items.php
new file mode 100644
index 0000000..88112fc
--- /dev/null
+++ b/kernel/repositories/items.php
@@ -0,0 +1,10 @@
+