Test Setup Failed
Push — master ( 066fb0...ef01f5 )
by John
05:19
created
app/Models/ContestModel.php 1 patch
Spacing   +64 added lines, -64 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,25 +156,25 @@  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
-        $problemSet = DB::table("contest_problem")->join("problem", "contest_problem.pid", "=", "problem.pid")->where([
171
+        $problemSet=DB::table("contest_problem")->join("problem", "contest_problem.pid", "=", "problem.pid")->where([
172 172
             "cid"=>$cid
173 173
         ])->orderBy('ncode', 'asc')->select("ncode", "alias", "contest_problem.pid as pid", "title")->get()->all();
174 174
 
175 175
         foreach ($problemSet as &$p) {
176
-            $frozen_time = strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]);
177
-            $prob_stat = DB::table("submission")->select(
176
+            $frozen_time=strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]);
177
+            $prob_stat=DB::table("submission")->select(
178 178
                 DB::raw("count(sid) as submission_count"),
179 179
                 DB::raw("sum(verdict='accepted') as passed_count"),
180 180
                 DB::raw("sum(verdict='accepted')/count(sid)*100 as ac_rate")
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 
227 227
     public function getCustomInfo($cid)
228 228
     {
229
-        $basic_info = DB::table($this->tableName)->where([
229
+        $basic_info=DB::table($this->tableName)->where([
230 230
             "cid"=>$cid
231 231
         ])->select("verified", "gid")->first();
232 232
         return $basic_info["verified"] ? DB::table("group")->where([
@@ -237,12 +237,12 @@  discard block
 block discarded – undo
237 237
 
238 238
     public function formatTime($seconds)
239 239
     {
240
-        if ($seconds >3600) {
241
-            $hours =intval($seconds/3600);
242
-            $minutes = $seconds % 3600;
243
-            $time = $hours.":".gmstrftime('%M:%S', $minutes);
240
+        if ($seconds>3600) {
241
+            $hours=intval($seconds / 3600);
242
+            $minutes=$seconds % 3600;
243
+            $time=$hours.":".gmstrftime('%M:%S', $minutes);
244 244
         } else {
245
-            $time = gmstrftime('%H:%M:%S', $seconds);
245
+            $time=gmstrftime('%H:%M:%S', $seconds);
246 246
         }
247 247
         return $time;
248 248
     }
@@ -255,9 +255,9 @@  discard block
 block discarded – undo
255 255
             "score_parsed"=>"",
256 256
         ];
257 257
 
258
-        $frozen_time = strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]);
258
+        $frozen_time=strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]);
259 259
 
260
-        $highest_record = DB::table("submission")->where([
260
+        $highest_record=DB::table("submission")->where([
261 261
             "cid"=>$cid,
262 262
             "pid"=>$pid,
263 263
             "uid"=>$uid
@@ -270,8 +270,8 @@  discard block
 block discarded – undo
270 270
                 "pid"=>$pid
271 271
             ])->first()["tot_score"];
272 272
 
273
-            $ret["color"]=($ret["score"]==$tot_score)?"wemd-teal-text":"wemd-green-text";
274
-            $ret["score_parsed"]=$ret["score"]/$tot_score*(DB::table("contest_problem")->where([
273
+            $ret["color"]=($ret["score"]==$tot_score) ? "wemd-teal-text" : "wemd-green-text";
274
+            $ret["score_parsed"]=$ret["score"] / $tot_score * (DB::table("contest_problem")->where([
275 275
                 "pid"=>$pid,
276 276
                 "cid"=>$cid
277 277
             ])->first()["points"]);
@@ -290,9 +290,9 @@  discard block
 block discarded – undo
290 290
             "color"=>"",
291 291
         ];
292 292
 
293
-        $frozen_time = strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]);
293
+        $frozen_time=strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]);
294 294
 
295
-        $ac_record = DB::table("submission")->where([
295
+        $ac_record=DB::table("submission")->where([
296 296
             "cid"=>$cid,
297 297
             "pid"=>$pid,
298 298
             "uid"=>$uid,
@@ -302,13 +302,13 @@  discard block
 block discarded – undo
302 302
         if (!empty($ac_record)) {
303 303
             $ret["solved"]=1;
304 304
 
305
-            $ret["solved_time"]=$ac_record["submission_date"] - strtotime(DB::table($this->tableName)->where([
305
+            $ret["solved_time"]=$ac_record["submission_date"]-strtotime(DB::table($this->tableName)->where([
306 306
                 "cid"=>$cid
307 307
             ])->first()["begin_time"]);
308 308
 
309 309
             $ret["solved_time_parsed"]=$this->formatTime($ret["solved_time"]);
310 310
 
311
-            $ret["wrong_doings"] = DB::table("submission")->where([
311
+            $ret["wrong_doings"]=DB::table("submission")->where([
312 312
                 "cid"=>$cid,
313 313
                 "pid"=>$pid,
314 314
                 "uid"=>$uid
@@ -322,15 +322,15 @@  discard block
 block discarded – undo
322 322
                 'Output Limit Exceeded'
323 323
             ])->where("submission_date", "<", $ac_record["submission_date"])->count();
324 324
 
325
-            $others_first = DB::table("submission")->where([
325
+            $others_first=DB::table("submission")->where([
326 326
                 "cid"=>$cid,
327 327
                 "pid"=>$pid,
328 328
                 "verdict"=>"Accepted"
329 329
             ])->where("submission_date", "<", $ac_record["submission_date"])->count();
330 330
 
331
-            $ret["color"]=$others_first?"wemd-green-text":"wemd-teal-text";
331
+            $ret["color"]=$others_first ? "wemd-green-text" : "wemd-teal-text";
332 332
         } else {
333
-            $ret["wrong_doings"] = DB::table("submission")->where([
333
+            $ret["wrong_doings"]=DB::table("submission")->where([
334 334
                 "cid"=>$cid,
335 335
                 "pid"=>$pid,
336 336
                 "uid"=>$uid
@@ -359,26 +359,26 @@  discard block
 block discarded – undo
359 359
 
360 360
         $ret=[];
361 361
 
362
-        $contest_info = DB::table("contest")->where("cid", $cid)->first();
362
+        $contest_info=DB::table("contest")->where("cid", $cid)->first();
363 363
 
364
-        $user_in_group = !empty(DB::table("group_member")->where([
364
+        $user_in_group=!empty(DB::table("group_member")->where([
365 365
             "uid" => $uid,
366 366
             "gid" => $contest_info["gid"]
367
-        ])->where("role",">",0)->first());
367
+        ])->where("role", ">", 0)->first());
368 368
 
369 369
         if ($contest_info["registration"]) {
370
-            $submissionUsers = DB::table("contest_participant")->where([
370
+            $submissionUsers=DB::table("contest_participant")->where([
371 371
                 "cid"=>$cid,
372 372
                 "audit"=>1
373 373
             ])->select('uid')->get()->all();
374 374
         } else {
375 375
             // Those who submitted are participants
376
-            $submissionUsers = DB::table("submission")->where([
376
+            $submissionUsers=DB::table("submission")->where([
377 377
                 "cid"=>$cid
378 378
             ])->select('uid')->groupBy('uid')->get()->all();
379 379
         }
380 380
 
381
-        $problemSet = DB::table("contest_problem")->join("problem", "contest_problem.pid", "=", "problem.pid")->where([
381
+        $problemSet=DB::table("contest_problem")->join("problem", "contest_problem.pid", "=", "problem.pid")->where([
382 382
             "cid"=>$cid
383 383
         ])->orderBy('ncode', 'asc')->select("ncode", "alias", "contest_problem.pid as pid", "title", "score", "tot_score")->get()->all();
384 384
 
@@ -398,8 +398,8 @@  discard block
 block discarded – undo
398 398
                         "solved_time_parsed"=>$prob_stat["solved_time_parsed"]
399 399
                     ];
400 400
                     if ($prob_stat["solved"]) {
401
-                        $totPen+=$prob_stat["wrong_doings"]*20;
402
-                        $totPen+=$prob_stat["solved_time"]/60;
401
+                        $totPen+=$prob_stat["wrong_doings"] * 20;
402
+                        $totPen+=$prob_stat["solved_time"] / 60;
403 403
                         $totScore+=$prob_stat["solved"];
404 404
                     }
405 405
                 }
@@ -449,7 +449,7 @@  discard block
 block discarded – undo
449 449
             }
450 450
         }
451 451
 
452
-        usort($ret, function ($a, $b) {
452
+        usort($ret, function($a, $b) {
453 453
             if ($a["score"]==$b["score"]) {
454 454
                 if ($a["penalty"]==$b["penalty"]) {
455 455
                     return 0;
@@ -489,19 +489,19 @@  discard block
 block discarded – undo
489 489
         return DB::table("contest")->where("cid", $cid)->where("end_time", "<", date("Y-m-d H:i:s"))->count();
490 490
     }
491 491
 
492
-    public function judgeClearance($cid, $uid = 0)
492
+    public function judgeClearance($cid, $uid=0)
493 493
     {
494 494
         if ($uid==0) {
495 495
             return 0;
496 496
         }
497
-        $contest_started = DB::table("contest")->where("cid", $cid)->where("begin_time", "<", date("Y-m-d H:i:s"))->count();
498
-        $contest_ended = DB::table("contest")->where("cid", $cid)->where("end_time", "<", date("Y-m-d H:i:s"))->count();
497
+        $contest_started=DB::table("contest")->where("cid", $cid)->where("begin_time", "<", date("Y-m-d H:i:s"))->count();
498
+        $contest_ended=DB::table("contest")->where("cid", $cid)->where("end_time", "<", date("Y-m-d H:i:s"))->count();
499 499
         if ($contest_started) {
500 500
             // judge if qualified
501 501
             // return 1 if view access, can only view
502 502
             // return 2 if participant access, can submit code
503 503
             // return 3 if admin access, can create announcements
504
-            $contest_info = DB::table("contest")->where("cid", $cid)->first();
504
+            $contest_info=DB::table("contest")->where("cid", $cid)->first();
505 505
             if ($contest_info["registration"]) {
506 506
                 // check if uid in registration, temp return 3
507 507
                 return 2;
@@ -521,9 +521,9 @@  discard block
 block discarded – undo
521 521
         }
522 522
     }
523 523
 
524
-    public function judgeOutsideClearance($cid, $uid = 0)
524
+    public function judgeOutsideClearance($cid, $uid=0)
525 525
     {
526
-        $contest_info = DB::table("contest")->where("cid", $cid)->first();
526
+        $contest_info=DB::table("contest")->where("cid", $cid)->first();
527 527
         if (empty($contest_info)) {
528 528
             return 0;
529 529
         }
@@ -547,24 +547,24 @@  discard block
 block discarded – undo
547 547
 
548 548
     public function arrangeContest($gid, $config, $problems)
549 549
     {
550
-        DB::transaction(function () use ($gid, $config, $problems) {
551
-            $cid = DB::table($this->tableName)->insertGetId([
550
+        DB::transaction(function() use ($gid, $config, $problems) {
551
+            $cid=DB::table($this->tableName)->insertGetId([
552 552
                 "gid"=>$gid,
553 553
                 "name"=>$config["name"],
554
-                "verified"=>0,                          //todo
554
+                "verified"=>0, //todo
555 555
                 "rated"=>0,
556 556
                 "anticheated"=>0,
557 557
                 "featured"=>0,
558 558
                 "description"=>$config["description"],
559
-                "rule"=>1,                              //todo
559
+                "rule"=>1, //todo
560 560
                 "begin_time"=>$config["begin_time"],
561 561
                 "end_time"=>$config["end_time"],
562
-                "public"=>0,                            //todo
563
-                "registration"=>0,                      //todo
564
-                "registration_due"=>null,               //todo
565
-                "registant_type"=>0,                    //todo
566
-                "froze_length"=>0,                      //todo
567
-                "status_visibility"=>3,                 //todo
562
+                "public"=>0, //todo
563
+                "registration"=>0, //todo
564
+                "registration_due"=>null, //todo
565
+                "registant_type"=>0, //todo
566
+                "froze_length"=>0, //todo
567
+                "status_visibility"=>3, //todo
568 568
                 "create_time"=>date("Y-m-d H:i:s"),
569 569
                 "audit_status"=>1                       //todo
570 570
             ]);
Please login to merge, or discard this patch.