vendor/ibexa/activity-log/src/bundle/Event/LocationEventsListener.php line 59

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4.  * @license For full copyright and license information view LICENSE file distributed with this source code.
  5.  */
  6. declare(strict_types=1);
  7. namespace Ibexa\Bundle\ActivityLog\Event;
  8. use Ibexa\Contracts\ActivityLog\ActivityLogServiceInterface;
  9. use Ibexa\Contracts\Core\Repository\Events\Location\CopySubtreeEvent;
  10. use Ibexa\Contracts\Core\Repository\Events\Location\CreateLocationEvent;
  11. use Ibexa\Contracts\Core\Repository\Events\Location\DeleteLocationEvent;
  12. use Ibexa\Contracts\Core\Repository\Events\Location\HideLocationEvent;
  13. use Ibexa\Contracts\Core\Repository\Events\Location\MoveSubtreeEvent;
  14. use Ibexa\Contracts\Core\Repository\Events\Location\SwapLocationEvent;
  15. use Ibexa\Contracts\Core\Repository\Events\Location\UnhideLocationEvent;
  16. use Ibexa\Contracts\Core\Repository\Events\Location\UpdateLocationEvent;
  17. use Ibexa\Contracts\Core\Repository\Values\Content\Location;
  18. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  19. final class LocationEventsListener implements EventSubscriberInterface
  20. {
  21.     private ActivityLogServiceInterface $activityLogService;
  22.     public function __construct(
  23.         ActivityLogServiceInterface $activityLogService
  24.     ) {
  25.         $this->activityLogService $activityLogService;
  26.     }
  27.     public static function getSubscribedEvents(): array
  28.     {
  29.         return [
  30.             CopySubtreeEvent::class => ['onCopy'],
  31.             CreateLocationEvent::class => ['onCreate'],
  32.             DeleteLocationEvent::class => ['onDelete'],
  33.             HideLocationEvent::class => ['onHide'],
  34.             MoveSubtreeEvent::class => ['onMove'],
  35.             SwapLocationEvent::class => ['onSwap'],
  36.             UnhideLocationEvent::class => ['onUnhide'],
  37.             UpdateLocationEvent::class => ['onUpdate'],
  38.         ];
  39.     }
  40.     public function onCopy(CopySubtreeEvent $event): void
  41.     {
  42.         $location $event->getLocation();
  43.         $this->saveActivityLog('copy'$location->id);
  44.     }
  45.     public function onCreate(CreateLocationEvent $event): void
  46.     {
  47.         $location $event->getLocation();
  48.         $this->saveActivityLog('create'$location->id);
  49.     }
  50.     public function onDelete(DeleteLocationEvent $event): void
  51.     {
  52.         $location $event->getLocation();
  53.         $this->saveActivityLog('delete'$location->id);
  54.     }
  55.     public function onHide(HideLocationEvent $event): void
  56.     {
  57.         $location $event->getLocation();
  58.         $this->saveActivityLog('hide'$location->id);
  59.     }
  60.     public function onMove(MoveSubtreeEvent $event): void
  61.     {
  62.         $location $event->getLocation();
  63.         $this->saveActivityLog('move'$location->id);
  64.     }
  65.     public function onSwap(SwapLocationEvent $event): void
  66.     {
  67.         $location $event->getLocation1();
  68.         $this->saveActivityLog('swap'$location->id);
  69.         $location $event->getLocation2();
  70.         $this->saveActivityLog('swap'$location->id);
  71.     }
  72.     public function onUnhide(UnhideLocationEvent $event): void
  73.     {
  74.         $location $event->getLocation();
  75.         $this->saveActivityLog('reveal'$location->id);
  76.     }
  77.     public function onUpdate(UpdateLocationEvent $event): void
  78.     {
  79.         $location $event->getLocation();
  80.         $this->saveActivityLog('update'$location->id);
  81.     }
  82.     private function saveActivityLog(string $actionint $id): void
  83.     {
  84.         $activityLog $this->activityLogService->build(Location::class, (string)$id$action);
  85.         $this->activityLogService->save($activityLog);
  86.     }
  87. }