-
+
diff --git a/src/API/API.php b/src/API/API.php
index 2f5dd7d..f3c10f1 100644
--- a/src/API/API.php
+++ b/src/API/API.php
@@ -10,9 +10,9 @@
public function __construct() {
parent::__construct(
- $_ENV["api"]["base_url"],
- $_ENV["api"]["api_key"],
- $_ENV["api"]["verify_peer"]
+ $_ENV["client_api"]["base_url"],
+ $_ENV["client_api"]["api_key"],
+ $_ENV["client_api"]["verify_peer"]
);
}
}
\ No newline at end of file
diff --git a/src/API/Endpoints.php b/src/API/Endpoints.php
index eac03ea..5c6ecbd 100644
--- a/src/API/Endpoints.php
+++ b/src/API/Endpoints.php
@@ -13,6 +13,7 @@
case MESSAGES = "/messages";
case WORK_TAGS = "/work/tags";
case WORK_ACTIONS = "/work/actions";
+ case WORK_TIMELINE = "/work/timeline";
case BATTLESTATION = "/battlestation";
case ABOUT_LANGUAGES = "/about/languages";
case BATTLESTATION_MB = "/battlestation/mb";
diff --git a/src/Consts.php b/src/Consts.php
new file mode 100644
index 0000000..615e2f5
--- /dev/null
+++ b/src/Consts.php
@@ -0,0 +1,28 @@
+db = new MySQL(
- $_ENV["api_database"]["host"],
- $_ENV["api_database"]["user"],
- $_ENV["api_database"]["pass"],
- $_ENV["api_database"]["db"],
+ $_ENV["server_database"]["host"],
+ $_ENV["server_database"]["user"],
+ $_ENV["server_database"]["pass"],
+ $_ENV["server_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);
+ $resp = $this->db->for($table)->where(array_intersect_key($_GET, array_flip($columns)));
// Optionally order rows by columns
if ($order) {
diff --git a/src/Database/Models/About/Language.php b/src/Database/Models/About/Language.php
new file mode 100644
index 0000000..f264b54
--- /dev/null
+++ b/src/Database/Models/About/Language.php
@@ -0,0 +1,30 @@
+value => $this->id
+ ]);
+ }
+
+ public static function all(array $params = []): array {
+ return array_map(fn(array $item): Language => new Language($item[LanguagesTable::ID->value]), parent::list(Endpoints::ABOUT_LANGUAGES, $params));
+ }
+
+ public function bytes(): int {
+ return $this->get(LanguagesTable::BYTES->value);
+ }
+ }
\ No newline at end of file
diff --git a/src/Database/Models/Model.php b/src/Database/Models/Model.php
index 79327cf..5bcc1a7 100644
--- a/src/Database/Models/Model.php
+++ b/src/Database/Models/Model.php
@@ -10,13 +10,17 @@
require_once VV::root("src/API/Endpoints.php");
abstract class Model {
- private readonly array $row;
+ abstract public static function all(array $params = []): array;
+
+ private array $row;
public function __construct(
- public readonly Endpoints $endpoint,
+ public readonly ?Endpoints $endpoint = null,
private readonly array $params = []
) {
- $this->row = self::first(self::list($endpoint, $params));
+ if ($this->endpoint) {
+ $this->assign(self::first(self::list($endpoint, $params)));
+ }
}
public static function first(array $array): array {
@@ -24,11 +28,16 @@
}
public static function list(Endpoints $endpoint, array $params = []): array {
- $resp = (new API())->call($endpoint->value)->params($params)->get();
+ $resp = (new Client())->call($endpoint->value)->params($params)->get();
return $resp->ok ? $resp->json() : [];
}
+ public function assign(array $row): self {
+ $this->row = $row;
+ return $this;
+ }
+
public function get(string $key): mixed {
- return $this->data[$key] ?? null;
+ return $this->row[$key] ?? null;
}
}
\ No newline at end of file
diff --git a/src/Database/Models/Work/Action.php b/src/Database/Models/Work/Action.php
new file mode 100644
index 0000000..fa1afb2
--- /dev/null
+++ b/src/Database/Models/Work/Action.php
@@ -0,0 +1,51 @@
+ (new Action())->assign($item), parent::list(Endpoints::WORK_ACTIONS, $params));
+ }
+
+ public static function from(Work $work): array {
+ return self::all([
+ ActionsTable::REF_WORK_ID->value => $work->id
+ ]);
+ }
+
+ public function icon_prepended(): ?string {
+ return $this->get(ActionsTable::ICON_PREPENDED->value);
+ }
+
+ public function icon_appended(): ?string {
+ return $this->get(ActionsTable::ICON_APPENDED->value);
+ }
+
+ public function display_text(): string {
+ return $this->get(ActionsTable::DISPLAY_TEXT->value);
+ }
+
+ public function href(): ?string {
+ return $this->get(ActionsTable::HREF->value);
+ }
+
+ public function classes(): array {
+ return $this->get(ActionsTable::CLASS_LIST->value) ? explode(",", $this->get(ActionsTable::CLASS_LIST->value)) : [];
+ }
+ }
\ No newline at end of file
diff --git a/src/Database/Models/Work/Tag.php b/src/Database/Models/Work/Tag.php
new file mode 100644
index 0000000..83df2ed
--- /dev/null
+++ b/src/Database/Models/Work/Tag.php
@@ -0,0 +1,35 @@
+ (new Tag())->assign($item), parent::list(Endpoints::WORK_TAGS, $params));
+ }
+
+ public static function from(Work $work): array {
+ return self::all([
+ TagsTable::REF_WORK_ID->value => $work->id
+ ]);
+ }
+
+ public function label(): TagsLabelEnum {
+ return TagsLabelEnum::from($this->get(TagsTable::LABEL->value));
+ }
+ }
\ No newline at end of file
diff --git a/src/Database/Models/Timeline/Timeline.php b/src/Database/Models/Work/Timeline.php
similarity index 61%
rename from src/Database/Models/Timeline/Timeline.php
rename to src/Database/Models/Work/Timeline.php
index 02ab358..08c5613 100644
--- a/src/Database/Models/Timeline/Timeline.php
+++ b/src/Database/Models/Work/Timeline.php
@@ -1,26 +1,28 @@
value => $this->id
+ parent::__construct(Endpoints::WORK_TIMELINE, [
+ TimelineTable::REF_WORK_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 static function all(array $params = []): array {
+ return array_map(fn(array $item): Timeline => new Timeline($item[TimelineTable::REF_WORK_ID->value]), parent::list(Endpoints::WORK_TIMELINE, $params));
}
public function work(): Work {
diff --git a/src/Database/Models/Work/Work.php b/src/Database/Models/Work/Work.php
index 1d33d21..c94f643 100644
--- a/src/Database/Models/Work/Work.php
+++ b/src/Database/Models/Work/Work.php
@@ -2,4 +2,47 @@
namespace VLW\Database\Models\Work;
- class Work
\ No newline at end of file
+ use \VV;
+
+ use VLW\API\Endpoints;
+ use VLW\Database\Models\Model;
+ use VLW\Database\Tables\Work\WorkTable;
+ use VLW\Database\Models\Work\{Tag, Action};
+
+ require_once VV::root("src/API/Endpoints.php");
+ require_once VV::root("src/Database/Models/Model.php");
+ require_once VV::root("src/Database/Models/Work/Tag.php");
+ require_once VV::root("src/Database/Tables/Work/Work.php");
+ require_once VV::root("src/Database/Models/Work/Action.php");
+
+ class Work extends Model {
+ public function __construct(public readonly string $id) {
+ parent::__construct(Endpoints::WORK, [
+ WorkTable::ID->value => $this->id
+ ]);
+ }
+
+ public static function all(array $params = []): array {
+ return array_map(fn(array $item): Work => new Work($item[WorkTable::ID->value]), parent::list(Endpoints::WORK, $params));
+ }
+
+ public function title(): ?string {
+ return $this->get(WorkTable::TITLE->value);
+ }
+
+ public function summary(): string {
+ return $this->get(WorkTable::SUMMARY->value);
+ }
+
+ public function created(): DateTimeImmutable {
+ return new DateTimeImmutable($this->get(WorkTable::CREATED->value));
+ }
+
+ public function tags(): array {
+ return Tag::from($this);
+ }
+
+ public function actions(): array {
+ return Action::from($this);
+ }
+ }
\ No newline at end of file
diff --git a/src/Database/Tables/About/Languages.php b/src/Database/Tables/About/Languages.php
new file mode 100644
index 0000000..54f4566
--- /dev/null
+++ b/src/Database/Tables/About/Languages.php
@@ -0,0 +1,14 @@
+