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

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

17
use T3o\Election\Domain\Model\Election;
18
19
20
21
use T3o\Election\Domain\Repository\ConfigurationRepository;
use T3o\Election\Domain\Repository\ElectionRepository;
use T3o\Election\Domain\Repository\ElectorateRepository;
use T3o\Election\Domain\Repository\NomineeRepository;
22
23
24
25
26
27
28
29

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

    /**
38
     * @var ElectionRepository
39
     */
40
    protected $electionRepository;
41

42
    /**
43
     * @var ElectorateRepository
44
     */
45
    protected $electorateRepository;
46
47

    /**
48
     * @var NomineeRepository
49
     */
50
51
52
53
54
55
56
57
58
59
60
61
62
    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;
    }
63

64
65
66
67
68
    /**
     *
     */
    public function listAction()
    {
69
70
71
72
73
74
        $this->view->assign('elections', $this->electionRepository->findAll());
    }

    /**
     *
     */
75
    public function newAction()
76
77
    {
        $this->view->assign('election', $this->objectManager->get(Election::class));
78
79
80
81
        $this->view->assign('electorates', $this->electorateRepository->findAll());
        $this->view->assign('nominees', $this->nomineeRepository->findAll());
    }

Oliver Eglseder's avatar
Oliver Eglseder committed
82
83
84
85
86
87
88
89
90
91
    /**
     * @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());
    }

92
93
94
95
96
97
98
99
100
    /**
     * @param Election $election
     */
    public function deleteAction(Election $election)
    {
        $this->electionRepository->remove($election);
        $this->redirect(self::ACTION_LIST);
    }

Oliver Eglseder's avatar
Oliver Eglseder committed
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
    /**
     *
     */
    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);
    }

118
119
120
121
122
123
124
125
    /**
     *
     */
    public function initializeCreateAction()
    {
        $this->setDateTimeConverterOptions('election', ['startDate', 'endDate']);
    }

126
127
128
129
130
131
132
    /**
     * @param Election $election
     */
    public function createAction(Election $election)
    {
        $this->electionRepository->add($election);
        $this->redirect(self::ACTION_LIST);
133
134
    }

135
136
137
138
139
140
141
142
    /**
     * @param Election $election
     */
    public function summaryAction(Election $election)
    {
        $this->view->assign('election', $election);
    }

143
144
145
146
147
    /**
     * @return string
     */
    public static function getActionsForModuleConfiguration()
    {
Oliver Eglseder's avatar
Oliver Eglseder committed
148
149
150
151
152
153
154
155
        return implode(
            ',',
            [
                self::ACTION_LIST,
                self::ACTION_NEW,
                self::ACTION_CREATE,
                self::ACTION_UPDATE,
                self::ACTION_EDIT,
156
                self::ACTION_DELETE,
157
                self::ACTION_SUMMARY,
Oliver Eglseder's avatar
Oliver Eglseder committed
158
159
            ]
        );
160
161
162
    }

    /**
163
     * @return int
164
     */
165
    protected function getRequiredUserGroup()
166
    {
167
        return $this->configuration->getElectionManagerGroup();
168
169
    }
}