Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Http\Request;
- use App\Product;
- use App\League;
- use App\Match;
- class HomeController extends Controller
- {
- /**
- * Create a new controller instance.
- *
- * @return void
- */
- public function __construct()
- {
- $this->middleware('auth', ['except' => ['index', 'csgoindex', 'sportsindex', 'dota2index', 'allmatches','showMoreMatches', 'showCsgoMatches', 'showDotaMatches', 'showSportsMatches', 'displayItemMarket']]);
- }
- /**
- * Show the application dashboard.
- *
- * @return \Illuminate\Http\Response
- */
- public function index()
- {
- $leagues = \App\League::active()->orderby('leagues.status','desc')->orderBy('created_at','desc')->get()->load('teams.bets');
- $_matches = \App\Match::mainMatches()->get()->load('teamA', 'teamB')->sortByDesc('schedule');
- $liveList = collect();
- $openList = collect();
- $oldList = collect();
- foreach ($_matches as $_m) {
- if ($_m->schedule->isFuture()) {
- if($_m->status == 'ongoing')
- $liveList->push($_m);
- else if($_m->status == 'open')
- $openList->push($_m);
- else
- $oldList->push($_m);
- } else {
- if ($_m->status == 'ongoing')
- $liveList->push($_m);
- else if($_m->status == 'open')
- $openList->push($_m);
- else
- $oldList->push($_m);
- }
- }
- $_liveList = $liveList->sortBy('schedule');
- $matches = $_liveList->merge($openList->sortBy('schedule'));
- $allresult = \App\Match::mainMatches()->whereIn('matches.status',['open','ongoing'])->first();
- return view('home', compact('teams', 'matches', 'allresult', 'leagues'));
- }
- //All matches index
- public function allmatches()
- {
- $leagues = \App\League::active()->orderby('leagues.status','desc')->orderBy('created_at','desc')->get()->load('teams.bets');
- $_matches = \App\Match::mainMatches()->get()->load('teamA', 'teamB')->sortByDesc('schedule');
- $liveList = collect();
- $openList = collect();
- $oldList = collect();
- foreach ($_matches as $_m) {
- if ($_m->schedule->isFuture()) {
- if($_m->status == 'ongoing')
- $liveList->push($_m);
- else if($_m->status == 'open')
- $openList->push($_m);
- else
- $oldList->push($_m);
- } else {
- if ($_m->status == 'ongoing')
- $liveList->push($_m);
- else if($_m->status == 'open')
- $openList->push($_m);
- else
- $oldList->push($_m);
- }
- }
- $_liveList = $liveList->sortBy('schedule');
- $matches = $_liveList->merge($openList->sortBy('schedule'));
- $allresult = \App\Match::mainMatches()->whereIn('matches.status',['open','ongoing'])->first();
- return view('allmatch', compact('teams', 'matches', 'allresult', 'leagues'));
- }
- //added dota2index
- public function dota2index()
- {
- $leagues = \App\League::active()->orderby('leagues.status','desc')->orderBy('created_at','desc')->get()->load('teams.bets');
- $_matches = \App\Match::mainMatches()->where('leagues.type','=','dota2')->get()->load('teamA', 'teamB')->sortByDesc('schedule');
- $liveList = collect();
- $openList = collect();
- $oldList = collect();
- foreach ($_matches as $_m) {
- if ($_m->schedule->isFuture()) {
- if($_m->status == 'ongoing')
- $liveList->push($_m);
- else if($_m->status == 'open')
- $openList->push($_m);
- else
- $oldList->push($_m);
- } else {
- if ($_m->status == 'ongoing')
- $liveList->push($_m);
- else if($_m->status == 'open')
- $openList->push($_m);
- else
- $oldList->push($_m);
- }
- }
- $_liveList = $liveList->sortBy('schedule');
- $dotamatches = $_liveList->merge($openList->sortBy('schedule'));
- $dotaresult = \App\Match::mainMatches()->where('leagues.type','=','dota2')->whereIn('matches.status',['open','ongoing'])->first();
- return view('dota2', compact('teams', 'dotamatches', 'dotaresult','leagues'));
- }
- //added csgo index tab
- public function csgoindex()
- {
- $leagues = \App\League::active()->orderby('leagues.status','desc')->orderBy('created_at','desc')->get()->load('teams.bets');
- $_matches = \App\Match::mainMatches()->where('leagues.type','=','csgo')->get()->load('teamA', 'teamB')->sortByDesc('schedule');
- $liveList = collect();
- $openList = collect();
- $oldList = collect();
- foreach ($_matches as $_m) {
- if ($_m->schedule->isFuture()) {
- if($_m->status == 'ongoing')
- $liveList->push($_m);
- else if($_m->status == 'open')
- $openList->push($_m);
- else
- $oldList->push($_m);
- } else {
- if ($_m->status == 'ongoing')
- $liveList->push($_m);
- else if($_m->status == 'open')
- $openList->push($_m);
- else
- $oldList->push($_m);
- }
- }
- $_liveList = $liveList->sortBy('schedule');
- $csgomatches = $_liveList->merge($openList->sortBy('schedule'));
- $csgoresult = \App\Match::mainMatches()->where('leagues.type','=','csgo')->whereIn('matches.status',['open','ongoing'])->first();
- return view('csgo', compact('teams', 'csgomatches', 'csgoresult', 'leagues'));
- }
- //added sports tab index
- public function sportsindex()
- {
- $leagues = \App\League::active()->orderby('status','desc')->orderBy('created_at','desc')->get()->load('teams.bets');
- $_matches = \App\Match::mainMatches()->whereIn('leagues.type',['pba','nba','boxing','mma','fifa','mpbl','soccer','volleyball','football','uaap','sports','basketball'])->get()->load('teamA', 'teamB')->sortByDesc('schedule');
- $liveList = collect();
- $openList = collect();
- $oldList = collect();
- foreach ($_matches as $_m) {
- if ($_m->schedule->isFuture()) {
- if($_m->status == 'ongoing')
- $liveList->push($_m);
- else if($_m->status == 'open')
- $openList->push($_m);
- else
- $oldList->push($_m);
- } else {
- if ($_m->status == 'ongoing')
- $liveList->push($_m);
- else if($_m->status == 'open')
- $openList->push($_m);
- else
- $oldList->push($_m);
- }
- }
- $_liveList = $liveList->sortBy('schedule');
- $sportsmatches = $_liveList->merge($openList->sortBy('schedule'));
- $sportsresult = \App\Match::mainMatches()->whereIn('leagues.type',['pba','nba','boxing','mma','fifa','mpbl','soccer','volleyball','football','uaap','sports','basketball'])
- ->whereIn('matches.status',['open','ongoing'])->first();
- return view('sports', compact('teams', 'sportsmatches', 'sportsresult','leagues'));
- }
- public function showMoreMatches($ptr) {
- $_matches = \App\Match::mainMatches()
- ->whereNotIn('matches.status', ['ongoing', 'open'])
- ->get()->load('league', 'teamA', 'teamB')
- ->sortByDesc('schedule')
- ->slice($ptr, 10);
- $currList = collect();
- $oldList = collect();
- foreach ($_matches as $index => $_m) {
- $_matches[$index]->team_a_winPercentage = number_format(matchWinPercentagePerTeam($_m->id, $_m->teamA->id), 2);
- $_matches[$index]->team_b_winPercentage = number_format(matchWinPercentagePerTeam($_m->id, $_m->teamB->id), 2);
- $_matches[$index]->match_sched = $_m->schedule->diffForHumans();
- unset($_matches[$index]->fee);
- switch($_m->status) {
- case 'open':
- $_matches[$index]->is_current = true;
- $_matches[$index]->status = '';
- case 'ongoing':
- $_matches[$index]->is_current = true;
- $_matches[$index]->status = $_m->schedule->diffForHumans() .
- ' <span style="color: #72A326; text-shadow: 1px 1px 0px #4A7010; font-weight: bold; font-size: 16px"> LIVE</span>';
- break;
- case 'settled':
- $_matches[$index]->is_current = false;
- $_matches[$index]->status = $_m->schedule->diffForHumans() .
- ' <span style="color: #606060; font-weight: bold; font-size: 16px"> SETTLED</span>';
- $_matches[$index]->team_a_winner = ($_m->teamA->id == $_m->team_winner);
- $_matches[$index]->team_b_winner = ($_m->teamB->id == $_m->team_winner);
- break;
- case 'draw':
- $_matches[$index]->is_current = false;
- $_matches[$index]->status = $_m->schedule->diffForHumans() .
- ' <span style="color: #606060; font-weight: bold; font-size: 16px"> DRAW - CREDITS RETURNED</span>';
- break;
- case 'cancelled':
- $_matches[$index]->is_current = false;
- $_matches[$index]->status = $_m->schedule->diffForHumans() .
- ' <span style="color: #606060; font-weight: bold; font-size: 16px"> CANCELLED</span>';
- break;
- default:
- $_matches[$index]->is_current = false;
- $_matches[$index]->status = '';
- break;
- }
- $oldList->push($_m);
- }
- return [
- 'matches' => $oldList,
- 'pointer' => $ptr += 10
- ];
- }
- public function showDotaMatches2($ptr){
- $_matches = \App\Match::mainMatches()->where('leagues.type','=','dota2')
- ->whereIn('matches.status', ['ongoing', 'open'])
- ->get()->load('league', 'teamA', 'teamB')
- ->sortByDesc('schedule')
- ->slice($ptr);
- $currList = collect();
- $oldList = collect();
- foreach ($_matches as $index => $_m) {
- $_matches[$index]->team_a_winPercentage = number_format(matchWinPercentagePerTeam($_m->id, $_m->teamA->id), 2);
- $_matches[$index]->team_b_winPercentage = number_format(matchWinPercentagePerTeam($_m->id, $_m->teamB->id), 2);
- $_matches[$index]->match_sched = $_m->schedule->diffForHumans();
- unset($_matches[$index]->fee);
- switch($_m->status) {
- case 'open':
- $_matches[$index]->is_current = true;
- $_matches[$index]->status = '';
- case 'ongoing':
- $_matches[$index]->is_current = true;
- $_matches[$index]->status = $_m->schedule->diffForHumans() .
- ' <span style="color: #72A326; text-shadow: 1px 1px 0px #4A7010; font-weight: bold; font-size: 16px"> LIVE</span>';
- break;
- case 'settled':
- $_matches[$index]->is_current = false;
- $_matches[$index]->status = $_m->schedule->diffForHumans() .
- ' <span style="color: #606060; font-weight: bold; font-size: 16px"> SETTLED</span>';
- $_matches[$index]->team_a_winner = ($_m->teamA->id == $_m->team_winner);
- $_matches[$index]->team_b_winner = ($_m->teamB->id == $_m->team_winner);
- break;
- case 'draw':
- $_matches[$index]->is_current = false;
- $_matches[$index]->status = $_m->schedule->diffForHumans() .
- ' <span style="color: #606060; font-weight: bold; font-size: 16px"> DRAW - CREDITS RETURNED</span>';
- break;
- case 'cancelled':
- $_matches[$index]->is_current = false;
- $_matches[$index]->status = $_m->schedule->diffForHumans() .
- ' <span style="color: #606060; font-weight: bold; font-size: 16px"> CANCELLED</span>';
- break;
- default:
- $_matches[$index]->is_current = false;
- $_matches[$index]->status = '';
- break;
- }
- $oldList->push($_m);
- }
- return [
- 'matches' => $oldList,
- 'pointer' => $ptr += 0
- ];
- }
- //show more dotamatches
- public function showDotaMatches($ptr){
- $_matches = \App\Match::mainMatches()->where('leagues.type','=','dota2')
- ->whereNotIn('matches.status', ['ongoing', 'open'])
- ->get()->load('league', 'teamA', 'teamB')
- ->sortByDesc('schedule')
- ->slice($ptr, 10);
- $currList = collect();
- $oldList = collect();
- foreach ($_matches as $index => $_m) {
- $_matches[$index]->team_a_winPercentage = number_format(matchWinPercentagePerTeam($_m->id, $_m->teamA->id), 2);
- $_matches[$index]->team_b_winPercentage = number_format(matchWinPercentagePerTeam($_m->id, $_m->teamB->id), 2);
- $_matches[$index]->match_sched = $_m->schedule->diffForHumans();
- unset($_matches[$index]->fee);
- switch($_m->status) {
- case 'open':
- $_matches[$index]->is_current = true;
- $_matches[$index]->status = '';
- case 'ongoing':
- $_matches[$index]->is_current = true;
- $_matches[$index]->status = $_m->schedule->diffForHumans() .
- ' <span style="color: #72A326; text-shadow: 1px 1px 0px #4A7010; font-weight: bold; font-size: 16px"> LIVE</span>';
- break;
- case 'settled':
- $_matches[$index]->is_current = false;
- $_matches[$index]->status = $_m->schedule->diffForHumans() .
- ' <span style="color: #606060; font-weight: bold; font-size: 16px"> SETTLED</span>';
- $_matches[$index]->team_a_winner = ($_m->teamA->id == $_m->team_winner);
- $_matches[$index]->team_b_winner = ($_m->teamB->id == $_m->team_winner);
- break;
- case 'draw':
- $_matches[$index]->is_current = false;
- $_matches[$index]->status = $_m->schedule->diffForHumans() .
- ' <span style="color: #606060; font-weight: bold; font-size: 16px"> DRAW - CREDITS RETURNED</span>';
- break;
- case 'cancelled':
- $_matches[$index]->is_current = false;
- $_matches[$index]->status = $_m->schedule->diffForHumans() .
- ' <span style="color: #606060; font-weight: bold; font-size: 16px"> CANCELLED</span>';
- break;
- default:
- $_matches[$index]->is_current = false;
- $_matches[$index]->status = '';
- break;
- }
- $oldList->push($_m);
- }
- return [
- 'matches' => $oldList,
- 'pointer' => $ptr += 10
- ];
- }
- //show more csgo matches
- public function showCsgoMatches($ptr) {
- $_matches = \App\Match::mainMatches()->where('leagues.type','=','csgo')
- ->whereNotIn('matches.status', ['ongoing', 'open'])
- ->get()->load('league', 'teamA', 'teamB')
- ->sortByDesc('schedule')
- ->slice($ptr, 10);
- $currList = collect();
- $oldList = collect();
- foreach ($_matches as $index => $_m) {
- $_matches[$index]->team_a_winPercentage = number_format(matchWinPercentagePerTeam($_m->id, $_m->teamA->id), 2);
- $_matches[$index]->team_b_winPercentage = number_format(matchWinPercentagePerTeam($_m->id, $_m->teamB->id), 2);
- $_matches[$index]->match_sched = $_m->schedule->diffForHumans();
- unset($_matches[$index]->fee);
- switch($_m->status) {
- case 'open':
- $_matches[$index]->is_current = true;
- $_matches[$index]->status = '';
- case 'ongoing':
- $_matches[$index]->is_current = true;
- $_matches[$index]->status = $_m->schedule->diffForHumans() .
- ' <span style="color: #72A326; text-shadow: 1px 1px 0px #4A7010; font-weight: bold; font-size: 16px"> LIVE</span>';
- break;
- case 'settled':
- $_matches[$index]->is_current = false;
- $_matches[$index]->status = $_m->schedule->diffForHumans() .
- ' <span style="color: #606060; font-weight: bold; font-size: 16px"> SETTLED</span>';
- $_matches[$index]->team_a_winner = ($_m->teamA->id == $_m->team_winner);
- $_matches[$index]->team_b_winner = ($_m->teamB->id == $_m->team_winner);
- break;
- case 'draw':
- $_matches[$index]->is_current = false;
- $_matches[$index]->status = $_m->schedule->diffForHumans() .
- ' <span style="color: #606060; font-weight: bold; font-size: 16px"> DRAW - CREDITS RETURNED</span>';
- break;
- case 'cancelled':
- $_matches[$index]->is_current = false;
- $_matches[$index]->status = $_m->schedule->diffForHumans() .
- ' <span style="color: #606060; font-weight: bold; font-size: 16px"> CANCELLED</span>';
- break;
- default:
- $_matches[$index]->is_current = false;
- $_matches[$index]->status = '';
- break;
- }
- $oldList->push($_m);
- }
- return [
- 'matches' => $oldList,
- 'pointer' => $ptr += 10
- ];
- }
- //show more sports matches
- public function showSportsMatches($ptr) {
- $_matches = \App\Match::mainMatches()->whereIn('leagues.type',['pba','nba','boxing','mma','fifa','mpbl','soccer','volleyball','football','uaap','sports','basketball'])
- ->whereNotIn('matches.status', ['ongoing', 'open'])
- ->get()->load('league', 'teamA', 'teamB')
- ->sortByDesc('schedule')
- ->slice($ptr, 10);
- $currList = collect();
- $oldList = collect();
- foreach ($_matches as $index => $_m) {
- $_matches[$index]->team_a_winPercentage = number_format(matchWinPercentagePerTeam($_m->id, $_m->teamA->id), 2);
- $_matches[$index]->team_b_winPercentage = number_format(matchWinPercentagePerTeam($_m->id, $_m->teamB->id), 2);
- $_matches[$index]->match_sched = $_m->schedule->diffForHumans();
- unset($_matches[$index]->fee);
- switch($_m->status) {
- case 'open':
- $_matches[$index]->is_current = true;
- $_matches[$index]->status = '';
- case 'ongoing':
- $_matches[$index]->is_current = true;
- $_matches[$index]->status = $_m->schedule->diffForHumans() .
- ' <span style="color: #72A326; text-shadow: 1px 1px 0px #4A7010; font-weight: bold; font-size: 16px"> LIVE</span>';
- break;
- case 'settled':
- $_matches[$index]->is_current = false;
- $_matches[$index]->status = $_m->schedule->diffForHumans() .
- ' <span style="color: #606060; font-weight: bold; font-size: 16px"> SETTLED</span>';
- $_matches[$index]->team_a_winner = ($_m->teamA->id == $_m->team_winner);
- $_matches[$index]->team_b_winner = ($_m->teamB->id == $_m->team_winner);
- break;
- case 'draw':
- $_matches[$index]->is_current = false;
- $_matches[$index]->status = $_m->schedule->diffForHumans() .
- ' <span style="color: #606060; font-weight: bold; font-size: 16px"> DRAW - CREDITS RETURNED</span>';
- break;
- case 'cancelled':
- $_matches[$index]->is_current = false;
- $_matches[$index]->status = $_m->schedule->diffForHumans() .
- ' <span style="color: #606060; font-weight: bold; font-size: 16px"> CANCELLED</span>';
- break;
- default:
- $_matches[$index]->is_current = false;
- $_matches[$index]->status = '';
- break;
- }
- $oldList->push($_m);
- }
- return [
- 'matches' => $oldList,
- 'pointer' => $ptr += 10
- ];
- }
- public function profile()
- {
- $beta_badge = \App\Badge::where('name','like','betatester')->first();
- $provinces = \App\Province::all();
- $earnings['today'] = number_format(\Auth::user()->bets()->earnings('today')->first()->total,2);
- $earnings['weekly'] = number_format(\Auth::user()->bets()->earnings('weekly')->first()->total,2);
- $earnings['monthly'] = number_format(\Auth::user()->bets()->earnings('monthly')->first()->total,2);
- $earnings['annual'] = number_format(\Auth::user()->bets()->earnings('annual')->first()->total,2);
- $earnings['total'] = number_format(\Auth::user()->bets()->earnings('total')->first()->total,2);
- $settings = [
- 'bdo-account-name' => '',
- 'bdo-account-number' => '',
- 'bpi-account-name' => '',
- 'bpi-account-number' => '',
- 'metro-account-name' => '',
- 'metro-account-number' => '',
- 'remittance-name' => '',
- 'remittance-number' => '',
- 'remittance-location' => '',
- 'coins-wallet-address' => '',
- 'security-account-name' => '',
- 'security-account-number' => ''
- ];
- foreach(\App\SiteSetting::all() as $siteSettings) {
- if(isset($settings[$siteSettings->name])) {
- $settings[$siteSettings->name] = $siteSettings->value;
- }
- }
- return view('profile', compact('beta_badge', 'provinces','earnings','settings'));
- }
- public function requestBetaTester(Request $request)
- {
- $user = \App\User::find($request->user_id);
- $badge = \App\Badge::where('name', 'like', 'betatester')->first();
- if ($badge) {
- if(!$user->badges->contains($badge->id)){
- $user->badges()->attach($badge->id);
- if ($user->rewards->where('type', 'badge')->where('class_id', $badge->id)->count() == 0 && $badge->credits > 0) {
- $reward = \App\Reward::create([
- 'user_id' => $user->id,
- 'type' => 'badge',
- 'class_id' => $badge->id,
- 'description' => 'Awarded Badge: ' . $badge->name . ($badge->credits ? ' with ' . $badge->credits . ' credits' : ''),
- 'credits' => $badge->credits
- ]);
- $user->credits += $badge->credits;
- $user->save();
- }
- return ['success' => true];
- }else{
- return ['success' => false];
- }
- } else
- return ['success' => false];
- }
- public function impersonate($uid) {
- $user = \App\User::find($uid);
- if ($user) {
- if (!\App::environment('prod')) {
- \Auth::login($user);
- return redirect('/login');
- } else {
- return redirect('/');
- }
- } else
- return abort(500, 'Invalid username entered!');
- }
- /**
- * Get market item
- * Display Item on market view
- *
- */
- public function displayItemMarket()
- {
- $upload = Product::all();
- return view('market', compact('upload'));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement