Commit f31b8d81 authored by Wolf-Peter Utz's avatar Wolf-Peter Utz
Browse files

Add DI and remove @inject usages

* Add Constants.php to store extension constants
* Add Services.yaml
* Update backend module mainModule from `voting` to `web`
* Update deprecated usage of `GeneralUtility::verifyFilenameAgainstDenyPattern` to `GeneralUtility::makeInstance(FileNameValidator::class)->isValid`
parent ab5ed30d
<?php
namespace T3o\Election;
class Constants
{
public const EXTENSION_KEY = 'election';
public const EXTENSION_NAME = 'Election';
}
......@@ -20,43 +20,43 @@ use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
use TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter;
use T3o\Election\Domain\Model\Configuration;
use T3o\Election\Domain\Repository\ConfigurationRepository;
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
/**
* Class AbstractBeController
*/
abstract class AbstractBeController extends ActionController
{
/**
* @var BackendUserAuthentication
*/
protected $backendUser = null;
protected $backendUser;
/**
* @var Configuration
*/
protected $configuration = null;
protected $configuration;
/**
* @var \T3o\Election\Domain\Repository\ConfigurationRepository
* @inject
* @var ConfigurationRepository
*/
protected $configurationRepository = null;
protected $configurationRepository;
/**
* Sets the current configuration
* AbstractBeController constructor.
*
* @param ConfigurationRepository $configurationRepository
*/
public function initializeObject()
public function __construct(ConfigurationRepository $configurationRepository)
{
$this->configuration = $this->configurationRepository->findCurrent();
$this->configurationRepository = $configurationRepository;
$this->backendUser = self::getBackendUserAuthentication();
}
/**
* ModuleController constructor.
* Sets the current configuration
*/
public function __construct()
public function initializeObject()
{
parent::__construct();
$this->backendUser = self::getBackendUserAuthentication();
$this->configuration = $this->configurationRepository->findCurrent();
}
/**
......
<?php
namespace T3o\Election\Controller;
/*
......@@ -14,18 +15,11 @@ namespace T3o\Election\Controller;
* The TYPO3 project - inspiring people to share!
*/
use Doctrine\Common\Util\Debug;
use TYPO3\CMS\Core\Messaging\AbstractMessage;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
/**
* Class AbstractProtectedBeController
*/
abstract class AbstractProtectedBeController extends AbstractBeController
{
/**
*
*/
protected function initializeAction()
{
if (!$this->backendUserHasUserGroup($this->getRequiredUserGroup())) {
......@@ -46,33 +40,32 @@ abstract class AbstractProtectedBeController extends AbstractBeController
protected function errorAction()
{
$this->clearCacheOnError();
$message="";
$message = "";
foreach ($this->arguments->getValidationResults()->getFlattenedErrors() as $propertyPath => $errors) {
foreach ($errors as $error) {
$message .= PHP_EOL. 'Error for ' . $propertyPath . ': ' . $error->render();
$message .= PHP_EOL . 'Error for ' . $propertyPath . ': ' . $error->render();
}
}
$errorFlashMessage = $this->getErrorFlashMessage();
if ($errorFlashMessage !== FALSE) {
if ($errorFlashMessage !== false) {
$errorFlashMessageObject = new \TYPO3\CMS\Core\Messaging\FlashMessage(
$errorFlashMessage." ".$message,
$errorFlashMessage . " " . $message,
'',
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
);
$this->controllerContext->getFlashMessageQueue()->enqueue($errorFlashMessageObject);
}
$referringRequest = $this->request->getReferringRequest();
if ($referringRequest !== NULL) {
if ($referringRequest !== null) {
$originalRequest = clone $this->request;
$this->request->setOriginalRequest($originalRequest);
$this->request->setOriginalRequestMappingResults($this->arguments->getValidationResults());
$this->forward($referringRequest->getControllerActionName(), $referringRequest->getControllerName(), $referringRequest->getControllerExtensionName(), $referringRequest->getArguments());
$this->forward($referringRequest->getControllerActionName(), $referringRequest->getControllerName(),
$referringRequest->getControllerExtensionName(), $referringRequest->getArguments());
}
$message = 'An error occurred while trying to call ' . get_class($this) . '->' . $this->actionMethodName . '().' . PHP_EOL;
return $message;
return $message;
}
}
<?php
namespace T3o\Election\Controller;
/*
......@@ -15,6 +16,9 @@ namespace T3o\Election\Controller;
*/
use T3o\Election\Domain\Model\Configuration;
use T3o\Election\Domain\Repository\ConfigurationRepository;
use TYPO3\CMS\Extbase\Domain\Repository\BackendUserGroupRepository;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
/**
* Class BeConfigurationController
......@@ -26,14 +30,18 @@ class BeConfigurationController extends AbstractProtectedBeController
const ACTION_UPDATE = 'update';
/**
* @var \TYPO3\CMS\Extbase\Domain\Repository\BackendUserGroupRepository
* @inject
* @var BackendUserGroupRepository
*/
protected $backendUserGroupRepository = null;
protected $backendUserGroupRepository;
public function __construct(
BackendUserGroupRepository $backendUserGroupRepository,
ConfigurationRepository $configurationRepository
) {
parent::__construct($configurationRepository);
$this->backendUserGroupRepository = $backendUserGroupRepository;
}
/**
*
*/
public function editAction()
{
if (null === $this->configuration) {
......@@ -49,6 +57,7 @@ class BeConfigurationController extends AbstractProtectedBeController
public function updateAction(Configuration $configuration)
{
$this->configurationRepository->update($configuration);
$this->objectManager->get(PersistenceManager::class)->persistAll();
$this->redirect(BeDashboardController::ACTION_INDEX, BeDashboardController::CONTROLLER_NAME);
}
......@@ -68,6 +77,7 @@ class BeConfigurationController extends AbstractProtectedBeController
if (null === $this->configuration) {
return Configuration::AUTH_NONE;
}
return $this->configuration->getAdministrationGroup();
}
}
<?php
namespace T3o\Election\Controller;
/*
......@@ -13,10 +14,13 @@ namespace T3o\Election\Controller;
*
* The TYPO3 project - inspiring people to share!
*/
use T3o\Election\Domain\Repository\ConfigurationRepository;
use TYPO3\CMS\Core\Messaging\AbstractMessage;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use T3o\Election\Domain\Repository\ElectionCircularRepository;
use T3o\Election\Domain\Repository\ElectorImportRepository;
use T3o\Election\Domain\Repository\ElectionRepository;
/**
* Dashboard controller
......@@ -27,10 +31,17 @@ class BeDashboardController extends AbstractBeController
const ACTION_INDEX = 'index';
/**
* @var \T3o\Election\Domain\Repository\ElectionRepository
* @inject
* @var ElectionRepository
*/
protected $electionRepository = null;
protected $electionRepository;
public function __construct(
ElectionRepository $electionRepository,
ConfigurationRepository $configurationRepository
) {
parent::__construct($configurationRepository);
$this->electionRepository = $electionRepository;
}
/**
*
......@@ -46,28 +57,32 @@ class BeDashboardController extends AbstractBeController
if ($this->configuration) {
if ($this->configuration->isGroupConfigComplete()) {
$electionManagerGroup = $this->configuration->getElectionManagerGroup();
}
else {
} else {
$this->addFlashMessage(
LocalizationUtility::translate('view.be.dashboard.index.no_proper_configuration_msg_body', $this->extensionName),
LocalizationUtility::translate('view.be.dashboard.index.no_configuration_msg_title', $this->extensionName),
LocalizationUtility::translate('view.be.dashboard.index.no_proper_configuration_msg_body',
\T3o\Election\Constants::EXTENSION_NAME),
LocalizationUtility::translate('view.be.dashboard.index.no_configuration_msg_title',
\T3o\Election\Constants::EXTENSION_NAME),
AbstractMessage::ERROR
);
if ($GLOBALS['BE_USER']->isAdmin()) {
$this->redirect('edit','BeConfiguration');
$this->redirect('edit', 'BeConfiguration');
} else {
$this->addFlashMessage(
LocalizationUtility::translate('view.be.dashboard.index.no_proper_configuration_msg_body_admin', $this->extensionName),
LocalizationUtility::translate('view.be.dashboard.index.no_configuration_msg_title', $this->extensionName),
LocalizationUtility::translate('view.be.dashboard.index.no_proper_configuration_msg_body_admin',
\T3o\Election\Constants::EXTENSION_NAME),
LocalizationUtility::translate('view.be.dashboard.index.no_configuration_msg_title',
\T3o\Election\Constants::EXTENSION_NAME),
AbstractMessage::ERROR
);
}
}
}
else {
} else {
$this->addFlashMessage(
LocalizationUtility::translate('view.be.dashboard.index.no_configuration_msg_body', $this->extensionName),
LocalizationUtility::translate('view.be.dashboard.index.no_configuration_msg_title', $this->extensionName),
LocalizationUtility::translate('view.be.dashboard.index.no_configuration_msg_body',
\T3o\Election\Constants::EXTENSION_NAME),
LocalizationUtility::translate('view.be.dashboard.index.no_configuration_msg_title',
\T3o\Election\Constants::EXTENSION_NAME),
AbstractMessage::ERROR
);
}
......@@ -83,11 +98,12 @@ class BeDashboardController extends AbstractBeController
$this->objectManager->get(ElectionCircularRepository::class)->findAll()
);
}
}
else {
} else {
$this->addFlashMessage(
LocalizationUtility::translate('view.be.dashboard.index.no_configuration_msg_body', $this->extensionName),
LocalizationUtility::translate('view.be.dashboard.index.no_electionmanagergroup_msg_body', $this->extensionName),
LocalizationUtility::translate('view.be.dashboard.index.no_configuration_msg_body',
\T3o\Election\Constants::EXTENSION_NAME),
LocalizationUtility::translate('view.be.dashboard.index.no_electionmanagergroup_msg_body',
\T3o\Election\Constants::EXTENSION_NAME),
AbstractMessage::WARNING
);
}
......
......@@ -13,7 +13,8 @@ namespace T3o\Election\Controller;
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Backend\Utility\BackendUtility;
use T3o\Election\Domain\Repository\ConfigurationRepository;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\DatabaseConnection;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -22,6 +23,8 @@ use T3o\Election\Domain\Model\Elector;
use T3o\Election\Service\CircularService;
use T3o\Election\Service\ElectionInvitationService;
use T3o\Election\Utility\MailUtility;
use T3o\Election\Domain\Repository\ElectionCircularRepository;
use T3o\Election\Domain\Repository\ElectionRepository;
/**
* Class BeConfigurationController
......@@ -41,16 +44,24 @@ class BeElectionCircularController extends AbstractProtectedBeController
const ACTION_SEND_PREVIEW = 'sendPreview';
/**
* @var \T3o\Election\Domain\Repository\ElectionCircularRepository
* @inject
* @var ElectionCircularRepository
*/
protected $electionCircularRepository = null;
protected $electionCircularRepository;
/**
* @var \T3o\Election\Domain\Repository\ElectionRepository
* @inject
* @var ElectionRepository
*/
protected $electionRepository = null;
protected $electionRepository;
public function __construct(
ElectionCircularRepository $electionCircularRepository,
ElectionRepository $electionRepository,
ConfigurationRepository $configurationRepository
) {
parent::__construct($configurationRepository);
$this->electionCircularRepository = $electionCircularRepository;
$this->electionRepository = $electionRepository;
}
/**
*
......
......@@ -15,6 +15,10 @@ namespace T3o\Election\Controller;
*/
use T3o\Election\Domain\Model\Election;
use T3o\Election\Domain\Repository\ConfigurationRepository;
use T3o\Election\Domain\Repository\ElectionRepository;
use T3o\Election\Domain\Repository\ElectorateRepository;
use T3o\Election\Domain\Repository\NomineeRepository;
/**
* Class BeConfigurationController
......@@ -31,22 +35,31 @@ class BeElectionController extends AbstractProtectedBeController
const ACTION_SUMMARY = 'summary';
/**
* @var \T3o\Election\Domain\Repository\ElectionRepository
* @inject
* @var ElectionRepository
*/
protected $electionRepository = null;
protected $electionRepository;
/**
* @var \T3o\Election\Domain\Repository\ElectorateRepository
* @inject
* @var ElectorateRepository
*/
protected $electorateRepository = null;
protected $electorateRepository;
/**
* @var \T3o\Election\Domain\Repository\NomineeRepository
* @inject
* @var NomineeRepository
*/
protected $nomineeRepository = null;
protected $nomineeRepository ;
public function __construct(
ElectionRepository $electionRepository,
ElectorateRepository $electorateRepository,
NomineeRepository $nomineeRepository,
ConfigurationRepository $configurationRepository
) {
parent::__construct($configurationRepository);
$this->electionRepository = $electionRepository;
$this->electorateRepository = $electorateRepository;
$this->nomineeRepository = $nomineeRepository;
}
/**
*
......
......@@ -13,13 +13,21 @@ namespace T3o\Election\Controller;
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
use T3o\Election\Domain\Model\ElectionInvitation;
use T3o\Election\Domain\Repository\ConfigurationRepository;
use T3o\Election\Service\ElectionInvitationService;
use TYPO3\CMS\Core\Messaging\AbstractMessage;
use T3o\Election\Domain\Model\Dto\ElectorImport as ElectorImportDto;
use T3o\Election\Domain\Model\Election;
use T3o\Election\Domain\Model\Elector;
use T3o\Election\Domain\Model\ElectorImport;
use T3o\Election\Utility\CsvUtility;
use T3o\Election\Utility\FileUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use T3o\Election\Domain\Repository\ElectorateRepository;
use T3o\Election\Domain\Repository\ElectorRepository;
use T3o\Election\Domain\Repository\ElectorImportRepository;
/**
* Class BeConfigurationController
......@@ -38,28 +46,35 @@ class BeElectorController extends AbstractProtectedBeController
const ACTION_UPLOAD = 'upload';
const ACTION_PROCESS_IMPORT = 'processImport';
const ACTION_OVERWRITE_ALL = 'overwriteAll';
const ACTION_RESEND_ELECTION_INVITATION = 'resendElectionInvitation';
/**
* @var \T3o\Election\Domain\Repository\ElectorateRepository
* @inject
* @var ElectorateRepository
*/
protected $electorateRepository = null;
protected $electorateRepository;
/**
* @var \T3o\Election\Domain\Repository\ElectorRepository
* @inject
* @var ElectorRepository
*/
protected $electorRepository = null;
protected $electorRepository;
/**
* @var \T3o\Election\Domain\Repository\ElectorImportRepository
* @inject
* @var ElectorImportRepository
*/
protected $electorImportRepository = null;
protected $electorImportRepository;
public function __construct(
ElectorateRepository $electorateRepository,
ElectorRepository $electorRepository,
ElectorImportRepository $electorImportRepository,
ConfigurationRepository $configurationRepository
) {
parent::__construct($configurationRepository);
$this->electorateRepository = $electorateRepository;
$this->electorRepository = $electorRepository;
$this->electorImportRepository = $electorImportRepository;
}
/**
*
*/
public function newAction()
{
$this->view->assign('elector', $this->objectManager->get(Elector::class));
......@@ -172,6 +187,7 @@ class BeElectorController extends AbstractProtectedBeController
$elector->setLastName($electorImport->getLastName());
$elector->setGender($electorImport->getGender());
$elector->setEmail($electorImport->getEmail());
$elector->setElectionInvitations(0);
$elector->addElectorate($electorImport->getElectorate());
$this->electorRepository->add($elector);
$this->electorImportRepository->remove($electorImport);
......@@ -179,6 +195,26 @@ class BeElectorController extends AbstractProtectedBeController
$this->redirect(self::ACTION_LIST);
}
/**
* @param Elector $elector
* @param ElectionInvitation $electionInvitation
*/
public function resendElectionInvitationAction(Elector $elector, ElectionInvitation $electionInvitation){
/** @var ElectionInvitationService $electionInvitationService */
$electionInvitationService = $this->objectManager->get(ElectionInvitationService::class);
$electionInvitationService->resendElectionInvitation($this->configuration, $electionInvitation);
$labelKey = $electionInvitation->isSuccess() ? 'view.be.elector.edit.election_invitaion_resend_body_success' : 'view.be.elector.edit.election_invitaion_resend_body_failure';
$severity = $electionInvitation->isSuccess() ? AbstractMessage::OK : AbstractMessage::ERROR;
$this->addFlashMessage(
LocalizationUtility::translate($labelKey, \T3o\Election\Constants::EXTENSION_NAME),
LocalizationUtility::translate('view.be.elector.edit.election_invitaion_resend_title', \T3o\Election\Constants::EXTENSION_NAME),
$severity
);
$this->redirect(self::ACTION_EDIT, self::CONTROLLER_NAME, 'election', ['elector' => $elector]);
}
/**
* @return string
*/
......@@ -198,6 +234,7 @@ class BeElectorController extends AbstractProtectedBeController
self::ACTION_UPLOAD,
self::ACTION_PROCESS_IMPORT,
self::ACTION_OVERWRITE_ALL,
self::ACTION_RESEND_ELECTION_INVITATION,
]
);
}
......
<?php
namespace T3o\Election\Controller;
/*
......@@ -15,6 +16,9 @@ namespace T3o\Election\Controller;
*/
use T3o\Election\Domain\Model\Electorate;
use T3o\Election\Domain\Repository\ConfigurationRepository;
use T3o\Election\Domain\Repository\ElectorateRepository;
use T3o\Election\Domain\Repository\ElectorRepository;
/**
* Class BeElectorateController
......@@ -24,23 +28,31 @@ class BeElectorateController extends AbstractProtectedBeController
const CONTROLLER_NAME = 'BeElectorate';
const ACTION_LIST = 'list';
const ACTION_NEW = 'new';
const ACTION_EDIT= 'edit';
const ACTION_EDIT = 'edit';
const ACTION_CREATE = 'create';
const ACTION_UPDATE = 'update';
const ACTION_CREATE_AND_IMPORT_ELECTORS = 'createAndImportElectors';
const ACTION_UPDATE_AND_IMPORT_ELECTORS = 'updateAndImportElectors';
/**
* @var \T3o\Election\Domain\Repository\ElectorateRepository
* @inject
* @var ElectorateRepository
*/
protected $electorateRepository = null;
protected $electorateRepository;
/**
* @var \T3o\Election\Domain\Repository\ElectorRepository
* @inject
* @var ElectorRepository
*/
protected $electorRepository = null;
protected $electorRepository;
public function __construct(
ElectorateRepository $electorateRepository,
ElectorRepository $electorRepository,
ConfigurationRepository $configurationRepository
) {
parent::__construct($configurationRepository);
$this->electorateRepository = $electorateRepository;
$this->electorRepository = $electorRepository;
}
/**
*
......@@ -80,7 +92,8 @@ class BeElectorateController extends AbstractProtectedBeController
/**
* @param Electorate $electorate
*/
public function updateAction(Electorate $electorate) {
public function updateAction(Electorate $electorate)
{
$this->electorateRepository->update($electorate);
$this->redirect(self::ACTION_LIST);
}
......
......@@ -15,11 +15,10 @@ namespace T3o\Election\Controller;
*/
use T3o\Election\Domain\Model\Nominee;
use T3o\Election\Domain\Repository\ConfigurationRepository;
use T3o\Election\Property\TypeConverter\UploadedFileReferenceConverter;
use T3o\Election\Domain\Repository\NomineeRepository;
/**
* Class BeConfigurationController
*/
class BeNomineeController extends AbstractProtectedBeController
{
const CONTROLLER_NAME = 'BeNominee';
......@@ -32,30 +31,26 @@ class BeNomineeController extends AbstractProtectedBeController
const ACTION_SHOW = 'show';
/**
* @var \T3o\Election\Domain\Repository\NomineeRepository
* @inject
* @var NomineeRepository
*/
protected $nomineeRepository = null;
protected $nomineeRepository;
public function __construct(NomineeRepository $nomineeRepository, ConfigurationRepository $configurationRepository)
{
parent::__construct($configurationRepository);
$this->nomineeRepository = $nomineeRepository;
}
/**
*
*/
public function listAction()
{
$this->view->assign('nominees', $this->nomineeRepository->findAll());
}