Dragon-Knight/server/models/Classes.php

29 lines
806 B
PHP

<?php
class Classes
{
public static function all(): array|false
{
$res = App::$db->q("SELECT * FROM classes");
return $res->fetchAll() ?: false;
}
public static function get(int $id): array|false
{
$res = App::$db->do("SELECT * FROM classes WHERE id = ?", [$id]);
return $res->fetch() ?: false;
}
public static function spells(int $id): array|false
{
$res = App::$db->do("SELECT level, spell_id FROM class_spells WHERE class_id = ?", [$id]);
return $res->fetchAll() ?: false;
}
public static function spellsAtLevel(int $id, int $level): array|false
{
// get all spells for the class under or equal to the level
$ids = App::$db->do("SELECT spell_id FROM class_spells WHERE class_id = ? AND level <= ?", [$id, $level]);
return $ids->fetchAll(PDO::FETCH_COLUMN) ?: false;
}
}