diff --git a/api/BusinessLogic/Emails/EmailSenderHelper.php b/api/BusinessLogic/Emails/EmailSenderHelper.php index 4dbd9436..1724dc25 100644 --- a/api/BusinessLogic/Emails/EmailSenderHelper.php +++ b/api/BusinessLogic/Emails/EmailSenderHelper.php @@ -47,6 +47,17 @@ class EmailSenderHelper { $emailBuilder->cc = $addressees->cc; $emailBuilder->bcc = $addressees->bcc; + foreach ($heskSettings['custom_fields'] as $k => $v) { + $number = intval(str_replace('custom', '', $k)); + if ($v['use'] && $v['type'] == 'email' && !empty($ticket->customFields[$number])) { + if ($v['value']['email_type'] == 'cc') { + $emailBuilder->cc[] = $ticket->customFields[$number]; + } elseif ($v['value']['email_type'] == 'bcc') { + $emailBuilder->bcc[] = $ticket->customFields[$number]; + } + } + } + if ($modsForHeskSettings['attachments']) { $emailBuilder->attachments = $ticket->attachments; } diff --git a/api/BusinessLogic/Tickets/TicketCreator.php b/api/BusinessLogic/Tickets/TicketCreator.php index 8409623c..25e4ba22 100644 --- a/api/BusinessLogic/Tickets/TicketCreator.php +++ b/api/BusinessLogic/Tickets/TicketCreator.php @@ -2,6 +2,7 @@ namespace BusinessLogic\Tickets; +use BusinessLogic\Emails\EmailSenderHelper; use BusinessLogic\Exceptions\ValidationException; use BusinessLogic\Statuses\DefaultStatusForAction; use DataAccess\Statuses\StatusGateway; @@ -38,13 +39,20 @@ class TicketCreator { */ private $verifiedEmailChecker; - function __construct($newTicketValidator, $trackingIdGenerator, $autoassigner, $statusGateway, $ticketGateway, $verifiedEmailChecker) { + /** + * @var $emailSenderHelper EmailSenderHelper + */ + private $emailSenderHelper; + + function __construct($newTicketValidator, $trackingIdGenerator, $autoassigner, + $statusGateway, $ticketGateway, $verifiedEmailChecker, $emailSenderHelper) { $this->newTicketValidator = $newTicketValidator; $this->trackingIdGenerator = $trackingIdGenerator; $this->autoassigner = $autoassigner; $this->statusGateway = $statusGateway; $this->ticketGateway = $ticketGateway; $this->verifiedEmailChecker = $verifiedEmailChecker; + $this->emailSenderHelper = $emailSenderHelper; } /** diff --git a/api/Tests/BusinessLogic/Emails/EmailSenderHelperTest.php b/api/Tests/BusinessLogic/Emails/EmailSenderHelperTest.php index 2f3a4d98..050abcb3 100644 --- a/api/Tests/BusinessLogic/Emails/EmailSenderHelperTest.php +++ b/api/Tests/BusinessLogic/Emails/EmailSenderHelperTest.php @@ -41,7 +41,9 @@ class EmailSenderHelperTest extends TestCase { $this->emailTemplateParser = $this->createMock(EmailTemplateParser::class); $this->basicEmailSender = $this->createMock(BasicEmailSender::class); $this->mailgunEmailSender = $this->createMock(MailgunEmailSender::class); - $this->heskSettings = array(); + $this->heskSettings = array( + 'custom_fields' => array() + ); $this->modsForHeskSettings = array( 'attachments' => 0, 'use_mailgun' => 0, diff --git a/api/Tests/BusinessLogic/Tickets/TicketCreatorTests/CreateTicketForCustomerTest.php b/api/Tests/BusinessLogic/Tickets/TicketCreatorTests/CreateTicketForCustomerTest.php index 54c22684..bf80c962 100644 --- a/api/Tests/BusinessLogic/Tickets/TicketCreatorTests/CreateTicketForCustomerTest.php +++ b/api/Tests/BusinessLogic/Tickets/TicketCreatorTests/CreateTicketForCustomerTest.php @@ -246,4 +246,8 @@ class CreateTicketTest extends TestCase { //-- Act $this->ticketCreator->createTicketByCustomer($this->ticketRequest, $this->heskSettings, $this->modsForHeskSettings, $this->userContext); } + + function testItSendsAnEmailToTheCustomerWhenTheTicketIsCreated() { + //-- + } }