Passed
Push — master ( b7ba29...167b3a )
by John
10:46 queued 05:08
created
app/Models/Eloquent/Problem.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -17,17 +17,17 @@
 block discarded – undo
17 17
 
18 18
     public function submissions()
19 19
     {
20
-        return $this->hasMany('App\Models\Eloquent\Submission','pid','pid');
20
+        return $this->hasMany('App\Models\Eloquent\Submission', 'pid', 'pid');
21 21
     }
22 22
 
23 23
     public function problemSamples()
24 24
     {
25
-        return $this->hasMany('App\Models\Eloquent\ProblemSample','pid','pid');
25
+        return $this->hasMany('App\Models\Eloquent\ProblemSample', 'pid', 'pid');
26 26
     }
27 27
 
28 28
     public function getProblemStatusAttribute()
29 29
     {
30
-        if(Auth::check()){
30
+        if (Auth::check()) {
31 31
             $prob_status=(new OutdatedSubmissionModel())->getProblemStatus($this->pid, Auth::user()->id);
32 32
             if (empty($prob_status)) {
33 33
                 return [
Please login to merge, or discard this patch.
app/Models/Eloquent/Tool/Pastebin.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -7,8 +7,8 @@
 block discarded – undo
7 7
 
8 8
 class Pastebin extends Model
9 9
 {
10
-    protected $table = 'pastebin';
11
-    protected $primaryKey = 'pbid';
10
+    protected $table='pastebin';
11
+    protected $primaryKey='pbid';
12 12
 
13 13
     protected $fillable=[
14 14
         'lang', 'title', 'user_id', 'expired_at', 'content', 'code'
Please login to merge, or discard this patch.
app/Models/Eloquent/ProblemSample.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -8,9 +8,9 @@
 block discarded – undo
8 8
 {
9 9
     protected $table='problem_sample';
10 10
     protected $primaryKey='psid';
11
-    protected $fillable = ['sample_input', 'sample_output'];
11
+    protected $fillable=['sample_input', 'sample_output'];
12 12
 
13 13
     public function problem() {
14
-        return $this->belongTo('App\Models\Eloquent\Problem','pid','pid');
14
+        return $this->belongTo('App\Models\Eloquent\Problem', 'pid', 'pid');
15 15
     }
16 16
 }
Please login to merge, or discard this patch.
app/Models/GroupModel.php 1 patch
Spacing   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -58,10 +58,10 @@  discard block
 block discarded – undo
58 58
         foreach ($trending_groups as &$t) {
59 59
             $t["members"]=$this->countGroupMembers($t["gid"]);
60 60
         }
61
-        usort($trending_groups, function ($a, $b) {
61
+        usort($trending_groups, function($a, $b) {
62 62
             return $b["members"]<=>$a["members"];
63 63
         });
64
-        Cache::tags(['group'])->put('trending', array_slice($trending_groups,0,12), 3600*24);
64
+        Cache::tags(['group'])->put('trending', array_slice($trending_groups, 0, 12), 3600 * 24);
65 65
     }
66 66
 
67 67
     public function userGroups($uid)
@@ -101,13 +101,13 @@  discard block
 block discarded – undo
101 101
 
102 102
     public function changeGroupName($gid, $GroupName)
103 103
     {
104
-        return DB::table("group")->where('gid',$gid)->update([
104
+        return DB::table("group")->where('gid', $gid)->update([
105 105
             "name"=>$GroupName
106 106
         ]);
107 107
     }
108 108
 
109
-    public function changeJoinPolicy($gid, $JoinPolicy){
110
-        return DB::table("group")->where('gid',$gid)->update([
109
+    public function changeJoinPolicy($gid, $JoinPolicy) {
110
+        return DB::table("group")->where('gid', $gid)->update([
111 111
             "join_policy"=>$JoinPolicy
112 112
         ]);
113 113
     }
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
     public function details($gcode)
122 122
     {
123 123
         $basic_info=DB::table($this->tableName)->where(["gcode"=>$gcode])->first();
124
-        if(empty($basic_info)) return [];
124
+        if (empty($basic_info)) return [];
125 125
         $basic_info["members"]=$this->countGroupMembers($basic_info["gid"]);
126 126
         $basic_info["tags"]=$this->getGroupTags($basic_info["gid"]);
127 127
         $basic_info["create_time_foramt"]=date_format(date_create($basic_info["created_at"]), 'M jS, Y');
@@ -138,10 +138,10 @@  discard block
 block discarded – undo
138 138
     public function userProfile($uid, $gid)
139 139
     {
140 140
         $info=DB::table("group_member")
141
-        ->join('users','users.id','=','group_member.uid')
141
+        ->join('users', 'users.id', '=', 'group_member.uid')
142 142
         ->where(["gid"=>$gid, "uid"=>$uid])
143 143
         ->where("role", ">", 0)
144
-        ->select('avatar','describes','email','gid','uid','name','nick_name','professional_rate','role','sub_group')
144
+        ->select('avatar', 'describes', 'email', 'gid', 'uid', 'name', 'nick_name', 'professional_rate', 'role', 'sub_group')
145 145
         ->first();
146 146
         if (!empty($info)) {
147 147
             $info["role_parsed"]=$this->role[$info["role"]];
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
         foreach ($user_list as &$u) {
170 170
             $u["role_parsed"]=$this->role[$u["role"]];
171 171
             $u["role_color"]=$this->role_color[$u["role"]];
172
-            if(is_null($u["sub_group"])) $u["sub_group"]="None";
172
+            if (is_null($u["sub_group"])) $u["sub_group"]="None";
173 173
         }
174 174
         return $user_list;
175 175
     }
@@ -230,16 +230,16 @@  discard block
 block discarded – undo
230 230
         ])->where("role", ">", 0)->count();
231 231
     }
232 232
 
233
-    public function problemTags($gid,$pid = -1)
233
+    public function problemTags($gid, $pid=-1)
234 234
     {
235
-        if($pid == -1){
236
-            $tags =  DB::table('group_problem_tag')
235
+        if ($pid==-1) {
236
+            $tags=DB::table('group_problem_tag')
237 237
             ->select('tag')
238
-            ->where('gid',$gid)
238
+            ->where('gid', $gid)
239 239
             ->distinct()
240 240
             ->get()->all();
241
-        }else{
242
-            $tags =  DB::table('group_problem_tag')
241
+        } else {
242
+            $tags=DB::table('group_problem_tag')
243 243
             ->select('tag')
244 244
             ->where('gid', $gid)
245 245
             ->where('pid', $pid)
@@ -247,10 +247,10 @@  discard block
 block discarded – undo
247 247
             ->get()->all();
248 248
         }
249 249
 
250
-        $tags_arr = [];
251
-        if(!empty($tags)){
250
+        $tags_arr=[];
251
+        if (!empty($tags)) {
252 252
             foreach ($tags as $value) {
253
-                array_push($tags_arr,$value['tag']);
253
+                array_push($tags_arr, $value['tag']);
254 254
             }
255 255
         }
256 256
         return $tags_arr;
@@ -258,28 +258,28 @@  discard block
 block discarded – undo
258 258
 
259 259
     public function problems($gid)
260 260
     {
261
-        $contestModel = new ContestModel();
262
-        $problems = DB::table('contest_problem')
263
-        ->join('contest','contest_problem.cid', '=', 'contest.cid')
264
-        ->join('problem','contest_problem.pid', '=', 'problem.pid' )
261
+        $contestModel=new ContestModel();
262
+        $problems=DB::table('contest_problem')
263
+        ->join('contest', 'contest_problem.cid', '=', 'contest.cid')
264
+        ->join('problem', 'contest_problem.pid', '=', 'problem.pid')
265 265
         ->select('contest_problem.cid as cid', 'problem.pid as pid', 'pcode', 'title')
266
-        ->where('contest.gid',$gid)
267
-        ->where('contest.practice',1)
268
-        ->orderBy('contest.created_at','desc')
266
+        ->where('contest.gid', $gid)
267
+        ->where('contest.practice', 1)
268
+        ->orderBy('contest.created_at', 'desc')
269 269
         ->distinct()
270 270
         ->get()->all();
271
-        $user_id = Auth::user()->id;
272
-        foreach($problems as $key => $value){
273
-            if($contestModel->judgeClearance($value['cid'],$user_id) != 3){
271
+        $user_id=Auth::user()->id;
272
+        foreach ($problems as $key => $value) {
273
+            if ($contestModel->judgeClearance($value['cid'], $user_id)!=3) {
274 274
                 unset($problems[$key]);
275
-            }else{
276
-                $problems[$key]['tags'] = $this->problemTags($gid,$value['pid']);
275
+            } else {
276
+                $problems[$key]['tags']=$this->problemTags($gid, $value['pid']);
277 277
             }
278 278
         }
279 279
         return $problems;
280 280
     }
281 281
 
282
-    public function problemAddTag($gid,$pid,$tag)
282
+    public function problemAddTag($gid, $pid, $tag)
283 283
     {
284 284
         return DB::table("group_problem_tag")->insert([
285 285
             "gid"=>$gid,
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
         ]);
289 289
     }
290 290
 
291
-    public function problemRemoveTag($gid,$pid,$tag)
291
+    public function problemRemoveTag($gid, $pid, $tag)
292 292
     {
293 293
         return DB::table("group_problem_tag")->where([
294 294
             "gid"=>$gid,
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
     public function judgeEmailClearance($gid, $email)
301 301
     {
302 302
         $user=DB::table("users")->where(["email"=>$email])->first();
303
-        if(empty($user)) return -4;
303
+        if (empty($user)) return -4;
304 304
         $ret=DB::table("group_member")->where([
305 305
             "gid"=>$gid,
306 306
             "uid"=>$user["id"],
@@ -391,20 +391,20 @@  discard block
 block discarded – undo
391 391
 
392 392
     public function groupMemberPracticeContestStat($gid)
393 393
     {
394
-        $contestModel = new ContestModel();
394
+        $contestModel=new ContestModel();
395 395
 
396
-        $allPracticeContest = DB::table('contest')
396
+        $allPracticeContest=DB::table('contest')
397 397
             ->where([
398 398
                 'gid' => $gid,
399 399
                 'practice' => 1,
400 400
             ])
401
-            ->select('cid','name')
401
+            ->select('cid', 'name')
402 402
             ->get()->all();
403
-        $user_list = $this->userList($gid);
403
+        $user_list=$this->userList($gid);
404 404
 
405
-        $memberData = [];
405
+        $memberData=[];
406 406
         foreach ($user_list as $u) {
407
-            $memberData[$u['uid']] = [
407
+            $memberData[$u['uid']]=[
408 408
                 'name' => $u['name'],
409 409
                 'nick_name' => $u['nick_name'],
410 410
                 'elo' => $u['ranking'],
@@ -415,61 +415,61 @@  discard block
 block discarded – undo
415 415
             ];
416 416
         }
417 417
         foreach ($allPracticeContest as $c) {
418
-            $contestRankRaw = $contestModel->contestRank($c['cid']);
419
-            foreach($contestRankRaw as $key => $contestRank){
420
-                if(isset($contestRank['remote']) && $contestRank['remote']){
418
+            $contestRankRaw=$contestModel->contestRank($c['cid']);
419
+            foreach ($contestRankRaw as $key => $contestRank) {
420
+                if (isset($contestRank['remote']) && $contestRank['remote']) {
421 421
                     unset($contestRankRaw[$key]);
422 422
                 }
423 423
             }
424
-            $contestRank = array_values($contestRankRaw);
425
-            $problemsCount = DB::table('contest_problem')
426
-                ->where('cid',$c['cid'])
424
+            $contestRank=array_values($contestRankRaw);
425
+            $problemsCount=DB::table('contest_problem')
426
+                ->where('cid', $c['cid'])
427 427
                 ->count();
428
-            $index = 1;
429
-            $rank = 1;
430
-            $last_cr = [];
431
-            $last_rank = 1;
428
+            $index=1;
429
+            $rank=1;
430
+            $last_cr=[];
431
+            $last_rank=1;
432 432
             foreach ($contestRank as $cr) {
433
-                $last_rank = $index;
434
-                if(!empty($last_cr)){
435
-                    if($cr['solved'] == $last_cr['solved'] && $cr['penalty'] == $last_cr['penalty'] ){
436
-                        $rank = $last_rank;
437
-                    }else{
438
-                        $rank = $index;
439
-                        $last_rank = $rank;
433
+                $last_rank=$index;
434
+                if (!empty($last_cr)) {
435
+                    if ($cr['solved']==$last_cr['solved'] && $cr['penalty']==$last_cr['penalty']) {
436
+                        $rank=$last_rank;
437
+                    } else {
438
+                        $rank=$index;
439
+                        $last_rank=$rank;
440 440
                     }
441 441
                 }
442
-                if(in_array($cr['uid'],array_keys($memberData))) {
443
-                    $memberData[$cr['uid']]['solved_all'] += $cr['solved'];
444
-                    $memberData[$cr['uid']]['problem_all'] += $problemsCount;
445
-                    $memberData[$cr['uid']]['penalty'] += $cr['penalty'];
446
-                    $memberData[$cr['uid']]['contest_detial'][$c['cid']] = [
442
+                if (in_array($cr['uid'], array_keys($memberData))) {
443
+                    $memberData[$cr['uid']]['solved_all']+=$cr['solved'];
444
+                    $memberData[$cr['uid']]['problem_all']+=$problemsCount;
445
+                    $memberData[$cr['uid']]['penalty']+=$cr['penalty'];
446
+                    $memberData[$cr['uid']]['contest_detial'][$c['cid']]=[
447 447
                         'rank' => $rank,
448 448
                         'solved' => $cr['solved'],
449 449
                         'problems' => $problemsCount,
450 450
                         'penalty' => $cr['penalty']
451 451
                     ];
452 452
                 }
453
-                $last_cr = $cr;
453
+                $last_cr=$cr;
454 454
                 $index++;
455 455
             }
456 456
         }
457
-        $new_memberData = [];
457
+        $new_memberData=[];
458 458
         foreach ($memberData as $uid => $data) {
459
-            $contest_count = 0;
460
-            $rank_sum = 0;
459
+            $contest_count=0;
460
+            $rank_sum=0;
461 461
             foreach ($data['contest_detial'] as $cid => $c) {
462
-                $rank_sum += $c['rank'];
463
-                $contest_count += 1;
462
+                $rank_sum+=$c['rank'];
463
+                $contest_count+=1;
464 464
             }
465
-            $temp = $data;
466
-            $temp['uid'] = $uid;
467
-            if($contest_count != 0){
468
-                $temp['rank_ave'] = $rank_sum/$contest_count;
465
+            $temp=$data;
466
+            $temp['uid']=$uid;
467
+            if ($contest_count!=0) {
468
+                $temp['rank_ave']=$rank_sum / $contest_count;
469 469
             }
470
-            array_push($new_memberData,$temp);
470
+            array_push($new_memberData, $temp);
471 471
         }
472
-        $ret = [
472
+        $ret=[
473 473
             'contest_list' => $allPracticeContest,
474 474
             'member_data' => $new_memberData
475 475
         ];
@@ -478,58 +478,58 @@  discard block
 block discarded – undo
478 478
 
479 479
     public function groupMemberPracticeTagStat($gid)
480 480
     {
481
-        $tags = $this->problemTags($gid);
482
-        $tag_problems = [];
481
+        $tags=$this->problemTags($gid);
482
+        $tag_problems=[];
483 483
 
484
-        $user_list = $this->userList($gid);
484
+        $user_list=$this->userList($gid);
485 485
         foreach ($tags as $tag) {
486
-            $tag_problems[$tag] = DB::table('problem')
487
-                ->join('group_problem_tag','problem.pid','=','group_problem_tag.pid')
486
+            $tag_problems[$tag]=DB::table('problem')
487
+                ->join('group_problem_tag', 'problem.pid', '=', 'group_problem_tag.pid')
488 488
                 ->where([
489 489
                     'group_problem_tag.gid' => $gid,
490 490
                     'tag' => $tag
491 491
                 ])
492
-                ->select('group_problem_tag.pid as pid','pcode','title')
492
+                ->select('group_problem_tag.pid as pid', 'pcode', 'title')
493 493
                 ->get()->all();
494 494
         }
495
-        $all_problems = [];
495
+        $all_problems=[];
496 496
         foreach ($tag_problems as &$tag_problem_set) {
497 497
             foreach ($tag_problem_set as $problem) {
498
-                $all_problems[$problem['pid']] = $problem;
498
+                $all_problems[$problem['pid']]=$problem;
499 499
             }
500
-            $tag_problem_set = array_column($tag_problem_set,'pid');
500
+            $tag_problem_set=array_column($tag_problem_set, 'pid');
501 501
         }
502
-        $submission_data =  DB::table('submission')
503
-            ->whereIn('pid',array_keys($all_problems))
504
-            ->whereIn('uid',array_column($user_list,'uid'))
505
-            ->where('verdict','Accepted')
506
-            ->select('pid','uid')
502
+        $submission_data=DB::table('submission')
503
+            ->whereIn('pid', array_keys($all_problems))
504
+            ->whereIn('uid', array_column($user_list, 'uid'))
505
+            ->where('verdict', 'Accepted')
506
+            ->select('pid', 'uid')
507 507
             ->get()->all();
508 508
 
509
-        $memberData = [];
509
+        $memberData=[];
510 510
         foreach ($user_list as $member) {
511
-            $completion = [];
512
-            foreach($tag_problems as $tag => $problems) {
513
-                $completion[$tag] = [];
511
+            $completion=[];
512
+            foreach ($tag_problems as $tag => $problems) {
513
+                $completion[$tag]=[];
514 514
                 foreach ($problems as $problem) {
515
-                    $is_accepted = 0;
515
+                    $is_accepted=0;
516 516
                     foreach ($submission_data as $sd) {
517
-                        if($sd['pid'] == $problem && $sd['uid'] == $member['uid']){
518
-                            $is_accepted = 1;
517
+                        if ($sd['pid']==$problem && $sd['uid']==$member['uid']) {
518
+                            $is_accepted=1;
519 519
                             break;
520 520
                         }
521 521
                     }
522
-                    $completion[$tag][$problem] = $is_accepted;
522
+                    $completion[$tag][$problem]=$is_accepted;
523 523
                 }
524 524
             }
525
-            array_push($memberData,[
525
+            array_push($memberData, [
526 526
                 'uid' => $member['uid'],
527 527
                 'name' => $member['name'],
528 528
                 'nick_name' => $member['nick_name'],
529 529
                 'completion' => $completion,
530 530
             ]);
531 531
         }
532
-        $ret = [
532
+        $ret=[
533 533
             'all_problems' => $all_problems,
534 534
             'tag_problems' => $tag_problems,
535 535
             'member_data' => $memberData
@@ -539,10 +539,10 @@  discard block
 block discarded – undo
539 539
 
540 540
     public function refreshAllElo()
541 541
     {
542
-        $result = [];
543
-        $gids = DB::table('group')->select('gid','name')->get()->all();
542
+        $result=[];
543
+        $gids=DB::table('group')->select('gid', 'name')->get()->all();
544 544
         foreach ($gids as $gid) {
545
-            $result[$gid['gid']] = [
545
+            $result[$gid['gid']]=[
546 546
                 'name' => $gid['name'],
547 547
                 'result' => $this->refreshElo($gid['gid']),
548 548
             ];
@@ -553,41 +553,41 @@  discard block
 block discarded – undo
553 553
     public function refreshElo($gid)
554 554
     {
555 555
         DB::table('group_rated_change_log')
556
-            ->where('gid',$gid)
556
+            ->where('gid', $gid)
557 557
             ->delete();
558 558
         DB::table('group_member')
559
-            ->where('gid',$gid)
559
+            ->where('gid', $gid)
560 560
             ->update([
561 561
                 'ranking' => 1500
562 562
             ]);
563
-        $contests = DB::table('contest')
563
+        $contests=DB::table('contest')
564 564
             ->where([
565 565
                 'gid' => $gid,
566 566
                 'practice' => 1
567 567
             ])
568
-            ->where('end_time','<',date("Y-m-d H:i:s"))
569
-            ->select('cid','name')
568
+            ->where('end_time', '<', date("Y-m-d H:i:s"))
569
+            ->select('cid', 'name')
570 570
             ->orderBy('end_time')
571 571
             ->get()->all();
572 572
 
573
-        if(empty($contests)) {
573
+        if (empty($contests)) {
574 574
             return [];
575 575
         }
576
-        $result = [];
577
-        $contestModel = new ContestModel();
576
+        $result=[];
577
+        $contestModel=new ContestModel();
578 578
         foreach ($contests as $contest) {
579
-            $judge_status = $contestModel->judgeOver($contest['cid']);
580
-            if($judge_status['result'] == true){
581
-                $calc = new GroupRatingCalculator($contest['cid']);
579
+            $judge_status=$contestModel->judgeOver($contest['cid']);
580
+            if ($judge_status['result']==true) {
581
+                $calc=new GroupRatingCalculator($contest['cid']);
582 582
                 $calc->calculate();
583 583
                 $calc->storage();
584
-                $result[] = [
584
+                $result[]=[
585 585
                     'ret' => 'success',
586 586
                     'cid' => $contest['cid'],
587 587
                     'name' => $contest['name']
588 588
                 ];
589
-            }else{
590
-                $result[] = [
589
+            } else {
590
+                $result[]=[
591 591
                     'ret' => 'judging',
592 592
                     'cid' => $contest['cid'],
593 593
                     'name' => $contest['name'],
@@ -599,21 +599,21 @@  discard block
 block discarded – undo
599 599
         return $result;
600 600
     }
601 601
 
602
-    public function getEloChangeLog($gid,$uid)
602
+    public function getEloChangeLog($gid, $uid)
603 603
     {
604
-        $ret = DB::table('group_rated_change_log')
605
-            ->join('contest','group_rated_change_log.cid','=','contest.cid')
604
+        $ret=DB::table('group_rated_change_log')
605
+            ->join('contest', 'group_rated_change_log.cid', '=', 'contest.cid')
606 606
             ->where([
607 607
                 'group_rated_change_log.gid' => $gid,
608 608
                 'group_rated_change_log.uid' => $uid
609 609
             ])->select('group_rated_change_log.cid as cid', 'contest.name as name', 'ranking', 'end_time')
610 610
             ->orderBy('contest.end_time')
611 611
             ->get()->all();
612
-        $begin = [
612
+        $begin=[
613 613
             'cid' => -1,
614 614
             'name' => '',
615 615
             'ranking' => '1500',
616
-            'end_time' => date("Y-m-d H:i:s",(strtotime($ret[0]['end_time'] ?? time())  - 3600*24)),
616
+            'end_time' => date("Y-m-d H:i:s", (strtotime($ret[0]['end_time'] ?? time())-3600 * 24)),
617 617
         ];
618 618
         array_unshift($ret, $begin);
619 619
         return $ret;
Please login to merge, or discard this patch.