Ejemplo n.º 1
0
 /**
  * returns iterator for all land units
  *
  * @return ModelIterator
  */
 public static function iterator()
 {
     $models = array();
     $query = 'get_all_land_units';
     // query units
     $result = DataSource::Singleton()->epp($query);
     foreach ($result as $unit) {
         $id_unit = $unit['id'];
         $models[] = self::getModelById($id_unit);
     }
     return new ModelIterator($models);
 }
 /**
  * returns an iterator for all games the user is in or all user for a given game
  *
  * @param int $id_user
  * @throws DataSourceException
  * @return ModelIterator
  */
 public static function iterator($id_user = null, $id_game = null)
 {
     $models = array();
     $query = 'get_iig_ids';
     $dict = array();
     $dict[':id_user'] = $id_user == null ? '%' : intval($id_user);
     $dict[':id_game'] = $id_game == null ? '%' : intval($id_game);
     // query user
     $result = DataSource::Singleton()->epp($query, $dict);
     foreach ($result as $iig) {
         $id_game = $iig['id_game'];
         $id_user = $iig['id_user'];
         $models[] = self::getInGamePhaseInfo($id_user, $id_game);
     }
     return new ModelIterator($models);
 }
Ejemplo n.º 3
0
 /**
  * returns the specific model
  *
  * @param $players int
  * @return ModelStartShips
  * @throws NullPointerException
  */
 public static function getStartShipsForPlayers($players)
 {
     $players = (int) $players;
     if (isset(self::$models[$players])) {
         return self::$models[$players];
     }
     // check if there is a game
     $query = 'get_start_ships_for_players';
     $dict = array(':players' => $players);
     $result = DataSource::Singleton()->epp($query, $dict);
     if (empty($result)) {
         throw new NullPointerException('No startships for ' . $players . ' players found.');
     }
     $ships = array();
     foreach ($result as $line) {
         $ships[(int) $line['id_unit']] = (int) $line['numberof'];
     }
     return self::$models[$players] = new ModelStartShips($players, $ships);
 }
Ejemplo n.º 4
0
 /**
  * returns an iterator for economy models
  * @param $economy_type string/enum
  * @param $random_order boolean - set true to get random order
  * @throws DataSourceException
  * @return ModelIterator
  */
 public static function iterator($economy_type, $random_order = true)
 {
     $models = array();
     $query = 'get_resource_allocation';
     $dict = array();
     $dict[':economy'] = $economy_type;
     // query phases
     $result = DataSource::Singleton()->epp($query, $dict);
     foreach ($result as $alloc) {
         $id_res = $alloc['id_resource'];
         $res_pow = $alloc['res_power'];
         $count = $alloc['count'];
         for ($x = 0; $x < $count; $x++) {
             $models[] = new ModelEconomy($id_res, $res_pow);
         }
     }
     if ($random_order) {
         shuffle($models);
     }
     return new ModelIterator($models);
 }
Ejemplo n.º 5
0
 private function fill_member_vars()
 {
     SQLCommands::init($this->id_game);
     // check if there is a game
     $result = DataSource::Singleton()->epp('get_all_zarea_info', array(':id_zarea' => $this->id));
     if (empty($result)) {
         return false;
     }
     $data = $result[0];
     $this->tank = (int) $data['tank'];
     $this->id_user = (int) $data['id_user'];
     $this->id_area = (int) $data['id_area'];
     $this->id_resource = (int) $data['id_resource'];
     $this->productivity = (int) $data['productivity'];
     return true;
 }
Ejemplo n.º 6
0
 private function fill_member_vars()
 {
     // check if there is a game
     $result = DataSource::Singleton()->epp('get_all_area_info', array(':id_area' => $this->id));
     if (empty($result)) {
         return false;
     }
     $data = $result[0];
     $this->name = $data['name'];
     $this->number = $data['number'];
     $this->coords_small = $data['coords_small'];
     $this->x = (int) $data['x'];
     $this->y = (int) $data['y'];
     $this->x2 = (int) $data['x2'];
     $this->y2 = (int) $data['y2'];
     $this->xres = (int) $data['xres'];
     $this->yres = (int) $data['yres'];
     $this->height = (int) $data['height'];
     $this->width = (int) $data['width'];
     $this->tanksize = (int) $data['tanksize'];
     $this->id_type = (int) $data['id_type'];
     $this->zone = (int) $data['zone'];
     $this->economy = $data['economy'];
     return true;
 }
Ejemplo n.º 7
0
 /**
  * creates land move for user
  *
  * @param $id_user int
  * @param $id_game int
  * @param $round int
  * @param $steps array(int step_nr => int id_zarea) -> step_nr counting from 1 to x
  * @param $units array(int id_unit => count)
  * @throws NullPointerException
  * @throws ModelException
  * @return ModelLandMove
  */
 public static function createLandMove($id_user, $id_game, $round, $steps, $units)
 {
     SQLCommands::init(intval($id_game));
     // CREATE MOVE
     $query = 'create_move';
     $dict = array();
     $dict[':id_user'] = intval($id_user);
     $dict[':id_phase'] = PHASE_LANDMOVE;
     $dict[':round'] = $round;
     DataSource::Singleton()->epp($query, $dict);
     $id_move = DataSource::getInstance()->getLastInsertId();
     try {
         // INSERT MOVE STEPS
         $x = 0;
         foreach ($steps as $step => $id_zarea) {
             ++$x;
             ModelGameArea::getGameArea((int) $id_game, (int) $id_zarea);
             if (!isset($steps[$x])) {
                 throw new ModelException('Cannot create landmove, steps not consistent.');
             }
             $query = 'insert_area_for_move';
             $dict = array();
             $dict[':id_move'] = intval($id_move);
             $dict[':step'] = intval($step);
             $dict[':id_zarea'] = intval($id_zarea);
             DataSource::Singleton()->epp($query, $dict);
         }
         $id_zarea_start = (int) $steps[1];
         // INSERT UNITS
         foreach ($units as $id_unit => $count) {
             ModelLandUnit::getModelById($id_unit);
             $zUnit = ModelInGameLandUnit::getModelByIdZAreaUserUnit((int) $id_game, $id_zarea_start, (int) $id_user, (int) $id_unit);
             $query = 'insert_land_units_for_move';
             $dict = array();
             $dict[':id_zunit'] = $zUnit->getId();
             $dict[':id_move'] = intval($id_move);
             $dict[':count'] = intval($count);
             DataSource::Singleton()->epp($query, $dict);
         }
     } catch (ModelException $ex) {
         self::flagMoveDeleted();
         throw $ex;
     } catch (NullPointerException $ex) {
         self::flagMoveDeleted();
         throw $ex;
     }
     return self::$moves[$id_game][$id_move] = new ModelLandMove((int) $id_user, (int) $id_game, PHASE_LANDMOVE, (int) $id_move, (int) $round, false, $steps, $units);
 }
 /**
  * updates selected areas if necessary
  *
  * @param $option_number int
  * @param $zareas array(int id_zarea)
  * @return void
  */
 public function setRegions($option_number, $zareas)
 {
     $option_number = intval($option_number);
     // check if areas are already set
     if (isset($this->regions[$option_number])) {
         $found_all = true;
         foreach ($zareas as $id_zarea) {
             if (!in_array($id_zarea, $this->regions[$option_number])) {
                 $found_all = false;
             }
         }
         if ($found_all) {
             return;
         }
     }
     $dict = array();
     $dict[':id_move'] = $this->id;
     $dict[':step'] = $option_number;
     if (isset($this->regions[$option_number])) {
         unset($this->regions[$option_number]);
         $query = 'delete_move_areas_for_step';
         DataSource::Singleton()->epp($query, $dict);
     }
     // insert areas
     $query = 'insert_area_for_move';
     foreach ($zareas as $id_zarea) {
         $dict[':id_zarea'] = $id_zarea;
         DataSource::getInstance()->epp($query, $dict);
     }
     $this->regions[$option_number] = $zareas;
 }
Ejemplo n.º 9
0
 private function fill_member_vars()
 {
     // check if there is a game
     $result = DataSource::Singleton()->epp('get_phase_info', array(':id_phase' => $this->id));
     if (empty($result)) {
         return false;
     }
     $data = $result[0];
     $this->name = $data['name'];
     $this->label = $data['label'];
     $this->id_type = $data['id_type'];
     return true;
 }
Ejemplo n.º 10
0
 private function fill_member_vars()
 {
     // check if there is a game
     $result = DataSource::Singleton()->epp('get_color', array(':id_color' => $this->id));
     if (empty($result)) {
         return false;
     }
     $data = $result[0];
     $this->name = $data['name'];
     $this->color = $data['color'];
     return true;
 }
Ejemplo n.º 11
0
 private function fill_member_vars()
 {
     // check if there is a game
     $result = DataSource::Singleton()->epp('get_full_game_info', array(':id_game' => $this->id));
     if (empty($result)) {
         return false;
     }
     // fill in info
     $data = $result[0];
     $this->name = $data['name'];
     $this->playerslots = intval($data['players']);
     $this->id_creator = intval($data['id_creator']);
     if ($data['password'] === null) {
         $this->pw_protected = false;
     } else {
         $this->pw_protected = true;
     }
     $this->status = $data['status'];
     $this->id_phase = intval($data['id_phase']);
     $this->round = intval($data['round']);
     if ((int) $data['processing'] === 1) {
         $this->processing = true;
     } else {
         $this->processing = false;
     }
     return true;
 }
 /**
  * creates land move for user
  *
  * @param $id_user int
  * @param $id_game int
  * @param $round int
  * @param $id_zarea int id_zarea
  * @param $units array(int id_unit => count)
  * @throws NullPointerException
  * @throws ModelException
  * @return ModelProductionMove
  */
 public static function createProductionMove($id_user, $id_game, $round, $id_zarea, $units)
 {
     SQLCommands::init(intval($id_game));
     // CREATE MOVE
     $query = 'create_move';
     $dict = array();
     $dict[':id_user'] = intval($id_user);
     $dict[':id_phase'] = PHASE_PRODUCTION;
     $dict[':round'] = $round;
     DataSource::Singleton()->epp($query, $dict);
     $id_move = DataSource::getInstance()->getLastInsertId();
     try {
         // INSERT MOVE STEPS
         ModelGameArea::getGameArea((int) $id_game, (int) $id_zarea);
         $query = 'insert_area_for_move';
         $dict = array();
         $dict[':id_move'] = intval($id_move);
         $dict[':step'] = intval(1);
         $dict[':id_zarea'] = intval($id_zarea);
         DataSource::Singleton()->epp($query, $dict);
         // INSERT UNITS
         foreach ($units as $id_unit => $count) {
             ModelLandUnit::getModelById($id_unit);
             $zUnit = ModelInGameLandUnit::getModelByIdZAreaUserUnit((int) $id_game, $id_zarea, (int) $id_user, (int) $id_unit);
             $query = 'insert_land_units_for_move';
             $dict = array();
             $dict[':id_zunit'] = $zUnit->getId();
             $dict[':id_move'] = intval($id_move);
             $dict[':count'] = intval($count);
             DataSource::Singleton()->epp($query, $dict);
         }
     } catch (ModelException $ex) {
         self::flagMoveDeleted();
         throw $ex;
     } catch (NullPointerException $ex) {
         self::flagMoveDeleted();
         throw $ex;
     }
     return self::$moves[$id_game][$id_move] = new ModelProductionMove((int) $id_user, (int) $id_game, PHASE_PRODUCTION, (int) $id_move, (int) $round, false, $id_zarea, $units);
 }
Ejemplo n.º 13
0
 private function fill_member_vars()
 {
     $result = DataSource::Singleton()->epp('get_all_user_data', array(':id_user' => $this->id));
     if (empty($result)) {
         return false;
     }
     $data = $result[0];
     $this->given_name = $data['name'];
     $this->last_name = $data['lastname'];
     $this->login = $data['login'];
     $this->email = $data['email'];
     $this->status = $data['status'];
     $this->verify = $data['verify'];
     $this->token = $data['token'];
     return true;
 }
Ejemplo n.º 14
0
 /**
  * returns all ships in area that are not destroyed
  *
  * @param $id_game int
  * @param $id_zarea_in_port int
  * @return ModelIterator
  */
 public static function getShipsInPort($id_game, $id_zarea_in_port)
 {
     $models = array();
     $query = 'get_all_ships_in_port';
     $dict = array();
     $dict[':id_zarea_in_port'] = $id_zarea_in_port;
     // query units
     SQLCommands::init($id_game);
     $result = DataSource::Singleton()->epp($query, $dict);
     foreach ($result as $ship) {
         $models[] = self::getShipById($id_game, (int) $ship['id']);
     }
     return new ModelIterator($models);
 }
Ejemplo n.º 15
0
 /**
  * permenantly remove move (and corresponding ship) from database
  *
  * @param ModelSetShipsMove $move
  * @throws NullPointerException
  */
 public static function deleteSetShipsMove(ModelSetShipsMove $move)
 {
     $id_game = $move->getIdGame();
     $id_move = $move->getId();
     SQLCommands::init($id_game);
     // 1. delete ship from DB
     ModelInGameShip::deleteShip($id_game, $move->getIdZunit());
     // 2. delete ship for move
     $query = 'delete_units_for_move';
     $dict = array();
     $dict[':id_move'] = $id_move;
     DataSource::Singleton()->epp($query, $dict);
     // 3. delete areas for move
     $query = 'delete_move_areas_for_move';
     DataSource::Singleton()->epp($query, $dict);
     // 4. delete move
     $query = 'delete_move';
     DataSource::Singleton()->epp($query, $dict);
     unset(self::$moves[$id_game][$id_move]);
 }
Ejemplo n.º 16
0
 /**
  * sets the starting set for the user
  *
  * @param $id_set int
  * @throws NullPointerException
  * @return void
  */
 public function setStartingSet($id_set)
 {
     $id_set = intval($id_set);
     ModelStartingSet::getSet($id_set);
     $this->id_set = $id_set;
     DataSource::Singleton()->epp('set_starting_set_for_user', array(':id_user' => $this->id_user, ':id_game' => $this->id_game, ':id_set' => $this->id_set));
 }