src/FMT/Domain/Listener/DonateReceived.php line 27

Open in your IDE?
  1. <?php
  2. /**
  3.  * Author: Anton Orlov
  4.  * Date: 10.05.2018
  5.  * Time: 12:30
  6.  */
  7. namespace FMT\Domain\Listener;
  8. use FMT\Data\Entity\Transaction;
  9. use FMT\Data\Entity\UserTransaction;
  10. use FMT\Domain\Event\TransactionEvent;
  11. use FMT\Infrastructure\Helper\NotificationHelper;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. use Twig\Environment;
  14. class DonateReceived implements EventSubscriberInterface
  15. {
  16.     /** @var Environment */
  17.     private $parser;
  18.     public function __construct(Environment $parser)
  19.     {
  20.         $this->parser $parser;
  21.     }
  22.     public function onDonationReceived(TransactionEvent $event)
  23.     {
  24.         if ($event->getTransaction()->getSubType() !== Transaction::TXN_DONATION) {
  25.             return;
  26.         }
  27.         $message $this->parser->render("@Public/payment/donate_received.html.twig", [
  28.             "transaction" => $event->getTransaction()
  29.         ]);
  30.         $recipient $event->getTransaction()->getRecipient()->getProfile()->getEmail();
  31.         NotificationHelper::submitFromTemplate($message$recipient);
  32.     }
  33.     /**
  34.      * Returns an array of event names this subscriber wants to listen to.
  35.      *
  36.      * The array keys are event names and the value can be:
  37.      *
  38.      *  * The method name to call (priority defaults to 0)
  39.      *  * An array composed of the method name to call and the priority
  40.      *  * An array of arrays composed of the method names to call and respective
  41.      *    priorities, or 0 if unset
  42.      *
  43.      * For instance:
  44.      *
  45.      *  * array('eventName' => 'methodName')
  46.      *  * array('eventName' => array('methodName', $priority))
  47.      *  * array('eventName' => array(array('methodName1', $priority), array('methodName2')))
  48.      *
  49.      * @return array The event names to listen to
  50.      */
  51.     public static function getSubscribedEvents()
  52.     {
  53.         return [
  54.             TransactionEvent::TRANSACTION_COMPLETED => "onDonationReceived"
  55.         ];
  56.     }
  57. }