Code Duplication    Length = 47-47 lines in 2 locations

src/Controller/Admin/LotteryController.php 1 location

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

src/Controller/Admin/MemoryController.php 1 location

@@ 21-67 (lines=47) @@
18
     */
19
    protected $adminGameService;
20
21
    public function createMemoryAction()
22
    {
23
        $service = $this->getAdminGameService();
24
        $viewModel = new ViewModel();
25
        $viewModel->setTemplate('playground-game/memory/memory');
26
27
        $gameForm = new ViewModel();
28
        $gameForm->setTemplate('playground-game/game/game-form');
29
30
        $memory = new Memory();
31
32
        $form = $this->getServiceLocator()->get('playgroundgame_memory_form');
33
        $form->bind($memory);
34
        $form->get('submit')->setAttribute('label', 'Add');
35
        $form->setAttribute(
36
            'action',
37
            $this->adminUrl()->fromRoute(
38
                'playgroundgame/create-memory',
39
                array('gameId' => 0)
40
            )
41
        );
42
        $form->setAttribute('method', 'post');
43
44
        $request = $this->getRequest();
45
        if ($request->isPost()) {
46
            $data = array_replace_recursive(
47
                $this->getRequest()->getPost()->toArray(),
48
                $this->getRequest()->getFiles()->toArray()
49
            );
50
            if (empty($data['prizes'])) {
51
                $data['prizes'] = array();
52
            }
53
            if (isset($data['drawDate']) && $data['drawDate']) {
54
                $data['drawDate'] = \DateTime::createFromFormat('d/m/Y', $data['drawDate']);
55
            }
56
            $game = $service->createOrUpdate($data, $memory, 'playgroundgame_memory_form');
57
            if ($game) {
58
                $this->flashMessenger()->setNamespace('playgroundgame')->addMessage('The game was created');
59
60
                return $this->redirect()->toUrl($this->adminUrl()->fromRoute('playgroundgame/list'));
61
            }
62
        }
63
        $gameForm->setVariables(array('form' => $form, 'game' => $memory));
64
        $viewModel->addChild($gameForm, 'game_form');
65
66
        return $viewModel->setVariables(array('form' => $form, 'title' => 'Create memory'));
67
    }
68
69
    public function editMemoryAction()
70
    {