mirror of
https://codeberg.org/vlw/vlw.se.git
synced 2025-09-13 21:13:40 +02:00
59 lines
No EOL
1.9 KiB
PHP
59 lines
No EOL
1.9 KiB
PHP
<?php
|
|
|
|
use const VLW\ICONS_DIR;
|
|
use VLW\Database\Models\Search\Search;
|
|
use VLW\Database\Tables\Search\{SearchTable, SearchCategoryEnum};
|
|
|
|
require_once VV::root("src/Consts.php");
|
|
require_once VV::root("src/Database/Tables/Search/Search.php");
|
|
require_once VV::root("src/Database/Models/Search/Search.php");
|
|
|
|
$search = new class extends Search {
|
|
public function __construct() {}
|
|
|
|
public static function get_query(): ?string {
|
|
return $_GET[SearchTable::QUERY->value] ?? null;
|
|
}
|
|
|
|
public static function get_category(): ?SearchCategoryEnum {
|
|
return SearchCategoryEnum::tryFromName($_GET[SearchTable::CATEGORY->value] ?? "");
|
|
}
|
|
|
|
public function search(): array {
|
|
$results = parent::all([SearchTable::QUERY->value => self::get_query()]);
|
|
}
|
|
}
|
|
|
|
?>
|
|
<style><?= VV::css("public/assets/css/pages/search") ?></style>
|
|
<section class="search">
|
|
<form>
|
|
<input name="<?= SearchTable::QUERY->value ?>" type="search" placeholder="search vlw.se..." value="<?= $search::get_query() ?>">
|
|
<select name="<?= SearchTable::CATEGORY->value ?>">
|
|
|
|
<option value="null">All</option>
|
|
<optgroup label="Categories">
|
|
|
|
<?php foreach (SearchCategoryEnum::names() as $category): ?>
|
|
<?php $category = SearchCategoryEnum::fromName($category); ?>
|
|
<option value="<?= $category->name ?>" <?= $search::get_category() === $category ? "selected" : "" ?>><?= ucfirst(strtolower($category->name)) ?></option>
|
|
<?php endforeach; ?>
|
|
|
|
</optgroup>
|
|
|
|
</select>
|
|
<button type="submit" class="inline solid"><?= VV::embed(ICONS_DIR . "search.svg") ?></button>
|
|
</form>
|
|
</section>
|
|
|
|
<?php if (array_key_exists(SearchTable::QUERY->value, $_GET)): ?>
|
|
<section class="results">
|
|
|
|
</section>
|
|
<?php else: ?>
|
|
<section class="start-search">
|
|
<?= VV::embed(ICONS_DIR . "search.svg") ?>
|
|
<p>Start typing to search</p>
|
|
</section>
|
|
<?php endif; ?>
|
|
<script><?= VV::js("public/assets/js/pages/search") ?></script>
|