src/Mailer/AccountMailer.php line 30

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: Ronald
  5.  * Date: 6/15/2020
  6.  * Time: 1:32 PM
  7.  */
  8. namespace App\Mailer;
  9. use App\Entity\CustomerAccount;
  10. use App\Entity\User;
  11. use App\Entity\RequestAccess;
  12. use App\Repository\CustomerAccountRepository;
  13. use App\Repository\UserRepository;
  14. use Symfony\Component\DependencyInjection\ContainerInterface;
  15. use Symfony\Component\Mailer\MailerInterface;
  16. class AccountMailer extends Mailer
  17. {
  18.     /**
  19.      * Mailer constructor.
  20.      * @param MailerInterface $mailer
  21.      * @param  ContainerInterface $container
  22.      * @param $env
  23.      * @throws \Exception
  24.      */
  25.     public function __construct(MailerInterface $mailer,  ContainerInterface $container,$env)
  26.     {
  27.         parent::__construct($mailer$container,$env);
  28.     }
  29. //USER Emails
  30.     public function newUserEmail(User $user,$plainPassword)
  31.     {
  32.         $emailBody $this->twig->render('email/account/newUser.html.twig', array('user' => $user,'plainPassword'=>$plainPassword));
  33.         $this->send('Welcome to Overseas Express!'$emailBody$user->getEmail());
  34.     }
  35.     public function changePasswordEmail(User $user,$plainPassword)
  36.     {
  37.         $fromEmail=null;
  38.         if($this->container->get('session')->get('customerAccountDomain')){
  39.             $fromEmail ='noreply@gtnxpress.com';
  40.         }
  41.         $emailBody $this->twig->render('email/account/changePassword.html.twig', array('user' => $user,'plainPassword'=>$plainPassword));
  42.         $this->send('Your password has been reset'$emailBody$user->getEmail(),null,[],false,$fromEmail);
  43.     }
  44.     public function forgotPasswordEmail(User $user)
  45.     {
  46.         $fromEmail=null;
  47.         if($this->container->get('session')->get('customerAccountDomain')){
  48.             $fromEmail ='noreply@gtnxpress.com';
  49.         }
  50.         $emailBody $this->twig->render('email/account/forgotPassword.html.twig', array('user' => $user));
  51.         $this->send('Reset Password Email'$emailBody$user->getEmail(),null,[],false,$fromEmail);
  52.     }
  53.     public function resetPasswordEmail(User $user)
  54.     {
  55.         $fromEmail=null;
  56.         if($this->container->get('session')->get('customerAccountDomain')){
  57.             $fromEmail ='noreply@gtnxpress.com';
  58.         }
  59.         $emailBody $this->twig->render('email/account/resetPassword.html.twig', array('user' => $user));
  60.         $this->send('Reset Password Email'$emailBody$user->getEmail(),null,[],false,$fromEmail);
  61.     }
  62. //CustomerAccount Emails
  63.     public function changeCreditLevelEmail(User $userCustomerAccount $customerAccount$currentLevel)
  64.     {
  65.         $emailBody $this->twig->render('email/account/customerAccountLevelChange.html.twig', array('user'=>$user,'customerAccount' => $customerAccount,'currentLevel'=>$currentLevel));
  66.         $this->send('CustomerAccount level change: '.$customerAccount->getName(), $emailBody);
  67.     }
  68.     //Request Access Emails
  69.     public function requestAccessEmail(RequestAccess $requestAccessUserRepository $userRepository,$isCustomerAccountDomain=false)
  70.     {
  71.         $customerAccount=null;
  72.         $from=null;
  73.         $from2=null;
  74.         if($isCustomerAccountDomain){
  75.             $customerAccount=$requestAccess->getCustomerAccount();
  76.             $emailList=['support@gtnxpress.com'];
  77.             $from='support@gtnxpress.com';
  78.             $from2='noreply@gtnxpress.com';
  79.         }
  80.         else {
  81.             $emailList = ['backoffice@overseasnetwork.com'];
  82.         }
  83.         //1st Email
  84.         $emailBody $this->twig->render('email/account/requestAccessUser.html.twig', array('requestAccess' => $requestAccess,'customerAccount'=>$customerAccount));
  85.         $this->send('New account request'$emailBody$requestAccess->getEmail(),null,[],false$from);
  86. //            $this->send('New account request', $emailBody, ['marinar@overseasnetwork.com'],null,[],false,'support@gtnxpress.com');//to test
  87.         //2nd Email
  88.         //Send to users with role "ROLE_MANAGER_ACCOUNT_APPROVAL"
  89.         if($managerAccountApprovalList=$userRepository->findAllByRoleManagerAccountApproval($customerAccount)) {
  90.             /**
  91.              * @var User $managerAccountApproval
  92.              */
  93.             foreach ($managerAccountApprovalList as $managerAccountApproval) {
  94.                 $emailList[] = $managerAccountApproval->getEmail();
  95.             }
  96.         }
  97.         $emailBody $this->twig->render('email/account/requestAccessAdmin.html.twig', array('requestAccess' => $requestAccess,'customerAccount'=>$customerAccount));
  98.         $this->send('New Account Request Pending - ' $requestAccess->getCustomerAccountName(), $emailBody$emailList,[],[],false,$from2);
  99.     }
  100.     public function sendCreationEmail(User $user,$isHost=false)
  101.     {
  102.         $fromEmail=null;
  103.         if($isHost){
  104.             $fromEmail='noreply@gtnxpress.com';
  105.             $customerAccountDomain=$user->getCustomerAccount();
  106.             if($customerAccountDomain->getParentCustomerAccount()){
  107.                 $customerAccountDomain=$user->getCustomerAccount()->getParentCustomerAccount();
  108.             }
  109.             $emailBody $this->twig->render('email/account/sendCreationEmailHost.html.twig', array('user' => $user,'customerAccount'=>$user->getCustomerAccount(),'customerAccountDomain'=>$customerAccountDomain));
  110.         }
  111.         else {
  112.             $emailBody $this->twig->render('email/account/sendCreationEmail.html.twig', array('user' => $user));
  113.         }
  114.         $this->send($isHost?'Welcome to '.$user->getCustomerAccount()->getName().'!':'Welcome to OverseasXpress!'$emailBody$user->getEmail(),null,[],false,$fromEmail);
  115.     }
  116. }