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.
This commit is contained in:
myname 2023-03-26 17:01:46 -05:00
parent ccb78e272c
commit a352a02b2e
4 changed files with 69 additions and 0 deletions

View File

@ -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";
}

View File

@ -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,

View File

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
class BulkParentChildInfo extends ExtensionInfo
{
public const KEY = "bulk_parent_child";
public string $key = self::KEY;
public string $name = "Bulk Parent Child";
public array $authors = ["Flatty"=>""];
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];
}

View File

@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
class BulkParentChildConfig
{
}
class BulkParentChildException extends BulkActionException
{
}
class BulkParentChild extends Extension
{
private const PARENT_CHILD_ACTION_NAME = "bulk_parent_child";
public function onInitExt(InitExtEvent $event)
{
global $config;
}
public function onBulkActionBlockBuilding(BulkActionBlockBuildingEvent $event)
{
global $user;
if ($user->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;
}
}
}
}