/** * Update an rank. * Responds to requests to PATCH /rank * * @param \App\Http\Requests\RankRequest $request * @return Response */ public function update(RankRequest $request) { $currentRank1 = Rank::where('rank', 1)->first(); $currentRank2 = Rank::where('rank', 2)->first(); $currentRank3 = Rank::where('rank', 3)->first(); $currentRank4 = Rank::where('rank', 4)->first(); $currentRank1->update(['min' => $request->get('rank_1')]); $currentRank2->update(['min' => $request->get('rank_2'), 'max' => $request->get('rank_1') - 1]); $currentRank3->update(['min' => $request->get('rank_3'), 'max' => $request->get('rank_2') - 1]); $currentRank4->update(['max' => $request->get('rank_3') - 1]); return back()->with('success', 'Ranks are updated successfully!'); }
/** * Handles registration process of new volunteer. * * @param \Illuminate\Http\Request $request * @return JSON array of status */ public function addUserAccount(Request $request) { Volunteer::create(['nric' => $request->get('nric'), 'name' => $request->get('name'), 'email' => $request->get('email'), 'password' => $request->get('password'), 'gender' => $request->get('gender'), 'date_of_birth' => $request->get('dob'), 'contact_no' => $request->get('phone'), 'occupation' => $request->get('occupation'), 'has_car' => $request->get('haveCar'), 'minutes_volunteered' => '0', 'area_of_preference_1' => $request->get('preferences1'), 'area_of_preference_2' => $request->get('preferences2'), 'image_nric_front' => $request->get('frontIC'), 'image_nric_back' => $request->get('backIC'), 'rank_id' => Rank::where('min', 0)->first()->rank_id]); $volunteer = Volunteer::where('email', $request->get('email'))->first(); $mailingList = Staff::where('is_admin', 'TRUE')->lists('email')->toArray(); if ($volunteer == null) { $status = ["error"]; return response()->json(compact('status')); } else { Mail::send('emails.volunteer_registration', compact('volunteer'), function ($message) use($mailingList) { $message->subject('New Volunteer Registration'); $message->bcc($mailingList); }); $status = ["Created successfully"]; return response()->json(compact('status')); } }
/** * Persist Account to database. * * @return */ public function store(AccountRequest $request) { $steam_account = new SteamAccount(); $email_account = new EmailAccount(); $email_account->email = $request->email; $email_account->password = $request->email_password; $steam_account->create(['steam_id' => $request->steam_id, 'username' => $request->username, 'password' => $request->email_password]); $steam_account = $steam_account->where('username', $request->username)->first(); $steam_account->email_account()->save($email_account); $rank = Rank::where('rank', $request->rank)->first(); $digits = Digit::where('digits', $request->digits)->first(); if ($rank->digits()->where('digits', $request->digits) !== $request->digits) { $rank->digits()->save($digits); } $digits->steam_account()->save($steam_account); $rank->steam_account()->save($steam_account); return redirect(url('/dashboard')); }
/** * Execute the console command. * * @return mixed */ public function handle() { $liendivision = $this->argument('liendivision'); $id = $this->argument('id'); $classements = xml_result_equ('classement', $liendivision); $i = 1; foreach ($classements as $classement) { $rank = Rank::where('team_id', $id)->where('equipe', $classement->equipe)->first(); if ($rank == null) { $rank = new Rank(); } $rank->team_id = $id; $rank->clt = $classement->clt; $rank->clt_h = $i; $rank->equipe = $classement->equipe; $rank->joue = $classement->joue; $rank->pts = $classement->pts; $rank->save(); $i++; } }
/** * Deletes old player_totals table and reload everything from * scratches into it. * * @return string */ public function calculate() { \DB::table('player_totals')->truncate(); $aliases = Alias::with('players')->whereNotIn('name', DeletedPlayer::lists('player_name'))->get(); $totalServerScore = Player::sum('score'); foreach ($aliases as $alias) { $playerTotal = new PlayerTotal(); $playerTotal->name = $alias->name; $playerTotal->alias_id = $alias->id; $playerTotal->profile_id = $alias->profile_id; /*$playerTotal->last_loadout_id = $alias->profile->loadout_id;*/ $playerTotal->last_team = $alias->profile->team; //$playerTotal->first_game_id = $alias->profile->game_first; //$playerTotal->last_game_id = $alias->profile->game_last; $playerTotal->country_id = $alias->players->last()->country_id; $playersCollection = $alias->players; //Permanent Solution if ($alias->profile->loadout->kyaKhali()) { foreach ($playersCollection->reverse() as $item) { if (!$item->loadout->kyaKhali()) { $playerTotal->last_loadout_id = $item->loadout_id; break; } else { $playerTotal->last_loadout_id = $item->loadout_id; } } } else { $playerTotal->last_loadout_id = $alias->profile->loadout_id; } $playerTotal->first_game_id = $playersCollection->min('game_id'); $playerTotal->last_game_id = $playersCollection->max('game_id'); $playerTotal->is_admin = $playersCollection->max('is_admin'); $playerTotal->total_score = $playersCollection->sum('score'); $playerTotal->highest_score = $playersCollection->max('score'); $playerTotal->total_time_played = $playersCollection->sum('time_played'); $playerTotal->total_kills = $playersCollection->sum('kills'); $playerTotal->total_team_kills = $playersCollection->sum('team_kills'); $playerTotal->total_deaths = $playersCollection->sum('deaths'); $playerTotal->total_suicides = $playersCollection->sum('suicides'); $playerTotal->total_arrests = $playersCollection->sum('arrests'); $playerTotal->total_arrested = $playersCollection->sum('arrested'); $playerTotal->best_killstreak = $playersCollection->max('kill_streak'); $playerTotal->best_deathstreak = $playersCollection->max('death_streak'); $playerTotal->best_arreststreak = $playersCollection->max('arrest_streak'); $playerTotal->total_round_played = $playersCollection->unique('game_id')->count('game_id'); $playerTotal->last_ip_address = $alias->ip_address; $playerTotal->killdeath_ratio = $playerTotal->total_deaths == 0 ? $playerTotal->total_kills : round($playerTotal->total_kills / $playerTotal->total_deaths, 2); $playerTotal->arr_ratio = $playerTotal->total_arrested == 0 ? $playerTotal->total_arrests : round($playerTotal->total_arrests / $playerTotal->total_arrested, 2); $playerTotal->score_per_min = $playerTotal->total_time_played == 0 ? $playerTotal->total_score : round($playerTotal->total_score / $playerTotal->total_time_played * 60, 2); $playerTotal->score_percentile = $playerTotal->total_score == 0 || $totalServerScore == 0 ? 0 : round($playerTotal->total_score / $totalServerScore * 100, 2); $won = 0; $lost = 0; $draw = 0; foreach ($playersCollection->unique('game_id') as $player) { switch ($player->game->isWinner($player->team)) { case 0: $lost++; break; case 1: $won++; break; case -1: $draw++; break; default: break; } } $playerTotal->game_won = $won; $playerTotal->game_lost = $lost; $playerTotal->game_draw = $draw; $playerTotal->total_points = max($playerTotal->total_kills * 4 + $playerTotal->total_arrests * 13 - $playerTotal->total_deaths - $playerTotal->total_arrested * 3 - $playerTotal->total_team_kills * 2, 0); /** * This give extra points to the player from PlayerPoints Model */ $playerPoints = PlayerPoint::where('name', $playerTotal->name)->get(); if (!$playerPoints->isEmpty()) { $pointsToGive = $playerPoints->sum('points'); $playerTotal->total_points += $pointsToGive; } /** * Calculation of player_rating * * Calculate only if player with this alias has played more than 10 hours in server * and also is active and seen in last 7 days */ $last_seen_game = Game::find($playerTotal->last_game_id); if ($playerTotal->total_time_played > 60 * 60 * 10 && \Carbon\Carbon::now()->timestamp - $last_seen_game->updated_at->timestamp <= 60 * 60 * 24 * 7) { $playerTotal->player_rating = max($playerTotal->killdeath_ratio + $playerTotal->arr_ratio + $playerTotal->score_per_min * 1.25, 0); $playerTotal->player_rating = min($playerTotal->player_rating, 10); } /** * Calculation of rank_id using total_points and Rank table * * Add this if want time played(rank_seconds) also used to calculate ranks * ->where('rank_seconds', '<=' ,$playerTotal->total_time_played) * * Make sure that there are ranks in ranks table if not, * Run php artisan db:seed */ $playerTotal->rank_id = Rank::where('rank_points', '>=', $playerTotal->total_points)->orderBy('rank_points')->first()->id; $playerTotal->save(); } /** * Getting all PlayerTotal and updating its position one by one. */ $pTs = PlayerTotal::orderBy('player_rating', 'DESC')->orderBy('total_points', 'DESC')->orderBy('total_score', 'DESC')->get(); $position = 0; foreach ($pTs as $pT) { $pT->position = ++$position; $pT->save(); } // Put to Top Player so that some bugs are fixed. $topPlayers = PlayerTotal::with(['country', 'rank'])->orderBy('position')->limit(10)->get(); Cache::put('top_players', $topPlayers, 31); return "Players total has been logged into player_total table successfully!"; }
/** * Handles the status updates through activity. If completed, compute points and add points to user. * * @param \Illuminate\Http\Request $request * @return JSON array with Status */ public function updateActivityStatus(Request $request) { if ($request->get('volunteer_id') == null || $request->get('activity_id') == null || $request->get('status') == null) { $status = ["Missing parameter"]; return response()->json(compact('status')); } else { $volunteer_id = $request->get('volunteer_id'); $activity_id = $request->get('activity_id'); $status = $request->get('status'); $task = Task::where('volunteer_id', $volunteer_id)->where('activity_id', $activity_id)->update(['status' => $status]); if ($status == "completed") { $activity = Activity::findOrFail($activity_id); $timeToAdd = $activity->expected_duration_minutes; $volunteer = Volunteer::findOrFail($volunteer_id); $currentTime = $volunteer->minutes_volunteered; $volunteer->minutes_volunteered = $timeToAdd + $currentTime; $newTime = floor($volunteer->minutes_volunteered / 60); if ($newTime > 0) { $newRank = Rank::where('min', '<', $newTime)->value('rank_id'); $volunteer->rank_id = $newRank; } $volunteer->save(); } $status = ["Update Successful"]; return response()->json(compact('status')); } }
return view('welcome'); }); Route::get('/push', function () { $devices = \App\Device::all(); foreach ($devices as $device) { \Davibennun\LaravelPushNotification\Facades\PushNotification::app('appNameIOS')->to($device->token)->send('Hello World, i`m a push message'); } echo 'pushed'; }); Route::get('/categories', function () { $categories = \App\Category::all(); return view('categories.index', compact('categories')); }); Route::get('/categories/{categoryId}', function ($categoryId) { $category = \App\Category::find($categoryId); $ranks = \App\Rank::where('category_id', '=', $categoryId)->with('place')->get(); $lat = 48.83213; $lon = 2.3218; $radius = 3; $places = \App\Place::select(DB::raw("*, (6371 * acos( cos( radians({$lat}) ) * cos( radians( latitude ) ) * cos( radians( {$lon} ) - radians(longitude) ) + sin( radians({$lat}) ) * sin( radians(latitude) ) )) AS distance"))->orderby('distance', 'asc')->whereHas('ranks', function ($query) use($categoryId) { $query->where('category_id', '=', $categoryId); })->with('ranks', 'ranks.category')->get(); return view('categories.show', compact('category', 'places')); }); Route::get('/nearby', function () { // -27.49611, 153.00207 -> brisbane $lat = 48.842147; $lon = 2.321984; $radius = 3; $places = \App\Place::select(DB::raw("*, (6371 * acos( cos( radians({$lat}) ) * cos( radians( latitude ) ) * cos( radians( {$lon} ) - radians(longitude) ) + sin( radians({$lat}) ) * sin( radians(latitude) ) )) AS distance"))->having('distance', '<', $radius)->orderby('distance', 'asc')->with('ranks', 'ranks.category')->get(); return view('places.index', compact('places'));