Admin: allow topic rename/delete and instant photo tagging

Add topic editing and deletion flows in the topics admin section with nesting safeguards for two-level hierarchy. Make photo topic assignment immediate on select change so tags are attached without extra confirmation clicks, while keeping inline detach actions.
This commit is contained in:
2026-02-21 12:22:38 +03:00
parent 3f80f3fbb7
commit f9b949a7bf
2 changed files with 93 additions and 17 deletions
+17
View File
@@ -109,6 +109,23 @@ function topicCreate(string $name, ?int $parentId, int $sortOrder = 1000): int
return (int)db()->lastInsertId();
}
function topicUpdate(int $topicId, string $name, ?int $parentId, int $sortOrder = 1000): void
{
$st = db()->prepare('UPDATE topics SET parent_id=:pid, name=:name, sort_order=:sort WHERE id=:id');
$st->bindValue('id', $topicId, PDO::PARAM_INT);
$st->bindValue('pid', $parentId, $parentId === null ? PDO::PARAM_NULL : PDO::PARAM_INT);
$st->bindValue('name', $name, PDO::PARAM_STR);
$st->bindValue('sort', $sortOrder, PDO::PARAM_INT);
$st->execute();
}
function topicChildrenCount(int $topicId): int
{
$st = db()->prepare('SELECT COUNT(*) FROM topics WHERE parent_id=:id');
$st->execute(['id' => $topicId]);
return (int)$st->fetchColumn();
}
function topicDelete(int $topicId): void
{
$st = db()->prepare('DELETE FROM topics WHERE id=:id');