BeElectorController.php 2.26 KB
Newer Older
Oliver Eglseder's avatar
Oliver Eglseder committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
namespace TYPO3\Election\Controller;

/*
 * 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\Election\Domain\Model\Dto\ElectorImport;
use TYPO3\Election\Domain\Model\Election;

/**
 * Class BeConfigurationController
 */
class BeElectorController extends AbstractProtectedBeController
{
    const CONTROLLER_NAME = 'BeElector';
    const ACTION_IMPORT = 'import';

    /**
     * @var \TYPO3\Election\Domain\Repository\ElectionRepository
     * @inject
     */
    protected $electionRepository = null;

    /**
     * @param Election|null $election Optional Election which any imported Elector will be assigned to
     */
    public function importAction(Election $election = null)
    {
        $this->view->assign('electorImport', new ElectorImport($election, $this->electionRepository->findAll()));
    }

Oliver Eglseder's avatar
Oliver Eglseder committed
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
    /**
     *
     */
    public function uploadImportAction()
    {
        $key = 'tx_election_electionvoting_electiontxelectionm1';
        if (FileUtility::isUploadedFileGood($key, 'electors', 'text/csv')) {
            $this->electorImportRepository->truncate();
            $electorImports = $this->csvUtility->convertToArray(FileUtility::getUploadedFileContents($key, 'electors'));
            foreach ($electorImports as $electorImport) {
                $this->electorImportRepository->add(new ElectorImport($electorImport));
            }
            $this->redirect(self::ACTION_PROCESS_IMPORT);
        } else {
            $this->addFlashMessage('Something went wrong with the upload', 'Oops', AbstractMessage::ERROR);
            $this->redirect(self::ACTION_IMPORT);
        }
    }

Oliver Eglseder's avatar
Oliver Eglseder committed
60
61
62
63
64
65
66
67
68
    /**
     * @return string
     */
    public static function getActionsForModuleConfiguration()
    {
        return implode(',', [self::ACTION_IMPORT]);
    }

    /**
Oliver Eglseder's avatar
Oliver Eglseder committed
69
     * @return int
Oliver Eglseder's avatar
Oliver Eglseder committed
70
71
72
73
74
75
     */
    protected function getRequiredUserGroup()
    {
        return $this->configuration->getElectionManagerGroup();
    }
}