src/EventListener/TreatmentActivityListener.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\Entity\AdminNotification;
  4. use App\Event\TreatmentActivityEvent;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Bridge\Twig\Mime\TemplatedEmail;
  7. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  8. use Symfony\Component\HttpFoundation\File\File;
  9. use Symfony\Component\Mailer\MailerInterface;
  10. use Symfony\Component\Mime\Address;
  11. use Symfony\Component\Mime\Part\DataPart;
  12. class TreatmentActivityListener
  13. {
  14.     public function __construct(
  15.         private MailerInterface $mailer,
  16.         private ParameterBagInterface $parameterBag,
  17.         private EntityManagerInterface $em
  18.     ){}
  19.     public function onPictureUploaded(TreatmentActivityEvent $event)
  20.     {
  21.         $treatmentActivity $event->getTreatmentActivity();
  22.         $patient $treatmentActivity->getTreatment()->getPatient();
  23.         $arguments = [
  24.             'treatment_id' => $treatmentActivity->getTreatment()->getId(),
  25.             'treatment_activity_id' => $treatmentActivity->getId(),
  26.             'patient_id' => $treatmentActivity->getId(),
  27.             'user_id' => $patient->getUser()->getId()
  28.         ];
  29.         $adminNotification = new AdminNotification();
  30.         $adminNotification->setNotificationType(AdminNotification::ADMIN_NOTIFICATION_TYPE_PICTURE_UPLOAD);
  31.         $adminNotification->setMessage($patient->getName().' has uploaded new pictures');
  32.         $adminNotification->setArguments($arguments);
  33.         $this->em->persist($adminNotification);
  34.         $this->em->flush();
  35.         $email = (new TemplatedEmail())
  36.             ->from(new Address('no-reply@idealofmed.bonzun.com''IdealOfMeD'))
  37.             ->to($this->parameterBag->get('feedback_email_receiver'))
  38.             ->subject('New Picture Upload Activity')
  39.             ->htmlTemplate('emails/picture_upload_activity.html.twig')
  40.             ->context([
  41.                 'treatmentActivity' => $treatmentActivity,
  42.                 'patient' => $patient,
  43.             ]);
  44.         try{
  45.             $this->mailer->send($email);
  46.         }catch (\Exception $e){
  47.             print_r($e->getMessage());
  48.         }
  49.     }
  50. }