src/Aqarmap/Bundle/ListingBundle/EventListener/ListingListener.php line 55
<?phpnamespace Aqarmap\Bundle\ListingBundle\EventListener;use Aqarmap\Bundle\FeatureToggleBundle\Service\FeatureToggleManager;use Aqarmap\Bundle\ListingBundle\Constant\ListingCategories;use Aqarmap\Bundle\ListingBundle\Event\ListingEvent;use Aqarmap\Bundle\ListingBundle\Service\ListingManager;use Aqarmap\Bundle\ListingBundle\Service\YoutubeHelper;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Symfony\Component\HttpFoundation\RequestStack;use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;class ListingListener implements EventSubscriberInterface{/*** @var TokenStorage*/private $tokenStorage;public function __construct(private readonly RequestStack $requestStack,private readonly YoutubeHelper $youtubeHelper,private readonly FeatureToggleManager $featureToggleManager,private readonly ListingManager $listingManager,TokenStorageInterface $tokenStorage,) {$this->tokenStorage = $tokenStorage;}public function preSubmittedListingEvent(ListingEvent $event): void{$listing = $event->getListing();// Check if the campaign exsist in the cookie add it to listing$cookies = $this->requestStack->getCurrentRequest()->cookies;if ($cookies->has('campaign') && null == $listing->getCampaign()) {$listing->setCampaign($cookies->get('campaign'));}}// ---------------------------------------------------------------------public function preSaveListingEvent(ListingEvent $event): void{$listing = $event->getListing();if ($listing->getVideoUrl()) {$listing->setVideoUrl($this->youtubeHelper->getYoutubeShareUrlFromAnyYoutubeUrl($listing->getVideoUrl()));}if ($listing->getParent()) {$listing->setVideoUrl($listing->getParent()->getVideoUrl());}$this->listingManager->syncVideoUrl($listing);if (null == $listing->getId() && null == $listing->getUser()) {$user = $this->tokenStorage->getToken()->getUser();$listing->setUser($user);$listing->setSellerRole($user->getUserType());}// Assign default admin category for the listingif ($listing->getSection() && !$listing->getSection()->getSearchable()) {$listing->setCategory(ListingCategories::PROJECTS);} elseif (ListingCategories::FIRST_LISTING_FOR_FREE != $listing->getCategory()&& ListingCategories::SCRAPPED != $listing->getCategory()&& ListingCategories::UNLIMITED != $listing->getCategory()) {$listing->setCategory(ListingCategories::NORMAL);}// Update updated date$listing->setUpdatedAt(new \DateTime());// Clear HTML tags from titleif (null != $listing->getTitle()) {$listing->setTitle(strip_tags($listing->getTitle()));}// Clear HTML tags from descriptionif (null != $listing->getDescription()) {$listing->setDescription(strip_tags($listing->getDescription()));}// Clear HTML tags from addressif (null != $listing->getAddress()) {$listing->setAddress(strip_tags($listing->getAddress()));}if ($listing->getPhones() && $this->featureToggleManager->isEnabled('listing_user_phones')) {$this->listingManager->filterListingPhones($listing);}}// ---------------------------------------------------------------------public static function getSubscribedEvents(): array{return ['aqarmap.listing.pre_save' => ['preSaveListingEvent', 1],'aqarmap.listing.pre_save_listener' => ['preSaveListingEvent', 3],'aqarmap.listing.pre_submitted' => ['preSubmittedListingEvent', 2],];}}