Code Duplication    Length = 44-46 lines in 3 locations

src/PlaygroundGame/Controller/Admin/PostVoteController.php 1 location

@@ 26-69 (lines=44) @@
23
        return $this->createForm($form);
24
    }
25
    
26
    public function createPostVoteAction()
27
    {
28
        $service = $this->getAdminGameService();
29
        $viewModel = new ViewModel();
30
        $viewModel->setTemplate('playground-game/post-vote/postvote');
31
32
        $gameForm = new ViewModel();
33
        $gameForm->setTemplate('playground-game/game/game-form');
34
35
        $postVote = new PostVote();
36
37
        $form = $this->getServiceLocator()->get('playgroundgame_postvote_form');
38
        $form->bind($postVote);
39
        $form->get('submit')->setAttribute('label', 'Add');
40
        $form->setAttribute(
41
            'action',
42
            $this->url()->fromRoute(
43
                'admin/playgroundgame/create-postvote',
44
                array('gameId' => 0)
45
            )
46
        );
47
        $form->setAttribute('method', 'post');
48
49
        $request = $this->getRequest();
50
        if ($request->isPost()) {
51
            $data = array_replace_recursive(
52
                $this->getRequest()->getPost()->toArray(),
53
                $this->getRequest()->getFiles()->toArray()
54
            );
55
            if (empty($data['prizes'])) {
56
                $data['prizes'] = array();
57
            }
58
            $game = $service->createOrUpdate($data, $postVote, 'playgroundgame_postvote_form');
59
            if ($game) {
60
                $this->flashMessenger()->setNamespace('playgroundgame')->addMessage('The game was created');
61
62
                return $this->redirect()->toRoute('admin/playgroundgame/list');
63
            }
64
        }
65
        $gameForm->setVariables(array('form' => $form, 'game' => $postVote));
66
        $viewModel->addChild($gameForm, 'game_form');
67
68
        return $viewModel->setVariables(array('form' => $form, 'title' => 'Create Post & Vote'));
69
    }
70
71
    public function editPostVoteAction()
72
    {

src/PlaygroundGame/Controller/Admin/QuizController.php 1 location

@@ 154-197 (lines=44) @@
151
        return $this->redirect()->toRoute('admin/playgroundgame/quiz-question-list', array('quizId'=>$quizId));
152
    }
153
154
    public function createQuizAction()
155
    {
156
        $service = $this->getAdminGameService();
157
        $viewModel = new ViewModel();
158
        $viewModel->setTemplate('playground-game/quiz/quiz');
159
160
        $gameForm = new ViewModel();
161
        $gameForm->setTemplate('playground-game/game/game-form');
162
163
        $quiz = new Quiz();
164
165
        $form = $this->getServiceLocator()->get('playgroundgame_quiz_form');
166
        $form->bind($quiz);
167
        $form->get('submit')->setAttribute('label', 'Add');
168
        $form->setAttribute(
169
            'action',
170
            $this->url()->fromRoute(
171
                'admin/playgroundgame/create-quiz',
172
                array('gameId' => 0)
173
            )
174
        );
175
        $form->setAttribute('method', 'post');
176
177
        $request = $this->getRequest();
178
        if ($request->isPost()) {
179
            $data = array_replace_recursive(
180
                $this->getRequest()->getPost()->toArray(),
181
                $this->getRequest()->getFiles()->toArray()
182
            );
183
            if (empty($data['prizes'])) {
184
                $data['prizes'] = array();
185
            }
186
            $game = $service->createOrUpdate($data, $quiz, 'playgroundgame_quiz_form');
187
            if ($game) {
188
                $this->flashMessenger()->setNamespace('playgroundgame')->addMessage('The game was created');
189
190
                return $this->redirect()->toRoute('admin/playgroundgame/list');
191
            }
192
        }
193
        $gameForm->setVariables(array('form' => $form, 'game' => $quiz));
194
        $viewModel->addChild($gameForm, 'game_form');
195
196
        return $viewModel->setVariables(array('form' => $form, 'title' => 'Create quiz'));
197
    }
198
199
    public function editQuizAction()
200
    {

src/PlaygroundGame/Controller/Admin/MissionController.php 1 location

@@ 19-64 (lines=46) @@
16
17
    protected $mission;
18
19
    public function createMissionAction()
20
    {
21
        $service = $this->getAdminGameService();
22
        $viewModel = new ViewModel();
23
        $viewModel->setTemplate('playground-game/game/mission');
24
25
        $gameForm = new ViewModel();
26
        $gameForm->setTemplate('playground-game/game/game-form');
27
28
        $mission = new Mission();
29
30
        $form = $this->getServiceLocator()->get('playgroundgame_mission_form');
31
        $form->bind($mission);
32
        $form->get('submit')->setAttribute('label', 'Add');
33
        $form->setAttribute(
34
            'action',
35
            $this->url()->fromRoute(
36
                'admin/playgroundgame/create-mission',
37
                array('gameId' => 0)
38
            )
39
        );
40
        $form->setAttribute('method', 'post');
41
42
        $request = $this->getRequest();
43
        if ($request->isPost()) {
44
            $data = array_replace_recursive(
45
                $this->getRequest()->getPost()->toArray(),
46
                $this->getRequest()->getFiles()->toArray()
47
            );
48
            if (empty($data['prizes'])) {
49
                $data['prizes'] = array();
50
            }
51
52
            $game = $service->createOrUpdate($data, $mission, 'playgroundgame_mission_form');
53
            if ($game) {
54
55
                $this->flashMessenger()->setNamespace('mission')->addMessage('The game was created');
56
57
                return $this->redirect()->toRoute('admin/playgroundgame/list');
58
            }
59
        }
60
        $gameForm->setVariables(array('form' => $form, 'game' => $mission));
61
        $viewModel->addChild($gameForm, 'game_form');
62
63
        return $viewModel->setVariables(array('form' => $form, 'title' => 'Create mission', 'mission' => $mission));
64
    }
65
66
    public function editMissionAction()
67
    {