another build_selector use case

This commit is contained in:
Luana 2023-06-25 20:49:19 -03:00 committed by Shish
parent 969a1eeab1
commit 9038afc47a
2 changed files with 10 additions and 15 deletions

View file

@ -466,13 +466,13 @@ class Pools extends Extension
{ {
global $config, $database, $user; global $config, $database, $user;
if ($config->get_bool(PoolsConfig::ADDER_ON_VIEW_IMAGE) && !$user->is_anonymous()) { if ($config->get_bool(PoolsConfig::ADDER_ON_VIEW_IMAGE) && !$user->is_anonymous()) {
$pools = [];
if ($user->can(Permissions::POOLS_ADMIN)) { if ($user->can(Permissions::POOLS_ADMIN)) {
$rows = $database->get_all("SELECT * FROM pools"); $pools = $database->get_pairs("SELECT id,title FROM pools ORDER BY title");
} else { } else {
$rows = $database->get_all("SELECT * FROM pools WHERE user_id=:id", ["id" => $user->id]); $pools = $database->get_pairs("SELECT id,title FROM pools ORDER BY title WHERE user_id=:id", ["id" => $user->id]);
} }
if (count($rows) > 0) { if (count($pools) > 0) {
$pools = array_map([Pool::class, "makePool"], $rows);
$event->add_part($this->theme->get_adder_html($event->image, $pools)); $event->add_part($this->theme->get_adder_html($event->image, $pools));
} }
} }

View file

@ -40,18 +40,13 @@ class PoolsTheme extends Themelet
public function get_adder_html(Image $image, array $pools): string public function get_adder_html(Image $image, array $pools): string
{ {
$h = ""; $selector = $this->build_selector("pool_id", $pools);
foreach ($pools as $pool) {
$h .= "<option value='" . $pool->id . "'>" . html_escape($pool->title) . "</option>";
}
return "\n" . make_form(make_link("pool/add_post")) . " return "\n" . make_form(make_link("pool/add_post")) . "
<select name='pool_id'> $selector
$h <input type='hidden' name='image_id' value='{$image->id}'>
</select> <input type='submit' value='Add Post to Pool'>
<input type='hidden' name='image_id' value='{$image->id}'> </form>
<input type='submit' value='Add Post to Pool'> ";
</form>
";
} }
/** /**