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

@@ 100-162 (lines=63) @@
97
        return $viewModel->setVariables(array('form' => $form, 'title' => 'Create Post & Vote'));
98
    }
99
100
    public function editPostVoteAction()
101
    {
102
        $service = $this->getAdminGameService();
103
        $gameId = $this->getEvent()->getRouteMatch()->getParam('gameId');
104
105
        if (!$gameId) {
106
            return $this->redirect()->toRoute('admin/playgroundgame/create-postvote');
107
        }
108
109
        $game = $service->getGameMapper()->findById($gameId);
110
        $viewModel = new ViewModel();
111
        $viewModel->setTemplate('playground-game/post-vote/postvote');
112
113
        $gameForm = new ViewModel();
114
        $gameForm->setTemplate('playground-game/game/game-form');
115
116
        $form   = $this->getServiceLocator()->get('playgroundgame_postvote_form');
117
        $form->setAttribute(
118
            'action',
119
            $this->url()->fromRoute(
120
                'admin/playgroundgame/edit-postvote',
121
                array('gameId' => $gameId)
122
            )
123
        );
124
        $form->setAttribute('method', 'post');
125
        
126
        if ($game->getFbAppId()) {
127
            $appIds = $form->get('fbAppId')->getOption('value_options');
128
            $appIds[$game->getFbAppId()] = $game->getFbAppId();
129
            $form->get('fbAppId')->setAttribute('options', $appIds);
130
        }
131
132
        $gameOptions = $this->getAdminGameService()->getOptions();
133
        $gameStylesheet = $gameOptions->getMediaPath() . '/' . 'stylesheet_'. $game->getId(). '.css';
134
        if (is_file($gameStylesheet)) {
135
            $values = $form->get('stylesheet')->getValueOptions();
136
            $values[$gameStylesheet] = 'Style personnalisé de ce jeu';
137
138
            $form->get('stylesheet')->setAttribute('options', $values);
139
        }
140
141
        $form->bind($game);
142
143
        if ($this->getRequest()->isPost()) {
144
            $data = array_replace_recursive(
145
                $this->getRequest()->getPost()->toArray(),
146
                $this->getRequest()->getFiles()->toArray()
147
            );
148
            if (empty($data['prizes'])) {
149
                $data['prizes'] = array();
150
            }
151
            $result = $service->edit($data, $game, 'playgroundgame_postvote_form');
152
153
            if ($result) {
154
                return $this->redirect()->toRoute('admin/playgroundgame/list');
155
            }
156
        }
157
158
        $gameForm->setVariables(array('form' => $form, 'game' => $game));
159
        $viewModel->addChild($gameForm, 'game_form');
160
161
        return $viewModel->setVariables(array('form' => $form, 'title' => 'Edit Post & Vote'));
162
    }
163
164
    public function modListAction()
165
    {

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

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