Commit 4286b2f9 authored by Torsten Oppermann's avatar Torsten Oppermann
Browse files

[TASK] Adding functioniality to register with an object. Providing translations for marker types

parent 660cbcad
...@@ -72,9 +72,6 @@ class QueueController extends ActionController { ...@@ -72,9 +72,6 @@ class QueueController extends ActionController {
* @param int $uid * @param int $uid
*/ */
public function sendMailAction($uid) { public function sendMailAction($uid) {
/** @var Mail $mail */
$mail = $this->mailRepository->findByUid($uid)->getFirst();
$mailService = new MailTemplateService(); $mailService = new MailTemplateService();
$mailService->sendMailFromQueue($uid); $mailService->sendMailFromQueue($uid);
......
...@@ -44,30 +44,8 @@ use TYPO3\CMS\Fluid\View\StandaloneView; ...@@ -44,30 +44,8 @@ use TYPO3\CMS\Fluid\View\StandaloneView;
* MailTemplateService * MailTemplateService
*/ */
class MailTemplateService { class MailTemplateService {
/**
* @var string
*/
const MARKER_TYPE_STRING = 'String'; const MARKER_TYPE_STRING = 'String';
/**
* @var string
*/
const MARKER_TYPE_DATE = 'Date';
/**
* @var string
*/
const MARKER_TYPE_INTEGER = 'Integer';
/**
* @var string
*/
const MARKER_TYPE_ARRAY = 'Array'; const MARKER_TYPE_ARRAY = 'Array';
/**
* @var string
*/
const MARKER_TYPE_OBJECT = 'Object'; const MARKER_TYPE_OBJECT = 'Object';
/** /**
...@@ -237,6 +215,26 @@ class MailTemplateService { ...@@ -237,6 +215,26 @@ class MailTemplateService {
]; ];
} }
/**
* call in extlocalconf of an extension if you have a custom register class
*
* @param RegisterInterface
*
* @return bool
*/
public static function registerByFile($fileNameWithNamespace) {
$registerObject = GeneralUtility::makeInstance($fileNameWithNamespace);
// check instance of interface
if (!($registerObject instanceof RegisterInterface)) {
return FALSE;
}
// object ruft registerTemplate auf, beinhaltet alles aus extlocalconf
$registerObject->init();
$registerObject->registerTemplate();
return TRUE;
}
/** /**
* Return default markers for sg_mail * Return default markers for sg_mail
* *
...@@ -387,10 +385,10 @@ class MailTemplateService { ...@@ -387,10 +385,10 @@ class MailTemplateService {
$this->mailMessage->send(); $this->mailMessage->send();
$dateTime = new DateTime(); $dateTime = new DateTime();
$this->addMailToMailQueue( $this->addMailToMailQueue(
$this->extensionKey, $this->templateName, $subject, $emailBody, $this->priority, $dateTime->getTimestamp(), TRUE $this->extensionKey, $this->templateName, $subject, $emailBody, $this->priority,
$dateTime->getTimestamp(), TRUE
); );
} else { } else {
$this->addMailToMailQueue($this->extensionKey, $this->templateName, $subject, $emailBody, $this->priority); $this->addMailToMailQueue($this->extensionKey, $this->templateName, $subject, $emailBody, $this->priority);
} }
...@@ -409,7 +407,9 @@ class MailTemplateService { ...@@ -409,7 +407,9 @@ class MailTemplateService {
* @param int $priority * @param int $priority
* @param bool $sent * @param bool $sent
*/ */
private function addMailToMailQueue($extensionKey, $templateName, $subject, $emailBody, $priority, $sendingTime = 0, $sent = FALSE) { private function addMailToMailQueue(
$extensionKey, $templateName, $subject, $emailBody, $priority, $sendingTime = 0, $sent = FALSE
) {
$mail = $this->objectManager->get(Mail::class); $mail = $this->objectManager->get(Mail::class);
$mail->setExtensionKey($extensionKey); $mail->setExtensionKey($extensionKey);
$mail->setTemplateName($templateName); $mail->setTemplateName($templateName);
...@@ -487,7 +487,7 @@ class MailTemplateService { ...@@ -487,7 +487,7 @@ class MailTemplateService {
*/ */
public function setCcAddresses($ccAddresses) { public function setCcAddresses($ccAddresses) {
$this->ccAddresses = $ccAddresses; $this->ccAddresses = $ccAddresses;
$this->mailMessage->setCc(explode(',',$this->ccAddresses)); $this->mailMessage->setCc(explode(',', $this->ccAddresses));
return $this; return $this;
} }
...@@ -607,4 +607,25 @@ class MailTemplateService { ...@@ -607,4 +607,25 @@ class MailTemplateService {
public function setFromName($fromName) { public function setFromName($fromName) {
$this->fromName = $fromName; $this->fromName = $fromName;
} }
/**
* Provides translation for the marker data type
*
* @param string $markerType
*/
public static function getReadableMarkerType($markerType) {
switch ($markerType) {
case self::MARKER_TYPE_STRING :
LocalizationUtility::translate('backend.marker.type.string', 'sg_mail');
break;
case self::MARKER_TYPE_ARRAY :
LocalizationUtility::translate('backend.marker.type.array', 'sg_mail');
break;
case self::MARKER_TYPE_OBJECT :
LocalizationUtility::translate('backend.marker.type.object', 'sg_mail');
break;
default:
LocalizationUtility::translate('backend.marker.type.mixed', 'sg_mail');
}
}
} }
<?php
namespace SGalinski\SgMail\Service;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (https://www.sgalinski.de)
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Interface RegisterInterface
* describes behaviour of objects that want to register a template with sg_mail
*
* @package SGalinski\SgMail\Service
*/
interface RegisterInterface {
/**
* initialize certain values
*
* @return mixed
*/
public function init();
/**
* call MailTemplateService registerTemplate with according values
*
* @return mixed
*/
public function registerTemplate();
}
?>
\ No newline at end of file
...@@ -9,120 +9,129 @@ ...@@ -9,120 +9,129 @@
<authorEmail>torsten@sgalinski.de</authorEmail> <authorEmail>torsten@sgalinski.de</authorEmail>
</header> </header>
<body> <body>
<trans-unit id="backend.bcc"> <trans-unit id="backend.bcc">
<source>Bcc (Comma separated if multiple):</source> <source>Bcc (Comma separated if multiple):</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.button_reset"> <trans-unit id="backend.button_reset">
<source>Reset Template</source> <source>Reset Template</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.button_reset_all"> <trans-unit id="backend.button_reset_all">
<source>Reset all</source> <source>Reset all</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.cc"> <trans-unit id="backend.cc">
<source>cc (Comma separated if multiple):</source> <source>cc (Comma separated if multiple):</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.content"> <trans-unit id="backend.content">
<source>Text</source> <source>Text</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.delete_template"> <trans-unit id="backend.delete_template">
<source>Do you really want to reset this Template ?</source> <source>Do you really want to reset this Template ?</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.description"> <trans-unit id="backend.description">
<source>Description</source> <source>Description</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.email"> <trans-unit id="backend.email">
<source>Email</source> <source>Email</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.failure_mail"> <trans-unit id="backend.failure_mail">
<source>There was an error when sending the Preview Email. Please check your Configuration</source> <source>There was an error when sending the Preview Email. Please check your Configuration</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.fromAddress"> <trans-unit id="backend.fromAddress">
<source>From</source> <source>From</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.fromMail"> <trans-unit id="backend.fromMail">
<source>From E-Mail Address:</source> <source>From E-Mail Address:</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.fromName"> <trans-unit id="backend.fromName">
<source>From Name:</source> <source>From Name:</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.mail_queue"> <trans-unit id="backend.mail_queue">
<source>Mail Queue</source> <source>Mail Queue</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.marker"> <trans-unit id="backend.marker">
<source>Marker</source> <source>Marker</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.no_extension"> <trans-unit id="backend.no_extension">
<source>No Extension was registered</source> <source>No Extension was registered</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.not_sent"> <trans-unit id="backend.not_sent">
<source>Not Sent</source> <source>Not Sent</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.priority"> <trans-unit id="backend.priority">
<source>Priority</source> <source>Priority</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.replyTo"> <trans-unit id="backend.replyTo">
<source>Reply to:</source> <source>Reply to:</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.save"> <trans-unit id="backend.save">
<source>Save</source> <source>Save</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.select_language"> <trans-unit id="backend.select_language">
<source>Language (Reloads the page):</source> <source>Language (Reloads the page):</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.send_mail_again"> <trans-unit id="backend.send_mail_again">
<source>Send this E-Mail again ?</source> <source>Send this E-Mail again ?</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.send_mail_manually"> <trans-unit id="backend.send_mail_manually">
<source>Send this E-Mail now ?</source> <source>Send this E-Mail now ?</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.send_test"> <trans-unit id="backend.send_test">
<source>Send Preview Mail</source> <source>Send Preview Mail</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.sending_time"> <trans-unit id="backend.sending_time">
<source>Sending Time</source> <source>Sending Time</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.sent"> <trans-unit id="backend.sent">
<source>Sent</source> <source>Sent</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.subject"> <trans-unit id="backend.subject">
<source>Subject:</source> <source>Subject:</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.success"> <trans-unit id="backend.success">
<source>Successfully saved !</source> <source>Successfully saved !</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.success_mail"> <trans-unit id="backend.marker.type.string">
<source>Preview Email sent</source> <source>String</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.template_editor"> <trans-unit id="backend.marker.type.array">
<source>Template Editor</source> <source>Array</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.template_path"> <trans-unit id="backend.marker.type.object">
<source>Template Path:</source> <source>Object</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.template_reset"> <trans-unit id="backend.success_mail">
<source>Template was resetted succesfully</source> <source>Preview Email sent</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.toAddress"> <trans-unit id="backend.template_editor">
<source>To</source> <source>Template Editor</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.type"> <trans-unit id="backend.template_path">
<source>Type</source> <source>Template Path:</source>
</trans-unit> </trans-unit>
<trans-unit id="backend.value"> <trans-unit id="backend.template_reset">
<source>Value</source> <source>Template was resetted succesfully</source>
</trans-unit> </trans-unit>
<trans-unit id="mlang_labels_tabdescr"> <trans-unit id="backend.toAddress">
<source>Mail Templates</source> <source>To</source>
</trans-unit> </trans-unit>
<trans-unit id="mlang_labels_tablabel"> <trans-unit id="backend.type">
<source>Mail Templates</source> <source>Type</source>
</trans-unit> </trans-unit>
<trans-unit id="mlang_tabs_tab"> <trans-unit id="backend.value">
<source>Mail Templates</source> <source>Value</source>
</trans-unit> </trans-unit>
<trans-unit id="registeredExtension.action.message"> <trans-unit id="mlang_labels_tabdescr">
<source>Extension</source> <source>Mail Templates</source>
</trans-unit> </trans-unit>
<trans-unit id="mlang_labels_tablabel">
<source>Mail Templates</source>
</trans-unit>
<trans-unit id="mlang_tabs_tab">
<source>Mail Templates</source>
</trans-unit>
<trans-unit id="registeredExtension.action.message">
<source>Extension</source>
</trans-unit>
</body> </body>
</file> </file>
</xliff> </xliff>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment