@@ -57,10 +57,10 @@ discard block |
||
57 | 57 | foreach ($trending_groups as &$t) { |
58 | 58 | $t["members"]=$this->countGroupMembers($t["gid"]); |
59 | 59 | } |
60 | - usort($trending_groups, function ($a, $b) { |
|
60 | + usort($trending_groups, function($a, $b) { |
|
61 | 61 | return $b["members"]<=>$a["members"]; |
62 | 62 | }); |
63 | - Cache::tags(['group'])->put('trending', array_slice($trending_groups,0,12), 3600*24); |
|
63 | + Cache::tags(['group'])->put('trending', array_slice($trending_groups, 0, 12), 3600 * 24); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | public function userGroups($uid) |
@@ -100,13 +100,13 @@ discard block |
||
100 | 100 | |
101 | 101 | public function changeGroupName($gid, $GroupName) |
102 | 102 | { |
103 | - return DB::table("group")->where('gid',$gid)->update([ |
|
103 | + return DB::table("group")->where('gid', $gid)->update([ |
|
104 | 104 | "name"=>$GroupName |
105 | 105 | ]); |
106 | 106 | } |
107 | 107 | |
108 | - public function changeJoinPolicy($gid, $JoinPolicy){ |
|
109 | - return DB::table("group")->where('gid',$gid)->update([ |
|
108 | + public function changeJoinPolicy($gid, $JoinPolicy) { |
|
109 | + return DB::table("group")->where('gid', $gid)->update([ |
|
110 | 110 | "join_policy"=>$JoinPolicy |
111 | 111 | ]); |
112 | 112 | } |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | public function details($gcode) |
115 | 115 | { |
116 | 116 | $basic_info=DB::table($this->tableName)->where(["gcode"=>$gcode])->first(); |
117 | - if(empty($basic_info)) return []; |
|
117 | + if (empty($basic_info)) return []; |
|
118 | 118 | $basic_info["members"]=$this->countGroupMembers($basic_info["gid"]); |
119 | 119 | $basic_info["tags"]=$this->getGroupTags($basic_info["gid"]); |
120 | 120 | $basic_info["create_time_foramt"]=date_format(date_create($basic_info["create_time"]), 'M jS, Y'); |
@@ -131,10 +131,10 @@ discard block |
||
131 | 131 | public function userProfile($uid, $gid) |
132 | 132 | { |
133 | 133 | $info=DB::table("group_member") |
134 | - ->join('users','users.id','=','group_member.uid') |
|
134 | + ->join('users', 'users.id', '=', 'group_member.uid') |
|
135 | 135 | ->where(["gid"=>$gid, "uid"=>$uid]) |
136 | 136 | ->where("role", ">", 0) |
137 | - ->select('avatar','describes','email','gid','uid','name','nick_name','professional_rate','role','sub_group') |
|
137 | + ->select('avatar', 'describes', 'email', 'gid', 'uid', 'name', 'nick_name', 'professional_rate', 'role', 'sub_group') |
|
138 | 138 | ->first(); |
139 | 139 | if (!empty($info)) { |
140 | 140 | $info["role_parsed"]=$this->role[$info["role"]]; |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | foreach ($user_list as &$u) { |
163 | 163 | $u["role_parsed"]=$this->role[$u["role"]]; |
164 | 164 | $u["role_color"]=$this->role_color[$u["role"]]; |
165 | - if(is_null($u["sub_group"])) $u["sub_group"]="None"; |
|
165 | + if (is_null($u["sub_group"])) $u["sub_group"]="None"; |
|
166 | 166 | } |
167 | 167 | return $user_list; |
168 | 168 | } |
@@ -223,16 +223,16 @@ discard block |
||
223 | 223 | ])->where("role", ">", 0)->count(); |
224 | 224 | } |
225 | 225 | |
226 | - public function problemTags($gid,$pid = -1) |
|
226 | + public function problemTags($gid, $pid=-1) |
|
227 | 227 | { |
228 | - if($pid == -1){ |
|
229 | - $tags = DB::table('group_problem_tag') |
|
228 | + if ($pid==-1) { |
|
229 | + $tags=DB::table('group_problem_tag') |
|
230 | 230 | ->select('tag') |
231 | - ->where('gid',$gid) |
|
231 | + ->where('gid', $gid) |
|
232 | 232 | ->distinct() |
233 | 233 | ->get()->all(); |
234 | - }else{ |
|
235 | - $tags = DB::table('group_problem_tag') |
|
234 | + } else { |
|
235 | + $tags=DB::table('group_problem_tag') |
|
236 | 236 | ->select('tag') |
237 | 237 | ->where('gid', $gid) |
238 | 238 | ->where('pid', $pid) |
@@ -240,10 +240,10 @@ discard block |
||
240 | 240 | ->get()->all(); |
241 | 241 | } |
242 | 242 | |
243 | - $tags_arr = []; |
|
244 | - if(!empty($tags)){ |
|
243 | + $tags_arr=[]; |
|
244 | + if (!empty($tags)) { |
|
245 | 245 | foreach ($tags as $value) { |
246 | - array_push($tags_arr,$value['tag']); |
|
246 | + array_push($tags_arr, $value['tag']); |
|
247 | 247 | } |
248 | 248 | } |
249 | 249 | return $tags_arr; |
@@ -251,28 +251,28 @@ discard block |
||
251 | 251 | |
252 | 252 | public function problems($gid) |
253 | 253 | { |
254 | - $contestModel = new ContestModel(); |
|
255 | - $problems = DB::table('contest_problem') |
|
256 | - ->join('contest','contest_problem.cid', '=', 'contest.cid') |
|
257 | - ->join('problem','contest_problem.pid', '=', 'problem.pid' ) |
|
254 | + $contestModel=new ContestModel(); |
|
255 | + $problems=DB::table('contest_problem') |
|
256 | + ->join('contest', 'contest_problem.cid', '=', 'contest.cid') |
|
257 | + ->join('problem', 'contest_problem.pid', '=', 'problem.pid') |
|
258 | 258 | ->select('contest_problem.cid as cid', 'problem.pid as pid', 'pcode', 'title') |
259 | - ->where('contest.gid',$gid) |
|
260 | - ->where('contest.practice',1) |
|
261 | - ->orderBy('contest.create_time','desc') |
|
259 | + ->where('contest.gid', $gid) |
|
260 | + ->where('contest.practice', 1) |
|
261 | + ->orderBy('contest.create_time', 'desc') |
|
262 | 262 | ->distinct() |
263 | 263 | ->get()->all(); |
264 | - $user_id = Auth::user()->id; |
|
265 | - foreach($problems as $key => $value){ |
|
266 | - if($contestModel->judgeClearance($value['cid'],$user_id) != 3){ |
|
264 | + $user_id=Auth::user()->id; |
|
265 | + foreach ($problems as $key => $value) { |
|
266 | + if ($contestModel->judgeClearance($value['cid'], $user_id)!=3) { |
|
267 | 267 | unset($problems[$key]); |
268 | - }else{ |
|
269 | - $problems[$key]['tags'] = $this->problemTags($gid,$value['pid']); |
|
268 | + } else { |
|
269 | + $problems[$key]['tags']=$this->problemTags($gid, $value['pid']); |
|
270 | 270 | } |
271 | 271 | } |
272 | 272 | return $problems; |
273 | 273 | } |
274 | 274 | |
275 | - public function problemAddTag($gid,$pid,$tag) |
|
275 | + public function problemAddTag($gid, $pid, $tag) |
|
276 | 276 | { |
277 | 277 | return DB::table("group_problem_tag")->insert([ |
278 | 278 | "gid"=>$gid, |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | ]); |
282 | 282 | } |
283 | 283 | |
284 | - public function problemRemoveTag($gid,$pid,$tag) |
|
284 | + public function problemRemoveTag($gid, $pid, $tag) |
|
285 | 285 | { |
286 | 286 | return DB::table("group_problem_tag")->where([ |
287 | 287 | "gid"=>$gid, |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | public function judgeEmailClearance($gid, $email) |
327 | 327 | { |
328 | 328 | $user=DB::table("users")->where(["email"=>$email])->first(); |
329 | - if(empty($user)) return -4; |
|
329 | + if (empty($user)) return -4; |
|
330 | 330 | $ret=DB::table("group_member")->where([ |
331 | 331 | "gid"=>$gid, |
332 | 332 | "uid"=>$user["id"], |
@@ -417,20 +417,20 @@ discard block |
||
417 | 417 | |
418 | 418 | public function groupMemberPracticeContestStat($gid) |
419 | 419 | { |
420 | - $contestModel = new ContestModel(); |
|
420 | + $contestModel=new ContestModel(); |
|
421 | 421 | |
422 | - $allPracticeContest = DB::table('contest') |
|
422 | + $allPracticeContest=DB::table('contest') |
|
423 | 423 | ->where([ |
424 | 424 | 'gid' => $gid, |
425 | 425 | 'practice' => 1, |
426 | 426 | ]) |
427 | - ->select('cid','name') |
|
427 | + ->select('cid', 'name') |
|
428 | 428 | ->get()->all(); |
429 | - $user_list = $this->userList($gid); |
|
429 | + $user_list=$this->userList($gid); |
|
430 | 430 | |
431 | - $memberData = []; |
|
431 | + $memberData=[]; |
|
432 | 432 | foreach ($user_list as $u) { |
433 | - $memberData[$u['uid']] = [ |
|
433 | + $memberData[$u['uid']]=[ |
|
434 | 434 | 'name' => $u['name'], |
435 | 435 | 'nick_name' => $u['nick_name'], |
436 | 436 | 'elo' => $u['ranking'], |
@@ -441,61 +441,61 @@ discard block |
||
441 | 441 | ]; |
442 | 442 | } |
443 | 443 | foreach ($allPracticeContest as $c) { |
444 | - $contestRankRaw = $contestModel->contestRank($c['cid']); |
|
445 | - foreach($contestRankRaw as $key => $contestRank){ |
|
446 | - if(isset($contestRank['remote']) && $contestRank['remote']){ |
|
444 | + $contestRankRaw=$contestModel->contestRank($c['cid']); |
|
445 | + foreach ($contestRankRaw as $key => $contestRank) { |
|
446 | + if (isset($contestRank['remote']) && $contestRank['remote']) { |
|
447 | 447 | unset($contestRankRaw[$key]); |
448 | 448 | } |
449 | 449 | } |
450 | - $contestRank = array_values($contestRankRaw); |
|
451 | - $problemsCount = DB::table('contest_problem') |
|
452 | - ->where('cid',$c['cid']) |
|
450 | + $contestRank=array_values($contestRankRaw); |
|
451 | + $problemsCount=DB::table('contest_problem') |
|
452 | + ->where('cid', $c['cid']) |
|
453 | 453 | ->count(); |
454 | - $index = 1; |
|
455 | - $rank = 1; |
|
456 | - $last_cr = []; |
|
457 | - $last_rank = 1; |
|
454 | + $index=1; |
|
455 | + $rank=1; |
|
456 | + $last_cr=[]; |
|
457 | + $last_rank=1; |
|
458 | 458 | foreach ($contestRank as $cr) { |
459 | - $last_rank = $index; |
|
460 | - if(!empty($last_cr)){ |
|
461 | - if($cr['solved'] == $last_cr['solved'] && $cr['penalty'] == $last_cr['penalty'] ){ |
|
462 | - $rank = $last_rank; |
|
463 | - }else{ |
|
464 | - $rank = $index; |
|
465 | - $last_rank = $rank; |
|
459 | + $last_rank=$index; |
|
460 | + if (!empty($last_cr)) { |
|
461 | + if ($cr['solved']==$last_cr['solved'] && $cr['penalty']==$last_cr['penalty']) { |
|
462 | + $rank=$last_rank; |
|
463 | + } else { |
|
464 | + $rank=$index; |
|
465 | + $last_rank=$rank; |
|
466 | 466 | } |
467 | 467 | } |
468 | - if(in_array($cr['uid'],array_keys($memberData))) { |
|
469 | - $memberData[$cr['uid']]['solved_all'] += $cr['solved']; |
|
470 | - $memberData[$cr['uid']]['problem_all'] += $problemsCount; |
|
471 | - $memberData[$cr['uid']]['penalty'] += $cr['penalty']; |
|
472 | - $memberData[$cr['uid']]['contest_detial'][$c['cid']] = [ |
|
468 | + if (in_array($cr['uid'], array_keys($memberData))) { |
|
469 | + $memberData[$cr['uid']]['solved_all']+=$cr['solved']; |
|
470 | + $memberData[$cr['uid']]['problem_all']+=$problemsCount; |
|
471 | + $memberData[$cr['uid']]['penalty']+=$cr['penalty']; |
|
472 | + $memberData[$cr['uid']]['contest_detial'][$c['cid']]=[ |
|
473 | 473 | 'rank' => $rank, |
474 | 474 | 'solved' => $cr['solved'], |
475 | 475 | 'problems' => $problemsCount, |
476 | 476 | 'penalty' => $cr['penalty'] |
477 | 477 | ]; |
478 | 478 | } |
479 | - $last_cr = $cr; |
|
479 | + $last_cr=$cr; |
|
480 | 480 | $index++; |
481 | 481 | } |
482 | 482 | } |
483 | - $new_memberData = []; |
|
483 | + $new_memberData=[]; |
|
484 | 484 | foreach ($memberData as $uid => $data) { |
485 | - $contest_count = 0; |
|
486 | - $rank_sum = 0; |
|
485 | + $contest_count=0; |
|
486 | + $rank_sum=0; |
|
487 | 487 | foreach ($data['contest_detial'] as $cid => $c) { |
488 | - $rank_sum += $c['rank']; |
|
489 | - $contest_count += 1; |
|
488 | + $rank_sum+=$c['rank']; |
|
489 | + $contest_count+=1; |
|
490 | 490 | } |
491 | - $temp = $data; |
|
492 | - $temp['uid'] = $uid; |
|
493 | - if($contest_count != 0){ |
|
494 | - $temp['rank_ave'] = $rank_sum/$contest_count; |
|
491 | + $temp=$data; |
|
492 | + $temp['uid']=$uid; |
|
493 | + if ($contest_count!=0) { |
|
494 | + $temp['rank_ave']=$rank_sum / $contest_count; |
|
495 | 495 | } |
496 | - array_push($new_memberData,$temp); |
|
496 | + array_push($new_memberData, $temp); |
|
497 | 497 | } |
498 | - $ret = [ |
|
498 | + $ret=[ |
|
499 | 499 | 'contest_list' => $allPracticeContest, |
500 | 500 | 'member_data' => $new_memberData |
501 | 501 | ]; |
@@ -504,58 +504,58 @@ discard block |
||
504 | 504 | |
505 | 505 | public function groupMemberPracticeTagStat($gid) |
506 | 506 | { |
507 | - $tags = $this->problemTags($gid); |
|
508 | - $tag_problems = []; |
|
507 | + $tags=$this->problemTags($gid); |
|
508 | + $tag_problems=[]; |
|
509 | 509 | |
510 | - $user_list = $this->userList($gid); |
|
510 | + $user_list=$this->userList($gid); |
|
511 | 511 | foreach ($tags as $tag) { |
512 | - $tag_problems[$tag] = DB::table('problem') |
|
513 | - ->join('group_problem_tag','problem.pid','=','group_problem_tag.pid') |
|
512 | + $tag_problems[$tag]=DB::table('problem') |
|
513 | + ->join('group_problem_tag', 'problem.pid', '=', 'group_problem_tag.pid') |
|
514 | 514 | ->where([ |
515 | 515 | 'group_problem_tag.gid' => $gid, |
516 | 516 | 'tag' => $tag |
517 | 517 | ]) |
518 | - ->select('group_problem_tag.pid as pid','pcode','title') |
|
518 | + ->select('group_problem_tag.pid as pid', 'pcode', 'title') |
|
519 | 519 | ->get()->all(); |
520 | 520 | } |
521 | - $all_problems = []; |
|
521 | + $all_problems=[]; |
|
522 | 522 | foreach ($tag_problems as &$tag_problem_set) { |
523 | 523 | foreach ($tag_problem_set as $problem) { |
524 | - $all_problems[$problem['pid']] = $problem; |
|
524 | + $all_problems[$problem['pid']]=$problem; |
|
525 | 525 | } |
526 | - $tag_problem_set = array_column($tag_problem_set,'pid'); |
|
526 | + $tag_problem_set=array_column($tag_problem_set, 'pid'); |
|
527 | 527 | } |
528 | - $submission_data = DB::table('submission') |
|
529 | - ->whereIn('pid',array_keys($all_problems)) |
|
530 | - ->whereIn('uid',array_column($user_list,'uid')) |
|
531 | - ->where('verdict','Accepted') |
|
532 | - ->select('pid','uid') |
|
528 | + $submission_data=DB::table('submission') |
|
529 | + ->whereIn('pid', array_keys($all_problems)) |
|
530 | + ->whereIn('uid', array_column($user_list, 'uid')) |
|
531 | + ->where('verdict', 'Accepted') |
|
532 | + ->select('pid', 'uid') |
|
533 | 533 | ->get()->all(); |
534 | 534 | |
535 | - $memberData = []; |
|
535 | + $memberData=[]; |
|
536 | 536 | foreach ($user_list as $member) { |
537 | - $completion = []; |
|
538 | - foreach($tag_problems as $tag => $problems) { |
|
539 | - $completion[$tag] = []; |
|
537 | + $completion=[]; |
|
538 | + foreach ($tag_problems as $tag => $problems) { |
|
539 | + $completion[$tag]=[]; |
|
540 | 540 | foreach ($problems as $problem) { |
541 | - $is_accepted = 0; |
|
541 | + $is_accepted=0; |
|
542 | 542 | foreach ($submission_data as $sd) { |
543 | - if($sd['pid'] == $problem && $sd['uid'] == $member['uid']){ |
|
544 | - $is_accepted = 1; |
|
543 | + if ($sd['pid']==$problem && $sd['uid']==$member['uid']) { |
|
544 | + $is_accepted=1; |
|
545 | 545 | break; |
546 | 546 | } |
547 | 547 | } |
548 | - $completion[$tag][$problem] = $is_accepted; |
|
548 | + $completion[$tag][$problem]=$is_accepted; |
|
549 | 549 | } |
550 | 550 | } |
551 | - array_push($memberData,[ |
|
551 | + array_push($memberData, [ |
|
552 | 552 | 'uid' => $member['uid'], |
553 | 553 | 'name' => $member['name'], |
554 | 554 | 'nick_name' => $member['nick_name'], |
555 | 555 | 'completion' => $completion, |
556 | 556 | ]); |
557 | 557 | } |
558 | - $ret = [ |
|
558 | + $ret=[ |
|
559 | 559 | 'all_problems' => $all_problems, |
560 | 560 | 'tag_problems' => $tag_problems, |
561 | 561 | 'member_data' => $memberData |
@@ -566,29 +566,29 @@ discard block |
||
566 | 566 | public function refreshElo($gid) |
567 | 567 | { |
568 | 568 | DB::table('group_rated_change_log') |
569 | - ->where('gid',$gid) |
|
569 | + ->where('gid', $gid) |
|
570 | 570 | ->delete(); |
571 | 571 | DB::table('group_member') |
572 | - ->where('gid',$gid) |
|
572 | + ->where('gid', $gid) |
|
573 | 573 | ->update([ |
574 | 574 | 'ranking' => 1500 |
575 | 575 | ]); |
576 | - $contests = DB::table('contest') |
|
576 | + $contests=DB::table('contest') |
|
577 | 577 | ->where([ |
578 | 578 | 'gid' => $gid, |
579 | 579 | 'practice' => 1 |
580 | 580 | ]) |
581 | - ->where('end_time','<',date("Y-m-d H:i:s")) |
|
581 | + ->where('end_time', '<', date("Y-m-d H:i:s")) |
|
582 | 582 | ->select('cid') |
583 | 583 | ->orderBy('end_time') |
584 | 584 | ->get()->all(); |
585 | 585 | |
586 | - if(empty($contests)) { |
|
586 | + if (empty($contests)) { |
|
587 | 587 | return true; |
588 | 588 | } |
589 | 589 | |
590 | 590 | foreach ($contests as $contest) { |
591 | - $calc = new GroupRatingCalculator($contest['cid']); |
|
591 | + $calc=new GroupRatingCalculator($contest['cid']); |
|
592 | 592 | $calc->calculate(); |
593 | 593 | $calc->storage(); |
594 | 594 | } |
@@ -596,23 +596,23 @@ discard block |
||
596 | 596 | return true; |
597 | 597 | } |
598 | 598 | |
599 | - public function getEloChangeLog($gid,$uid) |
|
599 | + public function getEloChangeLog($gid, $uid) |
|
600 | 600 | { |
601 | - $ret = DB::table('group_rated_change_log') |
|
602 | - ->join('contest','group_rated_change_log.cid','=','contest.cid') |
|
601 | + $ret=DB::table('group_rated_change_log') |
|
602 | + ->join('contest', 'group_rated_change_log.cid', '=', 'contest.cid') |
|
603 | 603 | ->where([ |
604 | 604 | 'group_rated_change_log.gid' => $gid, |
605 | 605 | 'group_rated_change_log.uid' => $uid |
606 | 606 | ])->select('group_rated_change_log.cid as cid', 'contest.name as name', 'ranking', 'end_time') |
607 | 607 | ->orderBy('contest.end_time') |
608 | 608 | ->get()->all(); |
609 | - $begin = [ |
|
609 | + $begin=[ |
|
610 | 610 | 'cid' => -1, |
611 | 611 | 'name' => '', |
612 | 612 | 'ranking' => '1500', |
613 | - 'end_time' => date("Y-m-d H:i:s",(strtotime($ret[0]['end_time'] ?? time()) - 3600*24)), |
|
613 | + 'end_time' => date("Y-m-d H:i:s", (strtotime($ret[0]['end_time'] ?? time())-3600 * 24)), |
|
614 | 614 | ]; |
615 | - $ret = array_prepend($ret,$begin); |
|
615 | + $ret=array_prepend($ret, $begin); |
|
616 | 616 | return $ret; |
617 | 617 | } |
618 | 618 | } |