This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/ext/bulk_parent_child/main.php
2024-02-11 16:03:23 +00:00

38 lines
1,018 B
PHP

<?php
declare(strict_types=1);
namespace Shimmie2;
class BulkParentChildConfig
{
}
class BulkParentChild extends Extension
{
private const PARENT_CHILD_ACTION_NAME = "bulk_parent_child";
public function onBulkActionBlockBuilding(BulkActionBlockBuildingEvent $event): void
{
global $user;
if ($user->can(Permissions::BULK_PARENT_CHILD)) {
$event->add_action(BulkParentChild::PARENT_CHILD_ACTION_NAME, "Set Parent Child");
}
}
public function onBulkAction(BulkActionEvent $event): void
{
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;
}
}
}
}