/**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(UpdatePlayerRequest $request, Player $player)
 {
     $player->first_name = $request->first_name;
     $player->last_name = $request->last_name;
     $player->email = $request->email;
     $player->save();
     return redirect()->route('dashboard.player.index')->with('app-success', $player->fullName . ' has been updated.');
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     DB::table('user_roles')->insert(['id' => 1, 'name' => 'Admin', 'identifier' => 'admin']);
     DB::table('users')->insert(['id' => 'user_id', 'name' => 'Matt Higgins', 'email' => '*****@*****.**', 'password' => bcrypt('testing'), 'user_role_id' => 1]);
     $player = new Player();
     $player->first_name = 'Matt';
     $player->last_name = 'Higgins';
     $player->email = '*****@*****.**';
     $player->user_id = 1;
     $player->save();
     DB::table('match_types')->insert([['id' => 1, 'name' => 'Singles', 'identifier' => 'singles'], ['id' => 2, 'name' => 'Doubles', 'identifier' => 'doubles']]);
     // Create players
     // $playerCount = 20;
     // factory(App\Player::class, $playerCount)->create();
     // // Create events with matches and teams
     // factory(App\Event::class, 10)->create()->each(function($event) {
     //     $event->matches()->saveMany(factory(App\Match::class, rand(2,5))->create()->each(function($match) use ($event) {
     //         $teams = factory(App\Team::class, 2)->make();
     //         $match->teams()->saveMany($teams);
     //         $event->teams()->saveMany($teams);
     //         $result = new MatchResult;
     //         $result->match_id = $match->id;
     //         $result->winning_team_id = $teams[0]->id;
     //         $result->losing_team_id = $teams[1]->id;
     //         $result->winning_score = rand(5,8);
     //         $result->losing_score = $result->winning_score - 2;
     //         $result->save();
     //     }));
     // });
     // $playerId = 1;
     // Team::all()->each(function($team, $key) use (&$playerId){
     //     for($i=0;$i<2;$i++)
     //     {
     //         $player = Player::find($playerId);
     //         if($player)
     //         {
     //             $team->players()->save($player);
     //         }else{
     //             $playerId = 1;
     //             $player = Player::find($playerId);
     //             $team->players()->save($player);
     //         }
     //         $playerId++;
     //     }
     // });
     // Event::all()->each(function($event){
     //     foreach($event->matches as $match)
     //     {
     //         $event->players()->saveMany($match->players());
     //     }
     // });
     Model::reguard();
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['player_name' => 'required', 'player_lastname' => 'required', 'birth_date' => 'required', 'birth_place' => 'required', 'player_weight' => 'required', 'player_height' => 'required', 'player_number' => 'required', 'season_id' => 'required', 'position_id' => 'required', 'country_id' => 'required', 'file' => 'required|image:jpg,png,gif,bmp']);
     if ($request->file('file')) {
         $file = $request->file('file');
         $path = 'images/players/';
         $name = $file->getClientOriginalName();
         $file->move($path, $name);
     }
     $player = new Player(array('name' => $request->get('player_name'), 'lastname' => $request->get('player_lastname'), 'birth_date' => $request->get('birth_date'), 'birth_place' => $request->get('birth_place'), 'weight' => $request->get('player_weight'), 'height' => $request->get('player_height'), 'number' => $request->get('player_number'), 'season_id' => $request->get('season_id'), 'position_id' => $request->get('position_id'), 'country_id' => $request->get('country_id'), 'photo' => $path . $name));
     $player->save();
     //flash()->error('Success!','Your flyer has been created');
     flash()->overlay('', 'Naujas žaidėjas sukurtas');
     return redirect()->back();
 }
 /**
  * Joins the game of another person
  */
 public function join()
 {
     $players = Player::where('user_id', Auth::id())->get();
     $gameIds = $players->lists('game_id')->toArray();
     $game = Game::whereNotIn('id', $gameIds)->where(['state' => Game::STATE_OPEN])->first();
     if (is_null($game)) {
         session()->flash('error', sprintf(self::ERROR_NO_GAMES_FOUND, Auth::user()->name));
         return redirect()->route('welcome');
     }
     $player = new Player();
     $player->game_id = $game->id;
     $player->user_id = Auth::id();
     $player->troops = 5;
     $player->save();
     session()->flash('success', sprintf(self::MESSAGE_JOINED_GAME, Auth::user()->name));
     return redirect()->route(self::ROUTE_SHOW_GAME, [$game->id]);
 }
Beispiel #5
0
 /**
  * Add new player.
  *
  * @return Response
  */
 public function add()
 {
     $rules = array('nick' => 'required|unique:players,nick|min:4|max:30|alpha_dash', 'fname' => 'alpha_dash', 'lname' => 'alpha_dash', 'password' => 'required|alpha_dash|min:4|confirmed');
     $validator = \Validator::make(\Input::all(), $rules);
     if ($validator->fails()) {
         return redirect('/player/add')->withInput(\Request::except('password'))->withErrors($validator);
     }
     $player = new Player();
     $player->nick = \Input::get('nick');
     $player->fname = \Input::get('fname');
     $player->lname = \Input::get('lname');
     $player->gender = \Input::get('gender');
     $player->group = 2;
     $player->password = \Hash::make(\Input::get('password'));
     $player->birth = \Input::get('birth');
     $player->save();
     //\Auth::loginUsingId($player->id);
     return \Redirect::route('players');
 }
Beispiel #6
0
 public function getPlayers()
 {
     //全部消す
     foreach (Player::all() as $player) {
         $player->delete();
     }
     //一覧更新
     $client = new Client();
     $crawler = $client->request('GET', 'http://www.wtatennis.com/players');
     $crawler->filter('div.col ul li a')->each(function ($node) {
         $player = new Player();
         $name = explode('(', $node->text());
         $player->name = $name[0];
         $national = str_replace(')', '', $name[1]);
         $player->national = $national;
         $player->url = $node->attr('href');
         $player->save();
     });
     $players = Player::all();
     return view('players.list')->with(compact('players'));
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function storePlayer(Request $request)
 {
     $player = new Player();
     $league_id = Input::get('league_id');
     $player_id = Input::get('player_id');
     // Player already exists?
     if (!is_null($player_id)) {
         $player = Player::find($player_id);
     } else {
         $user = new User();
         $user->first_name = Input::get('first_name');
         $user->last_name = Input::get('last_name');
         $user->email = Input::get('email');
         $user->save();
         $player = new Player();
         $player->first_name = Input::get('first_name');
         $player->last_name = Input::get('last_name');
         $player->player_id = $user->id;
         $player->save();
     }
     //Insert into league
     if ($player->player_id > 0) {
         $league_player = new LeaguePlayer();
         $league_player->player_id = $player->player_id;
         $league_player->league_id = $league_id;
         $league_player->save();
     }
     return \Redirect::route('tools.league.join', array($league_id));
 }
 /**
  * @return bool
  *
  * Track all round record into Database.
  */
 public function track()
 {
     /**
      * @var Game
      */
     $game = new Game();
     $game->tag = $this->roundTag;
     $game->server_time = $this->serverTime;
     $game->round_time = $this->timePlayed;
     $game->round_index = $this->roundIndex + 1 . " / " . $this->roundLimit;
     $game->gametype = $this->gameType;
     $game->outcome = $this->roundOutcome;
     $game->map_id = $this->gameMap;
     $game->total_players = $this->totalPlayers;
     $game->swat_score = $this->swatScore;
     $game->suspects_score = $this->suspectsScore;
     $game->swat_vict = $this->swatVictory;
     $game->suspects_vict = $this->suspectsVictory;
     if (!$game->save()) {
         return false;
     }
     /**
      * Iterate over each player array
      */
     foreach ($this->players as $p) {
         /**
          * @var Player
          */
         $player = new Player();
         $player->ingame_id = $p[0];
         $player->ip_address = $p[1];
         $player->name = str_replace('(VIEW)', '', $p[5]);
         $player->name = str_replace('(SPEC)', '', $player->name);
         $player->team = array_key_exists(6, $p) ? $p[6] : 0;
         $player->is_admin = array_key_exists(3, $p) ? $p[3] : 0;
         $player->is_dropped = array_key_exists(2, $p) ? $p[2] : 0;
         $player->score = array_key_exists(8, $p) ? $p[8] : 0;
         $player->time_played = array_key_exists(7, $p) ? $p[7] : 0;
         $player->kills = array_key_exists(9, $p) ? $p[9] : 0;
         $player->team_kills = array_key_exists(10, $p) ? $p[10] : 0;
         $player->deaths = array_key_exists(11, $p) ? $p[11] : 0;
         $player->suicides = array_key_exists(12, $p) ? $p[12] : 0;
         $player->arrests = array_key_exists(13, $p) ? $p[13] : 0;
         $player->arrested = array_key_exists(14, $p) ? $p[14] : 0;
         $player->kill_streak = array_key_exists(15, $p) ? $p[15] : 0;
         $player->arrest_streak = array_key_exists(16, $p) ? $p[16] : 0;
         $player->death_streak = array_key_exists(17, $p) ? $p[17] : 0;
         $player->game_id = $game->id;
         $player_ip_trim = substr($p[1], 0, strrpos($p[1], "."));
         $player_country_id = 0;
         $geoip = App::make('geoip');
         try {
             if ($player_geoip = $geoip->city($player->ip_address)) {
                 $player_isoCode = $player_geoip->country->isoCode;
                 $country = Country::where('countryCode', 'LIKE', $player_isoCode)->first();
                 /**
                  * Country returned is not in Countrie table
                  */
                 if ($country == null) {
                     $player_country_id = 0;
                 } else {
                     $player_country_id = $country->id;
                 }
             }
         } catch (\Exception $e) {
             switch ($e) {
                 case $e instanceof \InvalidArgumentException:
                     $player_country_id = 0;
                     break;
                 case $e instanceof \GeoIp2\Exception\AddressNotFoundException:
                     $player_country_id = 0;
                     break;
                 default:
                     $player_country_id = 0;
                     break;
             }
         }
         $loadout_array = array_key_exists(39, $p) ? $p[39] : [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
         /**
          * @var Loadout
          *
          * Create or find and return instance of Loadout and save to database.
          */
         $loadout = Loadout::firstOrCreate(['primary_weapon' => array_key_exists(0, $loadout_array) ? $loadout_array[0] : 0, 'primary_ammo' => array_key_exists(1, $loadout_array) ? $loadout_array[1] : 0, 'secondary_weapon' => array_key_exists(2, $loadout_array) ? $loadout_array[2] : 0, 'secondary_ammo' => array_key_exists(3, $loadout_array) ? $loadout_array[3] : 0, 'equip_one' => array_key_exists(4, $loadout_array) ? $loadout_array[4] : 0, 'equip_two' => array_key_exists(5, $loadout_array) ? $loadout_array[5] : 0, 'equip_three' => array_key_exists(6, $loadout_array) ? $loadout_array[6] : 0, 'equip_four' => array_key_exists(7, $loadout_array) ? $loadout_array[7] : 0, 'equip_five' => array_key_exists(8, $loadout_array) ? $loadout_array[8] : 0, 'breacher' => array_key_exists(9, $loadout_array) ? $loadout_array[9] : 0, 'body' => array_key_exists(10, $loadout_array) ? $loadout_array[10] : 0, 'head' => array_key_exists(11, $loadout_array) ? $loadout_array[11] : 0]);
         /**
          * Create or find and return instance of Alias.
          */
         $alias = Alias::firstOrNew(['name' => $player->name]);
         /**
          * If Alias is not present then new instance is created.
          */
         if ($alias->id == null) {
             //$profile = Profile::firstOrNew(['ip_address' => $player_ip_trim.'%']);
             $profile = Profile::where('ip_address', 'LIKE', $player_ip_trim . '%')->first();
             // If no profile present create new else ignore.
             if (!$profile) {
                 $profile = new Profile();
             }
             /**
              * Neither Alias not Profile is present.
              *
              * So it will create both new Alias and Profile.
              */
             if ($profile->id == null) {
                 $profile->name = $player->name;
                 $profile->team = $player->team;
                 $profile->country_id = $player_country_id;
                 $profile->loadout_id = $loadout->id;
                 $profile->game_first = $game->id;
                 $profile->game_last = $game->id;
                 $profile->ip_address = $player->ip_address;
                 $profile->save();
                 $alias->name = $player->name;
                 $alias->profile_id = $profile->id;
                 $alias->ip_address = $player->ip_address;
                 $alias->save();
             } else {
                 $alias->name = $player->name;
                 $alias->profile_id = $profile->id;
                 $alias->ip_address = $player->ip_address;
                 $alias->save();
                 $profile->team = $player->team;
                 $profile->game_last = $game->id;
                 $profile->loadout_id = $loadout->id;
                 $profile->ip_address = $player->ip_address;
                 $profile->country_id = $player_country_id;
                 $profile->save();
             }
         } else {
             $profile = Profile::find($alias->profile_id);
             $profile->team = $player->team;
             $profile->game_last = $game->id;
             $profile->loadout_id = $loadout->id;
             $profile->ip_address = $player->ip_address;
             $profile->country_id = $player_country_id;
             $profile->save();
             $alias->ip_address = $player->ip_address;
             $alias->save();
         }
         $player->alias_id = $alias->id;
         $player->loadout_id = $loadout->id;
         $player->country_id = $player_country_id;
         $player->save();
         /**
          * Iterate over all Weapon of each Player if exists
          */
         if (array_key_exists(40, $p)) {
             foreach ($p[40] as $w) {
                 $weapon = new Weapon();
                 $weapon->name = $w[0];
                 $weapon->player_id = $player->id;
                 $weapon->seconds_used = array_key_exists(1, $w) ? $w[1] : 0;
                 $weapon->shots_fired = array_key_exists(2, $w) ? $w[2] : 0;
                 $weapon->shots_hit = array_key_exists(3, $w) ? $w[3] : 0;
                 $weapon->shots_teamhit = array_key_exists(4, $w) ? $w[4] : 0;
                 $weapon->kills = array_key_exists(5, $w) ? $w[5] : 0;
                 $weapon->teamkills = array_key_exists(6, $w) ? $w[6] : 0;
                 $weapon->distance = array_key_exists(7, $w) ? $w[7] : 0;
                 $weapon->save();
             }
         }
     }
     //$pt = new App\Server\Repositories\PlayerTotalRepository();
     //$pt->calculate();
     //$response = Response::make("0\\nStats has been successfully tracked",200);
     printf("%s", "0\nRound report tracked.");
     exit(0);
 }
 /**
  * 创建玩家实例
  */
 public function create()
 {
     // 取得玩家终端ID
     $intDeviceId = Input::get('device_id');
     // 终端ID检查
     if (!$intDeviceId || $intDeviceId == "") {
         return 'Create Error';
     }
     // 检查玩家是否已经存在
     $objPlayerCheck = Player::where('device_id', $intDeviceId)->get();
     if (!empty($objPlayerCheck->toArray())) {
         return 'Player Is Exsit';
     }
     // TODO Truncate
     DB::beginTransaction();
     // 创建玩家实例
     $objPlayer = new Player();
     $objPlayer->device_id = $intDeviceId;
     if ($objPlayer->save()) {
         // 若玩家实例创建成功,创建玩家数据
         $objPlayerData = new PlayerData();
         // 玩家数据初始化 TODO
         $objPlayerData->id = $objPlayer->id;
         $objPlayerData->code = "";
         $objPlayerData->profile = "";
         $objPlayerData->money = 500;
         $objPlayerData->stone = 50;
         if ($objPlayerData->save()) {
             // 最初的卡片赋予 TODO 初始卡片选择
             $objPlayer->appendCard(1);
             // 最初的队伍组建
             $objPlayer->firstTeam();
             // 其他初始化项目 如果有的话添加
             DB::commit();
             return Response::json($objPlayerData);
         } else {
             // 若保持失败
             DB::rollback();
             return Response::json(null);
         }
     } else {
         // 若保持失败
         DB::rollback();
         return Response::json(null);
     }
 }
 public function save($data1, $data2, $data3, $data4, $data5, $data6, $data7, $data8, $data9, $data10, $data11)
 {
     /*
                     $pass_try_max=100;
                     $pass_succeeded_max=100;
                     $shots_max=15;
                     $goals_max=5;
     */
     $nb_goals_score = $data10;
     $nb_goals_conceded = $data11;
     $player = new Player();
     $player->firstname = $data1;
     $player->name = $data2;
     $player->position = $data3;
     $player->id_team = $data4;
     $player->id_match = $data5;
     $player->shots = $data6;
     $player->goals = $data7;
     $player->pass_try = $data8;
     $player->pass_succeeded = $data9;
     if ($player->shots == 0) {
         $ratio_shots = 0;
     } else {
         $ratio_shots = $player->goals / $player->shots;
     }
     if ($player->pass_try == 0) {
         $ratio_pass = 0;
     } else {
         $ratio_pass = $player->pass_succeeded / $player->pass_try;
     }
     if ($ratio_pass > 1) {
         $pass = 1;
     }
     if ($ratio_shots > 1) {
         $shots = 1;
     }
     if ($nb_goals_score > $nb_goals_conceded) {
         $bonus_win = 1.5;
         $bonus_goal = 1;
         $bonus_defender = 1;
     }
     if ($nb_goals_score < $nb_goals_conceded) {
         $bonus_win = -1;
         $bonus_goal = -1;
         $bonus_defender = -1;
     }
     if ($nb_goals_score == $nb_goals_conceded) {
         $bonus_win = 0;
         $bonus_goal = 0;
         $bonus_defender = 0;
     }
     if ($nb_goals_conceded == 0) {
         $bonus_goal = 2;
         $bonus_defender = 2;
     }
     if ($player->position == "Forward") {
         $mark = 4 + $bonus_win + 3 * $ratio_shots + $ratio_pass;
     }
     if ($player->position == "Midfielder") {
         $mark = 4 + $bonus_win + 2 * $ratio_pass + $ratio_shots;
     }
     if ($player->position == "Defender") {
         $mark = 4 + $bonus_win + $ratio_pass + $ratio_shots + $bonus_defender;
     }
     if ($player->position == "Goalkeeper") {
         $mark = 6 + $bonus_goal;
     }
     if ($mark > 10) {
         $mark = 10;
     }
     $player->mark = round($mark, 1);
     $player->ratio_pass = $ratio_pass * 100;
     $player->ratio_shots = $ratio_shots * 100;
     $player->save();
 }
Beispiel #11
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $licence = $this->argument('licence');
     if (is_array($licence)) {
         $licence = $licence[0];
     }
     $lic = xml_licence_b($licence)->licence;
     if ($lic != '') {
         $player = Player::where('licence', $licence)->first();
         if ($player == null) {
             $player = new Player();
         }
         $player->idlicence = $lic->idlicence;
         $player->licence = $lic->licence;
         $player->nom = $lic->nom;
         $player->prenom = $lic->prenom;
         $player->numclub = $lic->numclub;
         $player->sexe = $lic->sexe;
         $player->type = $lic->type;
         $player->certif = $lic->certif;
         $player->validation = $lic->validation;
         $player->echelon = $lic->echelon;
         $player->place = $lic->place;
         $player->point = (int) $lic->point;
         $player->cat = $lic->cat;
         $player->pointm = $lic->pointm == '' ? 500 : (int) $lic->pointm;
         $player->apointm = $lic->apointm == '' ? 500 : (int) $lic->apointm;
         $player->initm = $lic->initm == '' ? 500 : (int) $lic->initm;
         $player->active = 1;
         $player->save();
         $histos = xml_histo_classement($player->licence);
         $i = 1;
         foreach ($histos as $hist) {
             $histo = RankHisto::where('player_id', $player->id)->where('id_h', $i)->first();
             if ($histo == null) {
                 $histo = new RankHisto();
             }
             $histo->id_h = $i;
             $histo->player_id = $player->id;
             $histo->echelon = $hist->echelon;
             $histo->place = $hist->place;
             $histo->point = (int) $hist->point;
             $histo->saison = $hist->saison;
             $histo->phase = (int) $hist->phase;
             $histo->save();
             $i++;
         }
         Versus::where('player_id', $player->id)->where('active', 1)->update(['active' => 0, 'saison' => date('Y') . '-' . (date('Y') - 1)]);
         $parties_mysql = xml_partie_mysql($player->licence);
         foreach ($parties_mysql as $partie) {
             $versus = Versus::where('player_id', $player->id)->where('advlicence', $partie->advlic)->where('date', $partie->date)->first();
             if ($versus == null) {
                 $versus = new Versus();
             }
             $versus->player_id = $player->id;
             $versus->licence = $partie->licence;
             $versus->advlicence = $partie->advlic;
             $versus->vd = $partie->vd;
             $versus->numjourn = $partie->numjourn;
             $versus->codechamp = $partie->codechamp;
             $versus->date = $partie->date;
             $versus->datef = substr($partie->date, 6, 2) . substr($partie->date, 3, 2) . substr($partie->date, 0, 2);
             $versus->advsexe = $partie->advsexe;
             $versus->advnompre = $partie->advnompre;
             $versus->pointres = $partie->pointres;
             $versus->coefchamp = $partie->coefchamp;
             $versus->advclaof = $partie->advclaof;
             $versus->active = 1;
             $versus->save();
         }
         $parties_mysql = xml_partie($player->licence);
         foreach ($parties_mysql as $partie) {
             $versus = Versus::where('player_id', $player->id)->where('advnompre', substr($partie->nom, 0, 24))->where('date', $partie->date)->where('vd', $partie->victoire)->first();
             if ($versus != null) {
                 $versus->epreuve = $partie->epreuve;
                 $versus->classement = $partie->classement;
                 $versus->forfait = $partie->forfait;
                 $versus->active = 1;
                 $versus->save();
             }
         }
         if ($player->photo == null) {
             $glob = glob(public_path('img/photos/licencies/' . str_slug($player->nom) . '-' . str_slug($player->prenom) . '.*'));
             if (count($glob) > 0) {
                 $image = $glob[0];
                 $player->photo = 'licencies/' . str_slug($player->nom) . '-' . str_slug($player->prenom) . '.' . pathinfo($image)['extension'];
                 $player->save();
             } else {
                 $image = public_path('img/photos/none.jpg');
             }
         } else {
             $image = public_path('img/photos/' . $player->photo);
         }
         if (file_exists($image)) {
             if (pathinfo($image)['extension'] == 'png') {
                 $jpg_image = imagecreatefrompng($image);
             } else {
                 $jpg_image = imagecreatefromjpeg($image);
             }
             $red = imagecolorallocate($jpg_image, 180, 0, 0);
             $green = imagecolorallocate($jpg_image, 0, 180, 0);
             $font_path = public_path() . '/fonts/IndieFlower.ttf';
             $points = round($player->pointm - $player->point, 0);
             if ($points >= 0) {
                 $color = $green;
                 $points = '+' . $points;
             } else {
                 $color = $red;
             }
             $imgSize = getimagesize($image)[0];
             $size = 66 * $imgSize / 300;
             $x = 130 * $imgSize / 300;
             $y = 290 * $imgSize / 300;
             imagettftext($jpg_image, $size, 10, $x, $y, $color, $font_path, $points);
             imagejpeg($jpg_image, public_path() . '/img/photos/prog-' . str_slug($player->nom) . '-' . str_slug($player->prenom) . '.jpg');
             imagedestroy($jpg_image);
         }
     } else {
         dd($licence);
     }
 }