vlw.se/src/Database/Models/Work/Work.php
Victor Westerlund 56cf142e0d refactor: major refactor, design overhaul and merge of Reflect API and Vegvisir sources into the same root (#23)
The PR is a huge refactor of all Reflect and Vegvisir code. I've merged the API and "Front-end" codebases together into the same root, this will allow for both Reflect and Vegvisir to use the same resources. Not only that, but I've also added proper database modeling with actual OOP inheritance for database tables.

Reviewed-on: https://codeberg.org/vlw/vlw.se/pulls/23
2025-02-05 04:49:23 +00:00

48 lines
No EOL
1.3 KiB
PHP

<?php
namespace VLW\Database\Models\Work;
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);
}
}