wip: 2025-01-28T15:01:10+0100 (1738072870)

This commit is contained in:
Victor Westerlund 2025-01-28 18:15:49 +01:00
parent 2fa62991f9
commit 7313b9b0cd
77 changed files with 1220 additions and 1315 deletions

View file

@ -1,7 +1,17 @@
[api]
date_time_zone = "Europe/Stockholm"
[api_database]
host = ""
user = ""
pass = ""
db = ""
[api_forgejo]
base_url = ""
cache_file = ""
scan_profiles = ""
[api_client]
base_url = "https://api.vlw.one/"
api_key = ""
verify_peer = 0
[time]
date_time_zone = "Europe/Stockholm"

View file

@ -1,7 +1,7 @@
[connect]
host = ""
user = ""
pass = ""
database_host = ""
database_user = ""
database_pass = ""
[databases]
vlw = ""

View file

@ -1,51 +0,0 @@
<?php
use Reflect\Path;
use Reflect\Response;
use ReflectRules\Type;
use ReflectRules\Rules;
use ReflectRules\Ruleset;
use VLW\API\Databases\VLWdb\{
VLWdb,
Databases
};
use VLW\API\Databases\VLWdb\Models\Messages\MessagesModel;
require_once Path::root("src/databases/VLWdb.php");
require_once Path::root("src/databases/models/Messages/Messages.php");
class POST_Messages extends VLWdb {
protected Ruleset $ruleset;
public function __construct() {
$this->ruleset = new Ruleset(strict: true);
$this->ruleset->POST([
(new Rules(MessagesModel::EMAIL->value))
->type(Type::STRING)
->max(255)
->default(null),
(new Rules(MessagesModel::MESSAGE->value))
->required()
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_TEXT_MAX_LENGTH)
]);
parent::__construct(Databases::VLW, $this->ruleset);
}
public function main(): Response {
// Use copy of request body as entity
$entity = $_POST;
$entity[MessagesModel::ID->value] = parent::gen_uuid4();
$entity[MessagesModel::DATE_CREATED->value] = time();
return $this->db->for(MessagesModel::TABLE)->insert($entity) === true
? new Response($entity[MessagesModel::ID->value], 201)
: new Response("Failed to create message", 500);
}
}

View file

@ -1,107 +0,0 @@
<?php
use Reflect\Path;
use Reflect\Response;
use ReflectRules\Type;
use ReflectRules\Rules;
use ReflectRules\Ruleset;
use VLW\API\Databases\VLWdb\{
VLWdb,
Databases
};
use VLW\API\Databases\VLWdb\Models\Work\WorkModel;
require_once Path::root("src/databases/VLWdb.php");
require_once Path::root("src/databases/models/Work/Work.php");
const PARAM_LIMIT = "limit";
class GET_Work extends VLWdb {
protected Ruleset $ruleset;
public function __construct() {
$this->ruleset = new Ruleset(strict: true);
$this->ruleset->GET([
(new Rules(WorkModel::ID->value))
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(WorkModel::TITLE->value))
->type(Type::STRING)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(WorkModel::SUMMARY->value))
->type(Type::STRING)
->max(parent::MYSQL_TEXT_MAX_LENGTH),
(new Rules(WorkModel::IS_LISTED->value))
->type(Type::BOOLEAN)
->default(true),
(new Rules(WorkModel::DATE_MODIFIED->value))
->type(Type::NUMBER)
->min(1)
->max(parent::MYSQL_INT_MAX_LENGTH),
(new Rules(WorkModel::DATE_CREATED->value))
->type(Type::NUMBER)
->min(1)
->max(parent::MYSQL_INT_MAX_LENGTH),
(new Rules(PARAM_LIMIT))
->type(Type::NUMBER)
->type(Type::NULL)
->min(1)
->max(parent::MYSQL_INT_MAX_LENGTH)
->default(null)
]);
parent::__construct(Databases::VLW, $this->ruleset);
}
public function main(): Response {
// Use search parameters from model as filters
$filters = $_GET;
// Unset keys not included in database model from filter
foreach (array_diff(array_keys($_GET), WorkModel::values()) as $k) {
unset($filters[$k]);
}
// Do a wildcard search on the title column if provided
if (array_key_exists(WorkModel::TITLE->value, $_GET)) {
$filters[WorkModel::TITLE->value] = [
"LIKE" => "%{$_GET[WorkModel::TITLE->value]}%"
];
}
// Do a wildcard search on the summary column if provided
if (array_key_exists(WorkModel::SUMMARY->value, $_GET)) {
$filters[WorkModel::SUMMARY->value] = [
"LIKE" => "%{$_GET[WorkModel::SUMMARY->value]}%"
];
}
$response = $this->db->for(WorkModel::TABLE)
->where($filters)
->order([WorkModel::DATE_CREATED->value => "DESC"])
->limit($_GET[PARAM_LIMIT])
->select([
WorkModel::ID->value,
WorkModel::TITLE->value,
WorkModel::SUMMARY->value,
WorkModel::IS_LISTED->value,
WorkModel::DATE_YEAR->value,
WorkModel::DATE_MONTH->value,
WorkModel::DATE_DAY->value,
WorkModel::DATE_MODIFIED->value,
WorkModel::DATE_CREATED->value
]);
return $response->num_rows > 0
? new Response($response->fetch_all(MYSQLI_ASSOC))
: new Response([], 404);
}
}

View file

@ -1,38 +0,0 @@
<?php
use Reflect\Path;
use Reflect\Response;
use ReflectRules\Type;
use ReflectRules\Rules;
use ReflectRules\Ruleset;
use const VLW\API\RESP_DELETE_OK;
use VLW\API\Databases\VLWdb\{
VLWdb,
Databases
};
use VLW\API\Databases\VLWdb\Models\Work\WorkActionsModel;
require_once Path::root("src/databases/VLWdb.php");
require_once Path::root("src/databases/models/WorkActions.php");
class DELETE_WorkActions extends VLWdb {
protected Ruleset $ruleset;
public function __construct() {
parent::__construct();
$this->ruleset = new Ruleset(strict: true);
$this->ruleset->POST([
(new Rules(WorkActionsModel::REF_WORK_ID->value))
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
]);
}
public function main(): Response {
return $this->db->for(WorkActionsModel::TABLE)->delete($_POST) === true
? new Response(RESP_DELETE_OK)
: new Response("Failed to delete action for work entity", 500);
}
}

View file

@ -1,48 +0,0 @@
<?php
use Reflect\Path;
use Reflect\Response;
use ReflectRules\Type;
use ReflectRules\Rules;
use ReflectRules\Ruleset;
use VLW\API\Databases\VLWdb\{
VLWdb,
Databases
};
use VLW\API\Databases\VLWdb\Models\Work\WorkActionsModel;
require_once Path::root("src/databases/VLWdb.php");
require_once Path::root("src/databases/models/Work/WorkActions.php");
class GET_WorkActions extends VLWdb {
protected Ruleset $ruleset;
public function __construct() {
$this->ruleset = new Ruleset(strict: true);
$this->ruleset->GET([
(new Rules(WorkActionsModel::REF_WORK_ID->value))
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
]);
parent::__construct(Databases::VLW, $this->ruleset);
}
public function main(): Response {
$response = $this->db->for(WorkActionsModel::TABLE)
->where($_GET)
->select([
WorkActionsModel::REF_WORK_ID->value,
WorkActionsModel::DISPLAY_TEXT->value,
WorkActionsModel::HREF->value,
WorkActionsModel::CLASS_LIST->value
]);
return $response->num_rows > 0
? new Response(parent::index_array_by_key($response->fetch_all(MYSQLI_ASSOC), WorkActionsModel::REF_WORK_ID->value))
: new Response([], 404);
}
}

View file

@ -1,52 +0,0 @@
<?php
use Reflect\Path;
use Reflect\Response;
use ReflectRules\Type;
use ReflectRules\Rules;
use ReflectRules\Ruleset;
use VLW\API\Databases\VLWdb\{
VLWdb,
Databases
};
use VLW\API\Databases\VLWdb\Models\Work\WorkPermalinksModel;
require_once Path::root("src/databases/VLWdb.php");
require_once Path::root("src/databases/models/Work/WorkPermalinks.php");
class GET_WorkPermalinks extends VLWdb {
protected Ruleset $ruleset;
public function __construct() {
$this->ruleset = new Ruleset(strict: true);
$this->ruleset->GET([
(new Rules(WorkPermalinksModel::ID->value))
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(WorkPermalinksModel::REF_WORK_ID->value))
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
]);
parent::__construct(Databases::VLW, $this->ruleset);
}
public function main(): Response {
$response = $this->db->for(WorkPermalinksModel::TABLE)
->where($_GET)
->select([
WorkPermalinksModel::ID->value,
WorkPermalinksModel::REF_WORK_ID->value,
WorkPermalinksModel::DATE_CREATED->value
]);
return $response->num_rows > 0
? new Response($response->fetch_all(MYSQLI_ASSOC))
: new Response([], 404);
}
}

View file

@ -1,42 +0,0 @@
<?php
use Reflect\Path;
use Reflect\Response;
use ReflectRules\Type;
use ReflectRules\Rules;
use ReflectRules\Ruleset;
use const VLW\API\RESP_DELETE_OK;
use VLW\API\Databases\VLWdb\{
VLWdb,
Databases
};
use VLW\API\Databases\VLWdb\Models\Work\WorkTagsModel;
require_once Path::root("src/databases/VLWdb.php");
require_once Path::root("src/databases/models/Work/WorkTags.php");
class DELETE_WorkTags extends VLWdb {
private Ruleset $ruleset;
public function __construct() {
$this->ruleset = new Ruleset(strict: true);
$this->ruleset->GET([
(new Rules(WorkTagsModel::REF_WORK_ID->value))
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(WorkTagsModel::NAME->value))
->type(Type::ENUM, WorkTagsNameEnum::names())
]);
parent::__construct(Databases::VLW, $this->ruleset);
}
public function main(): Response {
return $this->db->for(WorkTagsModel::TABLE)->delete($_POST) === true
? new Response(RESP_DELETE_OK)
: new Response("Failed to delete value from document", 500);
}
}

View file

@ -1,51 +0,0 @@
<?php
use Reflect\Path;
use Reflect\Response;
use ReflectRules\Type;
use ReflectRules\Rules;
use ReflectRules\Ruleset;
use VLW\API\Databases\VLWdb\{
VLWdb,
Databases
};
use VLW\API\Databases\VLWdb\Models\Work\{
WorkTagsModel,
WorkTagsNameEnum
};
require_once Path::root("src/databases/VLWdb.php");
require_once Path::root("src/databases/models/Work/WorkTags.php");
class GET_WorkTags extends VLWdb {
private Ruleset $ruleset;
public function __construct() {
$this->ruleset = new Ruleset(strict: true);
$this->ruleset->GET([
(new Rules(WorkTagsModel::REF_WORK_ID->value))
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(WorkTagsModel::NAME->value))
->type(Type::ENUM, WorkTagsNameEnum::names())
]);
parent::__construct(Databases::VLW, $this->ruleset);
}
public function main(): Response {
$response = $this->db->for(WorkTagsModel::TABLE)
->where($_GET)
->select([
WorkTagsModel::REF_WORK_ID->value,
WorkTagsModel::NAME->value
]);
return $response->num_rows > 0
? new Response(parent::index_array_by_key($response->fetch_all(MYSQLI_ASSOC), WorkTagsModel::REF_WORK_ID->value))
: new Response([], 404);
}
}

View file

@ -1,63 +0,0 @@
<?php
use Reflect\Call;
use Reflect\Path;
use Reflect\Response;
use ReflectRules\Type;
use ReflectRules\Rules;
use ReflectRules\Ruleset;
use VLW\API\Endpoints;
use VLW\API\Databases\VLWdb\{
VLWdb,
Databases
};
use VLW\API\Databases\VLWdb\Models\Work\{
WorkModel,
WorkTagsModel,
WorkTagsNameEnum
};
require_once Path::root("src/Endpoints.php");
require_once Path::root("src/databases/VLWdb.php");
require_once Path::root("src/databases/models/Work/Work.php");
require_once Path::root("src/databases/models/Work/WorkTags.php");
class POST_WorkTags extends VLWdb {
protected Ruleset $ruleset;
public function __construct() {
$this->ruleset = new Ruleset(strict: true);
$this->ruleset->POST([
(new Rules(WorkTagsModel::REF_WORK_ID->value))
->required()
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(WorkTagsModel::NAME->value))
->required()
->type(Type::ENUM, WorkTagsNameEnum::names())
]);
parent::__construct(Databases::VLW, $this->ruleset);
}
private static function get_entity(): Response {
return (new Call(Endpoints::WORK->value))->params([
WorkModel::ID->value => $_POST[WorkTagsModel::REF_WORK_ID->value]
])->get();
}
public function main(): Response {
// Bail out if work entity could not be fetched
$entity = self::get_entity();
if (!$entity->ok) {
return $entity;
}
return $this->db->for(WorkTagsModel::TABLE)->insert($_POST) === true
? new Response($_POST[WorkTagsModel::REF_WORK_ID->value], 201)
: new Response("Failed to add tag to work entity", 500);
}
}

View file

@ -1,101 +0,0 @@
<?php
namespace VLW\API\Databases\VLWdb;
use Reflect\Path;
use Reflect\Request;
use Reflect\Response;
use ReflectRules\Ruleset;
use vlw\MySQL\MySQL;
enum Databases: string {
case VLW = "vlw";
case BATTLESTATION = "battlestation";
}
class VLWdb {
const UUID_LENGTH = 36;
const MYSQL_INT_MAX_LENGTH = 2147483647;
const MYSQL_TEXT_MAX_LENGTH = 65538;
const MYSQL_VARCHAR_MAX_LENGTH = 255;
const MYSQL_TINYINT_MAX_LENGTH = 255;
protected readonly MySQL $db;
public function __construct(Databases $database, Ruleset $ruleset) {
// Validate provided Ruleset before attempting to connect to the database
self::eval_ruleset_or_exit($ruleset);
// Create new MariaDB connection
$this->db = new MySQL(
$_ENV["connect"]["host"],
$_ENV["connect"]["user"],
$_ENV["connect"]["pass"],
$_ENV["databases"][$database->value],
);
}
// Bail out if provided ReflectRules\Ruleset is invalid
private static function eval_ruleset_or_exit(Ruleset $ruleset): ?Response {
return !$ruleset->is_valid() ? new Response($ruleset->get_errors(), 422) : null;
}
// Generate and return UUID4 string
public static function gen_uuid4(): string {
return sprintf("%04x%04x-%04x-%04x-%04x-%04x%04x%04x",
// 32 bits for "time_low"
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
// 16 bits for "time_mid"
mt_rand(0, 0xffff),
// 16 bits for "time_hi_and_version",
// four most significant bits holds version number 4
mt_rand(0, 0x0fff) | 0x4000,
// 16 bits, 8 bits for "clk_seq_hi_res",
// 8 bits for "clk_seq_low",
// two most significant bits holds zero and one for variant DCE1.1
mt_rand(0, 0x3fff) | 0x8000,
// 48 bits for "node"
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
);
}
// Mutate the value by array key $property_name into a libmysqldriver\MySQL custom operator
// https://codeberg.org/vlw/php-mysql#define-custom-operators
public static function make_wildcard_search(string $property_name, array &$filters): array {
// Bail out if property name is not set in filters array or if its value is null
if (!array_key_exists($property_name, $filters) || $filters[$property_name] === null) {
return $filters;
}
// Mutate filter value into a custom operator array
$filters[$property_name] = [
"LIKE" => "%{$filters[$property_name]}%"
];
return $filters;
}
public function index_array_by_key(array $input, string $key): array {
$output = [];
foreach ($input as $item) {
$idx = $item[$key];
// Create entry for key in output array if first item
if (!array_key_exists($idx, $output)) {
$output[$idx] = [];
}
// Append item to array of array by key
$output[$idx][] = $item;
}
return $output;
}
}

View file

@ -1,14 +0,0 @@
<?php
namespace VLW\API\Databases\VLWdb\Models\Battlestation\Config;
use victorwesterlund\xEnum;
enum ChassisMbModel: string {
use xEnum;
const TABLE = "config_chassis_mb";
case REF_CHASSIS_ID = "ref_chassis_id";
case REF_MB_ID = "ref_mb_id";
}

View file

@ -1,14 +0,0 @@
<?php
namespace VLW\API\Databases\VLWdb\Models\Battlestation\Config;
use victorwesterlund\xEnum;
enum MbGpuModel: string {
use xEnum;
const TABLE = "config_mb_gpu";
case REF_MB_ID = "ref_mb_id";
case REF_GPU_ID = "ref_gpu_id";
}

View file

@ -1,14 +0,0 @@
<?php
namespace VLW\API\Databases\VLWdb\Models\Battlestation\Config;
use victorwesterlund\xEnum;
enum MbPsuModel: string {
use xEnum;
const TABLE = "config_mb_psu";
case REF_MB_ID = "ref_mb_id";
case REF_PSU_ID = "ref_psu_id";
}

View file

@ -1,10 +0,0 @@
<?php
namespace VLW\API\Databases\VLWdb\Models\Work;
enum WorkMediaModel: string {
const TABLE = "work_media";
case ANCHOR = "anchor";
case MEDIA = "media";
}

View file

@ -1,21 +0,0 @@
<?php
namespace VLW\API\Databases\VLWdb\Models\Work;
use victorwesterlund\xEnum;
enum WorkTagsNameEnum {
use xEnum;
case VLW;
case RELEASE;
case WEBSITE;
case REPO;
}
enum WorkTagsModel: string {
const TABLE = "work_tags";
case REF_WORK_ID = "ref_work_id";
case NAME = "name";
}

View file

@ -1,7 +1,9 @@
{
"require": {
"reflect/client": "dev-master",
"victorwesterlund/xenum": "dev-master"
"reflect/plugin-rules": "dev-master",
"vlw/mysql": "dev-master",
"vlw/xenum": "dev-master"
},
"minimum-stability": "dev"
}

83
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "2a8a06dc452a4eb9055d238f771dcd37",
"content-hash": "cb70f9f3f538a72aa8bcf906fdc906bf",
"packages": [
{
"name": "reflect/client",
@ -45,24 +45,18 @@
"time": "2024-04-06T14:55:04+00:00"
},
{
"name": "victorwesterlund/xenum",
"name": "reflect/plugin-rules",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/VictorWesterlund/php-xenum.git",
"reference": "8972f06f42abd1f382807a67e937d5564bb89699"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/VictorWesterlund/php-xenum/zipball/8972f06f42abd1f382807a67e937d5564bb89699",
"reference": "8972f06f42abd1f382807a67e937d5564bb89699",
"shasum": ""
"url": "https://codeberg.org/reflect/rules-plugin",
"reference": "aa7d969350f50d00d7dce01b948276946fcc0e81"
},
"default-branch": true,
"type": "library",
"autoload": {
"psr-4": {
"victorwesterlund\\": "src/"
"ReflectRules\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
@ -75,12 +69,64 @@
"email": "victor.vesterlund@gmail.com"
}
],
"description": "PHP eXtended Enums. The missing quality-of-life features from PHP 8+ Enums",
"support": {
"issues": "https://github.com/VictorWesterlund/php-xenum/issues",
"source": "https://github.com/VictorWesterlund/php-xenum/tree/1.1.1"
"description": "Add request search paramter and request body constraints to an API built with Reflect",
"time": "2024-11-28T17:05:16+00:00"
},
{
"name": "vlw/mysql",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://codeberg.org/vlw/php-mysql",
"reference": "64c7bae3cf6124dcb64c9e8ef93425be3602e82a"
},
"time": "2023-11-20T10:10:39+00:00"
"default-branch": true,
"type": "library",
"autoload": {
"psr-4": {
"vlw\\MySQL\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"GPL-3.0-or-later"
],
"authors": [
{
"name": "Victor Westerlund",
"email": "victor@vlw.se"
}
],
"description": "Abstraction library for common MySQL/MariaDB DML operations with php-mysqli",
"time": "2025-01-16T13:53:30+00:00"
},
{
"name": "vlw/xenum",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://codeberg.org/vlw/php-xenum",
"reference": "1c997a5574656b88a62f5ee160ee5a6439932a2f"
},
"default-branch": true,
"type": "library",
"autoload": {
"psr-4": {
"vlw\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"GPL-3.0-only"
],
"authors": [
{
"name": "Victor Westerlund",
"email": "victor@vlw.se"
}
],
"description": "PHP eXtended Enums. The missing quality-of-life features from PHP 8+ Enums",
"time": "2024-12-02T10:36:32+00:00"
}
],
"packages-dev": [],
@ -88,11 +134,12 @@
"minimum-stability": "dev",
"stability-flags": {
"reflect/client": 20,
"victorwesterlund/xenum": 20
"reflect/plugin-rules": 20,
"vlw/mysql": 20
},
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"plugin-api-version": "2.0.0"
"plugin-api-version": "2.3.0"
}

View file

@ -1,8 +1,7 @@
<?php
use Reflect\Call;
use Reflect\Path;
use Reflect\Response;
use Reflect\{Response, Path};
const MSG_OK = "Cache file deleted";
const MSG_FAIL = "Cache file does not exist or can't be deleted";

View file

@ -1,11 +1,8 @@
<?php
use Reflect\Call;
use Reflect\Path;
use Reflect\Response;
use ReflectRules\Type;
use ReflectRules\Rules;
use ReflectRules\Ruleset;
use Reflect\{Response, Path};
use ReflectRules\{Ruleset, Rules, Type};
use VLW\API\Endpoints;

View file

@ -1,8 +1,7 @@
<?php
use Reflect\Call;
use Reflect\Path;
use Reflect\Response;
use Reflect\{Response, Path};
const ERRNO_CACHE_FAILED = 0;

View file

@ -1,21 +1,15 @@
<?php
use Reflect\Path;
use Reflect\Response;
use ReflectRules\Type;
use ReflectRules\Rules;
use ReflectRules\Ruleset;
use Reflect\{Response, Path};
use ReflectRules\{Ruleset, Rules, Type};
use VLW\API\Databases\VLWdb\{
VLWdb,
Databases
};
use VLW\API\Databases\VLWdb\Models\Battlestation\Config\ConfigModel;
use VLW\Database\Database;
use VLW\Database\Tables\Battlestation\Config\ConfigModel;
require_once Path::root("src/databases/VLWdb.php");
require_once Path::root("src/databases/models/Battlestation/Config/Config.php");
require_once Path::root("src/Database/Database.php");
require_once Path::root("src/Database/Models/Battlestation/Config/Config.php");
class GET_Battlestation extends VLWdb {
class GET_Battlestation extends Database {
protected Ruleset $ruleset;
private array $query;
@ -44,7 +38,7 @@
private function get_config(): array {
return $this->results = $this->db
->for(ConfigModel::TABLE)
->for(ConfigModel::NAME)
->where($this->query)
->order([ConfigModel::DATE_BUILT->value => "DESC"])
->select(ConfigModel::values())

View file

@ -1,23 +1,17 @@
<?php
use Reflect\Path;
use Reflect\Response;
use ReflectRules\Type;
use ReflectRules\Rules;
use ReflectRules\Ruleset;
use Reflect\{Response, Path};
use ReflectRules\{Ruleset, Rules, Type};
use VLW\API\Databases\VLWdb\{
VLWdb,
Databases
};
use VLW\API\Databases\VLWdb\Models\Battlestation\ChassisModel;
use VLW\API\Databases\VLWdb\Models\Battlestation\Config\ChassisMbModel;
use VLW\Database\Database;
use VLW\Database\Tables\Battlestation\ChassisTable;
use VLW\Database\Tables\Battlestation\Config\ChassisMbTable;
require_once Path::root("src/databases/VLWdb.php");
require_once Path::root("src/databases/models/Battlestation/Chassis.php");
require_once Path::root("src/databases/models/Battlestation/Config/ChassisMb.php");
require_once Path::root("src/Database/Database.php");
require_once Path::root("src/Database/Models/Battlestation/Chassis.php");
require_once Path::root("src/Database/Models/Battlestation/Config/ChassisMb.php");
class GET_BattlestationChassis extends VLWdb {
class GET_BattlestationChassis extends Database {
private const REL_MOTHERBOARDS = "motherboards";
protected Ruleset $ruleset;
@ -29,34 +23,34 @@
$this->ruleset = new Ruleset(strict: true);
$this->ruleset->GET([
(new Rules(ChassisModel::ID->value))
(new Rules(ChassisTable::ID->value))
->type(Type::STRING)
->min(parent::UUID_LENGTH)
->max(parent::UUID_LENGTH),
(new Rules(ChassisModel::VENDOR_NAME->value))
(new Rules(ChassisTable::VENDOR_NAME->value))
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(ChassisModel::VENDOR_MODEL->value))
(new Rules(ChassisTable::VENDOR_MODEL->value))
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(ChassisModel::STORAGE_TWOINCHFIVE->value))
(new Rules(ChassisTable::STORAGE_TWOINCHFIVE->value))
->type(Type::NUMBER)
->type(Type::NULL)
->min(0)
->max(parent::MYSQL_TINYINT_MAX_LENGTH),
(new Rules(ChassisModel::STORAGE_THREEINCHFIVE->value))
(new Rules(ChassisTable::STORAGE_THREEINCHFIVE->value))
->type(Type::NUMBER)
->type(Type::NULL)
->min(0)
->max(parent::MYSQL_TINYINT_MAX_LENGTH),
(new Rules(ChassisModel::IS_RETIRED->value))
(new Rules(ChassisTable::IS_RETIRED->value))
->type(Type::BOOLEAN)
]);
@ -70,26 +64,26 @@
foreach ($this->results as &$result) {
// Get motherboard id from relationship by chassis id
$result[self::REL_MOTHERBOARDS] = $this->db
->for(ChassisMbModel::TABLE)
->where([ChassisMbModel::REF_CHASSIS_ID->value => $result[ChassisModel::ID->value]])
->select(ChassisMbModel::values())
->for(ChassisMbTable::NAME)
->where([ChassisMbTable::REF_CHASSIS_ID->value => $result[ChassisTable::ID->value]])
->select(ChassisMbTable::values())
->fetch_all(MYSQLI_ASSOC);
}
}
private function get_chassis(): array {
return $this->results = $this->db
->for(ChassisModel::TABLE)
->for(ChassisTable::NAME)
->where($this->query)
->order([ChassisModel::DATE_AQUIRED->value => "DESC"])
->select(ChassisModel::values())
->order([ChassisTable::DATE_AQUIRED->value => "DESC"])
->select(ChassisTable::values())
->fetch_all(MYSQLI_ASSOC);
}
public function main(): Response {
// Set properties as "searchable"
parent::make_wildcard_search(ChassisModel::VENDOR_NAME->value, $this->query);
parent::make_wildcard_search(ChassisModel::VENDOR_MODEL->value, $this->query);
parent::make_wildcard_search(ChassisTable::VENDOR_NAME->value, $this->query);
parent::make_wildcard_search(ChassisTable::VENDOR_MODEL->value, $this->query);
// Get hardware
$this->get_chassis();

View file

@ -1,25 +1,19 @@
<?php
use Reflect\Path;
use Reflect\Response;
use ReflectRules\Type;
use ReflectRules\Rules;
use ReflectRules\Ruleset;
use Reflect\{Response, Path};
use ReflectRules\{Ruleset, Rules, Type};
use VLW\API\Databases\VLWdb\{
VLWdb,
Databases
};
use VLW\API\Databases\VLWdb\Models\Battlestation\{
use VLW\Database\Database;
use VLW\Database\Tables\Battlestation\{
CoolerModel
};
use VLW\API\Databases\VLWdb\Models\Battlestation\Config\MbCpuCoolerModel;
use VLW\Database\Tables\Battlestation\Config\MbCpuCoolerModel;
require_once Path::root("src/databases/VLWdb.php");
require_once Path::root("src/databases/models/Battlestation/Coolers.php");
require_once Path::root("src/databases/models/Battlestation/Config/MbCpuCooler.php");
require_once Path::root("src/Database/Database.php");
require_once Path::root("src/Database/Models/Battlestation/Coolers.php");
require_once Path::root("src/Database/Models/Battlestation/Config/MbCpuCooler.php");
class GET_BattlestationCoolers extends VLWdb {
class GET_BattlestationCoolers extends Database {
private const REL_MOTHERBOARDS = "motherboards";
protected Ruleset $ruleset;
@ -75,7 +69,7 @@
foreach ($this->results as &$result) {
// Get motherboard id from relationship by chassis id
$result[self::REL_MOTHERBOARDS] = $this->db
->for(MbCoolerModel::TABLE)
->for(MbCoolerModel::NAME)
->where([MbCoolerModel::REF_COOLER_ID->value => $result[CoolerModel::ID->value]])
->select(MbCoolerModel::values())
->fetch_all(MYSQLI_ASSOC);
@ -84,7 +78,7 @@
private function get_coolers(): array {
return $this->results = $this->db
->for(CoolerModel::TABLE)
->for(CoolerModel::NAME)
->where($this->query)
->order([CoolerModel::DATE_AQUIRED->value => "DESC"])
->select(CoolerModel::values())

View file

@ -1,26 +1,20 @@
<?php
use Reflect\Path;
use Reflect\Response;
use ReflectRules\Type;
use ReflectRules\Rules;
use ReflectRules\Ruleset;
use Reflect\{Response, Path};
use ReflectRules\{Ruleset, Rules, Type};
use VLW\API\Databases\VLWdb\{
VLWdb,
Databases
};
use VLW\API\Databases\VLWdb\Models\Battlestation\{
CpuModel,
use VLW\Database\Database;
use VLW\Database\Tables\Battlestation\{
CpuTable,
ClassEnum
};
use VLW\API\Databases\VLWdb\Models\Battlestation\Config\MbCpuCoolerModel;
use VLW\Database\Tables\Battlestation\Config\MbCpuCoolerModel;
require_once Path::root("src/databases/VLWdb.php");
require_once Path::root("src/databases/models/Battlestation/Cpu.php");
require_once Path::root("src/databases/models/Battlestation/Config/MbCpuCooler.php");
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 VLWdb {
class GET_BattlestationCpu extends Database {
private const REL_MOTHERBOARDS = "motherboards";
protected Ruleset $ruleset;
@ -32,45 +26,45 @@
$this->ruleset = new Ruleset(strict: true);
$this->ruleset->GET([
(new Rules(CpuModel::ID->value))
(new Rules(CpuTable::ID->value))
->type(Type::STRING)
->min(parent::UUID_LENGTH)
->max(parent::UUID_LENGTH),
(new Rules(CpuModel::CLOCK_BASE->value))
(new Rules(CpuTable::CLOCK_BASE->value))
->type(Type::NUMBER)
->min(1),
(new Rules(CpuModel::CLOCK_TURBO->value))
(new Rules(CpuTable::CLOCK_TURBO->value))
->type(Type::NUMBER)
->min(1),
(new Rules(CpuModel::CORE_COUNT_PERFORMANCE->value))
(new Rules(CpuTable::CORE_COUNT_PERFORMANCE->value))
->type(Type::NUMBER)
->min(1)
->max(parent::MYSQL_TINYINT_MAX_LENGTH),
(new Rules(CpuModel::CORE_COUNT_EFFICIENCY->value))
(new Rules(CpuTable::CORE_COUNT_EFFICIENCY->value))
->type(Type::NUMBER)
->min(1)
->max(parent::MYSQL_TINYINT_MAX_LENGTH),
(new Rules(CpuModel::CORE_THREADS->value))
(new Rules(CpuTable::CORE_THREADS->value))
->type(Type::NUMBER)
->min(1)
->max(parent::MYSQL_TINYINT_MAX_LENGTH),
(new Rules(CpuModel::VENDOR_NAME->value))
(new Rules(CpuTable::VENDOR_NAME->value))
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(CpuModel::VENDOR_MODEL->value))
(new Rules(CpuTable::VENDOR_MODEL->value))
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(CpuModel::IS_RETIRED->value))
(new Rules(CpuTable::IS_RETIRED->value))
->type(Type::BOOLEAN)
]);
@ -84,8 +78,8 @@
foreach ($this->results as &$result) {
// Get motherboard id from relationship by chassis id
$result[self::REL_MOTHERBOARDS] = $this->db
->for(MbCpuCoolerModel::TABLE)
->where([MbCpuCoolerModel::REF_CPU_ID->value => $result[CpuModel::ID->value]])
->for(MbCpuCoolerModel::NAME)
->where([MbCpuCoolerModel::REF_CPU_ID->value => $result[CpuTable::ID->value]])
->select(MbCpuCoolerModel::values())
->fetch_all(MYSQLI_ASSOC);
}
@ -93,17 +87,17 @@
private function get_cpu(): array {
return $this->results = $this->db
->for(CpuModel::TABLE)
->for(CpuTable::NAME)
->where($this->query)
->order([CpuModel::DATE_AQUIRED->value => "DESC"])
->select(CpuModel::values())
->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(CpuModel::VENDOR_NAME->value, $this->query);
parent::make_wildcard_search(CpuModel::VENDOR_MODEL->value, $this->query);
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();

View file

@ -1,27 +1,21 @@
<?php
use Reflect\Path;
use Reflect\Response;
use ReflectRules\Type;
use ReflectRules\Rules;
use ReflectRules\Ruleset;
use Reflect\{Response, Path};
use ReflectRules\{Ruleset, Rules, Type};
use VLW\API\Databases\VLWdb\{
VLWdb,
Databases
};
use VLW\API\Databases\VLWdb\Models\Battlestation\{
DramModel,
use VLW\Database\Database;
use VLW\Database\Tables\Battlestation\{
DramTable,
DramFormfactorEnum,
DramTechnologyEnum
};
use VLW\API\Databases\VLWdb\Models\Battlestation\Config\MbDramModel;
use VLW\Database\Tables\Battlestation\Config\MbDramTable;
require_once Path::root("src/databases/VLWdb.php");
require_once Path::root("src/databases/models/Battlestation/Dram.php");
require_once Path::root("src/databases/models/Battlestation/Config/MbDram.php");
require_once Path::root("src/Database/Database.php");
require_once Path::root("src/Database/Models/Battlestation/Dram.php");
require_once Path::root("src/Database/Models/Battlestation/Config/MbDram.php");
class GET_BattlestationDram extends VLWdb {
class GET_BattlestationDram extends Database {
private const REL_MOTHERBOARDS = "motherboards";
protected Ruleset $ruleset;
@ -33,42 +27,42 @@
$this->ruleset = new Ruleset(strict: true);
$this->ruleset->GET([
(new Rules(DramModel::ID->value))
(new Rules(DramTable::ID->value))
->type(Type::STRING)
->min(parent::UUID_LENGTH)
->max(parent::UUID_LENGTH),
(new Rules(DramModel::CAPACITY->value))
(new Rules(DramTable::CAPACITY->value))
->type(Type::NUMBER)
->min(1),
(new Rules(DramModel::SPEED->value))
(new Rules(DramTable::SPEED->value))
->type(Type::NUMBER)
->min(1),
(new Rules(DramModel::FORMFACTOR->value))
(new Rules(DramTable::FORMFACTOR->value))
->type(Type::ENUM, DramFormfactorEnum::names()),
(new Rules(DramModel::TECHNOLOGY->value))
(new Rules(DramTable::TECHNOLOGY->value))
->type(Type::ENUM, DramTechnologyEnum::names()),
(new Rules(DramModel::ECC->value))
(new Rules(DramTable::ECC->value))
->type(Type::BOOLEAN),
(new Rules(DramModel::BUFFERED->value))
(new Rules(DramTable::BUFFERED->value))
->type(Type::BOOLEAN),
(new Rules(DramModel::VENDOR_NAME->value))
(new Rules(DramTable::VENDOR_NAME->value))
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(DramModel::VENDOR_MODEL->value))
(new Rules(DramTable::VENDOR_MODEL->value))
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(DramModel::IS_RETIRED->value))
(new Rules(DramTable::IS_RETIRED->value))
->type(Type::BOOLEAN)
]);
@ -82,26 +76,26 @@
foreach ($this->results as &$result) {
// Get motherboard id from relationship by chassis id
$result[self::REL_MOTHERBOARDS] = $this->db
->for(MbDramModel::TABLE)
->where([MbDramModel::REF_DRAM_ID->value => $result[DramModel::ID->value]])
->select(MbDramModel::values())
->for(MbDramTable::NAME)
->where([MbDramTable::REF_DRAM_ID->value => $result[DramTable::ID->value]])
->select(MbDramTable::values())
->fetch_all(MYSQLI_ASSOC);
}
}
private function get_dram(): array {
return $this->results = $this->db
->for(DramModel::TABLE)
->for(DramTable::NAME)
->where($this->query)
->order([DramModel::DATE_AQUIRED->value => "DESC"])
->select(DramModel::values())
->order([DramTable::DATE_AQUIRED->value => "DESC"])
->select(DramTable::values())
->fetch_all(MYSQLI_ASSOC);
}
public function main(): Response {
// Set properties as "searchable"
parent::make_wildcard_search(DramModel::VENDOR_NAME->value, $this->query);
parent::make_wildcard_search(DramModel::VENDOR_MODEL->value, $this->query);
parent::make_wildcard_search(DramTable::VENDOR_NAME->value, $this->query);
parent::make_wildcard_search(DramTable::VENDOR_MODEL->value, $this->query);
// Get hardware
$this->get_dram();

View file

@ -1,23 +1,17 @@
<?php
use Reflect\Path;
use Reflect\Response;
use ReflectRules\Type;
use ReflectRules\Rules;
use ReflectRules\Ruleset;
use Reflect\{Response, Path};
use ReflectRules\{Ruleset, Rules, Type};
use VLW\API\Databases\VLWdb\{
VLWdb,
Databases
};
use VLW\API\Databases\VLWdb\Models\Battlestation\GpuModel;
use VLW\API\Databases\VLWdb\Models\Battlestation\Config\MbGpuModel;
use VLW\Database\Database;
use VLW\Database\Tables\Battlestation\GpuTable;
use VLW\Database\Tables\Battlestation\Config\MbGpuTable;
require_once Path::root("src/databases/VLWdb.php");
require_once Path::root("src/databases/models/Battlestation/Gpu.php");
require_once Path::root("src/databases/models/Battlestation/Config/MbGpu.php");
require_once Path::root("src/Database/Database.php");
require_once Path::root("src/Database/Models/Battlestation/Gpu.php");
require_once Path::root("src/Database/Models/Battlestation/Config/MbGpu.php");
class GET_BattlestationGpu extends VLWdb {
class GET_BattlestationGpu extends Database {
private const REL_MOTHERBOARDS = "motherboards";
protected Ruleset $ruleset;
@ -29,36 +23,36 @@
$this->ruleset = new Ruleset(strict: true);
$this->ruleset->GET([
(new Rules(GpuModel::ID->value))
(new Rules(GpuTable::ID->value))
->type(Type::STRING)
->min(parent::UUID_LENGTH)
->max(parent::UUID_LENGTH),
(new Rules(GpuModel::MEMORY->value))
(new Rules(GpuTable::MEMORY->value))
->type(Type::NUMBER)
->min(1),
(new Rules(GpuModel::VENDOR_NAME->value))
(new Rules(GpuTable::VENDOR_NAME->value))
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(GpuModel::VENDOR_MODEL->value))
(new Rules(GpuTable::VENDOR_MODEL->value))
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(GpuModel::VENDOR_CHIP_NAME->value))
(new Rules(GpuTable::VENDOR_CHIP_NAME->value))
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(GpuModel::VENDOR_CHIP_MODEL->value))
(new Rules(GpuTable::VENDOR_CHIP_MODEL->value))
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(GpuModel::IS_RETIRED->value))
(new Rules(GpuTable::IS_RETIRED->value))
->type(Type::BOOLEAN)
]);
@ -72,28 +66,28 @@
foreach ($this->results as &$result) {
// Get motherboard id from relationship by chassis id
$result[self::REL_MOTHERBOARDS] = $this->db
->for(MbGpuModel::TABLE)
->where([MbGpuModel::REF_GPU_ID->value => $result[GpuModel::ID->value]])
->select(MbGpuModel::values())
->for(MbGpuTable::NAME)
->where([MbGpuTable::REF_GPU_ID->value => $result[GpuTable::ID->value]])
->select(MbGpuTable::values())
->fetch_all(MYSQLI_ASSOC);
}
}
private function get_gpu(): array {
return $this->results = $this->db
->for(GpuModel::TABLE)
->for(GpuTable::NAME)
->where($this->query)
->order([GpuModel::DATE_AQUIRED->value => "DESC"])
->select(GpuModel::values())
->order([GpuTable::DATE_AQUIRED->value => "DESC"])
->select(GpuTable::values())
->fetch_all(MYSQLI_ASSOC);
}
public function main(): Response {
// Set properties as "searchable"
parent::make_wildcard_search(GpuModel::VENDOR_NAME->value, $this->query);
parent::make_wildcard_search(GpuModel::VENDOR_MODEL->value, $this->query);
parent::make_wildcard_search(GpuModel::VENDOR_CHIP_NAME->value, $this->query);
parent::make_wildcard_search(GpuModel::VENDOR_CHIP_MODEL->value, $this->query);
parent::make_wildcard_search(GpuTable::VENDOR_NAME->value, $this->query);
parent::make_wildcard_search(GpuTable::VENDOR_MODEL->value, $this->query);
parent::make_wildcard_search(GpuTable::VENDOR_CHIP_NAME->value, $this->query);
parent::make_wildcard_search(GpuTable::VENDOR_CHIP_MODEL->value, $this->query);
// Get hardware
$this->get_gpu();

View file

@ -1,38 +1,32 @@
<?php
use Reflect\Path;
use Reflect\Response;
use ReflectRules\Type;
use ReflectRules\Rules;
use ReflectRules\Ruleset;
use Reflect\{Response, Path};
use ReflectRules\{Ruleset, Rules, Type};
use VLW\API\Databases\VLWdb\{
VLWdb,
Databases
};
use VLW\API\Databases\VLWdb\Models\Battlestation\{
MbModel,
use VLW\Database\Database;
use VLW\Database\Tables\Battlestation\{
MbTable,
MbFormfactorEnum
};
use VLW\API\Databases\VLWdb\Models\Battlestation\Config\{
MbGpuModel,
MbPsuModel,
MbDramModel,
MbStorageModel,
ChassisMbModel,
use VLW\Database\Tables\Battlestation\Config\{
MbGpuTable,
MbPsuTable,
MbDramTable,
MbStorageTable,
ChassisMbTable,
MbCpuCoolerModel
};
require_once Path::root("src/databases/VLWdb.php");
require_once Path::root("src/databases/models/Battlestation/Mb.php");
require_once Path::root("src/databases/models/Battlestation/Config/MbPsu.php");
require_once Path::root("src/databases/models/Battlestation/Config/MbGpu.php");
require_once Path::root("src/databases/models/Battlestation/Config/MbDram.php");
require_once Path::root("src/databases/models/Battlestation/Config/MbStorage.php");
require_once Path::root("src/databases/models/Battlestation/Config/ChassisMb.php");
require_once Path::root("src/databases/models/Battlestation/Config/MbCpuCooler.php");
require_once Path::root("src/Database/Database.php");
require_once Path::root("src/Database/Models/Battlestation/Mb.php");
require_once Path::root("src/Database/Models/Battlestation/Config/MbPsu.php");
require_once Path::root("src/Database/Models/Battlestation/Config/MbGpu.php");
require_once Path::root("src/Database/Models/Battlestation/Config/MbDram.php");
require_once Path::root("src/Database/Models/Battlestation/Config/MbStorage.php");
require_once Path::root("src/Database/Models/Battlestation/Config/ChassisMb.php");
require_once Path::root("src/Database/Models/Battlestation/Config/MbCpuCooler.php");
class GET_BattlestationMb extends VLWdb {
class GET_BattlestationMb extends Database {
private const REL_CPU = "cpus";
private const REL_PSU = "psus";
private const REL_GPU = "gpus";
@ -49,43 +43,43 @@
$this->ruleset = new Ruleset(strict: true);
$this->ruleset->GET([
(new Rules(MbModel::ID->value))
(new Rules(MbTable::ID->value))
->type(Type::STRING)
->min(parent::UUID_LENGTH)
->max(parent::UUID_LENGTH),
(new Rules(MbModel::FORMFACTOR->value))
(new Rules(MbTable::FORMFACTOR->value))
->type(Type::ENUM, MbFormfactorEnum::names()),
(new Rules(MbModel::VENDOR_NAME->value))
(new Rules(MbTable::VENDOR_NAME->value))
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(MbModel::VENDOR_MODEL->value))
(new Rules(MbTable::VENDOR_MODEL->value))
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(MbModel::NETWORK_ETHERNET->value))
(new Rules(MbTable::NETWORK_ETHERNET->value))
->type(Type::NULL)
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(MbModel::NETWORK_WLAN->value))
(new Rules(MbTable::NETWORK_WLAN->value))
->type(Type::NULL)
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(MbModel::NETWORK_BLUETOOTH->value))
(new Rules(MbTable::NETWORK_BLUETOOTH->value))
->type(Type::NULL)
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(MbModel::IS_RETIRED->value))
(new Rules(MbTable::IS_RETIRED->value))
->type(Type::BOOLEAN)
]);
@ -99,9 +93,9 @@
foreach ($this->results as &$result) {
// Get motherboard id from relationship by chassis id
$result[self::REL_CHASSIS] = $this->db
->for(ChassisMbModel::TABLE)
->where([ChassisMbModel::REF_MB_ID->value => $result[MbModel::ID->value]])
->select(ChassisMbModel::values())
->for(ChassisMbTable::NAME)
->where([ChassisMbTable::REF_MB_ID->value => $result[MbTable::ID->value]])
->select(ChassisMbTable::values())
->fetch_all(MYSQLI_ASSOC);
}
}
@ -110,9 +104,9 @@
foreach ($this->results as &$result) {
// Get motherboard id from relationship by chassis id
$result[self::REL_PSU] = $this->db
->for(MbPsuModel::TABLE)
->where([MbPsuModel::REF_MB_ID->value => $result[MbModel::ID->value]])
->select(MbPsuModel::values())
->for(MbPsuTable::NAME)
->where([MbPsuTable::REF_MB_ID->value => $result[MbTable::ID->value]])
->select(MbPsuTable::values())
->fetch_all(MYSQLI_ASSOC);
}
}
@ -121,8 +115,8 @@
foreach ($this->results as &$result) {
// Get motherboard id from relationship by chassis id
$result[self::REL_CPU] = $this->db
->for(MbCpuCoolerModel::TABLE)
->where([MbCpuCoolerModel::REF_MB_ID->value => $result[MbModel::ID->value]])
->for(MbCpuCoolerModel::NAME)
->where([MbCpuCoolerModel::REF_MB_ID->value => $result[MbTable::ID->value]])
->select(MbCpuCoolerModel::values())
->fetch_all(MYSQLI_ASSOC);
}
@ -132,9 +126,9 @@
foreach ($this->results as &$result) {
// Get motherboard id from relationship by chassis id
$result[self::REL_GPU] = $this->db
->for(MbGpuModel::TABLE)
->where([MbGpuModel::REF_MB_ID->value => $result[MbModel::ID->value]])
->select(MbGpuModel::values())
->for(MbGpuTable::NAME)
->where([MbGpuTable::REF_MB_ID->value => $result[MbTable::ID->value]])
->select(MbGpuTable::values())
->fetch_all(MYSQLI_ASSOC);
}
}
@ -143,9 +137,9 @@
foreach ($this->results as &$result) {
// Get motherboard id from relationship by chassis id
$result[self::REL_DRAM] = $this->db
->for(MbDramModel::TABLE)
->where([MbDramModel::REF_MB_ID->value => $result[MbModel::ID->value]])
->select(MbDramModel::values())
->for(MbDramTable::NAME)
->where([MbDramTable::REF_MB_ID->value => $result[MbTable::ID->value]])
->select(MbDramTable::values())
->fetch_all(MYSQLI_ASSOC);
}
}
@ -154,9 +148,9 @@
foreach ($this->results as &$result) {
// Get motherboard id from relationship by chassis id
$result[self::REL_STORAGE] = $this->db
->for(MbStorageModel::TABLE)
->where([MbStorageModel::REF_MB_ID->value => $result[MbModel::ID->value]])
->select(MbStorageModel::values())
->for(MbStorageTable::NAME)
->where([MbStorageTable::REF_MB_ID->value => $result[MbTable::ID->value]])
->select(MbStorageTable::values())
->fetch_all(MYSQLI_ASSOC);
}
}
@ -165,17 +159,17 @@
private function get_motherboards(): array {
return $this->results = $this->db
->for(MbModel::TABLE)
->for(MbTable::NAME)
->where($this->query)
->order([MbModel::DATE_AQUIRED->value => "DESC"])
->select(MbModel::values())
->order([MbTable::DATE_AQUIRED->value => "DESC"])
->select(MbTable::values())
->fetch_all(MYSQLI_ASSOC);
}
public function main(): Response {
// Set properties as "searchable"
parent::make_wildcard_search(MbModel::VENDOR_NAME->value, $this->query);
parent::make_wildcard_search(MbModel::VENDOR_MODEL->value, $this->query);
parent::make_wildcard_search(MbTable::VENDOR_NAME->value, $this->query);
parent::make_wildcard_search(MbTable::VENDOR_MODEL->value, $this->query);
// Get hardware
$this->get_motherboards();

View file

@ -1,26 +1,20 @@
<?php
use Reflect\Path;
use Reflect\Response;
use ReflectRules\Type;
use ReflectRules\Rules;
use ReflectRules\Ruleset;
use Reflect\{Response, Path};
use ReflectRules\{Ruleset, Rules, Type};
use VLW\API\Databases\VLWdb\{
VLWdb,
Databases
};
use VLW\API\Databases\VLWdb\Models\Battlestation\{
PsuModel,
use VLW\Database\Database;
use VLW\Database\Tables\Battlestation\{
PsuTable,
EightyplusRatingEnum
};
use VLW\API\Databases\VLWdb\Models\Battlestation\Config\MbPsuModel;
use VLW\Database\Tables\Battlestation\Config\MbPsuTable;
require_once Path::root("src/databases/VLWdb.php");
require_once Path::root("src/databases/models/Battlestation/Psu.php");
require_once Path::root("src/databases/models/Battlestation/Config/MbPsu.php");
require_once Path::root("src/Database/Database.php");
require_once Path::root("src/Database/Models/Battlestation/Psu.php");
require_once Path::root("src/Database/Models/Battlestation/Config/MbPsu.php");
class GET_BattlestationPsu extends VLWdb {
class GET_BattlestationPsu extends Database {
private const REL_MOTHERBOARDS = "motherboards";
protected Ruleset $ruleset;
@ -32,30 +26,30 @@
$this->ruleset = new Ruleset(strict: true);
$this->ruleset->GET([
(new Rules(PsuModel::ID->value))
(new Rules(PsuTable::ID->value))
->type(Type::STRING)
->min(parent::UUID_LENGTH)
->max(parent::UUID_LENGTH),
(new Rules(PsuModel::POWER->value))
(new Rules(PsuTable::POWER->value))
->type(Type::NUMBER)
->min(1)
->max(parent::MYSQL_INT_MAX_LENGTH),
(new Rules(PsuModel::EIGHTYPLUS_RATING->value))
(new Rules(PsuTable::EIGHTYPLUS_RATING->value))
->type(Type::ENUM, EightyplusRatingEnum::names()),
(new Rules(PsuModel::VENDOR_NAME->value))
(new Rules(PsuTable::VENDOR_NAME->value))
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(PsuModel::VENDOR_MODEL->value))
(new Rules(PsuTable::VENDOR_MODEL->value))
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(PsuModel::IS_RETIRED->value))
(new Rules(PsuTable::IS_RETIRED->value))
->type(Type::BOOLEAN)
]);
@ -69,26 +63,26 @@
foreach ($this->results as &$result) {
// Get motherboard id from relationship by chassis id
$result[self::REL_MOTHERBOARDS] = $this->db
->for(MbPsuModel::TABLE)
->where([MbPsuModel::REF_PSU_ID->value => $result[PsuModel::ID->value]])
->select(MbPsuModel::values())
->for(MbPsuTable::NAME)
->where([MbPsuTable::REF_PSU_ID->value => $result[PsuTable::ID->value]])
->select(MbPsuTable::values())
->fetch_all(MYSQLI_ASSOC);
}
}
private function get_psu(): array {
return $this->results = $this->db
->for(PsuModel::TABLE)
->for(PsuTable::NAME)
->where($this->query)
->order([PsuModel::DATE_AQUIRED->value => "DESC"])
->select(PsuModel::values())
->order([PsuTable::DATE_AQUIRED->value => "DESC"])
->select(PsuTable::values())
->fetch_all(MYSQLI_ASSOC);
}
public function main(): Response {
// Set properties as "searchable"
parent::make_wildcard_search(PsuModel::VENDOR_NAME->value, $this->query);
parent::make_wildcard_search(PsuModel::VENDOR_MODEL->value, $this->query);
parent::make_wildcard_search(PsuTable::VENDOR_NAME->value, $this->query);
parent::make_wildcard_search(PsuTable::VENDOR_MODEL->value, $this->query);
// Get hardware
$this->get_psu();

View file

@ -1,28 +1,22 @@
<?php
use Reflect\Path;
use Reflect\Response;
use ReflectRules\Type;
use ReflectRules\Rules;
use ReflectRules\Ruleset;
use Reflect\{Response, Path};
use ReflectRules\{Ruleset, Rules, Type};
use VLW\API\Databases\VLWdb\{
VLWdb,
Databases
};
use VLW\API\Databases\VLWdb\Models\Battlestation\{
StorageModel,
use VLW\Database\Database;
use VLW\Database\Tables\Battlestation\{
StorageTable,
StorageDiskTypeEnum,
StorageDiskInterfaceEnum,
StorageDiskFormfactorEnum
};
use VLW\API\Databases\VLWdb\Models\Battlestation\Config\MbStorageModel;
use VLW\Database\Tables\Battlestation\Config\MbStorageTable;
require_once Path::root("src/databases/VLWdb.php");
require_once Path::root("src/databases/models/Battlestation/Storage.php");
require_once Path::root("src/databases/models/Battlestation/Config/MbStorage.php");
require_once Path::root("src/Database/Database.php");
require_once Path::root("src/Database/Models/Battlestation/Storage.php");
require_once Path::root("src/Database/Models/Battlestation/Config/MbStorage.php");
class GET_BattlestationStorage extends VLWdb {
class GET_BattlestationStorage extends Database {
private const REL_MOTHERBOARDS = "motherboards";
protected Ruleset $ruleset;
@ -34,36 +28,36 @@
$this->ruleset = new Ruleset(strict: true);
$this->ruleset->GET([
(new Rules(StorageModel::ID->value))
(new Rules(StorageTable::ID->value))
->type(Type::STRING)
->min(parent::UUID_LENGTH)
->max(parent::UUID_LENGTH),
(new Rules(StorageModel::DISK_TYPE->value))
(new Rules(StorageTable::DISK_TYPE->value))
->type(Type::ENUM, StorageDiskTypeEnum::names()),
(new Rules(StorageModel::DISK_SIZE->value))
(new Rules(StorageTable::DISK_SIZE->value))
->type(Type::NUMBER)
->min(1)
->max(parent::MYSQL_INT_MAX_LENGTH),
(new Rules(StorageModel::DISK_INTERFACE->value))
(new Rules(StorageTable::DISK_INTERFACE->value))
->type(Type::ENUM, StorageDiskInterfaceEnum::names()),
(new Rules(StorageModel::DISK_FORMFACTOR->value))
(new Rules(StorageTable::DISK_FORMFACTOR->value))
->type(Type::ENUM, StorageDiskFormfactorEnum::names()),
(new Rules(StorageModel::VENDOR_NAME->value))
(new Rules(StorageTable::VENDOR_NAME->value))
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(StorageModel::VENDOR_MODEL->value))
(new Rules(StorageTable::VENDOR_MODEL->value))
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(StorageModel::IS_RETIRED->value))
(new Rules(StorageTable::IS_RETIRED->value))
->type(Type::BOOLEAN)
]);
@ -77,26 +71,26 @@
foreach ($this->results as &$result) {
// Get motherboard id from relationship by chassis id
$result[self::REL_MOTHERBOARDS] = $this->db
->for(MbStorageModel::TABLE)
->where([MbStorageModel::REF_STORAGE_ID->value => $result[StorageModel::ID->value]])
->select(MbStorageModel::values())
->for(MbStorageTable::NAME)
->where([MbStorageTable::REF_STORAGE_ID->value => $result[StorageTable::ID->value]])
->select(MbStorageTable::values())
->fetch_all(MYSQLI_ASSOC);
}
}
private function get_storage(): array {
return $this->results = $this->db
->for(StorageModel::TABLE)
->for(StorageTable::NAME)
->where($this->query)
->order([StorageModel::DATE_AQUIRED->value => "DESC"])
->select(StorageModel::values())
->order([StorageTable::DATE_AQUIRED->value => "DESC"])
->select(StorageTable::values())
->fetch_all(MYSQLI_ASSOC);
}
public function main(): Response {
// Set properties as "searchable"
parent::make_wildcard_search(StorageModel::VENDOR_NAME->value, $this->query);
parent::make_wildcard_search(StorageModel::VENDOR_MODEL->value, $this->query);
parent::make_wildcard_search(StorageTable::VENDOR_NAME->value, $this->query);
parent::make_wildcard_search(StorageTable::VENDOR_MODEL->value, $this->query);
// Get hardware
$this->get_storage();

View file

@ -0,0 +1,47 @@
<?php
use Reflect\{Response, Path};
use ReflectRules\{Ruleset, Rules, Type};
use VLW\Database\Database;
use VLW\Database\Tables\Messages\MessagesTable;
require_once Path::root("src/Database/Database.php");
require_once Path::root("src/Database/Models/Messages/Messages.php");
class POST_Messages extends Database {
protected Ruleset $ruleset;
public function __construct() {
$this->ruleset = new Ruleset(strict: true);
$this->ruleset->POST([
(new Rules(MessagesTable::EMAIL->value))
->type(Type::STRING)
->max(255)
->default(null),
(new Rules(MessagesTable::MESSAGE->value))
->required()
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_TEXT_MAX_LENGTH)
]);
$ruleset->validate_or_exit();
parent::__construct();
}
public function main(): Response {
// Use copy of request body as entity
$entity = $_POST;
$entity[MessagesTable::ID->value] = parent::gen_uuid4();
$entity[MessagesTable::DATE_CREATED->value] = time();
return $this->db->for(MessagesTable::NAME)->insert($entity) === true
? new Response($entity[MessagesTable::ID->value], 201)
: new Response("Failed to create message", 500);
}
}

View file

@ -1,25 +1,19 @@
<?php
use Reflect\Call;
use Reflect\Path;
use Reflect\Response;
use ReflectRules\Type;
use ReflectRules\Rules;
use ReflectRules\Ruleset;
use Reflect\{Response, Path};
use ReflectRules\{Ruleset, Rules, Type};
use VLW\API\Endpoints;
use VLW\API\Databases\VLWdb\{
VLWdb,
Databases
};
use VLW\API\Databases\VLWdb\Models\Work\WorkModel;
use VLW\Database\Database;
use VLW\Database\Tables\Work\WorkTable;
require_once Path::root("src/Endpoints.php");
require_once Path::root("src/databases/VLWdb.php");
require_once Path::root("src/databases/models/Work/Work.php");
require_once Path::root("src/Database/Database.php");
require_once Path::root("src/Database/Models/Work/Work.php");
class GET_Search extends VLWdb {
class GET_Search extends Database {
const GET_QUERY = "q";
protected Ruleset $ruleset;
@ -35,13 +29,15 @@
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
]);
parent::__construct(Databases::VLW, $this->ruleset);
$ruleset->validate_or_exit();
parent::__construct();
}
private function search_work(): Response {
return (new Call(Endpoints::WORK->value))->params([
WorkModel::TITLE->value => $_GET[self::GET_QUERY],
WorkModel::SUMMARY->value => $_GET[self::GET_QUERY]
WorkTable::TITLE->value => $_GET[self::GET_QUERY],
WorkTable::SUMMARY->value => $_GET[self::GET_QUERY]
])->get();
}

View file

@ -1,63 +1,59 @@
<?php
use Reflect\Path;
use Reflect\Response;
use ReflectRules\Type;
use ReflectRules\Rules;
use ReflectRules\Ruleset;
use Reflect\{Response, Path};
use ReflectRules\{Ruleset, Rules, Type};
use const VLW\API\RESP_DELETE_OK;
use VLW\API\Databases\VLWdb\{
VLWdb,
Databases
};
use VLW\API\Databases\VLWdb\Models\Work\WorkModel;
use VLW\Database\Database;
use VLW\Database\Tables\Work\WorkTable;
require_once Path::root("src/Endpoints.php");
require_once Path::root("src/databases/VLWdb.php");
require_once Path::root("src/databases/models/Work.php");
require_once Path::root("src/Database/Database.php");
require_once Path::root("src/Database/Models/Work.php");
class DELETE_Work extends VLWdb {
class DELETE_Work extends Database {
protected Ruleset $ruleset;
public function __construct() {
$this->ruleset = new Ruleset(strict: true);
$this->ruleset->POST([
(new Rules(WorkModel::ID->value))
(new Rules(WorkTable::ID->value))
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(WorkModel::TITLE->value))
(new Rules(WorkTable::TITLE->value))
->type(Type::STRING)
->min(3)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(WorkModel::SUMMARY->value))
(new Rules(WorkTable::SUMMARY->value))
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_TEXT_MAX_LENGTH),
(new Rules(WorkModel::IS_LISTED->value))
(new Rules(WorkTable::IS_LISTED->value))
->type(Type::BOOLEAN),
(new Rules(WorkModel::DATE_MODIFIED->value))
(new Rules(WorkTable::DATE_MODIFIED->value))
->type(Type::NUMBER)
->min(1)
->max(parent::MYSQL_INT_MAX_LENGTH),
(new Rules(WorkModel::DATE_CREATED->value))
(new Rules(WorkTable::DATE_CREATED->value))
->type(Type::NUMBER)
->min(1)
->max(parent::MYSQL_INT_MAX_LENGTH)
]);
parent::__construct(Databases::VLW, $this->ruleset);
$ruleset->validate_or_exit();
parent::__construct();
}
public function main(): Response {
return $this->db->for(FieldsEnumsModel::TABLE)->delete($_POST) === true
return $this->db->for(FieldsEnumsModel::NAME)->delete($_POST) === true
? new Response(RESP_DELETE_OK)
: new Response("Failed to delete work entity", 500);
}

55
endpoints/work/GET.php Normal file
View file

@ -0,0 +1,55 @@
<?php
use Reflect\{Response, Path};
use ReflectRules\{Ruleset, Rules, Type};
use VLW\Database\Database;
use VLW\Database\Tables\Work\WorkTable;
require_once Path::root("src/Database/Database.php");
require_once Path::root("src/Database/Models/Work/Work.php");
class GET_Work extends Database {
protected Ruleset $ruleset;
public function __construct() {
$this->ruleset = new Ruleset(strict: true);
$this->ruleset->GET([
(new Rules(WorkTable::ID->value))
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(WorkTable::TITLE->value))
->type(Type::STRING)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(WorkTable::SUMMARY->value))
->type(Type::STRING)
->max(parent::MYSQL_TEXT_MAX_LENGTH),
(new Rules(WorkTable::IS_LISTED->value))
->type(Type::BOOLEAN)
->default(true),
(new Rules(WorkTable::DATE_MODIFIED->value))
->type(Type::NUMBER)
->min(1)
->max(parent::MYSQL_INT_MAX_LENGTH),
(new Rules(WorkTable::DATE_CREATED->value))
->type(Type::NUMBER)
->min(1)
->max(parent::MYSQL_INT_MAX_LENGTH)
]);
$ruleset->validate_or_exit();
parent::__construct();
}
public function main(): Response {
return $this->list(WorkTable::NAME, WorkTable::values());
}
}

View file

@ -1,35 +1,29 @@
<?php
use Reflect\Call;
use Reflect\Path;
use Reflect\Response;
use ReflectRules\Type;
use ReflectRules\Rules;
use ReflectRules\Ruleset;
use Reflect\{Response, Path};
use ReflectRules\{Ruleset, Rules, Type};
use VLW\API\Endpoints;
use VLW\API\Databases\VLWdb\{
VLWdb,
Databases
};
use VLW\API\Databases\VLWdb\Models\Work\{
WorkModel,
WorkPermalinksModel
use VLW\Database\Database;
use VLW\Database\Tables\Work\{
WorkTable,
PermalinksTable
};
require_once Path::root("src/Endpoints.php");
require_once Path::root("src/databases/VLWdb.php");
require_once Path::root("src/databases/models/Work/Work.php");
require_once Path::root("src/databases/models/Work/WorkPermalinks.php");
require_once Path::root("src/Database/Database.php");
require_once Path::root("src/Database/Models/Work/Work.php");
require_once Path::root("src/Database/Models/Work/WorkPermalinks.php");
class PATCH_Work extends VLWdb {
class PATCH_Work extends Database {
protected Ruleset $ruleset;
public function __construct() {
$this->ruleset = new Ruleset(strict: true);
$this->ruleset->GET([
(new Rules(WorkModel::ID->value))
(new Rules(WorkTable::ID->value))
->required()
->type(Type::STRING)
->min(1)
@ -37,26 +31,26 @@
]);
$this->ruleset->POST([
(new Rules(WorkModel::TITLE->value))
(new Rules(WorkTable::TITLE->value))
->type(Type::STRING)
->min(3)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(WorkModel::SUMMARY->value))
(new Rules(WorkTable::SUMMARY->value))
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_TEXT_MAX_LENGTH),
(new Rules(WorkModel::IS_LISTED->value))
(new Rules(WorkTable::IS_LISTED->value))
->type(Type::BOOLEAN),
(new Rules(WorkModel::DATE_MODIFIED->value))
(new Rules(WorkTable::DATE_MODIFIED->value))
->type(Type::NUMBER)
->min(1)
->max(parent::MYSQL_INT_MAX_LENGTH)
->default(time()),
(new Rules(WorkModel::DATE_CREATED->value))
(new Rules(WorkTable::DATE_CREATED->value))
->type(Type::NUMBER)
->min(1)
->max(parent::MYSQL_INT_MAX_LENGTH)
@ -73,15 +67,15 @@
// Compute and return modeled year, month, and day from Unix timestamp in request body
private static function gen_date_created(): array {
return [
WorkModel::DATE_YEAR->value => date("Y", $_POST[WorkModel::DATE_CREATED->value]),
WorkModel::DATE_MONTH ->value => date("n", $_POST[WorkModel::DATE_CREATED->value]),
WorkModel::DATE_DAY->value => date("j", $_POST[WorkModel::DATE_CREATED->value])
WorkTable::DATE_YEAR->value => date("Y", $_POST[WorkTable::DATE_CREATED->value]),
WorkTable::DATE_MONTH ->value => date("n", $_POST[WorkTable::DATE_CREATED->value]),
WorkTable::DATE_DAY->value => date("j", $_POST[WorkTable::DATE_CREATED->value])
];
}
private function get_entity_by_id(string $id): Response {
return (new Call(Endpoints::WORK->value))->params([
WorkModel::ID->value => $id
WorkTable::ID->value => $id
])->get();
}
@ -90,8 +84,8 @@
$entity = $_POST;
// Generate a new slug id from title if changed
if ($_POST[WorkModel::TITLE->value]) {
$slug = $_POST[WorkModel::TITLE->value];
if ($_POST[WorkTable::TITLE->value]) {
$slug = $_POST[WorkTable::TITLE->value];
// Bail out if the slug generated from the new tite already exist
if ($this->get_entity_by_id($slug)) {
@ -99,17 +93,17 @@
}
// Add the new slug to update entity
$entity[WorkModel::ID] = $slug;
$entity[WorkTable::ID] = $slug;
}
// Generate new work date fields from timestamp
if ($_POST[WorkModel::DATE_CREATED->value]) {
if ($_POST[WorkTable::DATE_CREATED->value]) {
array_merge($entity, self::gen_date_created());
}
// Update entity by existing id
return $this->db->for(WorkModel::TABLE)->where([WorkModel::ID->value => $_GET[WorkModel::ID->value]])->update($entity) === true
? new Response($_GET[WorkModel::ID->value])
return $this->db->for(WorkTable::NAME)->where([WorkTable::ID->value => $_GET[WorkTable::ID->value]])->update($entity) === true
? new Response($_GET[WorkTable::ID->value])
: new Response("Failed to update entity", 500);
}
}

62
api/endpoints/work/POST.php → endpoints/work/POST.php Executable file → Normal file
View file

@ -1,58 +1,54 @@
<?php
use Reflect\Call;
use Reflect\Path;
use Reflect\Response;
use ReflectRules\Type;
use ReflectRules\Rules;
use ReflectRules\Ruleset;
use Reflect\{Response, Path};
use ReflectRules\{Ruleset, Rules, Type};
use VLW\API\Endpoints;
use VLW\API\Databases\VLWdb\{
VLWdb,
Databases
};
use VLW\API\Databases\VLWdb\Models\Work\{
WorkModel,
WorkPermalinksModel
use VLW\Database\Database;
use VLW\Database\Tables\Work\{
WorkTable,
PermalinksTable
};
require_once Path::root("src/Endpoints.php");
require_once Path::root("src/databases/VLWdb.php");
require_once Path::root("src/databases/models/Work/Work.php");
require_once Path::root("src/databases/models/Work/WorkPermalinks.php");
require_once Path::root("src/Database/Database.php");
require_once Path::root("src/Database/Models/Work/Work.php");
require_once Path::root("src/Database/Models/Work/WorkPermalinks.php");
class POST_Work extends VLWdb {
class POST_Work extends Database {
protected Ruleset $ruleset;
public function __construct() {
$this->ruleset = new Ruleset(strict: true);
$this->ruleset->POST([
(new Rules(WorkModel::TITLE->value))
(new Rules(WorkTable::TITLE->value))
->type(Type::STRING)
->min(3)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
->default(null),
(new Rules(WorkModel::SUMMARY->value))
(new Rules(WorkTable::SUMMARY->value))
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_TEXT_MAX_LENGTH)
->default(null),
(new Rules(WorkModel::IS_LISTED->value))
(new Rules(WorkTable::IS_LISTED->value))
->type(Type::BOOLEAN)
->default(false),
(new Rules(WorkModel::DATE_CREATED->value))
(new Rules(WorkTable::DATE_CREATED->value))
->type(Type::NUMBER)
->min(1)
->max(parent::MYSQL_INT_MAX_LENGTH)
->default(time())
]);
parent::__construct(Databases::VLW, $this->ruleset);
$ruleset->validate_or_exit();
parent::__construct();
}
// Generate a slug URL from string
@ -63,18 +59,18 @@
// Compute and return modeled year, month, and day from a Unix timestamp
private static function gen_date_created(): array {
// Use provided timestamp in request
$date_created = $_POST[WorkModel::DATE_CREATED->value];
$date_created = $_POST[WorkTable::DATE_CREATED->value];
return [
WorkModel::DATE_YEAR->value => date("Y", $date_created),
WorkModel::DATE_MONTH ->value => date("n", $date_created),
WorkModel::DATE_DAY->value => date("j", $date_created)
WorkTable::DATE_YEAR->value => date("Y", $date_created),
WorkTable::DATE_MONTH ->value => date("n", $date_created),
WorkTable::DATE_DAY->value => date("j", $date_created)
];
}
private function get_entity_by_id(string $id): Response {
return (new Call(Endpoints::WORK->value))->params([
WorkModel::ID->value => $id
WorkTable::ID->value => $id
])->get();
}
@ -83,12 +79,12 @@
$entity = $_POST;
// Generate URL slug from title text or UUID if undefined
$entity[WorkModel::ID->value] = $_POST[WorkModel::TITLE->value]
? self::gen_slug($_POST[WorkModel::TITLE->value])
$entity[WorkTable::ID->value] = $_POST[WorkTable::TITLE->value]
? self::gen_slug($_POST[WorkTable::TITLE->value])
: parent::gen_uuid4();
// Bail out here if a work entry with id had been created already
if ($this->get_entity_by_id($entity[WorkModel::ID->value])->ok) {
if ($this->get_entity_by_id($entity[WorkTable::ID->value])->ok) {
return new Response("An entity with id '{$slug}' already exist", 409);
}
@ -96,15 +92,15 @@
array_merge($entity, self::gen_date_created());
// Let's try to insert the new entity
if (!$this->db->for(WorkModel::TABLE)->insert($entity)) {
if (!$this->db->for(WorkTable::NAME)->insert($entity)) {
return new Response("Failed to insert work entry", 500);
}
// Generate permalink for new entity
return (new Call(Endpoints::WORK_PERMALINKS->value))->post([
WorkPermalinksModel::ID => $entity[WorkModel::ID->value],
WorkPermalinksModel::REF_WORK_ID => $entity[WorkModel::ID->value],
WorkPermalinksModel::DATE_CREATED => time()
PermalinksTable::ID => $entity[WorkTable::ID->value],
PermalinksTable::REF_WORK_ID => $entity[WorkTable::ID->value],
PermalinksTable::DATE_CREATED => time()
]);
}
}

View file

@ -0,0 +1,32 @@
<?php
use Reflect\{Response, Path};
use ReflectRules\{Ruleset, Rules, Type};
use const VLW\API\RESP_DELETE_OK;
use VLW\Database\Database;
use VLW\Database\Tables\Work\ActionsTable;
require_once Path::root("src/Database/Database.php");
require_once Path::root("src/Database/Models/WorkActions.php");
class DELETE_WorkActions extends Database {
protected Ruleset $ruleset;
public function __construct() {
parent::__construct();
$this->ruleset = new Ruleset(strict: true);
$this->ruleset->POST([
(new Rules(ActionsTable::REF_WORK_ID->value))
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
]);
}
public function main(): Response {
return $this->db->for(ActionsTable::NAME)->delete($_POST) === true
? new Response(RESP_DELETE_OK)
: new Response("Failed to delete action for work entity", 500);
}
}

View file

@ -0,0 +1,44 @@
<?php
use Reflect\{Response, Path};
use ReflectRules\{Ruleset, Rules, Type};
use VLW\Database\Database;
use VLW\Database\Tables\Work\ActionsTable;
require_once Path::root("src/Database/Database.php");
require_once Path::root("src/Database/Models/Work/WorkActions.php");
class GET_WorkActions extends Database {
protected Ruleset $ruleset;
public function __construct() {
$this->ruleset = new Ruleset(strict: true);
$this->ruleset->GET([
(new Rules(ActionsTable::REF_WORK_ID->value))
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
]);
$ruleset->validate_or_exit();
parent::__construct();
}
public function main(): Response {
$response = $this->db->for(ActionsTable::NAME)
->where($_GET)
->select([
ActionsTable::REF_WORK_ID->value,
ActionsTable::DISPLAY_TEXT->value,
ActionsTable::HREF->value,
ActionsTable::CLASS_LIST->value
]);
return $response->num_rows > 0
? new Response(parent::index_array_by_key($response->fetch_all(MYSQLI_ASSOC), ActionsTable::REF_WORK_ID->value))
: new Response([], 404);
}
}

View file

@ -1,64 +1,60 @@
<?php
use Reflect\Call;
use Reflect\Path;
use Reflect\Response;
use ReflectRules\Type;
use ReflectRules\Rules;
use ReflectRules\Ruleset;
use Reflect\{Response, Path};
use ReflectRules\{Ruleset, Rules, Type};
use VLW\API\Endpoints;
use VLW\API\Databases\VLWdb\{
VLWdb,
Databases
};
use VLW\API\Databases\VLWdb\Models\Work\{
WorkModel,
WorkActionsModel
use VLW\Database\Database;
use VLW\Database\Tables\Work\{
WorkTable,
ActionsTable
};
require_once Path::root("src/Endpoints.php");
require_once Path::root("src/databases/VLWdb.php");
require_once Path::root("src/databases/models/Work/Work.php");
require_once Path::root("src/databases/models/Work/WorkActions.php");
require_once Path::root("src/Database/Database.php");
require_once Path::root("src/Database/Models/Work/Work.php");
require_once Path::root("src/Database/Models/Work/WorkActions.php");
class POST_WorkActions extends VLWdb {
class POST_WorkActions extends Database {
protected Ruleset $ruleset;
public function __construct() {
$this->ruleset = new Ruleset(strict: true);
$this->ruleset->POST([
(new Rules(WorkActionsModel::REF_WORK_ID->value))
(new Rules(ActionsTable::REF_WORK_ID->value))
->required()
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(WorkActionsModel::DISPLAY_TEXT->value))
(new Rules(ActionsTable::DISPLAY_TEXT->value))
->required()
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(WorkActionsModel::HREF->value))
(new Rules(ActionsTable::HREF->value))
->required()
->type(Type::STRING)
->type(Type::NULL)
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(WorkActionsModel::CLASS_LIST->value))
(new Rules(ActionsTable::CLASS_LIST->value))
->type(Type::ARRAY)
->min(1)
->default([])
]);
parent::__construct(Databases::VLW, $this->ruleset);
$ruleset->validate_or_exit();
parent::__construct();
}
private static function get_entity(): Response {
return (new Call(Endpoints::WORK->value))->params([
WorkModel::ID->value => $_POST[WorkActionsModel::REF_WORK_ID->value]
WorkTable::ID->value => $_POST[ActionsTable::REF_WORK_ID->value]
])->get();
}
@ -69,8 +65,8 @@
return $entity;
}
return $this->db->for(WorkActionsModel::TABLE)->insert($_POST) === true
? new Response($_POST[WorkActionsModel::REF_WORK_ID->value], 201)
return $this->db->for(ActionsTable::NAME)->insert($_POST) === true
? new Response($_POST[ActionsTable::REF_WORK_ID->value], 201)
: new Response("Failed to add action to work entity", 500);
}
}

View file

@ -0,0 +1,48 @@
<?php
use Reflect\{Response, Path};
use ReflectRules\{Ruleset, Rules, Type};
use VLW\Database\Database;
use VLW\Database\Tables\Work\PermalinksTable;
require_once Path::root("src/Database/Database.php");
require_once Path::root("src/Database/Models/Work/WorkPermalinks.php");
class GET_WorkPermalinks extends Database {
protected Ruleset $ruleset;
public function __construct() {
$this->ruleset = new Ruleset(strict: true);
$this->ruleset->GET([
(new Rules(PermalinksTable::ID->value))
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(PermalinksTable::REF_WORK_ID->value))
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
]);
$ruleset->validate_or_exit();
parent::__construct();
}
public function main(): Response {
$response = $this->db->for(PermalinksTable::NAME)
->where($_GET)
->select([
PermalinksTable::ID->value,
PermalinksTable::REF_WORK_ID->value,
PermalinksTable::DATE_CREATED->value
]);
return $response->num_rows > 0
? new Response($response->fetch_all(MYSQLI_ASSOC))
: new Response([], 404);
}
}

View file

@ -1,53 +1,49 @@
<?php
use Reflect\Call;
use Reflect\Path;
use Reflect\Response;
use ReflectRules\Type;
use ReflectRules\Rules;
use ReflectRules\Ruleset;
use Reflect\{Response, Path};
use ReflectRules\{Ruleset, Rules, Type};
use VLW\API\Databases\VLWdb\{
VLWdb,
Databases
};
use VLW\API\Databases\VLWdb\Models\Work\WorkPermalinksModel;
use VLW\Database\Database;
use VLW\Database\Tables\Work\PermalinksTable;
require_once Path::root("src/databases/VLWdb.php");
require_once Path::root("src/databases/models/Work/WorkPermalinks.php");
require_once Path::root("src/Database/Database.php");
require_once Path::root("src/Database/Models/Work/WorkPermalinks.php");
class POST_WorkPermalinks extends VLWdb {
class POST_WorkPermalinks extends Database {
protected Ruleset $ruleset;
public function __construct() {
$this->ruleset = new Ruleset(strict: true);
$this->ruleset->POST([
(new Rules(WorkPermalinksModel::ID->value))
(new Rules(PermalinksTable::ID->value))
->required()
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(WorkPermalinksModel::REF_WORK_ID->value))
(new Rules(PermalinksTable::REF_WORK_ID->value))
->required()
->type(Type::STRING)
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(WorkPermalinksModel::DATE_CREATED->value))
(new Rules(PermalinksTable::DATE_CREATED->value))
->type(Type::NUMBER)
->min(1)
->max(parent::MYSQL_INT_MAX_LENGTH)
->default(time())
]);
parent::__construct(Databases::VLW, $this->ruleset);
$ruleset->validate_or_exit();
parent::__construct();
}
private static function get_entity(): Response {
return (new Call(Endpoints::WORK->value))->params([
WorkModel::ID->value => $_POST[WorkTagsModel::REF_WORK_ID->value]
WorkTable::ID->value => $_POST[TagsTable::REF_WORK_ID->value]
])->get();
}
@ -58,8 +54,8 @@
return $entity;
}
return $this->db->for(WorkPermalinksModel::TABLE)->insert($_POST) === true
? new Response($_POST[WorkPermalinksModel::ID->value], 201)
return $this->db->for(PermalinksTable::NAME)->insert($_POST) === true
? new Response($_POST[PermalinksTable::ID->value], 201)
: new Response("Failed to add permalink to work entity", 500);
}
}

View file

@ -0,0 +1,38 @@
<?php
use Reflect\{Response, Path};
use ReflectRules\{Ruleset, Rules, Type};
use const VLW\API\RESP_DELETE_OK;
use VLW\Database\Database;
use VLW\Database\Tables\Work\TagsTable;
require_once Path::root("src/Database/Database.php");
require_once Path::root("src/Database/Models/Work/WorkTags.php");
class DELETE_WorkTags extends Database {
private Ruleset $ruleset;
public function __construct() {
$this->ruleset = new Ruleset(strict: true);
$this->ruleset->GET([
(new Rules(TagsTable::REF_WORK_ID->value))
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(TagsTable::NAME->value))
->type(Type::ENUM, TagsNameEnum::names())
]);
$ruleset->validate_or_exit();
parent::__construct();
}
public function main(): Response {
return $this->db->for(TagsTable::NAME)->delete($_POST) === true
? new Response(RESP_DELETE_OK)
: new Response("Failed to delete value from document", 500);
}
}

View file

@ -0,0 +1,47 @@
<?php
use Reflect\{Response, Path};
use ReflectRules\{Ruleset, Rules, Type};
use VLW\Database\Database;
use VLW\Database\Tables\Work\{
TagsTable,
TagsNameEnum
};
require_once Path::root("src/Database/Database.php");
require_once Path::root("src/Database/Models/Work/WorkTags.php");
class GET_WorkTags extends Database {
private Ruleset $ruleset;
public function __construct() {
$this->ruleset = new Ruleset(strict: true);
$this->ruleset->GET([
(new Rules(TagsTable::REF_WORK_ID->value))
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(TagsTable::NAME->value))
->type(Type::ENUM, TagsNameEnum::names())
]);
$ruleset->validate_or_exit();
parent::__construct();
}
public function main(): Response {
$response = $this->db->for(TagsTable::NAME)
->where($_GET)
->select([
TagsTable::REF_WORK_ID->value,
TagsTable::NAME->value
]);
return $response->num_rows > 0
? new Response(parent::index_array_by_key($response->fetch_all(MYSQLI_ASSOC), TagsTable::REF_WORK_ID->value))
: new Response([], 404);
}
}

View file

@ -0,0 +1,59 @@
<?php
use Reflect\Call;
use Reflect\{Response, Path};
use ReflectRules\{Ruleset, Rules, Type};
use VLW\API\Endpoints;
use VLW\Database\Database;
use VLW\Database\Tables\Work\{
WorkTable,
TagsTable,
TagsNameEnum
};
require_once Path::root("src/Endpoints.php");
require_once Path::root("src/Database/Database.php");
require_once Path::root("src/Database/Models/Work/Work.php");
require_once Path::root("src/Database/Models/Work/WorkTags.php");
class POST_WorkTags extends Database {
protected Ruleset $ruleset;
public function __construct() {
$this->ruleset = new Ruleset(strict: true);
$this->ruleset->POST([
(new Rules(TagsTable::REF_WORK_ID->value))
->required()
->min(1)
->max(parent::MYSQL_VARCHAR_MAX_LENGTH),
(new Rules(TagsTable::NAME->value))
->required()
->type(Type::ENUM, TagsNameEnum::names())
]);
$ruleset->validate_or_exit();
parent::__construct();
}
private static function get_entity(): Response {
return (new Call(Endpoints::WORK->value))->params([
WorkTable::ID->value => $_POST[TagsTable::REF_WORK_ID->value]
])->get();
}
public function main(): Response {
// Bail out if work entity could not be fetched
$entity = self::get_entity();
if (!$entity->ok) {
return $entity;
}
return $this->db->for(TagsTable::NAME)->insert($_POST) === true
? new Response($_POST[TagsTable::REF_WORK_ID->value], 201)
: new Response("Failed to add tag to work entity", 500);
}
}

View file

@ -5,22 +5,22 @@
use VLW\Client\API;
use VLW\API\Endpoints;
use VLW\API\Databases\VLWdb\Models\Battlestation\{
MbModel,
CpuModel,
GpuModel,
PsuModel,
DramModel,
StorageModel,
ChassisModel
use VLW\Database\Tables\Battlestation\{
MbTable,
CpuTable,
GpuTable,
PsuTable,
DramTable,
StorageTable,
ChassisTable
};
use VLW\API\Databases\VLWdb\Models\Battlestation\Config\{
MbPsuModel,
MbGpuModel,
MbDramModel,
use VLW\Database\Tables\Battlestation\Config\{
MbPsuTable,
MbGpuTable,
MbDramTable,
ConfigModel,
MbStorageModel,
ChassisMbModel,
MbStorageTable,
ChassisMbTable,
MbCpuCoolerModel,
MbStorageSlotFormfactorEnum
};
@ -29,22 +29,22 @@
require_once VV::root("api/src/Endpoints.php");
// Load hardware database models
require_once VV::root("api/src/databases/models/Battlestation/Mb.php");
require_once VV::root("api/src/databases/models/Battlestation/Cpu.php");
require_once VV::root("api/src/databases/models/Battlestation/Gpu.php");
require_once VV::root("api/src/databases/models/Battlestation/Psu.php");
require_once VV::root("api/src/databases/models/Battlestation/Dram.php");
require_once VV::root("api/src/databases/models/Battlestation/Storage.php");
require_once VV::root("api/src/databases/models/Battlestation/Chassis.php");
require_once VV::root("api/src/Database/Models/Battlestation/Mb.php");
require_once VV::root("api/src/Database/Models/Battlestation/Cpu.php");
require_once VV::root("api/src/Database/Models/Battlestation/Gpu.php");
require_once VV::root("api/src/Database/Models/Battlestation/Psu.php");
require_once VV::root("api/src/Database/Models/Battlestation/Dram.php");
require_once VV::root("api/src/Database/Models/Battlestation/Storage.php");
require_once VV::root("api/src/Database/Models/Battlestation/Chassis.php");
// Load hardware config database models
require_once VV::root("api/src/databases/models/Battlestation/Config/MbPsu.php");
require_once VV::root("api/src/databases/models/Battlestation/Config/MbGpu.php");
require_once VV::root("api/src/databases/models/Battlestation/Config/MbDram.php");
require_once VV::root("api/src/databases/models/Battlestation/Config/Config.php");
require_once VV::root("api/src/databases/models/Battlestation/Config/MbStorage.php");
require_once VV::root("api/src/databases/models/Battlestation/Config/ChassisMb.php");
require_once VV::root("api/src/databases/models/Battlestation/Config/MbCpuCooler.php");
require_once VV::root("api/src/Database/Models/Battlestation/Config/MbPsu.php");
require_once VV::root("api/src/Database/Models/Battlestation/Config/MbGpu.php");
require_once VV::root("api/src/Database/Models/Battlestation/Config/MbDram.php");
require_once VV::root("api/src/Database/Models/Battlestation/Config/Config.php");
require_once VV::root("api/src/Database/Models/Battlestation/Config/MbStorage.php");
require_once VV::root("api/src/Database/Models/Battlestation/Config/ChassisMb.php");
require_once VV::root("api/src/Database/Models/Battlestation/Config/MbCpuCooler.php");
const GIGA = 0x3B9ACA00;
const MEGA = 0xF4240;
@ -73,7 +73,7 @@
// Get motherboard details by ref_mb_id from config
$motherboard = $api->call(Endpoints::BATTLESTATION_MB->value)->params([
MbModel::ID->value => $config[ChassisMbModel::REF_MB_ID->value]
MbTable::ID->value => $config[ChassisMbTable::REF_MB_ID->value]
])->get()->json()[0];
?>
@ -89,9 +89,9 @@
data-gpu="<?= count($motherboard["gpus"]) ?>"
data-dram="<?= count($motherboard["dram"]) ?>"
data-case="<?= count($motherboard["chassis"]) ?>"
data-drives-mdottwo="<?= count(array_keys(array_column($motherboard["storage"], MbStorageModel::SLOT_FORMFACTOR->value), MbStorageSlotFormfactorEnum::MDOTTWO->value)) ?>"
data-drives-twodotfive="<?= count(array_keys(array_column($motherboard["storage"], MbStorageModel::SLOT_FORMFACTOR->value), MbStorageSlotFormfactorEnum::TWODOTFIVE->value)) ?>"
data-drives-threedotfive="<?= count(array_keys(array_column($motherboard["storage"], MbStorageModel::SLOT_FORMFACTOR->value), MbStorageSlotFormfactorEnum::THREEDOTFIVE->value)) ?>"
data-drives-mdottwo="<?= count(array_keys(array_column($motherboard["storage"], MbStorageTable::SLOT_FORMFACTOR->value), MbStorageSlotFormfactorEnum::MDOTTWO->value)) ?>"
data-drives-twodotfive="<?= count(array_keys(array_column($motherboard["storage"], MbStorageTable::SLOT_FORMFACTOR->value), MbStorageSlotFormfactorEnum::TWODOTFIVE->value)) ?>"
data-drives-threedotfive="<?= count(array_keys(array_column($motherboard["storage"], MbStorageTable::SLOT_FORMFACTOR->value), MbStorageSlotFormfactorEnum::THREEDOTFIVE->value)) ?>"
>
<?= VV::embed("public/assets/media/battlestation.svg") ?>
<div class="specs">
@ -100,38 +100,38 @@
<?php if ($motherboard): ?>
<div data-target="mb" class="spec">
<p>Motherboard</p>
<h3><?= $motherboard[MbModel::VENDOR_NAME->value] ?> <span><?= $motherboard[MbModel::VENDOR_MODEL->value] ?></span></h3>
<h3><?= $motherboard[MbTable::VENDOR_NAME->value] ?> <span><?= $motherboard[MbTable::VENDOR_MODEL->value] ?></span></h3>
<div>
<div>
<label>Formfactor</label>
<p><?= $motherboard[MbModel::FORMFACTOR->value] ?></p>
<p><?= $motherboard[MbTable::FORMFACTOR->value] ?></p>
</div>
<div>
<label>Brand name</label>
<p><?= $motherboard[MbModel::VENDOR_NAME->value] ?></p>
<p><?= $motherboard[MbTable::VENDOR_NAME->value] ?></p>
</div>
<div>
<label>Brand model</label>
<p><?= $motherboard[MbModel::VENDOR_MODEL->value] ?></p>
<p><?= $motherboard[MbTable::VENDOR_MODEL->value] ?></p>
</div>
<div>
<label>LAN</label>
<p><?= $motherboard[MbModel::NETWORK_ETHERNET->value] ?? "No LAN" ?></p>
<p><?= $motherboard[MbTable::NETWORK_ETHERNET->value] ?? "No LAN" ?></p>
</div>
<div>
<label>WLAN</label>
<p><?= $motherboard[MbModel::NETWORK_WLAN->value] ?? "No WLAN" ?></p>
<p><?= $motherboard[MbTable::NETWORK_WLAN->value] ?? "No WLAN" ?></p>
</div>
<div>
<label>Bluetooth</label>
<p><?= $motherboard[MbModel::NETWORK_BLUETOOTH->value] ?? "No Bluetooth" ?></p>
<p><?= $motherboard[MbTable::NETWORK_BLUETOOTH->value] ?? "No Bluetooth" ?></p>
</div>
<div>
<label>Aquired</label>
<p><?= date(API::DATE_FORMAT, $motherboard[MbModel::DATE_AQUIRED->value]) ?></p>
<p><?= date(API::DATE_FORMAT, $motherboard[MbTable::DATE_AQUIRED->value]) ?></p>
</div>
<?php if ($motherboard[MbModel::IS_RETIRED->value]): ?>
<?php if ($motherboard[MbTable::IS_RETIRED->value]): ?>
<div>
<label>Retired</label>
<p>Yes</p>
@ -146,35 +146,35 @@
<?php // Get case details from endpoint by id ?>
<?php $case = $api->call(Endpoints::BATTLESTATION_CHASSIS->value)->params([
ChassisModel::ID->value => $mb_chassis[ChassisMbModel::REF_CHASSIS_ID->value]
ChassisTable::ID->value => $mb_chassis[ChassisMbTable::REF_CHASSIS_ID->value]
])->get()->json()[0]; ?>
<div data-target="case" class="spec">
<p>Case</p>
<h3><?= $case[ChassisModel::VENDOR_NAME->value] ?> <span><?= $case[ChassisModel::VENDOR_MODEL->value] ?></span></h3>
<h3><?= $case[ChassisTable::VENDOR_NAME->value] ?> <span><?= $case[ChassisTable::VENDOR_MODEL->value] ?></span></h3>
<div>
<div>
<label>Brand name</label>
<p><?= $case[ChassisModel::VENDOR_NAME->value] ?></p>
<p><?= $case[ChassisTable::VENDOR_NAME->value] ?></p>
</div>
<div>
<label>Brand model</label>
<p><?= $case[ChassisModel::VENDOR_MODEL->value] ?></p>
<p><?= $case[ChassisTable::VENDOR_MODEL->value] ?></p>
</div>
<div>
<label> 2.5" slots</label>
<p><?= $case[ChassisModel::STORAGE_TWOINCHFIVE->value] ?></p>
<p><?= $case[ChassisTable::STORAGE_TWOINCHFIVE->value] ?></p>
</div>
<div>
<label> 3.5" slots</label>
<p><?= $case[ChassisModel::STORAGE_THREEINCHFIVE->value] ?></p>
<p><?= $case[ChassisTable::STORAGE_THREEINCHFIVE->value] ?></p>
</div>
<div>
<label>Aquired</label>
<p><?= date(API::DATE_FORMAT, $case[ChassisModel::DATE_AQUIRED->value]) ?></p>
<p><?= date(API::DATE_FORMAT, $case[ChassisTable::DATE_AQUIRED->value]) ?></p>
</div>
<?php if ($case[ChassisModel::IS_RETIRED->value]): ?>
<?php if ($case[ChassisTable::IS_RETIRED->value]): ?>
<div>
<label>Retired</label>
<p>Yes</p>
@ -189,47 +189,47 @@
<?php // Get case details from endpoint by id ?>
<?php $cpu = $api->call(Endpoints::BATTLESTATION_CPU->value)->params([
CpuModel::ID->value => $mb_cpu[MbCpuCoolerModel::REF_CPU_ID->value]
CpuTable::ID->value => $mb_cpu[MbCpuCoolerModel::REF_CPU_ID->value]
])->get()->json()[0]; ?>
<div data-target="cpu" class="spec">
<p>CPU</p>
<h3><?= $cpu[CpuModel::VENDOR_NAME->value] ?> <span><?= $cpu[CpuModel::VENDOR_MODEL->value] ?></span></h3>
<h3><?= $cpu[CpuTable::VENDOR_NAME->value] ?> <span><?= $cpu[CpuTable::VENDOR_MODEL->value] ?></span></h3>
<div>
<div>
<label>Brand name</label>
<p><?= $cpu[CpuModel::VENDOR_NAME->value] ?></p>
<p><?= $cpu[CpuTable::VENDOR_NAME->value] ?></p>
</div>
<div>
<label>Brand model</label>
<p><?= $cpu[CpuModel::VENDOR_MODEL->value] ?></p>
<p><?= $cpu[CpuTable::VENDOR_MODEL->value] ?></p>
</div>
<div>
<label>Class</label>
<p><?= $cpu[CpuModel::CPU_CLASS->value] ?></p>
<p><?= $cpu[CpuTable::CPU_CLASS->value] ?></p>
</div>
<div>
<label>Base Clockspeed</label>
<p><?= $cpu[CpuModel::CLOCK_BASE->value] / GIGA ?>GHz</p>
<p><?= $cpu[CpuTable::CLOCK_BASE->value] / GIGA ?>GHz</p>
</div>
<div>
<label>Turbo Clockspeed</label>
<p><?= $cpu[CpuModel::CLOCK_TURBO->value] / GIGA ?>GHz</p>
<p><?= $cpu[CpuTable::CLOCK_TURBO->value] / GIGA ?>GHz</p>
</div>
<div>
<label> cores (P/E)</label>
<p><?= $cpu[CpuModel::CORE_COUNT_PERFORMANCE->value] + $cpu[CpuModel::CORE_COUNT_EFFICIENCY->value] ?> (<?= $cpu[CpuModel::CORE_COUNT_PERFORMANCE->value] ?>/<?= $cpu[CpuModel::CORE_COUNT_EFFICIENCY->value] ?>)</p>
<p><?= $cpu[CpuTable::CORE_COUNT_PERFORMANCE->value] + $cpu[CpuTable::CORE_COUNT_EFFICIENCY->value] ?> (<?= $cpu[CpuTable::CORE_COUNT_PERFORMANCE->value] ?>/<?= $cpu[CpuTable::CORE_COUNT_EFFICIENCY->value] ?>)</p>
</div>
<div>
<label> total threads</label>
<p><?= $cpu[CpuModel::CORE_THREADS->value] ?></p>
<p><?= $cpu[CpuTable::CORE_THREADS->value] ?></p>
</div>
<div>
<label>Aquired</label>
<p><?= date(API::DATE_FORMAT, $cpu[CpuModel::DATE_AQUIRED->value]) ?></p>
<p><?= date(API::DATE_FORMAT, $cpu[CpuTable::DATE_AQUIRED->value]) ?></p>
</div>
<?php if ($cpu[CpuModel::IS_RETIRED->value]): ?>
<?php if ($cpu[CpuTable::IS_RETIRED->value]): ?>
<div>
<label>Retired</label>
<p>Yes</p>
@ -254,39 +254,39 @@
<?php // Get case details from endpoint by id ?>
<?php $gpu = $api->call(Endpoints::BATTLESTATION_GPU->value)->params([
GpuModel::ID->value => $mb_gpu[MbGpuModel::REF_GPU_ID->value]
GpuTable::ID->value => $mb_gpu[MbGpuTable::REF_GPU_ID->value]
])->get()->json()[0]; ?>
<div data-target="gpu" class="spec">
<p>GPU</p>
<h3><?= $gpu[GpuModel::VENDOR_NAME->value] ?> <span><?= $gpu[GpuModel::VENDOR_CHIP_MODEL->value] ?></span></h3>
<h3><?= $gpu[GpuTable::VENDOR_NAME->value] ?> <span><?= $gpu[GpuTable::VENDOR_CHIP_MODEL->value] ?></span></h3>
<div>
<div>
<label>Chip brand name</label>
<p><?= $gpu[GpuModel::VENDOR_CHIP_NAME->value] ?></p>
<p><?= $gpu[GpuTable::VENDOR_CHIP_NAME->value] ?></p>
</div>
<div>
<label>Chip brand model</label>
<p><?= $gpu[GpuModel::VENDOR_CHIP_MODEL->value] ?></p>
<p><?= $gpu[GpuTable::VENDOR_CHIP_MODEL->value] ?></p>
</div>
<div>
<label>VRAM</label>
<p><?= $gpu[GpuModel::MEMORY->value] / GIGA ?>GB</p>
<p><?= $gpu[GpuTable::MEMORY->value] / GIGA ?>GB</p>
</div>
<div>
<label>Brand name</label>
<p><?= $gpu[GpuModel::VENDOR_NAME->value] ?></p>
<p><?= $gpu[GpuTable::VENDOR_NAME->value] ?></p>
</div>
<div>
<label>Brand model</label>
<p><?= $gpu[GpuModel::VENDOR_MODEL->value] ?></p>
<p><?= $gpu[GpuTable::VENDOR_MODEL->value] ?></p>
</div>
<div>
<label>Aquired</label>
<p><?= date(API::DATE_FORMAT, $gpu[GpuModel::DATE_AQUIRED->value]) ?></p>
<p><?= date(API::DATE_FORMAT, $gpu[GpuTable::DATE_AQUIRED->value]) ?></p>
</div>
<?php if ($gpu[GpuModel::IS_RETIRED->value]): ?>
<?php if ($gpu[GpuTable::IS_RETIRED->value]): ?>
<div>
<label>Retired</label>
<p>Yes</p>
@ -301,39 +301,39 @@
<?php // Get case details from endpoint by id ?>
<?php $psu = $api->call(Endpoints::BATTLESTATION_PSU->value)->params([
PsuModel::ID->value => $mb_psu[MbPsuModel::REF_PSU_ID->value]
PsuTable::ID->value => $mb_psu[MbPsuTable::REF_PSU_ID->value]
])->get()->json()[0]; ?>
<div data-target="psu" class="spec">
<p>PSU</p>
<h3><?= $psu[PsuModel::VENDOR_NAME->value] ?> <span><?= $psu[PsuModel::VENDOR_MODEL->value] ?></span> <span><?= $psu[PsuModel::POWER->value] ?>W</span></h3>
<h3><?= $psu[PsuTable::VENDOR_NAME->value] ?> <span><?= $psu[PsuTable::VENDOR_MODEL->value] ?></span> <span><?= $psu[PsuTable::POWER->value] ?>W</span></h3>
<div>
<div>
<label>Power</label>
<p><?= $psu[PsuModel::POWER->value] ?>W</p>
<p><?= $psu[PsuTable::POWER->value] ?>W</p>
</div>
<div>
<label>Brand name</label>
<p><?= $psu[PsuModel::VENDOR_NAME->value] ?></p>
<p><?= $psu[PsuTable::VENDOR_NAME->value] ?></p>
</div>
<div>
<label>Brand model</label>
<p><?= $psu[PsuModel::VENDOR_MODEL->value] ?></p>
<p><?= $psu[PsuTable::VENDOR_MODEL->value] ?></p>
</div>
<div>
<label>Is modular?</label>
<p><?= $psu[PsuModel::TYPE_MODULAR->value] === "TRUE" ? "Yes" : "No" ?></p>
<p><?= $psu[PsuTable::TYPE_MODULAR->value] === "TRUE" ? "Yes" : "No" ?></p>
</div>
<div>
<label>80+ Rating</label>
<p><?= $psu[PsuModel::EIGHTYPLUS_RATING->value] ?? "None" ?></p>
<p><?= $psu[PsuTable::EIGHTYPLUS_RATING->value] ?? "None" ?></p>
</div>
<div>
<label>Aquired</label>
<p><?= date(API::DATE_FORMAT, $psu[PsuModel::DATE_AQUIRED->value]) ?></p>
<p><?= date(API::DATE_FORMAT, $psu[PsuTable::DATE_AQUIRED->value]) ?></p>
</div>
<?php if ($psu[PsuModel::IS_RETIRED->value]): ?>
<?php if ($psu[PsuTable::IS_RETIRED->value]): ?>
<div>
<label>Retired</label>
<p>Yes</p>
@ -354,54 +354,54 @@
<?php // Get case details from endpoint by id ?>
<?php $dram = $api->call(Endpoints::BATTLESTATION_DRAM->value)->params([
DramModel::ID->value => $mb_dram[MbDramModel::REF_DRAM_ID->value]
DramTable::ID->value => $mb_dram[MbDramTable::REF_DRAM_ID->value]
])->get()->json()[0]; ?>
<div data-target="dram" class="spec">
<p>DRAM - <?= $dram[DramModel::TECHNOLOGY->value] ?></p>
<h3><?= $dram[DramModel::VENDOR_NAME->value] ?>
<span><?= $dram[DramModel::CAPACITY->value] / GIGA ?>GB</span>
<span><?= $dram[DramModel::SPEED->value] / MEGA ?>MHz</span>
<p>DRAM - <?= $dram[DramTable::TECHNOLOGY->value] ?></p>
<h3><?= $dram[DramTable::VENDOR_NAME->value] ?>
<span><?= $dram[DramTable::CAPACITY->value] / GIGA ?>GB</span>
<span><?= $dram[DramTable::SPEED->value] / MEGA ?>MHz</span>
</h3>
<div>
<div>
<label>Capacity</label>
<p><?= $dram[DramModel::CAPACITY->value] / GIGA ?>GB</p>
<p><?= $dram[DramTable::CAPACITY->value] / GIGA ?>GB</p>
</div>
<div>
<label>Speed</label>
<p><?= $dram[DramModel::SPEED->value] / MEGA ?>MHz</p>
<p><?= $dram[DramTable::SPEED->value] / MEGA ?>MHz</p>
</div>
<div>
<label>Brand name</label>
<p><?= $dram[DramModel::VENDOR_NAME->value] ?></p>
<p><?= $dram[DramTable::VENDOR_NAME->value] ?></p>
</div>
<div>
<label>Brand model</label>
<p><?= $dram[DramModel::VENDOR_MODEL->value] ?></p>
<p><?= $dram[DramTable::VENDOR_MODEL->value] ?></p>
</div>
<div>
<label>Formfactor</label>
<p><?= $dram[DramModel::FORMFACTOR->value] ?></p>
<p><?= $dram[DramTable::FORMFACTOR->value] ?></p>
</div>
<div>
<label>Technology</label>
<p><?= $dram[DramModel::TECHNOLOGY->value] ?></p>
<p><?= $dram[DramTable::TECHNOLOGY->value] ?></p>
</div>
<div>
<label>Is ECC?</label>
<p><?= $dram[DramModel::ECC->value] === "TRUE" ? "Yes" : "No" ?></p>
<p><?= $dram[DramTable::ECC->value] === "TRUE" ? "Yes" : "No" ?></p>
</div>
<div>
<label>Is buffered?</label>
<p><?= $dram[DramModel::BUFFERED->value] === "TRUE" ? "Yes" : "No" ?></p>
<p><?= $dram[DramTable::BUFFERED->value] === "TRUE" ? "Yes" : "No" ?></p>
</div>
<div>
<label>Aquired</label>
<p><?= date(API::DATE_FORMAT, $dram[DramModel::DATE_AQUIRED->value]) ?></p>
<p><?= date(API::DATE_FORMAT, $dram[DramTable::DATE_AQUIRED->value]) ?></p>
</div>
<?php if ($dram[DramModel::IS_RETIRED->value]): ?>
<?php if ($dram[DramTable::IS_RETIRED->value]): ?>
<div>
<label>Retired</label>
<p>Yes</p>
@ -411,11 +411,11 @@
<div>
<div>
<label>In motherboard slot number</label>
<p><?= $mb_dram[MbDramModel::SOCKET->value] ?></p>
<p><?= $mb_dram[MbDramTable::SOCKET->value] ?></p>
</div>
<div>
<label>Motherboard slot type</label>
<p><?= $mb_dram[MbDramModel::SOCKET_TYPE->value] ?></p>
<p><?= $mb_dram[MbDramTable::SOCKET_TYPE->value] ?></p>
</div>
</div>
</div>
@ -433,46 +433,46 @@
<?php // Get case details from endpoint by id ?>
<?php $storage = $api->call(Endpoints::BATTLESTATION_STORAGE->value)->params([
StorageModel::ID->value => $mb_storage[MbStorageModel::REF_STORAGE_ID->value]
StorageTable::ID->value => $mb_storage[MbStorageTable::REF_STORAGE_ID->value]
])->get()->json()[0]; ?>
<div data-target="drive" class="spec">
<p><?= $storage[StorageModel::DISK_FORMFACTOR->value] ?> <?= $storage[StorageModel::DISK_TYPE->value] ?></p>
<p><?= $storage[StorageTable::DISK_FORMFACTOR->value] ?> <?= $storage[StorageTable::DISK_TYPE->value] ?></p>
<h3>
<?= $storage[StorageModel::VENDOR_NAME->value] ?>
<span><?= floor($storage[StorageModel::DISK_SIZE->value] / GIGA) ?>GB</span>
<?= $storage[StorageTable::VENDOR_NAME->value] ?>
<span><?= floor($storage[StorageTable::DISK_SIZE->value] / GIGA) ?>GB</span>
</h3>
<div>
<div>
<label>Type</label>
<p><?= $storage[StorageModel::DISK_TYPE->value] ?></p>
<p><?= $storage[StorageTable::DISK_TYPE->value] ?></p>
</div>
<div>
<label>Capacity</label>
<p><?= floor($storage[StorageModel::DISK_SIZE->value] / GIGA) ?>GB</p>
<p><?= floor($storage[StorageTable::DISK_SIZE->value] / GIGA) ?>GB</p>
</div>
<div>
<label>Interface</label>
<p><?= $storage[StorageModel::DISK_INTERFACE->value] ?></p>
<p><?= $storage[StorageTable::DISK_INTERFACE->value] ?></p>
</div>
<div>
<label>Formfactor</label>
<p><?= $storage[StorageModel::DISK_FORMFACTOR->value] ?></p>
<p><?= $storage[StorageTable::DISK_FORMFACTOR->value] ?></p>
</div>
<div>
<label>Brand name</label>
<p><?= $storage[StorageModel::VENDOR_NAME->value] ?></p>
<p><?= $storage[StorageTable::VENDOR_NAME->value] ?></p>
</div>
<div>
<label>Brand model</label>
<p><?= $storage[StorageModel::VENDOR_MODEL->value] ?></p>
<p><?= $storage[StorageTable::VENDOR_MODEL->value] ?></p>
</div>
<div>
<label>Aquired</label>
<p><?= date(API::DATE_FORMAT, $storage[StorageModel::DATE_AQUIRED->value]) ?></p>
<p><?= date(API::DATE_FORMAT, $storage[StorageTable::DATE_AQUIRED->value]) ?></p>
</div>
<?php if ($storage[StorageModel::IS_RETIRED->value]): ?>
<?php if ($storage[StorageTable::IS_RETIRED->value]): ?>
<div>
<label>Retired</label>
<p>Yes</p>
@ -482,7 +482,7 @@
<div>
<div>
<label>Attatched via interface</label>
<p><?= $mb_storage[MbStorageModel::INTERFACE->value] ?></p>
<p><?= $mb_storage[MbStorageTable::INTERFACE->value] ?></p>
</div>
</div>
</div>

View file

@ -5,12 +5,12 @@
use VLW\Client\API;
use VLW\API\Endpoints;
use VLW\API\Databases\VLWdb\Models\Messages\MessagesModel;
use VLW\Database\Tables\Messages\MessagesTable;
require_once VV::root("src/client/API.php");
require_once VV::root("api/src/Endpoints.php");
require_once VV::root("api/src/databases/models/Messages/Messages.php");
require_once VV::root("api/src/Database/Models/Messages/Messages.php");
// Connect to VLW API
$api = new API();
@ -104,8 +104,8 @@
// Send message via API
$send = $api->call(Endpoints::MESSAGES->value)->post([
MessagesModel::EMAIL->value => $_POST[MessagesModel::EMAIL->value],
MessagesModel::MESSAGE->value => $_POST[MessagesModel::MESSAGE->value]
MessagesTable::EMAIL->value => $_POST[MessagesTable::EMAIL->value],
MessagesTable::MESSAGE->value => $_POST[MessagesTable::MESSAGE->value]
]);
?>
@ -128,11 +128,11 @@
<form method="POST">
<input-group>
<label>your email (optional)</label>
<input type="email" name="<?= MessagesModel::EMAIL->value ?>" placeholder="nissehult@example.com" autocomplete="off"></input>
<input type="email" name="<?= MessagesTable::EMAIL->value ?>" placeholder="nissehult@example.com" autocomplete="off"></input>
</input-group>
<input-group>
<label title="this field is required">your message (required)</label>
<textarea name="<?= MessagesModel::MESSAGE->value ?>" required placeholder="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed molestie dignissim mauris vel dignissim. Sed et aliquet odio, id egestas libero. Vestibulum ut dui a turpis aliquam hendrerit id et dui. Morbi eu tristique quam, sit amet dictum felis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin ac nibh a ex accumsan ullamcorper non quis eros. Nam at suscipit lacus. Nullam placerat semper sapien, vitae aliquet nisl elementum a. Duis viverra quam eros, eu vestibulum quam egestas sit amet. Duis lobortis varius malesuada. Mauris in fringilla mi. "></textarea>
<textarea name="<?= MessagesTable::MESSAGE->value ?>" required placeholder="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed molestie dignissim mauris vel dignissim. Sed et aliquet odio, id egestas libero. Vestibulum ut dui a turpis aliquam hendrerit id et dui. Morbi eu tristique quam, sit amet dictum felis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin ac nibh a ex accumsan ullamcorper non quis eros. Nam at suscipit lacus. Nullam placerat semper sapien, vitae aliquet nisl elementum a. Duis viverra quam eros, eu vestibulum quam egestas sit amet. Duis lobortis varius malesuada. Mauris in fringilla mi. "></textarea>
</input-group>
<button class="inline solid">
<?= VV::embed("public/assets/media/icons/email.svg") ?>

View file

@ -5,16 +5,16 @@
use VLW\Client\API;
use VLW\API\Endpoints;
use VLW\API\Databases\VLWdb\Models\Work\{
WorkModel,
WorkActionsModel
use VLW\Database\Tables\Work\{
WorkTable,
ActionsTable
};
require_once VV::root("src/client/API.php");
require_once VV::root("api/src/Endpoints.php");
require_once VV::root("api/src/databases/models/Work/Work.php");
require_once VV::root("api/src/databases/models/Work/WorkActions.php");
require_once VV::root("api/src/Database/Models/Work/Work.php");
require_once VV::root("api/src/Database/Models/Work/WorkActions.php");
// Search endpoint query paramter
const SEARCH_PARAM = "q";
@ -53,12 +53,12 @@
<?php // List all work category search results ?>
<?php foreach ($results[Endpoints::WORK->value] as $result): ?>
<div class="result">
<h3><?= $result[WorkModel::TITLE->value] ?></h3>
<p><?= $result[WorkModel::SUMMARY->value] ?></p>
<p><?= date(API::DATE_FORMAT, $result[WorkModel::DATE_CREATED->value]) ?></p>
<h3><?= $result[WorkTable::TITLE->value] ?></h3>
<p><?= $result[WorkTable::SUMMARY->value] ?></p>
<p><?= date(API::DATE_FORMAT, $result[WorkTable::DATE_CREATED->value]) ?></p>
<?php // Get action buttons for work entity by id ?>
<?php $actions = $api->call(Endpoints::WORK_ACTIONS->value)->params([WorkActionsModel::REF_WORK_ID->value => $result[WorkModel::ID->value]])->get(); ?>
<?php $actions = $api->call(Endpoints::WORK_ACTIONS->value)->params([ActionsTable::REF_WORK_ID->value => $result[WorkTable::ID->value]])->get(); ?>
<?php // List each action button for work entity if exists ?>
<?php if ($actions->ok): ?>
@ -66,7 +66,7 @@
<?php foreach ($actions->json() as $action): ?>
<?php // Bind VV Interactions if link is same origin, else open in new tab ?>
<a href="<?= $action[WorkActionsModel::HREF->value] ?>" target="_blank"><button class="inline <?= $action[WorkActionsModel::CLASS_LIST->value] ?>"><?= $action[WorkActionsModel::DISPLAY_TEXT->value] ?></button></a>
<a href="<?= $action[ActionsTable::HREF->value] ?>" target="_blank"><button class="inline <?= $action[ActionsTable::CLASS_LIST->value] ?>"><?= $action[ActionsTable::DISPLAY_TEXT->value] ?></button></a>
<?php endforeach; ?>
</div>

View file

@ -5,12 +5,12 @@
use VLW\Client\API;
use VLW\API\Endpoints;
use VLW\API\Databases\VLWdb\Models\Work\WorkModel;
use VLW\Database\Tables\Work\WorkTable;
require_once VV::root("src/client/API.php");
require_once VV::root("api/src/Endpoints.php");
require_once VV::root("api/src/databases/models/Work/Work.php");
require_once VV::root("api/src/Database/Models/Work/Work.php");
// Number of items from the timeline to display on this page
const TIMELINE_PREVIEW_LIMIT = 5;
@ -25,17 +25,17 @@
// Get work items from endpoint
$this->resp = $this->call(Endpoints::WORK->value)->params([
WorkModel::IS_LISTED->value => true
WorkTable::IS_LISTED->value => true
])->get();
}
private function get_item(string $key): array {
$idx = array_search($key, array_column($this->resp->json(), WorkModel::ID->value));
$idx = array_search($key, array_column($this->resp->json(), WorkTable::ID->value));
return $this->resp->json()[$idx];
}
public function get_summary(string $key): string {
return $this->resp->ok ? $this->get_item($key)[WorkModel::SUMMARY->value] : self::ERROR_MSG;
return $this->resp->ok ? $this->get_item($key)[WorkTable::SUMMARY->value] : self::ERROR_MSG;
}
}

View file

@ -6,18 +6,18 @@
use VLW\Client\API;
use VLW\API\Endpoints;
use VLW\API\Databases\VLWdb\Models\Work\{
WorkModel,
WorkTagsModel,
WorkActionsModel
use VLW\Database\Tables\Work\{
WorkTable,
TagsTable,
ActionsTable
};
require_once VV::root("src/client/API.php");
require_once VV::root("api/src/Endpoints.php");
require_once VV::root("api/src/databases/models/Work/Work.php");
require_once VV::root("api/src/databases/models/Work/WorkTags.php");
require_once VV::root("api/src/databases/models/Work/WorkActions.php");
require_once VV::root("api/src/Database/Models/Work/Work.php");
require_once VV::root("api/src/Database/Models/Work/WorkTags.php");
require_once VV::root("api/src/Database/Models/Work/WorkActions.php");
$work = new class extends API {
private const API_PARAM_LIMIT = "limit";
@ -30,7 +30,7 @@
parent::__construct();
$this->resp = $this->call(Endpoints::WORK->value)->params([
WorkModel::IS_LISTED->value => true,
WorkTable::IS_LISTED->value => true,
self::API_PARAM_LIMIT => $_GET[self::API_PARAM_LIMIT] ?? null
])->get();
@ -56,22 +56,22 @@
// Create array of arrays ordered by decending year, month, day, items
foreach ($this->resp->json() as $row) {
// Create array for current year if it doesn't exist
if (!array_key_exists($row[WorkModel::DATE_YEAR->value], $timeline)) {
$timeline[$row[WorkModel::DATE_YEAR->value]] = [];
if (!array_key_exists($row[WorkTable::DATE_YEAR->value], $timeline)) {
$timeline[$row[WorkTable::DATE_YEAR->value]] = [];
}
// Create array for current month if it doesn't exist
if (!array_key_exists($row[WorkModel::DATE_MONTH->value], $timeline[$row[WorkModel::DATE_YEAR->value]])) {
$timeline[$row[WorkModel::DATE_YEAR->value]][$row[WorkModel::DATE_MONTH->value]] = [];
if (!array_key_exists($row[WorkTable::DATE_MONTH->value], $timeline[$row[WorkTable::DATE_YEAR->value]])) {
$timeline[$row[WorkTable::DATE_YEAR->value]][$row[WorkTable::DATE_MONTH->value]] = [];
}
// Create array for current day if it doesn't exist
if (!array_key_exists($row[WorkModel::DATE_DAY->value], $timeline[$row[WorkModel::DATE_YEAR->value]][$row[WorkModel::DATE_MONTH->value]])) {
$timeline[$row[WorkModel::DATE_YEAR->value]][$row[WorkModel::DATE_MONTH->value]][$row[WorkModel::DATE_DAY->value]] = [];
if (!array_key_exists($row[WorkTable::DATE_DAY->value], $timeline[$row[WorkTable::DATE_YEAR->value]][$row[WorkTable::DATE_MONTH->value]])) {
$timeline[$row[WorkTable::DATE_YEAR->value]][$row[WorkTable::DATE_MONTH->value]][$row[WorkTable::DATE_DAY->value]] = [];
}
// Append item to ordered array
$timeline[$row[WorkModel::DATE_YEAR->value]][$row[WorkModel::DATE_MONTH->value]][$row[WorkModel::DATE_DAY->value]][] = $row;
$timeline[$row[WorkTable::DATE_YEAR->value]][$row[WorkTable::DATE_MONTH->value]][$row[WorkTable::DATE_DAY->value]][] = $row;
}
return $timeline;
@ -142,35 +142,35 @@
<div class="item">
<?php // List tags if available ?>
<?php if ($work->get_tags($item[WorkModel::ID->value])): ?>
<?php if ($work->get_tags($item[WorkTable::ID->value])): ?>
<div class="tags">
<?php foreach ($work->get_tags($item[WorkModel::ID->value]) as $tag): ?>
<p class="tag <?= $tag[WorkTagsModel::NAME->value] ?>"><?= $tag[WorkTagsModel::NAME->value] ?></p>
<?php foreach ($work->get_tags($item[WorkTable::ID->value]) as $tag): ?>
<p class="tag <?= $tag[TagsTable::NAME->value] ?>"><?= $tag[TagsTable::NAME->value] ?></p>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php // Show large heading if defined ?>
<?php if (!empty($item[WorkModel::TITLE->value])): ?>
<h2><?= $item[WorkModel::TITLE->value] ?></h2>
<?php if (!empty($item[WorkTable::TITLE->value])): ?>
<h2><?= $item[WorkTable::TITLE->value] ?></h2>
<?php endif; ?>
<p><?= $item[WorkModel::SUMMARY->value] ?></p>
<p><?= $item[WorkTable::SUMMARY->value] ?></p>
<div class="actions">
<?php if ($work->get_actions($item[WorkModel::ID->value])): ?>
<?php if ($work->get_actions($item[WorkTable::ID->value])): ?>
<?php // Display each action button ?>
<?php foreach ($work->get_actions($item[WorkModel::ID->value]) as $action): ?>
<a href="<?= $action[WorkActionsModel::HREF->value] ?>"><button class="inline <?= $action[WorkActionsModel::CLASS_LIST->value] ?>">
<p><?= $action[WorkActionsModel::DISPLAY_TEXT->value] ?></p>
<?php foreach ($work->get_actions($item[WorkTable::ID->value]) as $action): ?>
<a href="<?= $action[ActionsTable::HREF->value] ?>"><button class="inline <?= $action[ActionsTable::CLASS_LIST->value] ?>">
<p><?= $action[ActionsTable::DISPLAY_TEXT->value] ?></p>
<?= VV::embed("public/assets/media/icons/chevron.svg") ?>
</button></a>
<?php endforeach; ?>
<?php // Display a link to namespaced page on vlw.se if no action is defined ?>
<?php else: ?>
<a href="<?= $item[WorkModel::ID->value] ?>"><button class="inline">
<a href="<?= $item[WorkTable::ID->value] ?>"><button class="inline">
<p>read more</p>
<?= VV::embed("public/assets/media/icons/chevron.svg") ?>
</button></a>

View file

@ -1,10 +1,10 @@
<?php
namespace VLW\Client;
namespace VLW\API;
use Reflect\Client;
use Reflect\Client as ReflectClient;
class API extends Client {
class Client extends ReflectClient {
// ISO 8601: YYYY-MM-DD
public const DATE_FORMAT = "Y-m-d";

View file

@ -2,22 +2,19 @@
namespace VLW\API;
// Default string to return when a DELETE request is successful
const RESP_DELETE_OK = "OK";
use vlw\xEnum;
// Enum of all available VLW endpoints grouped by category
enum Endpoints: string {
case ABOUT_LANGUAGES = "/about/languages";
case SEARCH = "/search";
case MESSAGES = "/messages";
case WORK = "/work";
case WORK_TAGS = "/work/tags";
case WORK_ACTIONS = "/work/actions";
use xEnum;
case WORK = "/work";
case SEARCH = "/search";
case MESSAGES = "/messages";
case WORK_TAGS = "/work/tags";
case WORK_ACTIONS = "/work/actions";
case BATTLESTATION = "/battlestation";
case ABOUT_LANGUAGES = "/about/languages";
case BATTLESTATION_MB = "/battlestation/mb";
case BATTLESTATION_CPU = "/battlestation/cpu";
case BATTLESTATION_GPU = "/battlestation/gpu";

37
src/Database/Database.php Normal file
View file

@ -0,0 +1,37 @@
<?php
namespace VLW\Database;
use Reflect\Response;
use vlw\MySQL\MySQL;
class Database {
protected readonly MySQL $db;
public function __construct() {
// Create new MariaDB connection
$this->db = new MySQL(
$_ENV["api_database"]["host"],
$_ENV["api_database"]["user"],
$_ENV["api_database"]["pass"],
$_ENV["api_database"]["db"],
);
}
// Return all rows from a table using $_GET paramters as the WHERE clause as a Reflect\Response
public function list(string $table, array $columns, array $order = null): Response {
$resp = $this->for($table)->where($_GET);
// Optionally order rows by columns
if ($order) {
$resp = $resp->order($order);
}
// Return all matched rows or a 404 with an empty array if there were not results
$resp = $resp->select($columns);
return $resp && $resp->num_rows > 0
? new Response($resp->fetch_all(MYSQLI_ASSOC))
: new Response([], 404);
}
}

View file

@ -0,0 +1,34 @@
<?php
namespace VLW\Database\Models;
use \VV;
use VLW\API\{Client, Endpoints};
require_once VV::root("src/API/API.php");
require_once VV::root("src/API/Endpoints.php");
abstract class Model {
private readonly array $row;
public function __construct(
public readonly Endpoints $endpoint,
private readonly array $params = []
) {
$this->row = self::first(self::list($endpoint, $params));
}
public static function first(array $array): array {
return $array && is_array(array_values($array)[0]) ? $array[0] : $array;
}
public static function list(Endpoints $endpoint, array $params = []): array {
$resp = (new API())->call($endpoint->value)->params($params)->get();
return $resp->ok ? $resp->json() : [];
}
public function get(string $key): mixed {
return $this->data[$key] ?? null;
}
}

View file

@ -0,0 +1,41 @@
<?php
namespace VLW\Database\Models;
use \VV;
use VLW\Endpoints;
use VLW\Database\Models\Model;
use VLW\Database\Models\Work\Work;
require_once VV::root("src/Endpoints.php");
require_once VV::root("src/Database/Models/Model.php");
require_once VV::root("src/Database/Models/Work/Work.php");
class Timeline extends Model {
public function __construct(public readonly string $id) {
parent::__construct(Endpoints::TIMELINE, [
TimelineTable::ID->value => $this->id
]);
}
public static function list(): array {
return array_map(fn(array $item): Timeline => new Timeline($item[TimelineTable::ID->value]), parent::list(Endpoints::TIMELINE));
}
public function work(): Work {
return new Work($this->get(TimelineTable::REF_WORK_ID->value));
}
public function year(): int {
return $this->get(TimelineTable::YEAR->value);
}
public function month(): int {
return $this->get(TimelineTable::MONTH->value);
}
public function day(): int {
return $this->get(TimelineTable::DAY->value);
}
}

View file

@ -0,0 +1,5 @@
<?php
namespace VLW\Database\Models\Work;
class Work

View file

@ -1,13 +1,13 @@
<?php
namespace VLW\API\Databases\VLWdb\Models\Battlestation;
namespace VLW\Database\Tables\Battlestation;
use victorwesterlund\xEnum;
use vlw\xEnum;
enum ChassisModel: string {
enum ChassisTable: string {
use xEnum;
const TABLE = "chassis";
const NAME = "chassis";
case ID = "id";
case VENDOR_NAME = "vendor_name";

View file

@ -0,0 +1,14 @@
<?php
namespace VLW\Database\Tables\Battlestation\Config;
use vlw\xEnum;
enum ChassisMbTable: string {
use xEnum;
const NAME = "config_chassis_mb";
case REF_CHASSIS_ID = "ref_chassis_id";
case REF_MB_ID = "ref_mb_id";
}

View file

@ -1,13 +1,13 @@
<?php
namespace VLW\API\Databases\VLWdb\Models\Battlestation\Config;
namespace VLW\Database\Tables\Battlestation\Config;
use victorwesterlund\xEnum;
use vlw\xEnum;
enum ConfigModel: string {
use xEnum;
const TABLE = "config";
const NAME = "config";
case REF_MB_ID = "ref_mb_id";
case FRIENDLY_NAME = "friendly_name";

View file

@ -1,8 +1,8 @@
<?php
namespace VLW\API\Databases\VLWdb\Models\Battlestation\Config;
namespace VLW\Database\Tables\Battlestation\Config;
use victorwesterlund\xEnum;
use vlw\xEnum;
enum SocketTypeEnum {
use xEnum;
@ -14,7 +14,7 @@
enum MbCpuCoolerModel: string {
use xEnum;
const TABLE = "config_mb_cpu_cooler";
const NAME = "config_mb_cpu_cooler";
case REF_MB_ID = "ref_mb_id";
case REF_CPU_ID = "ref_cpu_id";

View file

@ -1,8 +1,8 @@
<?php
namespace VLW\API\Databases\VLWdb\Models\Battlestation\Config;
namespace VLW\Database\Tables\Battlestation\Config;
use victorwesterlund\xEnum;
use vlw\xEnum;
enum SocketTypeModel {
use xEnum;
@ -11,10 +11,10 @@
case INTEGRATED;
}
enum MbDramModel: string {
enum MbDramTable: string {
use xEnum;
const TABLE = "config_mb_dram";
const NAME = "config_mb_dram";
case REF_MB_ID = "ref_mb_id";
case REF_DRAM_ID = "ref_dram_id";

View file

@ -0,0 +1,14 @@
<?php
namespace VLW\Database\Tables\Battlestation\Config;
use vlw\xEnum;
enum MbGpuTable: string {
use xEnum;
const NAME = "config_mb_gpu";
case REF_MB_ID = "ref_mb_id";
case REF_GPU_ID = "ref_gpu_id";
}

View file

@ -0,0 +1,14 @@
<?php
namespace VLW\Database\Tables\Battlestation\Config;
use vlw\xEnum;
enum MbPsuTable: string {
use xEnum;
const NAME = "config_mb_psu";
case REF_MB_ID = "ref_mb_id";
case REF_PSU_ID = "ref_psu_id";
}

View file

@ -1,8 +1,8 @@
<?php
namespace VLW\API\Databases\VLWdb\Models\Battlestation\Config;
namespace VLW\Database\Tables\Battlestation\Config;
use victorwesterlund\xEnum;
use vlw\xEnum;
enum MbStorageSlotFormfactorEnum: string {
use xEnum;
@ -13,10 +13,10 @@
case EXTERNAL = "EXTERNAL";
}
enum MbStorageModel: string {
enum MbStorageTable: string {
use xEnum;
const TABLE = "config_mb_storage";
const NAME = "config_mb_storage";
case REF_MB_ID = "ref_mb_id";
case REF_STORAGE_ID = "ref_storage_id";

View file

@ -1,9 +1,9 @@
<?php
namespace VLW\API\Databases\VLWdb\Models\Battlestation;
namespace VLW\Database\Tables\Battlestation;
enum CoolersModel: string {
const TABLE = "coolers";
enum CoolersTable: string {
const NAME = "coolers";
case ID = "id";
case TYPE_LIQUID = "type_liquid";

View file

@ -1,8 +1,8 @@
<?php
namespace VLW\API\Databases\VLWdb\Models\Battlestation;
namespace VLW\Database\Tables\Battlestation;
use victorwesterlund\xEnum;
use vlw\xEnum;
enum ClassEnum {
use xEnum;
@ -12,10 +12,10 @@
case SERVER;
}
enum CpuModel: string {
enum CpuTable: string {
use xEnum;
const TABLE = "cpu";
const NAME = "cpu";
case ID = "id";
case CPU_CLASS = "class";

View file

@ -1,8 +1,8 @@
<?php
namespace VLW\API\Databases\VLWdb\Models\Battlestation;
namespace VLW\Database\Tables\Battlestation;
use victorwesterlund\xEnum;
use vlw\xEnum;
enum DramFormfactorEnum {
use xEnum;
@ -18,10 +18,10 @@
case DDR5;
}
enum DramModel: string {
enum DramTable: string {
use xEnum;
const TABLE = "dram";
const NAME = "dram";
case ID = "id";
case CAPACITY = "capacity";

View file

@ -1,13 +1,13 @@
<?php
namespace VLW\API\Databases\VLWdb\Models\Battlestation;
namespace VLW\Database\Tables\Battlestation;
use victorwesterlund\xEnum;
use vlw\xEnum;
enum GpuModel: string {
enum GpuTable: string {
use xEnum;
const TABLE = "gpu";
const NAME = "gpu";
case ID = "id";
case MEMORY = "memory";

View file

@ -1,8 +1,8 @@
<?php
namespace VLW\API\Databases\VLWdb\Models\Battlestation;
namespace VLW\Database\Tables\Battlestation;
use victorwesterlund\xEnum;
use vlw\xEnum;
enum MbFormfactorEnum {
use xEnum;
@ -13,10 +13,10 @@
case LAPTOP;
}
enum MbModel: string {
enum MbTable: string {
use xEnum;
const TABLE = "mb";
const NAME = "mb";
case ID = "id";
case FORMFACTOR = "formfactor";

View file

@ -1,8 +1,8 @@
<?php
namespace VLW\API\Databases\VLWdb\Models\Battlestation;
namespace VLW\Database\Tables\Battlestation;
use victorwesterlund\xEnum;
use vlw\xEnum;
enum EightyplusRatingEnum {
use xEnum;
@ -15,10 +15,10 @@
case TITANIUM;
}
enum PsuModel: string {
enum PsuTable: string {
use xEnum;
const TABLE = "psu";
const NAME = "psu";
case ID = "id";
case POWER = "power";

View file

@ -1,8 +1,8 @@
<?php
namespace VLW\API\Databases\VLWdb\Models\Battlestation;
namespace VLW\Database\Tables\Battlestation;
use victorwesterlund\xEnum;
use vlw\xEnum;
enum StorageDiskTypeEnum {
use xEnum;
@ -27,10 +27,10 @@
case MDOTTWO;
}
enum StorageModel: string {
enum StorageTable: string {
use xEnum;
const TABLE = "storage";
const NAME = "storage";
case ID = "id";
case DISK_TYPE = "disk_type";

View file

@ -1,9 +1,9 @@
<?php
namespace VLW\API\Databases\VLWdb\Models\Messages;
namespace VLW\Database\Tables\Messages;
enum MessagesModel: string {
const TABLE = "messages";
enum MessagesTable: string {
const NAME = "messages";
case ID = "id";
case EMAIL = "email";

View file

@ -1,9 +1,9 @@
<?php
namespace VLW\API\Databases\VLWdb\Models\Work;
namespace VLW\Database\Tables\Work;
enum WorkActionsModel: string {
const TABLE = "work_actions";
enum ActionsTable: string {
const NAME = "work_actions";
case REF_WORK_ID = "ref_work_id";
case ICON_PREFIX = "icon_prefix";

View file

@ -0,0 +1,10 @@
<?php
namespace VLW\Database\Tables\Work;
enum MediaTable: string {
const NAME = "work_media";
case ANCHOR = "anchor";
case MEDIA = "media";
}

View file

@ -1,9 +1,9 @@
<?php
namespace VLW\API\Databases\VLWdb\Models\Work;
namespace VLW\Database\Tables\Work;
enum WorkNamespacesModel: string {
const TABLE = "work_actions";
enum NamespacesTable: string {
const NAME = "work_actions";
case REF_WORK_ID = "ref_work_id";
case ICON_PREFIX = "icon_prefix";

View file

@ -1,9 +1,9 @@
<?php
namespace VLW\API\Databases\VLWdb\Models\Work;
namespace VLW\Database\Tables\Work;
enum WorkPermalinksModel: string {
const TABLE = "work_permalinks";
enum PermalinksTable: string {
const NAME = "work_permalinks";
case SLUG = "slug";
case ANCHOR = "anchor";

View file

@ -0,0 +1,21 @@
<?php
namespace VLW\Database\Tables\Work;
use vlw\xEnum;
enum TagsNameEnum {
use xEnum;
case VLW;
case RELEASE;
case WEBSITE;
case REPO;
}
enum TagsTable: string {
const NAME = "work_tags";
case REF_WORK_ID = "ref_work_id";
case NAME = "name";
}

View file

@ -1,13 +1,13 @@
<?php
namespace VLW\API\Databases\VLWdb\Models\Work;
namespace VLW\Database\Tables\Work;
use victorwesterlund\xEnum;
use vlw\xEnum;
enum WorkModel: string {
enum WorkTable: string {
use xEnum;
const TABLE = "work";
const NAME = "work";
case ID = "id";
case TITLE = "title";