@@ -9,7 +9,7 @@ |
||
| 9 | 9 | { |
| 10 | 10 | use SoftDeletes; |
| 11 | 11 | |
| 12 | - protected $fillable = ['user_id', 'abuse_id', 'reason', 'removed_at']; |
|
| 12 | + protected $fillable=['user_id', 'abuse_id', 'reason', 'removed_at']; |
|
| 13 | 13 | |
| 14 | 14 | public function abuse() { |
| 15 | 15 | return $this->belongsTo('\App\Models\Eloquent\Abuse'); |
@@ -17,7 +17,7 @@ |
||
| 17 | 17 | |
| 18 | 18 | public function fetch() |
| 19 | 19 | { |
| 20 | - $list=DB::table($this->table)->orderBy('created_at','desc')->get()->all(); |
|
| 20 | + $list=DB::table($this->table)->orderBy('created_at', 'desc')->get()->all(); |
|
| 21 | 21 | if (empty($list)) { |
| 22 | 22 | return []; |
| 23 | 23 | } |
@@ -9,12 +9,12 @@ |
||
| 9 | 9 | { |
| 10 | 10 | public static function info($ltxsource, $type="png") |
| 11 | 11 | { |
| 12 | - if(!in_array($type,['png','svg'])) return []; |
|
| 12 | + if (!in_array($type, ['png', 'svg'])) return []; |
|
| 13 | 13 | $url=route("latex.$type", ['ltxsource' => $ltxsource]); |
| 14 | - $image = new Imagick(); |
|
| 14 | + $image=new Imagick(); |
|
| 15 | 15 | $image->readImageBlob(Storage::get('latex-svg/'.urlencode($ltxsource).'.svg')); |
| 16 | - $width = $image->getImageWidth(); |
|
| 17 | - $height = $image->getImageHeight(); |
|
| 18 | - return [$url,$width/5,$height/5]; |
|
| 16 | + $width=$image->getImageWidth(); |
|
| 17 | + $height=$image->getImageHeight(); |
|
| 18 | + return [$url, $width / 5, $height / 5]; |
|
| 19 | 19 | } |
| 20 | 20 | } |
@@ -9,7 +9,9 @@ |
||
| 9 | 9 | { |
| 10 | 10 | public static function info($ltxsource, $type="png") |
| 11 | 11 | { |
| 12 | - if(!in_array($type,['png','svg'])) return []; |
|
| 12 | + if(!in_array($type,['png','svg'])) { |
|
| 13 | + return []; |
|
| 14 | + } |
|
| 13 | 15 | $url=route("latex.$type", ['ltxsource' => $ltxsource]); |
| 14 | 16 | $image = new Imagick(); |
| 15 | 17 | $image->readImageBlob(Storage::get('latex-svg/'.urlencode($ltxsource).'.svg')); |
@@ -115,8 +115,8 @@ discard block |
||
| 115 | 115 | |
| 116 | 116 | public function gcode($cid) |
| 117 | 117 | { |
| 118 | - $gid = $this->gid($cid); |
|
| 119 | - return DB::table('group')->where('gid','=',$gid)->first()["gcode"]; |
|
| 118 | + $gid=$this->gid($cid); |
|
| 119 | + return DB::table('group')->where('gid', '=', $gid)->first()["gcode"]; |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | public function runningContest() |
@@ -141,19 +141,19 @@ discard block |
||
| 141 | 141 | |
| 142 | 142 | public function listForSetting($gid) |
| 143 | 143 | { |
| 144 | - $uid = Auth::user()->id; |
|
| 145 | - $group_contests = DB::table('contest') |
|
| 146 | - ->where('gid',$gid) |
|
| 147 | - ->orderBy('begin_time','desc') |
|
| 144 | + $uid=Auth::user()->id; |
|
| 145 | + $group_contests=DB::table('contest') |
|
| 146 | + ->where('gid', $gid) |
|
| 147 | + ->orderBy('begin_time', 'desc') |
|
| 148 | 148 | ->get()->all(); |
| 149 | - $groupModel = new GroupModel(); |
|
| 150 | - $group_clearance = $groupModel->judgeClearance($gid,$uid); |
|
| 149 | + $groupModel=new GroupModel(); |
|
| 150 | + $group_clearance=$groupModel->judgeClearance($gid, $uid); |
|
| 151 | 151 | foreach ($group_contests as &$contest) { |
| 152 | - $contest['is_admin'] = ($contest['assign_uid'] == $uid || $group_clearance == 3); |
|
| 153 | - $contest['begin_stamps'] = strtotime($contest['begin_time']); |
|
| 154 | - $contest['end_stamps'] = strtotime($contest['end_time']); |
|
| 155 | - $contest['status'] = time() >= $contest['end_stamps'] ? 1 |
|
| 156 | - : (time() <= $contest['begin_stamps'] ? -1 : 0); |
|
| 152 | + $contest['is_admin']=($contest['assign_uid']==$uid || $group_clearance==3); |
|
| 153 | + $contest['begin_stamps']=strtotime($contest['begin_time']); |
|
| 154 | + $contest['end_stamps']=strtotime($contest['end_time']); |
|
| 155 | + $contest['status']=time()>=$contest['end_stamps'] ? 1 |
|
| 156 | + : (time()<=$contest['begin_stamps'] ? -1 : 0); |
|
| 157 | 157 | $contest["rule_parsed"]=$this->rule[$contest["rule"]]; |
| 158 | 158 | $contest["date_parsed"]=[ |
| 159 | 159 | "date"=>date_format(date_create($contest["begin_time"]), 'j'), |
@@ -161,11 +161,11 @@ discard block |
||
| 161 | 161 | ]; |
| 162 | 162 | $contest["length"]=$this->calcLength($contest["begin_time"], $contest["end_time"]); |
| 163 | 163 | } |
| 164 | - usort($group_contests,function($a,$b){ |
|
| 165 | - if($a['is_admin'] == $b['is_admin']){ |
|
| 166 | - return $b['begin_stamps'] - $a['begin_stamps']; |
|
| 164 | + usort($group_contests, function($a, $b) { |
|
| 165 | + if ($a['is_admin']==$b['is_admin']) { |
|
| 166 | + return $b['begin_stamps']-$a['begin_stamps']; |
|
| 167 | 167 | } |
| 168 | - return $b['is_admin'] - $a['is_admin']; |
|
| 168 | + return $b['is_admin']-$a['is_admin']; |
|
| 169 | 169 | }); |
| 170 | 170 | return $group_contests; |
| 171 | 171 | } |
@@ -176,9 +176,9 @@ discard block |
||
| 176 | 176 | // "gid"=>$gid |
| 177 | 177 | // ])->orderBy('begin_time', 'desc')->get()->all(); |
| 178 | 178 | $preQuery=DB::table($this->tableName); |
| 179 | - $paginator=$preQuery->where('gid','=',$gid)->orderBy('begin_time', 'desc')->paginate(10); |
|
| 179 | + $paginator=$preQuery->where('gid', '=', $gid)->orderBy('begin_time', 'desc')->paginate(10); |
|
| 180 | 180 | $contest_list=$paginator->all(); |
| 181 | - if(empty($contest_list)){ |
|
| 181 | + if (empty($contest_list)) { |
|
| 182 | 182 | return null; |
| 183 | 183 | } |
| 184 | 184 | |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | ])->first()["rule"]; |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - public function list($filter,$uid) |
|
| 206 | + public function list($filter, $uid) |
|
| 207 | 207 | { |
| 208 | 208 | if ($uid) { |
| 209 | 209 | //$paginator=DB::select('SELECT DISTINCT contest.* FROM group_member inner join contest on group_member.gid=contest.gid left join contest_participant on contest.cid=contest_participant.cid where (public=1 and audit=1) or (group_member.uid=:uid and group_member.role>0 and (contest_participant.uid=:uidd or ISNULL(contest_participant.uid)) and (registration=0 or (registration=1 and not ISNULL(contest_participant.uid))))',["uid"=>$uid,"uidd"=>$uid])->paginate(10); |
@@ -227,15 +227,15 @@ discard block |
||
| 227 | 227 | if ($filter['practice']) { |
| 228 | 228 | $paginator=$paginator->where(["practice"=>$filter['practice']]); |
| 229 | 229 | } |
| 230 | - $paginator = $paginator ->paginate(10); |
|
| 231 | - }elseif($filter['public']=='0'){ |
|
| 230 | + $paginator=$paginator ->paginate(10); |
|
| 231 | + }elseif ($filter['public']=='0') { |
|
| 232 | 232 | $paginator=DB::table('group_member') |
| 233 | 233 | ->groupBy('contest.cid') |
| 234 | 234 | ->select('contest.*') |
| 235 | 235 | ->join('contest', 'group_member.gid', '=', 'contest.gid') |
| 236 | 236 | ->leftJoin('contest_participant', 'contest.cid', '=', 'contest_participant.cid') |
| 237 | 237 | ->where( |
| 238 | - function ($query) use ($filter,$uid) { |
|
| 238 | + function($query) use ($filter, $uid) { |
|
| 239 | 239 | if ($filter['rule']) { |
| 240 | 240 | $query=$query->where(["rule"=>$filter['rule']]); |
| 241 | 241 | } |
@@ -258,14 +258,14 @@ discard block |
||
| 258 | 258 | ) |
| 259 | 259 | ->orderBy('contest.begin_time', 'desc') |
| 260 | 260 | ->paginate(10); |
| 261 | - }else{ |
|
| 261 | + } else { |
|
| 262 | 262 | $paginator=DB::table('group_member') |
| 263 | 263 | ->groupBy('contest.cid') |
| 264 | 264 | ->select('contest.*') |
| 265 | 265 | ->join('contest', 'group_member.gid', '=', 'contest.gid') |
| 266 | 266 | ->leftJoin('contest_participant', 'contest.cid', '=', 'contest_participant.cid') |
| 267 | 267 | ->where( |
| 268 | - function ($query) use ($filter) { |
|
| 268 | + function($query) use ($filter) { |
|
| 269 | 269 | if ($filter['rule']) { |
| 270 | 270 | $query=$query->where(["rule"=>$filter['rule']]); |
| 271 | 271 | } |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | } |
| 287 | 287 | ) |
| 288 | 288 | ->orWhere( |
| 289 | - function ($query) use ($filter,$uid) { |
|
| 289 | + function($query) use ($filter, $uid) { |
|
| 290 | 290 | if ($filter['rule']) { |
| 291 | 291 | $query=$query->where(["rule"=>$filter['rule']]); |
| 292 | 292 | } |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | if ($filter['practice']) { |
| 333 | 333 | $paginator=$paginator->where(["practice"=>$filter['practice']]); |
| 334 | 334 | } |
| 335 | - $paginator = $paginator ->paginate(10); |
|
| 335 | + $paginator=$paginator ->paginate(10); |
|
| 336 | 336 | } |
| 337 | 337 | $contest_list=$paginator->all(); |
| 338 | 338 | foreach ($contest_list as &$c) { |
@@ -370,14 +370,14 @@ discard block |
||
| 370 | 370 | } |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | - public function registContest($cid,$uid) |
|
| 373 | + public function registContest($cid, $uid) |
|
| 374 | 374 | { |
| 375 | 375 | $registered=DB::table("contest_participant")->where([ |
| 376 | 376 | "cid"=>$cid, |
| 377 | 377 | "uid"=>$uid |
| 378 | 378 | ])->first(); |
| 379 | 379 | |
| 380 | - if(empty($registered)){ |
|
| 380 | + if (empty($registered)) { |
|
| 381 | 381 | DB::table("contest_participant")->insert([ |
| 382 | 382 | "cid"=>$cid, |
| 383 | 383 | "uid"=>$uid, |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | ]); |
| 386 | 386 | $name=User::find($uid)->name; |
| 387 | 387 | $contest=$this->basic($cid); |
| 388 | - $url=route('contest.detail',['cid' => $cid]); |
|
| 388 | + $url=route('contest.detail', ['cid' => $cid]); |
|
| 389 | 389 | sendMessage([ |
| 390 | 390 | 'receiver' => $uid, |
| 391 | 391 | 'sender' => 1, // potential bugs |
@@ -419,9 +419,9 @@ discard block |
||
| 419 | 419 | public function problems($cid) |
| 420 | 420 | { |
| 421 | 421 | return DB::table('contest_problem') |
| 422 | - ->join('problem','contest_problem.pid','=','problem.pid') |
|
| 423 | - ->where('cid',$cid) |
|
| 424 | - ->select('problem.pid as pid','pcode','number') |
|
| 422 | + ->join('problem', 'contest_problem.pid', '=', 'problem.pid') |
|
| 423 | + ->where('cid', $cid) |
|
| 424 | + ->select('problem.pid as pid', 'pcode', 'number') |
|
| 425 | 425 | ->orderBy('number') |
| 426 | 426 | ->get()->all(); |
| 427 | 427 | } |
@@ -443,18 +443,18 @@ discard block |
||
| 443 | 443 | $end_time=strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]); |
| 444 | 444 | |
| 445 | 445 | foreach ($problemSet as &$p) { |
| 446 | - if($p['practice']){ |
|
| 447 | - $tags = DB::table("group_problem_tag") |
|
| 448 | - ->where('gid',$p['gid']) |
|
| 449 | - ->where('pid',$p['pid']) |
|
| 446 | + if ($p['practice']) { |
|
| 447 | + $tags=DB::table("group_problem_tag") |
|
| 448 | + ->where('gid', $p['gid']) |
|
| 449 | + ->where('pid', $p['pid']) |
|
| 450 | 450 | ->get()->all(); |
| 451 | - $tags_arr = []; |
|
| 452 | - if(!empty($tags)){ |
|
| 451 | + $tags_arr=[]; |
|
| 452 | + if (!empty($tags)) { |
|
| 453 | 453 | foreach ($tags as $value) { |
| 454 | - array_push($tags_arr,$value['tag']); |
|
| 454 | + array_push($tags_arr, $value['tag']); |
|
| 455 | 455 | } |
| 456 | 456 | } |
| 457 | - $p['tags'] = $tags_arr; |
|
| 457 | + $p['tags']=$tags_arr; |
|
| 458 | 458 | } |
| 459 | 459 | if ($contest_rule==1) { |
| 460 | 460 | $prob_stat=DB::table("submission")->select( |
@@ -715,7 +715,7 @@ discard block |
||
| 715 | 715 | "problem_detail" => $prob_detail |
| 716 | 716 | ]; |
| 717 | 717 | } |
| 718 | - usort($ret, function ($a, $b) { |
|
| 718 | + usort($ret, function($a, $b) { |
|
| 719 | 719 | if ($a["score"]==$b["score"]) { |
| 720 | 720 | if ($a["penalty"]==$b["penalty"]) { |
| 721 | 721 | return 0; |
@@ -762,7 +762,7 @@ discard block |
||
| 762 | 762 | "problem_detail" => $prob_detail |
| 763 | 763 | ]; |
| 764 | 764 | } |
| 765 | - usort($ret, function ($a, $b) { |
|
| 765 | + usort($ret, function($a, $b) { |
|
| 766 | 766 | if ($a["score"]==$b["score"]) { |
| 767 | 767 | if ($a["solved"]==$b["solved"]) { |
| 768 | 768 | return 0; |
@@ -784,7 +784,7 @@ discard block |
||
| 784 | 784 | return $ret; |
| 785 | 785 | } |
| 786 | 786 | |
| 787 | - public function contestRank($cid, $uid = 0) |
|
| 787 | + public function contestRank($cid, $uid=0) |
|
| 788 | 788 | { |
| 789 | 789 | // [ToDo] If the current user's in the organizer group show nick name |
| 790 | 790 | // [ToDo] The participants determination |
@@ -801,36 +801,36 @@ discard block |
||
| 801 | 801 | "gid" => $contest_info["gid"] |
| 802 | 802 | ])->where("role", ">", 0)->first()); |
| 803 | 803 | |
| 804 | - $clearance = $this -> judgeClearance($cid, $uid); |
|
| 804 | + $clearance=$this -> judgeClearance($cid, $uid); |
|
| 805 | 805 | |
| 806 | 806 | /** New Version With MySQL */ |
| 807 | 807 | $end_time=strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]); |
| 808 | - $contest_eloquent = EloquentContestModel::find($cid); |
|
| 808 | + $contest_eloquent=EloquentContestModel::find($cid); |
|
| 809 | 809 | |
| 810 | - if(time() < $end_time){ |
|
| 811 | - if($clearance == 3){ |
|
| 810 | + if (time()<$end_time) { |
|
| 811 | + if ($clearance==3) { |
|
| 812 | 812 | $contestRankRaw=Cache::tags(['contest', 'rank'])->get("contestAdmin$cid"); |
| 813 | - }else{ |
|
| 813 | + } else { |
|
| 814 | 814 | $contestRankRaw=Cache::tags(['contest', 'rank'])->get($cid); |
| 815 | 815 | } |
| 816 | - if(!isset($contestRankRaw)){ |
|
| 816 | + if (!isset($contestRankRaw)) { |
|
| 817 | 817 | $contestRankRaw=$contest_eloquent->rankRefresh(); |
| 818 | 818 | } |
| 819 | - }else{ |
|
| 820 | - if($clearance == 3){ |
|
| 819 | + } else { |
|
| 820 | + if ($clearance==3) { |
|
| 821 | 821 | $contestRankRaw=Cache::tags(['contest', 'rank'])->get("contestAdmin$cid"); |
| 822 | 822 | if (!isset($contestRankRaw)) { |
| 823 | 823 | $contestRankRaw=$this->getContestRankFromMySQL($cid); |
| 824 | - if(!isset($contestRankRaw)){ |
|
| 824 | + if (!isset($contestRankRaw)) { |
|
| 825 | 825 | $contestRankRaw=$contest_eloquent->rankRefresh(); |
| 826 | 826 | $this->storeContestRankInMySQL($cid, $contestRankRaw); |
| 827 | 827 | } |
| 828 | 828 | } |
| 829 | - }else{ |
|
| 829 | + } else { |
|
| 830 | 830 | $contestRankRaw=$this->getContestRankFromMySQL($cid); |
| 831 | - if(!isset($contestRankRaw)){ |
|
| 831 | + if (!isset($contestRankRaw)) { |
|
| 832 | 832 | $contestRankRaw=Cache::tags(['contest', 'rank'])->get($cid); |
| 833 | - if(!isset($contestRankRaw)){ |
|
| 833 | + if (!isset($contestRankRaw)) { |
|
| 834 | 834 | $contestRankRaw=$contest_eloquent->rankRefresh(); |
| 835 | 835 | } |
| 836 | 836 | $this->storeContestRankInMySQL($cid, $contestRankRaw); |
@@ -848,15 +848,15 @@ discard block |
||
| 848 | 848 | // $contestRankRaw=$this->contestRankCache($cid); |
| 849 | 849 | // } |
| 850 | 850 | // } |
| 851 | - if($contest_info["rule"]==1){ |
|
| 851 | + if ($contest_info["rule"]==1) { |
|
| 852 | 852 | foreach ($contestRankRaw as &$cr) { |
| 853 | - $solved = 0; |
|
| 854 | - foreach($cr['problem_detail'] as $pd){ |
|
| 855 | - if(!empty($pd['solved_time_parsed'])){ |
|
| 856 | - $solved ++; |
|
| 853 | + $solved=0; |
|
| 854 | + foreach ($cr['problem_detail'] as $pd) { |
|
| 855 | + if (!empty($pd['solved_time_parsed'])) { |
|
| 856 | + $solved++; |
|
| 857 | 857 | } |
| 858 | 858 | } |
| 859 | - $cr['solved'] = $solved; |
|
| 859 | + $cr['solved']=$solved; |
|
| 860 | 860 | } |
| 861 | 861 | } |
| 862 | 862 | |
@@ -905,16 +905,16 @@ discard block |
||
| 905 | 905 | |
| 906 | 906 | public function getClarificationList($cid) |
| 907 | 907 | { |
| 908 | - $uid = Auth::user()->id; |
|
| 909 | - $clearance = $this -> judgeClearance($cid, $uid); |
|
| 910 | - if($clearance == 3){ |
|
| 908 | + $uid=Auth::user()->id; |
|
| 909 | + $clearance=$this -> judgeClearance($cid, $uid); |
|
| 910 | + if ($clearance==3) { |
|
| 911 | 911 | return DB::table("contest_clarification")->where([ |
| 912 | 912 | "cid"=>$cid |
| 913 | 913 | ])->orderBy('created_at', 'desc')->get()->all(); |
| 914 | - }else{ |
|
| 914 | + } else { |
|
| 915 | 915 | return DB::table("contest_clarification")->where([ |
| 916 | 916 | "cid"=>$cid |
| 917 | - ])->where(function ($query) { |
|
| 917 | + ])->where(function($query) { |
|
| 918 | 918 | $query->where([ |
| 919 | 919 | "public"=>1 |
| 920 | 920 | ])->orWhere([ |
@@ -1060,7 +1060,7 @@ discard block |
||
| 1060 | 1060 | public function getContestRecord($filter, $cid) |
| 1061 | 1061 | { |
| 1062 | 1062 | $basicInfo=$this->basic($cid); |
| 1063 | - $userInfo=DB::table('group_member')->where('gid',$basicInfo["gid"])->where('uid',Auth::user()->id)->get()->first(); |
|
| 1063 | + $userInfo=DB::table('group_member')->where('gid', $basicInfo["gid"])->where('uid', Auth::user()->id)->get()->first(); |
|
| 1064 | 1064 | $problemSet_temp=DB::table("contest_problem")->join("problem", "contest_problem.pid", "=", "problem.pid")->where([ |
| 1065 | 1065 | "cid"=>$cid |
| 1066 | 1066 | ])->orderBy('ncode', 'asc')->select("ncode", "alias", "contest_problem.pid as pid", "title", "points", "tot_score")->get()->all(); |
@@ -1073,14 +1073,14 @@ discard block |
||
| 1073 | 1073 | $end_time=strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]); |
| 1074 | 1074 | $contestEnd=time()>$end_time; |
| 1075 | 1075 | |
| 1076 | - $filter['pid'] = array_search($filter['ncode'], array_column($problemSet_temp, 'ncode')); |
|
| 1077 | - if($filter['pid']==false){ |
|
| 1078 | - $filter['pid'] = null; |
|
| 1079 | - }else{ |
|
| 1080 | - $filter['pid'] = $problemSet_temp[$filter['pid']]['pid']; |
|
| 1076 | + $filter['pid']=array_search($filter['ncode'], array_column($problemSet_temp, 'ncode')); |
|
| 1077 | + if ($filter['pid']==false) { |
|
| 1078 | + $filter['pid']=null; |
|
| 1079 | + } else { |
|
| 1080 | + $filter['pid']=$problemSet_temp[$filter['pid']]['pid']; |
|
| 1081 | 1081 | } |
| 1082 | 1082 | |
| 1083 | - if($userInfo==null || $userInfo["role"]!=3){ |
|
| 1083 | + if ($userInfo==null || $userInfo["role"]!=3) { |
|
| 1084 | 1084 | if ($basicInfo["status_visibility"]==2) { |
| 1085 | 1085 | // View all |
| 1086 | 1086 | $paginator=DB::table("submission")->where([ |
@@ -1094,7 +1094,7 @@ discard block |
||
| 1094 | 1094 | "users.id", |
| 1095 | 1095 | "=", |
| 1096 | 1096 | "submission.uid" |
| 1097 | - )->where(function ($query) use ($frozen_time) { |
|
| 1097 | + )->where(function($query) use ($frozen_time) { |
|
| 1098 | 1098 | $query->where( |
| 1099 | 1099 | "submission_date", |
| 1100 | 1100 | "<", |
@@ -1121,15 +1121,15 @@ discard block |
||
| 1121 | 1121 | 'desc' |
| 1122 | 1122 | ); |
| 1123 | 1123 | |
| 1124 | - if($filter["pid"]){ |
|
| 1124 | + if ($filter["pid"]) { |
|
| 1125 | 1125 | $paginator=$paginator->where(["pid"=>$filter["pid"]]); |
| 1126 | 1126 | } |
| 1127 | 1127 | |
| 1128 | - if($filter["result"]){ |
|
| 1128 | + if ($filter["result"]) { |
|
| 1129 | 1129 | $paginator=$paginator->where(["verdict"=>$filter["result"]]); |
| 1130 | 1130 | } |
| 1131 | 1131 | |
| 1132 | - if($filter["account"]){ |
|
| 1132 | + if ($filter["account"]) { |
|
| 1133 | 1133 | $paginator=$paginator->where(["name"=>$filter["account"]]); |
| 1134 | 1134 | } |
| 1135 | 1135 | |
@@ -1165,15 +1165,15 @@ discard block |
||
| 1165 | 1165 | 'desc' |
| 1166 | 1166 | ); |
| 1167 | 1167 | |
| 1168 | - if($filter["pid"]){ |
|
| 1168 | + if ($filter["pid"]) { |
|
| 1169 | 1169 | $paginator=$paginator->where(["pid"=>$filter["pid"]]); |
| 1170 | 1170 | } |
| 1171 | 1171 | |
| 1172 | - if($filter["result"]){ |
|
| 1172 | + if ($filter["result"]) { |
|
| 1173 | 1173 | $paginator=$paginator->where(["verdict"=>$filter["result"]]); |
| 1174 | 1174 | } |
| 1175 | 1175 | |
| 1176 | - if($filter["account"]){ |
|
| 1176 | + if ($filter["account"]) { |
|
| 1177 | 1177 | $paginator=$paginator->where(["name"=>$filter["account"]]); |
| 1178 | 1178 | } |
| 1179 | 1179 | |
@@ -1184,7 +1184,7 @@ discard block |
||
| 1184 | 1184 | "records"=>[] |
| 1185 | 1185 | ]; |
| 1186 | 1186 | } |
| 1187 | - }else{ |
|
| 1187 | + } else { |
|
| 1188 | 1188 | if ($basicInfo["status_visibility"]==2) { |
| 1189 | 1189 | // View all |
| 1190 | 1190 | $paginator=DB::table("submission")->where([ |
@@ -1216,15 +1216,15 @@ discard block |
||
| 1216 | 1216 | 'desc' |
| 1217 | 1217 | ); |
| 1218 | 1218 | |
| 1219 | - if($filter["pid"]){ |
|
| 1219 | + if ($filter["pid"]) { |
|
| 1220 | 1220 | $paginator=$paginator->where(["pid"=>$filter["pid"]]); |
| 1221 | 1221 | } |
| 1222 | 1222 | |
| 1223 | - if($filter["result"]){ |
|
| 1223 | + if ($filter["result"]) { |
|
| 1224 | 1224 | $paginator=$paginator->where(["verdict"=>$filter["result"]]); |
| 1225 | 1225 | } |
| 1226 | 1226 | |
| 1227 | - if($filter["account"]){ |
|
| 1227 | + if ($filter["account"]) { |
|
| 1228 | 1228 | $paginator=$paginator->where(["name"=>$filter["account"]]); |
| 1229 | 1229 | } |
| 1230 | 1230 | |
@@ -1260,15 +1260,15 @@ discard block |
||
| 1260 | 1260 | 'desc' |
| 1261 | 1261 | ); |
| 1262 | 1262 | |
| 1263 | - if($filter["pid"]){ |
|
| 1263 | + if ($filter["pid"]) { |
|
| 1264 | 1264 | $paginator=$paginator->where(["pid"=>$filter["pid"]]); |
| 1265 | 1265 | } |
| 1266 | 1266 | |
| 1267 | - if($filter["result"]){ |
|
| 1267 | + if ($filter["result"]) { |
|
| 1268 | 1268 | $paginator=$paginator->where(["verdict"=>$filter["result"]]); |
| 1269 | 1269 | } |
| 1270 | 1270 | |
| 1271 | - if($filter["account"]){ |
|
| 1271 | + if ($filter["account"]) { |
|
| 1272 | 1272 | $paginator=$paginator->where(["name"=>$filter["account"]]); |
| 1273 | 1273 | } |
| 1274 | 1274 | |
@@ -1324,21 +1324,21 @@ discard block |
||
| 1324 | 1324 | if ($uid==0) { |
| 1325 | 1325 | return 0; |
| 1326 | 1326 | } |
| 1327 | - $groupModel = new GroupModel(); |
|
| 1327 | + $groupModel=new GroupModel(); |
|
| 1328 | 1328 | $contest_info=DB::table("contest")->where("cid", $cid)->first(); |
| 1329 | - $userInfo=DB::table('group_member')->where('gid',$contest_info["gid"])->where('uid',$uid)->get()->first(); |
|
| 1329 | + $userInfo=DB::table('group_member')->where('gid', $contest_info["gid"])->where('uid', $uid)->get()->first(); |
|
| 1330 | 1330 | |
| 1331 | - if(empty($contest_info)){ |
|
| 1331 | + if (empty($contest_info)) { |
|
| 1332 | 1332 | // contest not exist |
| 1333 | 1333 | return 0; |
| 1334 | 1334 | } |
| 1335 | 1335 | |
| 1336 | - if($uid == $contest_info['assign_uid'] || $groupModel->judgeClearance($contest_info['gid'],$uid) == 3){ |
|
| 1336 | + if ($uid==$contest_info['assign_uid'] || $groupModel->judgeClearance($contest_info['gid'], $uid)==3) { |
|
| 1337 | 1337 | return 3; |
| 1338 | 1338 | } |
| 1339 | 1339 | |
| 1340 | - $contest_started = strtotime($contest_info['begin_time']) < time(); |
|
| 1341 | - $contest_ended = strtotime($contest_info['end_time']) < time(); |
|
| 1340 | + $contest_started=strtotime($contest_info['begin_time'])<time(); |
|
| 1341 | + $contest_ended=strtotime($contest_info['end_time'])<time(); |
|
| 1342 | 1342 | if (!$contest_started) { |
| 1343 | 1343 | // not started or do not exist |
| 1344 | 1344 | return 0; |
@@ -1429,12 +1429,12 @@ discard block |
||
| 1429 | 1429 | public function updateProfessionalRate($cid) |
| 1430 | 1430 | { |
| 1431 | 1431 | $basic=$this->basic($cid); |
| 1432 | - if($basic["rated"]&&!$basic["is_rated"]){ |
|
| 1432 | + if ($basic["rated"] && !$basic["is_rated"]) { |
|
| 1433 | 1433 | $ratingCalculator=new RatingCalculator($cid); |
| 1434 | - if($ratingCalculator->calculate()){ |
|
| 1434 | + if ($ratingCalculator->calculate()) { |
|
| 1435 | 1435 | $ratingCalculator->storage(); |
| 1436 | 1436 | return true; |
| 1437 | - }else{ |
|
| 1437 | + } else { |
|
| 1438 | 1438 | return false; |
| 1439 | 1439 | } |
| 1440 | 1440 | } else { |
@@ -1442,26 +1442,26 @@ discard block |
||
| 1442 | 1442 | } |
| 1443 | 1443 | } |
| 1444 | 1444 | |
| 1445 | - public function contestUpdate($cid,$data,$problems) |
|
| 1445 | + public function contestUpdate($cid, $data, $problems) |
|
| 1446 | 1446 | { |
| 1447 | - if($problems !== false){ |
|
| 1448 | - $old_problmes = array_column( |
|
| 1447 | + if ($problems!==false) { |
|
| 1448 | + $old_problmes=array_column( |
|
| 1449 | 1449 | DB::table('contest_problem') |
| 1450 | - ->where('cid',$cid) |
|
| 1450 | + ->where('cid', $cid) |
|
| 1451 | 1451 | ->get()->all(), |
| 1452 | 1452 | 'pid' |
| 1453 | 1453 | ); |
| 1454 | - DB::transaction(function () use ($cid, $data, $problems,$old_problmes) { |
|
| 1454 | + DB::transaction(function() use ($cid, $data, $problems, $old_problmes) { |
|
| 1455 | 1455 | DB::table($this->tableName) |
| 1456 | - ->where('cid',$cid) |
|
| 1456 | + ->where('cid', $cid) |
|
| 1457 | 1457 | ->update($data); |
| 1458 | 1458 | DB::table('contest_problem') |
| 1459 | - ->where('cid',$cid) |
|
| 1459 | + ->where('cid', $cid) |
|
| 1460 | 1460 | ->delete(); |
| 1461 | - $new_problems = []; |
|
| 1461 | + $new_problems=[]; |
|
| 1462 | 1462 | foreach ($problems as $p) { |
| 1463 | 1463 | $pid=DB::table("problem")->where(["pcode"=>$p["pcode"]])->select("pid")->first()["pid"]; |
| 1464 | - array_push($new_problems,$pid); |
|
| 1464 | + array_push($new_problems, $pid); |
|
| 1465 | 1465 | DB::table("contest_problem")->insert([ |
| 1466 | 1466 | "cid"=>$cid, |
| 1467 | 1467 | "number"=>$p["number"], |
@@ -1471,29 +1471,29 @@ discard block |
||
| 1471 | 1471 | "points"=>$p["points"] |
| 1472 | 1472 | ]); |
| 1473 | 1473 | } |
| 1474 | - foreach($old_problmes as $op) { |
|
| 1475 | - if(!in_array($op,$new_problems)){ |
|
| 1474 | + foreach ($old_problmes as $op) { |
|
| 1475 | + if (!in_array($op, $new_problems)) { |
|
| 1476 | 1476 | DB::table('submission') |
| 1477 | - ->where('cid',$cid) |
|
| 1478 | - ->where('pid',$op) |
|
| 1477 | + ->where('cid', $cid) |
|
| 1478 | + ->where('pid', $op) |
|
| 1479 | 1479 | ->delete(); |
| 1480 | 1480 | } |
| 1481 | 1481 | } |
| 1482 | 1482 | }, 5); |
| 1483 | - $contestRankRaw = $this->contestRankCache($cid); |
|
| 1483 | + $contestRankRaw=$this->contestRankCache($cid); |
|
| 1484 | 1484 | Cache::tags(['contest', 'rank'])->put($cid, $contestRankRaw); |
| 1485 | 1485 | Cache::tags(['contest', 'rank'])->put("contestAdmin$cid", $contestRankRaw); |
| 1486 | - }else{ |
|
| 1486 | + } else { |
|
| 1487 | 1487 | DB::table($this->tableName) |
| 1488 | - ->where('cid',$cid) |
|
| 1488 | + ->where('cid', $cid) |
|
| 1489 | 1489 | ->update($data); |
| 1490 | 1490 | } |
| 1491 | 1491 | } |
| 1492 | 1492 | |
| 1493 | - public function contestUpdateProblem($cid,$problems) |
|
| 1493 | + public function contestUpdateProblem($cid, $problems) |
|
| 1494 | 1494 | { |
| 1495 | 1495 | DB::table('contest_problem') |
| 1496 | - ->where('cid',$cid) |
|
| 1496 | + ->where('cid', $cid) |
|
| 1497 | 1497 | ->delete(); |
| 1498 | 1498 | foreach ($problems as $p) { |
| 1499 | 1499 | DB::table("contest_problem")->insertGetId([ |
@@ -1509,8 +1509,8 @@ discard block |
||
| 1509 | 1509 | |
| 1510 | 1510 | public function arrangeContest($gid, $config, $problems) |
| 1511 | 1511 | { |
| 1512 | - $cid = -1; |
|
| 1513 | - DB::transaction(function () use ($gid, $config, $problems,&$cid) { |
|
| 1512 | + $cid=-1; |
|
| 1513 | + DB::transaction(function() use ($gid, $config, $problems, &$cid) { |
|
| 1514 | 1514 | $cid=DB::table($this->tableName)->insertGetId([ |
| 1515 | 1515 | "gid"=>$gid, |
| 1516 | 1516 | "name"=>$config["name"], |
@@ -1524,7 +1524,7 @@ discard block |
||
| 1524 | 1524 | "rule"=>1, //todo |
| 1525 | 1525 | "begin_time"=>$config["begin_time"], |
| 1526 | 1526 | "end_time"=>$config["end_time"], |
| 1527 | - "vcid"=>isset($config["vcid"])?$config["vcid"]:null, |
|
| 1527 | + "vcid"=>isset($config["vcid"]) ? $config["vcid"] : null, |
|
| 1528 | 1528 | "public"=>$config["public"], |
| 1529 | 1529 | "registration"=>0, //todo |
| 1530 | 1530 | "registration_due"=>null, //todo |
@@ -1532,7 +1532,7 @@ discard block |
||
| 1532 | 1532 | "froze_length"=>0, //todo |
| 1533 | 1533 | "status_visibility"=>2, //todo |
| 1534 | 1534 | "created_up"=>date("Y-m-d H:i:s"), |
| 1535 | - "crawled" => isset($config['vcid'])?$config['crawled'] : null, |
|
| 1535 | + "crawled" => isset($config['vcid']) ? $config['crawled'] : null, |
|
| 1536 | 1536 | "audit_status"=>$config["public"] ? 0 : 1 |
| 1537 | 1537 | ]); |
| 1538 | 1538 | |
@@ -1551,13 +1551,13 @@ discard block |
||
| 1551 | 1551 | return $cid; |
| 1552 | 1552 | } |
| 1553 | 1553 | |
| 1554 | - public function updateContestRankTable($cid,$sub) |
|
| 1554 | + public function updateContestRankTable($cid, $sub) |
|
| 1555 | 1555 | { |
| 1556 | - $lock = Cache::lock("contestrank$cid",10); |
|
| 1557 | - try{ |
|
| 1558 | - if($lock->get()){ |
|
| 1559 | - if(Cache::tags(['contest','rank'])->get($cid) != null){ |
|
| 1560 | - $ret = Cache::tags(['contest','rank'])->get($cid); |
|
| 1556 | + $lock=Cache::lock("contestrank$cid", 10); |
|
| 1557 | + try { |
|
| 1558 | + if ($lock->get()) { |
|
| 1559 | + if (Cache::tags(['contest', 'rank'])->get($cid)!=null) { |
|
| 1560 | + $ret=Cache::tags(['contest', 'rank'])->get($cid); |
|
| 1561 | 1561 | $chache=[]; |
| 1562 | 1562 | $chache['contest_info']=DB::table("contest")->where("cid", $cid)->first(); |
| 1563 | 1563 | $chache['problemSet']=DB::table("contest_problem")->join("problem", "contest_problem.pid", "=", "problem.pid")->where([ |
@@ -1566,27 +1566,27 @@ discard block |
||
| 1566 | 1566 | $chache['frozen_time']=DB::table("contest")->where(["cid"=>$cid])->select(DB::raw("UNIX_TIMESTAMP(end_time)-froze_length as frozen_time"))->first()["frozen_time"]; |
| 1567 | 1567 | $chache['end_time']=strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]); |
| 1568 | 1568 | |
| 1569 | - $id = 0; |
|
| 1569 | + $id=0; |
|
| 1570 | 1570 | |
| 1571 | - foreach($chache['problemSet'] as $key => $p){ |
|
| 1572 | - if ($p['pid'] == $sub['pid']){ |
|
| 1573 | - $chache['problemSet'][$key]['cpid'] = $key; |
|
| 1574 | - $id = $key; |
|
| 1571 | + foreach ($chache['problemSet'] as $key => $p) { |
|
| 1572 | + if ($p['pid']==$sub['pid']) { |
|
| 1573 | + $chache['problemSet'][$key]['cpid']=$key; |
|
| 1574 | + $id=$key; |
|
| 1575 | 1575 | } |
| 1576 | 1576 | } |
| 1577 | 1577 | |
| 1578 | - $ret = $this->updateContestRankDetail($chache['contest_info'],$chache['problemSet'][$id],$cid,$sub['uid'],$ret); |
|
| 1579 | - $ret = $this->sortContestRankTable($chache['contest_info'],$cid,$ret); |
|
| 1578 | + $ret=$this->updateContestRankDetail($chache['contest_info'], $chache['problemSet'][$id], $cid, $sub['uid'], $ret); |
|
| 1579 | + $ret=$this->sortContestRankTable($chache['contest_info'], $cid, $ret); |
|
| 1580 | 1580 | |
| 1581 | - if (time() < $chache['frozen_time']){ |
|
| 1581 | + if (time()<$chache['frozen_time']) { |
|
| 1582 | 1582 | Cache::tags(['contest', 'rank'])->put($cid, $ret); |
| 1583 | 1583 | } |
| 1584 | 1584 | Cache::tags(['contest', 'rank'])->put("contestAdmin$cid", $ret); |
| 1585 | - if(time() > $chache['end_time']){ |
|
| 1585 | + if (time()>$chache['end_time']) { |
|
| 1586 | 1586 | $this->storeContestRankInMySQL($cid, $ret); |
| 1587 | 1587 | } |
| 1588 | 1588 | } |
| 1589 | - else{ |
|
| 1589 | + else { |
|
| 1590 | 1590 | $ret=[]; |
| 1591 | 1591 | $chache=[]; |
| 1592 | 1592 | $chache['contest_info']=DB::table("contest")->where("cid", $cid)->first(); |
@@ -1601,7 +1601,7 @@ discard block |
||
| 1601 | 1601 | "cid"=>$cid, |
| 1602 | 1602 | "audit"=>1 |
| 1603 | 1603 | ])->select('uid')->get()->all(); |
| 1604 | - }else{ |
|
| 1604 | + } else { |
|
| 1605 | 1605 | $submissionUsers=DB::table("submission")->where([ |
| 1606 | 1606 | "cid"=>$cid |
| 1607 | 1607 | ])->where( |
@@ -1614,39 +1614,39 @@ discard block |
||
| 1614 | 1614 | ])->select('uid')->groupBy('uid')->get()->all(); |
| 1615 | 1615 | } |
| 1616 | 1616 | |
| 1617 | - $chacheAdmin = $chache; |
|
| 1617 | + $chacheAdmin=$chache; |
|
| 1618 | 1618 | |
| 1619 | 1619 | foreach ($submissionUsers as $s) { |
| 1620 | 1620 | foreach ($chache['problemSet'] as $key => $p) { |
| 1621 | - $p['cpid'] = $key; |
|
| 1622 | - $ret = $this->updateContestRankDetail($chache['contest_info'],$p,$cid,$s['uid'],$ret); |
|
| 1621 | + $p['cpid']=$key; |
|
| 1622 | + $ret=$this->updateContestRankDetail($chache['contest_info'], $p, $cid, $s['uid'], $ret); |
|
| 1623 | 1623 | } |
| 1624 | 1624 | } |
| 1625 | - $ret = $this->sortContestRankTable($chache['contest_info'],$cid,$ret); |
|
| 1625 | + $ret=$this->sortContestRankTable($chache['contest_info'], $cid, $ret); |
|
| 1626 | 1626 | Cache::tags(['contest', 'rank'])->put($cid, $ret); |
| 1627 | 1627 | |
| 1628 | 1628 | $retAdmin=[]; |
| 1629 | 1629 | foreach ($submissionUsersAdmin as $s) { |
| 1630 | 1630 | foreach ($chacheAdmin['problemSet'] as $key => $p) { |
| 1631 | - $p['cpid'] = $key; |
|
| 1632 | - $retAdmin = $this->updateContestRankDetail($chacheAdmin['contest_info'],$p,$cid,$s['uid'],$retAdmin); |
|
| 1631 | + $p['cpid']=$key; |
|
| 1632 | + $retAdmin=$this->updateContestRankDetail($chacheAdmin['contest_info'], $p, $cid, $s['uid'], $retAdmin); |
|
| 1633 | 1633 | } |
| 1634 | 1634 | } |
| 1635 | - $retAdmin = $this->sortContestRankTable($chacheAdmin['contest_info'],$cid,$retAdmin); |
|
| 1635 | + $retAdmin=$this->sortContestRankTable($chacheAdmin['contest_info'], $cid, $retAdmin); |
|
| 1636 | 1636 | Cache::tags(['contest', 'rank'])->put("contestAdmin$cid", $retAdmin); |
| 1637 | 1637 | } |
| 1638 | 1638 | } |
| 1639 | - }catch(LockTimeoutException $e){ |
|
| 1639 | + } catch (LockTimeoutException $e) { |
|
| 1640 | 1640 | Log::warning("Contest Rank Lock Timed Out"); |
| 1641 | - }finally{ |
|
| 1641 | + } finally { |
|
| 1642 | 1642 | optional($lock)->release(); |
| 1643 | 1643 | } |
| 1644 | 1644 | } |
| 1645 | 1645 | |
| 1646 | - public function sortContestRankTable($contest_info,$cid,$ret) |
|
| 1646 | + public function sortContestRankTable($contest_info, $cid, $ret) |
|
| 1647 | 1647 | { |
| 1648 | - if ($contest_info["rule"]==1){ |
|
| 1649 | - usort($ret, function ($a, $b) { |
|
| 1648 | + if ($contest_info["rule"]==1) { |
|
| 1649 | + usort($ret, function($a, $b) { |
|
| 1650 | 1650 | if ($a["score"]==$b["score"]) { |
| 1651 | 1651 | if ($a["penalty"]==$b["penalty"]) { |
| 1652 | 1652 | return 0; |
@@ -1661,8 +1661,8 @@ discard block |
||
| 1661 | 1661 | return 1; |
| 1662 | 1662 | } |
| 1663 | 1663 | }); |
| 1664 | - }else if ($contest_info["rule"]==2){ |
|
| 1665 | - usort($ret, function ($a, $b) { |
|
| 1664 | + } else if ($contest_info["rule"]==2) { |
|
| 1665 | + usort($ret, function($a, $b) { |
|
| 1666 | 1666 | if ($a["score"]==$b["score"]) { |
| 1667 | 1667 | if ($a["solved"]==$b["solved"]) { |
| 1668 | 1668 | return 0; |
@@ -1681,21 +1681,21 @@ discard block |
||
| 1681 | 1681 | return $ret; |
| 1682 | 1682 | } |
| 1683 | 1683 | |
| 1684 | - public function updateContestRankDetail($contest_info,$problem,$cid,$uid,$ret) |
|
| 1684 | + public function updateContestRankDetail($contest_info, $problem, $cid, $uid, $ret) |
|
| 1685 | 1685 | { |
| 1686 | - $id = count($ret); |
|
| 1687 | - foreach($ret as $key => $r){ |
|
| 1688 | - if($r['uid'] == $uid) |
|
| 1689 | - $id = $key; |
|
| 1686 | + $id=count($ret); |
|
| 1687 | + foreach ($ret as $key => $r) { |
|
| 1688 | + if ($r['uid']==$uid) |
|
| 1689 | + $id=$key; |
|
| 1690 | 1690 | } |
| 1691 | 1691 | if ($contest_info["rule"]==1) { |
| 1692 | 1692 | // ACM/ICPC Mode |
| 1693 | - if($id == count($ret)){ |
|
| 1694 | - $prob_detail = []; |
|
| 1695 | - $totPen = 0; |
|
| 1696 | - $totScore = 0; |
|
| 1697 | - }else{ |
|
| 1698 | - $prob_detail = $ret[$id]['problem_detail']; |
|
| 1693 | + if ($id==count($ret)) { |
|
| 1694 | + $prob_detail=[]; |
|
| 1695 | + $totPen=0; |
|
| 1696 | + $totScore=0; |
|
| 1697 | + } else { |
|
| 1698 | + $prob_detail=$ret[$id]['problem_detail']; |
|
| 1699 | 1699 | $totPen=$ret[$id]['penalty']; |
| 1700 | 1700 | $totScore=$ret[$id]['score']; |
| 1701 | 1701 | }; |
@@ -1713,7 +1713,7 @@ discard block |
||
| 1713 | 1713 | "uid"=>$uid, |
| 1714 | 1714 | ])->orderBy('submission_date', 'desc')->first(); |
| 1715 | 1715 | |
| 1716 | - if ($ac_times<=1 && isset($last_record) && $last_record['verdict']!="Waiting" && $last_record['verdict']!="Submission Error" && $last_record['verdict']!="System Error"){ |
|
| 1716 | + if ($ac_times<=1 && isset($last_record) && $last_record['verdict']!="Waiting" && $last_record['verdict']!="Submission Error" && $last_record['verdict']!="System Error") { |
|
| 1717 | 1717 | $prob_stat=$this->contestProblemInfoACM($cid, $problem["pid"], $uid); |
| 1718 | 1718 | |
| 1719 | 1719 | $prob_detail[$problem['cpid']]=[ |
@@ -1745,12 +1745,12 @@ discard block |
||
| 1745 | 1745 | } |
| 1746 | 1746 | } elseif ($contest_info["rule"]==2) { |
| 1747 | 1747 | // IOI Mode |
| 1748 | - if($id == count($ret)){ |
|
| 1749 | - $prob_detail = []; |
|
| 1750 | - $totSolved = 0; |
|
| 1751 | - $totScore = 0; |
|
| 1752 | - }else{ |
|
| 1753 | - $prob_detail = $ret[$id]['problem_detail']; |
|
| 1748 | + if ($id==count($ret)) { |
|
| 1749 | + $prob_detail=[]; |
|
| 1750 | + $totSolved=0; |
|
| 1751 | + $totScore=0; |
|
| 1752 | + } else { |
|
| 1753 | + $prob_detail=$ret[$id]['problem_detail']; |
|
| 1754 | 1754 | $totSolved=$ret[$id]['solved']; |
| 1755 | 1755 | $totScore=$ret[$id]['score']; |
| 1756 | 1756 | }; |
@@ -1783,47 +1783,47 @@ discard block |
||
| 1783 | 1783 | return $ret; |
| 1784 | 1784 | } |
| 1785 | 1785 | |
| 1786 | - public function assignMember($cid,$uid){ |
|
| 1786 | + public function assignMember($cid, $uid) { |
|
| 1787 | 1787 | return DB::table("contest")->where(["cid"=>$cid])->update([ |
| 1788 | 1788 | "assign_uid"=>$uid |
| 1789 | 1789 | ]); |
| 1790 | 1790 | } |
| 1791 | 1791 | |
| 1792 | - public function canUpdateContestTime($cid,$time = []) |
|
| 1792 | + public function canUpdateContestTime($cid, $time=[]) |
|
| 1793 | 1793 | { |
| 1794 | - $begin_time_new = $time['begin'] ?? null; |
|
| 1795 | - $end_time_new = $time['end'] ?? null; |
|
| 1794 | + $begin_time_new=$time['begin'] ?? null; |
|
| 1795 | + $end_time_new=$time['end'] ?? null; |
|
| 1796 | 1796 | |
| 1797 | - $hold_time = DB::table('contest') |
|
| 1798 | - ->where('cid',$cid) |
|
| 1799 | - ->select('begin_time','end_time') |
|
| 1797 | + $hold_time=DB::table('contest') |
|
| 1798 | + ->where('cid', $cid) |
|
| 1799 | + ->select('begin_time', 'end_time') |
|
| 1800 | 1800 | ->first(); |
| 1801 | - $begin_stamps = strtotime($hold_time['begin_time']); |
|
| 1802 | - $end_stamps = strtotime($hold_time['end_time']); |
|
| 1801 | + $begin_stamps=strtotime($hold_time['begin_time']); |
|
| 1802 | + $end_stamps=strtotime($hold_time['end_time']); |
|
| 1803 | 1803 | /* |
| 1804 | 1804 | -1 : have not begun |
| 1805 | 1805 | 0 : ing |
| 1806 | 1806 | 1 : end |
| 1807 | 1807 | */ |
| 1808 | - $status = time() >= $end_stamps ? 1 |
|
| 1809 | - : (time() <= $begin_stamps ? -1 : 0); |
|
| 1810 | - if($status === -1){ |
|
| 1811 | - if(time() > $begin_time_new){ |
|
| 1808 | + $status=time()>=$end_stamps ? 1 |
|
| 1809 | + : (time()<=$begin_stamps ? -1 : 0); |
|
| 1810 | + if ($status===-1) { |
|
| 1811 | + if (time()>$begin_time_new) { |
|
| 1812 | 1812 | return false; |
| 1813 | 1813 | } |
| 1814 | 1814 | return true; |
| 1815 | - }else if($status === 0){ |
|
| 1816 | - if($begin_time_new !== null){ |
|
| 1815 | + } else if ($status===0) { |
|
| 1816 | + if ($begin_time_new!==null) { |
|
| 1817 | 1817 | return false; |
| 1818 | 1818 | } |
| 1819 | - if($end_time_new !== null){ |
|
| 1820 | - if(strtotime($end_time_new) <= time()){ |
|
| 1819 | + if ($end_time_new!==null) { |
|
| 1820 | + if (strtotime($end_time_new)<=time()) { |
|
| 1821 | 1821 | return false; |
| 1822 | - }else{ |
|
| 1822 | + } else { |
|
| 1823 | 1823 | return true; |
| 1824 | 1824 | } |
| 1825 | 1825 | } |
| 1826 | - }else{ |
|
| 1826 | + } else { |
|
| 1827 | 1827 | return false; |
| 1828 | 1828 | } |
| 1829 | 1829 | |
@@ -1832,22 +1832,22 @@ discard block |
||
| 1832 | 1832 | |
| 1833 | 1833 | public function replyClarification($ccid, $content) |
| 1834 | 1834 | { |
| 1835 | - return DB::table("contest_clarification")->where('ccid','=',$ccid)->update([ |
|
| 1835 | + return DB::table("contest_clarification")->where('ccid', '=', $ccid)->update([ |
|
| 1836 | 1836 | "reply"=>$content |
| 1837 | 1837 | ]); |
| 1838 | 1838 | } |
| 1839 | 1839 | |
| 1840 | 1840 | public function setClarificationPublic($ccid, $public) |
| 1841 | 1841 | { |
| 1842 | - if($public) |
|
| 1842 | + if ($public) |
|
| 1843 | 1843 | { |
| 1844 | - return DB::table("contest_clarification")->where('ccid','=',$ccid)->update([ |
|
| 1844 | + return DB::table("contest_clarification")->where('ccid', '=', $ccid)->update([ |
|
| 1845 | 1845 | "public"=>1 |
| 1846 | 1846 | ]); |
| 1847 | 1847 | } |
| 1848 | 1848 | else |
| 1849 | 1849 | { |
| 1850 | - return DB::table("contest_clarification")->where('ccid','=',$ccid)->update([ |
|
| 1850 | + return DB::table("contest_clarification")->where('ccid', '=', $ccid)->update([ |
|
| 1851 | 1851 | "public"=>0 |
| 1852 | 1852 | ]); |
| 1853 | 1853 | } |
@@ -1860,90 +1860,90 @@ discard block |
||
| 1860 | 1860 | |
| 1861 | 1861 | public function praticeAnalysis($cid) |
| 1862 | 1862 | { |
| 1863 | - $gid = DB::table('contest') |
|
| 1864 | - ->where('cid',$cid) |
|
| 1863 | + $gid=DB::table('contest') |
|
| 1864 | + ->where('cid', $cid) |
|
| 1865 | 1865 | ->first()['gid']; |
| 1866 | - $contestRank = $this->contestRank($cid,Auth::user()->id); |
|
| 1867 | - if(!empty($contestRank)){ |
|
| 1868 | - $all_problems = DB::table('problem') |
|
| 1869 | - ->whereIn('pid',array_column($contestRank[0]['problem_detail'],'pid')) |
|
| 1870 | - ->select('pid','title') |
|
| 1866 | + $contestRank=$this->contestRank($cid, Auth::user()->id); |
|
| 1867 | + if (!empty($contestRank)) { |
|
| 1868 | + $all_problems=DB::table('problem') |
|
| 1869 | + ->whereIn('pid', array_column($contestRank[0]['problem_detail'], 'pid')) |
|
| 1870 | + ->select('pid', 'title') |
|
| 1871 | 1871 | ->get()->all(); |
| 1872 | - }else{ |
|
| 1873 | - $all_problems = []; |
|
| 1872 | + } else { |
|
| 1873 | + $all_problems=[]; |
|
| 1874 | 1874 | } |
| 1875 | - $tags = DB::table('group_problem_tag') |
|
| 1875 | + $tags=DB::table('group_problem_tag') |
|
| 1876 | 1876 | ->where('gid', $gid) |
| 1877 | - ->whereIn('pid', array_column($all_problems,'pid')) |
|
| 1877 | + ->whereIn('pid', array_column($all_problems, 'pid')) |
|
| 1878 | 1878 | ->get()->all(); |
| 1879 | - $all_tags = array_unique(array_column($tags,'tag')); |
|
| 1880 | - $memberData = []; |
|
| 1881 | - foreach($contestRank as $member){ |
|
| 1882 | - $m = [ |
|
| 1879 | + $all_tags=array_unique(array_column($tags, 'tag')); |
|
| 1880 | + $memberData=[]; |
|
| 1881 | + foreach ($contestRank as $member) { |
|
| 1882 | + $m=[ |
|
| 1883 | 1883 | 'uid' => $member['uid'], |
| 1884 | 1884 | 'name' => $member['name'], |
| 1885 | 1885 | 'nick_name' => $member['nick_name'], |
| 1886 | 1886 | ]; |
| 1887 | - $completion = []; |
|
| 1888 | - foreach ($all_tags as $tag){ |
|
| 1889 | - $completion[$tag] = []; |
|
| 1887 | + $completion=[]; |
|
| 1888 | + foreach ($all_tags as $tag) { |
|
| 1889 | + $completion[$tag]=[]; |
|
| 1890 | 1890 | foreach ($tags as $t) { |
| 1891 | - if($t['tag'] == $tag){ |
|
| 1891 | + if ($t['tag']==$tag) { |
|
| 1892 | 1892 | foreach ($member['problem_detail'] as $pd) { |
| 1893 | - if($pd['pid'] == $t['pid']){ |
|
| 1894 | - $completion[$tag][$t['pid']] = $pd['solved_time_parsed'] == "" ? 0 : 1; |
|
| 1893 | + if ($pd['pid']==$t['pid']) { |
|
| 1894 | + $completion[$tag][$t['pid']]=$pd['solved_time_parsed']=="" ? 0 : 1; |
|
| 1895 | 1895 | } |
| 1896 | 1896 | } |
| 1897 | 1897 | } |
| 1898 | 1898 | } |
| 1899 | 1899 | } |
| 1900 | - $m['completion'] = $completion; |
|
| 1901 | - $memberData[] = $m; |
|
| 1900 | + $m['completion']=$completion; |
|
| 1901 | + $memberData[]=$m; |
|
| 1902 | 1902 | } |
| 1903 | 1903 | return $memberData; |
| 1904 | 1904 | } |
| 1905 | 1905 | |
| 1906 | 1906 | public function storeContestRankInMySQL($cid, $data) |
| 1907 | 1907 | { |
| 1908 | - $contestRankJson = json_encode($data); |
|
| 1909 | - return DB::table('contest')->where('cid','=',$cid)->update([ |
|
| 1908 | + $contestRankJson=json_encode($data); |
|
| 1909 | + return DB::table('contest')->where('cid', '=', $cid)->update([ |
|
| 1910 | 1910 | 'rank' => $contestRankJson |
| 1911 | 1911 | ]); |
| 1912 | 1912 | } |
| 1913 | 1913 | |
| 1914 | 1914 | public function getContestRankFromMySQL($cid) |
| 1915 | 1915 | { |
| 1916 | - $contestRankJson = DB::table('contest')->where('cid','=',$cid)->pluck('rank')->first(); |
|
| 1917 | - $data = json_decode($contestRankJson, true); |
|
| 1916 | + $contestRankJson=DB::table('contest')->where('cid', '=', $cid)->pluck('rank')->first(); |
|
| 1917 | + $data=json_decode($contestRankJson, true); |
|
| 1918 | 1918 | return $data; |
| 1919 | 1919 | } |
| 1920 | 1920 | |
| 1921 | 1921 | public function isVerified($cid) |
| 1922 | 1922 | { |
| 1923 | - return DB::table('contest')->where('cid','=',$cid)->pluck('verified')->first(); |
|
| 1923 | + return DB::table('contest')->where('cid', '=', $cid)->pluck('verified')->first(); |
|
| 1924 | 1924 | } |
| 1925 | 1925 | |
| 1926 | 1926 | public function getScrollBoardData($cid) |
| 1927 | 1927 | { |
| 1928 | - $members = DB::table("submission") |
|
| 1929 | - ->join('users','users.id','=','submission.uid') |
|
| 1928 | + $members=DB::table("submission") |
|
| 1929 | + ->join('users', 'users.id', '=', 'submission.uid') |
|
| 1930 | 1930 | ->join('contest', 'contest.cid', '=', 'submission.cid') |
| 1931 | 1931 | ->join('group_member', 'users.id', '=', 'group_member.uid') |
| 1932 | - ->where('submission.cid', $cid)->select('users.id as uid','users.name as name','group_member.nick_name as nick_name') |
|
| 1932 | + ->where('submission.cid', $cid)->select('users.id as uid', 'users.name as name', 'group_member.nick_name as nick_name') |
|
| 1933 | 1933 | ->groupBy('uid')->get()->all(); |
| 1934 | - $submissions = DB::table("submission") |
|
| 1934 | + $submissions=DB::table("submission") |
|
| 1935 | 1935 | ->where('cid', $cid) |
| 1936 | 1936 | ->select('sid', 'verdict', 'submission_date', 'pid', 'uid') |
| 1937 | 1937 | ->orderBy('submission_date') |
| 1938 | 1938 | ->get()->all(); |
| 1939 | - $problems = DB::table('contest_problem') |
|
| 1939 | + $problems=DB::table('contest_problem') |
|
| 1940 | 1940 | ->where('cid', $cid) |
| 1941 | - ->select('ncode','pid') |
|
| 1941 | + ->select('ncode', 'pid') |
|
| 1942 | 1942 | ->orderBy('ncode') |
| 1943 | 1943 | ->get()->all(); |
| 1944 | - $contest = DB::table('contest') |
|
| 1945 | - ->where('cid',$cid) |
|
| 1946 | - ->select('begin_time','end_time','froze_length') |
|
| 1944 | + $contest=DB::table('contest') |
|
| 1945 | + ->where('cid', $cid) |
|
| 1946 | + ->select('begin_time', 'end_time', 'froze_length') |
|
| 1947 | 1947 | ->first(); |
| 1948 | 1948 | return [ |
| 1949 | 1949 | 'members' => $members, |
@@ -1953,7 +1953,7 @@ discard block |
||
| 1953 | 1953 | ]; |
| 1954 | 1954 | } |
| 1955 | 1955 | |
| 1956 | - public function storageCode($path,$cid) |
|
| 1956 | + public function storageCode($path, $cid) |
|
| 1957 | 1957 | { |
| 1958 | 1958 | |
| 1959 | 1959 | Storage::disk("private")->makeDirectory($path); |
@@ -1964,7 +1964,7 @@ discard block |
||
| 1964 | 1964 | "cid"=>$cid |
| 1965 | 1965 | ])->get(); |
| 1966 | 1966 | $problem_info=array(); |
| 1967 | - foreach($contest_problems as $contest_problem) { |
|
| 1967 | + foreach ($contest_problems as $contest_problem) { |
|
| 1968 | 1968 | $problem_info[$contest_problem["pid"]]=DB::table("problem")->where([ |
| 1969 | 1969 | "pid"=>$contest_problem["pid"] |
| 1970 | 1970 | ])->first(); |
@@ -1975,7 +1975,7 @@ discard block |
||
| 1975 | 1975 | |
| 1976 | 1976 | $compilers=DB::table("compiler")->get(); |
| 1977 | 1977 | $language=array(); |
| 1978 | - foreach($compilers as $compiler) { |
|
| 1978 | + foreach ($compilers as $compiler) { |
|
| 1979 | 1979 | $language[$compiler["coid"]]=$compiler["lang"]; |
| 1980 | 1980 | } |
| 1981 | 1981 | |
@@ -1984,14 +1984,14 @@ discard block |
||
| 1984 | 1984 | $submissions=DB::table("submission")->where([ |
| 1985 | 1985 | "cid"=>$cid, |
| 1986 | 1986 | ])->get(); |
| 1987 | - foreach($submissions as $submission) { |
|
| 1987 | + foreach ($submissions as $submission) { |
|
| 1988 | 1988 | $user_name=DB::table("users")->where([ |
| 1989 | 1989 | "id"=>$submission["uid"] |
| 1990 | 1990 | ])->first(); |
| 1991 | 1991 | $SubmissionModel=new SubmissionModel(); |
| 1992 | 1992 | $suffix_name=isset($SubmissionModel->langConfig[$language[$submission["coid"]]]) ? $SubmissionModel->langConfig[$language[$submission["coid"]]]["extensions"][0] : $SubmissionModel->langConfig["plaintext"]["extensions"][0]; |
| 1993 | 1993 | //die($submission["sid"]); |
| 1994 | - $file_name=(string)($submission["sid"])."-".$user_name["name"]."-".$problem_info[$submission["pid"]]["ncode"]."-".$submission["verdict"].$suffix_name; |
|
| 1994 | + $file_name=(string) ($submission["sid"])."-".$user_name["name"]."-".$problem_info[$submission["pid"]]["ncode"]."-".$submission["verdict"].$suffix_name; |
|
| 1995 | 1995 | Storage::disk("private")->put($path."/".urlencode($problem_info[$submission["pid"]]["path"])."/".$file_name, $submission["solution"]); |
| 1996 | 1996 | } |
| 1997 | 1997 | } |
@@ -2001,33 +2001,33 @@ discard block |
||
| 2001 | 2001 | Storage::disk("private")->deleteDirectory($path); |
| 2002 | 2002 | } |
| 2003 | 2003 | |
| 2004 | - public function GenerateZip($path,$cid,$code_path,$outputFilename) |
|
| 2004 | + public function GenerateZip($path, $cid, $code_path, $outputFilename) |
|
| 2005 | 2005 | { |
| 2006 | 2006 | Storage::disk("private")->deleteDirectory($code_path); |
| 2007 | 2007 | |
| 2008 | - $this->storageCode($code_path,$cid); |
|
| 2008 | + $this->storageCode($code_path, $cid); |
|
| 2009 | 2009 | |
| 2010 | 2010 | Storage::disk("private")->makeDirectory($path); |
| 2011 | 2011 | |
| 2012 | 2012 | // create new archive |
| 2013 | - $zipFile = new \PhpZip\ZipFile(); |
|
| 2014 | - $directories = Storage::disk("private")->allDirectories($code_path); |
|
| 2015 | - try{ |
|
| 2016 | - foreach($directories as $directorie) |
|
| 2013 | + $zipFile=new \PhpZip\ZipFile(); |
|
| 2014 | + $directories=Storage::disk("private")->allDirectories($code_path); |
|
| 2015 | + try { |
|
| 2016 | + foreach ($directories as $directorie) |
|
| 2017 | 2017 | { |
| 2018 | 2018 | |
| 2019 | - preg_match("/contestCode\/\d+(.*)/",$directorie,$problem_name); |
|
| 2020 | - $zipFile->addDir(base_path('storage/app/private/'.$directorie),urldecode($problem_name[1]));// add files from the directory |
|
| 2019 | + preg_match("/contestCode\/\d+(.*)/", $directorie, $problem_name); |
|
| 2020 | + $zipFile->addDir(base_path('storage/app/private/'.$directorie), urldecode($problem_name[1])); // add files from the directory |
|
| 2021 | 2021 | } |
| 2022 | 2022 | $zipFile |
| 2023 | 2023 | ->saveAsFile(base_path('storage/app/private/'.$path.$cid.".zip")); // save the archive to a file |
| 2024 | 2024 | //->extractTo(base_path('storage/app/private/'.$path)); // extract files to the specified directory |
| 2025 | 2025 | } |
| 2026 | - catch(\PhpZip\Exception\ZipException $e){ |
|
| 2026 | + catch (\PhpZip\Exception\ZipException $e) { |
|
| 2027 | 2027 | // handle exception |
| 2028 | 2028 | Log::debug($e); |
| 2029 | 2029 | } |
| 2030 | - finally{ |
|
| 2030 | + finally { |
|
| 2031 | 2031 | $zipFile->close(); |
| 2032 | 2032 | } |
| 2033 | 2033 | } |
@@ -2039,21 +2039,21 @@ discard block |
||
| 2039 | 2039 | $contest=DB::table("contest")->where([ |
| 2040 | 2040 | "cid"=>$cid |
| 2041 | 2041 | ])->first(); |
| 2042 | - return $outputFilename=(string)($contest["cid"])."-".$contest["name"].".zip"; |
|
| 2042 | + return $outputFilename=(string) ($contest["cid"])."-".$contest["name"].".zip"; |
|
| 2043 | 2043 | } |
| 2044 | 2044 | |
| 2045 | 2045 | public function judgeOver($cid) |
| 2046 | 2046 | { |
| 2047 | - $submissions = DB::table('submission') |
|
| 2047 | + $submissions=DB::table('submission') |
|
| 2048 | 2048 | ->where(['cid' => $cid]) |
| 2049 | - ->whereIn('verdict',['Waiting','Pending']) |
|
| 2049 | + ->whereIn('verdict', ['Waiting', 'Pending']) |
|
| 2050 | 2050 | ->select('sid') |
| 2051 | 2051 | ->get()->all(); |
| 2052 | - if(empty($submissions)){ |
|
| 2052 | + if (empty($submissions)) { |
|
| 2053 | 2053 | return [ |
| 2054 | 2054 | 'result' => true |
| 2055 | 2055 | ]; |
| 2056 | - }else{ |
|
| 2056 | + } else { |
|
| 2057 | 2057 | return [ |
| 2058 | 2058 | 'result' => false, |
| 2059 | 2059 | 'sid' => $submissions |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | $paginator=$paginator->where(["practice"=>$filter['practice']]); |
| 229 | 229 | } |
| 230 | 230 | $paginator = $paginator ->paginate(10); |
| 231 | - }elseif($filter['public']=='0'){ |
|
| 231 | + } elseif($filter['public']=='0'){ |
|
| 232 | 232 | $paginator=DB::table('group_member') |
| 233 | 233 | ->groupBy('contest.cid') |
| 234 | 234 | ->select('contest.*') |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | ) |
| 259 | 259 | ->orderBy('contest.begin_time', 'desc') |
| 260 | 260 | ->paginate(10); |
| 261 | - }else{ |
|
| 261 | + } else{ |
|
| 262 | 262 | $paginator=DB::table('group_member') |
| 263 | 263 | ->groupBy('contest.cid') |
| 264 | 264 | ->select('contest.*') |
@@ -810,13 +810,13 @@ discard block |
||
| 810 | 810 | if(time() < $end_time){ |
| 811 | 811 | if($clearance == 3){ |
| 812 | 812 | $contestRankRaw=Cache::tags(['contest', 'rank'])->get("contestAdmin$cid"); |
| 813 | - }else{ |
|
| 813 | + } else{ |
|
| 814 | 814 | $contestRankRaw=Cache::tags(['contest', 'rank'])->get($cid); |
| 815 | 815 | } |
| 816 | 816 | if(!isset($contestRankRaw)){ |
| 817 | 817 | $contestRankRaw=$contest_eloquent->rankRefresh(); |
| 818 | 818 | } |
| 819 | - }else{ |
|
| 819 | + } else{ |
|
| 820 | 820 | if($clearance == 3){ |
| 821 | 821 | $contestRankRaw=Cache::tags(['contest', 'rank'])->get("contestAdmin$cid"); |
| 822 | 822 | if (!isset($contestRankRaw)) { |
@@ -826,7 +826,7 @@ discard block |
||
| 826 | 826 | $this->storeContestRankInMySQL($cid, $contestRankRaw); |
| 827 | 827 | } |
| 828 | 828 | } |
| 829 | - }else{ |
|
| 829 | + } else{ |
|
| 830 | 830 | $contestRankRaw=$this->getContestRankFromMySQL($cid); |
| 831 | 831 | if(!isset($contestRankRaw)){ |
| 832 | 832 | $contestRankRaw=Cache::tags(['contest', 'rank'])->get($cid); |
@@ -911,7 +911,7 @@ discard block |
||
| 911 | 911 | return DB::table("contest_clarification")->where([ |
| 912 | 912 | "cid"=>$cid |
| 913 | 913 | ])->orderBy('created_at', 'desc')->get()->all(); |
| 914 | - }else{ |
|
| 914 | + } else{ |
|
| 915 | 915 | return DB::table("contest_clarification")->where([ |
| 916 | 916 | "cid"=>$cid |
| 917 | 917 | ])->where(function ($query) { |
@@ -1076,7 +1076,7 @@ discard block |
||
| 1076 | 1076 | $filter['pid'] = array_search($filter['ncode'], array_column($problemSet_temp, 'ncode')); |
| 1077 | 1077 | if($filter['pid']==false){ |
| 1078 | 1078 | $filter['pid'] = null; |
| 1079 | - }else{ |
|
| 1079 | + } else{ |
|
| 1080 | 1080 | $filter['pid'] = $problemSet_temp[$filter['pid']]['pid']; |
| 1081 | 1081 | } |
| 1082 | 1082 | |
@@ -1184,7 +1184,7 @@ discard block |
||
| 1184 | 1184 | "records"=>[] |
| 1185 | 1185 | ]; |
| 1186 | 1186 | } |
| 1187 | - }else{ |
|
| 1187 | + } else{ |
|
| 1188 | 1188 | if ($basicInfo["status_visibility"]==2) { |
| 1189 | 1189 | // View all |
| 1190 | 1190 | $paginator=DB::table("submission")->where([ |
@@ -1434,7 +1434,7 @@ discard block |
||
| 1434 | 1434 | if($ratingCalculator->calculate()){ |
| 1435 | 1435 | $ratingCalculator->storage(); |
| 1436 | 1436 | return true; |
| 1437 | - }else{ |
|
| 1437 | + } else{ |
|
| 1438 | 1438 | return false; |
| 1439 | 1439 | } |
| 1440 | 1440 | } else { |
@@ -1483,7 +1483,7 @@ discard block |
||
| 1483 | 1483 | $contestRankRaw = $this->contestRankCache($cid); |
| 1484 | 1484 | Cache::tags(['contest', 'rank'])->put($cid, $contestRankRaw); |
| 1485 | 1485 | Cache::tags(['contest', 'rank'])->put("contestAdmin$cid", $contestRankRaw); |
| 1486 | - }else{ |
|
| 1486 | + } else{ |
|
| 1487 | 1487 | DB::table($this->tableName) |
| 1488 | 1488 | ->where('cid',$cid) |
| 1489 | 1489 | ->update($data); |
@@ -1585,8 +1585,7 @@ discard block |
||
| 1585 | 1585 | if(time() > $chache['end_time']){ |
| 1586 | 1586 | $this->storeContestRankInMySQL($cid, $ret); |
| 1587 | 1587 | } |
| 1588 | - } |
|
| 1589 | - else{ |
|
| 1588 | + } else{ |
|
| 1590 | 1589 | $ret=[]; |
| 1591 | 1590 | $chache=[]; |
| 1592 | 1591 | $chache['contest_info']=DB::table("contest")->where("cid", $cid)->first(); |
@@ -1601,7 +1600,7 @@ discard block |
||
| 1601 | 1600 | "cid"=>$cid, |
| 1602 | 1601 | "audit"=>1 |
| 1603 | 1602 | ])->select('uid')->get()->all(); |
| 1604 | - }else{ |
|
| 1603 | + } else{ |
|
| 1605 | 1604 | $submissionUsers=DB::table("submission")->where([ |
| 1606 | 1605 | "cid"=>$cid |
| 1607 | 1606 | ])->where( |
@@ -1636,9 +1635,9 @@ discard block |
||
| 1636 | 1635 | Cache::tags(['contest', 'rank'])->put("contestAdmin$cid", $retAdmin); |
| 1637 | 1636 | } |
| 1638 | 1637 | } |
| 1639 | - }catch(LockTimeoutException $e){ |
|
| 1638 | + } catch(LockTimeoutException $e){ |
|
| 1640 | 1639 | Log::warning("Contest Rank Lock Timed Out"); |
| 1641 | - }finally{ |
|
| 1640 | + } finally{ |
|
| 1642 | 1641 | optional($lock)->release(); |
| 1643 | 1642 | } |
| 1644 | 1643 | } |
@@ -1661,7 +1660,7 @@ discard block |
||
| 1661 | 1660 | return 1; |
| 1662 | 1661 | } |
| 1663 | 1662 | }); |
| 1664 | - }else if ($contest_info["rule"]==2){ |
|
| 1663 | + } else if ($contest_info["rule"]==2){ |
|
| 1665 | 1664 | usort($ret, function ($a, $b) { |
| 1666 | 1665 | if ($a["score"]==$b["score"]) { |
| 1667 | 1666 | if ($a["solved"]==$b["solved"]) { |
@@ -1685,8 +1684,9 @@ discard block |
||
| 1685 | 1684 | { |
| 1686 | 1685 | $id = count($ret); |
| 1687 | 1686 | foreach($ret as $key => $r){ |
| 1688 | - if($r['uid'] == $uid) |
|
| 1689 | - $id = $key; |
|
| 1687 | + if($r['uid'] == $uid) { |
|
| 1688 | + $id = $key; |
|
| 1689 | + } |
|
| 1690 | 1690 | } |
| 1691 | 1691 | if ($contest_info["rule"]==1) { |
| 1692 | 1692 | // ACM/ICPC Mode |
@@ -1694,7 +1694,7 @@ discard block |
||
| 1694 | 1694 | $prob_detail = []; |
| 1695 | 1695 | $totPen = 0; |
| 1696 | 1696 | $totScore = 0; |
| 1697 | - }else{ |
|
| 1697 | + } else{ |
|
| 1698 | 1698 | $prob_detail = $ret[$id]['problem_detail']; |
| 1699 | 1699 | $totPen=$ret[$id]['penalty']; |
| 1700 | 1700 | $totScore=$ret[$id]['score']; |
@@ -1749,7 +1749,7 @@ discard block |
||
| 1749 | 1749 | $prob_detail = []; |
| 1750 | 1750 | $totSolved = 0; |
| 1751 | 1751 | $totScore = 0; |
| 1752 | - }else{ |
|
| 1752 | + } else{ |
|
| 1753 | 1753 | $prob_detail = $ret[$id]['problem_detail']; |
| 1754 | 1754 | $totSolved=$ret[$id]['solved']; |
| 1755 | 1755 | $totScore=$ret[$id]['score']; |
@@ -1812,18 +1812,18 @@ discard block |
||
| 1812 | 1812 | return false; |
| 1813 | 1813 | } |
| 1814 | 1814 | return true; |
| 1815 | - }else if($status === 0){ |
|
| 1815 | + } else if($status === 0){ |
|
| 1816 | 1816 | if($begin_time_new !== null){ |
| 1817 | 1817 | return false; |
| 1818 | 1818 | } |
| 1819 | 1819 | if($end_time_new !== null){ |
| 1820 | 1820 | if(strtotime($end_time_new) <= time()){ |
| 1821 | 1821 | return false; |
| 1822 | - }else{ |
|
| 1822 | + } else{ |
|
| 1823 | 1823 | return true; |
| 1824 | 1824 | } |
| 1825 | 1825 | } |
| 1826 | - }else{ |
|
| 1826 | + } else{ |
|
| 1827 | 1827 | return false; |
| 1828 | 1828 | } |
| 1829 | 1829 | |
@@ -1844,8 +1844,7 @@ discard block |
||
| 1844 | 1844 | return DB::table("contest_clarification")->where('ccid','=',$ccid)->update([ |
| 1845 | 1845 | "public"=>1 |
| 1846 | 1846 | ]); |
| 1847 | - } |
|
| 1848 | - else |
|
| 1847 | + } else |
|
| 1849 | 1848 | { |
| 1850 | 1849 | return DB::table("contest_clarification")->where('ccid','=',$ccid)->update([ |
| 1851 | 1850 | "public"=>0 |
@@ -1869,7 +1868,7 @@ discard block |
||
| 1869 | 1868 | ->whereIn('pid',array_column($contestRank[0]['problem_detail'],'pid')) |
| 1870 | 1869 | ->select('pid','title') |
| 1871 | 1870 | ->get()->all(); |
| 1872 | - }else{ |
|
| 1871 | + } else{ |
|
| 1873 | 1872 | $all_problems = []; |
| 1874 | 1873 | } |
| 1875 | 1874 | $tags = DB::table('group_problem_tag') |
@@ -2022,12 +2021,10 @@ discard block |
||
| 2022 | 2021 | $zipFile |
| 2023 | 2022 | ->saveAsFile(base_path('storage/app/private/'.$path.$cid.".zip")); // save the archive to a file |
| 2024 | 2023 | //->extractTo(base_path('storage/app/private/'.$path)); // extract files to the specified directory |
| 2025 | - } |
|
| 2026 | - catch(\PhpZip\Exception\ZipException $e){ |
|
| 2024 | + } catch(\PhpZip\Exception\ZipException $e){ |
|
| 2027 | 2025 | // handle exception |
| 2028 | 2026 | Log::debug($e); |
| 2029 | - } |
|
| 2030 | - finally{ |
|
| 2027 | + } finally{ |
|
| 2031 | 2028 | $zipFile->close(); |
| 2032 | 2029 | } |
| 2033 | 2030 | } |
@@ -2053,7 +2050,7 @@ discard block |
||
| 2053 | 2050 | return [ |
| 2054 | 2051 | 'result' => true |
| 2055 | 2052 | ]; |
| 2056 | - }else{ |
|
| 2053 | + } else{ |
|
| 2057 | 2054 | return [ |
| 2058 | 2055 | 'result' => false, |
| 2059 | 2056 | 'sid' => $submissions |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | * |
| 15 | 15 | * @var string |
| 16 | 16 | */ |
| 17 | - protected $signature = 'babel:crawl |
|
| 17 | + protected $signature='babel:crawl |
|
| 18 | 18 | {extension : The package name of the extension} |
| 19 | 19 | {--action=crawl_problem : The action of the Crawler} |
| 20 | 20 | {--con=all : The target problemset of the Crawler} |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | * |
| 27 | 27 | * @var string |
| 28 | 28 | */ |
| 29 | - protected $description = 'Crawl problems for a given Babel Extension to NOJ'; |
|
| 29 | + protected $description='Crawl problems for a given Babel Extension to NOJ'; |
|
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * Create a new command instance. |
@@ -45,11 +45,11 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public function handle() |
| 47 | 47 | { |
| 48 | - $extension = $this->argument('extension'); |
|
| 49 | - $action = $this->option('action'); |
|
| 50 | - $con = $this->option('con'); |
|
| 51 | - [$from, $to] = sscanf($this->option('range'),"%d:%d"); |
|
| 52 | - $cached = $this->option('cached'); |
|
| 48 | + $extension=$this->argument('extension'); |
|
| 49 | + $action=$this->option('action'); |
|
| 50 | + $con=$this->option('con'); |
|
| 51 | + [$from, $to]=sscanf($this->option('range'), "%d:%d"); |
|
| 52 | + $cached=$this->option('cached'); |
|
| 53 | 53 | $babel=new Babel(); |
| 54 | 54 | $babel->crawl([ |
| 55 | 55 | "name" => $extension, |
@@ -13,19 +13,19 @@ discard block |
||
| 13 | 13 | * |
| 14 | 14 | * @var string |
| 15 | 15 | */ |
| 16 | - protected $signature = 'babel'; |
|
| 16 | + protected $signature='babel'; |
|
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * The console command description. |
| 20 | 20 | * |
| 21 | 21 | * @var string |
| 22 | 22 | */ |
| 23 | - protected $description = 'List all babel commands'; |
|
| 23 | + protected $description='List all babel commands'; |
|
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * @var string |
| 27 | 27 | */ |
| 28 | - public static $logo = <<<LOGO |
|
| 28 | + public static $logo=<<<LOGO |
|
| 29 | 29 | |
| 30 | 30 | ███╗ ██╗ ██████╗ ██╗ ██████╗ █████╗ ██████╗ ███████╗██╗ |
| 31 | 31 | ████╗ ██║██╔═══██╗ ██║ ██╔══██╗██╔══██╗██╔══██╗██╔════╝██║ |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | public function handle() |
| 43 | 43 | { |
| 44 | 44 | $this->line(static::$logo); |
| 45 | - $this->line(sprintf('NOJ <comment>version</comment> <info>%s</info>',version())); |
|
| 45 | + $this->line(sprintf('NOJ <comment>version</comment> <info>%s</info>', version())); |
|
| 46 | 46 | |
| 47 | 47 | $this->comment(''); |
| 48 | 48 | $this->comment('Available commands:'); |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | protected function listBabelCommands() |
| 59 | 59 | { |
| 60 | - $commands = collect(Artisan::all())->mapWithKeys(function ($command, $key) { |
|
| 60 | + $commands=collect(Artisan::all())->mapWithKeys(function($command, $key) { |
|
| 61 | 61 | if (Str::startsWith($key, 'babel:')) { |
| 62 | 62 | return [$key => $command]; |
| 63 | 63 | } |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | return []; |
| 66 | 66 | })->toArray(); |
| 67 | 67 | |
| 68 | - $width = $this->getColumnWidth($commands); |
|
| 68 | + $width=$this->getColumnWidth($commands); |
|
| 69 | 69 | |
| 70 | 70 | /** @var Command $command */ |
| 71 | 71 | foreach ($commands as $command) { |
@@ -80,16 +80,16 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | private function getColumnWidth(array $commands) |
| 82 | 82 | { |
| 83 | - $widths = []; |
|
| 83 | + $widths=[]; |
|
| 84 | 84 | |
| 85 | 85 | foreach ($commands as $command) { |
| 86 | - $widths[] = static::strlen($command->getName()); |
|
| 86 | + $widths[]=static::strlen($command->getName()); |
|
| 87 | 87 | foreach ($command->getAliases() as $alias) { |
| 88 | - $widths[] = static::strlen($alias); |
|
| 88 | + $widths[]=static::strlen($alias); |
|
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - return $widths ? max($widths) + 2 : 0; |
|
| 92 | + return $widths ? max($widths)+2 : 0; |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | */ |
| 102 | 102 | public static function strlen($string) |
| 103 | 103 | { |
| 104 | - if (false === $encoding = mb_detect_encoding($string, null, true)) { |
|
| 104 | + if (false===$encoding=mb_detect_encoding($string, null, true)) { |
|
| 105 | 105 | return strlen($string); |
| 106 | 106 | } |
| 107 | 107 | |
@@ -13,14 +13,14 @@ discard block |
||
| 13 | 13 | * |
| 14 | 14 | * @var string |
| 15 | 15 | */ |
| 16 | - protected $signature = 'manage:ban {--uid=: the user you want to ban} {--time=: Unban time, Supports time that can be resolved by the strtotime method} {--reason=: reason}'; |
|
| 16 | + protected $signature='manage:ban {--uid=: the user you want to ban} {--time=: Unban time, Supports time that can be resolved by the strtotime method} {--reason=: reason}'; |
|
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * The console command description. |
| 20 | 20 | * |
| 21 | 21 | * @var string |
| 22 | 22 | */ |
| 23 | - protected $description = 'Ban a user'; |
|
| 23 | + protected $description='Ban a user'; |
|
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * Create a new command instance. |
@@ -39,23 +39,23 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | public function handle() |
| 41 | 41 | { |
| 42 | - $uid=(int)$this->option('uid'); |
|
| 42 | + $uid=(int) $this->option('uid'); |
|
| 43 | 43 | $reason=$this->option('reason'); |
| 44 | 44 | $time=$this->option('time'); |
| 45 | - $user = User::find($uid); |
|
| 46 | - if(empty($user)) { |
|
| 45 | + $user=User::find($uid); |
|
| 46 | + if (empty($user)) { |
|
| 47 | 47 | $this->line("\n <bg=red;fg=white> Exception </> : <fg=yellow>User Not Found</>\n"); |
| 48 | 48 | return; |
| 49 | 49 | } |
| 50 | - try{ |
|
| 51 | - $ban_time = date('Y-m-d H:i:s',strtotime($time)); |
|
| 50 | + try { |
|
| 51 | + $ban_time=date('Y-m-d H:i:s', strtotime($time)); |
|
| 52 | 52 | UserBanned::create([ |
| 53 | 53 | 'user_id' => $user->id, |
| 54 | 54 | 'reason' => $reason, |
| 55 | 55 | 'removed_at' => $ban_time |
| 56 | 56 | ]); |
| 57 | 57 | $this->line("The user <fg=yellow>{$user->name}</> will be banned until <fg=yellow>{$ban_time}</>"); |
| 58 | - }catch(Throwable $e){ |
|
| 58 | + } catch (Throwable $e) { |
|
| 59 | 59 | $this->line("\n <bg=red;fg=white> Exception </> : <fg=yellow>Wrong Time.</>\n"); |
| 60 | 60 | return; |
| 61 | 61 | } |
@@ -55,7 +55,7 @@ |
||
| 55 | 55 | 'removed_at' => $ban_time |
| 56 | 56 | ]); |
| 57 | 57 | $this->line("The user <fg=yellow>{$user->name}</> will be banned until <fg=yellow>{$ban_time}</>"); |
| 58 | - }catch(Throwable $e){ |
|
| 58 | + } catch(Throwable $e){ |
|
| 59 | 59 | $this->line("\n <bg=red;fg=white> Exception </> : <fg=yellow>Wrong Time.</>\n"); |
| 60 | 60 | return; |
| 61 | 61 | } |
@@ -11,25 +11,25 @@ |
||
| 11 | 11 | * |
| 12 | 12 | * @var string |
| 13 | 13 | */ |
| 14 | - protected $signature = 'manage:create-admin'; |
|
| 14 | + protected $signature='manage:create-admin'; |
|
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | 17 | * The console command description. |
| 18 | 18 | * |
| 19 | 19 | * @var string |
| 20 | 20 | */ |
| 21 | - protected $description = 'Create a admin user'; |
|
| 21 | + protected $description='Create a admin user'; |
|
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | 24 | * Execute the console command. |
| 25 | 25 | */ |
| 26 | 26 | public function handle() |
| 27 | 27 | { |
| 28 | - $userModel = config('admin.database.users_model'); |
|
| 29 | - $username = $this->ask('Please enter a username to login'); |
|
| 30 | - $password = bcrypt($this->secret('Please enter a password to login')); |
|
| 31 | - $name = $this->ask('Please enter a name to display'); |
|
| 32 | - $user = new $userModel(compact('username', 'password', 'name')); |
|
| 28 | + $userModel=config('admin.database.users_model'); |
|
| 29 | + $username=$this->ask('Please enter a username to login'); |
|
| 30 | + $password=bcrypt($this->secret('Please enter a password to login')); |
|
| 31 | + $name=$this->ask('Please enter a name to display'); |
|
| 32 | + $user=new $userModel(compact('username', 'password', 'name')); |
|
| 33 | 33 | $user->save(); |
| 34 | 34 | $this->info("Admin User [$name] created successfully."); |
| 35 | 35 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | { |
| 16 | 16 | use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, Trackable; |
| 17 | 17 | |
| 18 | - public $tries = 5; |
|
| 18 | + public $tries=5; |
|
| 19 | 19 | protected $cid; |
| 20 | 20 | protected $config; |
| 21 | 21 | |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | 'cover'=>false, |
| 34 | 34 | 'advice'=>false, |
| 35 | 35 | ]; |
| 36 | - $this->config=array_merge($default,$config); |
|
| 36 | + $this->config=array_merge($default, $config); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | $cid=$this->cid; |
| 47 | 47 | $config=$this->config; |
| 48 | 48 | |
| 49 | - if (!is_dir(storage_path("app/contest/pdf/"))){ |
|
| 49 | + if (!is_dir(storage_path("app/contest/pdf/"))) { |
|
| 50 | 50 | mkdir(storage_path("app/contest/pdf/"), 0777, true); |
| 51 | 51 | } |
| 52 | 52 | |