Test Setup Failed
Push — master ( eb21ec...2ac834 )
by John
04:36
created
app/Models/ContestModel.php 1 patch
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -8,14 +8,14 @@  discard block
 block discarded – undo
8 8
 
9 9
 class ContestModel extends Model
10 10
 {
11
-    protected $tableName = 'contest';
12
-    public $rule = ["Unknown","ACM","OI","Custom ACM","Custom OI"];
11
+    protected $tableName='contest';
12
+    public $rule=["Unknown", "ACM", "OI", "Custom ACM", "Custom OI"];
13 13
 
14 14
     public function calcLength($a, $b)
15 15
     {
16 16
         $s=strtotime($b)-strtotime($a);
17
-        $h=intval($s/3600);
18
-        $m=round(($s-$h*3600)/60);
17
+        $h=intval($s / 3600);
18
+        $m=round(($s-$h * 3600) / 60);
19 19
         if ($m==60) {
20 20
             $h++;
21 21
             $m=0;
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 
35 35
     public function canViewContest($cid, $uid)
36 36
     {
37
-        $contest_detail = DB::table($this->tableName)->where([
37
+        $contest_detail=DB::table($this->tableName)->where([
38 38
             "cid"=>$cid
39 39
         ])->first();
40 40
 
@@ -45,19 +45,19 @@  discard block
 block discarded – undo
45 45
             if ($uid==0) {
46 46
                 return [];
47 47
             }
48
-            $group_info = DB::table("group_member")->where([
48
+            $group_info=DB::table("group_member")->where([
49 49
                 "uid"=>$uid,
50 50
                 "gid"=>$contest_detail['gid'],
51
-                ["role",">",0]
51
+                ["role", ">", 0]
52 52
             ])->first();
53 53
             return empty($group_info) ? [] : $contest_detail;
54 54
         }
55 55
     }
56 56
 
57
-    public function detail($cid, $uid = 0)
57
+    public function detail($cid, $uid=0)
58 58
     {
59
-        $contest_clearance = $this->judgeOutSideClearance($cid, $uid);
60
-        $contest_detail = DB::table($this->tableName)->where([
59
+        $contest_clearance=$this->judgeOutSideClearance($cid, $uid);
60
+        $contest_detail=DB::table($this->tableName)->where([
61 61
             "cid"=>$cid
62 62
         ])->first();
63 63
 
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 
90 90
     public function listByGroup($gid)
91 91
     {
92
-        $contest_list = DB::table($this->tableName)->where([
92
+        $contest_list=DB::table($this->tableName)->where([
93 93
             "gid"=>$gid
94 94
         ])->orderBy('begin_time', 'desc')->get()->all();
95 95
 
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 
114 114
     public function list()
115 115
     {
116
-        $contest_list = DB::table($this->tableName)->where([
116
+        $contest_list=DB::table($this->tableName)->where([
117 117
             "public"=>1,
118 118
             "audit_status"=>1
119 119
         ])->orderBy('begin_time', 'desc')->get()->all();
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 
132 132
     public function featured()
133 133
     {
134
-        $featured = DB::table($this->tableName)->where([
134
+        $featured=DB::table($this->tableName)->where([
135 135
             "public"=>1,
136 136
             "audit_status"=>1,
137 137
             "featured"=>1
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 
149 149
     public function remainingTime($cid)
150 150
     {
151
-        $end_time = DB::table($this->tableName)->where([
151
+        $end_time=DB::table($this->tableName)->where([
152 152
             "cid"=>$cid
153 153
         ])->select("end_time")->first()["end_time"];
154 154
         $end_time=strtotime($end_time);
@@ -156,29 +156,29 @@  discard block
 block discarded – undo
156 156
         return $end_time-$cur_time;
157 157
     }
158 158
 
159
-    public function intToChr($index, $start = 65)
159
+    public function intToChr($index, $start=65)
160 160
     {
161
-        $str = '';
162
-        if (floor($index / 26) > 0) {
163
-            $str .= $this->intToChr(floor($index / 26)-1);
161
+        $str='';
162
+        if (floor($index / 26)>0) {
163
+            $str.=$this->intToChr(floor($index / 26)-1);
164 164
         }
165
-        return $str . chr($index % 26 + $start);
165
+        return $str.chr($index % 26+$start);
166 166
     }
167 167
 
168 168
     public function contestProblems($cid, $uid)
169 169
     {
170 170
         $submissionModel=new SubmissionModel();
171 171
 
172
-        $contest_rule = $this->contestRule($cid);
172
+        $contest_rule=$this->contestRule($cid);
173 173
 
174
-        $problemSet = DB::table("contest_problem")->join("problem", "contest_problem.pid", "=", "problem.pid")->where([
174
+        $problemSet=DB::table("contest_problem")->join("problem", "contest_problem.pid", "=", "problem.pid")->where([
175 175
             "cid"=>$cid
176 176
         ])->orderBy('ncode', 'asc')->select("ncode", "alias", "contest_problem.pid as pid", "title")->get()->all();
177 177
 
178 178
         foreach ($problemSet as &$p) {
179
-            $frozen_time = strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]);
179
+            $frozen_time=strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]);
180 180
             if ($contest_rule==1) {
181
-                $prob_stat = DB::table("submission")->select(
181
+                $prob_stat=DB::table("submission")->select(
182 182
                     DB::raw("count(sid) as submission_count"),
183 183
                     DB::raw("sum(verdict='accepted') as passed_count"),
184 184
                     DB::raw("sum(verdict='accepted')/count(sid)*100 as ac_rate")
@@ -197,9 +197,9 @@  discard block
 block discarded – undo
197 197
                     $p["ac_rate"]=round($prob_stat["ac_rate"], 2);
198 198
                 }
199 199
             } else {
200
-                $prob_stat = $this->contestProblemInfoOI($cid,$p["pid"],$uid);
201
-                $p["points"] = $prob_stat["points"];
202
-                $p["score"] = empty($prob_stat["score_parsed"])?0:$prob_stat["score_parsed"];
200
+                $prob_stat=$this->contestProblemInfoOI($cid, $p["pid"], $uid);
201
+                $p["points"]=$prob_stat["points"];
202
+                $p["score"]=empty($prob_stat["score_parsed"]) ? 0 : $prob_stat["score_parsed"];
203 203
             }
204 204
             $prob_status=$submissionModel->getProblemStatus($p["pid"], $uid, $cid);
205 205
             if (empty($prob_status)) {
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 
236 236
     public function getCustomInfo($cid)
237 237
     {
238
-        $basic_info = DB::table($this->tableName)->where([
238
+        $basic_info=DB::table($this->tableName)->where([
239 239
             "cid"=>$cid
240 240
         ])->select("verified", "gid")->first();
241 241
         return $basic_info["verified"] ? DB::table("group")->where([
@@ -246,12 +246,12 @@  discard block
 block discarded – undo
246 246
 
247 247
     public function formatTime($seconds)
248 248
     {
249
-        if ($seconds >3600) {
250
-            $hours =intval($seconds/3600);
251
-            $minutes = $seconds % 3600;
252
-            $time = $hours.":".gmstrftime('%M:%S', $minutes);
249
+        if ($seconds>3600) {
250
+            $hours=intval($seconds / 3600);
251
+            $minutes=$seconds % 3600;
252
+            $time=$hours.":".gmstrftime('%M:%S', $minutes);
253 253
         } else {
254
-            $time = gmstrftime('%H:%M:%S', $seconds);
254
+            $time=gmstrftime('%H:%M:%S', $seconds);
255 255
         }
256 256
         return $time;
257 257
     }
@@ -268,9 +268,9 @@  discard block
 block discarded – undo
268 268
             ])->first()["points"]
269 269
         ];
270 270
 
271
-        $frozen_time = strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]);
271
+        $frozen_time=strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]);
272 272
 
273
-        $highest_record = DB::table("submission")->where([
273
+        $highest_record=DB::table("submission")->where([
274 274
             "cid"=>$cid,
275 275
             "pid"=>$pid,
276 276
             "uid"=>$uid
@@ -283,8 +283,8 @@  discard block
 block discarded – undo
283 283
                 "pid"=>$pid
284 284
             ])->first()["tot_score"];
285 285
 
286
-            $ret["color"]=($ret["score"]==$tot_score)?"wemd-teal-text":"wemd-green-text";
287
-            $ret["score_parsed"]=$ret["score"]/$tot_score*($ret["points"]);
286
+            $ret["color"]=($ret["score"]==$tot_score) ? "wemd-teal-text" : "wemd-green-text";
287
+            $ret["score_parsed"]=$ret["score"] / $tot_score * ($ret["points"]);
288 288
         }
289 289
         return $ret;
290 290
     }
@@ -300,9 +300,9 @@  discard block
 block discarded – undo
300 300
             "color"=>"",
301 301
         ];
302 302
 
303
-        $frozen_time = strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]);
303
+        $frozen_time=strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]);
304 304
 
305
-        $ac_record = DB::table("submission")->where([
305
+        $ac_record=DB::table("submission")->where([
306 306
             "cid"=>$cid,
307 307
             "pid"=>$pid,
308 308
             "uid"=>$uid,
@@ -312,13 +312,13 @@  discard block
 block discarded – undo
312 312
         if (!empty($ac_record)) {
313 313
             $ret["solved"]=1;
314 314
 
315
-            $ret["solved_time"]=$ac_record["submission_date"] - strtotime(DB::table($this->tableName)->where([
315
+            $ret["solved_time"]=$ac_record["submission_date"]-strtotime(DB::table($this->tableName)->where([
316 316
                 "cid"=>$cid
317 317
             ])->first()["begin_time"]);
318 318
 
319 319
             $ret["solved_time_parsed"]=$this->formatTime($ret["solved_time"]);
320 320
 
321
-            $ret["wrong_doings"] = DB::table("submission")->where([
321
+            $ret["wrong_doings"]=DB::table("submission")->where([
322 322
                 "cid"=>$cid,
323 323
                 "pid"=>$pid,
324 324
                 "uid"=>$uid
@@ -332,15 +332,15 @@  discard block
 block discarded – undo
332 332
                 'Output Limit Exceeded'
333 333
             ])->where("submission_date", "<", $ac_record["submission_date"])->count();
334 334
 
335
-            $others_first = DB::table("submission")->where([
335
+            $others_first=DB::table("submission")->where([
336 336
                 "cid"=>$cid,
337 337
                 "pid"=>$pid,
338 338
                 "verdict"=>"Accepted"
339 339
             ])->where("submission_date", "<", $ac_record["submission_date"])->count();
340 340
 
341
-            $ret["color"]=$others_first?"wemd-green-text":"wemd-teal-text";
341
+            $ret["color"]=$others_first ? "wemd-green-text" : "wemd-teal-text";
342 342
         } else {
343
-            $ret["wrong_doings"] = DB::table("submission")->where([
343
+            $ret["wrong_doings"]=DB::table("submission")->where([
344 344
                 "cid"=>$cid,
345 345
                 "pid"=>$pid,
346 346
                 "uid"=>$uid
@@ -369,26 +369,26 @@  discard block
 block discarded – undo
369 369
 
370 370
         $ret=[];
371 371
 
372
-        $contest_info = DB::table("contest")->where("cid", $cid)->first();
372
+        $contest_info=DB::table("contest")->where("cid", $cid)->first();
373 373
 
374
-        $user_in_group = !empty(DB::table("group_member")->where([
374
+        $user_in_group=!empty(DB::table("group_member")->where([
375 375
             "uid" => $uid,
376 376
             "gid" => $contest_info["gid"]
377
-        ])->where("role",">",0)->first());
377
+        ])->where("role", ">", 0)->first());
378 378
 
379 379
         if ($contest_info["registration"]) {
380
-            $submissionUsers = DB::table("contest_participant")->where([
380
+            $submissionUsers=DB::table("contest_participant")->where([
381 381
                 "cid"=>$cid,
382 382
                 "audit"=>1
383 383
             ])->select('uid')->get()->all();
384 384
         } else {
385 385
             // Those who submitted are participants
386
-            $submissionUsers = DB::table("submission")->where([
386
+            $submissionUsers=DB::table("submission")->where([
387 387
                 "cid"=>$cid
388 388
             ])->select('uid')->groupBy('uid')->get()->all();
389 389
         }
390 390
 
391
-        $problemSet = DB::table("contest_problem")->join("problem", "contest_problem.pid", "=", "problem.pid")->where([
391
+        $problemSet=DB::table("contest_problem")->join("problem", "contest_problem.pid", "=", "problem.pid")->where([
392 392
             "cid"=>$cid
393 393
         ])->orderBy('ncode', 'asc')->select("ncode", "alias", "contest_problem.pid as pid", "title")->get()->all();
394 394
 
@@ -408,8 +408,8 @@  discard block
 block discarded – undo
408 408
                         "solved_time_parsed"=>$prob_stat["solved_time_parsed"]
409 409
                     ];
410 410
                     if ($prob_stat["solved"]) {
411
-                        $totPen+=$prob_stat["wrong_doings"]*20;
412
-                        $totPen+=$prob_stat["solved_time"]/60;
411
+                        $totPen+=$prob_stat["wrong_doings"] * 20;
412
+                        $totPen+=$prob_stat["solved_time"] / 60;
413 413
                         $totScore+=$prob_stat["solved"];
414 414
                     }
415 415
                 }
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
             }
460 460
         }
461 461
 
462
-        usort($ret, function ($a, $b) {
462
+        usort($ret, function($a, $b) {
463 463
             if ($a["score"]==$b["score"]) {
464 464
                 if ($a["penalty"]==$b["penalty"]) {
465 465
                     return 0;
@@ -499,19 +499,19 @@  discard block
 block discarded – undo
499 499
         return DB::table("contest")->where("cid", $cid)->where("end_time", "<", date("Y-m-d H:i:s"))->count();
500 500
     }
501 501
 
502
-    public function judgeClearance($cid, $uid = 0)
502
+    public function judgeClearance($cid, $uid=0)
503 503
     {
504 504
         if ($uid==0) {
505 505
             return 0;
506 506
         }
507
-        $contest_started = DB::table("contest")->where("cid", $cid)->where("begin_time", "<", date("Y-m-d H:i:s"))->count();
508
-        $contest_ended = DB::table("contest")->where("cid", $cid)->where("end_time", "<", date("Y-m-d H:i:s"))->count();
507
+        $contest_started=DB::table("contest")->where("cid", $cid)->where("begin_time", "<", date("Y-m-d H:i:s"))->count();
508
+        $contest_ended=DB::table("contest")->where("cid", $cid)->where("end_time", "<", date("Y-m-d H:i:s"))->count();
509 509
         if ($contest_started) {
510 510
             // judge if qualified
511 511
             // return 1 if view access, can only view
512 512
             // return 2 if participant access, can submit code
513 513
             // return 3 if admin access, can create announcements
514
-            $contest_info = DB::table("contest")->where("cid", $cid)->first();
514
+            $contest_info=DB::table("contest")->where("cid", $cid)->first();
515 515
             if ($contest_info["registration"]) {
516 516
                 // check if uid in registration, temp return 3
517 517
                 return 2;
@@ -531,9 +531,9 @@  discard block
 block discarded – undo
531 531
         }
532 532
     }
533 533
 
534
-    public function judgeOutsideClearance($cid, $uid = 0)
534
+    public function judgeOutsideClearance($cid, $uid=0)
535 535
     {
536
-        $contest_info = DB::table("contest")->where("cid", $cid)->first();
536
+        $contest_info=DB::table("contest")->where("cid", $cid)->first();
537 537
         if (empty($contest_info)) {
538 538
             return 0;
539 539
         }
@@ -562,24 +562,24 @@  discard block
 block discarded – undo
562 562
 
563 563
     public function arrangeContest($gid, $config, $problems)
564 564
     {
565
-        DB::transaction(function () use ($gid, $config, $problems) {
566
-            $cid = DB::table($this->tableName)->insertGetId([
565
+        DB::transaction(function() use ($gid, $config, $problems) {
566
+            $cid=DB::table($this->tableName)->insertGetId([
567 567
                 "gid"=>$gid,
568 568
                 "name"=>$config["name"],
569
-                "verified"=>0,                          //todo
569
+                "verified"=>0, //todo
570 570
                 "rated"=>0,
571 571
                 "anticheated"=>0,
572 572
                 "featured"=>0,
573 573
                 "description"=>$config["description"],
574
-                "rule"=>1,                              //todo
574
+                "rule"=>1, //todo
575 575
                 "begin_time"=>$config["begin_time"],
576 576
                 "end_time"=>$config["end_time"],
577
-                "public"=>0,                            //todo
578
-                "registration"=>0,                      //todo
579
-                "registration_due"=>null,               //todo
580
-                "registant_type"=>0,                    //todo
581
-                "froze_length"=>0,                      //todo
582
-                "status_visibility"=>3,                 //todo
577
+                "public"=>0, //todo
578
+                "registration"=>0, //todo
579
+                "registration_due"=>null, //todo
580
+                "registant_type"=>0, //todo
581
+                "froze_length"=>0, //todo
582
+                "status_visibility"=>3, //todo
583 583
                 "create_time"=>date("Y-m-d H:i:s"),
584 584
                 "audit_status"=>1                       //todo
585 585
             ]);
Please login to merge, or discard this patch.
app/Http/Controllers/ContestController.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -76,11 +76,11 @@  discard block
 block discarded – undo
76 76
         if (!$contestModel->judgeClearance($cid, Auth::user()->id)) {
77 77
             return Redirect::route('contest_detail', ['cid' => $cid]);
78 78
         }
79
-        $contest_name = $contestModel->contestName($cid);
80
-        $contest_rule = $contestModel->contestRule($cid);
81
-        $problemSet = $contestModel->contestProblems($cid, Auth::user()->id);
82
-        $remainingTime = $contestModel->remainingTime($cid);
83
-        $customInfo = $contestModel->getCustomInfo($cid);
79
+        $contest_name=$contestModel->contestName($cid);
80
+        $contest_rule=$contestModel->contestRule($cid);
81
+        $problemSet=$contestModel->contestProblems($cid, Auth::user()->id);
82
+        $remainingTime=$contestModel->remainingTime($cid);
83
+        $customInfo=$contestModel->getCustomInfo($cid);
84 84
         if ($remainingTime<=0) {
85 85
             $remainingTime=0;
86 86
         }
@@ -111,10 +111,10 @@  discard block
 block discarded – undo
111 111
         if (!$contestModel->judgeClearance($cid, Auth::user()->id)) {
112 112
             return Redirect::route('contest_detail', ['cid' => $cid]);
113 113
         }
114
-        $contest_name = $contestModel->contestName($cid);
115
-        $contest_ended = $contestModel->isContestEnded($cid);
114
+        $contest_name=$contestModel->contestName($cid);
115
+        $contest_ended=$contestModel->isContestEnded($cid);
116 116
         $pid=$contestModel->getPid($cid, $ncode);
117
-        if(empty($pid)){
117
+        if (empty($pid)) {
118 118
             return Redirect::route('contest_board', ['cid' => $cid]);
119 119
         }
120 120
         $pcode=$problemModel->pcode($pid);
@@ -192,11 +192,11 @@  discard block
 block discarded – undo
192 192
         if (!$contestModel->judgeClearance($cid, Auth::user()->id)) {
193 193
             return Redirect::route('contest_detail', ['cid' => $cid]);
194 194
         }
195
-        $contest_name = $contestModel->contestName($cid);
196
-        $contest_rule = $contestModel->contestRule($cid);
197
-        $problemSet = $contestModel->contestProblems($cid, Auth::user()->id);
198
-        $customInfo = $contestModel->getCustomInfo($cid);
199
-        $contestRank = $contestModel->contestRank($cid, Auth::user()->id);
195
+        $contest_name=$contestModel->contestName($cid);
196
+        $contest_rule=$contestModel->contestRule($cid);
197
+        $problemSet=$contestModel->contestProblems($cid, Auth::user()->id);
198
+        $customInfo=$contestModel->getCustomInfo($cid);
199
+        $contestRank=$contestModel->contestRank($cid, Auth::user()->id);
200 200
         return view('contest.board.rank', [
201 201
             'page_title'=>"Challenge",
202 202
             'navigation' => "Contest",
@@ -221,9 +221,9 @@  discard block
 block discarded – undo
221 221
         if (!$contestModel->judgeClearance($cid, Auth::user()->id)) {
222 222
             return Redirect::route('contest_detail', ['cid' => $cid]);
223 223
         }
224
-        $contest_name = $contestModel->contestName($cid);
225
-        $customInfo = $contestModel->getCustomInfo($cid);
226
-        $clarificationList = $contestModel->getClarificationList($cid);
224
+        $contest_name=$contestModel->contestName($cid);
225
+        $customInfo=$contestModel->getCustomInfo($cid);
226
+        $clarificationList=$contestModel->getClarificationList($cid);
227 227
         return view('contest.board.clarification', [
228 228
             'page_title'=>"Clarification",
229 229
             'navigation' => "Contest",
@@ -246,8 +246,8 @@  discard block
 block discarded – undo
246 246
         if (!$contestModel->judgeClearance($cid, Auth::user()->id)) {
247 247
             return Redirect::route('contest_detail', ['cid' => $cid]);
248 248
         }
249
-        $contest_name = $contestModel->contestName($cid);
250
-        $customInfo = $contestModel->getCustomInfo($cid);
249
+        $contest_name=$contestModel->contestName($cid);
250
+        $customInfo=$contestModel->getCustomInfo($cid);
251 251
         return view('contest.board.print', [
252 252
             'page_title'=>"Print",
253 253
             'navigation' => "Contest",
Please login to merge, or discard this patch.