Code Duplication    Length = 57-68 lines in 3 locations

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

@@ 83-150 (lines=68) @@
80
        );
81
    }
82
83
    public function editInstantWinAction()
84
    {
85
        $service = $this->getAdminGameService();
86
        $gameId = $this->getEvent()->getRouteMatch()->getParam('gameId');
87
88
        if (!$gameId) {
89
            return $this->redirect()->toRoute('admin/playgroundgame/create-instantwin');
90
        }
91
92
        $game = $service->getGameMapper()->findById($gameId);
93
        $viewModel = new ViewModel();
94
        $viewModel->setTemplate('playground-game/instant-win/instantwin');
95
96
        $gameForm = new ViewModel();
97
        $gameForm->setTemplate('playground-game/game/game-form');
98
99
        $form   = $this->getServiceLocator()->get('playgroundgame_instantwin_form');
100
        $form->setAttribute(
101
            'action',
102
            $this->url()->fromRoute(
103
                'admin/playgroundgame/edit-instantwin',
104
                array('gameId' => $gameId)
105
            )
106
        );
107
        $form->setAttribute('method', 'post');
108
109
        if ($game->getFbAppId()) {
110
            $appIds = $form->get('fbAppId')->getOption('value_options');
111
            $appIds[$game->getFbAppId()] = $game->getFbAppId();
112
            $form->get('fbAppId')->setAttribute('options', $appIds);
113
        }
114
115
        $gameOptions = $this->getAdminGameService()->getOptions();
116
        $gameStylesheet = $gameOptions->getMediaPath() . '/' . 'stylesheet_'. $game->getId(). '.css';
117
        if (is_file($gameStylesheet)) {
118
            $values = $form->get('stylesheet')->getValueOptions();
119
            $values[$gameStylesheet] = 'Style personnalisé de ce jeu';
120
121
            $form->get('stylesheet')->setAttribute('options', $values);
122
        }
123
124
        $form->bind($game);
125
126
        if ($this->getRequest()->isPost()) {
127
            $data = array_replace_recursive(
128
                $this->getRequest()->getPost()->toArray(),
129
                $this->getRequest()->getFiles()->toArray()
130
            );
131
            if (empty($data['prizes'])) {
132
                $data['prizes'] = array();
133
            }
134
            $result = $service->edit($data, $game, 'playgroundgame_instantwin_form');
135
136
            if ($result) {
137
                return $this->redirect()->toRoute('admin/playgroundgame/list');
138
            }
139
        }
140
141
        $gameForm->setVariables(array('form' => $form, 'game' => $game));
142
        $viewModel->addChild($gameForm, 'game_form');
143
144
        return $viewModel->setVariables(
145
            array(
146
                'form' => $form,
147
                'title' => 'Edit instant win',
148
            )
149
        );
150
    }
151
152
    public function listOccurrenceAction()
153
    {

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

@@ 61-123 (lines=63) @@
58
        return $viewModel->setVariables(array('form' => $form, 'title' => 'Create Post & Vote'));
59
    }
60
61
    public function editPostVoteAction()
62
    {
63
        $service = $this->getAdminGameService();
64
        $gameId = $this->getEvent()->getRouteMatch()->getParam('gameId');
65
66
        if (!$gameId) {
67
            return $this->redirect()->toRoute('admin/playgroundgame/create-postvote');
68
        }
69
70
        $game = $service->getGameMapper()->findById($gameId);
71
        $viewModel = new ViewModel();
72
        $viewModel->setTemplate('playground-game/post-vote/postvote');
73
74
        $gameForm = new ViewModel();
75
        $gameForm->setTemplate('playground-game/game/game-form');
76
77
        $form   = $this->getServiceLocator()->get('playgroundgame_postvote_form');
78
        $form->setAttribute(
79
            'action',
80
            $this->url()->fromRoute(
81
                'admin/playgroundgame/edit-postvote',
82
                array('gameId' => $gameId)
83
            )
84
        );
85
        $form->setAttribute('method', 'post');
86
        
87
        if ($game->getFbAppId()) {
88
            $appIds = $form->get('fbAppId')->getOption('value_options');
89
            $appIds[$game->getFbAppId()] = $game->getFbAppId();
90
            $form->get('fbAppId')->setAttribute('options', $appIds);
91
        }
92
93
        $gameOptions = $this->getAdminGameService()->getOptions();
94
        $gameStylesheet = $gameOptions->getMediaPath() . '/' . 'stylesheet_'. $game->getId(). '.css';
95
        if (is_file($gameStylesheet)) {
96
            $values = $form->get('stylesheet')->getValueOptions();
97
            $values[$gameStylesheet] = 'Style personnalisé de ce jeu';
98
99
            $form->get('stylesheet')->setAttribute('options', $values);
100
        }
101
102
        $form->bind($game);
103
104
        if ($this->getRequest()->isPost()) {
105
            $data = array_replace_recursive(
106
                $this->getRequest()->getPost()->toArray(),
107
                $this->getRequest()->getFiles()->toArray()
108
            );
109
            if (empty($data['prizes'])) {
110
                $data['prizes'] = array();
111
            }
112
            $result = $service->edit($data, $game, 'playgroundgame_postvote_form');
113
114
            if ($result) {
115
                return $this->redirect()->toRoute('admin/playgroundgame/list');
116
            }
117
        }
118
119
        $gameForm->setVariables(array('form' => $form, 'game' => $game));
120
        $viewModel->addChild($gameForm, 'game_form');
121
122
        return $viewModel->setVariables(array('form' => $form, 'title' => 'Edit Post & Vote'));
123
    }
124
125
    public function modListAction()
126
    {

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

@@ 193-249 (lines=57) @@
190
        return $viewModel->setVariables(array('form' => $form, 'title' => 'Create quiz'));
191
    }
192
193
    public function editQuizAction()
194
    {
195
        $service = $this->getAdminGameService();
196
        $gameId = $this->getEvent()->getRouteMatch()->getParam('gameId');
197
198
        if (!$gameId) {
199
            return $this->redirect()->toRoute('admin/playgroundgame/create-quiz');
200
        }
201
202
        $game = $service->getGameMapper()->findById($gameId);
203
        $viewModel = new ViewModel();
204
        $viewModel->setTemplate('playground-game/quiz/quiz');
205
206
        $gameForm = new ViewModel();
207
        $gameForm->setTemplate('playground-game/game/game-form');
208
209
        $form   = $this->getServiceLocator()->get('playgroundgame_quiz_form');
210
        $form->setAttribute('action', $this->url()->fromRoute('admin/playgroundgame/edit-quiz', array('gameId' => $gameId)));
211
        $form->setAttribute('method', 'post');
212
213
        if ($game->getFbAppId()) {
214
            $appIds = $form->get('fbAppId')->getOption('value_options');
215
            $appIds[$game->getFbAppId()] = $game->getFbAppId();
216
            $form->get('fbAppId')->setAttribute('options', $appIds);
217
        }
218
219
        $gameOptions = $this->getAdminGameService()->getOptions();
220
        $gameStylesheet = $gameOptions->getMediaPath() . '/' . 'stylesheet_'. $game->getId(). '.css';
221
        if (is_file($gameStylesheet)) {
222
            $values = $form->get('stylesheet')->getValueOptions();
223
            $values[$gameStylesheet] = 'Style personnalisé de ce jeu';
224
225
            $form->get('stylesheet')->setAttribute('options', $values);
226
        }
227
228
        $form->bind($game);
229
230
        if ($this->getRequest()->isPost()) {
231
            $data = array_replace_recursive(
232
                $this->getRequest()->getPost()->toArray(),
233
                $this->getRequest()->getFiles()->toArray()
234
            );
235
            if (empty($data['prizes'])) {
236
                $data['prizes'] = array();
237
            }
238
            $result = $service->edit($data, $game, 'playgroundgame_quiz_form');
239
240
            if ($result) {
241
                return $this->redirect()->toRoute('admin/playgroundgame/list');
242
            }
243
        }
244
245
        $gameForm->setVariables(array('form' => $form, 'game' => $game));
246
        $viewModel->addChild($gameForm, 'game_form');
247
248
        return $viewModel->setVariables(array('form' => $form, 'title' => 'Edit quiz'));
249
    }
250
251
    public function getAdminGameService()
252
    {