vendor/uvdesk/core-framework/Workflow/Actions/Customer/MailCustomer.php line 44

Open in your IDE?
  1. <?php
  2. namespace Webkul\UVDesk\CoreFrameworkBundle\Workflow\Actions\Customer;
  3. use Webkul\UVDesk\CoreFrameworkBundle\Entity as CoreEntities;
  4. use Webkul\UVDesk\AutomationBundle\Workflow\FunctionalGroup;
  5. use Webkul\UVDesk\CoreFrameworkBundle\Entity\Ticket;
  6. use Symfony\Component\DependencyInjection\ContainerInterface;
  7. use Webkul\UVDesk\AutomationBundle\Workflow\Action as WorkflowAction;
  8. use Webkul\UVDesk\CoreFrameworkBundle\Entity\EmailTemplates;
  9. use Webkul\UVDesk\AutomationBundle\Workflow\Event;
  10. use Webkul\UVDesk\AutomationBundle\Workflow\Events\AgentActivity;
  11. use Webkul\UVDesk\AutomationBundle\Workflow\Events\CustomerActivity;
  12. class MailCustomer extends WorkflowAction
  13. {
  14.     public static function getId()
  15.     {
  16.         return 'uvdesk.customer.mail_customer';
  17.     }
  18.     public static function getDescription()
  19.     {
  20.         return "Mail to customer";
  21.     }
  22.     public static function getFunctionalGroup()
  23.     {
  24.         return FunctionalGroup::CUSTOMER;
  25.     }
  26.     
  27.     public static function getOptions(ContainerInterface $container)
  28.     {
  29.         $entityManager $container->get('doctrine.orm.entity_manager');
  30.         return array_map(function ($emailTemplate) {
  31.             return [
  32.                 'id' => $emailTemplate->getId(),
  33.                 'name' => $emailTemplate->getName(),
  34.             ];
  35.         }, $entityManager->getRepository(EmailTemplates::class)->findAll());
  36.     }
  37.     public static function applyAction(ContainerInterface $containerEvent $event$value null)
  38.     {
  39.         $entityManager $container->get('doctrine.orm.entity_manager');
  40.         if (!$event instanceof CustomerActivity) {
  41.             return;
  42.         } else {
  43.             $user $event->getUser();
  44.             $emailTemplate $entityManager->getRepository(EmailTemplates::class)->findOneById($value);
  45.     
  46.             if (empty($user) || empty($emailTemplate)) {
  47.                 // @TODO: Send default email template
  48.                 return;
  49.             }
  50.         }
  51.         $emailPlaceholders $container->get('email.service')->getEmailPlaceholderValues($user'customer');
  52.         $subject $container->get('email.service')->processEmailSubject($emailTemplate->getSubject(), $emailPlaceholders);
  53.         $message $container->get('email.service')->processEmailContent($emailTemplate->getMessage(), $emailPlaceholders);
  54.         
  55.         $messageId $container->get('email.service')->sendMail($subject$message$user->getEmail());
  56.     }
  57. }