src/Aqarmap/Bundle/ListingBundle/EventListener/ListingActivityLogListener.php line 245

  1. <?php
  2. namespace Aqarmap\Bundle\ListingBundle\EventListener;
  3. use Aqarmap\Bundle\ListingBundle\Constant\ListingActivityType;
  4. use Aqarmap\Bundle\ListingBundle\Constant\ListingStatus;
  5. use Aqarmap\Bundle\ListingBundle\Entity\Listing;
  6. use Aqarmap\Bundle\ListingBundle\Event\BumpListingEvent;
  7. use Aqarmap\Bundle\ListingBundle\Event\ListingEvent;
  8. use Aqarmap\Bundle\ListingBundle\Event\ListingEventInterface;
  9. use Aqarmap\Bundle\ListingBundle\Service\ListingActivityLogManager;
  10. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  13. use Symfony\Component\Security\Core\User\UserInterface;
  14. /**
  15. * Listing Activity Log listener.
  16. */
  17. class ListingActivityLogListener implements EventSubscriberInterface
  18. {
  19. /** @var UserInterface */
  20. protected $user;
  21. /** @var ListingActivityLogManager */
  22. protected $listingActivity;
  23. /**
  24. * @var EventDispatcherInterface
  25. */
  26. protected $dispatcher;
  27. public function __construct(EventDispatcherInterface $dispatcher, private readonly TokenStorageInterface $tokenStorage, ListingActivityLogManager $listingActivity)
  28. {
  29. $this->dispatcher = $dispatcher;
  30. $this->user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null;
  31. $this->listingActivity = $listingActivity;
  32. }
  33. protected function log(Listing $listing, ?UserInterface $user, string $actionType, array $rejectionReasons = []): void
  34. {
  35. $this->listingActivity->log($listing, $user, $actionType, $rejectionReasons);
  36. }
  37. public function listingCreatedEvent(ListingEvent $event): void
  38. {
  39. $actionType = ListingActivityType::CREATED;
  40. $this->log($event->getlisting(), $this->user, $actionType);
  41. }
  42. public function listingPendingApprovalEvent(ListingEvent $event): void
  43. {
  44. $actionType = ListingActivityType::PENDING_APPROVAL;
  45. $this->log($event->getlisting(), $this->user ?? $event->getListing()->getUser(), $actionType);
  46. }
  47. public function listingPublishEvent(ListingEventInterface $event): void
  48. {
  49. $actionType = $this->user instanceof UserInterface
  50. ? ListingActivityType::PUBLISH
  51. : ListingActivityType::APPROVED_BY_SYSTEM;
  52. $this->log($event->getlisting(), $this->user, $actionType);
  53. }
  54. public function listingDeleteEvent(ListingEvent $event): void
  55. {
  56. $actionType = ListingActivityType::DELETE;
  57. $this->log($event->getlisting(), $this->user, $actionType);
  58. }
  59. public function listingDeleteByUserEvent(ListingEvent $event): void
  60. {
  61. $actionType = ListingActivityType::DELETE_BY_USER;
  62. $this->log($event->getlisting(), $this->user, $actionType);
  63. }
  64. public function listingResetTitleEvent(ListingEvent $event): void
  65. {
  66. $actionType = ListingActivityType::RESET_TITLE;
  67. $this->log($event->getlisting(), $this->user, $actionType);
  68. }
  69. public function listingResetDescriptionEvent(ListingEvent $event): void
  70. {
  71. $actionType = ListingActivityType::RESET_DESCRIPTION;
  72. $this->log($event->getlisting(), $this->user, $actionType);
  73. }
  74. public function listingRemoveNumbersEvent(ListingEvent $event): void
  75. {
  76. $actionType = ListingActivityType::REMOVE_NUMBERS;
  77. $this->log($event->getlisting(), $this->user, $actionType);
  78. }
  79. public function listingRemoveVideoEvent(ListingEvent $event): void
  80. {
  81. $actionType = ListingActivityType::REMOVE_VIDEO;
  82. $this->log($event->getlisting(), $this->user, $actionType);
  83. }
  84. public function listingRemoveMapEvent(ListingEvent $event): void
  85. {
  86. $actionType = ListingActivityType::REMOVE_MAP;
  87. $this->log($event->getlisting(), $this->user, $actionType);
  88. }
  89. public function listingRemovePriceEvent(ListingEvent $event): void
  90. {
  91. $actionType = ListingActivityType::CLEAR_PRICE;
  92. $this->log($event->getlisting(), $this->user, $actionType);
  93. }
  94. public function listingFeaturedEvent(ListingEvent $event): void
  95. {
  96. $actionType = ListingActivityType::FEATURED;
  97. $this->log($event->getlisting(), $this->user, $actionType);
  98. }
  99. public function listingSuperFeaturedEvent(ListingEvent $event): void
  100. {
  101. $actionType = ListingActivityType::SUPER_FEATURED;
  102. $this->log($event->getlisting(), $this->user, $actionType);
  103. }
  104. public function listingPremiumFeaturedEvent(ListingEvent $event): void
  105. {
  106. $actionType = ListingActivityType::PREMIUM;
  107. $this->log($event->getlisting(), $this->user, $actionType);
  108. }
  109. public function listingSponsoredFeaturedEvent(ListingEvent $event): void
  110. {
  111. $actionType = ListingActivityType::SPONSORED;
  112. $this->log($event->getlisting(), $this->user, $actionType);
  113. }
  114. public function listingSpotlightFeaturedEvent(ListingEvent $event): void
  115. {
  116. $actionType = ListingActivityType::SPOTLIGHT;
  117. $this->log($event->getlisting(), $this->user, $actionType);
  118. }
  119. public function listingUnFeaturedEvent(ListingEvent $event): void
  120. {
  121. $actionType = ListingActivityType::UNFEATURED;
  122. $this->log($event->getlisting(), $this->user, $actionType);
  123. }
  124. public function listingExpiredEvent(ListingEvent $event): void
  125. {
  126. $actionType = ListingActivityType::EXPIRED;
  127. $this->log($event->getlisting(), $this->user, $actionType);
  128. }
  129. public function listingRejectedEvent(ListingEvent $event): void
  130. {
  131. $actionType = ListingActivityType::REJECTED;
  132. $this->log($event->getlisting(), $this->user, $actionType, $event->getRejectionReasons());
  133. }
  134. public function listingPendingPhotoEvent(ListingEvent $event): void
  135. {
  136. $actionType = ListingActivityType::PENDING_PHOTOS;
  137. $this->log($event->getlisting(), $this->user, $actionType);
  138. }
  139. public function listingPendingPaymentEvent(ListingEvent $event): void
  140. {
  141. $actionType = ListingActivityType::PENDING_PAYMENT;
  142. if (ListingStatus::PENDING_PAYMENT != $event->getListing()->getStatus()) {
  143. $this->log($event->getlisting(), $this->user, $actionType);
  144. }
  145. }
  146. public function listingPublishFreeEvent(ListingEvent $event): void
  147. {
  148. $actionType = ListingActivityType::FREE_PUBLISH;
  149. $this->log($event->getlisting(), $this->user, $actionType);
  150. }
  151. public function listingPublishWithOutPhotoEvent(ListingEvent $event): void
  152. {
  153. $actionType = $this->user instanceof UserInterface
  154. ? ListingActivityType::PUBLISH_WITHOUT_PHOTOS
  155. : ListingActivityType::PUBLISH_WITHOUT_PHOTOS_BY_SYSTEM;
  156. $this->log($event->getlisting(), $this->user, $actionType);
  157. }
  158. public function listingAutoBumpUpStartedEvent(BumpListingEvent $event): void
  159. {
  160. $this->log(
  161. $event->getListing(),
  162. $this->user,
  163. ListingActivityType::AUTO_BUMP_UP_STARTED
  164. );
  165. }
  166. public function listingAutoBumpUpRevertedEvent(BumpListingEvent $event): void
  167. {
  168. $this->log(
  169. $event->getListing(),
  170. $this->user,
  171. ListingActivityType::AUTO_BUMP_UP_REVERTED
  172. );
  173. }
  174. public function listingAutoBumpUpStepEvent(BumpListingEvent $event): void
  175. {
  176. $this->log(
  177. $event->getListing(),
  178. $event->getBumpUpOwner(),
  179. ListingActivityType::AUTO_BUMP_UP_STEP
  180. );
  181. }
  182. public function listingAutoBumpUpExpiredEvent(BumpListingEvent $event): void
  183. {
  184. $this->log(
  185. $event->getListing(),
  186. $event->getBumpUpOwner(),
  187. ListingActivityType::AUTO_BUMP_UP_EXPIRED
  188. );
  189. }
  190. public function listingSoldByOwnerFeaturedEvent(ListingEvent $event): void
  191. {
  192. $this->log($event->getlisting(), $this->user, ListingActivityType::SOLD_BY_ADMIN);
  193. }
  194. public function listingSoldByOwnerSponsoredEvent(ListingEvent $event): void
  195. {
  196. $this->log($event->getlisting(), $this->user, ListingActivityType::SOLD_BY_ADMIN);
  197. }
  198. public function firstListingForFreeEvent(ListingEvent $event): void
  199. {
  200. $this->log($event->getlisting(), $this->user, ListingActivityType::FIRST_LISTING_FOR_FREE);
  201. }
  202. public function listingAiReviewEvent(ListingEvent $event): void
  203. {
  204. $this->log($event->getListing(), $this->user, ListingActivityType::AI_REVIEW);
  205. }
  206. public static function getSubscribedEvents(): array
  207. {
  208. return [
  209. 'aqarmap.listing.publish' => ['listingPublishEvent'],
  210. 'aqarmap.listing.scrapped.publish' => ['listingPublishEvent'],
  211. 'aqarmap.listing.delete' => ['listingDeleteEvent'],
  212. 'aqarmap.listing.delete_by_user' => ['listingDeleteByUserEvent'],
  213. 'aqarmap.listing.reset_title' => ['listingResetTitleEvent'],
  214. 'aqarmap.listing.reset_description' => ['listingResetDescriptionEvent'],
  215. 'aqarmap.listing.remove_numbers' => ['listingRemoveNumbersEvent'],
  216. 'aqarmap.listing.clear_video' => ['listingRemoveVideoEvent'],
  217. 'aqarmap.listing.clear_map' => ['listingRemoveMapEvent'],
  218. 'aqarmap.listing.clear_price' => ['listingRemovePriceEvent'],
  219. 'aqarmap.listing.featured' => ['listingFeaturedEvent'],
  220. 'aqarmap.listing.super_featured' => ['listingSuperFeaturedEvent'],
  221. 'aqarmap.listing.premium' => ['listingPremiumFeaturedEvent'],
  222. 'aqarmap.listing.sponsored' => ['listingSponsoredFeaturedEvent'],
  223. 'aqarmap.listing.spotlight' => ['listingSpotlightFeaturedEvent'],
  224. 'aqarmap.listing.bump_up_started' => ['listingAutoBumpUpStartedEvent'],
  225. 'aqarmap.listing.bump_up_reverted' => ['listingAutoBumpUpRevertedEvent'],
  226. 'aqarmap.listing.bump_up_step' => ['listingAutoBumpUpStepEvent'],
  227. 'aqarmap.listing.bump_up_expired' => ['listingAutoBumpUpExpiredEvent'],
  228. 'aqarmap.listing.unfeatured' => ['listingUnFeaturedEvent'],
  229. 'aqarmap.listing.expired' => ['listingExpiredEvent'],
  230. 'aqarmap.listing.rejected' => ['listingRejectedEvent'],
  231. 'aqarmap.listing.pending_photos' => ['listingPendingPhotoEvent'],
  232. 'aqarmap.listing.pending_payment' => ['listingPendingPaymentEvent'],
  233. 'aqarmap.listing.free_publish' => ['listingPublishFreeEvent'],
  234. 'aqarmap.listing.publish_without_photos' => ['listingPublishWithOutPhotoEvent'],
  235. 'aqarmap.listing.created' => ['listingCreatedEvent'],
  236. 'aqarmap.listing.pending_approval' => ['listingPendingApprovalEvent'],
  237. 'aqarmap.listing.sold_by_owner' => ['listingSoldByOwnerFeaturedEvent'],
  238. 'aqarmap.listing.sold_by_owner_sponsored' => ['listingSoldByOwnerSponsoredEvent'],
  239. 'aqarmap.listing.first_listing_for_free' => ['firstListingForFreeEvent'],
  240. 'aqarmap.listing.ai_review' => ['listingAiReviewEvent'],
  241. ];
  242. }
  243. }