| @@ -32,7 +32,7 @@ discard block | ||
| 32 | 32 | */ | 
| 33 | 33 | protected function schedule(Schedule $schedule) | 
| 34 | 34 |      { | 
| 35 | -        $schedule->call(function () { | |
| 35 | +        $schedule->call(function() { | |
| 36 | 36 | $babel=new Babel(); | 
| 37 | 37 |              for ($i=1; $i<=12; $i++) { | 
| 38 | 38 | $babel->judge(); | 
| @@ -41,38 +41,38 @@ discard block | ||
| 41 | 41 |              // file_put_contents(storage_path('app/task-schedule.output'),"Successfully Synced Judger"); | 
| 42 | 42 |          })->everyMinute()->description("Sync Judger"); | 
| 43 | 43 | |
| 44 | -        $schedule->call(function () { | |
| 44 | +        $schedule->call(function() { | |
| 45 | 45 | $rankModel=new RankModel(); | 
| 46 | 46 | $rankModel->rankList(); | 
| 47 | 47 |              // file_put_contents(storage_path('app/task-schedule.output'),"Successfully Updated Rank"); | 
| 48 | 48 |          })->dailyAt('02:00')->description("Update Rank"); | 
| 49 | 49 | |
| 50 | -        $schedule->call(function () { | |
| 50 | +        $schedule->call(function() { | |
| 51 | 51 | $siteMapModel=new SiteMapModel(); | 
| 52 | 52 |              // file_put_contents(storage_path('app/task-schedule.output'),"Successfully Updated SiteMap"); | 
| 53 | 53 |          })->dailyAt('02:00')->description("Update SiteMap"); | 
| 54 | 54 | |
| 55 | -        $schedule->call(function () { | |
| 55 | +        $schedule->call(function() { | |
| 56 | 56 | $groupModel=new GroupModel(); | 
| 57 | 57 | $groupModel->cacheTrendingGroups(); | 
| 58 | 58 |              // file_put_contents(storage_path('app/task-schedule.output'),"Successfully Cached Trending Groups"); | 
| 59 | 59 |          })->dailyAt('03:00')->description("Update Trending Groups"); | 
| 60 | 60 | |
| 61 | 61 |          $schedule->call(function() { | 
| 62 | - $contestModel = new ContestModel(); | |
| 63 | - $syncList = $contestModel->runningContest(); | |
| 64 | -            foreach($syncList as $syncContest) { | |
| 65 | -                if(!isset($syncContest['vcid'])) { | |
| 62 | + $contestModel=new ContestModel(); | |
| 63 | + $syncList=$contestModel->runningContest(); | |
| 64 | +            foreach ($syncList as $syncContest) { | |
| 65 | +                if (!isset($syncContest['vcid'])) { | |
| 66 | 66 | continue; | 
| 67 | 67 | } | 
| 68 | - $className = "App\\Babel\\Extension\\hdu\\Synchronizer"; // TODO Add OJ judgement. | |
| 69 | - $all_data = [ | |
| 68 | + $className="App\\Babel\\Extension\\hdu\\Synchronizer"; // TODO Add OJ judgement. | |
| 69 | + $all_data=[ | |
| 70 | 70 | 'oj'=>"hdu", | 
| 71 | 71 | 'vcid'=>$syncContest['vcid'], | 
| 72 | 72 | 'gid'=>$syncContest['gid'], | 
| 73 | 73 | 'cid'=>$syncContest['cid'], | 
| 74 | 74 | ]; | 
| 75 | - $hduSync = new $className($all_data); | |
| 75 | + $hduSync=new $className($all_data); | |
| 76 | 76 | $hduSync->crawlRank(); | 
| 77 | 77 | $hduSync->crawlClarification(); | 
| 78 | 78 | } | 
| @@ -80,19 +80,19 @@ discard block | ||
| 80 | 80 |          })->everyMinute()->description("Sync Remote Rank and Clarification"); | 
| 81 | 81 | |
| 82 | 82 |          $schedule->call(function() { | 
| 83 | - $contestModel = new ContestModel(); | |
| 84 | - $syncList = $contestModel->runningContest(); | |
| 85 | -            foreach($syncList as $syncContest) { | |
| 86 | -                if(isset($syncContest['crawled'])) { | |
| 87 | -                    if(!$syncContest['crawled']) { | |
| 88 | - $className = "App\\Babel\\Extension\\hdu\\Synchronizer"; | |
| 89 | - $all_data = [ | |
| 83 | + $contestModel=new ContestModel(); | |
| 84 | + $syncList=$contestModel->runningContest(); | |
| 85 | +            foreach ($syncList as $syncContest) { | |
| 86 | +                if (isset($syncContest['crawled'])) { | |
| 87 | +                    if (!$syncContest['crawled']) { | |
| 88 | + $className="App\\Babel\\Extension\\hdu\\Synchronizer"; | |
| 89 | + $all_data=[ | |
| 90 | 90 | 'oj'=>"hdu", | 
| 91 | 91 | 'vcid'=>$syncContest['vcid'], | 
| 92 | 92 | 'gid'=>$syncContest['gid'], | 
| 93 | 93 | 'cid'=>$syncContest['cid'], | 
| 94 | 94 | ]; | 
| 95 | - $hduSync = new $className($all_data); | |
| 95 | + $hduSync=new $className($all_data); | |
| 96 | 96 | $hduSync->scheduleCrawl(); | 
| 97 | 97 | $contestModel->updateCrawlStatus($syncContest['cid']); | 
| 98 | 98 | } | 
| @@ -100,7 +100,7 @@ discard block | ||
| 100 | 100 | } | 
| 101 | 101 |          })->everyMinute()->description("Sync Contest Problem"); | 
| 102 | 102 | |
| 103 | -        $schedule->call(function () { | |
| 103 | +        $schedule->call(function() { | |
| 104 | 104 | $judgerModel=new JudgerModel(); | 
| 105 | 105 | $judgerModel->updateServerStatus(1); | 
| 106 | 106 |              // file_put_contents(storage_path('app/task-schedule.output'),"Successfully Updated Judge Server Status"); | 
| @@ -14,14 +14,14 @@ discard block | ||
| 14 | 14 | * | 
| 15 | 15 | * @var string | 
| 16 | 16 | */ | 
| 17 | -    protected $signature = 'babel:rerank {extension : The package name of the extension} {--vcid= : The target contest of the Crawler} {--gid=1 : The holding group} {--cid= : The NOJ contest}'; | |
| 17 | +    protected $signature='babel:rerank {extension : The package name of the extension} {--vcid= : The target contest of the Crawler} {--gid=1 : The holding group} {--cid= : The NOJ contest}'; | |
| 18 | 18 | |
| 19 | 19 | /** | 
| 20 | 20 | * The console command description. | 
| 21 | 21 | * | 
| 22 | 22 | * @var string | 
| 23 | 23 | */ | 
| 24 | - protected $description = 'Refresh Rank from a remote contest'; | |
| 24 | + protected $description='Refresh Rank from a remote contest'; | |
| 25 | 25 | |
| 26 | 26 | /** | 
| 27 | 27 | * Create a new command instance. | 
| @@ -40,18 +40,18 @@ discard block | ||
| 40 | 40 | */ | 
| 41 | 41 | public function handle() | 
| 42 | 42 |      { | 
| 43 | -        $extension = $this->argument('extension'); | |
| 44 | -        $vcid = $this->option('vcid'); | |
| 45 | -        $gid = $this->option('gid'); | |
| 46 | -        $cid = $this->option('cid'); | |
| 47 | - $className = "App\\Babel\\Extension\\$extension\\Synchronizer"; | |
| 48 | - $all_data = [ | |
| 43 | +        $extension=$this->argument('extension'); | |
| 44 | +        $vcid=$this->option('vcid'); | |
| 45 | +        $gid=$this->option('gid'); | |
| 46 | +        $cid=$this->option('cid'); | |
| 47 | + $className="App\\Babel\\Extension\\$extension\\Synchronizer"; | |
| 48 | + $all_data=[ | |
| 49 | 49 | 'oj'=>$extension, | 
| 50 | 50 | 'vcid'=>$vcid, | 
| 51 | 51 | 'gid'=>$gid, | 
| 52 | 52 | 'cid'=>$cid, | 
| 53 | 53 | ]; | 
| 54 | - $Sync = new $className($all_data); | |
| 54 | + $Sync=new $className($all_data); | |
| 55 | 55 | $Sync->crawlRank(); | 
| 56 | 56 | } | 
| 57 | 57 | } | 
| @@ -111,8 +111,8 @@ discard block | ||
| 111 | 111 | |
| 112 | 112 | public function gcode($cid) | 
| 113 | 113 |      { | 
| 114 | - $gid = $this->gid($cid); | |
| 115 | -        return DB::table('group')->where('gid','=',$gid)->first()["gcode"]; | |
| 114 | + $gid=$this->gid($cid); | |
| 115 | +        return DB::table('group')->where('gid', '=', $gid)->first()["gcode"]; | |
| 116 | 116 | } | 
| 117 | 117 | |
| 118 | 118 | public function runningContest() | 
| @@ -137,19 +137,19 @@ discard block | ||
| 137 | 137 | |
| 138 | 138 | public function listForSetting($gid) | 
| 139 | 139 |      { | 
| 140 | - $uid = Auth::user()->id; | |
| 141 | -        $group_contests = DB::table('contest') | |
| 142 | -            ->where('gid',$gid) | |
| 143 | -            ->orderBy('begin_time','desc') | |
| 140 | + $uid=Auth::user()->id; | |
| 141 | +        $group_contests=DB::table('contest') | |
| 142 | +            ->where('gid', $gid) | |
| 143 | +            ->orderBy('begin_time', 'desc') | |
| 144 | 144 | ->get()->all(); | 
| 145 | - $groupModel = new GroupModel(); | |
| 146 | - $group_clearance = $groupModel->judgeClearance($gid,$uid); | |
| 145 | + $groupModel=new GroupModel(); | |
| 146 | + $group_clearance=$groupModel->judgeClearance($gid, $uid); | |
| 147 | 147 |          foreach ($group_contests as &$contest) { | 
| 148 | - $contest['is_admin'] = ($contest['assign_uid'] == $uid || $group_clearance == 3); | |
| 149 | - $begin_stamps = strtotime($contest['begin_time']); | |
| 150 | - $end_stamps = strtotime($contest['end_time']); | |
| 151 | - $contest['status'] = time() >= $end_stamps ? 1 | |
| 152 | - : (time() <= $begin_stamps ? -1 : 0); | |
| 148 | + $contest['is_admin']=($contest['assign_uid']==$uid || $group_clearance==3); | |
| 149 | + $begin_stamps=strtotime($contest['begin_time']); | |
| 150 | + $end_stamps=strtotime($contest['end_time']); | |
| 151 | + $contest['status']=time()>=$end_stamps ? 1 | |
| 152 | + : (time()<=$begin_stamps ? -1 : 0); | |
| 153 | 153 | $contest["rule_parsed"]=$this->rule[$contest["rule"]]; | 
| 154 | 154 | $contest["date_parsed"]=[ | 
| 155 | 155 | "date"=>date_format(date_create($contest["begin_time"]), 'j'), | 
| @@ -166,9 +166,9 @@ discard block | ||
| 166 | 166 | // "gid"=>$gid | 
| 167 | 167 |          // ])->orderBy('begin_time', 'desc')->get()->all(); | 
| 168 | 168 | $preQuery=DB::table($this->tableName); | 
| 169 | -        $paginator=$preQuery->where('gid','=',$gid)->orderBy('begin_time', 'desc')->paginate(10); | |
| 169 | +        $paginator=$preQuery->where('gid', '=', $gid)->orderBy('begin_time', 'desc')->paginate(10); | |
| 170 | 170 | $contest_list=$paginator->all(); | 
| 171 | -        if(empty($contest_list)){ | |
| 171 | +        if (empty($contest_list)) { | |
| 172 | 172 | return null; | 
| 173 | 173 | } | 
| 174 | 174 | |
| @@ -193,7 +193,7 @@ discard block | ||
| 193 | 193 | ])->first()["rule"]; | 
| 194 | 194 | } | 
| 195 | 195 | |
| 196 | - public function list($filter,$uid) | |
| 196 | + public function list($filter, $uid) | |
| 197 | 197 |      { | 
| 198 | 198 |          if ($uid) { | 
| 199 | 199 |              //$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); | 
| @@ -217,15 +217,15 @@ discard block | ||
| 217 | 217 |                  if ($filter['practice']) { | 
| 218 | 218 | $paginator=$paginator->where(["practice"=>$filter['practice']]); | 
| 219 | 219 | } | 
| 220 | - $paginator = $paginator ->paginate(10); | |
| 221 | -            }elseif($filter['public']=='0'){ | |
| 220 | + $paginator=$paginator ->paginate(10); | |
| 221 | +            }elseif ($filter['public']=='0') { | |
| 222 | 222 |                  $paginator=DB::table('group_member') | 
| 223 | 223 |                  ->groupBy('contest.cid') | 
| 224 | 224 |                  ->select('contest.*') | 
| 225 | 225 |                  ->join('contest', 'group_member.gid', '=', 'contest.gid') | 
| 226 | 226 |                  ->leftJoin('contest_participant', 'contest.cid', '=', 'contest_participant.cid') | 
| 227 | 227 | ->where( | 
| 228 | -                    function ($query) use ($filter,$uid) { | |
| 228 | +                    function($query) use ($filter, $uid) { | |
| 229 | 229 |                          if ($filter['rule']) { | 
| 230 | 230 | $query=$query->where(["rule"=>$filter['rule']]); | 
| 231 | 231 | } | 
| @@ -248,14 +248,14 @@ discard block | ||
| 248 | 248 | ) | 
| 249 | 249 |                  ->orderBy('contest.begin_time', 'desc') | 
| 250 | 250 | ->paginate(10); | 
| 251 | -            }else{ | |
| 251 | +            } else { | |
| 252 | 252 |                  $paginator=DB::table('group_member') | 
| 253 | 253 |                  ->groupBy('contest.cid') | 
| 254 | 254 |                  ->select('contest.*') | 
| 255 | 255 |                  ->join('contest', 'group_member.gid', '=', 'contest.gid') | 
| 256 | 256 |                  ->leftJoin('contest_participant', 'contest.cid', '=', 'contest_participant.cid') | 
| 257 | 257 | ->where( | 
| 258 | -                    function ($query) use ($filter) { | |
| 258 | +                    function($query) use ($filter) { | |
| 259 | 259 |                          if ($filter['rule']) { | 
| 260 | 260 | $query=$query->where(["rule"=>$filter['rule']]); | 
| 261 | 261 | } | 
| @@ -276,7 +276,7 @@ discard block | ||
| 276 | 276 | } | 
| 277 | 277 | ) | 
| 278 | 278 | ->orWhere( | 
| 279 | -                    function ($query) use ($filter,$uid) { | |
| 279 | +                    function($query) use ($filter, $uid) { | |
| 280 | 280 |                          if ($filter['rule']) { | 
| 281 | 281 | $query=$query->where(["rule"=>$filter['rule']]); | 
| 282 | 282 | } | 
| @@ -322,7 +322,7 @@ discard block | ||
| 322 | 322 |              if ($filter['practice']) { | 
| 323 | 323 | $paginator=$paginator->where(["practice"=>$filter['practice']]); | 
| 324 | 324 | } | 
| 325 | - $paginator = $paginator ->paginate(10); | |
| 325 | + $paginator=$paginator ->paginate(10); | |
| 326 | 326 | } | 
| 327 | 327 | $contest_list=$paginator->all(); | 
| 328 | 328 |          foreach ($contest_list as &$c) { | 
| @@ -360,14 +360,14 @@ discard block | ||
| 360 | 360 | } | 
| 361 | 361 | } | 
| 362 | 362 | |
| 363 | - public function registContest($cid,$uid) | |
| 363 | + public function registContest($cid, $uid) | |
| 364 | 364 |      { | 
| 365 | 365 |          $registered=DB::table("contest_participant")->where([ | 
| 366 | 366 | "cid"=>$cid, | 
| 367 | 367 | "uid"=>$uid | 
| 368 | 368 | ])->first(); | 
| 369 | 369 | |
| 370 | -        if(empty($registered)){ | |
| 370 | +        if (empty($registered)) { | |
| 371 | 371 |              DB::table("contest_participant")->insert([ | 
| 372 | 372 | "cid"=>$cid, | 
| 373 | 373 | "uid"=>$uid, | 
| @@ -400,9 +400,9 @@ discard block | ||
| 400 | 400 | public function problems($cid) | 
| 401 | 401 |      { | 
| 402 | 402 |          return DB::table('contest_problem') | 
| 403 | -            ->join('problem','contest_problem.pid','=','problem.pid') | |
| 404 | -            ->where('cid',$cid) | |
| 405 | -            ->select('problem.pid as pid','pcode','number') | |
| 403 | +            ->join('problem', 'contest_problem.pid', '=', 'problem.pid') | |
| 404 | +            ->where('cid', $cid) | |
| 405 | +            ->select('problem.pid as pid', 'pcode', 'number') | |
| 406 | 406 |              ->orderBy('number') | 
| 407 | 407 | ->get()->all(); | 
| 408 | 408 | } | 
| @@ -424,18 +424,18 @@ discard block | ||
| 424 | 424 |          $end_time=strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]); | 
| 425 | 425 | |
| 426 | 426 |          foreach ($problemSet as &$p) { | 
| 427 | -            if($p['practice']){ | |
| 428 | -                $tags = DB::table("group_problem_tag") | |
| 429 | -                ->where('gid',$p['gid']) | |
| 430 | -                ->where('pid',$p['pid']) | |
| 427 | +            if ($p['practice']) { | |
| 428 | +                $tags=DB::table("group_problem_tag") | |
| 429 | +                ->where('gid', $p['gid']) | |
| 430 | +                ->where('pid', $p['pid']) | |
| 431 | 431 | ->get()->all(); | 
| 432 | - $tags_arr = []; | |
| 433 | -                if(!empty($tags)){ | |
| 432 | + $tags_arr=[]; | |
| 433 | +                if (!empty($tags)) { | |
| 434 | 434 |                      foreach ($tags as $value) { | 
| 435 | - array_push($tags_arr,$value['tag']); | |
| 435 | + array_push($tags_arr, $value['tag']); | |
| 436 | 436 | } | 
| 437 | 437 | } | 
| 438 | - $p['tags'] = $tags_arr; | |
| 438 | + $p['tags']=$tags_arr; | |
| 439 | 439 | } | 
| 440 | 440 |              if ($contest_rule==1) { | 
| 441 | 441 |                  $prob_stat=DB::table("submission")->select( | 
| @@ -696,7 +696,7 @@ discard block | ||
| 696 | 696 | "problem_detail" => $prob_detail | 
| 697 | 697 | ]; | 
| 698 | 698 | } | 
| 699 | -            usort($ret, function ($a, $b) { | |
| 699 | +            usort($ret, function($a, $b) { | |
| 700 | 700 |                  if ($a["score"]==$b["score"]) { | 
| 701 | 701 |                      if ($a["penalty"]==$b["penalty"]) { | 
| 702 | 702 | return 0; | 
| @@ -743,7 +743,7 @@ discard block | ||
| 743 | 743 | "problem_detail" => $prob_detail | 
| 744 | 744 | ]; | 
| 745 | 745 | } | 
| 746 | -            usort($ret, function ($a, $b) { | |
| 746 | +            usort($ret, function($a, $b) { | |
| 747 | 747 |                  if ($a["score"]==$b["score"]) { | 
| 748 | 748 |                      if ($a["solved"]==$b["solved"]) { | 
| 749 | 749 | return 0; | 
| @@ -765,7 +765,7 @@ discard block | ||
| 765 | 765 | return $ret; | 
| 766 | 766 | } | 
| 767 | 767 | |
| 768 | - public function contestRank($cid, $uid = 0) | |
| 768 | + public function contestRank($cid, $uid=0) | |
| 769 | 769 |      { | 
| 770 | 770 | // [ToDo] If the current user's in the organizer group show nick name | 
| 771 | 771 | // [ToDo] The participants determination | 
| @@ -783,31 +783,31 @@ discard block | ||
| 783 | 783 | "gid" => $contest_info["gid"] | 
| 784 | 784 |          ])->where("role", ">", 0)->first()); | 
| 785 | 785 | |
| 786 | - $clearance = $this -> judgeClearance($cid, $uid); | |
| 786 | + $clearance=$this -> judgeClearance($cid, $uid); | |
| 787 | 787 | |
| 788 | 788 | /** New Version With MySQL */ | 
| 789 | 789 |          $end_time=strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]); | 
| 790 | 790 | |
| 791 | -        if(time() < $end_time){ | |
| 792 | -            if($clearance == 3){ | |
| 791 | +        if (time()<$end_time) { | |
| 792 | +            if ($clearance==3) { | |
| 793 | 793 |                  $contestRankRaw=Cache::tags(['contest', 'rank'])->get("contestAdmin$cid"); | 
| 794 | -            }else{ | |
| 794 | +            } else { | |
| 795 | 795 | $contestRankRaw=Cache::tags(['contest', 'rank'])->get($cid); | 
| 796 | 796 | } | 
| 797 | -            if(!isset($contestRankRaw)){ | |
| 797 | +            if (!isset($contestRankRaw)) { | |
| 798 | 798 | $contestRankRaw=$this->contestRankCache($cid); | 
| 799 | 799 | } | 
| 800 | -        }else{ | |
| 801 | -            if($clearance == 3){ | |
| 800 | +        } else { | |
| 801 | +            if ($clearance==3) { | |
| 802 | 802 |                  $contestRankRaw=Cache::tags(['contest', 'rank'])->get("contestAdmin$cid"); | 
| 803 | 803 |                  if (!isset($contestRankRaw)) { | 
| 804 | 804 | $contestRankRaw=$this->contestRankCache($cid); | 
| 805 | 805 | } | 
| 806 | -            }else{ | |
| 806 | +            } else { | |
| 807 | 807 | $contestRankRaw=$this->getContestRankFromMySQL($cid); | 
| 808 | -                if(!isset($contestRankRaw)){ | |
| 808 | +                if (!isset($contestRankRaw)) { | |
| 809 | 809 | $contestRankRaw=Cache::tags(['contest', 'rank'])->get($cid); | 
| 810 | -                    if(!isset($contestRankRaw)){ | |
| 810 | +                    if (!isset($contestRankRaw)) { | |
| 811 | 811 | $contestRankRaw=$this->contestRankCache($cid); | 
| 812 | 812 | } | 
| 813 | 813 | $this->storeContestRankInMySQL($cid, $contestRankRaw); | 
| @@ -825,15 +825,15 @@ discard block | ||
| 825 | 825 | // $contestRankRaw=$this->contestRankCache($cid); | 
| 826 | 826 | // } | 
| 827 | 827 | // } | 
| 828 | -        if($contest_info["rule"]==1){ | |
| 828 | +        if ($contest_info["rule"]==1) { | |
| 829 | 829 |              foreach ($contestRankRaw as &$cr) { | 
| 830 | - $solved = 0; | |
| 831 | -                foreach($cr['problem_detail'] as $pd){ | |
| 832 | -                    if(!empty($pd['solved_time_parsed'])){ | |
| 833 | - $solved ++; | |
| 830 | + $solved=0; | |
| 831 | +                foreach ($cr['problem_detail'] as $pd) { | |
| 832 | +                    if (!empty($pd['solved_time_parsed'])) { | |
| 833 | + $solved++; | |
| 834 | 834 | } | 
| 835 | 835 | } | 
| 836 | - $cr['solved'] = $solved; | |
| 836 | + $cr['solved']=$solved; | |
| 837 | 837 | } | 
| 838 | 838 | } | 
| 839 | 839 | |
| @@ -882,16 +882,16 @@ discard block | ||
| 882 | 882 | |
| 883 | 883 | public function getClarificationList($cid) | 
| 884 | 884 |      { | 
| 885 | - $uid = Auth::user()->id; | |
| 886 | - $clearance = $this -> judgeClearance($cid, $uid); | |
| 887 | -        if($clearance == 3){ | |
| 885 | + $uid=Auth::user()->id; | |
| 886 | + $clearance=$this -> judgeClearance($cid, $uid); | |
| 887 | +        if ($clearance==3) { | |
| 888 | 888 |              return DB::table("contest_clarification")->where([ | 
| 889 | 889 | "cid"=>$cid | 
| 890 | 890 |              ])->orderBy('create_time', 'desc')->get()->all(); | 
| 891 | -        }else{ | |
| 891 | +        } else { | |
| 892 | 892 |              return DB::table("contest_clarification")->where([ | 
| 893 | 893 | "cid"=>$cid | 
| 894 | -            ])->where(function ($query) { | |
| 894 | +            ])->where(function($query) { | |
| 895 | 895 | $query->where([ | 
| 896 | 896 | "public"=>1 | 
| 897 | 897 | ])->orWhere([ | 
| @@ -1036,7 +1036,7 @@ discard block | ||
| 1036 | 1036 | public function getContestRecord($cid) | 
| 1037 | 1037 |      { | 
| 1038 | 1038 | $basicInfo=$this->basic($cid); | 
| 1039 | -        $userInfo=DB::table('group_member')->where('gid',$basicInfo["gid"])->where('uid',Auth::user()->id)->get()->first(); | |
| 1039 | +        $userInfo=DB::table('group_member')->where('gid', $basicInfo["gid"])->where('uid', Auth::user()->id)->get()->first(); | |
| 1040 | 1040 |          $problemSet_temp=DB::table("contest_problem")->join("problem", "contest_problem.pid", "=", "problem.pid")->where([ | 
| 1041 | 1041 | "cid"=>$cid | 
| 1042 | 1042 |          ])->orderBy('ncode', 'asc')->select("ncode", "alias", "contest_problem.pid as pid", "title", "points", "tot_score")->get()->all(); | 
| @@ -1049,7 +1049,7 @@ discard block | ||
| 1049 | 1049 |          $end_time=strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]); | 
| 1050 | 1050 | $contestEnd=time()>$end_time; | 
| 1051 | 1051 | |
| 1052 | -        if($userInfo==null || $userInfo["role"]!=3){ | |
| 1052 | +        if ($userInfo==null || $userInfo["role"]!=3) { | |
| 1053 | 1053 |              if ($basicInfo["status_visibility"]==2) { | 
| 1054 | 1054 | // View all | 
| 1055 | 1055 |                  $paginator=DB::table("submission")->where([ | 
| @@ -1063,7 +1063,7 @@ discard block | ||
| 1063 | 1063 | "users.id", | 
| 1064 | 1064 | "=", | 
| 1065 | 1065 | "submission.uid" | 
| 1066 | -                )->where(function ($query) use ($frozen_time) { | |
| 1066 | +                )->where(function($query) use ($frozen_time) { | |
| 1067 | 1067 | $query->where( | 
| 1068 | 1068 | "submission_date", | 
| 1069 | 1069 | "<", | 
| @@ -1125,7 +1125,7 @@ discard block | ||
| 1125 | 1125 | "records"=>[] | 
| 1126 | 1126 | ]; | 
| 1127 | 1127 | } | 
| 1128 | -        }else{ | |
| 1128 | +        } else { | |
| 1129 | 1129 |              if ($basicInfo["status_visibility"]==2) { | 
| 1130 | 1130 | // View all | 
| 1131 | 1131 |                  $paginator=DB::table("submission")->where([ | 
| @@ -1237,21 +1237,21 @@ discard block | ||
| 1237 | 1237 |          if ($uid==0) { | 
| 1238 | 1238 | return 0; | 
| 1239 | 1239 | } | 
| 1240 | - $groupModel = new GroupModel(); | |
| 1240 | + $groupModel=new GroupModel(); | |
| 1241 | 1241 |          $contest_info=DB::table("contest")->where("cid", $cid)->first(); | 
| 1242 | -        $userInfo=DB::table('group_member')->where('gid',$contest_info["gid"])->where('uid',$uid)->get()->first(); | |
| 1242 | +        $userInfo=DB::table('group_member')->where('gid', $contest_info["gid"])->where('uid', $uid)->get()->first(); | |
| 1243 | 1243 | |
| 1244 | -        if(empty($contest_info)){ | |
| 1244 | +        if (empty($contest_info)) { | |
| 1245 | 1245 | // contest not exist | 
| 1246 | 1246 | return 0; | 
| 1247 | 1247 | } | 
| 1248 | 1248 | |
| 1249 | -        if($uid == $contest_info['assign_uid'] || $groupModel->judgeClearance($contest_info['gid'],$uid) == 3){ | |
| 1249 | +        if ($uid==$contest_info['assign_uid'] || $groupModel->judgeClearance($contest_info['gid'], $uid)==3) { | |
| 1250 | 1250 | return 3; | 
| 1251 | 1251 | } | 
| 1252 | 1252 | |
| 1253 | - $contest_started = strtotime($contest_info['begin_time']) < time(); | |
| 1254 | - $contest_ended = strtotime($contest_info['end_time']) < time(); | |
| 1253 | + $contest_started=strtotime($contest_info['begin_time'])<time(); | |
| 1254 | + $contest_ended=strtotime($contest_info['end_time'])<time(); | |
| 1255 | 1255 |          if (!$contest_started) { | 
| 1256 | 1256 | // not started or do not exist | 
| 1257 | 1257 | return 0; | 
| @@ -1342,12 +1342,12 @@ discard block | ||
| 1342 | 1342 | public function updateProfessionalRate($cid) | 
| 1343 | 1343 |      { | 
| 1344 | 1344 | $basic=$this->basic($cid); | 
| 1345 | -        if($basic["rated"]&&!$basic["is_rated"]){ | |
| 1345 | +        if ($basic["rated"] && !$basic["is_rated"]) { | |
| 1346 | 1346 | $ratingCalculator=new RatingCalculator($cid); | 
| 1347 | -            if($ratingCalculator->calculate()){ | |
| 1347 | +            if ($ratingCalculator->calculate()) { | |
| 1348 | 1348 | $ratingCalculator->storage(); | 
| 1349 | 1349 | return true; | 
| 1350 | -            }else{ | |
| 1350 | +            } else { | |
| 1351 | 1351 | return false; | 
| 1352 | 1352 | } | 
| 1353 | 1353 |          } else { | 
| @@ -1355,14 +1355,14 @@ discard block | ||
| 1355 | 1355 | } | 
| 1356 | 1356 | } | 
| 1357 | 1357 | |
| 1358 | - public function contestUpdate($cid,$data,$problems) | |
| 1358 | + public function contestUpdate($cid, $data, $problems) | |
| 1359 | 1359 |      { | 
| 1360 | -        DB::transaction(function () use ($cid, $data, $problems) { | |
| 1360 | +        DB::transaction(function() use ($cid, $data, $problems) { | |
| 1361 | 1361 | DB::table($this->tableName) | 
| 1362 | 1362 |                  ->where('cid', $cid) | 
| 1363 | 1363 | ->update($data); | 
| 1364 | 1364 |              DB::table('contest_problem') | 
| 1365 | -                ->where('cid',$cid) | |
| 1365 | +                ->where('cid', $cid) | |
| 1366 | 1366 | ->delete(); | 
| 1367 | 1367 |              foreach ($problems as $p) { | 
| 1368 | 1368 |                  $pid=DB::table("problem")->where(["pcode"=>$p["pcode"]])->select("pid")->first()["pid"]; | 
| @@ -1378,10 +1378,10 @@ discard block | ||
| 1378 | 1378 | }, 5); | 
| 1379 | 1379 | } | 
| 1380 | 1380 | |
| 1381 | - public function contestUpdateProblem($cid,$problems) | |
| 1381 | + public function contestUpdateProblem($cid, $problems) | |
| 1382 | 1382 |      { | 
| 1383 | 1383 |          DB::table('contest_problem') | 
| 1384 | -                ->where('cid',$cid) | |
| 1384 | +                ->where('cid', $cid) | |
| 1385 | 1385 | ->delete(); | 
| 1386 | 1386 |          foreach ($problems as $p) { | 
| 1387 | 1387 |              DB::table("contest_problem")->insertGetId([ | 
| @@ -1396,7 +1396,7 @@ discard block | ||
| 1396 | 1396 | } | 
| 1397 | 1397 | public function arrangeContest($gid, $config, $problems) | 
| 1398 | 1398 |      { | 
| 1399 | -        DB::transaction(function () use ($gid, $config, $problems) { | |
| 1399 | +        DB::transaction(function() use ($gid, $config, $problems) { | |
| 1400 | 1400 | $cid=DB::table($this->tableName)->insertGetId([ | 
| 1401 | 1401 | "gid"=>$gid, | 
| 1402 | 1402 | "name"=>$config["name"], | 
| @@ -1410,7 +1410,7 @@ discard block | ||
| 1410 | 1410 | "rule"=>1, //todo | 
| 1411 | 1411 | "begin_time"=>$config["begin_time"], | 
| 1412 | 1412 | "end_time"=>$config["end_time"], | 
| 1413 | - "vcid"=>isset($config["vcid"])?$config["vcid"]:null, | |
| 1413 | + "vcid"=>isset($config["vcid"]) ? $config["vcid"] : null, | |
| 1414 | 1414 | "public"=>0, //todo | 
| 1415 | 1415 | "registration"=>0, //todo | 
| 1416 | 1416 | "registration_due"=>null, //todo | 
| @@ -1418,7 +1418,7 @@ discard block | ||
| 1418 | 1418 | "froze_length"=>0, //todo | 
| 1419 | 1419 | "status_visibility"=>2, //todo | 
| 1420 | 1420 |                  "create_time"=>date("Y-m-d H:i:s"), | 
| 1421 | - "crawled" => isset($config['vcid'])?$config['crawled'] : null, | |
| 1421 | + "crawled" => isset($config['vcid']) ? $config['crawled'] : null, | |
| 1422 | 1422 | "audit_status"=>1 //todo | 
| 1423 | 1423 | ]); | 
| 1424 | 1424 | |
| @@ -1436,33 +1436,33 @@ discard block | ||
| 1436 | 1436 | }, 5); | 
| 1437 | 1437 | } | 
| 1438 | 1438 | |
| 1439 | - public function updateContestRankTable($cid,$sub) | |
| 1439 | + public function updateContestRankTable($cid, $sub) | |
| 1440 | 1440 |      { | 
| 1441 | -        $lock = Cache::lock("contestrank$cid",10); | |
| 1442 | -        try{ | |
| 1443 | -            if($lock->get()){ | |
| 1444 | -                if(Cache::tags(['contest','rank'])->get($cid) != null){ | |
| 1445 | - $chache = Cache::tags(['contest','data'])->get($cid); | |
| 1446 | - $ret = Cache::tags(['contest','rank'])->get($cid); | |
| 1447 | - | |
| 1448 | - $id = 0; | |
| 1449 | - | |
| 1450 | -                    foreach($chache['problemSet'] as $key => $p){ | |
| 1451 | -                        if ($p['pid'] == $sub['pid']){ | |
| 1452 | - $chache['problemSet'][$key]['cpid'] = $key; | |
| 1453 | - $id = $key; | |
| 1441 | +        $lock=Cache::lock("contestrank$cid", 10); | |
| 1442 | +        try { | |
| 1443 | +            if ($lock->get()) { | |
| 1444 | +                if (Cache::tags(['contest', 'rank'])->get($cid)!=null) { | |
| 1445 | + $chache=Cache::tags(['contest', 'data'])->get($cid); | |
| 1446 | + $ret=Cache::tags(['contest', 'rank'])->get($cid); | |
| 1447 | + | |
| 1448 | + $id=0; | |
| 1449 | + | |
| 1450 | +                    foreach ($chache['problemSet'] as $key => $p) { | |
| 1451 | +                        if ($p['pid']==$sub['pid']) { | |
| 1452 | + $chache['problemSet'][$key]['cpid']=$key; | |
| 1453 | + $id=$key; | |
| 1454 | 1454 | } | 
| 1455 | 1455 | } | 
| 1456 | 1456 | |
| 1457 | - $ret = $this->updateContestRankDetail($chache['contest_info'],$chache['problemSet'][$id],$cid,$sub['uid'],$ret); | |
| 1458 | - $ret = $this->sortContestRankTable($chache['contest_info'],$cid,$ret); | |
| 1457 | + $ret=$this->updateContestRankDetail($chache['contest_info'], $chache['problemSet'][$id], $cid, $sub['uid'], $ret); | |
| 1458 | + $ret=$this->sortContestRankTable($chache['contest_info'], $cid, $ret); | |
| 1459 | 1459 | |
| 1460 | -                    if (time() < $chache['frozen_time']){ | |
| 1460 | +                    if (time()<$chache['frozen_time']) { | |
| 1461 | 1461 | Cache::tags(['contest', 'rank'])->put($cid, $ret); | 
| 1462 | 1462 | } | 
| 1463 | 1463 |                      Cache::tags(['contest', 'rank'])->put("contestAdmin$cid", $ret); | 
| 1464 | 1464 | } | 
| 1465 | -                else{ | |
| 1465 | +                else { | |
| 1466 | 1466 | $ret=[]; | 
| 1467 | 1467 | $chache=[]; | 
| 1468 | 1468 |                      $chache['contest_info']=DB::table("contest")->where("cid", $cid)->first(); | 
| @@ -1479,7 +1479,7 @@ discard block | ||
| 1479 | 1479 | "cid"=>$cid, | 
| 1480 | 1480 | "audit"=>1 | 
| 1481 | 1481 |                          ])->select('uid')->get()->all(); | 
| 1482 | -                    }else{ | |
| 1482 | +                    } else { | |
| 1483 | 1483 |                          $submissionUsers=DB::table("submission")->where([ | 
| 1484 | 1484 | "cid"=>$cid | 
| 1485 | 1485 | ])->where( | 
| @@ -1492,39 +1492,39 @@ discard block | ||
| 1492 | 1492 |                          ])->select('uid')->groupBy('uid')->get()->all(); | 
| 1493 | 1493 | } | 
| 1494 | 1494 | |
| 1495 | - $chacheAdmin = $chache; | |
| 1495 | + $chacheAdmin=$chache; | |
| 1496 | 1496 | |
| 1497 | 1497 |                      foreach ($submissionUsers as $s) { | 
| 1498 | 1498 |                          foreach ($chache['problemSet'] as $key => $p) { | 
| 1499 | - $p['cpid'] = $key; | |
| 1500 | - $ret = $this->updateContestRankDetail($chache['contest_info'],$p,$cid,$s['uid'],$ret); | |
| 1499 | + $p['cpid']=$key; | |
| 1500 | + $ret=$this->updateContestRankDetail($chache['contest_info'], $p, $cid, $s['uid'], $ret); | |
| 1501 | 1501 | } | 
| 1502 | 1502 | } | 
| 1503 | - $ret = $this->sortContestRankTable($chache['contest_info'],$cid,$ret); | |
| 1503 | + $ret=$this->sortContestRankTable($chache['contest_info'], $cid, $ret); | |
| 1504 | 1504 | Cache::tags(['contest', 'rank'])->put($cid, $ret); | 
| 1505 | 1505 | |
| 1506 | 1506 | $retAdmin=[]; | 
| 1507 | 1507 |                      foreach ($submissionUsersAdmin as $s) { | 
| 1508 | 1508 |                          foreach ($chacheAdmin['problemSet'] as $key => $p) { | 
| 1509 | - $p['cpid'] = $key; | |
| 1510 | - $retAdmin = $this->updateContestRankDetail($chacheAdmin['contest_info'],$p,$cid,$s['uid'],$retAdmin); | |
| 1509 | + $p['cpid']=$key; | |
| 1510 | + $retAdmin=$this->updateContestRankDetail($chacheAdmin['contest_info'], $p, $cid, $s['uid'], $retAdmin); | |
| 1511 | 1511 | } | 
| 1512 | 1512 | } | 
| 1513 | - $retAdmin = $this->sortContestRankTable($chacheAdmin['contest_info'],$cid,$retAdmin); | |
| 1513 | + $retAdmin=$this->sortContestRankTable($chacheAdmin['contest_info'], $cid, $retAdmin); | |
| 1514 | 1514 |                      Cache::tags(['contest', 'rank'])->put("contestAdmin$cid", $retAdmin); | 
| 1515 | 1515 | } | 
| 1516 | 1516 | } | 
| 1517 | -        }catch(LockTimeoutException $e){ | |
| 1517 | +        } catch (LockTimeoutException $e) { | |
| 1518 | 1518 |              Log::warning("Contest Rank Lock Timed Out"); | 
| 1519 | -        }finally{ | |
| 1519 | +        } finally { | |
| 1520 | 1520 | optional($lock)->release(); | 
| 1521 | 1521 | } | 
| 1522 | 1522 | } | 
| 1523 | 1523 | |
| 1524 | - public function sortContestRankTable($contest_info,$cid,$ret) | |
| 1524 | + public function sortContestRankTable($contest_info, $cid, $ret) | |
| 1525 | 1525 |      { | 
| 1526 | -        if ($contest_info["rule"]==1){ | |
| 1527 | -            usort($ret, function ($a, $b) { | |
| 1526 | +        if ($contest_info["rule"]==1) { | |
| 1527 | +            usort($ret, function($a, $b) { | |
| 1528 | 1528 |                  if ($a["score"]==$b["score"]) { | 
| 1529 | 1529 |                      if ($a["penalty"]==$b["penalty"]) { | 
| 1530 | 1530 | return 0; | 
| @@ -1539,8 +1539,8 @@ discard block | ||
| 1539 | 1539 | return 1; | 
| 1540 | 1540 | } | 
| 1541 | 1541 | }); | 
| 1542 | -        }else if ($contest_info["rule"]==2){ | |
| 1543 | -            usort($ret, function ($a, $b) { | |
| 1542 | +        } else if ($contest_info["rule"]==2) { | |
| 1543 | +            usort($ret, function($a, $b) { | |
| 1544 | 1544 |                  if ($a["score"]==$b["score"]) { | 
| 1545 | 1545 |                      if ($a["solved"]==$b["solved"]) { | 
| 1546 | 1546 | return 0; | 
| @@ -1559,21 +1559,21 @@ discard block | ||
| 1559 | 1559 | return $ret; | 
| 1560 | 1560 | } | 
| 1561 | 1561 | |
| 1562 | - public function updateContestRankDetail($contest_info,$problem,$cid,$uid,$ret) | |
| 1562 | + public function updateContestRankDetail($contest_info, $problem, $cid, $uid, $ret) | |
| 1563 | 1563 |      { | 
| 1564 | - $id = count($ret); | |
| 1565 | -        foreach($ret as $key => $r){ | |
| 1566 | - if($r['uid'] == $uid) | |
| 1567 | - $id = $key; | |
| 1564 | + $id=count($ret); | |
| 1565 | +        foreach ($ret as $key => $r) { | |
| 1566 | + if ($r['uid']==$uid) | |
| 1567 | + $id=$key; | |
| 1568 | 1568 | } | 
| 1569 | 1569 |          if ($contest_info["rule"]==1) { | 
| 1570 | 1570 | // ACM/ICPC Mode | 
| 1571 | -            if($id == count($ret)){ | |
| 1572 | - $prob_detail = []; | |
| 1573 | - $totPen = 0; | |
| 1574 | - $totScore = 0; | |
| 1575 | -            }else{ | |
| 1576 | - $prob_detail = $ret[$id]['problem_detail']; | |
| 1571 | +            if ($id==count($ret)) { | |
| 1572 | + $prob_detail=[]; | |
| 1573 | + $totPen=0; | |
| 1574 | + $totScore=0; | |
| 1575 | +            } else { | |
| 1576 | + $prob_detail=$ret[$id]['problem_detail']; | |
| 1577 | 1577 | $totPen=$ret[$id]['penalty']; | 
| 1578 | 1578 | $totScore=$ret[$id]['score']; | 
| 1579 | 1579 | }; | 
| @@ -1608,12 +1608,12 @@ discard block | ||
| 1608 | 1608 | ]; | 
| 1609 | 1609 |          } elseif ($contest_info["rule"]==2) { | 
| 1610 | 1610 | // OI Mode | 
| 1611 | -            if($id == count($ret)){ | |
| 1612 | - $prob_detail = []; | |
| 1613 | - $totSolved = 0; | |
| 1614 | - $totScore = 0; | |
| 1615 | -            }else{ | |
| 1616 | - $prob_detail = $ret[$id]['problem_detail']; | |
| 1611 | +            if ($id==count($ret)) { | |
| 1612 | + $prob_detail=[]; | |
| 1613 | + $totSolved=0; | |
| 1614 | + $totScore=0; | |
| 1615 | +            } else { | |
| 1616 | + $prob_detail=$ret[$id]['problem_detail']; | |
| 1617 | 1617 | $totSolved=$ret[$id]['solved']; | 
| 1618 | 1618 | $totScore=$ret[$id]['score']; | 
| 1619 | 1619 | }; | 
| @@ -1646,47 +1646,47 @@ discard block | ||
| 1646 | 1646 | return $ret; | 
| 1647 | 1647 | } | 
| 1648 | 1648 | |
| 1649 | -    public function assignMember($cid,$uid){ | |
| 1649 | +    public function assignMember($cid, $uid) { | |
| 1650 | 1650 |          return DB::table("contest")->where(["cid"=>$cid])->update([ | 
| 1651 | 1651 | "assign_uid"=>$uid | 
| 1652 | 1652 | ]); | 
| 1653 | 1653 | } | 
| 1654 | 1654 | |
| 1655 | - public function canUpdateContestTime($cid,$time = []) | |
| 1655 | + public function canUpdateContestTime($cid, $time=[]) | |
| 1656 | 1656 |      { | 
| 1657 | - $begin_time_new = $time['begin'] ?? null; | |
| 1658 | - $end_time_new = $time['end'] ?? null; | |
| 1657 | + $begin_time_new=$time['begin'] ?? null; | |
| 1658 | + $end_time_new=$time['end'] ?? null; | |
| 1659 | 1659 | |
| 1660 | -        $hold_time = DB::table('contest') | |
| 1661 | -            ->where('cid',$cid) | |
| 1662 | -            ->select('begin_time','end_time') | |
| 1660 | +        $hold_time=DB::table('contest') | |
| 1661 | +            ->where('cid', $cid) | |
| 1662 | +            ->select('begin_time', 'end_time') | |
| 1663 | 1663 | ->first(); | 
| 1664 | - $begin_stamps = strtotime($hold_time['begin_time']); | |
| 1665 | - $end_stamps = strtotime($hold_time['end_time']); | |
| 1664 | + $begin_stamps=strtotime($hold_time['begin_time']); | |
| 1665 | + $end_stamps=strtotime($hold_time['end_time']); | |
| 1666 | 1666 | /* | 
| 1667 | 1667 | -1 : have not begun | 
| 1668 | 1668 | 0 : ing | 
| 1669 | 1669 | 1 : end | 
| 1670 | 1670 | */ | 
| 1671 | - $status = time() >= $end_stamps ? 1 | |
| 1672 | - : (time() <= $begin_stamps ? -1 : 0); | |
| 1673 | -        if($status === -1){ | |
| 1674 | -            if(time() > $begin_time_new){ | |
| 1671 | + $status=time()>=$end_stamps ? 1 | |
| 1672 | + : (time()<=$begin_stamps ? -1 : 0); | |
| 1673 | +        if ($status===-1) { | |
| 1674 | +            if (time()>$begin_time_new) { | |
| 1675 | 1675 | return false; | 
| 1676 | 1676 | } | 
| 1677 | 1677 | return true; | 
| 1678 | -        }else if($status === 0){ | |
| 1679 | -            if($begin_time_new !== null){ | |
| 1678 | +        } else if ($status===0) { | |
| 1679 | +            if ($begin_time_new!==null) { | |
| 1680 | 1680 | return false; | 
| 1681 | 1681 | } | 
| 1682 | -            if($end_time_new !== null){ | |
| 1683 | -                if(strtotime($end_time_new) <= time()){ | |
| 1682 | +            if ($end_time_new!==null) { | |
| 1683 | +                if (strtotime($end_time_new)<=time()) { | |
| 1684 | 1684 | return false; | 
| 1685 | -                }else{ | |
| 1685 | +                } else { | |
| 1686 | 1686 | return true; | 
| 1687 | 1687 | } | 
| 1688 | 1688 | } | 
| 1689 | -        }else{ | |
| 1689 | +        } else { | |
| 1690 | 1690 | return false; | 
| 1691 | 1691 | } | 
| 1692 | 1692 | |
| @@ -1695,22 +1695,22 @@ discard block | ||
| 1695 | 1695 | |
| 1696 | 1696 | public function replyClarification($ccid, $content) | 
| 1697 | 1697 |      { | 
| 1698 | -        return DB::table("contest_clarification")->where('ccid','=',$ccid)->update([ | |
| 1698 | +        return DB::table("contest_clarification")->where('ccid', '=', $ccid)->update([ | |
| 1699 | 1699 | "reply"=>$content | 
| 1700 | 1700 | ]); | 
| 1701 | 1701 | } | 
| 1702 | 1702 | |
| 1703 | 1703 | public function setClarificationPublic($ccid, $public) | 
| 1704 | 1704 |      { | 
| 1705 | - if($public) | |
| 1705 | + if ($public) | |
| 1706 | 1706 |          { | 
| 1707 | -            return DB::table("contest_clarification")->where('ccid','=',$ccid)->update([ | |
| 1707 | +            return DB::table("contest_clarification")->where('ccid', '=', $ccid)->update([ | |
| 1708 | 1708 | "public"=>1 | 
| 1709 | 1709 | ]); | 
| 1710 | 1710 | } | 
| 1711 | 1711 | else | 
| 1712 | 1712 |          { | 
| 1713 | -            return DB::table("contest_clarification")->where('ccid','=',$ccid)->update([ | |
| 1713 | +            return DB::table("contest_clarification")->where('ccid', '=', $ccid)->update([ | |
| 1714 | 1714 | "public"=>0 | 
| 1715 | 1715 | ]); | 
| 1716 | 1716 | } | 
| @@ -1721,67 +1721,67 @@ discard block | ||
| 1721 | 1721 | return Cache::tags(['contest', 'account'])->get($cid); | 
| 1722 | 1722 | } | 
| 1723 | 1723 | |
| 1724 | -    public function praticeAnalysis($cid){ | |
| 1725 | -        $gid = DB::table('contest') | |
| 1726 | -            ->where('cid',$cid) | |
| 1724 | +    public function praticeAnalysis($cid) { | |
| 1725 | +        $gid=DB::table('contest') | |
| 1726 | +            ->where('cid', $cid) | |
| 1727 | 1727 | ->first()['gid']; | 
| 1728 | - $contestRank = $this->contestRank($cid,Auth::user()->id); | |
| 1729 | -        if(!empty($contestRank)){ | |
| 1730 | -            $all_problems = DB::table('problem') | |
| 1731 | -            ->whereIn('pid',array_column($contestRank[0]['problem_detail'],'pid')) | |
| 1732 | -            ->select('pid','title') | |
| 1728 | + $contestRank=$this->contestRank($cid, Auth::user()->id); | |
| 1729 | +        if (!empty($contestRank)) { | |
| 1730 | +            $all_problems=DB::table('problem') | |
| 1731 | +            ->whereIn('pid', array_column($contestRank[0]['problem_detail'], 'pid')) | |
| 1732 | +            ->select('pid', 'title') | |
| 1733 | 1733 | ->get()->all(); | 
| 1734 | -        }else{ | |
| 1735 | - $all_problems = []; | |
| 1734 | +        } else { | |
| 1735 | + $all_problems=[]; | |
| 1736 | 1736 | } | 
| 1737 | -        $tags = DB::table('group_problem_tag') | |
| 1737 | +        $tags=DB::table('group_problem_tag') | |
| 1738 | 1738 |              ->where('gid', $gid) | 
| 1739 | -            ->whereIn('pid', array_column($all_problems,'pid')) | |
| 1739 | +            ->whereIn('pid', array_column($all_problems, 'pid')) | |
| 1740 | 1740 | ->get()->all(); | 
| 1741 | - $all_tags = array_unique(array_column($tags,'tag')); | |
| 1742 | - $memberData = []; | |
| 1743 | -        foreach($contestRank as $member){ | |
| 1744 | - $m = [ | |
| 1741 | + $all_tags=array_unique(array_column($tags, 'tag')); | |
| 1742 | + $memberData=[]; | |
| 1743 | +        foreach ($contestRank as $member) { | |
| 1744 | + $m=[ | |
| 1745 | 1745 | 'uid' => $member['uid'], | 
| 1746 | 1746 | 'name' => $member['name'], | 
| 1747 | 1747 | 'nick_name' => $member['nick_name'], | 
| 1748 | 1748 | ]; | 
| 1749 | - $completion = []; | |
| 1750 | -            foreach ($all_tags as $tag){ | |
| 1751 | - $completion[$tag] = []; | |
| 1749 | + $completion=[]; | |
| 1750 | +            foreach ($all_tags as $tag) { | |
| 1751 | + $completion[$tag]=[]; | |
| 1752 | 1752 |                  foreach ($tags as $t) { | 
| 1753 | -                    if($t['tag'] == $tag){ | |
| 1753 | +                    if ($t['tag']==$tag) { | |
| 1754 | 1754 |                          foreach ($member['problem_detail'] as $pd) { | 
| 1755 | -                            if($pd['pid'] == $t['pid']){ | |
| 1756 | - $completion[$tag][$t['pid']] = $pd['solved_time_parsed'] == "" ? 0 : 1; | |
| 1755 | +                            if ($pd['pid']==$t['pid']) { | |
| 1756 | + $completion[$tag][$t['pid']]=$pd['solved_time_parsed']=="" ? 0 : 1; | |
| 1757 | 1757 | } | 
| 1758 | 1758 | } | 
| 1759 | 1759 | } | 
| 1760 | 1760 | } | 
| 1761 | 1761 | } | 
| 1762 | - $m['completion'] = $completion; | |
| 1763 | - $memberData[] = $m; | |
| 1762 | + $m['completion']=$completion; | |
| 1763 | + $memberData[]=$m; | |
| 1764 | 1764 | } | 
| 1765 | 1765 | return $memberData; | 
| 1766 | 1766 | } | 
| 1767 | 1767 | |
| 1768 | 1768 | public function storeContestRankInMySQL($cid, $data) | 
| 1769 | 1769 |      { | 
| 1770 | - $contestRankJson = json_encode($data); | |
| 1771 | -        return DB::table('contest')->where('cid','=',$cid)->update([ | |
| 1770 | + $contestRankJson=json_encode($data); | |
| 1771 | +        return DB::table('contest')->where('cid', '=', $cid)->update([ | |
| 1772 | 1772 | 'rank' => $contestRankJson | 
| 1773 | 1773 | ]); | 
| 1774 | 1774 | } | 
| 1775 | 1775 | |
| 1776 | 1776 | public function getContestRankFromMySQL($cid) | 
| 1777 | 1777 |      { | 
| 1778 | -        $contestRankJson = DB::table('contest')->where('cid','=',$cid)->pluck('rank')->first(); | |
| 1779 | - $data = json_decode($contestRankJson, true); | |
| 1778 | +        $contestRankJson=DB::table('contest')->where('cid', '=', $cid)->pluck('rank')->first(); | |
| 1779 | + $data=json_decode($contestRankJson, true); | |
| 1780 | 1780 | return $data; | 
| 1781 | 1781 | } | 
| 1782 | 1782 | |
| 1783 | 1783 | public function isVerified($cid) | 
| 1784 | 1784 |      { | 
| 1785 | -        return DB::table('contest')->where('cid','=',$cid)->pluck('verified')->first(); | |
| 1785 | +        return DB::table('contest')->where('cid', '=', $cid)->pluck('verified')->first(); | |
| 1786 | 1786 | } | 
| 1787 | 1787 | } | 
| @@ -218,7 +218,7 @@ discard block | ||
| 218 | 218 | $paginator=$paginator->where(["practice"=>$filter['practice']]); | 
| 219 | 219 | } | 
| 220 | 220 | $paginator = $paginator ->paginate(10); | 
| 221 | -            }elseif($filter['public']=='0'){ | |
| 221 | +            } elseif($filter['public']=='0'){ | |
| 222 | 222 |                  $paginator=DB::table('group_member') | 
| 223 | 223 |                  ->groupBy('contest.cid') | 
| 224 | 224 |                  ->select('contest.*') | 
| @@ -248,7 +248,7 @@ discard block | ||
| 248 | 248 | ) | 
| 249 | 249 |                  ->orderBy('contest.begin_time', 'desc') | 
| 250 | 250 | ->paginate(10); | 
| 251 | -            }else{ | |
| 251 | +            } else{ | |
| 252 | 252 |                  $paginator=DB::table('group_member') | 
| 253 | 253 |                  ->groupBy('contest.cid') | 
| 254 | 254 |                  ->select('contest.*') | 
| @@ -791,19 +791,19 @@ discard block | ||
| 791 | 791 |          if(time() < $end_time){ | 
| 792 | 792 |              if($clearance == 3){ | 
| 793 | 793 |                  $contestRankRaw=Cache::tags(['contest', 'rank'])->get("contestAdmin$cid"); | 
| 794 | -            }else{ | |
| 794 | +            } else{ | |
| 795 | 795 | $contestRankRaw=Cache::tags(['contest', 'rank'])->get($cid); | 
| 796 | 796 | } | 
| 797 | 797 |              if(!isset($contestRankRaw)){ | 
| 798 | 798 | $contestRankRaw=$this->contestRankCache($cid); | 
| 799 | 799 | } | 
| 800 | -        }else{ | |
| 800 | +        } else{ | |
| 801 | 801 |              if($clearance == 3){ | 
| 802 | 802 |                  $contestRankRaw=Cache::tags(['contest', 'rank'])->get("contestAdmin$cid"); | 
| 803 | 803 |                  if (!isset($contestRankRaw)) { | 
| 804 | 804 | $contestRankRaw=$this->contestRankCache($cid); | 
| 805 | 805 | } | 
| 806 | -            }else{ | |
| 806 | +            } else{ | |
| 807 | 807 | $contestRankRaw=$this->getContestRankFromMySQL($cid); | 
| 808 | 808 |                  if(!isset($contestRankRaw)){ | 
| 809 | 809 | $contestRankRaw=Cache::tags(['contest', 'rank'])->get($cid); | 
| @@ -888,7 +888,7 @@ discard block | ||
| 888 | 888 |              return DB::table("contest_clarification")->where([ | 
| 889 | 889 | "cid"=>$cid | 
| 890 | 890 |              ])->orderBy('create_time', 'desc')->get()->all(); | 
| 891 | -        }else{ | |
| 891 | +        } else{ | |
| 892 | 892 |              return DB::table("contest_clarification")->where([ | 
| 893 | 893 | "cid"=>$cid | 
| 894 | 894 |              ])->where(function ($query) { | 
| @@ -1125,7 +1125,7 @@ discard block | ||
| 1125 | 1125 | "records"=>[] | 
| 1126 | 1126 | ]; | 
| 1127 | 1127 | } | 
| 1128 | -        }else{ | |
| 1128 | +        } else{ | |
| 1129 | 1129 |              if ($basicInfo["status_visibility"]==2) { | 
| 1130 | 1130 | // View all | 
| 1131 | 1131 |                  $paginator=DB::table("submission")->where([ | 
| @@ -1347,7 +1347,7 @@ discard block | ||
| 1347 | 1347 |              if($ratingCalculator->calculate()){ | 
| 1348 | 1348 | $ratingCalculator->storage(); | 
| 1349 | 1349 | return true; | 
| 1350 | -            }else{ | |
| 1350 | +            } else{ | |
| 1351 | 1351 | return false; | 
| 1352 | 1352 | } | 
| 1353 | 1353 |          } else { | 
| @@ -1461,8 +1461,7 @@ discard block | ||
| 1461 | 1461 | Cache::tags(['contest', 'rank'])->put($cid, $ret); | 
| 1462 | 1462 | } | 
| 1463 | 1463 |                      Cache::tags(['contest', 'rank'])->put("contestAdmin$cid", $ret); | 
| 1464 | - } | |
| 1465 | -                else{ | |
| 1464 | +                } else{ | |
| 1466 | 1465 | $ret=[]; | 
| 1467 | 1466 | $chache=[]; | 
| 1468 | 1467 |                      $chache['contest_info']=DB::table("contest")->where("cid", $cid)->first(); | 
| @@ -1479,7 +1478,7 @@ discard block | ||
| 1479 | 1478 | "cid"=>$cid, | 
| 1480 | 1479 | "audit"=>1 | 
| 1481 | 1480 |                          ])->select('uid')->get()->all(); | 
| 1482 | -                    }else{ | |
| 1481 | +                    } else{ | |
| 1483 | 1482 |                          $submissionUsers=DB::table("submission")->where([ | 
| 1484 | 1483 | "cid"=>$cid | 
| 1485 | 1484 | ])->where( | 
| @@ -1514,9 +1513,9 @@ discard block | ||
| 1514 | 1513 |                      Cache::tags(['contest', 'rank'])->put("contestAdmin$cid", $retAdmin); | 
| 1515 | 1514 | } | 
| 1516 | 1515 | } | 
| 1517 | -        }catch(LockTimeoutException $e){ | |
| 1516 | +        } catch(LockTimeoutException $e){ | |
| 1518 | 1517 |              Log::warning("Contest Rank Lock Timed Out"); | 
| 1519 | -        }finally{ | |
| 1518 | +        } finally{ | |
| 1520 | 1519 | optional($lock)->release(); | 
| 1521 | 1520 | } | 
| 1522 | 1521 | } | 
| @@ -1539,7 +1538,7 @@ discard block | ||
| 1539 | 1538 | return 1; | 
| 1540 | 1539 | } | 
| 1541 | 1540 | }); | 
| 1542 | -        }else if ($contest_info["rule"]==2){ | |
| 1541 | +        } else if ($contest_info["rule"]==2){ | |
| 1543 | 1542 |              usort($ret, function ($a, $b) { | 
| 1544 | 1543 |                  if ($a["score"]==$b["score"]) { | 
| 1545 | 1544 |                      if ($a["solved"]==$b["solved"]) { | 
| @@ -1563,8 +1562,9 @@ discard block | ||
| 1563 | 1562 |      { | 
| 1564 | 1563 | $id = count($ret); | 
| 1565 | 1564 |          foreach($ret as $key => $r){ | 
| 1566 | - if($r['uid'] == $uid) | |
| 1567 | - $id = $key; | |
| 1565 | +            if($r['uid'] == $uid) { | |
| 1566 | + $id = $key; | |
| 1567 | + } | |
| 1568 | 1568 | } | 
| 1569 | 1569 |          if ($contest_info["rule"]==1) { | 
| 1570 | 1570 | // ACM/ICPC Mode | 
| @@ -1572,7 +1572,7 @@ discard block | ||
| 1572 | 1572 | $prob_detail = []; | 
| 1573 | 1573 | $totPen = 0; | 
| 1574 | 1574 | $totScore = 0; | 
| 1575 | -            }else{ | |
| 1575 | +            } else{ | |
| 1576 | 1576 | $prob_detail = $ret[$id]['problem_detail']; | 
| 1577 | 1577 | $totPen=$ret[$id]['penalty']; | 
| 1578 | 1578 | $totScore=$ret[$id]['score']; | 
| @@ -1612,7 +1612,7 @@ discard block | ||
| 1612 | 1612 | $prob_detail = []; | 
| 1613 | 1613 | $totSolved = 0; | 
| 1614 | 1614 | $totScore = 0; | 
| 1615 | -            }else{ | |
| 1615 | +            } else{ | |
| 1616 | 1616 | $prob_detail = $ret[$id]['problem_detail']; | 
| 1617 | 1617 | $totSolved=$ret[$id]['solved']; | 
| 1618 | 1618 | $totScore=$ret[$id]['score']; | 
| @@ -1675,18 +1675,18 @@ discard block | ||
| 1675 | 1675 | return false; | 
| 1676 | 1676 | } | 
| 1677 | 1677 | return true; | 
| 1678 | -        }else if($status === 0){ | |
| 1678 | +        } else if($status === 0){ | |
| 1679 | 1679 |              if($begin_time_new !== null){ | 
| 1680 | 1680 | return false; | 
| 1681 | 1681 | } | 
| 1682 | 1682 |              if($end_time_new !== null){ | 
| 1683 | 1683 |                  if(strtotime($end_time_new) <= time()){ | 
| 1684 | 1684 | return false; | 
| 1685 | -                }else{ | |
| 1685 | +                } else{ | |
| 1686 | 1686 | return true; | 
| 1687 | 1687 | } | 
| 1688 | 1688 | } | 
| 1689 | -        }else{ | |
| 1689 | +        } else{ | |
| 1690 | 1690 | return false; | 
| 1691 | 1691 | } | 
| 1692 | 1692 | |
| @@ -1707,8 +1707,7 @@ discard block | ||
| 1707 | 1707 |              return DB::table("contest_clarification")->where('ccid','=',$ccid)->update([ | 
| 1708 | 1708 | "public"=>1 | 
| 1709 | 1709 | ]); | 
| 1710 | - } | |
| 1711 | - else | |
| 1710 | + } else | |
| 1712 | 1711 |          { | 
| 1713 | 1712 |              return DB::table("contest_clarification")->where('ccid','=',$ccid)->update([ | 
| 1714 | 1713 | "public"=>0 | 
| @@ -1731,7 +1730,7 @@ discard block | ||
| 1731 | 1730 |              ->whereIn('pid',array_column($contestRank[0]['problem_detail'],'pid')) | 
| 1732 | 1731 |              ->select('pid','title') | 
| 1733 | 1732 | ->get()->all(); | 
| 1734 | -        }else{ | |
| 1733 | +        } else{ | |
| 1735 | 1734 | $all_problems = []; | 
| 1736 | 1735 | } | 
| 1737 | 1736 |          $tags = DB::table('group_problem_tag') |