Merge pull request #889 from yls4/master

Pool - Reverse function
This commit is contained in:
Shish 2022-10-27 16:58:00 +01:00 committed by GitHub
commit bf03c0849a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 65 additions and 7 deletions

View file

@ -210,8 +210,26 @@ class AutoTagger extends Extension
private function add_auto_tag(string $tag, string $additional_tags) private function add_auto_tag(string $tag, string $additional_tags)
{ {
global $database; global $database;
if ($database->exists("SELECT * FROM auto_tag WHERE LOWER(tag)=LOWER(:tag)", ["tag"=>$tag])) { $existing_tags = $database->get_one("SELECT additional_tags FROM auto_tag WHERE LOWER(tag)=LOWER(:tag)", ["tag"=>$tag]);
throw new AutoTaggerException("Auto-Tag is already set for that tag"); if (!is_null($existing_tags)) {
// Auto Tags already exist, so we will append new tags to the existing one
$tag = Tag::sanitize($tag);
$additional_tags = Tag::explode($additional_tags);
$existing_tags = Tag::explode($existing_tags);
foreach ($additional_tags as $t) {
if (!in_array(strtolower($t), $existing_tags)) {
array_push($existing_tags, strtolower($t));
}
}
$database->execute(
"UPDATE auto_tag set additional_tags=:existing_tags where tag=:tag",
["tag"=>$tag, "existing_tags"=>Tag::implode($existing_tags)]
);
log_info(
AutoTaggerInfo::KEY,
"Updated auto-tag for {$tag} -> {".implode(" ", $additional_tags)."}"
);
} else { } else {
$tag = Tag::sanitize($tag); $tag = Tag::sanitize($tag);
$additional_tags = Tag::explode($additional_tags); $additional_tags = Tag::explode($additional_tags);
@ -225,10 +243,9 @@ class AutoTagger extends Extension
AutoTaggerInfo::KEY, AutoTaggerInfo::KEY,
"Added auto-tag for {$tag} -> {".implode(" ", $additional_tags)."}" "Added auto-tag for {$tag} -> {".implode(" ", $additional_tags)."}"
); );
// Now we apply it to existing items
$this->apply_new_auto_tag($tag);
} }
// Now we apply it to existing items
$this->apply_new_auto_tag($tag);
} }
private function update_auto_tag(string $tag, string $additional_tags): bool private function update_auto_tag(string $tag, string $additional_tags): bool

View file

@ -206,7 +206,6 @@ class Pools extends Extension
public function onPageRequest(PageRequestEvent $event) public function onPageRequest(PageRequestEvent $event)
{ {
global $config, $database, $page, $user; global $config, $database, $page, $user;
if ($event->page_matches("pool")) { if ($event->page_matches("pool")) {
$pool_id = 0; $pool_id = 0;
$pool = []; $pool = [];
@ -326,7 +325,37 @@ class Pools extends Extension
} }
} }
break; break;
case "reverse":
if ($this->have_permission($user, $pool)) {
$result = $database->execute(
"SELECT image_id FROM pool_images WHERE pool_id=:pid ORDER BY image_order DESC",
["pid" => $pool_id]
);
$image_order = 1;
try {
$database->begin_transaction();
while ($row = $result->fetch()) {
$database->execute(
"
UPDATE pool_images
SET image_order=:ord
WHERE pool_id = :pid AND image_id = :iid",
["ord" => $image_order, "pid" => $pool_id, "iid" => (int)$row['image_id']]
);
$image_order = $image_order + 1;
}
$database->commit();
}
catch (Exception $e) {
$database->rollback();
}
$page->set_mode(PageMode::REDIRECT);
$page->set_redirect(make_link("pool/view/" . $pool_id));
}
else {
$this->theme->display_error(403, "Permission Denied", "You do not have permission to access this page");
}
break;
case "import": case "import":
if ($this->have_permission($user, $pool)) { if ($this->have_permission($user, $pool)) {
$images = Image::find_images( $images = Image::find_images(
@ -489,7 +518,11 @@ class Pools extends Extension
$poolID = $pool->id; $poolID = $pool->id;
} }
$event->add_querylet(new Querylet("images.id IN (SELECT DISTINCT image_id FROM pool_images WHERE pool_id = $poolID)")); $event->add_querylet(new Querylet("images.id IN (SELECT DISTINCT image_id FROM pool_images WHERE pool_id = $poolID)"));
} elseif (preg_match("/^pool_id[=|:](.*)$/i", $event->term, $matches)) {
$poolID = str_replace("_", " ", $matches[1]);
$event->add_querylet(new Querylet("images.id IN (SELECT DISTINCT image_id FROM pool_images WHERE pool_id = $poolID)"));
} }
} }
public function onTagTermCheck(TagTermCheckEvent $event) public function onTagTermCheck(TagTermCheckEvent $event)

View file

@ -192,6 +192,14 @@ class PoolsTheme extends Themelet
<input type="hidden" name="order_view" value="yes"> <input type="hidden" name="order_view" value="yes">
<input type="hidden" name="pool_id" value="' . $pool->id . '"> <input type="hidden" name="pool_id" value="' . $pool->id . '">
</form> </form>
' . make_form(make_link('pool/reverse')) . '
<input type="submit" name="edit" id="reverse_pool_order_btn" value="Reverse Order"/>
<input type="hidden" name="reverse_view" value="yes">
<input type="hidden" name="pool_id" value="' . $pool->id . '">
</form>
' . make_form(make_link('post/list/pool_id%3A' . $pool->id . '/1')) . '
<input type="submit" name="edit" id="postlist_pool_btn" value="Post/List View"/>
</form>
'; ';
if ($user->id == $pool->user_id || $user->can(Permissions::POOLS_ADMIN)) { if ($user->id == $pool->user_id || $user->can(Permissions::POOLS_ADMIN)) {