Passed
Pull Request — master (#206)
by
unknown
04:01
created
app/Models/ContestModel.php 2 patches
Spacing   +200 added lines, -200 removed lines patch added patch discarded remove patch
@@ -111,8 +111,8 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
-            $contest['begin_stamps'] = strtotime($contest['begin_time']);
150
-            $contest['end_stamps'] = strtotime($contest['end_time']);
151
-            $contest['status'] = time() >= $contest['end_stamps'] ? 1
152
-                : (time() <= $contest['begin_stamps'] ? -1 : 0);
148
+            $contest['is_admin']=($contest['assign_uid']==$uid || $group_clearance==3);
149
+            $contest['begin_stamps']=strtotime($contest['begin_time']);
150
+            $contest['end_stamps']=strtotime($contest['end_time']);
151
+            $contest['status']=time()>=$contest['end_stamps'] ? 1
152
+                : (time()<=$contest['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'),
@@ -157,11 +157,11 @@  discard block
 block discarded – undo
157 157
             ];
158 158
             $contest["length"]=$this->calcLength($contest["begin_time"], $contest["end_time"]);
159 159
         }
160
-        usort($group_contests,function($a,$b){
161
-            if($a['is_admin'] == $b['is_admin']){
162
-                return $b['begin_stamps'] - $a['begin_stamps'];
160
+        usort($group_contests, function($a, $b) {
161
+            if ($a['is_admin']==$b['is_admin']) {
162
+                return $b['begin_stamps']-$a['begin_stamps'];
163 163
             }
164
-            return $b['is_admin'] - $a['is_admin'];
164
+            return $b['is_admin']-$a['is_admin'];
165 165
         });
166 166
         return $group_contests;
167 167
     }
@@ -172,9 +172,9 @@  discard block
 block discarded – undo
172 172
         //     "gid"=>$gid
173 173
         // ])->orderBy('begin_time', 'desc')->get()->all();
174 174
         $preQuery=DB::table($this->tableName);
175
-        $paginator=$preQuery->where('gid','=',$gid)->orderBy('begin_time', 'desc')->paginate(10);
175
+        $paginator=$preQuery->where('gid', '=', $gid)->orderBy('begin_time', 'desc')->paginate(10);
176 176
         $contest_list=$paginator->all();
177
-        if(empty($contest_list)){
177
+        if (empty($contest_list)) {
178 178
             return null;
179 179
         }
180 180
 
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
         ])->first()["rule"];
200 200
     }
201 201
 
202
-    public function list($filter,$uid)
202
+    public function list($filter, $uid)
203 203
     {
204 204
         if ($uid) {
205 205
             //$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);
@@ -223,15 +223,15 @@  discard block
 block discarded – undo
223 223
                 if ($filter['practice']) {
224 224
                     $paginator=$paginator->where(["practice"=>$filter['practice']]);
225 225
                 }
226
-                $paginator = $paginator ->paginate(10);
227
-            }elseif($filter['public']=='0'){
226
+                $paginator=$paginator ->paginate(10);
227
+            }elseif ($filter['public']=='0') {
228 228
                 $paginator=DB::table('group_member')
229 229
                 ->groupBy('contest.cid')
230 230
                 ->select('contest.*')
231 231
                 ->join('contest', 'group_member.gid', '=', 'contest.gid')
232 232
                 ->leftJoin('contest_participant', 'contest.cid', '=', 'contest_participant.cid')
233 233
                 ->where(
234
-                    function ($query) use ($filter,$uid) {
234
+                    function($query) use ($filter, $uid) {
235 235
                         if ($filter['rule']) {
236 236
                             $query=$query->where(["rule"=>$filter['rule']]);
237 237
                         }
@@ -254,14 +254,14 @@  discard block
 block discarded – undo
254 254
                 )
255 255
                 ->orderBy('contest.begin_time', 'desc')
256 256
                 ->paginate(10);
257
-            }else{
257
+            } else {
258 258
                 $paginator=DB::table('group_member')
259 259
                 ->groupBy('contest.cid')
260 260
                 ->select('contest.*')
261 261
                 ->join('contest', 'group_member.gid', '=', 'contest.gid')
262 262
                 ->leftJoin('contest_participant', 'contest.cid', '=', 'contest_participant.cid')
263 263
                 ->where(
264
-                    function ($query) use ($filter) {
264
+                    function($query) use ($filter) {
265 265
                         if ($filter['rule']) {
266 266
                             $query=$query->where(["rule"=>$filter['rule']]);
267 267
                         }
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
                     }
283 283
                 )
284 284
                 ->orWhere(
285
-                    function ($query) use ($filter,$uid) {
285
+                    function($query) use ($filter, $uid) {
286 286
                         if ($filter['rule']) {
287 287
                             $query=$query->where(["rule"=>$filter['rule']]);
288 288
                         }
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
             if ($filter['practice']) {
329 329
                 $paginator=$paginator->where(["practice"=>$filter['practice']]);
330 330
             }
331
-            $paginator = $paginator ->paginate(10);
331
+            $paginator=$paginator ->paginate(10);
332 332
         }
333 333
         $contest_list=$paginator->all();
334 334
         foreach ($contest_list as &$c) {
@@ -366,14 +366,14 @@  discard block
 block discarded – undo
366 366
         }
367 367
     }
368 368
 
369
-    public function registContest($cid,$uid)
369
+    public function registContest($cid, $uid)
370 370
     {
371 371
         $registered=DB::table("contest_participant")->where([
372 372
             "cid"=>$cid,
373 373
             "uid"=>$uid
374 374
         ])->first();
375 375
 
376
-        if(empty($registered)){
376
+        if (empty($registered)) {
377 377
             DB::table("contest_participant")->insert([
378 378
                 "cid"=>$cid,
379 379
                 "uid"=>$uid,
@@ -406,9 +406,9 @@  discard block
 block discarded – undo
406 406
     public function problems($cid)
407 407
     {
408 408
         return DB::table('contest_problem')
409
-            ->join('problem','contest_problem.pid','=','problem.pid')
410
-            ->where('cid',$cid)
411
-            ->select('problem.pid as pid','pcode','number')
409
+            ->join('problem', 'contest_problem.pid', '=', 'problem.pid')
410
+            ->where('cid', $cid)
411
+            ->select('problem.pid as pid', 'pcode', 'number')
412 412
             ->orderBy('number')
413 413
             ->get()->all();
414 414
     }
@@ -430,18 +430,18 @@  discard block
 block discarded – undo
430 430
         $end_time=strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]);
431 431
 
432 432
         foreach ($problemSet as &$p) {
433
-            if($p['practice']){
434
-                $tags = DB::table("group_problem_tag")
435
-                ->where('gid',$p['gid'])
436
-                ->where('pid',$p['pid'])
433
+            if ($p['practice']) {
434
+                $tags=DB::table("group_problem_tag")
435
+                ->where('gid', $p['gid'])
436
+                ->where('pid', $p['pid'])
437 437
                 ->get()->all();
438
-                $tags_arr = [];
439
-                if(!empty($tags)){
438
+                $tags_arr=[];
439
+                if (!empty($tags)) {
440 440
                     foreach ($tags as $value) {
441
-                        array_push($tags_arr,$value['tag']);
441
+                        array_push($tags_arr, $value['tag']);
442 442
                     }
443 443
                 }
444
-                $p['tags'] = $tags_arr;
444
+                $p['tags']=$tags_arr;
445 445
             }
446 446
             if ($contest_rule==1) {
447 447
                 $prob_stat=DB::table("submission")->select(
@@ -702,7 +702,7 @@  discard block
 block discarded – undo
702 702
                     "problem_detail" => $prob_detail
703 703
                 ];
704 704
             }
705
-            usort($ret, function ($a, $b) {
705
+            usort($ret, function($a, $b) {
706 706
                 if ($a["score"]==$b["score"]) {
707 707
                     if ($a["penalty"]==$b["penalty"]) {
708 708
                         return 0;
@@ -749,7 +749,7 @@  discard block
 block discarded – undo
749 749
                     "problem_detail" => $prob_detail
750 750
                 ];
751 751
             }
752
-            usort($ret, function ($a, $b) {
752
+            usort($ret, function($a, $b) {
753 753
                 if ($a["score"]==$b["score"]) {
754 754
                     if ($a["solved"]==$b["solved"]) {
755 755
                         return 0;
@@ -771,7 +771,7 @@  discard block
 block discarded – undo
771 771
         return $ret;
772 772
     }
773 773
 
774
-    public function contestRank($cid, $uid = 0)
774
+    public function contestRank($cid, $uid=0)
775 775
     {
776 776
         // [ToDo] If the current user's in the organizer group show nick name
777 777
         // [ToDo] The participants determination
@@ -789,35 +789,35 @@  discard block
 block discarded – undo
789 789
             "gid" => $contest_info["gid"]
790 790
         ])->where("role", ">", 0)->first());
791 791
 
792
-        $clearance = $this -> judgeClearance($cid, $uid);
792
+        $clearance=$this -> judgeClearance($cid, $uid);
793 793
 
794 794
         /** New Version With MySQL */
795 795
         $end_time=strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]);
796 796
 
797
-        if(time() < $end_time){
798
-            if($clearance == 3){
797
+        if (time()<$end_time) {
798
+            if ($clearance==3) {
799 799
                 $contestRankRaw=Cache::tags(['contest', 'rank'])->get("contestAdmin$cid");
800
-            }else{
800
+            } else {
801 801
                 $contestRankRaw=Cache::tags(['contest', 'rank'])->get($cid);
802 802
             }
803
-            if(!isset($contestRankRaw)){
803
+            if (!isset($contestRankRaw)) {
804 804
                 $contestRankRaw=$this->contestRankCache($cid);
805 805
             }
806
-        }else{
807
-            if($clearance == 3){
806
+        } else {
807
+            if ($clearance==3) {
808 808
                 $contestRankRaw=Cache::tags(['contest', 'rank'])->get("contestAdmin$cid");
809 809
                 if (!isset($contestRankRaw)) {
810 810
                     $contestRankRaw=$this->getContestRankFromMySQL($cid);
811
-                    if(!isset($contestRankRaw)){
811
+                    if (!isset($contestRankRaw)) {
812 812
                         $contestRankRaw=$this->contestRankCache($cid);
813 813
                         $this->storeContestRankInMySQL($cid, $contestRankRaw);
814 814
                     }
815 815
                 }
816
-            }else{
816
+            } else {
817 817
                 $contestRankRaw=$this->getContestRankFromMySQL($cid);
818
-                if(!isset($contestRankRaw)){
818
+                if (!isset($contestRankRaw)) {
819 819
                     $contestRankRaw=Cache::tags(['contest', 'rank'])->get($cid);
820
-                    if(!isset($contestRankRaw)){
820
+                    if (!isset($contestRankRaw)) {
821 821
                         $contestRankRaw=$this->contestRankCache($cid);
822 822
                     }
823 823
                     $this->storeContestRankInMySQL($cid, $contestRankRaw);
@@ -835,15 +835,15 @@  discard block
 block discarded – undo
835 835
         //         $contestRankRaw=$this->contestRankCache($cid);
836 836
         //     }
837 837
         // }
838
-        if($contest_info["rule"]==1){
838
+        if ($contest_info["rule"]==1) {
839 839
             foreach ($contestRankRaw as &$cr) {
840
-                $solved = 0;
841
-                foreach($cr['problem_detail'] as $pd){
842
-                    if(!empty($pd['solved_time_parsed'])){
843
-                        $solved ++;
840
+                $solved=0;
841
+                foreach ($cr['problem_detail'] as $pd) {
842
+                    if (!empty($pd['solved_time_parsed'])) {
843
+                        $solved++;
844 844
                     }
845 845
                 }
846
-                $cr['solved'] = $solved;
846
+                $cr['solved']=$solved;
847 847
             }
848 848
         }
849 849
 
@@ -892,16 +892,16 @@  discard block
 block discarded – undo
892 892
 
893 893
     public function getClarificationList($cid)
894 894
     {
895
-        $uid = Auth::user()->id;
896
-        $clearance = $this -> judgeClearance($cid, $uid);
897
-        if($clearance == 3){
895
+        $uid=Auth::user()->id;
896
+        $clearance=$this -> judgeClearance($cid, $uid);
897
+        if ($clearance==3) {
898 898
             return DB::table("contest_clarification")->where([
899 899
                 "cid"=>$cid
900 900
             ])->orderBy('create_time', 'desc')->get()->all();
901
-        }else{
901
+        } else {
902 902
             return DB::table("contest_clarification")->where([
903 903
                 "cid"=>$cid
904
-            ])->where(function ($query) {
904
+            ])->where(function($query) {
905 905
                 $query->where([
906 906
                     "public"=>1
907 907
                 ])->orWhere([
@@ -1046,7 +1046,7 @@  discard block
 block discarded – undo
1046 1046
     public function getContestRecord($cid)
1047 1047
     {
1048 1048
         $basicInfo=$this->basic($cid);
1049
-        $userInfo=DB::table('group_member')->where('gid',$basicInfo["gid"])->where('uid',Auth::user()->id)->get()->first();
1049
+        $userInfo=DB::table('group_member')->where('gid', $basicInfo["gid"])->where('uid', Auth::user()->id)->get()->first();
1050 1050
         $problemSet_temp=DB::table("contest_problem")->join("problem", "contest_problem.pid", "=", "problem.pid")->where([
1051 1051
             "cid"=>$cid
1052 1052
         ])->orderBy('ncode', 'asc')->select("ncode", "alias", "contest_problem.pid as pid", "title", "points", "tot_score")->get()->all();
@@ -1059,7 +1059,7 @@  discard block
 block discarded – undo
1059 1059
         $end_time=strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]);
1060 1060
         $contestEnd=time()>$end_time;
1061 1061
 
1062
-        if($userInfo==null || $userInfo["role"]!=3){
1062
+        if ($userInfo==null || $userInfo["role"]!=3) {
1063 1063
             if ($basicInfo["status_visibility"]==2) {
1064 1064
                 // View all
1065 1065
                 $paginator=DB::table("submission")->where([
@@ -1073,7 +1073,7 @@  discard block
 block discarded – undo
1073 1073
                     "users.id",
1074 1074
                     "=",
1075 1075
                     "submission.uid"
1076
-                )->where(function ($query) use ($frozen_time) {
1076
+                )->where(function($query) use ($frozen_time) {
1077 1077
                     $query->where(
1078 1078
                         "submission_date",
1079 1079
                         "<",
@@ -1135,7 +1135,7 @@  discard block
 block discarded – undo
1135 1135
                     "records"=>[]
1136 1136
                 ];
1137 1137
             }
1138
-        }else{
1138
+        } else {
1139 1139
             if ($basicInfo["status_visibility"]==2) {
1140 1140
                 // View all
1141 1141
                 $paginator=DB::table("submission")->where([
@@ -1247,21 +1247,21 @@  discard block
 block discarded – undo
1247 1247
         if ($uid==0) {
1248 1248
             return 0;
1249 1249
         }
1250
-        $groupModel = new GroupModel();
1250
+        $groupModel=new GroupModel();
1251 1251
         $contest_info=DB::table("contest")->where("cid", $cid)->first();
1252
-        $userInfo=DB::table('group_member')->where('gid',$contest_info["gid"])->where('uid',$uid)->get()->first();
1252
+        $userInfo=DB::table('group_member')->where('gid', $contest_info["gid"])->where('uid', $uid)->get()->first();
1253 1253
 
1254
-        if(empty($contest_info)){
1254
+        if (empty($contest_info)) {
1255 1255
             // contest not exist
1256 1256
             return 0;
1257 1257
         }
1258 1258
 
1259
-        if($uid == $contest_info['assign_uid'] || $groupModel->judgeClearance($contest_info['gid'],$uid) == 3){
1259
+        if ($uid==$contest_info['assign_uid'] || $groupModel->judgeClearance($contest_info['gid'], $uid)==3) {
1260 1260
             return 3;
1261 1261
         }
1262 1262
 
1263
-        $contest_started = strtotime($contest_info['begin_time']) < time();
1264
-        $contest_ended = strtotime($contest_info['end_time']) < time();
1263
+        $contest_started=strtotime($contest_info['begin_time'])<time();
1264
+        $contest_ended=strtotime($contest_info['end_time'])<time();
1265 1265
         if (!$contest_started) {
1266 1266
             // not started or do not exist
1267 1267
             return 0;
@@ -1352,12 +1352,12 @@  discard block
 block discarded – undo
1352 1352
     public function updateProfessionalRate($cid)
1353 1353
     {
1354 1354
         $basic=$this->basic($cid);
1355
-        if($basic["rated"]&&!$basic["is_rated"]){
1355
+        if ($basic["rated"] && !$basic["is_rated"]) {
1356 1356
             $ratingCalculator=new RatingCalculator($cid);
1357
-            if($ratingCalculator->calculate()){
1357
+            if ($ratingCalculator->calculate()) {
1358 1358
                 $ratingCalculator->storage();
1359 1359
                 return true;
1360
-            }else{
1360
+            } else {
1361 1361
                 return false;
1362 1362
             }
1363 1363
         } else {
@@ -1365,26 +1365,26 @@  discard block
 block discarded – undo
1365 1365
         }
1366 1366
     }
1367 1367
 
1368
-    public function contestUpdate($cid,$data,$problems)
1368
+    public function contestUpdate($cid, $data, $problems)
1369 1369
     {
1370
-        if($problems !== false){
1371
-            $old_problmes = array_column(
1370
+        if ($problems!==false) {
1371
+            $old_problmes=array_column(
1372 1372
                 DB::table('contest_problem')
1373
-                ->where('cid',$cid)
1373
+                ->where('cid', $cid)
1374 1374
                 ->get()->all(),
1375 1375
                 'pid'
1376 1376
             );
1377
-            DB::transaction(function () use ($cid, $data, $problems,$old_problmes) {
1377
+            DB::transaction(function() use ($cid, $data, $problems, $old_problmes) {
1378 1378
                 DB::table($this->tableName)
1379
-                    ->where('cid',$cid)
1379
+                    ->where('cid', $cid)
1380 1380
                     ->update($data);
1381 1381
                 DB::table('contest_problem')
1382
-                    ->where('cid',$cid)
1382
+                    ->where('cid', $cid)
1383 1383
                     ->delete();
1384
-                $new_problems = [];
1384
+                $new_problems=[];
1385 1385
                 foreach ($problems as $p) {
1386 1386
                     $pid=DB::table("problem")->where(["pcode"=>$p["pcode"]])->select("pid")->first()["pid"];
1387
-                    array_push($new_problems,$pid);
1387
+                    array_push($new_problems, $pid);
1388 1388
                     DB::table("contest_problem")->insert([
1389 1389
                         "cid"=>$cid,
1390 1390
                         "number"=>$p["number"],
@@ -1394,29 +1394,29 @@  discard block
 block discarded – undo
1394 1394
                         "points"=>$p["points"]
1395 1395
                     ]);
1396 1396
                 }
1397
-                foreach($old_problmes as $op) {
1398
-                    if(!in_array($op,$new_problems)){
1397
+                foreach ($old_problmes as $op) {
1398
+                    if (!in_array($op, $new_problems)) {
1399 1399
                         DB::table('submission')
1400
-                            ->where('cid',$cid)
1401
-                            ->where('pid',$op)
1400
+                            ->where('cid', $cid)
1401
+                            ->where('pid', $op)
1402 1402
                             ->delete();
1403 1403
                     }
1404 1404
                 }
1405 1405
             }, 5);
1406
-            $contestRankRaw = $this->contestRankCache($cid);
1406
+            $contestRankRaw=$this->contestRankCache($cid);
1407 1407
             Cache::tags(['contest', 'rank'])->put($cid, $contestRankRaw);
1408 1408
             Cache::tags(['contest', 'rank'])->put("contestAdmin$cid", $contestRankRaw);
1409
-        }else{
1409
+        } else {
1410 1410
             DB::table($this->tableName)
1411
-                ->where('cid',$cid)
1411
+                ->where('cid', $cid)
1412 1412
                 ->update($data);
1413 1413
         }
1414 1414
     }
1415 1415
 
1416
-    public function contestUpdateProblem($cid,$problems)
1416
+    public function contestUpdateProblem($cid, $problems)
1417 1417
     {
1418 1418
         DB::table('contest_problem')
1419
-                ->where('cid',$cid)
1419
+                ->where('cid', $cid)
1420 1420
                 ->delete();
1421 1421
         foreach ($problems as $p) {
1422 1422
             DB::table("contest_problem")->insertGetId([
@@ -1432,7 +1432,7 @@  discard block
 block discarded – undo
1432 1432
 
1433 1433
     public function arrangeContest($gid, $config, $problems)
1434 1434
     {
1435
-        DB::transaction(function () use ($gid, $config, $problems) {
1435
+        DB::transaction(function() use ($gid, $config, $problems) {
1436 1436
             $cid=DB::table($this->tableName)->insertGetId([
1437 1437
                 "gid"=>$gid,
1438 1438
                 "name"=>$config["name"],
@@ -1446,7 +1446,7 @@  discard block
 block discarded – undo
1446 1446
                 "rule"=>1, //todo
1447 1447
                 "begin_time"=>$config["begin_time"],
1448 1448
                 "end_time"=>$config["end_time"],
1449
-                "vcid"=>isset($config["vcid"])?$config["vcid"]:null,
1449
+                "vcid"=>isset($config["vcid"]) ? $config["vcid"] : null,
1450 1450
                 "public"=>0, //todo
1451 1451
                 "registration"=>0, //todo
1452 1452
                 "registration_due"=>null, //todo
@@ -1454,7 +1454,7 @@  discard block
 block discarded – undo
1454 1454
                 "froze_length"=>0, //todo
1455 1455
                 "status_visibility"=>2, //todo
1456 1456
                 "create_time"=>date("Y-m-d H:i:s"),
1457
-                "crawled" => isset($config['vcid'])?$config['crawled'] : null,
1457
+                "crawled" => isset($config['vcid']) ? $config['crawled'] : null,
1458 1458
                 "audit_status"=>1                       //todo
1459 1459
             ]);
1460 1460
 
@@ -1472,13 +1472,13 @@  discard block
 block discarded – undo
1472 1472
         }, 5);
1473 1473
     }
1474 1474
 
1475
-    public function updateContestRankTable($cid,$sub)
1475
+    public function updateContestRankTable($cid, $sub)
1476 1476
     {
1477
-        $lock = Cache::lock("contestrank$cid",10);
1478
-        try{
1479
-            if($lock->get()){
1480
-                if(Cache::tags(['contest','rank'])->get($cid) != null){
1481
-                    $ret = Cache::tags(['contest','rank'])->get($cid);
1477
+        $lock=Cache::lock("contestrank$cid", 10);
1478
+        try {
1479
+            if ($lock->get()) {
1480
+                if (Cache::tags(['contest', 'rank'])->get($cid)!=null) {
1481
+                    $ret=Cache::tags(['contest', 'rank'])->get($cid);
1482 1482
                     $chache=[];
1483 1483
                     $chache['contest_info']=DB::table("contest")->where("cid", $cid)->first();
1484 1484
                     $chache['problemSet']=DB::table("contest_problem")->join("problem", "contest_problem.pid", "=", "problem.pid")->where([
@@ -1487,27 +1487,27 @@  discard block
 block discarded – undo
1487 1487
                     $chache['frozen_time']=DB::table("contest")->where(["cid"=>$cid])->select(DB::raw("UNIX_TIMESTAMP(end_time)-froze_length as frozen_time"))->first()["frozen_time"];
1488 1488
                     $chache['end_time']=strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]);
1489 1489
 
1490
-                    $id = 0;
1490
+                    $id=0;
1491 1491
 
1492
-                    foreach($chache['problemSet'] as $key => $p){
1493
-                        if ($p['pid'] == $sub['pid']){
1494
-                            $chache['problemSet'][$key]['cpid'] = $key;
1495
-                            $id = $key;
1492
+                    foreach ($chache['problemSet'] as $key => $p) {
1493
+                        if ($p['pid']==$sub['pid']) {
1494
+                            $chache['problemSet'][$key]['cpid']=$key;
1495
+                            $id=$key;
1496 1496
                         }
1497 1497
                     }
1498 1498
 
1499
-                    $ret = $this->updateContestRankDetail($chache['contest_info'],$chache['problemSet'][$id],$cid,$sub['uid'],$ret);
1500
-                    $ret = $this->sortContestRankTable($chache['contest_info'],$cid,$ret);
1499
+                    $ret=$this->updateContestRankDetail($chache['contest_info'], $chache['problemSet'][$id], $cid, $sub['uid'], $ret);
1500
+                    $ret=$this->sortContestRankTable($chache['contest_info'], $cid, $ret);
1501 1501
 
1502
-                    if (time() < $chache['frozen_time']){
1502
+                    if (time()<$chache['frozen_time']) {
1503 1503
                         Cache::tags(['contest', 'rank'])->put($cid, $ret);
1504 1504
                     }
1505 1505
                     Cache::tags(['contest', 'rank'])->put("contestAdmin$cid", $ret);
1506
-                    if(time() > $chache['end_time']){
1506
+                    if (time()>$chache['end_time']) {
1507 1507
                         $this->storeContestRankInMySQL($cid, $ret);
1508 1508
                     }
1509 1509
                 }
1510
-                else{
1510
+                else {
1511 1511
                     $ret=[];
1512 1512
                     $chache=[];
1513 1513
                     $chache['contest_info']=DB::table("contest")->where("cid", $cid)->first();
@@ -1522,7 +1522,7 @@  discard block
 block discarded – undo
1522 1522
                             "cid"=>$cid,
1523 1523
                             "audit"=>1
1524 1524
                         ])->select('uid')->get()->all();
1525
-                    }else{
1525
+                    } else {
1526 1526
                         $submissionUsers=DB::table("submission")->where([
1527 1527
                             "cid"=>$cid
1528 1528
                         ])->where(
@@ -1535,39 +1535,39 @@  discard block
 block discarded – undo
1535 1535
                         ])->select('uid')->groupBy('uid')->get()->all();
1536 1536
                     }
1537 1537
 
1538
-                    $chacheAdmin = $chache;
1538
+                    $chacheAdmin=$chache;
1539 1539
 
1540 1540
                     foreach ($submissionUsers as $s) {
1541 1541
                         foreach ($chache['problemSet'] as $key => $p) {
1542
-                            $p['cpid'] = $key;
1543
-                            $ret = $this->updateContestRankDetail($chache['contest_info'],$p,$cid,$s['uid'],$ret);
1542
+                            $p['cpid']=$key;
1543
+                            $ret=$this->updateContestRankDetail($chache['contest_info'], $p, $cid, $s['uid'], $ret);
1544 1544
                         }
1545 1545
                     }
1546
-                    $ret = $this->sortContestRankTable($chache['contest_info'],$cid,$ret);
1546
+                    $ret=$this->sortContestRankTable($chache['contest_info'], $cid, $ret);
1547 1547
                     Cache::tags(['contest', 'rank'])->put($cid, $ret);
1548 1548
 
1549 1549
                     $retAdmin=[];
1550 1550
                     foreach ($submissionUsersAdmin as $s) {
1551 1551
                         foreach ($chacheAdmin['problemSet'] as $key => $p) {
1552
-                            $p['cpid'] = $key;
1553
-                            $retAdmin = $this->updateContestRankDetail($chacheAdmin['contest_info'],$p,$cid,$s['uid'],$retAdmin);
1552
+                            $p['cpid']=$key;
1553
+                            $retAdmin=$this->updateContestRankDetail($chacheAdmin['contest_info'], $p, $cid, $s['uid'], $retAdmin);
1554 1554
                         }
1555 1555
                     }
1556
-                    $retAdmin = $this->sortContestRankTable($chacheAdmin['contest_info'],$cid,$retAdmin);
1556
+                    $retAdmin=$this->sortContestRankTable($chacheAdmin['contest_info'], $cid, $retAdmin);
1557 1557
                     Cache::tags(['contest', 'rank'])->put("contestAdmin$cid", $retAdmin);
1558 1558
                 }
1559 1559
             }
1560
-        }catch(LockTimeoutException $e){
1560
+        } catch (LockTimeoutException $e) {
1561 1561
             Log::warning("Contest Rank Lock Timed Out");
1562
-        }finally{
1562
+        } finally {
1563 1563
             optional($lock)->release();
1564 1564
         }
1565 1565
     }
1566 1566
 
1567
-    public function sortContestRankTable($contest_info,$cid,$ret)
1567
+    public function sortContestRankTable($contest_info, $cid, $ret)
1568 1568
     {
1569
-        if ($contest_info["rule"]==1){
1570
-            usort($ret, function ($a, $b) {
1569
+        if ($contest_info["rule"]==1) {
1570
+            usort($ret, function($a, $b) {
1571 1571
                 if ($a["score"]==$b["score"]) {
1572 1572
                     if ($a["penalty"]==$b["penalty"]) {
1573 1573
                         return 0;
@@ -1582,8 +1582,8 @@  discard block
 block discarded – undo
1582 1582
                     return 1;
1583 1583
                 }
1584 1584
             });
1585
-        }else if ($contest_info["rule"]==2){
1586
-            usort($ret, function ($a, $b) {
1585
+        } else if ($contest_info["rule"]==2) {
1586
+            usort($ret, function($a, $b) {
1587 1587
                 if ($a["score"]==$b["score"]) {
1588 1588
                     if ($a["solved"]==$b["solved"]) {
1589 1589
                         return 0;
@@ -1602,21 +1602,21 @@  discard block
 block discarded – undo
1602 1602
         return $ret;
1603 1603
     }
1604 1604
 
1605
-    public function updateContestRankDetail($contest_info,$problem,$cid,$uid,$ret)
1605
+    public function updateContestRankDetail($contest_info, $problem, $cid, $uid, $ret)
1606 1606
     {
1607
-        $id = count($ret);
1608
-        foreach($ret as $key => $r){
1609
-            if($r['uid'] == $uid)
1610
-                $id = $key;
1607
+        $id=count($ret);
1608
+        foreach ($ret as $key => $r) {
1609
+            if ($r['uid']==$uid)
1610
+                $id=$key;
1611 1611
         }
1612 1612
         if ($contest_info["rule"]==1) {
1613 1613
             // ACM/ICPC Mode
1614
-            if($id == count($ret)){
1615
-                $prob_detail = [];
1616
-                $totPen = 0;
1617
-                $totScore = 0;
1618
-            }else{
1619
-                $prob_detail = $ret[$id]['problem_detail'];
1614
+            if ($id==count($ret)) {
1615
+                $prob_detail=[];
1616
+                $totPen=0;
1617
+                $totScore=0;
1618
+            } else {
1619
+                $prob_detail=$ret[$id]['problem_detail'];
1620 1620
                 $totPen=$ret[$id]['penalty'];
1621 1621
                 $totScore=$ret[$id]['score'];
1622 1622
             };
@@ -1634,7 +1634,7 @@  discard block
 block discarded – undo
1634 1634
                 "uid"=>$uid,
1635 1635
             ])->orderBy('submission_date', 'desc')->first();
1636 1636
     
1637
-            if ($ac_times<=1 && $last_record->verdict!="Waiting" && $last_record->verdict!="Submission Error" && $last_record->verdict!="System Error"){
1637
+            if ($ac_times<=1 && $last_record->verdict!="Waiting" && $last_record->verdict!="Submission Error" && $last_record->verdict!="System Error") {
1638 1638
                 $prob_stat=$this->contestProblemInfoACM($cid, $problem["pid"], $uid);
1639 1639
 
1640 1640
                 $prob_detail[$problem['cpid']]=[
@@ -1666,12 +1666,12 @@  discard block
 block discarded – undo
1666 1666
             }
1667 1667
         } elseif ($contest_info["rule"]==2) {
1668 1668
             // OI Mode
1669
-            if($id == count($ret)){
1670
-                $prob_detail = [];
1671
-                $totSolved = 0;
1672
-                $totScore = 0;
1673
-            }else{
1674
-                $prob_detail = $ret[$id]['problem_detail'];
1669
+            if ($id==count($ret)) {
1670
+                $prob_detail=[];
1671
+                $totSolved=0;
1672
+                $totScore=0;
1673
+            } else {
1674
+                $prob_detail=$ret[$id]['problem_detail'];
1675 1675
                 $totSolved=$ret[$id]['solved'];
1676 1676
                 $totScore=$ret[$id]['score'];
1677 1677
             };
@@ -1704,47 +1704,47 @@  discard block
 block discarded – undo
1704 1704
         return $ret;
1705 1705
     }
1706 1706
 
1707
-    public function assignMember($cid,$uid){
1707
+    public function assignMember($cid, $uid) {
1708 1708
         return DB::table("contest")->where(["cid"=>$cid])->update([
1709 1709
             "assign_uid"=>$uid
1710 1710
         ]);
1711 1711
     }
1712 1712
 
1713
-    public function canUpdateContestTime($cid,$time = [])
1713
+    public function canUpdateContestTime($cid, $time=[])
1714 1714
     {
1715
-        $begin_time_new = $time['begin'] ?? null;
1716
-        $end_time_new = $time['end'] ?? null;
1715
+        $begin_time_new=$time['begin'] ?? null;
1716
+        $end_time_new=$time['end'] ?? null;
1717 1717
 
1718
-        $hold_time = DB::table('contest')
1719
-            ->where('cid',$cid)
1720
-            ->select('begin_time','end_time')
1718
+        $hold_time=DB::table('contest')
1719
+            ->where('cid', $cid)
1720
+            ->select('begin_time', 'end_time')
1721 1721
             ->first();
1722
-        $begin_stamps = strtotime($hold_time['begin_time']);
1723
-        $end_stamps = strtotime($hold_time['end_time']);
1722
+        $begin_stamps=strtotime($hold_time['begin_time']);
1723
+        $end_stamps=strtotime($hold_time['end_time']);
1724 1724
         /*
1725 1725
         -1 : have not begun
1726 1726
          0 : ing
1727 1727
          1 : end
1728 1728
         */
1729
-        $status = time() >= $end_stamps ? 1
1730
-                : (time() <= $begin_stamps ? -1 : 0);
1731
-        if($status === -1){
1732
-            if(time() > $begin_time_new){
1729
+        $status=time()>=$end_stamps ? 1
1730
+                : (time()<=$begin_stamps ? -1 : 0);
1731
+        if ($status===-1) {
1732
+            if (time()>$begin_time_new) {
1733 1733
                 return false;
1734 1734
             }
1735 1735
             return true;
1736
-        }else if($status === 0){
1737
-            if($begin_time_new !== null){
1736
+        } else if ($status===0) {
1737
+            if ($begin_time_new!==null) {
1738 1738
                 return false;
1739 1739
             }
1740
-            if($end_time_new !== null){
1741
-                if(strtotime($end_time_new) <= time()){
1740
+            if ($end_time_new!==null) {
1741
+                if (strtotime($end_time_new)<=time()) {
1742 1742
                     return false;
1743
-                }else{
1743
+                } else {
1744 1744
                     return true;
1745 1745
                 }
1746 1746
             }
1747
-        }else{
1747
+        } else {
1748 1748
             return false;
1749 1749
         }
1750 1750
 
@@ -1753,22 +1753,22 @@  discard block
 block discarded – undo
1753 1753
 
1754 1754
     public function replyClarification($ccid, $content)
1755 1755
     {
1756
-        return DB::table("contest_clarification")->where('ccid','=',$ccid)->update([
1756
+        return DB::table("contest_clarification")->where('ccid', '=', $ccid)->update([
1757 1757
             "reply"=>$content
1758 1758
         ]);
1759 1759
     }
1760 1760
 
1761 1761
     public function setClarificationPublic($ccid, $public)
1762 1762
     {
1763
-        if($public)
1763
+        if ($public)
1764 1764
         {
1765
-            return DB::table("contest_clarification")->where('ccid','=',$ccid)->update([
1765
+            return DB::table("contest_clarification")->where('ccid', '=', $ccid)->update([
1766 1766
                 "public"=>1
1767 1767
             ]);
1768 1768
         }
1769 1769
         else
1770 1770
         {
1771
-            return DB::table("contest_clarification")->where('ccid','=',$ccid)->update([
1771
+            return DB::table("contest_clarification")->where('ccid', '=', $ccid)->update([
1772 1772
                 "public"=>0
1773 1773
             ]);
1774 1774
         }
@@ -1779,67 +1779,67 @@  discard block
 block discarded – undo
1779 1779
         return Cache::tags(['contest', 'account'])->get($cid);
1780 1780
     }
1781 1781
 
1782
-    public function praticeAnalysis($cid){
1783
-        $gid = DB::table('contest')
1784
-            ->where('cid',$cid)
1782
+    public function praticeAnalysis($cid) {
1783
+        $gid=DB::table('contest')
1784
+            ->where('cid', $cid)
1785 1785
             ->first()['gid'];
1786
-        $contestRank = $this->contestRank($cid,Auth::user()->id);
1787
-        if(!empty($contestRank)){
1788
-            $all_problems = DB::table('problem')
1789
-            ->whereIn('pid',array_column($contestRank[0]['problem_detail'],'pid'))
1790
-            ->select('pid','title')
1786
+        $contestRank=$this->contestRank($cid, Auth::user()->id);
1787
+        if (!empty($contestRank)) {
1788
+            $all_problems=DB::table('problem')
1789
+            ->whereIn('pid', array_column($contestRank[0]['problem_detail'], 'pid'))
1790
+            ->select('pid', 'title')
1791 1791
             ->get()->all();
1792
-        }else{
1793
-            $all_problems = [];
1792
+        } else {
1793
+            $all_problems=[];
1794 1794
         }
1795
-        $tags = DB::table('group_problem_tag')
1795
+        $tags=DB::table('group_problem_tag')
1796 1796
             ->where('gid', $gid)
1797
-            ->whereIn('pid', array_column($all_problems,'pid'))
1797
+            ->whereIn('pid', array_column($all_problems, 'pid'))
1798 1798
             ->get()->all();
1799
-        $all_tags = array_unique(array_column($tags,'tag'));
1800
-        $memberData = [];
1801
-        foreach($contestRank as $member){
1802
-            $m = [
1799
+        $all_tags=array_unique(array_column($tags, 'tag'));
1800
+        $memberData=[];
1801
+        foreach ($contestRank as $member) {
1802
+            $m=[
1803 1803
                 'uid' => $member['uid'],
1804 1804
                 'name' => $member['name'],
1805 1805
                 'nick_name' => $member['nick_name'],
1806 1806
             ];
1807
-            $completion = [];
1808
-            foreach ($all_tags as $tag){
1809
-                $completion[$tag] = [];
1807
+            $completion=[];
1808
+            foreach ($all_tags as $tag) {
1809
+                $completion[$tag]=[];
1810 1810
                 foreach ($tags as $t) {
1811
-                    if($t['tag'] == $tag){
1811
+                    if ($t['tag']==$tag) {
1812 1812
                         foreach ($member['problem_detail'] as $pd) {
1813
-                            if($pd['pid'] == $t['pid']){
1814
-                                $completion[$tag][$t['pid']] = $pd['solved_time_parsed'] == "" ? 0 : 1;
1813
+                            if ($pd['pid']==$t['pid']) {
1814
+                                $completion[$tag][$t['pid']]=$pd['solved_time_parsed']=="" ? 0 : 1;
1815 1815
                             }
1816 1816
                         }
1817 1817
                     }
1818 1818
                 }
1819 1819
             }
1820
-            $m['completion'] = $completion;
1821
-            $memberData[] = $m;
1820
+            $m['completion']=$completion;
1821
+            $memberData[]=$m;
1822 1822
         }
1823 1823
         return $memberData;
1824 1824
     }
1825 1825
 
1826 1826
     public function storeContestRankInMySQL($cid, $data)
1827 1827
     {
1828
-        $contestRankJson = json_encode($data);
1829
-        return DB::table('contest')->where('cid','=',$cid)->update([
1828
+        $contestRankJson=json_encode($data);
1829
+        return DB::table('contest')->where('cid', '=', $cid)->update([
1830 1830
             'rank' => $contestRankJson
1831 1831
         ]);
1832 1832
     }
1833 1833
 
1834 1834
     public function getContestRankFromMySQL($cid)
1835 1835
     {
1836
-        $contestRankJson = DB::table('contest')->where('cid','=',$cid)->pluck('rank')->first();
1837
-        $data = json_decode($contestRankJson, true);
1836
+        $contestRankJson=DB::table('contest')->where('cid', '=', $cid)->pluck('rank')->first();
1837
+        $data=json_decode($contestRankJson, true);
1838 1838
         return $data;
1839 1839
     }
1840 1840
 
1841 1841
     public function isVerified($cid)
1842 1842
     {
1843
-        return DB::table('contest')->where('cid','=',$cid)->pluck('verified')->first();
1843
+        return DB::table('contest')->where('cid', '=', $cid)->pluck('verified')->first();
1844 1844
     }
1845 1845
 }
Please login to merge, or discard this patch.
Braces   +24 added lines, -25 removed lines patch added patch discarded remove patch
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
                     $paginator=$paginator->where(["practice"=>$filter['practice']]);
225 225
                 }
226 226
                 $paginator = $paginator ->paginate(10);
227
-            }elseif($filter['public']=='0'){
227
+            } elseif($filter['public']=='0'){
228 228
                 $paginator=DB::table('group_member')
229 229
                 ->groupBy('contest.cid')
230 230
                 ->select('contest.*')
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
                 )
255 255
                 ->orderBy('contest.begin_time', 'desc')
256 256
                 ->paginate(10);
257
-            }else{
257
+            } else{
258 258
                 $paginator=DB::table('group_member')
259 259
                 ->groupBy('contest.cid')
260 260
                 ->select('contest.*')
@@ -797,13 +797,13 @@  discard block
 block discarded – undo
797 797
         if(time() < $end_time){
798 798
             if($clearance == 3){
799 799
                 $contestRankRaw=Cache::tags(['contest', 'rank'])->get("contestAdmin$cid");
800
-            }else{
800
+            } else{
801 801
                 $contestRankRaw=Cache::tags(['contest', 'rank'])->get($cid);
802 802
             }
803 803
             if(!isset($contestRankRaw)){
804 804
                 $contestRankRaw=$this->contestRankCache($cid);
805 805
             }
806
-        }else{
806
+        } else{
807 807
             if($clearance == 3){
808 808
                 $contestRankRaw=Cache::tags(['contest', 'rank'])->get("contestAdmin$cid");
809 809
                 if (!isset($contestRankRaw)) {
@@ -813,7 +813,7 @@  discard block
 block discarded – undo
813 813
                         $this->storeContestRankInMySQL($cid, $contestRankRaw);
814 814
                     }
815 815
                 }
816
-            }else{
816
+            } else{
817 817
                 $contestRankRaw=$this->getContestRankFromMySQL($cid);
818 818
                 if(!isset($contestRankRaw)){
819 819
                     $contestRankRaw=Cache::tags(['contest', 'rank'])->get($cid);
@@ -898,7 +898,7 @@  discard block
 block discarded – undo
898 898
             return DB::table("contest_clarification")->where([
899 899
                 "cid"=>$cid
900 900
             ])->orderBy('create_time', 'desc')->get()->all();
901
-        }else{
901
+        } else{
902 902
             return DB::table("contest_clarification")->where([
903 903
                 "cid"=>$cid
904 904
             ])->where(function ($query) {
@@ -1135,7 +1135,7 @@  discard block
 block discarded – undo
1135 1135
                     "records"=>[]
1136 1136
                 ];
1137 1137
             }
1138
-        }else{
1138
+        } else{
1139 1139
             if ($basicInfo["status_visibility"]==2) {
1140 1140
                 // View all
1141 1141
                 $paginator=DB::table("submission")->where([
@@ -1357,7 +1357,7 @@  discard block
 block discarded – undo
1357 1357
             if($ratingCalculator->calculate()){
1358 1358
                 $ratingCalculator->storage();
1359 1359
                 return true;
1360
-            }else{
1360
+            } else{
1361 1361
                 return false;
1362 1362
             }
1363 1363
         } else {
@@ -1406,7 +1406,7 @@  discard block
 block discarded – undo
1406 1406
             $contestRankRaw = $this->contestRankCache($cid);
1407 1407
             Cache::tags(['contest', 'rank'])->put($cid, $contestRankRaw);
1408 1408
             Cache::tags(['contest', 'rank'])->put("contestAdmin$cid", $contestRankRaw);
1409
-        }else{
1409
+        } else{
1410 1410
             DB::table($this->tableName)
1411 1411
                 ->where('cid',$cid)
1412 1412
                 ->update($data);
@@ -1506,8 +1506,7 @@  discard block
 block discarded – undo
1506 1506
                     if(time() > $chache['end_time']){
1507 1507
                         $this->storeContestRankInMySQL($cid, $ret);
1508 1508
                     }
1509
-                }
1510
-                else{
1509
+                } else{
1511 1510
                     $ret=[];
1512 1511
                     $chache=[];
1513 1512
                     $chache['contest_info']=DB::table("contest")->where("cid", $cid)->first();
@@ -1522,7 +1521,7 @@  discard block
 block discarded – undo
1522 1521
                             "cid"=>$cid,
1523 1522
                             "audit"=>1
1524 1523
                         ])->select('uid')->get()->all();
1525
-                    }else{
1524
+                    } else{
1526 1525
                         $submissionUsers=DB::table("submission")->where([
1527 1526
                             "cid"=>$cid
1528 1527
                         ])->where(
@@ -1557,9 +1556,9 @@  discard block
 block discarded – undo
1557 1556
                     Cache::tags(['contest', 'rank'])->put("contestAdmin$cid", $retAdmin);
1558 1557
                 }
1559 1558
             }
1560
-        }catch(LockTimeoutException $e){
1559
+        } catch(LockTimeoutException $e){
1561 1560
             Log::warning("Contest Rank Lock Timed Out");
1562
-        }finally{
1561
+        } finally{
1563 1562
             optional($lock)->release();
1564 1563
         }
1565 1564
     }
@@ -1582,7 +1581,7 @@  discard block
 block discarded – undo
1582 1581
                     return 1;
1583 1582
                 }
1584 1583
             });
1585
-        }else if ($contest_info["rule"]==2){
1584
+        } else if ($contest_info["rule"]==2){
1586 1585
             usort($ret, function ($a, $b) {
1587 1586
                 if ($a["score"]==$b["score"]) {
1588 1587
                     if ($a["solved"]==$b["solved"]) {
@@ -1606,8 +1605,9 @@  discard block
 block discarded – undo
1606 1605
     {
1607 1606
         $id = count($ret);
1608 1607
         foreach($ret as $key => $r){
1609
-            if($r['uid'] == $uid)
1610
-                $id = $key;
1608
+            if($r['uid'] == $uid) {
1609
+                            $id = $key;
1610
+            }
1611 1611
         }
1612 1612
         if ($contest_info["rule"]==1) {
1613 1613
             // ACM/ICPC Mode
@@ -1615,7 +1615,7 @@  discard block
 block discarded – undo
1615 1615
                 $prob_detail = [];
1616 1616
                 $totPen = 0;
1617 1617
                 $totScore = 0;
1618
-            }else{
1618
+            } else{
1619 1619
                 $prob_detail = $ret[$id]['problem_detail'];
1620 1620
                 $totPen=$ret[$id]['penalty'];
1621 1621
                 $totScore=$ret[$id]['score'];
@@ -1670,7 +1670,7 @@  discard block
 block discarded – undo
1670 1670
                 $prob_detail = [];
1671 1671
                 $totSolved = 0;
1672 1672
                 $totScore = 0;
1673
-            }else{
1673
+            } else{
1674 1674
                 $prob_detail = $ret[$id]['problem_detail'];
1675 1675
                 $totSolved=$ret[$id]['solved'];
1676 1676
                 $totScore=$ret[$id]['score'];
@@ -1733,18 +1733,18 @@  discard block
 block discarded – undo
1733 1733
                 return false;
1734 1734
             }
1735 1735
             return true;
1736
-        }else if($status === 0){
1736
+        } else if($status === 0){
1737 1737
             if($begin_time_new !== null){
1738 1738
                 return false;
1739 1739
             }
1740 1740
             if($end_time_new !== null){
1741 1741
                 if(strtotime($end_time_new) <= time()){
1742 1742
                     return false;
1743
-                }else{
1743
+                } else{
1744 1744
                     return true;
1745 1745
                 }
1746 1746
             }
1747
-        }else{
1747
+        } else{
1748 1748
             return false;
1749 1749
         }
1750 1750
 
@@ -1765,8 +1765,7 @@  discard block
 block discarded – undo
1765 1765
             return DB::table("contest_clarification")->where('ccid','=',$ccid)->update([
1766 1766
                 "public"=>1
1767 1767
             ]);
1768
-        }
1769
-        else
1768
+        } else
1770 1769
         {
1771 1770
             return DB::table("contest_clarification")->where('ccid','=',$ccid)->update([
1772 1771
                 "public"=>0
@@ -1789,7 +1788,7 @@  discard block
 block discarded – undo
1789 1788
             ->whereIn('pid',array_column($contestRank[0]['problem_detail'],'pid'))
1790 1789
             ->select('pid','title')
1791 1790
             ->get()->all();
1792
-        }else{
1791
+        } else{
1793 1792
             $all_problems = [];
1794 1793
         }
1795 1794
         $tags = DB::table('group_problem_tag')
Please login to merge, or discard this patch.
app/Models/SubmissionModel.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
                                             ->where(['verdict'=>'Waiting'])
414 414
                                             ->get()
415 415
                                             ->all();
416
-        foreach($ret as &$r){
416
+        foreach ($ret as &$r) {
417 417
             $r["ocode"]=DB::table("oj")->where(["oid"=>$r["oid"]])->first()["ocode"];
418 418
         }
419 419
         return $ret;
@@ -431,15 +431,15 @@  discard block
 block discarded – undo
431 431
         if (isset($sub['verdict'])) {
432 432
             $sub["color"]=$this->colorScheme[$sub['verdict']];
433 433
         }
434
-        $result = DB::table($this->tableName)->where(['sid'=>$sid])->update($sub);
435
-        $contestModel = new ContestModel();
436
-        $submission_info = DB::table($this->tableName) -> where(['sid'=>$sid]) -> get() -> first();
437
-        if ($result==1 && $submission_info['cid'] && $contestModel->isContestRunning($submission_info['cid'])){
438
-            $sub['pid'] = $submission_info['pid'];
439
-            $sub['uid'] = $submission_info['uid'];
440
-            $sub['cid'] = $submission_info['cid'];
441
-            $sub['sid'] = $sid;
442
-            $contestModel->updateContestRankTable($submission_info['cid'],$sub);
434
+        $result=DB::table($this->tableName)->where(['sid'=>$sid])->update($sub);
435
+        $contestModel=new ContestModel();
436
+        $submission_info=DB::table($this->tableName) -> where(['sid'=>$sid]) -> get() -> first();
437
+        if ($result==1 && $submission_info['cid'] && $contestModel->isContestRunning($submission_info['cid'])) {
438
+            $sub['pid']=$submission_info['pid'];
439
+            $sub['uid']=$submission_info['uid'];
440
+            $sub['cid']=$submission_info['cid'];
441
+            $sub['sid']=$sid;
442
+            $contestModel->updateContestRankTable($submission_info['cid'], $sub);
443 443
         }
444 444
         return $result;
445 445
     }
@@ -510,15 +510,15 @@  discard block
 block discarded – undo
510 510
             'desc'
511 511
         );
512 512
 
513
-        if($filter["pcode"]){
513
+        if ($filter["pcode"]) {
514 514
             $paginator=$paginator->where(["pcode"=>$filter["pcode"]]);
515 515
         }
516 516
 
517
-        if($filter["result"]){
517
+        if ($filter["result"]) {
518 518
             $paginator=$paginator->where(["verdict"=>$filter["result"]]);
519 519
         }
520 520
 
521
-        if($filter["account"]){
521
+        if ($filter["account"]) {
522 522
             $paginator=$paginator->where(["name"=>$filter["account"]]);
523 523
         }
524 524
 
Please login to merge, or discard this patch.
app/Http/Controllers/ContestController.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
         $filter["rated"]=isset($all_data["rated"]) ? $all_data["rated"] : null;
35 35
         $filter["anticheated"]=isset($all_data["anticheated"]) ? $all_data["anticheated"] : null;
36 36
         $filter["practice"]=isset($all_data["practice"]) ? $all_data["practice"] : null;
37
-        $return_list=$contestModel->list($filter,Auth::check()?Auth::user()->id:0);
37
+        $return_list=$contestModel->list($filter, Auth::check() ?Auth::user()->id : 0);
38 38
         $featured=$contestModel->featured();
39 39
         if (is_null($return_list)) {
40 40
             if (isset($all_data["page"]) && $all_data["page"]>1) {
@@ -188,8 +188,8 @@  discard block
 block discarded – undo
188 188
             ];
189 189
         }
190 190
 
191
-        $editor_left_width = $accountModel->getExtra(Auth::user()->id, 'editor_left_width');
192
-        if(empty($editor_left_width)) $editor_left_width='40';
191
+        $editor_left_width=$accountModel->getExtra(Auth::user()->id, 'editor_left_width');
192
+        if (empty($editor_left_width)) $editor_left_width='40';
193 193
 
194 194
         return view('contest.board.editor', [
195 195
             'page_title'=>"Problem Detail",
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
         $contestModel=new ContestModel();
352 352
         $verified=$contestModel->isVerified($cid);
353 353
         $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
354
-        if ($clearance <= 2) {
354
+        if ($clearance<=2) {
355 355
             return Redirect::route('contest_detail', ['cid' => $cid]);
356 356
         }
357 357
         $contest_name=$contestModel->contestName($cid);
@@ -379,20 +379,20 @@  discard block
 block discarded – undo
379 379
     {
380 380
         $contestModel=new ContestModel();
381 381
         $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
382
-        if ($clearance <= 2) {
382
+        if ($clearance<=2) {
383 383
             return Redirect::route('contest_detail', ['cid' => $cid]);
384 384
         }
385 385
         $account=$contestModel->getContestAccount($cid);
386
-        if($account==null){
387
-            return ;
388
-        }else{
386
+        if ($account==null) {
387
+            return;
388
+        } else {
389 389
             $AccountExport=new AccountExport($account);
390 390
             $filename="ContestAccount$cid";
391 391
             return Excel::download($AccountExport, $filename.'.xlsx');
392 392
         }
393 393
     }
394 394
 
395
-    public function analysis($cid){
395
+    public function analysis($cid) {
396 396
         $contestModel=new ContestModel();
397 397
         $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
398 398
         if (!$clearance) {
@@ -413,17 +413,17 @@  discard block
 block discarded – undo
413 413
         ]);
414 414
     }
415 415
 
416
-    public function refreshContestRank($cid){
416
+    public function refreshContestRank($cid) {
417 417
         $contestModel=new ContestModel();
418 418
         $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
419
-        if ($clearance <= 2) {
419
+        if ($clearance<=2) {
420 420
             return Redirect::route('contest.detail', ['cid' => $cid]);
421 421
         }
422 422
         $contestRankRaw=$contestModel->contestRankCache($cid);
423 423
         Cache::tags(['contest', 'rank'])->put($cid, $contestRankRaw);
424 424
         Cache::tags(['contest', 'rank'])->put("contestAdmin$cid", $contestRankRaw);
425 425
         $end_time=strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]);
426
-        if(time() > $end_time){
426
+        if (time()>$end_time) {
427 427
             $this->storeContestRankInMySQL($cid, $contestRankRaw);
428 428
         }
429 429
         return Redirect::route('contest.rank', ['cid' => $cid]);
Please login to merge, or discard this patch.