/** * fixates the move if no error occured * * @throws ControllerException * @return void */ public function finishMove() { if ($this->error) { return; } // check if every option has taken countries $move = ModelSelectStartMove::getSelectStartMoveForUser($this->id_user, $this->id_game); $regions_selected = $move->getRegions(); // array(int option_number => array(int id_zarea)) // get Model Data /** @var $iig ModelIsInGameInfo */ $iig = ModelIsInGameInfo::getIsInGameInfo($this->id_user, $this->id_game); $id_set = $iig->getIdStartingSet(); $regions = ModelStartRegion::getRegionsForSet($id_set); // array(int id_opttype => array(int option_number => array(int id_area => ModelStartRegion))) foreach ($regions as $opttype) { foreach ($opttype as $opt_number => $areas) { if (!isset($regions_selected[$opt_number])) { throw new ControllerException('Choose countries first.'); } } } $this->fixatePhase(true); }
private function parseOptions(array &$data) { $viewData = array(); foreach ($this->possibleStartRegions as $id_option_type => $option_types) { $optionType = ModelOptionType::getOptionType($id_option_type); foreach ($option_types as $option_number => $options) { $optionViewData = array(); $optionViewData['number'] = $option_number; $optionViewData['countrySelectUnitCount'] = $optionType->getUnits(); $optionViewData['countrySelectCount'] = $optionType->getCountries(); $optionViewData['areas'] = array(); foreach ($options as $id_area => $startRegion) { // get area infos $areaModel = ModelArea::getArea($id_area); $area = array(); $area['id_area'] = $id_area; $area['number'] = $areaModel->getNumber(); $area['name'] = $areaModel->getName(); // check if country already selected $gameArea = ModelGameArea::getGameAreaForArea(ModelGame::getCurrentGame()->getId(), $id_area); $id_zarea = $gameArea->getId(); $modelMove = ModelSelectStartMove::getSelectStartMoveForUser(ModelUser::getCurrentUser()->getId(), ModelGame::getCurrentGame()->getId()); if ($modelMove->checkIfAreaIsSelected($option_number, $id_zarea)) { $area['checked'] = true; } $optionViewData['areas'][] = $area; } $viewData[] = $optionViewData; } } $data['options'] = $viewData; }