<?php
namespace App\EventListener;
use App\Entity\AdminNotification;
use App\Event\TreatmentActivityEvent;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Part\DataPart;
class TreatmentActivityListener
{
public function __construct(
private MailerInterface $mailer,
private ParameterBagInterface $parameterBag,
private EntityManagerInterface $em
){}
public function onPictureUploaded(TreatmentActivityEvent $event)
{
$treatmentActivity = $event->getTreatmentActivity();
$patient = $treatmentActivity->getTreatment()->getPatient();
$arguments = [
'treatment_id' => $treatmentActivity->getTreatment()->getId(),
'treatment_activity_id' => $treatmentActivity->getId(),
'patient_id' => $treatmentActivity->getId(),
'user_id' => $patient->getUser()->getId()
];
$adminNotification = new AdminNotification();
$adminNotification->setNotificationType(AdminNotification::ADMIN_NOTIFICATION_TYPE_PICTURE_UPLOAD);
$adminNotification->setMessage($patient->getName().' has uploaded new pictures');
$adminNotification->setArguments($arguments);
$this->em->persist($adminNotification);
$this->em->flush();
$email = (new TemplatedEmail())
->from(new Address('no-reply@idealofmed.bonzun.com', 'IdealOfMeD'))
->to($this->parameterBag->get('feedback_email_receiver'))
->subject('New Picture Upload Activity')
->htmlTemplate('emails/picture_upload_activity.html.twig')
->context([
'treatmentActivity' => $treatmentActivity,
'patient' => $patient,
]);
try{
$this->mailer->send($email);
}catch (\Exception $e){
print_r($e->getMessage());
}
}
}