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

@@ 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
    {