mirror of
https://codeberg.org/vlw/vlw.se.git
synced 2025-09-13 21:13:40 +02:00
111 lines
No EOL
3 KiB
PHP
111 lines
No EOL
3 KiB
PHP
<?php
|
|
|
|
use Reflect\{Response, Path};
|
|
use ReflectRules\{Ruleset, Rules, Type};
|
|
|
|
use VLW\Database\Database;
|
|
use VLW\Database\Tables\Battlestation\{
|
|
CpuTable,
|
|
ClassEnum
|
|
};
|
|
use VLW\Database\Tables\Battlestation\Config\MbCpuCoolerModel;
|
|
|
|
require_once Path::root("src/Database/Database.php");
|
|
require_once Path::root("src/Database/Models/Battlestation/Cpu.php");
|
|
require_once Path::root("src/Database/Models/Battlestation/Config/MbCpuCooler.php");
|
|
|
|
class GET_BattlestationCpu extends Database {
|
|
private const REL_MOTHERBOARDS = "motherboards";
|
|
|
|
protected Ruleset $ruleset;
|
|
|
|
private array $query;
|
|
private array $results = [];
|
|
|
|
public function __construct() {
|
|
$this->ruleset = new Ruleset(strict: true);
|
|
|
|
$this->ruleset->GET([
|
|
(new Rules(CpuTable::ID->value))
|
|
->type(Type::STRING)
|
|
->min(parent::UUID_LENGTH)
|
|
->max(parent::UUID_LENGTH),
|
|
|
|
(new Rules(CpuTable::CLOCK_BASE->value))
|
|
->type(Type::NUMBER)
|
|
->min(1),
|
|
|
|
(new Rules(CpuTable::CLOCK_TURBO->value))
|
|
->type(Type::NUMBER)
|
|
->min(1),
|
|
|
|
(new Rules(CpuTable::CORE_COUNT_PERFORMANCE->value))
|
|
->type(Type::NUMBER)
|
|
->min(1)
|
|
->max(parent::MYSQL_TINYINT_MAX_LENGTH),
|
|
|
|
(new Rules(CpuTable::CORE_COUNT_EFFICIENCY->value))
|
|
->type(Type::NUMBER)
|
|
->min(1)
|
|
->max(parent::MYSQL_TINYINT_MAX_LENGTH),
|
|
|
|
(new Rules(CpuTable::CORE_THREADS->value))
|
|
->type(Type::NUMBER)
|
|
->min(1)
|
|
->max(parent::MYSQL_TINYINT_MAX_LENGTH),
|
|
|
|
(new Rules(CpuTable::VENDOR_NAME->value))
|
|
->type(Type::STRING)
|
|
->min(1)
|
|
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
|
|
|
(new Rules(CpuTable::VENDOR_MODEL->value))
|
|
->type(Type::STRING)
|
|
->min(1)
|
|
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
|
|
|
|
(new Rules(CpuTable::IS_RETIRED->value))
|
|
->type(Type::BOOLEAN)
|
|
]);
|
|
|
|
parent::__construct(Databases::BATTLESTATION, $this->ruleset);
|
|
|
|
// Use a copy of search parameters
|
|
$this->query = $_GET;
|
|
}
|
|
|
|
private function get_motherboards(): void {
|
|
foreach ($this->results as &$result) {
|
|
// Get motherboard id from relationship by chassis id
|
|
$result[self::REL_MOTHERBOARDS] = $this->db
|
|
->for(MbCpuCoolerModel::NAME)
|
|
->where([MbCpuCoolerModel::REF_CPU_ID->value => $result[CpuTable::ID->value]])
|
|
->select(MbCpuCoolerModel::values())
|
|
->fetch_all(MYSQLI_ASSOC);
|
|
}
|
|
}
|
|
|
|
private function get_cpu(): array {
|
|
return $this->results = $this->db
|
|
->for(CpuTable::NAME)
|
|
->where($this->query)
|
|
->order([CpuTable::DATE_AQUIRED->value => "DESC"])
|
|
->select(CpuTable::values())
|
|
->fetch_all(MYSQLI_ASSOC);
|
|
}
|
|
|
|
public function main(): Response {
|
|
// Set properties as "searchable"
|
|
parent::make_wildcard_search(CpuTable::VENDOR_NAME->value, $this->query);
|
|
parent::make_wildcard_search(CpuTable::VENDOR_MODEL->value, $this->query);
|
|
|
|
// Get hardware
|
|
$this->get_cpu();
|
|
|
|
// Resolve hardware relationships
|
|
$this->get_motherboards();
|
|
|
|
// Return 404 Not Found if response array is empty
|
|
return new Response($this->results, $this->results ? 200 : 404);
|
|
}
|
|
} |