Commit 38376929 authored by Oliver Eglseder's avatar Oliver Eglseder
Browse files

[WIP][TASK] Add testSend

parent 0d33cf15
......@@ -13,8 +13,9 @@ namespace TYPO3\Election\Controller;
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Messaging\AbstractMessage;
use TYPO3\Election\Domain\Model\ElectionCircular;
use TYPO3\Election\Domain\Model\Elector;
use TYPO3\Election\Utility\MailUtility;
/**
* Class BeConfigurationController
......@@ -29,6 +30,7 @@ class BeElectionCircularController extends AbstractProtectedBeController
const ACTION_UPDATE = 'update';
const ACTION_DELETE = 'delete';
const ACTION_PREVIEW = 'preview';
const ACTION_TEST_SEND = 'testSend';
/**
* @var \TYPO3\Election\Domain\Repository\ElectionCircularRepository
......@@ -104,6 +106,25 @@ class BeElectionCircularController extends AbstractProtectedBeController
$this->view->assign('electionCircular', $electionCircular);
}
/**
* @param ElectionCircular $electionCircular
* @param string $email
*/
public function testSendAction(ElectionCircular $electionCircular, $email)
{
$elector = new Elector();
$elector->setFirstName('[FIRST NAME]');
$elector->setMiddleName('[MIDDLE NAME]');
$elector->setLastName('[LAST NAME]');
$elector->setEmail($email);
$elector->setGender(rand(1, 2));
$this->objectManager->get(MailUtility::class)->sendElectionCircularToElector(
$electionCircular,
$elector,
$this->configuration
);
}
/**
* @return bool
*/
......@@ -128,6 +149,7 @@ class BeElectionCircularController extends AbstractProtectedBeController
self::ACTION_UPDATE,
self::ACTION_DELETE,
self::ACTION_PREVIEW,
self::ACTION_TEST_SEND,
]
);
}
......
......@@ -13,6 +13,7 @@ namespace TYPO3\Election\Domain\Model;
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
/**
......
......@@ -14,6 +14,10 @@ namespace TYPO3\Election\Domain\Model;
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
use TYPO3\Election\Domain\Repository\ConfigurationRepository;
class Configuration extends AbstractEntity
{
const AUTH_NONE = 0;
......@@ -49,6 +53,16 @@ class Configuration extends AbstractEntity
*/
protected $numberOfMails = 10;
/**
* @var string
*/
protected $fromEmail = 'eab@typo3.org';
/**
* @var string
*/
protected $fromName = 'TYPO3 Association Board';
/**
* @return int
*/
......@@ -129,6 +143,38 @@ class Configuration extends AbstractEntity
$this->numberOfMails = $numberOfMails;
}
/**
* @return string
*/
public function getFromEmail()
{
return $this->fromEmail;
}
/**
* @param string $fromEmail
*/
public function setFromEmail($fromEmail)
{
$this->fromEmail = $fromEmail;
}
/**
* @return string
*/
public function getFromName()
{
return $this->fromName;
}
/**
* @param string $fromName
*/
public function setFromName($fromName)
{
$this->fromName = $fromName;
}
/**
* @return Configuration
*/
......
......@@ -46,7 +46,7 @@ class Electorate extends AbstractEntity
}
/**
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
* @return \TYPO3\Election\Domain\Model\Elector[]
*/
public function getElectors()
{
......@@ -54,7 +54,7 @@ class Electorate extends AbstractEntity
}
/**
* @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $electors
* @param \TYPO3\Election\Domain\Model\Elector[] $electors
*/
public function setElectors($electors)
{
......
<?php
namespace TYPO3\Election\Utility;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Mail\MailMessage;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\Election\Domain\Model\Configuration;
use TYPO3\Election\Domain\Model\ElectionCircular;
use TYPO3\Election\Domain\Model\Elector;
/**
* Class MailUtility
*/
class MailUtility
{
/**
* @param ElectionCircular $electionCircular
* @param Elector $elector
* @param Configuration $configuration
*/
public function sendElectionCircularToElector(
ElectionCircular $electionCircular,
Elector $elector,
Configuration $configuration
) {
if (GeneralUtility::makeInstance(MailMessage::class)
->setSubject($electionCircular->getSubject())
->setFrom(array($configuration->getFromEmail() => $configuration->getFromName()))
->setTo(array($elector->getEmail() => $elector->getFullName()))
->setBody($electionCircular->getRenderedBody($elector))
->send() === 1) {
$elector->getElectionTokensForElection($electionCircular->getElection())->setEmailSent(true);
}
}
}
......@@ -321,8 +321,8 @@
<trans-unit id="view.be.election_circular.edit.welcome">
<source>Edit an Election Circular</source>
</trans-unit>
<trans-unit id="view.be.election_circular.send.welcome">
<source>Send out the Circular</source>
<trans-unit id="view.be.election_circular.preview.welcome">
<source>Preview the Election Circular</source>
</trans-unit>
<trans-unit id="view.be.election_circular.edit.save_and_send">
<source>Save and send</source>
......@@ -339,6 +339,15 @@
<trans-unit id="view.be.election_circular.no_plugin_detected_message">
<source>There is no active election plugin on the configured page [%d]. You will not be able to send out the circular.</source>
</trans-unit>
<trans-unit id="view.be.election_circular.preview.title">
<source>Preview</source>
</trans-unit>
<trans-unit id="view.be.election_circular.preview.test_receiver">
<source>Test receiver</source>
</trans-unit>
<trans-unit id="view.be.election_circular.preview.send_to_test_email">
<source>Send test</source>
</trans-unit>
<!-- MODEL ELECTION CIRCULARS -->
......
......@@ -9,8 +9,15 @@
</span>
</div>
<div class="media-body">
<h4 class="alert-title"><f:translate key="view.be.election_circular.plugin_detected">Plugin detected</f:translate></h4>
<div class="alert-message"><f:translate key="view.be.election_circular.plugin_detected_message" arguments="{0:configuration.pluginPid}">There is an active election plugin on the configured page</f:translate></div>
<h4 class="alert-title">
<f:translate key="view.be.election_circular.plugin_detected">Plugin detected</f:translate>
</h4>
<div class="alert-message">
<f:translate key="view.be.election_circular.plugin_detected_message"
arguments="{0:configuration.pluginPid}">There is an active election plugin on the
configured page
</f:translate>
</div>
</div>
</div>
</div>
......@@ -25,17 +32,52 @@
</span>
</div>
<div class="media-body">
<h4 class="alert-title"><f:translate key="view.be.election_circular.no_plugin_detected">no plugin detected</f:translate></h4>
<div class="alert-message"><f:translate key="view.be.election_circular.no_plugin_detected_message" arguments="{0:configuration.pluginPid}">There is no active election plugin on the configured page</f:translate></div>
<h4 class="alert-title">
<f:translate key="view.be.election_circular.no_plugin_detected">no plugin detected</f:translate>
</h4>
<div class="alert-message">
<f:translate key="view.be.election_circular.no_plugin_detected_message"
arguments="{0:configuration.pluginPid}">There is no active election plugin on the
configured page
</f:translate>
</div>
</div>
</div>
</div>
</f:else>
</f:if>
<h1>Preview</h1>
<div>
<h2>
<f:translate key="view.be.election_circular.preview.title">Preview</f:translate>
</h2>
<div style="border: 1px solid black; padding: 10px;">
<h1>{electionCircular.subject}</h1>
<f:format.nl2br>{electionCircular.dummyBody}</f:format.nl2br>
<div style="border: 1px solid black; padding: 10px;">
<h1>{electionCircular.subject}</h1>
<f:format.nl2br>{electionCircular.dummyBody}</f:format.nl2br>
</div>
</div>
<div>
<h2>
<f:translate key="view.be.election_circular.preview.test_send">Send test email to this address</f:translate>
</h2>
<f:form action="testSend" arguments="{electionCircular:electionCircular}" name="testReceiver" method="post">
<fieldset class="form-section">
<div class="form-group">
<label>
<f:translate key="view.be.election_circular.preview.test_receiver">test receiver</f:translate>
</label>
<div class="form-control-wrap" style="max-width: 480px">
<f:form.textfield class="form-control" name="email"/>
</div>
</div>
<div class="form-group">
<div class="form-control-wrap" style="max-width: 480px">
<f:form.submit value="{f:translate(key:'view.be.election_circular.preview.send_to_test_email')}"/>
</div>
</div>
</fieldset>
</f:form>
</div>
......@@ -14,7 +14,7 @@
<f:section name="Welcome">
<h1>
<f:translate key="view.be.election_circular.send.welcome">
<f:translate key="view.be.election_circular.preview.welcome">
Send out circular
</f:translate>
</h1>
......
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