src/Aqarmap/Bundle/ListingBundle/EventListener/CompoundAveragePricePerMeterListener.php line 28

  1. <?php
  2. namespace Aqarmap\Bundle\ListingBundle\EventListener;
  3. use Aqarmap\Bundle\ListingBundle\Event\ListingEvent;
  4. use Aqarmap\Bundle\ListingBundle\Service\V4\CompoundAveragePriceService;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. class CompoundAveragePricePerMeterListener implements EventSubscriberInterface
  7. {
  8. public const PRIORITY_ONE = 1;
  9. public function __construct(private readonly CompoundAveragePriceService $compoundAveragePriceService)
  10. {
  11. }
  12. /**
  13. * Calculate Average price per meter for compound units regarding property types.
  14. *
  15. * @param ListingEvent
  16. */
  17. public function calculateAveragePricePerMeter(ListingEvent $event): void
  18. {
  19. $compound = $event->getListing()->getParent();
  20. $this->compoundAveragePriceService->addSubscriber($compound);
  21. }
  22. /**
  23. * @return array The event names to listen to
  24. */
  25. public static function getSubscribedEvents(): array
  26. {
  27. return [
  28. 'aqarmap.project.calculate.average.pricePerMeter' => ['calculateAveragePricePerMeter', self::PRIORITY_ONE],
  29. ];
  30. }
  31. }