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;
if ($config->get_bool(PoolsConfig::ADDER_ON_VIEW_IMAGE) && !$user->is_anonymous()) {
$pools = [];
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 {
$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) {
$pools = array_map([Pool::class, "makePool"], $rows);
if (count($pools) > 0) {
$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
{
$h = "";
foreach ($pools as $pool) {
$h .= "<option value='" . $pool->id . "'>" . html_escape($pool->title) . "</option>";
}
$selector = $this->build_selector("pool_id", $pools);
return "\n" . make_form(make_link("pool/add_post")) . "
<select name='pool_id'>
$h
</select>
<input type='hidden' name='image_id' value='{$image->id}'>
<input type='submit' value='Add Post to Pool'>
</form>
";
$selector
<input type='hidden' name='image_id' value='{$image->id}'>
<input type='submit' value='Add Post to Pool'>
</form>
";
}
/**