Code Duplication    Length = 46-50 lines in 2 locations

src/Controller/Admin/MemoryController.php 1 location

@@ 101-146 (lines=46) @@
98
        );
99
    }
100
101
    public function addCardAction()
102
    {
103
        $this->checkGame();
104
105
        $viewModel = new ViewModel();
106
        $viewModel->setTemplate('playground-game/memory/card');
107
108
        $form = $this->getServiceLocator()->get('playgroundgame_memorycard_form');
109
        $form->get('submit')->setAttribute('label', 'Add');
110
111
        $form->setAttribute(
112
            'action',
113
            $this->adminUrl()->fromRoute(
114
                'playgroundgame/memory-card-add',
115
                array('gameId' => $this->game->getId())
116
            )
117
        );
118
        $form->setAttribute('method', 'post');
119
        $form->get('memory_id')->setAttribute('value', $this->game->getId());
120
        $card = new MemoryCard();
121
        $form->bind($card);
122
123
        if ($this->getRequest()->isPost()) {
124
            $data = array_merge(
125
                $this->getRequest()->getPost()->toArray(),
126
                $this->getRequest()->getFiles()->toArray()
127
            );
128
129
            $card = $this->getAdminGameService()->updateCard($data, $card);
130
            if ($card) {
131
                // Redirect to list of games
132
                $this->flashMessenger()->setNamespace('playgroundgame')->addMessage('The card has been created');
133
                return $this->redirect()->toUrl(
134
                    $this->adminUrl()->fromRoute('playgroundgame/memory-card-list', array('gameId' => $this->game->getId()))
135
                );
136
            }
137
        }
138
        return $viewModel->setVariables(
139
            array(
140
                'form'     => $form,
141
                'game'     => $this->game,
142
                'card_id' => 0,
143
                'title'    => 'Add card',
144
            )
145
        );
146
    }
147
148
    public function editCardAction()
149
    {

src/Controller/Admin/TradingCardController.php 1 location

@@ 98-147 (lines=50) @@
95
        );
96
    }
97
98
    public function addModelAction()
99
    {
100
        $this->checkGame();
101
102
        $viewModel = new ViewModel();
103
        $viewModel->setTemplate('playground-game/trading-card/model');
104
105
        $form = $this->getServiceLocator()->get('playgroundgame_tradingcardmodel_form');
106
        $form->get('submit')->setAttribute('label', 'Add');
107
108
        // $form->get('availability')->setOptions(array(
109
        //     'format' => 'Y-m-d H:i:s'
110
        // ));
111
112
        $form->setAttribute(
113
            'action',
114
            $this->adminUrl()->fromRoute(
115
                'playgroundgame/tradingcard-model-add',
116
                array('gameId' => $this->game->getId())
117
            )
118
        );
119
        $form->setAttribute('method', 'post');
120
        $form->get('trading_card_id')->setAttribute('value', $this->game->getId());
121
        $model = new TradingCardModel();
122
        $form->bind($model);
123
124
        if ($this->getRequest()->isPost()) {
125
            $data = array_merge(
126
                $this->getRequest()->getPost()->toArray(),
127
                $this->getRequest()->getFiles()->toArray()
128
            );
129
130
            $model = $this->getAdminGameService()->updateModel($data, $model);
131
            if ($model) {
132
                // Redirect to list of games
133
                $this->flashMessenger()->setNamespace('playgroundgame')->addMessage('The model has been created');
134
                return $this->redirect()->toUrl(
135
                    $this->adminUrl()->fromRoute('playgroundgame/tradingcard-model-list', array('gameId' => $this->game->getId()))
136
                );
137
            }
138
        }
139
        return $viewModel->setVariables(
140
            array(
141
                'form'     => $form,
142
                'game'     => $this->game,
143
                'model_id' => 0,
144
                'title'    => 'Add model',
145
            )
146
        );
147
    }
148
149
    public function editModelAction()
150
    {