Commit 2bbeb0cf authored by Wolf Utz's avatar Wolf Utz
Browse files

Fix link generation for emails

parent 8d8f4c46
......@@ -125,7 +125,7 @@ class FeElectionController extends ActionController
}
/**
* @Validate("param"="electionVoting", validator="T3o\Election\Domain\Validator\ElectionVotingValidator")
* @Validate(param="electionVoting", validator="T3o\Election\Domain\Validator\ElectionVotingValidator")
*/
public function submitVoteAction(ElectionVoting $electionVoting): void
{
......
......@@ -40,12 +40,12 @@ class Election extends AbstractEntity
protected $endDate;
/**
* @var \T3o\Election\Domain\Model\Electorate
* @var \T3o\Election\Domain\Model\Electorate|null
*/
protected $electorate;
/**
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\T3o\Election\Domain\Model\Nominee>
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\T3o\Election\Domain\Model\Nominee>|null
*
* @Lazy
*/
......@@ -57,7 +57,7 @@ class Election extends AbstractEntity
protected $numberOfVotes = 0;
/**
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\T3o\Election\Domain\Model\ElectionVote>
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\T3o\Election\Domain\Model\ElectionVote>|null
*
* @Lazy
*/
......@@ -109,22 +109,22 @@ class Election extends AbstractEntity
$this->endDate = $endDate;
}
public function getElectorate(): Electorate
public function getElectorate(): ?Electorate
{
return $this->electorate;
}
public function setElectorate(Electorate $electorate): void
public function setElectorate(?Electorate $electorate): void
{
$this->electorate = $electorate;
}
public function getNominees(): ObjectStorage
public function getNominees(): ?ObjectStorage
{
return $this->nominees;
}
public function setNominees(ObjectStorage $nominees): void
public function setNominees(?ObjectStorage $nominees): void
{
$this->nominees = $nominees;
}
......@@ -139,12 +139,12 @@ class Election extends AbstractEntity
$this->numberOfVotes = $numberOfVotes;
}
public function getElectionVotes(): ObjectStorage
public function getElectionVotes(): ?ObjectStorage
{
return $this->electionVotes;
}
public function setElectionVotes(ObjectStorage $electionVotes): void
public function setElectionVotes(?ObjectStorage $electionVotes): void
{
$this->electionVotes = $electionVotes;
}
......
......@@ -13,15 +13,14 @@ declare(strict_types=1);
namespace T3o\Election\Domain\Model;
use T3o\Election\Constants;
use T3o\Election\Controller\FeElectionController;
use T3o\Election\Domain\Repository\ConfigurationRepository;
use TYPO3\CMS\Core\TimeTracker\TimeTracker;
use TYPO3\CMS\Core\Site\SiteFinder;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
use TYPO3\CMS\Extbase\Object\Container\Container;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Security\Cryptography\HashService;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3\CMS\Extbase\Service\ExtensionService;
class ElectionCircular extends AbstractEntity
{
......@@ -36,7 +35,7 @@ class ElectionCircular extends AbstractEntity
protected $body = '';
/**
* @var \T3o\Election\Domain\Model\Election
* @var \T3o\Election\Domain\Model\Election|null
*/
protected $election;
......@@ -60,12 +59,12 @@ class ElectionCircular extends AbstractEntity
$this->body = $body;
}
public function getElection(): Election
public function getElection(): ?Election
{
return $this->election;
}
public function setElection(Election $election): void
public function setElection(?Election $election): void
{
$this->election = $election;
}
......@@ -123,6 +122,7 @@ class ElectionCircular extends AbstractEntity
{
$election = $this->getElection();
$electors = $election->getElectorate()->getElectorsAsArray();
$receivers = [];
foreach ($electors as $elector) {
if (!$elector->hasElectionInvitationForElection($election)) {
......@@ -135,40 +135,31 @@ class ElectionCircular extends AbstractEntity
protected function getLink(Configuration $configuration, ElectionInvitation $electionInvitation): string
{
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$hashService = $objectManager->get(HashService::class);
if (!isset($GLOBALS['TT'])) {
$GLOBALS['TT'] = GeneralUtility::makeInstance(TimeTracker::class);
}
if (!isset($GLOBALS['TSFE'])) {
$GLOBALS['TSFE'] = GeneralUtility::makeInstance(
TypoScriptFrontendController::class,
$GLOBALS['TYPO3_CONF_VARS'],
$configuration->getPluginPid(),
0
);
$GLOBALS['TSFE']->config = ['config' => []];
$GLOBALS['TSFE']->fetch_the_id();
}
/** @var UriBuilder $uriBuilder */
$uriBuilder = $objectManager->get(UriBuilder::class);
$uriBuilder->setTargetPageUid($configuration->getPluginPid());
$uriBuilder->setCreateAbsoluteUri(true);
$uriBuilder->uriFor(
FeElectionController::ACTION_VOTE,
[
'electionInvitation' => $electionInvitation,
/** @var Container $container */
$container = GeneralUtility::makeInstance(Container::class);
/** @var HashService $hashService */
$hashService = $container->getInstance(HashService::class);
/** @var ExtensionService $extensionService */
$extensionService = $container->getInstance(ExtensionService::class);
/** @var SiteFinder $siteFinder */
$siteFinder = GeneralUtility::makeInstance(SiteFinder::class);
$site = $siteFinder->getSiteByPageId($configuration->getPluginPid());
$argumentsPrefix = $extensionService->getPluginNamespace(Constants::EXTENSION_NAME, 'pi1');
$arguments = [
"$argumentsPrefix" => [
'action' => FeElectionController::ACTION_VOTE,
'controller' => FeElectionController::CONTROLLER_NAME,
'electionInvitation' => $electionInvitation->getUid(),
'hmac' => $hashService->generateHmac(
$electionInvitation->getSecret() . $electionInvitation->getElector()->getEmail()
),
],
FeElectionController::CONTROLLER_NAME,
'election',
'pi1'
);
];
return $uriBuilder->buildFrontendUri();
return (string) $site->getRouter()->generateUri(
(string) $configuration->getPluginPid(),
$arguments
);
}
}
......@@ -38,7 +38,6 @@ class ElectionInvitationService
{
$limit = $configuration->getNumberOfMails();
$receiver = [];
$possibleReceivers = $electionCircular->getRemainingReceivers();
while (count($receiver) < $limit && count($possibleReceivers) > 0) {
/** @var Elector $possibleReceiver */
......@@ -77,7 +76,7 @@ class ElectionInvitationService
$mail->setTo([$elector->getEmail() => $elector->getFullName()]);
}
$mail->setBody($electionCircular->getRenderedBody($configuration, $electionInvitation));
$mail->setBody()->text($electionCircular->getRenderedBody($configuration, $electionInvitation));
return 1 === $mail->send();
}
......
......@@ -49,7 +49,7 @@ class MailUtility
$mail->setTo([$elector->getEmail() => $elector->getFullName()]);
}
$mail->setBody($electionCircular->getRenderedBody($configuration, $electionInvitation));
$mail->setBody()->text($electionCircular->getRenderedBody($configuration, $electionInvitation));
return 1 === $mail->send();
}
......
......@@ -81,7 +81,7 @@ return (function () {
'multiple' => true,
'foreign_table' => 'tx_election_domain_model_electorate',
'MM' => 'tx_election_domain_model_electorate_elector_mm',
'MM_opposite_field' => 'electors'
'MM_opposite_field' => 'electors',
],
],
'election_invitations' => [
......
Markdown is supported
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