BeElectionController.php 3.52 KB
Newer Older
1
2
3
<?php
namespace TYPO3\Election\Controller;

4
5
6
7
8
9
10
11
12
13
14
15
/*
 * 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!
 */
16
use TYPO3\Election\Domain\Model\Election;
17
18
19
20
21
22
23
24

/**
 * Class BeConfigurationController
 */
class BeElectionController extends AbstractProtectedBeController
{
    const CONTROLLER_NAME = 'BeElection';
    const ACTION_LIST = 'list';
25
    const ACTION_NEW = 'new';
26
    const ACTION_CREATE = 'create';
Oliver Eglseder's avatar
Oliver Eglseder committed
27
28
    const ACTION_EDIT = 'edit';
    const ACTION_UPDATE = 'update';
29
    const ACTION_DELETE = 'delete';
30
31
32
33
34
35

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

37
38
39
40
41
42
43
44
45
46
47
48
    /**
     * @var \TYPO3\Election\Domain\Repository\ElectorateRepository
     * @inject
     */
    protected $electorateRepository = null;

    /**
     * @var \TYPO3\Election\Domain\Repository\NomineeRepository
     * @inject
     */
    protected $nomineeRepository = null;

49
50
51
52
53
    /**
     *
     */
    public function listAction()
    {
54
55
56
57
58
59
        $this->view->assign('elections', $this->electionRepository->findAll());
    }

    /**
     *
     */
60
    public function newAction()
61
62
    {
        $this->view->assign('election', $this->objectManager->get(Election::class));
63
64
65
66
        $this->view->assign('electorates', $this->electorateRepository->findAll());
        $this->view->assign('nominees', $this->nomineeRepository->findAll());
    }

Oliver Eglseder's avatar
Oliver Eglseder committed
67
68
69
70
71
72
73
74
75
76
    /**
     * @param Election $election
     */
    public function editAction(Election $election)
    {
        $this->view->assign('election', $election);
        $this->view->assign('electorates', $this->electorateRepository->findAll());
        $this->view->assign('nominees', $this->nomineeRepository->findAll());
    }

77
78
79
80
81
82
83
84
85
    /**
     * @param Election $election
     */
    public function deleteAction(Election $election)
    {
        $this->electionRepository->remove($election);
        $this->redirect(self::ACTION_LIST);
    }

Oliver Eglseder's avatar
Oliver Eglseder committed
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
    /**
     *
     */
    public function initializeUpdateAction()
    {
        $this->setDateTimeConverterOptions('election', ['startDate', 'endDate']);
    }

    /**
     * @param Election $election
     */
    public function updateAction(Election $election)
    {
        $this->electionRepository->update($election);
        $this->redirect(self::ACTION_LIST);
    }

103
104
105
106
107
108
109
110
    /**
     *
     */
    public function initializeCreateAction()
    {
        $this->setDateTimeConverterOptions('election', ['startDate', 'endDate']);
    }

111
112
113
114
115
116
117
    /**
     * @param Election $election
     */
    public function createAction(Election $election)
    {
        $this->electionRepository->add($election);
        $this->redirect(self::ACTION_LIST);
118
119
120
121
122
123
124
    }

    /**
     * @return string
     */
    public static function getActionsForModuleConfiguration()
    {
Oliver Eglseder's avatar
Oliver Eglseder committed
125
126
127
128
129
130
131
132
        return implode(
            ',',
            [
                self::ACTION_LIST,
                self::ACTION_NEW,
                self::ACTION_CREATE,
                self::ACTION_UPDATE,
                self::ACTION_EDIT,
133
                self::ACTION_DELETE,
Oliver Eglseder's avatar
Oliver Eglseder committed
134
135
            ]
        );
136
137
138
    }

    /**
139
     * @return int[]
140
     */
141
    protected function getRequiredUserGroups()
142
    {
143
        return [$this->configuration->getElectionManagerGroup()];
144
145
    }
}