Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
TYPO3
sg_mail
Commits
fefdc1a1
Commit
fefdc1a1
authored
Sep 27, 2016
by
Torsten Oppermann
Browse files
[TASK] New MailTemplateService API
parent
78f816d7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Classes/Service/MailTemplateService.php
View file @
fefdc1a1
...
@@ -8,8 +8,6 @@ use TYPO3\CMS\Core\Mail\MailMessage;
...
@@ -8,8 +8,6 @@ use TYPO3\CMS\Core\Mail\MailMessage;
use
TYPO3\CMS\Core\Utility\GeneralUtility
;
use
TYPO3\CMS\Core\Utility\GeneralUtility
;
use
TYPO3\CMS\Extbase\Object\ObjectManager
;
use
TYPO3\CMS\Extbase\Object\ObjectManager
;
use
TYPO3\CMS\Fluid\View\StandaloneView
;
use
TYPO3\CMS\Fluid\View\StandaloneView
;
use
TYPO3\CMS\Lang\LanguageService
;
use
Typoheads\Formhandler\Finisher\AbstractFinisher
;
/***************************************************************
/***************************************************************
* Copyright notice
* Copyright notice
...
@@ -45,6 +43,69 @@ class MailTemplateService {
...
@@ -45,6 +43,69 @@ class MailTemplateService {
*/
*/
private
static
$registerArray
=
[];
private
static
$registerArray
=
[];
/**
* @var array to
*/
private
$to
=
[];
/**
* @var string from
*/
private
$from
;
/**
* @var string $cc
*/
private
$cc
;
/**
* @var string replyTo
*/
private
$replyTo
;
/**
* @var string language
*/
private
$language
;
/**
* @var boolean ignoreMailQueue
*/
private
$ignoreMailQueue
=
TRUE
;
/**
* @var \TYPO3\CMS\Core\Mail\MailMessage $mailMessage
*/
private
$mailMessage
;
/**
* @var string templateName
*/
private
$templateName
;
/**
* @var string extensionKey
*/
private
$extensionKey
;
/**
* @var array content
*/
private
$content
=
[];
/**
* @var string subject
*/
private
$subject
;
/**
* MailTemplateService constructor.
*/
public
function
__construct
()
{
$objectManager
=
GeneralUtility
::
makeInstance
(
ObjectManager
::
class
);
$this
->
mailMessage
=
$objectManager
->
get
(
MailMessage
::
class
);
}
/**
/**
* register a template with sg_mail
* register a template with sg_mail
*
*
...
@@ -82,61 +143,36 @@ class MailTemplateService {
...
@@ -82,61 +143,36 @@ class MailTemplateService {
}
}
/**
/**
* send an Email
* send the Email
*
* @param string $language
* @param string $templateKey
* @param string $extensionKey
* @param array $toAddress
* @param array $fromAddress
* @param string $subject
* @param array $content
* @param boolean $ignoreMailQueue
*/
*/
public
static
function
sendEmail
(
public
function
sendEmail
()
{
$language
,
$templateKey
,
$extensionKey
,
array
$toAddress
,
array
$fromAddress
,
$subject
,
array
$content
,
$ignoreMailQueue
=
FALSE
)
{
// @TODO get language dynamically
!
isset
(
$language
)
?
$language
=
'de'
:
null
;
// Set Email Content
$registerArray
=
MailTemplateService
::
getRegisterArray
();
$registerArray
=
MailTemplateService
::
getRegisterArray
();
$templateEntry
=
$registerArray
[
$extensionKey
][
$template
Key
];
$templateEntry
=
$registerArray
[
$
this
->
extensionKey
][
$
this
->
template
Name
];
$objectManager
=
GeneralUtility
::
makeInstance
(
ObjectManager
::
class
);
$objectManager
=
GeneralUtility
::
makeInstance
(
ObjectManager
::
class
);
$emailView
=
$objectManager
->
get
(
StandaloneView
::
class
);
$emailView
=
$objectManager
->
get
(
StandaloneView
::
class
);
$emailView
->
setTemplatePathAndFilename
(
$templateEntry
[
'templatePath'
]
.
$language
.
'.sg_mail.locallang.html'
);
$emailView
->
setTemplatePathAndFilename
(
$emailView
->
assignMultiple
(
$content
);
$templateEntry
[
'templatePath'
]
.
$this
->
language
.
'.sg_mail.locallang.html'
);
$emailView
->
assignMultiple
(
$this
->
content
);
$emailBody
=
$emailView
->
render
();
$emailBody
=
$emailView
->
render
();
if
(
$ignoreMailQueue
)
{
if
(
$this
->
ignoreMailQueue
)
{
$mailMessage
=
$objectManager
->
get
(
MailMessage
::
class
);
$mailMessage
->
setFrom
(
$fromAddress
);
$this
->
mailMessage
->
setSubject
(
$this
->
subject
);
$mailMessage
->
setTo
(
$toAddress
);
$this
->
mailMessage
->
setBody
(
$emailBody
,
'text/html'
);
$mailMessage
->
setSubject
(
$subject
);
$this
->
mailMessage
->
send
();
$mailMessage
->
setBody
(
$emailBody
,
'text/html'
);
$mailMessage
->
send
();
}
else
{
}
else
{
// @todo evtl. sollten hier noch die Parameter $priority und $pid mit gegeben werden.
$this
->
addMailToMailQueue
(
$emailBody
);
self
::
addMailToMailQueue
(
$fromAddress
,
$toAddress
,
$subject
,
$emailBody
);
}
}
}
}
/**
/**
* Adds a new mail to the mail queue.
This will have the given parameters.
* Adds a new mail to the mail queue.
*
*
* @param string $fromAddress
* @param string $emailBody
* @param string $toAddress
*/
* @param string $mailSubject
private
function
addMailToMailQueue
(
$emailBody
,
$priority
=
Mail
::
PRIORITY_LOWEST
,
$pid
=
0
)
{
* @param string $mailBody
* @param int $priority
* @param int $pid
*/
public
static
function
addMailToMailQueue
(
$fromAddress
,
$toAddress
,
$mailSubject
,
$mailBody
=
''
,
$priority
=
Mail
::
PRIORITY_LOWEST
,
$pid
=
0
)
{
/** @var ObjectManager $objectManager */
/** @var ObjectManager $objectManager */
$objectManager
=
GeneralUtility
::
makeInstance
(
ObjectManager
::
class
);
$objectManager
=
GeneralUtility
::
makeInstance
(
ObjectManager
::
class
);
...
@@ -146,13 +182,107 @@ class MailTemplateService {
...
@@ -146,13 +182,107 @@ class MailTemplateService {
$mail
=
$objectManager
->
get
(
Mail
::
class
);
$mail
=
$objectManager
->
get
(
Mail
::
class
);
$mail
->
setPid
(
$pid
);
$mail
->
setPid
(
$pid
);
$mail
->
setFromAddress
(
$
fromAddress
);
$mail
->
setFromAddress
(
$
this
->
from
);
$mail
->
setToAddress
(
$t
oAddress
);
$mail
->
setToAddress
(
$t
his
->
to
);
$mail
->
setMailSubject
(
$
mailS
ubject
);
$mail
->
setMailSubject
(
$
this
->
s
ubject
);
$mail
->
setMailBody
(
$mailBody
);
$mail
->
setMailBody
(
$
e
mailBody
);
$mail
->
setPriority
(
$priority
);
$mail
->
setPriority
(
$priority
);
$mailRepository
=
$objectManager
->
get
(
MailRepository
::
class
);
$mailRepository
=
$objectManager
->
get
(
MailRepository
::
class
);
$mailRepository
->
add
(
$mail
);
$mailRepository
->
add
(
$mail
);
}
}
/**
* @param array $registerArray
* @return MailTemplateService
*/
public
static
function
setRegisterArray
(
$registerArray
)
{
self
::
$registerArray
=
$registerArray
;
}
/**
* @param array | string $to
* @return MailTemplateService
*/
public
function
setTo
(
$to
)
{
$this
->
to
=
$to
;
$this
->
mailMessage
->
setTo
(
$to
);
return
$this
;
}
/**
* @param array | string $from
* @return MailTemplateService
*/
public
function
setFrom
(
$from
)
{
$this
->
from
=
$from
;
$this
->
mailMessage
->
setFrom
(
$from
);
return
$this
;
}
/**
* @param array | string $cc
* @return MailTemplateService
*/
public
function
setCc
(
$cc
)
{
$this
->
cc
=
$cc
;
$this
->
mailMessage
->
setCc
(
$cc
);
return
$this
;
}
/**
* @param array | string $replyTo
* @return MailTemplateService
*/
public
function
setReplyTo
(
$replyTo
)
{
$this
->
replyTo
=
$replyTo
;
$this
->
mailMessage
->
setReplyTo
(
$replyTo
);
return
$this
;
}
/**
* @param string $language
* @return MailTemplateService
*/
public
function
setLanguage
(
$language
)
{
$this
->
language
=
$language
;
return
$this
;
}
/**
* @param boolean $ignoreMailQueue
* @return MailTemplateService
*/
public
function
setIgnoreMailQueue
(
$ignoreMailQueue
)
{
$this
->
ignoreMailQueue
=
$ignoreMailQueue
;
return
$this
;
}
/**
* @param string $templateName
* @return MailTemplateService
*/
public
function
setTemplateName
(
$templateName
)
{
$this
->
templateName
=
$templateName
;
return
$this
;
}
/**
* @param string $extensionKey
* @return MailTemplateService
*/
public
function
setExtensionKey
(
$extensionKey
)
{
$this
->
extensionKey
=
$extensionKey
;
return
$this
;
}
/**
* @param string $subject
* @return MailTemplateService
*/
public
function
setSubject
(
$subject
)
{
$this
->
subject
=
$subject
;
$this
->
mailMessage
->
setSubject
(
$subject
);
return
$this
;
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment