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 {
* @param int $uid
*/
public function sendMailAction($uid) {
/** @var Mail $mail */
$mail = $this->mailRepository->findByUid($uid)->getFirst();
$mailService = new MailTemplateService();
$mailService->sendMailFromQueue($uid);
......
......@@ -44,30 +44,8 @@ use TYPO3\CMS\Fluid\View\StandaloneView;
* MailTemplateService
*/
class MailTemplateService {
/**
* @var 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';
/**
* @var string
*/
const MARKER_TYPE_OBJECT = 'Object';
/**
......@@ -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
*
......@@ -387,10 +385,10 @@ class MailTemplateService {
$this->mailMessage->send();
$dateTime = new DateTime();
$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 {
$this->addMailToMailQueue($this->extensionKey, $this->templateName, $subject, $emailBody, $this->priority);
}
......@@ -409,7 +407,9 @@ class MailTemplateService {
* @param int $priority
* @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->setExtensionKey($extensionKey);
$mail->setTemplateName($templateName);
......@@ -487,7 +487,7 @@ class MailTemplateService {
*/
public function setCcAddresses($ccAddresses) {
$this->ccAddresses = $ccAddresses;
$this->mailMessage->setCc(explode(',',$this->ccAddresses));
$this->mailMessage->setCc(explode(',', $this->ccAddresses));
return $this;
}
......@@ -607,4 +607,25 @@ class MailTemplateService {
public function setFromName($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
......@@ -90,6 +90,15 @@
<trans-unit id="backend.success">
<source>Successfully saved !</source>
</trans-unit>
<trans-unit id="backend.marker.type.string">
<source>String</source>
</trans-unit>
<trans-unit id="backend.marker.type.array">
<source>Array</source>
</trans-unit>
<trans-unit id="backend.marker.type.object">
<source>Object</source>
</trans-unit>
<trans-unit id="backend.success_mail">
<source>Preview Email sent</source>
</trans-unit>
......
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