| @@ 148-192 (lines=45) @@ | ||
| 145 | ); |
|
| 146 | } |
|
| 147 | ||
| 148 | public function editCardAction() |
|
| 149 | { |
|
| 150 | $this->checkGame(); |
|
| 151 | ||
| 152 | $viewModel = new ViewModel(); |
|
| 153 | $viewModel->setTemplate('playground-game/memory/card'); |
|
| 154 | $service = $this->getAdminGameService(); |
|
| 155 | ||
| 156 | $cardId = $this->getEvent()->getRouteMatch()->getParam('cardId'); |
|
| 157 | $card = $service->getMemoryCardMapper()->findById($cardId); |
|
| 158 | ||
| 159 | $form = $this->getServiceLocator()->get('playgroundgame_memorycard_form'); |
|
| 160 | $form->remove('cards_file'); |
|
| 161 | ||
| 162 | $form->get('submit')->setAttribute('label', 'Edit'); |
|
| 163 | $form->setAttribute('action', ''); |
|
| 164 | ||
| 165 | $form->get('memory_id')->setAttribute('value', $this->game->getId()); |
|
| 166 | ||
| 167 | $form->bind($card); |
|
| 168 | ||
| 169 | if ($this->getRequest()->isPost()) { |
|
| 170 | $data = array_merge( |
|
| 171 | $this->getRequest()->getPost()->toArray(), |
|
| 172 | $this->getRequest()->getFiles()->toArray() |
|
| 173 | ); |
|
| 174 | $card = $service->updateCard($data, $card); |
|
| 175 | ||
| 176 | if ($card) { |
|
| 177 | // Redirect to list of games |
|
| 178 | $this->flashMessenger()->setNamespace('playgroundgame')->addMessage('The card has been edited'); |
|
| 179 | return $this->redirect()->toUrl( |
|
| 180 | $this->adminUrl()->fromRoute('playgroundgame/memory-card-list', array('gameId' => $this->game->getId())) |
|
| 181 | ); |
|
| 182 | } |
|
| 183 | } |
|
| 184 | return $viewModel->setVariables( |
|
| 185 | array( |
|
| 186 | 'form' => $form, |
|
| 187 | 'game' => $this->game, |
|
| 188 | 'card_id' => $cardId, |
|
| 189 | 'title' => 'Edit card', |
|
| 190 | ) |
|
| 191 | ); |
|
| 192 | } |
|
| 193 | ||
| 194 | public function removeCardAction() |
|
| 195 | { |
|
| @@ 149-193 (lines=45) @@ | ||
| 146 | ); |
|
| 147 | } |
|
| 148 | ||
| 149 | public function editModelAction() |
|
| 150 | { |
|
| 151 | $this->checkGame(); |
|
| 152 | ||
| 153 | $viewModel = new ViewModel(); |
|
| 154 | $viewModel->setTemplate('playground-game/trading-card/model'); |
|
| 155 | $service = $this->getAdminGameService(); |
|
| 156 | ||
| 157 | $modelId = $this->getEvent()->getRouteMatch()->getParam('modelId'); |
|
| 158 | $model = $service->getTradingCardModelMapper()->findById($modelId); |
|
| 159 | ||
| 160 | $form = $this->getServiceLocator()->get('playgroundgame_tradingcardmodel_form'); |
|
| 161 | $form->remove('models_file'); |
|
| 162 | ||
| 163 | $form->get('submit')->setAttribute('label', 'Edit'); |
|
| 164 | $form->setAttribute('action', ''); |
|
| 165 | ||
| 166 | $form->get('trading_card_id')->setAttribute('value', $this->game->getId()); |
|
| 167 | ||
| 168 | $form->bind($model); |
|
| 169 | ||
| 170 | if ($this->getRequest()->isPost()) { |
|
| 171 | $data = array_merge( |
|
| 172 | $this->getRequest()->getPost()->toArray(), |
|
| 173 | $this->getRequest()->getFiles()->toArray() |
|
| 174 | ); |
|
| 175 | $model = $service->updateModel($data, $model); |
|
| 176 | ||
| 177 | if ($model) { |
|
| 178 | // Redirect to list of games |
|
| 179 | $this->flashMessenger()->setNamespace('playgroundgame')->addMessage('The model has been edited'); |
|
| 180 | return $this->redirect()->toUrl( |
|
| 181 | $this->adminUrl()->fromRoute('playgroundgame/tradingcard-model-list', array('gameId' => $this->game->getId())) |
|
| 182 | ); |
|
| 183 | } |
|
| 184 | } |
|
| 185 | return $viewModel->setVariables( |
|
| 186 | array( |
|
| 187 | 'form' => $form, |
|
| 188 | 'game' => $this->game, |
|
| 189 | 'model_id' => $modelId, |
|
| 190 | 'title' => 'Edit model', |
|
| 191 | ) |
|
| 192 | ); |
|
| 193 | } |
|
| 194 | ||
| 195 | /** |
|
| 196 | * This function helps the admin to position UGC image on a card model |
|