From a352a02b2e4b686a786b46bc0c5e109b1ebc55ea Mon Sep 17 00:00:00 2001 From: myname Date: Sun, 26 Mar 2023 17:01:46 -0500 Subject: [PATCH] Bulk Actions for setting a chain of parent child relationships in the order of images selected. Does not support setting multiple children to one parent in bulk. --- core/permissions.php | 1 + core/userclass.php | 1 + ext/bulk_parent_child/info.php | 16 +++++++++++ ext/bulk_parent_child/main.php | 51 ++++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+) create mode 100644 ext/bulk_parent_child/info.php create mode 100644 ext/bulk_parent_child/main.php diff --git a/core/permissions.php b/core/permissions.php index 351fa2a9..28142259 100644 --- a/core/permissions.php +++ b/core/permissions.php @@ -109,4 +109,5 @@ abstract class Permissions public const BULK_IMPORT = "bulk_import"; public const BULK_EXPORT = "bulk_export"; public const BULK_DOWNLOAD = "bulk_download"; + public const BULK_PARENT_CHILD = "bulk_parent_child"; } diff --git a/core/userclass.php b/core/userclass.php index a15d1767..a68ebb1b 100644 --- a/core/userclass.php +++ b/core/userclass.php @@ -199,6 +199,7 @@ new UserClass("admin", "base", [ Permissions::BULK_IMPORT =>true, Permissions::BULK_EXPORT =>true, Permissions::BULK_DOWNLOAD => true, + Permissions::BULK_PARENT_CHILD => true, Permissions::SET_PRIVATE_IMAGE => true, Permissions::SET_OTHERS_PRIVATE_IMAGES => true, diff --git a/ext/bulk_parent_child/info.php b/ext/bulk_parent_child/info.php new file mode 100644 index 00000000..f4a6b673 --- /dev/null +++ b/ext/bulk_parent_child/info.php @@ -0,0 +1,16 @@ +""]; + public string $license = self::LICENSE_WTFPL; + public string $description = "Allows bulk setting of parent-child relationships, in order of manual selection"; + public array $dependencies = [BulkActionsInfo::KEY]; +} diff --git a/ext/bulk_parent_child/main.php b/ext/bulk_parent_child/main.php new file mode 100644 index 00000000..9362debd --- /dev/null +++ b/ext/bulk_parent_child/main.php @@ -0,0 +1,51 @@ +can(Permissions::BULK_PARENT_CHILD)) { + $event->add_action(BulkParentChild::PARENT_CHILD_ACTION_NAME, "Set Parent Child"); + } + } + + public function onSetupBuilding(SetupBuildingEvent $event) + { + $sb = $event->panel->create_new_block("Bulk Parent Child"); + $sb->start_table(); + $sb->end_table(); + } + + public function onBulkAction(BulkActionEvent $event) + { + global $user, $page, $config; + if ($user->can(Permissions::BULK_PARENT_CHILD)&& + ($event->action == BulkParentChild::PARENT_CHILD_ACTION_NAME)) { + $prev_id = null; + foreach ($event->items as $image) { + if ($prev_id != null) { + send_event(new ImageRelationshipSetEvent($image->id, $prev_id)); + } + $prev_id = $image->id; + } + } + } +}