Inheritance: extends Illuminate\Database\Eloquent\Model
 /**
  * 
  * @param string $playerName
  * @return type
  */
 public function showName($playerName)
 {
     $sorties = $this->sortieService->getForPlayer($playerName);
     try {
         $player = Player::with(['groupedAwards'])->where('playerName', $playerName)->firstOrFail();
     } catch (ModelNotFoundException $exception) {
         // If we can't find that player, but there are sorties available
         // for them, create a new record for them
         $player = new Player();
         $player->playerName = $playerName;
         $player->isActive = true;
         $player->save();
     }
     return view('player.show')->with('player', $player)->with('sorties', $sorties)->with('activity1', $this->generateActivity(1))->with('activity2', $this->generateActivity(2))->with('activity3', $this->generateActivity(3));
 }
 /**
  * Tests if the remove function works correctly.
  */
 public function testRepoRemovePlayerSuccessRemoval()
 {
     $player = Factory::create('App\\Models\\Player');
     $success = $this->repository->removePlayer($player->nickname);
     $this->assertTrue($success);
     $this->assertNull(Player::find($player->id));
 }
Exemplo n.º 3
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = Player::findByMail($this->email);
     }
     return $this->_user;
 }
Exemplo n.º 4
0
 public function edit(Game $game)
 {
     $team = Team::find(config('mls.team_id'));
     $playerList = Player::where('team_id', $team->id)->get();
     $visitMap = ['' => ''] + Stat::$visitList;
     $visitList = StatRepository::getActiveVisitsForGame($game->id);
     $visitList = $visitList->lists(Stat::VISIT, 'player_id');
     return view('backend.visits.edit')->with('playerList', $playerList)->with('visitList', $visitList)->with('visitMap', $visitMap)->with('game', $game);
 }
 public function edit(Training $training)
 {
     $team = Team::find(config('mls.team_id'));
     $playerList = Player::where('team_id', $team->id)->get();
     $visitMap = ['' => ''] + Stat::$visitList;
     $visitList = TrainingVisitRepository::getActiveTrainingVisits($training->id);
     $visitList = $visitList->lists('visit', 'player_id');
     return view('backend.training_visits.edit')->with('playerList', $playerList)->with('visitList', $visitList)->with('training', $training)->with('visitMap', $visitMap);
 }
Exemplo n.º 6
0
 public function getAttack($playerHash, $countryIdFrom, $countryIdTo)
 {
     $from = Country::find($countryIdFrom);
     /** @var $from Country */
     $to = Country::find($countryIdTo);
     $player = Player::getByHash($playerHash);
     if ($from->isOwnedBy($player)) {
         Action::attack($from, $to);
     }
 }
Exemplo n.º 7
0
 private function performPlayerMailSearch($player_mail)
 {
     if (empty($player_mail)) {
         return array();
     }
     if ($player = \app\models\Player::findByMail($player_mail)) {
         return $player->teams;
     }
     return array();
 }
Exemplo n.º 8
0
 public static function checkTextureOccupied($tid)
 {
     $skin_type_map = ["steve", "alex", "cape"];
     for ($i = 0; $i <= 2; $i++) {
         if (Player::where('tid_' . $skin_type_map[$i], $tid)->count() > 0) {
             return true;
         }
     }
     return false;
 }
Exemplo n.º 9
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     // $this->call(UserTableSeeder::class);
     $field = Field::create();
     for ($i = 0; $i < Config::get('settings.players'); $i++) {
         $player = Player::create();
         $field->addPlayer($player);
     }
     Model::reguard();
 }
Exemplo n.º 10
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     // Read the database of allied awards
     $csv = Reader::createFromPath(storage_path('app/csv/issued_allied_awards.csv'));
     // This will read the CSV as set of data into the listed array keys
     $data = $csv->fetchAssoc(['playerName', 'playerLabel', 'awardName', 'campaign_id', 'awardedAt', 'submitterName', 'cincName', 'forumSource'], function ($row) {
         // manipulate the incoming data as it is read. This is turn it into
         // a set of data which can be immediately added to our awards table
         $drow = [];
         $drow['playerName'] = trim(strtolower($row[1]));
         $drow['playerLabel'] = trim($row[1]);
         // case as it appears in csv
         $drow['awardName'] = snake_case(strtolower(trim($row[2])));
         $drow['campaign_id'] = trim($row[3]) == '' ? null : trim($row[3]);
         $drow['awardedAt'] = trim($row[6]);
         $drow['submitterName'] = trim(strtolower($row[7]));
         $drow['cincName'] = trim(strtolower($row[8]));
         $drow['forumSource'] = trim(strtolower($row[9]));
         return $drow;
     });
     Player::unguard();
     foreach ($data as $item) {
         $award = Award::where('key', $item['awardName'])->first();
         if ($award == null) {
             Log::info(sprintf('Could not find an award with key %s', $item['awardName']));
             continue;
         }
         $submitter = Player::where('playerName', $item['submitterName'])->first();
         if ($submitter == null) {
             $submitter = Player::create(['playerName' => $item['submitterName'], 'isActive' => true]);
         }
         $cinc = Player::where('playerName', $item['cincName'])->first();
         if ($cinc == null) {
             $cinc = Player::create(['playerName' => $item['cincName'], 'isActive' => true]);
         }
         // check the rype of award we are presenting. If it's a squad award, find the squad and apply it
         // also, if there is a space in the name, its not a player name
         if ($award->awardedTo == 'squad' || preg_match('/\\s/', $item['playerName']) > 0) {
             $squad = Squad::where('key', snake_case($item['playerName']))->first();
             if ($squad == null) {
                 $squad = Squad::create(['key' => snake_case($item['playerName']), 'label' => $item['playerLabel'], 'isActive' => true]);
             }
             $squad->awards()->save($award, ['awardedBy_id' => $submitter->id, 'cinc_id' => $cinc->id, 'campaign_id' => $item['campaign_id'], 'awardedAt' => Carbon\Carbon::createFromFormat('d/m/Y', $item['awardedAt']), 'forumLink' => $item['forumSource']]);
         } else {
             $player = Player::where('playerName', $item['playerName'])->first();
             if ($player == null) {
                 $player = Player::create(['playerName' => $item['playerName'], 'isActive' => true]);
             }
             $player->awards()->save($award, ['awardedBy_id' => $submitter->id, 'cinc_id' => $cinc->id, 'campaign_id' => $item['campaign_id'], 'awardedAt' => Carbon\Carbon::createFromFormat('d/m/Y', $item['awardedAt']), 'forumLink' => $item['forumSource']]);
         }
     }
     Player::reguard();
 }
Exemplo n.º 11
0
 public function run()
 {
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     //DB::table('team_user')->truncate();
     DB::table('players')->truncate();
     $faker = Faker::create();
     $teams = Db::table('teams')->lists('id');
     foreach (range(1, 100) as $key => $value) {
         $team = Player::create(['fname' => $faker->firstName(), 'lname' => $faker->lastName(), 'number' => $faker->numberBetween($min = 4, $max = 15), 'email' => $faker->email(), 'birthday' => $faker->date($format = 'Y-m-d', $max = 'now'), 'team_id' => $faker->randomElement($teams)]);
         //$team->users()->sync([$faker->randomElement($users)]) ;
     }
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
 }
 public static function saveQuickVisits($request)
 {
     if (!Training::find($request->get('training_id'))) {
         return;
     }
     self::removeVisits($request->get('training_id'));
     foreach ($request->all() as $key => $input) {
         if (strpos($key, 'player_') !== false && $input > 0) {
             $id = str_replace('player_', '', $key);
             if (Player::find($id)) {
                 self::addVisit($request->get('training_id'), $id, $input);
             }
         }
     }
 }
Exemplo n.º 13
0
 /**
  * Handle the event.
  *
  * @param  TrainingVisitChange $event
  * @return void
  */
 public function handle(TrainingVisitChange $event)
 {
     $player = Player::find($event->playerId);
     $training = Training::find($event->trainingId);
     $users = \App\Models\User::whereNotNull('email')->where('email', '!=', '')->get();
     $status = $event->visit;
     $visitList = TrainingVisit::getVisitList();
     $subject = trans('email.training.subject') . ' ' . str_limit($player->name, 10) . ' ' . str_limit($training->name, 10) . ' ' . $visitList[$status];
     Mail::send('emails.training_visit', ['player' => $player, 'training' => $training, 'status' => $status], function ($m) use($users, $subject) {
         foreach ($users as $user) {
             if ($user->isAdmin()) {
                 $m->to($user->email);
             }
         }
         $m->subject($subject);
     });
 }
Exemplo n.º 14
0
 public function actionFindByAgent($agent = null, $id = null)
 {
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $out = ['results' => ['id' => '', 'text' => '']];
     if (!is_null($agent)) {
         $data = Player::find()->byAgent($agent)->all();
         $out['results'] = array_map(function ($item) {
             /**
              * @var $item Player
              */
             return ['id' => $item->id, 'text' => $item->agentId];
         }, $data);
     } elseif ($id > 0) {
         $out['results'] = ['id' => $id, 'text' => Player::findOne($id)->agentId];
     }
     return $out;
 }
 /**
  * Get a user from repository and cache it.
  *
  * @param  string  $identification
  * @param  string  $type
  * @return mixed
  */
 public function get($identification, $type = 'uid')
 {
     if (!$this->has($identification, $type)) {
         if ($type == "username") {
             $player = Player::where('player_name', $identification)->first();
             if ($player) {
                 $identification = $player->uid;
                 $type = "uid";
             } else {
                 return null;
             }
         }
         $user = User::where($type, $identification)->first();
         if ($user) {
             $this->set($user->uid, $user);
             return $user;
         }
     }
     return Arr::get($this->items, $identification, null);
 }
Exemplo n.º 16
0
 /**
  * Handle the event.
  *
  * @param  GameVisitChange  $event
  * @return void
  */
 public function handle(GameVisitChange $event)
 {
     $player = Player::find($event->playerId);
     $game = Game::find($event->gameId);
     $users = \App\Models\User::whereNotNull('email')->where('email', '!=', '')->get();
     $visitList = Stat::$visitList;
     if (isset($event->visit) && $event->visit) {
         $status = $visitList[$event->visit];
     } else {
         $status = 'Cancelled';
     }
     $subject = str_limit($player->name, 50) . ' ' . str_limit($game->team, 20) . ' ' . $status;
     Mail::send('emails.game_visit', ['player' => $player, 'game' => $game, 'status' => $status], function ($m) use($users, $subject) {
         foreach ($users as $user) {
             if ($user->isAdmin()) {
                 $m->to($user->email);
             }
         }
         $m->subject($subject);
     });
 }
 public function handle($request, \Closure $next)
 {
     if (stripos($request->getUri(), '.json') != false) {
         preg_match('/\\/([^\\/]*)\\.json/', $request->getUri(), $matches);
     } else {
         preg_match('/\\/([^\\/]*)\\.png/', $request->getUri(), $matches);
     }
     $player_name = urldecode($matches[1]);
     $responses = Event::fire(new CheckPlayerExists($player_name));
     foreach ($responses as $r) {
         if ($r) {
             return $next($request);
         }
     }
     if (!Player::where('player_name', $player_name)->get()->isEmpty()) {
         return $next($request);
     }
     if (option('return_200_when_notfound')) {
         return json(['player_name' => $player_name, 'errno' => 404, 'msg' => 'Player Not Found.'])->header('Cache-Control', 'public, max-age=' . option('cache_expire_time'));
     } else {
         abort(404, trans('general.unexistent-player'));
     }
 }
Exemplo n.º 18
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRes8Owner()
 {
     return $this->hasOne(Player::className(), ['id' => 'res8OwnerId'])->from(Player::tableName() . ' pro8');
 }
 /**
  * Removes the specified player.
  *
  * @param str $nickname
  *
  * @throws ModelNotFoundException
  *
  * @return bool
  */
 public function removePlayer($nickname)
 {
     return Player::where('nickname', $nickname)->firstOrFail()->delete();
 }
Exemplo n.º 20
0
 function getPlayers()
 {
     $players = Player::leftJoin('player_positions', 'players.id', '=', 'player_positions.player_id')->leftJoin('positions', 'positions.id', '=', 'player_positions.position_id')->selectRaw('players.id, players.mlb_id, players.name, players.batter_hand, players.pitcher_hand, group_concat(ifnull(positions.abbr, \'P\') order by positions.id) positions')->groupBy('players.id')->get();
     return $players;
 }
Exemplo n.º 21
0
 public function testByAgent()
 {
     $this->assertCount(1, Player::find()->byAgent('foo')->all());
 }
Exemplo n.º 22
0
 public function update(Player $player, PlayerRequest $request)
 {
     $player->update($request->all());
     Flash::success(trans('general.updated_msg'));
     return redirect(route('admin.players'));
 }
 private function getPlayerInstance($player_name)
 {
     $player = Player::where('player_name', $player_name)->first();
     if (!$player) {
         abort(404, '角色不存在');
     }
     if ($player->isBanned()) {
         abort(404, '该角色拥有者已被本站封禁。');
     }
     return $player;
 }
Exemplo n.º 24
0
 /**
  * mark players psence on the game
  * @return int|void
  * @throws \yii\db\Exception
  */
 private function managePlayersPresence()
 {
     if ($this->isNewRecord) {
         return;
     }
     if ($player = Player::findIdentity($this->join_player)) {
         $presence = 1;
     } elseif ($player = Player::findIdentity($this->reject_player)) {
         $presence = 0;
     } else {
         return;
     }
     $sql = "INSERT INTO `game_has_player` (`game_id`, `player_id`, `presence`)\n                VALUES ('{$this->id}', '{$player->id}', '{$presence}')\n                ON DUPLICATE KEY UPDATE `presence` = '{$presence}'";
     return Yii::$app->db->createCommand($sql)->execute();
 }
Exemplo n.º 25
0
 public function edit(Stat $stat)
 {
     return view('backend.stats.edit')->with('stat', $stat)->with('gameList', Game::lists('team', 'id'))->with('playerList', Player::lists('name', 'id'))->with('parameterList', Stat::getParameterList());
 }
Exemplo n.º 26
0
 private function reformatStats(array $stats)
 {
     $formated = [];
     foreach ($stats as $stat) {
         $player = Player::where('name', 'like', '%' . $stat['player'] . '%')->first();
         if (!$player || empty($stat['player'])) {
             continue;
         }
         if (isset($formated[$stat['parameter']][$player->id])) {
             $formated[$stat['parameter']][$player->id]['value']++;
         } else {
             $formated[$stat['parameter']][$player->id] = ['value' => 1, 'player_id' => $player->id, 'parameter' => $stat['parameter']];
         }
     }
     $result = [];
     foreach ($formated as $subarr) {
         foreach ($subarr as $arr) {
             array_push($result, $arr);
         }
     }
     return $result;
 }
 public function setPreference(Request $request)
 {
     $this->validate($request, ['preference' => 'required|preference']);
     $this->player->setPreference($request->preference);
     return json(trans('user.player.preference.success', ['name' => $this->player->player_name, 'preference' => $request->preference]), 0);
 }
Exemplo n.º 28
0
 /**
  * When team is updated, link/unlink players with team
  */
 private function manageTeamMembers()
 {
     if ($this->isNewRecord) {
         return;
     }
     if ($player = Player::findByMail($this->join_player)) {
         $this->link('players', $player);
     }
     if ($player = Player::findByMail($this->remove_player)) {
         $this->unlink('players', $player, true);
     }
 }
Exemplo n.º 29
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $this->startLog();
     $team = Team::find(self::TEAM_ID);
     if ($team == null) {
         $this->error('Team with id: ' . self::TEAM_ID . ' not found');
         exit;
     }
     $html = new Htmldom($team->link);
     $team_table = $html->find('table.team-list', 0);
     if ($team_table == null) {
         $this->error('Team table not found on this page: ' . $team->link);
         exit;
     }
     $player_links = [];
     foreach ($team_table->find('p.player-name a') as $link) {
         if (isset($link->href)) {
             array_push($player_links, $link->href);
         }
     }
     if (count($player_links) < 1) {
         $this->error('No players found');
         exit;
     }
     $this->comment('Found players: ' . count($player_links));
     $bar = $this->output->createProgressBar(count($player_links));
     foreach ($player_links as $link) {
         if (strpos($link, self::DOMAIN) === false) {
             $link = self::DOMAIN . $link;
         }
         $player = new Player();
         $player->team_id = self::TEAM_ID;
         $player->mls_id = $this->parseIdFromUrl($link);
         $player_html = new Htmldom($link);
         if ($player_html == null) {
             continue;
         }
         $player_table = $player_html->find('table.adf-fields-table', 0);
         if ($player_table == null) {
             continue;
         }
         foreach ($player_table->find('tr') as $row) {
             $td1 = $row->find('td', 0);
             $td2 = $row->find('td', 1);
             if ($td1 != null && strpos($td1->innertext, 'Полное имя') !== false) {
                 $player->name = $td2->plaintext;
             }
             if ($td1 != null && strpos($td1->innertext, 'Дата рождения') !== false) {
                 $player->date_of_birth = Carbon::parse($td2->plaintext);
             }
         }
         $check_player = Player::where('mls_id', $player->mls_id)->where('name', $player->name)->where('team_id', $player->team_id)->where('date_of_birth', $player->date_of_birth)->first();
         if ($check_player) {
             $player->id = $check_player->id;
             $player->update();
         } else {
             $player->save();
         }
         $img = $player_html->find('div#etab_player_div div.gray-box img', 0);
         if ($img != null && $img->src != null && strpos($img->src, self::DEFAULT_IMG) === false) {
             $src = $img->src;
             if (strpos($src, self::DOMAIN) === false) {
                 $src = self::DOMAIN . $src;
             }
             copy($src, public_path() . '/img/avatars/players/' . $player->id . '.jpg');
         }
         $bar->advance();
     }
     $bar->finish();
     $this->endLog();
 }
Exemplo n.º 30
0
 public function getPlayer(Player $playerModel, $resultNames)
 {
     return $playerModel->whereIn('name', $resultNames)->get();
 }