src/Auction/EventSubscriber/AuctionAttendeesSubscriber.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Auction\EventSubscriber;
  3. use App\Auction\Event\AuctionAttendEvent;
  4. use App\Auction\Event\AuctionEvents;
  5. use App\Profile\Model\Profile;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\Mercure\HubInterface;
  8. use Symfony\Component\Mercure\Update;
  9. class AuctionAttendeesSubscriber implements EventSubscriberInterface
  10. {
  11.   public function __construct(
  12.     protected HubInterface $hub,
  13.     protected \Twig\Environment $twig
  14.   ) {
  15.   }
  16.   public static function getSubscribedEvents()
  17.   {
  18.     return [
  19.       AuctionEvents::ATTEND => 'updateAuctionAttendees',
  20.       AuctionEvents::UNATTEND => 'updateAuctionAttendees',
  21.     ];
  22.   }
  23.   public function updateAuctionAttendees(AuctionAttendEvent $event)
  24.   {
  25.     $attendees $event->auction->getAttendees();
  26.     $attendeeProfiles = [];
  27.     foreach ($attendees as $attendee) {
  28.       $attendeeProfiles[] = Profile::getById($attendee->getObjectId());
  29.     }
  30.     $sortedAttendeeProfile = [];
  31.     foreach ($attendeeProfiles as $profile) {
  32.       $key explode('\\'$profile->getPrimaryProfile());
  33.       $key end($key);
  34.       $key str_replace('Profile'''$key);
  35.       $key mb_strtolower($key);
  36.       $sortedAttendeeProfile[$key][] = $profile;
  37.       usort($sortedAttendeeProfile[$key], fn ($a$b) => strcmp($a->getName(), $b->getName()));
  38.     }
  39.     $html $this->twig->render('network/auction/event/attend.stream.twig', ['event' => $event->auction'attendees' => $sortedAttendeeProfile]);
  40.     $this->hub->publish(new Update($event->getTopic(), $html));
  41.   }
  42. }