Advertisement
Guest User

ha

a guest
Feb 11th, 2019
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.08 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use Illuminate\Http\Request;
  6. use App\Product;
  7. use App\League;
  8. use App\Match;
  9.  
  10. class HomeController extends Controller
  11. {
  12. /**
  13. * Create a new controller instance.
  14. *
  15. * @return void
  16. */
  17. public function __construct()
  18. {
  19. $this->middleware('auth', ['except' => ['index', 'csgoindex', 'sportsindex', 'dota2index', 'allmatches','showMoreMatches', 'showCsgoMatches', 'showDotaMatches', 'showSportsMatches', 'displayItemMarket']]);
  20. }
  21.  
  22. /**
  23. * Show the application dashboard.
  24. *
  25. * @return \Illuminate\Http\Response
  26. */
  27. public function index()
  28. {
  29. $leagues = \App\League::active()->orderby('leagues.status','desc')->orderBy('created_at','desc')->get()->load('teams.bets');
  30. $_matches = \App\Match::mainMatches()->get()->load('teamA', 'teamB')->sortByDesc('schedule');
  31. $liveList = collect();
  32. $openList = collect();
  33. $oldList = collect();
  34. foreach ($_matches as $_m) {
  35. if ($_m->schedule->isFuture()) {
  36. if($_m->status == 'ongoing')
  37. $liveList->push($_m);
  38. else if($_m->status == 'open')
  39. $openList->push($_m);
  40. else
  41. $oldList->push($_m);
  42. } else {
  43. if ($_m->status == 'ongoing')
  44. $liveList->push($_m);
  45. else if($_m->status == 'open')
  46. $openList->push($_m);
  47. else
  48. $oldList->push($_m);
  49. }
  50. }
  51. $_liveList = $liveList->sortBy('schedule');
  52. $matches = $_liveList->merge($openList->sortBy('schedule'));
  53. $allresult = \App\Match::mainMatches()->whereIn('matches.status',['open','ongoing'])->first();
  54. return view('home', compact('teams', 'matches', 'allresult', 'leagues'));
  55. }
  56. //All matches index
  57. public function allmatches()
  58. {
  59. $leagues = \App\League::active()->orderby('leagues.status','desc')->orderBy('created_at','desc')->get()->load('teams.bets');
  60. $_matches = \App\Match::mainMatches()->get()->load('teamA', 'teamB')->sortByDesc('schedule');
  61. $liveList = collect();
  62. $openList = collect();
  63. $oldList = collect();
  64. foreach ($_matches as $_m) {
  65. if ($_m->schedule->isFuture()) {
  66. if($_m->status == 'ongoing')
  67. $liveList->push($_m);
  68. else if($_m->status == 'open')
  69. $openList->push($_m);
  70. else
  71. $oldList->push($_m);
  72. } else {
  73. if ($_m->status == 'ongoing')
  74. $liveList->push($_m);
  75. else if($_m->status == 'open')
  76. $openList->push($_m);
  77. else
  78. $oldList->push($_m);
  79. }
  80. }
  81. $_liveList = $liveList->sortBy('schedule');
  82. $matches = $_liveList->merge($openList->sortBy('schedule'));
  83. $allresult = \App\Match::mainMatches()->whereIn('matches.status',['open','ongoing'])->first();
  84. return view('allmatch', compact('teams', 'matches', 'allresult', 'leagues'));
  85. }
  86. //added dota2index
  87. public function dota2index()
  88. {
  89. $leagues = \App\League::active()->orderby('leagues.status','desc')->orderBy('created_at','desc')->get()->load('teams.bets');
  90. $_matches = \App\Match::mainMatches()->where('leagues.type','=','dota2')->get()->load('teamA', 'teamB')->sortByDesc('schedule');
  91. $liveList = collect();
  92. $openList = collect();
  93. $oldList = collect();
  94. foreach ($_matches as $_m) {
  95. if ($_m->schedule->isFuture()) {
  96. if($_m->status == 'ongoing')
  97. $liveList->push($_m);
  98. else if($_m->status == 'open')
  99. $openList->push($_m);
  100. else
  101. $oldList->push($_m);
  102. } else {
  103. if ($_m->status == 'ongoing')
  104. $liveList->push($_m);
  105. else if($_m->status == 'open')
  106. $openList->push($_m);
  107. else
  108. $oldList->push($_m);
  109. }
  110. }
  111. $_liveList = $liveList->sortBy('schedule');
  112. $dotamatches = $_liveList->merge($openList->sortBy('schedule'));
  113. $dotaresult = \App\Match::mainMatches()->where('leagues.type','=','dota2')->whereIn('matches.status',['open','ongoing'])->first();
  114. return view('dota2', compact('teams', 'dotamatches', 'dotaresult','leagues'));
  115. }
  116.  
  117. //added csgo index tab
  118. public function csgoindex()
  119. {
  120. $leagues = \App\League::active()->orderby('leagues.status','desc')->orderBy('created_at','desc')->get()->load('teams.bets');
  121. $_matches = \App\Match::mainMatches()->where('leagues.type','=','csgo')->get()->load('teamA', 'teamB')->sortByDesc('schedule');
  122. $liveList = collect();
  123. $openList = collect();
  124. $oldList = collect();
  125. foreach ($_matches as $_m) {
  126. if ($_m->schedule->isFuture()) {
  127. if($_m->status == 'ongoing')
  128. $liveList->push($_m);
  129. else if($_m->status == 'open')
  130. $openList->push($_m);
  131. else
  132. $oldList->push($_m);
  133. } else {
  134. if ($_m->status == 'ongoing')
  135. $liveList->push($_m);
  136. else if($_m->status == 'open')
  137. $openList->push($_m);
  138. else
  139. $oldList->push($_m);
  140. }
  141. }
  142. $_liveList = $liveList->sortBy('schedule');
  143. $csgomatches = $_liveList->merge($openList->sortBy('schedule'));
  144. $csgoresult = \App\Match::mainMatches()->where('leagues.type','=','csgo')->whereIn('matches.status',['open','ongoing'])->first();
  145. return view('csgo', compact('teams', 'csgomatches', 'csgoresult', 'leagues'));
  146. }
  147. //added sports tab index
  148. public function sportsindex()
  149. {
  150. $leagues = \App\League::active()->orderby('status','desc')->orderBy('created_at','desc')->get()->load('teams.bets');
  151. $_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');
  152. $liveList = collect();
  153. $openList = collect();
  154. $oldList = collect();
  155. foreach ($_matches as $_m) {
  156. if ($_m->schedule->isFuture()) {
  157. if($_m->status == 'ongoing')
  158. $liveList->push($_m);
  159. else if($_m->status == 'open')
  160. $openList->push($_m);
  161. else
  162. $oldList->push($_m);
  163. } else {
  164. if ($_m->status == 'ongoing')
  165. $liveList->push($_m);
  166. else if($_m->status == 'open')
  167. $openList->push($_m);
  168. else
  169. $oldList->push($_m);
  170. }
  171. }
  172. $_liveList = $liveList->sortBy('schedule');
  173. $sportsmatches = $_liveList->merge($openList->sortBy('schedule'));
  174. $sportsresult = \App\Match::mainMatches()->whereIn('leagues.type',['pba','nba','boxing','mma','fifa','mpbl','soccer','volleyball','football','uaap','sports','basketball'])
  175. ->whereIn('matches.status',['open','ongoing'])->first();
  176. return view('sports', compact('teams', 'sportsmatches', 'sportsresult','leagues'));
  177. }
  178.  
  179. public function showMoreMatches($ptr) {
  180. $_matches = \App\Match::mainMatches()
  181. ->whereNotIn('matches.status', ['ongoing', 'open'])
  182. ->get()->load('league', 'teamA', 'teamB')
  183. ->sortByDesc('schedule')
  184. ->slice($ptr, 10);
  185. $currList = collect();
  186. $oldList = collect();
  187. foreach ($_matches as $index => $_m) {
  188. $_matches[$index]->team_a_winPercentage = number_format(matchWinPercentagePerTeam($_m->id, $_m->teamA->id), 2);
  189. $_matches[$index]->team_b_winPercentage = number_format(matchWinPercentagePerTeam($_m->id, $_m->teamB->id), 2);
  190. $_matches[$index]->match_sched = $_m->schedule->diffForHumans();
  191. unset($_matches[$index]->fee);
  192.  
  193. switch($_m->status) {
  194. case 'open':
  195. $_matches[$index]->is_current = true;
  196. $_matches[$index]->status = '';
  197. case 'ongoing':
  198. $_matches[$index]->is_current = true;
  199. $_matches[$index]->status = $_m->schedule->diffForHumans() .
  200. ' <span style="color: #72A326; text-shadow: 1px 1px 0px #4A7010; font-weight: bold; font-size: 16px">&nbsp;LIVE</span>';
  201. break;
  202. case 'settled':
  203. $_matches[$index]->is_current = false;
  204. $_matches[$index]->status = $_m->schedule->diffForHumans() .
  205. ' <span style="color: #606060; font-weight: bold; font-size: 16px">&nbsp;SETTLED</span>';
  206. $_matches[$index]->team_a_winner = ($_m->teamA->id == $_m->team_winner);
  207. $_matches[$index]->team_b_winner = ($_m->teamB->id == $_m->team_winner);
  208. break;
  209. case 'draw':
  210. $_matches[$index]->is_current = false;
  211. $_matches[$index]->status = $_m->schedule->diffForHumans() .
  212. ' <span style="color: #606060; font-weight: bold; font-size: 16px">&nbsp;DRAW - CREDITS RETURNED</span>';
  213. break;
  214. case 'cancelled':
  215. $_matches[$index]->is_current = false;
  216. $_matches[$index]->status = $_m->schedule->diffForHumans() .
  217. ' <span style="color: #606060; font-weight: bold; font-size: 16px">&nbsp;CANCELLED</span>';
  218. break;
  219. default:
  220. $_matches[$index]->is_current = false;
  221. $_matches[$index]->status = '';
  222. break;
  223. }
  224.  
  225. $oldList->push($_m);
  226. }
  227. return [
  228. 'matches' => $oldList,
  229. 'pointer' => $ptr += 10
  230. ];
  231. }
  232.  
  233. public function showDotaMatches2($ptr){
  234. $_matches = \App\Match::mainMatches()->where('leagues.type','=','dota2')
  235. ->whereIn('matches.status', ['ongoing', 'open'])
  236. ->get()->load('league', 'teamA', 'teamB')
  237. ->sortByDesc('schedule')
  238. ->slice($ptr);
  239. $currList = collect();
  240. $oldList = collect();
  241. foreach ($_matches as $index => $_m) {
  242. $_matches[$index]->team_a_winPercentage = number_format(matchWinPercentagePerTeam($_m->id, $_m->teamA->id), 2);
  243. $_matches[$index]->team_b_winPercentage = number_format(matchWinPercentagePerTeam($_m->id, $_m->teamB->id), 2);
  244. $_matches[$index]->match_sched = $_m->schedule->diffForHumans();
  245. unset($_matches[$index]->fee);
  246.  
  247. switch($_m->status) {
  248. case 'open':
  249. $_matches[$index]->is_current = true;
  250. $_matches[$index]->status = '';
  251. case 'ongoing':
  252. $_matches[$index]->is_current = true;
  253. $_matches[$index]->status = $_m->schedule->diffForHumans() .
  254. ' <span style="color: #72A326; text-shadow: 1px 1px 0px #4A7010; font-weight: bold; font-size: 16px">&nbsp;LIVE</span>';
  255. break;
  256. case 'settled':
  257. $_matches[$index]->is_current = false;
  258. $_matches[$index]->status = $_m->schedule->diffForHumans() .
  259. ' <span style="color: #606060; font-weight: bold; font-size: 16px">&nbsp;SETTLED</span>';
  260. $_matches[$index]->team_a_winner = ($_m->teamA->id == $_m->team_winner);
  261. $_matches[$index]->team_b_winner = ($_m->teamB->id == $_m->team_winner);
  262. break;
  263. case 'draw':
  264. $_matches[$index]->is_current = false;
  265. $_matches[$index]->status = $_m->schedule->diffForHumans() .
  266. ' <span style="color: #606060; font-weight: bold; font-size: 16px">&nbsp;DRAW - CREDITS RETURNED</span>';
  267. break;
  268. case 'cancelled':
  269. $_matches[$index]->is_current = false;
  270. $_matches[$index]->status = $_m->schedule->diffForHumans() .
  271. ' <span style="color: #606060; font-weight: bold; font-size: 16px">&nbsp;CANCELLED</span>';
  272. break;
  273.  
  274. default:
  275. $_matches[$index]->is_current = false;
  276. $_matches[$index]->status = '';
  277. break;
  278. }
  279.  
  280. $oldList->push($_m);
  281. }
  282. return [
  283. 'matches' => $oldList,
  284. 'pointer' => $ptr += 0
  285. ];
  286. }
  287. //show more dotamatches
  288. public function showDotaMatches($ptr){
  289. $_matches = \App\Match::mainMatches()->where('leagues.type','=','dota2')
  290. ->whereNotIn('matches.status', ['ongoing', 'open'])
  291. ->get()->load('league', 'teamA', 'teamB')
  292. ->sortByDesc('schedule')
  293. ->slice($ptr, 10);
  294. $currList = collect();
  295. $oldList = collect();
  296. foreach ($_matches as $index => $_m) {
  297. $_matches[$index]->team_a_winPercentage = number_format(matchWinPercentagePerTeam($_m->id, $_m->teamA->id), 2);
  298. $_matches[$index]->team_b_winPercentage = number_format(matchWinPercentagePerTeam($_m->id, $_m->teamB->id), 2);
  299. $_matches[$index]->match_sched = $_m->schedule->diffForHumans();
  300. unset($_matches[$index]->fee);
  301.  
  302. switch($_m->status) {
  303. case 'open':
  304. $_matches[$index]->is_current = true;
  305. $_matches[$index]->status = '';
  306. case 'ongoing':
  307. $_matches[$index]->is_current = true;
  308. $_matches[$index]->status = $_m->schedule->diffForHumans() .
  309. ' <span style="color: #72A326; text-shadow: 1px 1px 0px #4A7010; font-weight: bold; font-size: 16px">&nbsp;LIVE</span>';
  310. break;
  311. case 'settled':
  312. $_matches[$index]->is_current = false;
  313. $_matches[$index]->status = $_m->schedule->diffForHumans() .
  314. ' <span style="color: #606060; font-weight: bold; font-size: 16px">&nbsp;SETTLED</span>';
  315. $_matches[$index]->team_a_winner = ($_m->teamA->id == $_m->team_winner);
  316. $_matches[$index]->team_b_winner = ($_m->teamB->id == $_m->team_winner);
  317. break;
  318. case 'draw':
  319. $_matches[$index]->is_current = false;
  320. $_matches[$index]->status = $_m->schedule->diffForHumans() .
  321. ' <span style="color: #606060; font-weight: bold; font-size: 16px">&nbsp;DRAW - CREDITS RETURNED</span>';
  322. break;
  323. case 'cancelled':
  324. $_matches[$index]->is_current = false;
  325. $_matches[$index]->status = $_m->schedule->diffForHumans() .
  326. ' <span style="color: #606060; font-weight: bold; font-size: 16px">&nbsp;CANCELLED</span>';
  327. break;
  328.  
  329. default:
  330. $_matches[$index]->is_current = false;
  331. $_matches[$index]->status = '';
  332. break;
  333. }
  334.  
  335. $oldList->push($_m);
  336. }
  337. return [
  338. 'matches' => $oldList,
  339. 'pointer' => $ptr += 10
  340. ];
  341. }
  342. //show more csgo matches
  343. public function showCsgoMatches($ptr) {
  344. $_matches = \App\Match::mainMatches()->where('leagues.type','=','csgo')
  345. ->whereNotIn('matches.status', ['ongoing', 'open'])
  346. ->get()->load('league', 'teamA', 'teamB')
  347. ->sortByDesc('schedule')
  348. ->slice($ptr, 10);
  349. $currList = collect();
  350. $oldList = collect();
  351. foreach ($_matches as $index => $_m) {
  352. $_matches[$index]->team_a_winPercentage = number_format(matchWinPercentagePerTeam($_m->id, $_m->teamA->id), 2);
  353. $_matches[$index]->team_b_winPercentage = number_format(matchWinPercentagePerTeam($_m->id, $_m->teamB->id), 2);
  354. $_matches[$index]->match_sched = $_m->schedule->diffForHumans();
  355. unset($_matches[$index]->fee);
  356.  
  357. switch($_m->status) {
  358. case 'open':
  359. $_matches[$index]->is_current = true;
  360. $_matches[$index]->status = '';
  361. case 'ongoing':
  362. $_matches[$index]->is_current = true;
  363. $_matches[$index]->status = $_m->schedule->diffForHumans() .
  364. ' <span style="color: #72A326; text-shadow: 1px 1px 0px #4A7010; font-weight: bold; font-size: 16px">&nbsp;LIVE</span>';
  365. break;
  366. case 'settled':
  367. $_matches[$index]->is_current = false;
  368. $_matches[$index]->status = $_m->schedule->diffForHumans() .
  369. ' <span style="color: #606060; font-weight: bold; font-size: 16px">&nbsp;SETTLED</span>';
  370. $_matches[$index]->team_a_winner = ($_m->teamA->id == $_m->team_winner);
  371. $_matches[$index]->team_b_winner = ($_m->teamB->id == $_m->team_winner);
  372. break;
  373. case 'draw':
  374. $_matches[$index]->is_current = false;
  375. $_matches[$index]->status = $_m->schedule->diffForHumans() .
  376. ' <span style="color: #606060; font-weight: bold; font-size: 16px">&nbsp;DRAW - CREDITS RETURNED</span>';
  377. break;
  378. case 'cancelled':
  379. $_matches[$index]->is_current = false;
  380. $_matches[$index]->status = $_m->schedule->diffForHumans() .
  381. ' <span style="color: #606060; font-weight: bold; font-size: 16px">&nbsp;CANCELLED</span>';
  382. break;
  383. default:
  384. $_matches[$index]->is_current = false;
  385. $_matches[$index]->status = '';
  386. break;
  387. }
  388.  
  389. $oldList->push($_m);
  390. }
  391. return [
  392. 'matches' => $oldList,
  393. 'pointer' => $ptr += 10
  394. ];
  395. }
  396. //show more sports matches
  397. public function showSportsMatches($ptr) {
  398. $_matches = \App\Match::mainMatches()->whereIn('leagues.type',['pba','nba','boxing','mma','fifa','mpbl','soccer','volleyball','football','uaap','sports','basketball'])
  399. ->whereNotIn('matches.status', ['ongoing', 'open'])
  400. ->get()->load('league', 'teamA', 'teamB')
  401. ->sortByDesc('schedule')
  402. ->slice($ptr, 10);
  403. $currList = collect();
  404. $oldList = collect();
  405. foreach ($_matches as $index => $_m) {
  406. $_matches[$index]->team_a_winPercentage = number_format(matchWinPercentagePerTeam($_m->id, $_m->teamA->id), 2);
  407. $_matches[$index]->team_b_winPercentage = number_format(matchWinPercentagePerTeam($_m->id, $_m->teamB->id), 2);
  408. $_matches[$index]->match_sched = $_m->schedule->diffForHumans();
  409. unset($_matches[$index]->fee);
  410.  
  411. switch($_m->status) {
  412. case 'open':
  413. $_matches[$index]->is_current = true;
  414. $_matches[$index]->status = '';
  415. case 'ongoing':
  416. $_matches[$index]->is_current = true;
  417. $_matches[$index]->status = $_m->schedule->diffForHumans() .
  418. ' <span style="color: #72A326; text-shadow: 1px 1px 0px #4A7010; font-weight: bold; font-size: 16px">&nbsp;LIVE</span>';
  419. break;
  420. case 'settled':
  421. $_matches[$index]->is_current = false;
  422. $_matches[$index]->status = $_m->schedule->diffForHumans() .
  423. ' <span style="color: #606060; font-weight: bold; font-size: 16px">&nbsp;SETTLED</span>';
  424. $_matches[$index]->team_a_winner = ($_m->teamA->id == $_m->team_winner);
  425. $_matches[$index]->team_b_winner = ($_m->teamB->id == $_m->team_winner);
  426. break;
  427. case 'draw':
  428. $_matches[$index]->is_current = false;
  429. $_matches[$index]->status = $_m->schedule->diffForHumans() .
  430. ' <span style="color: #606060; font-weight: bold; font-size: 16px">&nbsp;DRAW - CREDITS RETURNED</span>';
  431. break;
  432. case 'cancelled':
  433. $_matches[$index]->is_current = false;
  434. $_matches[$index]->status = $_m->schedule->diffForHumans() .
  435. ' <span style="color: #606060; font-weight: bold; font-size: 16px">&nbsp;CANCELLED</span>';
  436. break;
  437. default:
  438. $_matches[$index]->is_current = false;
  439. $_matches[$index]->status = '';
  440. break;
  441. }
  442.  
  443. $oldList->push($_m);
  444. }
  445. return [
  446. 'matches' => $oldList,
  447. 'pointer' => $ptr += 10
  448. ];
  449. }
  450.  
  451. public function profile()
  452. {
  453. $beta_badge = \App\Badge::where('name','like','betatester')->first();
  454. $provinces = \App\Province::all();
  455. $earnings['today'] = number_format(\Auth::user()->bets()->earnings('today')->first()->total,2);
  456. $earnings['weekly'] = number_format(\Auth::user()->bets()->earnings('weekly')->first()->total,2);
  457. $earnings['monthly'] = number_format(\Auth::user()->bets()->earnings('monthly')->first()->total,2);
  458. $earnings['annual'] = number_format(\Auth::user()->bets()->earnings('annual')->first()->total,2);
  459. $earnings['total'] = number_format(\Auth::user()->bets()->earnings('total')->first()->total,2);
  460. $settings = [
  461. 'bdo-account-name' => '',
  462. 'bdo-account-number' => '',
  463. 'bpi-account-name' => '',
  464. 'bpi-account-number' => '',
  465. 'metro-account-name' => '',
  466. 'metro-account-number' => '',
  467. 'remittance-name' => '',
  468. 'remittance-number' => '',
  469. 'remittance-location' => '',
  470. 'coins-wallet-address' => '',
  471. 'security-account-name' => '',
  472. 'security-account-number' => ''
  473. ];
  474. foreach(\App\SiteSetting::all() as $siteSettings) {
  475. if(isset($settings[$siteSettings->name])) {
  476. $settings[$siteSettings->name] = $siteSettings->value;
  477. }
  478. }
  479. return view('profile', compact('beta_badge', 'provinces','earnings','settings'));
  480. }
  481.  
  482. public function requestBetaTester(Request $request)
  483. {
  484. $user = \App\User::find($request->user_id);
  485. $badge = \App\Badge::where('name', 'like', 'betatester')->first();
  486. if ($badge) {
  487. if(!$user->badges->contains($badge->id)){
  488. $user->badges()->attach($badge->id);
  489. if ($user->rewards->where('type', 'badge')->where('class_id', $badge->id)->count() == 0 && $badge->credits > 0) {
  490. $reward = \App\Reward::create([
  491. 'user_id' => $user->id,
  492. 'type' => 'badge',
  493. 'class_id' => $badge->id,
  494. 'description' => 'Awarded Badge: ' . $badge->name . ($badge->credits ? ' with ' . $badge->credits . ' credits' : ''),
  495. 'credits' => $badge->credits
  496. ]);
  497. $user->credits += $badge->credits;
  498. $user->save();
  499. }
  500. return ['success' => true];
  501. }else{
  502. return ['success' => false];
  503. }
  504. } else
  505. return ['success' => false];
  506. }
  507.  
  508. public function impersonate($uid) {
  509. $user = \App\User::find($uid);
  510.  
  511. if ($user) {
  512. if (!\App::environment('prod')) {
  513. \Auth::login($user);
  514. return redirect('/login');
  515. } else {
  516. return redirect('/');
  517. }
  518. } else
  519. return abort(500, 'Invalid username entered!');
  520. }
  521.  
  522. /**
  523. * Get market item
  524. * Display Item on market view
  525. *
  526. */
  527. public function displayItemMarket()
  528. {
  529. $upload = Product::all();
  530. return view('market', compact('upload'));
  531. }
  532.  
  533. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement