<?php
/**
* Author: Anton Orlov
* Date: 10.05.2018
* Time: 12:30
*/
namespace FMT\Domain\Listener;
use FMT\Data\Entity\Transaction;
use FMT\Data\Entity\UserTransaction;
use FMT\Domain\Event\TransactionEvent;
use FMT\Infrastructure\Helper\NotificationHelper;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Twig\Environment;
class DonateSubmitted implements EventSubscriberInterface
{
/** @var Environment */
private $parser;
public function __construct(Environment $parser)
{
$this->parser = $parser;
}
public function onDonationSubmitted(TransactionEvent $event)
{
if ($event->getTransaction()->getSubType() !== Transaction::TXN_DONATION) {
return;
}
$message = $this->parser->render("@Public/payment/donate_submitted.html.twig", [
"transaction" => $event->getTransaction()
]);
$recipient = $event->getTransaction()->getSender()->getEmail();
NotificationHelper::submitFromTemplate($message, $recipient);
}
/**
* Returns an array of event names this subscriber wants to listen to.
*
* The array keys are event names and the value can be:
*
* * The method name to call (priority defaults to 0)
* * An array composed of the method name to call and the priority
* * An array of arrays composed of the method names to call and respective
* priorities, or 0 if unset
*
* For instance:
*
* * array('eventName' => 'methodName')
* * array('eventName' => array('methodName', $priority))
* * array('eventName' => array(array('methodName1', $priority), array('methodName2')))
*
* @return array The event names to listen to
*/
public static function getSubscribedEvents()
{
return [
TransactionEvent::TRANSACTION_COMPLETED => "onDonationSubmitted"
];
}
}