/** * user selected areas * * @param $id_set int * @param $option_number int * @param $areas array(int id_area) * @throws ControllerException * @return void */ public function selectStartAreas($id_set, $option_number, $areas) { if ($this->error) { return; } // check if user has already finished this move if ($this->checkIfDone()) { $this->error = true; throw new ControllerException('You have already finished this move.'); } // check if regions are in the set option $supported_areas = ModelStartRegion::getRegionsForSetAndOption($id_set, $option_number); foreach ($areas as $id_area) { if (!isset($supported_areas[$id_area])) { $this->error = true; throw new ControllerException('The area ' . $id_area . ' is not in your set and option-number.'); } } // check if correct number of areas selected $startRegion = array_shift($supported_areas); $id_option_type = $startRegion->getIdOptionType(); $optionType = ModelOptionType::getOptionType($id_option_type); if ($optionType->getCountries() !== count($areas)) { $this->error = true; throw new ControllerException('Please choose the correct amount of areas.'); } // insert $move = ModelSelectStartMove::getSelectStartMoveForUser($this->id_user, $this->id_game); $zareas = array(); foreach ($areas as $id_area) { $gameArea = ModelGameArea::getGameAreaForArea($this->id_game, $id_area); $zareas[] = $gameArea->getId(); } $move->setRegions($option_number, $zareas); }
public function run(array &$data) { $data['template'] = $this->getTemplate(); $this->addCurrentGameInfo($data); $this->moveController = new SetShipsController(ModelUser::getCurrentUser()->getId(), ModelGame::getCurrentGame()->getId()); // update moves if (isset($_POST['setship'])) { $this->setShip($data); } if (isset($_POST['fixate_start'])) { $this->fixateMove($data); } if (isset($_POST['delete'])) { $this->deleteMove($data); } // show already set ships $data['currentShips'] = array(); $iterator = ModelSetShipsMove::getSetShipMovesForUser(ModelUser::getCurrentUser()->getId(), ModelGame::getCurrentGame()->getId()); while ($iterator->hasNext()) { /** @var ModelSetShipsMove $move */ $move = $iterator->next(); $zShip = ModelInGameShip::getShipById(ModelGame::getCurrentGame()->getId(), $move->getIdZunit()); $id_ship = $zShip->getIdUnit(); $ship = ModelShip::getModelById($id_ship); $zAreaInPort = ModelGameArea::getGameArea(ModelGame::getCurrentGame()->getId(), $move->getIdZareaInPort()); $zAreaAtSea = ModelGameArea::getGameArea(ModelGame::getCurrentGame()->getId(), $move->getIdZarea()); $data['currentShips'][] = array('id' => $move->getId(), 'ship_type' => $ship->getName(), 'ship_name' => $zShip->getName(), 'zarea_in_port' => $zAreaInPort->getName() . ' ' . $zAreaInPort->getNumber(), 'zarea_at_sea' => $zAreaAtSea->getName() . ' ' . $zAreaAtSea->getNumber()); } // show still available ships $data['availableShips'] = array(); $stillAvailableShips = $this->moveController->getStillAvailableShips(); foreach ($stillAvailableShips as $id_unit => $count) { if ($count <= 0) { continue; } $data['availableShips'][] = array('id' => $id_unit, 'count' => $count, 'name' => ModelShip::getModelById($id_unit)->getName()); } // show available countries $data['availableZAreasInPort'] = array(); $data['availableZAreasAtSea'] = array(); $iterator = ModelGameArea::iterator(ModelUser::getCurrentUser()->getId(), ModelGame::getCurrentGame()->getId()); while ($iterator->hasNext()) { /** @var ModelGameArea $zArea */ $zArea = $iterator->next(); $data['availableZAreasInPort'][] = array('id_zarea_in_port' => $zArea->getId(), 'name' => $zArea->getName(), 'number' => $zArea->getNumber()); } $iterator = ModelArea::iterator(TYPE_SEA); while ($iterator->hasNext()) { /** @var ModelArea $area */ $area = $iterator->next(); $data['availableZAreasAtSea'][] = array('id_zarea_at_sea' => ModelGameArea::getGameAreaForArea(ModelGame::getCurrentGame()->getId(), $area->getId())->getId(), 'name' => $area->getName(), 'number' => $area->getNumber()); } $this->checkFixate($data, PHASE_SETSHIPS); $this->checkCurrentPhase($data, PHASE_SETSHIPS); }
private function showNewMove(array &$data) { $startAreas = array(); $destinationAreas = array(); $areas = ModelArea::iterator(TYPE_LAND); while ($areas->hasNext()) { /* @var $area ModelArea */ $area = $areas->next(); $zArea = ModelGameArea::getGameAreaForArea(ModelGame::getCurrentGame()->getId(), $area->getId()); $areaViewData = array(); $areaViewData['id_zarea'] = $zArea->getId(); $areaViewData['number'] = $area->getNumber(); $areaViewData['name'] = $area->getName(); if ($zArea->getIdUser() === ModelUser::getCurrentUser()->getId()) { $startAreas[] = $areaViewData; } $destinationAreas[] = $areaViewData; } $data['startAreas'] = $startAreas; $data['destinationAreas'] = $destinationAreas; }
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; }
private function showNewMove(array &$data) { $areasViewData = array(); $areas = ModelArea::iterator(TYPE_LAND); while ($areas->hasNext()) { /* @var $area ModelArea */ $area = $areas->next(); $zArea = ModelGameArea::getGameAreaForArea(ModelGame::getCurrentGame()->getId(), $area->getId()); $areaViewData = array(); $areaViewData['id_zarea'] = $zArea->getId(); $areaViewData['number'] = $area->getNumber(); $areaViewData['name'] = $area->getName(); if ($zArea->getIdUser() === ModelUser::getCurrentUser()->getId()) { $areasViewData[] = $areaViewData; } } $data['areas'] = $areasViewData; $unitsViewData = array(); $unit_iter = ModelLandUnit::iterator(); while ($unit_iter->hasNext()) { /* @var $unit ModelLandUnit */ $unit = $unit_iter->next(); $unitsViewData[] = array('id' => $unit->getId(), 'name' => $unit->getName()); } $data['units'] = $unitsViewData; }