mirror of
https://codeberg.org/vlw/vlw.se.git
synced 2025-09-14 05:13:46 +02:00
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
42 lines
No EOL
1.2 KiB
PHP
42 lines
No EOL
1.2 KiB
PHP
<?php
|
|
|
|
namespace VLW\Database\Models\Search;
|
|
|
|
use \VV;
|
|
|
|
use VLW\API\Endpoints;
|
|
use VLW\Database\Models\Model;
|
|
use VLW\Database\Tables\Search\{SearchTable, SearchCategoryEnum};
|
|
|
|
require_once VV::root("src/Consts.php");
|
|
require_once VV::root("src/API/Endpoints.php");
|
|
require_once VV::root("src/Database/Models/Model.php");
|
|
require_once VV::root("src/Database/Tables/Search/Search.php");
|
|
|
|
class Search extends Model {
|
|
public function __construct(public readonly string $id) {
|
|
parent::__construct(Endpoints::SEARCH, [
|
|
SearchTable::ID->value => $this->id
|
|
]);
|
|
}
|
|
|
|
public static function all(array $params = []): array {
|
|
return array_map(fn(array $item): Search => new Search($item[SearchTable::ID->value]), parent::list(Endpoints::SEARCH, $params));
|
|
}
|
|
|
|
public function title(): ?string {
|
|
return $this->get(SearchTable::TITLE->value);
|
|
}
|
|
|
|
public function summary(): ?string {
|
|
return $this->get(SearchTable::SUMMARY->value);
|
|
}
|
|
|
|
public function category(): ?SearchCategoryEnum {
|
|
return SearchCategoryEnum::tryFromName($this->get(SearchTable::CATEGORY->value));
|
|
}
|
|
|
|
public function href(): ?string {
|
|
return $this->get(SearchTable::HREF->value);
|
|
}
|
|
} |