Passed
Push — master ( b831b6...96f132 )
by John
06:04 queued 21s
created
app/Models/GroupModel.php 2 patches
Spacing   +120 added lines, -120 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,
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
     public function judgeEmailClearance($gid, $email)
334 334
     {
335 335
         $user=DB::table("users")->where(["email"=>$email])->first();
336
-        if(empty($user)) return -4;
336
+        if (empty($user)) return -4;
337 337
         $ret=DB::table("group_member")->where([
338 338
             "gid"=>$gid,
339 339
             "uid"=>$user["id"],
@@ -424,20 +424,20 @@  discard block
 block discarded – undo
424 424
 
425 425
     public function groupMemberPracticeContestStat($gid)
426 426
     {
427
-        $contestModel = new ContestModel();
427
+        $contestModel=new ContestModel();
428 428
 
429
-        $allPracticeContest = DB::table('contest')
429
+        $allPracticeContest=DB::table('contest')
430 430
             ->where([
431 431
                 'gid' => $gid,
432 432
                 'practice' => 1,
433 433
             ])
434
-            ->select('cid','name')
434
+            ->select('cid', 'name')
435 435
             ->get()->all();
436
-        $user_list = $this->userList($gid);
436
+        $user_list=$this->userList($gid);
437 437
 
438
-        $memberData = [];
438
+        $memberData=[];
439 439
         foreach ($user_list as $u) {
440
-            $memberData[$u['uid']] = [
440
+            $memberData[$u['uid']]=[
441 441
                 'name' => $u['name'],
442 442
                 'nick_name' => $u['nick_name'],
443 443
                 'elo' => $u['ranking'],
@@ -448,61 +448,61 @@  discard block
 block discarded – undo
448 448
             ];
449 449
         }
450 450
         foreach ($allPracticeContest as $c) {
451
-            $contestRankRaw = $contestModel->contestRank($c['cid']);
452
-            foreach($contestRankRaw as $key => $contestRank){
453
-                if(isset($contestRank['remote']) && $contestRank['remote']){
451
+            $contestRankRaw=$contestModel->contestRank($c['cid']);
452
+            foreach ($contestRankRaw as $key => $contestRank) {
453
+                if (isset($contestRank['remote']) && $contestRank['remote']) {
454 454
                     unset($contestRankRaw[$key]);
455 455
                 }
456 456
             }
457
-            $contestRank = array_values($contestRankRaw);
458
-            $problemsCount = DB::table('contest_problem')
459
-                ->where('cid',$c['cid'])
457
+            $contestRank=array_values($contestRankRaw);
458
+            $problemsCount=DB::table('contest_problem')
459
+                ->where('cid', $c['cid'])
460 460
                 ->count();
461
-            $index = 1;
462
-            $rank = 1;
463
-            $last_cr = [];
464
-            $last_rank = 1;
461
+            $index=1;
462
+            $rank=1;
463
+            $last_cr=[];
464
+            $last_rank=1;
465 465
             foreach ($contestRank as $cr) {
466
-                $last_rank = $index;
467
-                if(!empty($last_cr)){
468
-                    if($cr['solved'] == $last_cr['solved'] && $cr['penalty'] == $last_cr['penalty'] ){
469
-                        $rank = $last_rank;
470
-                    }else{
471
-                        $rank = $index;
472
-                        $last_rank = $rank;
466
+                $last_rank=$index;
467
+                if (!empty($last_cr)) {
468
+                    if ($cr['solved']==$last_cr['solved'] && $cr['penalty']==$last_cr['penalty']) {
469
+                        $rank=$last_rank;
470
+                    } else {
471
+                        $rank=$index;
472
+                        $last_rank=$rank;
473 473
                     }
474 474
                 }
475
-                if(in_array($cr['uid'],array_keys($memberData))) {
476
-                    $memberData[$cr['uid']]['solved_all'] += $cr['solved'];
477
-                    $memberData[$cr['uid']]['problem_all'] += $problemsCount;
478
-                    $memberData[$cr['uid']]['penalty'] += $cr['penalty'];
479
-                    $memberData[$cr['uid']]['contest_detial'][$c['cid']] = [
475
+                if (in_array($cr['uid'], array_keys($memberData))) {
476
+                    $memberData[$cr['uid']]['solved_all']+=$cr['solved'];
477
+                    $memberData[$cr['uid']]['problem_all']+=$problemsCount;
478
+                    $memberData[$cr['uid']]['penalty']+=$cr['penalty'];
479
+                    $memberData[$cr['uid']]['contest_detial'][$c['cid']]=[
480 480
                         'rank' => $rank,
481 481
                         'solved' => $cr['solved'],
482 482
                         'problems' => $problemsCount,
483 483
                         'penalty' => $cr['penalty']
484 484
                     ];
485 485
                 }
486
-                $last_cr = $cr;
486
+                $last_cr=$cr;
487 487
                 $index++;
488 488
             }
489 489
         }
490
-        $new_memberData = [];
490
+        $new_memberData=[];
491 491
         foreach ($memberData as $uid => $data) {
492
-            $contest_count = 0;
493
-            $rank_sum = 0;
492
+            $contest_count=0;
493
+            $rank_sum=0;
494 494
             foreach ($data['contest_detial'] as $cid => $c) {
495
-                $rank_sum += $c['rank'];
496
-                $contest_count += 1;
495
+                $rank_sum+=$c['rank'];
496
+                $contest_count+=1;
497 497
             }
498
-            $temp = $data;
499
-            $temp['uid'] = $uid;
500
-            if($contest_count != 0){
501
-                $temp['rank_ave'] = $rank_sum/$contest_count;
498
+            $temp=$data;
499
+            $temp['uid']=$uid;
500
+            if ($contest_count!=0) {
501
+                $temp['rank_ave']=$rank_sum / $contest_count;
502 502
             }
503
-            array_push($new_memberData,$temp);
503
+            array_push($new_memberData, $temp);
504 504
         }
505
-        $ret = [
505
+        $ret=[
506 506
             'contest_list' => $allPracticeContest,
507 507
             'member_data' => $new_memberData
508 508
         ];
@@ -511,58 +511,58 @@  discard block
 block discarded – undo
511 511
 
512 512
     public function groupMemberPracticeTagStat($gid)
513 513
     {
514
-        $tags = $this->problemTags($gid);
515
-        $tag_problems = [];
514
+        $tags=$this->problemTags($gid);
515
+        $tag_problems=[];
516 516
 
517
-        $user_list = $this->userList($gid);
517
+        $user_list=$this->userList($gid);
518 518
         foreach ($tags as $tag) {
519
-            $tag_problems[$tag] = DB::table('problem')
520
-                ->join('group_problem_tag','problem.pid','=','group_problem_tag.pid')
519
+            $tag_problems[$tag]=DB::table('problem')
520
+                ->join('group_problem_tag', 'problem.pid', '=', 'group_problem_tag.pid')
521 521
                 ->where([
522 522
                     'group_problem_tag.gid' => $gid,
523 523
                     'tag' => $tag
524 524
                 ])
525
-                ->select('group_problem_tag.pid as pid','pcode','title')
525
+                ->select('group_problem_tag.pid as pid', 'pcode', 'title')
526 526
                 ->get()->all();
527 527
         }
528
-        $all_problems = [];
528
+        $all_problems=[];
529 529
         foreach ($tag_problems as &$tag_problem_set) {
530 530
             foreach ($tag_problem_set as $problem) {
531
-                $all_problems[$problem['pid']] = $problem;
531
+                $all_problems[$problem['pid']]=$problem;
532 532
             }
533
-            $tag_problem_set = array_column($tag_problem_set,'pid');
533
+            $tag_problem_set=array_column($tag_problem_set, 'pid');
534 534
         }
535
-        $submission_data =  DB::table('submission')
536
-            ->whereIn('pid',array_keys($all_problems))
537
-            ->whereIn('uid',array_column($user_list,'uid'))
538
-            ->where('verdict','Accepted')
539
-            ->select('pid','uid')
535
+        $submission_data=DB::table('submission')
536
+            ->whereIn('pid', array_keys($all_problems))
537
+            ->whereIn('uid', array_column($user_list, 'uid'))
538
+            ->where('verdict', 'Accepted')
539
+            ->select('pid', 'uid')
540 540
             ->get()->all();
541 541
 
542
-        $memberData = [];
542
+        $memberData=[];
543 543
         foreach ($user_list as $member) {
544
-            $completion = [];
545
-            foreach($tag_problems as $tag => $problems) {
546
-                $completion[$tag] = [];
544
+            $completion=[];
545
+            foreach ($tag_problems as $tag => $problems) {
546
+                $completion[$tag]=[];
547 547
                 foreach ($problems as $problem) {
548
-                    $is_accepted = 0;
548
+                    $is_accepted=0;
549 549
                     foreach ($submission_data as $sd) {
550
-                        if($sd['pid'] == $problem && $sd['uid'] == $member['uid']){
551
-                            $is_accepted = 1;
550
+                        if ($sd['pid']==$problem && $sd['uid']==$member['uid']) {
551
+                            $is_accepted=1;
552 552
                             break;
553 553
                         }
554 554
                     }
555
-                    $completion[$tag][$problem] = $is_accepted;
555
+                    $completion[$tag][$problem]=$is_accepted;
556 556
                 }
557 557
             }
558
-            array_push($memberData,[
558
+            array_push($memberData, [
559 559
                 'uid' => $member['uid'],
560 560
                 'name' => $member['name'],
561 561
                 'nick_name' => $member['nick_name'],
562 562
                 'completion' => $completion,
563 563
             ]);
564 564
         }
565
-        $ret = [
565
+        $ret=[
566 566
             'all_problems' => $all_problems,
567 567
             'tag_problems' => $tag_problems,
568 568
             'member_data' => $memberData
@@ -572,10 +572,10 @@  discard block
 block discarded – undo
572 572
 
573 573
     public function refreshAllElo()
574 574
     {
575
-        $result = [];
576
-        $gids = DB::table('group')->select('gid','name')->get()->all();
575
+        $result=[];
576
+        $gids=DB::table('group')->select('gid', 'name')->get()->all();
577 577
         foreach ($gids as $gid) {
578
-            $result[$gid['gid']] = [
578
+            $result[$gid['gid']]=[
579 579
                 'name' => $gid['name'],
580 580
                 'result' => $this->refreshElo($gid['gid']),
581 581
             ];
@@ -586,41 +586,41 @@  discard block
 block discarded – undo
586 586
     public function refreshElo($gid)
587 587
     {
588 588
         DB::table('group_rated_change_log')
589
-            ->where('gid',$gid)
589
+            ->where('gid', $gid)
590 590
             ->delete();
591 591
         DB::table('group_member')
592
-            ->where('gid',$gid)
592
+            ->where('gid', $gid)
593 593
             ->update([
594 594
                 'ranking' => 1500
595 595
             ]);
596
-        $contests = DB::table('contest')
596
+        $contests=DB::table('contest')
597 597
             ->where([
598 598
                 'gid' => $gid,
599 599
                 'practice' => 1
600 600
             ])
601
-            ->where('end_time','<',date("Y-m-d H:i:s"))
602
-            ->select('cid','name')
601
+            ->where('end_time', '<', date("Y-m-d H:i:s"))
602
+            ->select('cid', 'name')
603 603
             ->orderBy('end_time')
604 604
             ->get()->all();
605 605
 
606
-        if(empty($contests)) {
606
+        if (empty($contests)) {
607 607
             return [];
608 608
         }
609
-        $result = [];
610
-        $contestModel = new ContestModel();
609
+        $result=[];
610
+        $contestModel=new ContestModel();
611 611
         foreach ($contests as $contest) {
612
-            $judge_status = $contestModel->judgeOver($contest['cid']);
613
-            if($judge_status['result'] == true){
614
-                $calc = new GroupRatingCalculator($contest['cid']);
612
+            $judge_status=$contestModel->judgeOver($contest['cid']);
613
+            if ($judge_status['result']==true) {
614
+                $calc=new GroupRatingCalculator($contest['cid']);
615 615
                 $calc->calculate();
616 616
                 $calc->storage();
617
-                $result[] = [
617
+                $result[]=[
618 618
                     'ret' => 'success',
619 619
                     'cid' => $contest['cid'],
620 620
                     'name' => $contest['name']
621 621
                 ];
622
-            }else{
623
-                $result[] = [
622
+            } else {
623
+                $result[]=[
624 624
                     'ret' => 'judging',
625 625
                     'cid' => $contest['cid'],
626 626
                     'name' => $contest['name'],
@@ -632,23 +632,23 @@  discard block
 block discarded – undo
632 632
         return $result;
633 633
     }
634 634
 
635
-    public function getEloChangeLog($gid,$uid)
635
+    public function getEloChangeLog($gid, $uid)
636 636
     {
637
-        $ret = DB::table('group_rated_change_log')
638
-            ->join('contest','group_rated_change_log.cid','=','contest.cid')
637
+        $ret=DB::table('group_rated_change_log')
638
+            ->join('contest', 'group_rated_change_log.cid', '=', 'contest.cid')
639 639
             ->where([
640 640
                 'group_rated_change_log.gid' => $gid,
641 641
                 'group_rated_change_log.uid' => $uid
642 642
             ])->select('group_rated_change_log.cid as cid', 'contest.name as name', 'ranking', 'end_time')
643 643
             ->orderBy('contest.end_time')
644 644
             ->get()->all();
645
-            $begin = [
645
+            $begin=[
646 646
                 'cid' => -1,
647 647
                 'name' => '',
648 648
                 'ranking' => '1500',
649
-                'end_time' => date("Y-m-d H:i:s",(strtotime($ret[0]['end_time'] ?? time())  - 3600*24)),
649
+                'end_time' => date("Y-m-d H:i:s", (strtotime($ret[0]['end_time'] ?? time())-3600 * 24)),
650 650
             ];
651
-            $ret = array_prepend($ret,$begin);
651
+            $ret=array_prepend($ret, $begin);
652 652
         return $ret;
653 653
     }
654 654
 }
Please login to merge, or discard this patch.
Braces   +13 added lines, -7 removed lines patch added patch discarded remove patch
@@ -121,7 +121,9 @@  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)) {
125
+            return [];
126
+        }
125 127
         $basic_info["members"]=$this->countGroupMembers($basic_info["gid"]);
126 128
         $basic_info["tags"]=$this->getGroupTags($basic_info["gid"]);
127 129
         $basic_info["create_time_foramt"]=date_format(date_create($basic_info["created_at"]), 'M jS, Y');
@@ -169,7 +171,9 @@  discard block
 block discarded – undo
169 171
         foreach ($user_list as &$u) {
170 172
             $u["role_parsed"]=$this->role[$u["role"]];
171 173
             $u["role_color"]=$this->role_color[$u["role"]];
172
-            if(is_null($u["sub_group"])) $u["sub_group"]="None";
174
+            if(is_null($u["sub_group"])) {
175
+                $u["sub_group"]="None";
176
+            }
173 177
         }
174 178
         return $user_list;
175 179
     }
@@ -238,7 +242,7 @@  discard block
 block discarded – undo
238 242
             ->where('gid',$gid)
239 243
             ->distinct()
240 244
             ->get()->all();
241
-        }else{
245
+        } else{
242 246
             $tags =  DB::table('group_problem_tag')
243 247
             ->select('tag')
244 248
             ->where('gid', $gid)
@@ -272,7 +276,7 @@  discard block
 block discarded – undo
272 276
         foreach($problems as $key => $value){
273 277
             if($contestModel->judgeClearance($value['cid'],$user_id) != 3){
274 278
                 unset($problems[$key]);
275
-            }else{
279
+            } else{
276 280
                 $problems[$key]['tags'] = $this->problemTags($gid,$value['pid']);
277 281
             }
278 282
         }
@@ -333,7 +337,9 @@  discard block
 block discarded – undo
333 337
     public function judgeEmailClearance($gid, $email)
334 338
     {
335 339
         $user=DB::table("users")->where(["email"=>$email])->first();
336
-        if(empty($user)) return -4;
340
+        if(empty($user)) {
341
+            return -4;
342
+        }
337 343
         $ret=DB::table("group_member")->where([
338 344
             "gid"=>$gid,
339 345
             "uid"=>$user["id"],
@@ -467,7 +473,7 @@  discard block
 block discarded – undo
467 473
                 if(!empty($last_cr)){
468 474
                     if($cr['solved'] == $last_cr['solved'] && $cr['penalty'] == $last_cr['penalty'] ){
469 475
                         $rank = $last_rank;
470
-                    }else{
476
+                    } else{
471 477
                         $rank = $index;
472 478
                         $last_rank = $rank;
473 479
                     }
@@ -619,7 +625,7 @@  discard block
 block discarded – undo
619 625
                     'cid' => $contest['cid'],
620 626
                     'name' => $contest['name']
621 627
                 ];
622
-            }else{
628
+            } else{
623 629
                 $result[] = [
624 630
                     'ret' => 'judging',
625 631
                     'cid' => $contest['cid'],
Please login to merge, or discard this patch.
app/Models/ResponseModel.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@
 block discarded – undo
96 96
             '7002' => "Insufficient Clearance",
97 97
             '7003' => "No Need to Approve",
98 98
             '7004' => "Group Member Not Found",
99
-            '7005' => "Don't play just for fun",//gcode=="create"
99
+            '7005' => "Don't play just for fun", //gcode=="create"
100 100
             '7006' => "A group with the same gcode already exists",
101 101
             '7007' => "Group Problem Tag Exist",
102 102
             '7008' => "The group leader cannot leave the group",
Please login to merge, or discard this patch.
app/Models/Eloquent/Message.php 2 patches
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -17,78 +17,78 @@  discard block
 block discarded – undo
17 17
      */
18 18
     public static function send($config)
19 19
     {
20
-        if(!empty($config['type'])){
21
-            if($config['type'] == 1) { //to a leader that member apply to join the group
22
-                $messages = Message::where([
20
+        if (!empty($config['type'])) {
21
+            if ($config['type']==1) { //to a leader that member apply to join the group
22
+                $messages=Message::where([
23 23
                     'receiver' => $config['receiver'],
24 24
                     'type'     => $config['type'],
25 25
                     'unread'   => 1
26 26
                 ])->get();
27
-                if(!empty($messages)) {
28
-                    foreach($messages as $message) {
29
-                        $data = json_decode($message->data,true);
30
-                        if($data['group']['gcode'] == $config['data']['group']['gcode']) {
31
-                            array_push($data['user'],$config['data']['user'][0]);
32
-                            $message->data = json_encode($data);
27
+                if (!empty($messages)) {
28
+                    foreach ($messages as $message) {
29
+                        $data=json_decode($message->data, true);
30
+                        if ($data['group']['gcode']==$config['data']['group']['gcode']) {
31
+                            array_push($data['user'], $config['data']['user'][0]);
32
+                            $message->data=json_encode($data);
33 33
                             $message->save();
34 34
                             return true;
35 35
                         }
36 36
                     }
37 37
                 }
38
-            }elseif ($config['type'] == 2) { //to a leader that member agree to join the group
39
-                $messages = Message::where([
38
+            }elseif ($config['type']==2) { //to a leader that member agree to join the group
39
+                $messages=Message::where([
40 40
                     'receiver' => $config['receiver'],
41 41
                     'type'     => $config['type'],
42 42
                     'unread'   => 1
43 43
                 ])->get();
44
-                if(!empty($messages)) {
45
-                    foreach($messages as $message) {
46
-                        $data = json_decode($message->data,true);
47
-                        if($data['group'] == $config['data']['group']) {
48
-                            array_push($data['user'],$config['data']['user'][0]);
49
-                            $message->data = json_encode($data);
44
+                if (!empty($messages)) {
45
+                    foreach ($messages as $message) {
46
+                        $data=json_decode($message->data, true);
47
+                        if ($data['group']==$config['data']['group']) {
48
+                            array_push($data['user'], $config['data']['user'][0]);
49
+                            $message->data=json_encode($data);
50 50
                             $message->save();
51 51
                             return true;
52 52
                         }
53 53
                     }
54 54
                 }
55
-            }elseif ($config['type'] == 3) { //to a person that solution was passed
56
-                $message = Message::where([
55
+            }elseif ($config['type']==3) { //to a person that solution was passed
56
+                $message=Message::where([
57 57
                     'receiver' => $config['receiver'],
58 58
                     'type'     => $config['type'],
59 59
                     'unread'   => 1
60 60
                 ])->first();
61
-                if(!empty($message)) {
62
-                    $data = json_decode($message->data,true);
63
-                    array_push($data,$config['data']);
64
-                    $message->data = json_encode($data);
61
+                if (!empty($message)) {
62
+                    $data=json_decode($message->data, true);
63
+                    array_push($data, $config['data']);
64
+                    $message->data=json_encode($data);
65 65
                     $message->save();
66 66
                     return true;
67 67
                 }
68
-            }elseif ($config['type'] == 4) { //to a person that solution was blocked
69
-                $message = Message::where([
68
+            }elseif ($config['type']==4) { //to a person that solution was blocked
69
+                $message=Message::where([
70 70
                     'receiver' => $config['receiver'],
71 71
                     'type'     => $config['type'],
72 72
                     'unread'   => 1
73 73
                 ])->first();
74
-                if(!empty($message)) {
75
-                    $data = json_decode($message->data,true);
76
-                    array_push($data,$config['data']);
77
-                    $message->data = json_encode($data);
74
+                if (!empty($message)) {
75
+                    $data=json_decode($message->data, true);
76
+                    array_push($data, $config['data']);
77
+                    $message->data=json_encode($data);
78 78
                     $message->save();
79 79
                     return true;
80 80
                 }
81 81
             }
82 82
         }
83
-        $message = new Message;
84
-        $message->sender = $config['sender'];
85
-        $message->receiver = $config['receiver'];
86
-        $message->title = $config['title'];
87
-        if(isset($config['data']) && isset($config['type'])){
88
-            $message->type = $config['type'] ?? null;
89
-            $message->data = json_encode($config['data']);
90
-        }else{
91
-            $message->content = $config['content'];
83
+        $message=new Message;
84
+        $message->sender=$config['sender'];
85
+        $message->receiver=$config['receiver'];
86
+        $message->title=$config['title'];
87
+        if (isset($config['data']) && isset($config['type'])) {
88
+            $message->type=$config['type'] ?? null;
89
+            $message->data=json_encode($config['data']);
90
+        } else {
91
+            $message->content=$config['content'];
92 92
         }
93 93
         /*
94 94
         if(isset($config['reply'])){
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
             $message->reply = $config['allow_reply'];
99 99
         }
100 100
         */
101
-        $message->official = 1;
101
+        $message->official=1;
102 102
         $message->save();
103 103
         return true;
104 104
     }
@@ -132,9 +132,9 @@  discard block
 block discarded – undo
132 132
     {
133 133
 
134 134
         return static::with('sender_user')
135
-            ->where('receiver',$uid)
136
-            ->orderBy('unread','desc')
137
-            ->orderBy('updated_at','desc')
135
+            ->where('receiver', $uid)
136
+            ->orderBy('unread', 'desc')
137
+            ->orderBy('updated_at', 'desc')
138 138
             ->paginate(15);
139 139
     }
140 140
 
@@ -147,9 +147,9 @@  discard block
 block discarded – undo
147 147
      */
148 148
     public static function read($mid)
149 149
     {
150
-        $message = static::with('sender_user')->find($mid);
151
-        if(!empty($message)){
152
-            $message->unread = 0;
150
+        $message=static::with('sender_user')->find($mid);
151
+        if (!empty($message)) {
152
+            $message->unread=0;
153 153
             $message->save();
154 154
         }
155 155
         return $message;
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
      */
165 165
     public static function allRead($uid)
166 166
     {
167
-        return static::where('receiver',$uid)
167
+        return static::where('receiver', $uid)
168 168
             ->update(['unread' => 0]);
169 169
     }
170 170
 
@@ -192,20 +192,20 @@  discard block
 block discarded – undo
192 192
      */
193 193
     public static function remove($messages)
194 194
     {
195
-        $del_count = 0;
196
-        if(is_array($messages)){
195
+        $del_count=0;
196
+        if (is_array($messages)) {
197 197
             foreach ($messages as $mid) {
198
-                $message = static::find($mid);
199
-                if(!empty($message)){
198
+                $message=static::find($mid);
199
+                if (!empty($message)) {
200 200
                     $message->delete();
201
-                    $del_count ++;
201
+                    $del_count++;
202 202
                 }
203 203
             }
204
-        }else{
205
-            $message = static::find($messages);
206
-            if(!empty($message)){
204
+        } else {
205
+            $message=static::find($messages);
206
+            if (!empty($message)) {
207 207
                 $message->delete();
208
-                $del_count ++;
208
+                $del_count++;
209 209
             }
210 210
         }
211 211
         return $del_count;
@@ -213,36 +213,36 @@  discard block
 block discarded – undo
213 213
 
214 214
     public function getContentAttribute($value)
215 215
     {
216
-        if(!empty($this->type)){
217
-            $data = json_decode($this->data,true);
218
-            $content = '';
219
-            if($this->type == 1) {
220
-                foreach($data['user'] as $user) {
221
-                    $content .= "[{$user['name']}]({$user['url']}), ";
216
+        if (!empty($this->type)) {
217
+            $data=json_decode($this->data, true);
218
+            $content='';
219
+            if ($this->type==1) {
220
+                foreach ($data['user'] as $user) {
221
+                    $content.="[{$user['name']}]({$user['url']}), ";
222 222
                 }
223
-                $content = substr($content,0,strlen($content)-2);
224
-                $content .= " want to join your group [{$data['group']['name']}]({$data['group']['url']})";
223
+                $content=substr($content, 0, strlen($content)-2);
224
+                $content.=" want to join your group [{$data['group']['name']}]({$data['group']['url']})";
225 225
                 return $content;
226
-            }elseif($this->type == 2) {
227
-                foreach($data['user'] as $user) {
228
-                    $content .= "[{$user['name']}]({$user['url']}), ";
226
+            }elseif ($this->type==2) {
227
+                foreach ($data['user'] as $user) {
228
+                    $content.="[{$user['name']}]({$user['url']}), ";
229 229
                 }
230
-                $content = substr($content,0,strlen($content)-2);
231
-                $content .= " have agreed to join your group [{$data['group']['name']}]({$data['group']['url']})";
230
+                $content=substr($content, 0, strlen($content)-2);
231
+                $content.=" have agreed to join your group [{$data['group']['name']}]({$data['group']['url']})";
232 232
                 return $content;
233 233
             } //todo
234
-        }else{
234
+        } else {
235 235
             return $value;
236 236
         }
237 237
     }
238 238
 
239 239
     public function sender_user()
240 240
     {
241
-        return $this->belongsTo('App\Models\Eloquent\UserModel','sender','id');
241
+        return $this->belongsTo('App\Models\Eloquent\UserModel', 'sender', 'id');
242 242
     }
243 243
 
244 244
     public function receiver_user()
245 245
     {
246
-        return $this->belongsTo('App\Models\Eloquent\UserModel','receiver','id');
246
+        return $this->belongsTo('App\Models\Eloquent\UserModel', 'receiver', 'id');
247 247
     }
248 248
 }
Please login to merge, or discard this patch.
Braces   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
                         }
36 36
                     }
37 37
                 }
38
-            }elseif ($config['type'] == 2) { //to a leader that member agree to join the group
38
+            } elseif ($config['type'] == 2) { //to a leader that member agree to join the group
39 39
                 $messages = Message::where([
40 40
                     'receiver' => $config['receiver'],
41 41
                     'type'     => $config['type'],
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
                         }
53 53
                     }
54 54
                 }
55
-            }elseif ($config['type'] == 3) { //to a person that solution was passed
55
+            } elseif ($config['type'] == 3) { //to a person that solution was passed
56 56
                 $message = Message::where([
57 57
                     'receiver' => $config['receiver'],
58 58
                     'type'     => $config['type'],
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
                     $message->save();
66 66
                     return true;
67 67
                 }
68
-            }elseif ($config['type'] == 4) { //to a person that solution was blocked
68
+            } elseif ($config['type'] == 4) { //to a person that solution was blocked
69 69
                 $message = Message::where([
70 70
                     'receiver' => $config['receiver'],
71 71
                     'type'     => $config['type'],
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
         if(isset($config['data']) && isset($config['type'])){
88 88
             $message->type = $config['type'] ?? null;
89 89
             $message->data = json_encode($config['data']);
90
-        }else{
90
+        } else{
91 91
             $message->content = $config['content'];
92 92
         }
93 93
         /*
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
                     $del_count ++;
202 202
                 }
203 203
             }
204
-        }else{
204
+        } else{
205 205
             $message = static::find($messages);
206 206
             if(!empty($message)){
207 207
                 $message->delete();
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
                 $content = substr($content,0,strlen($content)-2);
224 224
                 $content .= " want to join your group [{$data['group']['name']}]({$data['group']['url']})";
225 225
                 return $content;
226
-            }elseif($this->type == 2) {
226
+            } elseif($this->type == 2) {
227 227
                 foreach($data['user'] as $user) {
228 228
                     $content .= "[{$user['name']}]({$user['url']}), ";
229 229
                 }
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
                 $content .= " have agreed to join your group [{$data['group']['name']}]({$data['group']['url']})";
232 232
                 return $content;
233 233
             } //todo
234
-        }else{
234
+        } else{
235 235
             return $value;
236 236
         }
237 237
     }
Please login to merge, or discard this patch.
app/Models/Eloquent/GroupMember.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,10 +13,10 @@
 block discarded – undo
13 13
     protected $primaryKey='gmid';
14 14
 
15 15
     public function user() {
16
-        return $this->belongsTo('App\Models\Eloquent\UserModel','uid','id');
16
+        return $this->belongsTo('App\Models\Eloquent\UserModel', 'uid', 'id');
17 17
     }
18 18
 
19 19
     public function group() {
20
-        return $this->belongsTo('App\Models\Eloquent\Group','gid','gid');
20
+        return $this->belongsTo('App\Models\Eloquent\Group', 'gid', 'gid');
21 21
     }
22 22
 }
Please login to merge, or discard this patch.
app/Models/Eloquent/GroupBanned.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -9,13 +9,13 @@
 block discarded – undo
9 9
 {
10 10
     use SoftDeletes;
11 11
 
12
-    protected $fillable = ['group_id', 'abuse_id', 'reason', 'removed_at'];
12
+    protected $fillable=['group_id', 'abuse_id', 'reason', 'removed_at'];
13 13
 
14 14
     public function abuse() {
15 15
         return $this->belongsTo('\App\Models\Eloquent\Abuse');
16 16
     }
17 17
 
18 18
     public function group() {
19
-        return $this->belongsTo('\App\Models\Eloquent\Group',null,'gid');
19
+        return $this->belongsTo('\App\Models\Eloquent\Group', null, 'gid');
20 20
     }
21 21
 }
Please login to merge, or discard this patch.
app/Models/Eloquent/Dojo/Dojo.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
     public function canPass()
28 28
     {
29 29
         $tot=0;
30
-        foreach($this->problems->sortBy('order') as $problem){
30
+        foreach ($this->problems->sortBy('order') as $problem) {
31 31
             $problem=$problem->problem;
32 32
             $tot+=$problem->problem_status['color']=='wemd-green-text';
33 33
         }
@@ -41,11 +41,11 @@  discard block
 block discarded – undo
41 41
 
42 42
     public function getAvailabilityAttribute()
43 43
     {
44
-        foreach(explode(',', $this->precondition) as $dojo_id){
45
-            if(blank($dojo_id)) continue;
46
-            if(!DojoPass::isPassed($dojo_id)) return 'locked';
44
+        foreach (explode(',', $this->precondition) as $dojo_id) {
45
+            if (blank($dojo_id)) continue;
46
+            if (!DojoPass::isPassed($dojo_id)) return 'locked';
47 47
         }
48
-        return $this->passed?'passed':'available';
48
+        return $this->passed ? 'passed' : 'available';
49 49
     }
50 50
 
51 51
 }
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -42,8 +42,12 @@
 block discarded – undo
42 42
     public function getAvailabilityAttribute()
43 43
     {
44 44
         foreach(explode(',', $this->precondition) as $dojo_id){
45
-            if(blank($dojo_id)) continue;
46
-            if(!DojoPass::isPassed($dojo_id)) return 'locked';
45
+            if(blank($dojo_id)) {
46
+                continue;
47
+            }
48
+            if(!DojoPass::isPassed($dojo_id)) {
49
+                return 'locked';
50
+            }
47 51
         }
48 52
         return $this->passed?'passed':'available';
49 53
     }
Please login to merge, or discard this patch.
app/Models/Eloquent/Dojo/DojoPass.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -26,9 +26,9 @@
 block discarded – undo
26 26
 
27 27
     public static function isPassed($dojo_id)
28 28
     {
29
-        return Auth::check()?self::where([
29
+        return Auth::check() ?self::where([
30 30
             "dojo_id"=>$dojo_id,
31 31
             "user_id"=>Auth::user()->id,
32
-        ])->count()>0:false;
32
+        ])->count()>0 : false;
33 33
     }
34 34
 }
Please login to merge, or discard this patch.
app/Models/Eloquent/Group.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 
11 11
     public function members()
12 12
     {
13
-        return $this->hasMany('App\Models\Eloquent\GroupMember', 'gid','gid');
13
+        return $this->hasMany('App\Models\Eloquent\GroupMember', 'gid', 'gid');
14 14
     }
15 15
 
16 16
     public function banneds()
@@ -20,11 +20,11 @@  discard block
 block discarded – undo
20 20
 
21 21
     public function getLeaderAttribute()
22 22
     {
23
-        return $this->members()->where('role',3)->first()->user;
23
+        return $this->members()->where('role', 3)->first()->user;
24 24
     }
25 25
 
26 26
     public function getLinkAttribute()
27 27
     {
28
-        return route('group.detail',['gcode' => $this->gcode]);
28
+        return route('group.detail', ['gcode' => $this->gcode]);
29 29
     }
30 30
 }
Please login to merge, or discard this patch.
app/Models/Eloquent/ContestModel.php 1 patch
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -18,28 +18,28 @@  discard block
 block discarded – undo
18 18
     const CREATED_AT=null;
19 19
 
20 20
     //Repository function
21
-    public function participants($ignore_frozen = true)
21
+    public function participants($ignore_frozen=true)
22 22
     {
23
-        if($this->registration){
24
-            $participants = ContestParticipant::where('cid',$this->cid)->get();
23
+        if ($this->registration) {
24
+            $participants=ContestParticipant::where('cid', $this->cid)->get();
25 25
             $participants->load('user');
26
-            $users = new EloquentCollection;
26
+            $users=new EloquentCollection;
27 27
             foreach ($participants as $participant) {
28
-                $user = $participant->user;
28
+                $user=$participant->user;
29 29
                 $users->add($user);
30 30
             }
31 31
             return $users->unique();
32
-        }else{
32
+        } else {
33 33
             $this->load('submissions.user');
34
-            if($ignore_frozen){
35
-                $frozen_time = $this->frozen_time;
36
-                $submissions = $this->submissions()->where('submission_date','<',$frozen_time)->get();
37
-            }else{
38
-                $submissions = $this->submissions;
34
+            if ($ignore_frozen) {
35
+                $frozen_time=$this->frozen_time;
36
+                $submissions=$this->submissions()->where('submission_date', '<', $frozen_time)->get();
37
+            } else {
38
+                $submissions=$this->submissions;
39 39
             }
40
-            $users = new EloquentCollection;
40
+            $users=new EloquentCollection;
41 41
             foreach ($submissions as $submission) {
42
-                $user = $submission->user;
42
+                $user=$submission->user;
43 43
                 $users->add($user);
44 44
             }
45 45
             return $users->unique();
@@ -49,18 +49,18 @@  discard block
 block discarded – undo
49 49
     // Repository/Service? function
50 50
     public function rankRefresh()
51 51
     {
52
-        $ret = [];
53
-        $participants = $this->participants();
54
-        $contest_problems = $this->problems;
52
+        $ret=[];
53
+        $participants=$this->participants();
54
+        $contest_problems=$this->problems;
55 55
         $contest_problems->load('problem');
56
-        if($this->rule == 1){
56
+        if ($this->rule==1) {
57 57
             // ACM/ICPC Mode
58 58
             foreach ($participants as $participant) {
59 59
                 $prob_detail=[];
60 60
                 $totPen=0;
61 61
                 $totScore=0;
62 62
                 foreach ($contest_problems as $contest_problem) {
63
-                    $prob_stat = $contest_problem->userStatus($participant);
63
+                    $prob_stat=$contest_problem->userStatus($participant);
64 64
                     $prob_detail[]=[
65 65
                         'ncode'=>$contest_problem->ncode,
66 66
                         'pid'=>$contest_problem->pid,
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
                     "problem_detail" => $prob_detail
87 87
                 ];
88 88
             }
89
-            usort($ret, function ($a, $b) {
89
+            usort($ret, function($a, $b) {
90 90
                 if ($a["score"]==$b["score"]) {
91 91
                     if ($a["penalty"]==$b["penalty"]) {
92 92
                         return 0;
@@ -103,43 +103,43 @@  discard block
 block discarded – undo
103 103
             });
104 104
             Cache::tags(['contest', 'rank'])->put($this->cid, $ret, 60);
105 105
             return $ret;
106
-        }else{
106
+        } else {
107 107
             // IO Mode
108
-            $c = new OutdatedContestModel();
108
+            $c=new OutdatedContestModel();
109 109
             return $c->contestRankCache($this->cid);
110 110
         }
111 111
     }
112 112
 
113 113
     public function problems()
114 114
     {
115
-        return $this->hasMany('App\Models\Eloquent\ContestProblem','cid','cid');
115
+        return $this->hasMany('App\Models\Eloquent\ContestProblem', 'cid', 'cid');
116 116
     }
117 117
 
118 118
     public function submissions()
119 119
     {
120
-        return $this->hasMany('App\Models\Eloquent\SubmissionModel','cid','cid');
120
+        return $this->hasMany('App\Models\Eloquent\SubmissionModel', 'cid', 'cid');
121 121
     }
122 122
 
123 123
     public function group()
124 124
     {
125
-        return $this->hasOne('App\Models\Eloquent\Group','gid','gid');
125
+        return $this->hasOne('App\Models\Eloquent\Group', 'gid', 'gid');
126 126
     }
127 127
 
128 128
     public function getFrozenTimeAttribute()
129 129
     {
130
-        $end_time = strtotime($this->end_time);
131
-        return $end_time - $this->froze_length;
130
+        $end_time=strtotime($this->end_time);
131
+        return $end_time-$this->froze_length;
132 132
     }
133 133
 
134 134
     public static function getProblemSet($cid, $renderLatex=false)
135 135
     {
136 136
         $ret=[];
137
-        $problemset=ContestProblemModel::where('cid', $cid)->orderBy('number','asc')->get();
138
-        foreach($problemset as $problem){
137
+        $problemset=ContestProblemModel::where('cid', $cid)->orderBy('number', 'asc')->get();
138
+        foreach ($problemset as $problem) {
139 139
             $problemDetail=ProblemModel::find($problem->pid);
140 140
             $problemRet=(new OutdatedProblemModel())->detail($problemDetail->pcode);
141
-            if ($renderLatex){
142
-                foreach (['description','input','output','note'] as $section){
141
+            if ($renderLatex) {
142
+                foreach (['description', 'input', 'output', 'note'] as $section) {
143 143
                     $problemRet['parsed'][$section]=latex2Image($problemRet['parsed'][$section]);
144 144
                 }
145 145
             }
@@ -153,6 +153,6 @@  discard block
 block discarded – undo
153 153
 
154 154
     public function isJudgingComplete()
155 155
     {
156
-        return $this->submissions->whereIn('verdict',['Waiting','Pending'])->count()==0;
156
+        return $this->submissions->whereIn('verdict', ['Waiting', 'Pending'])->count()==0;
157 157
     }
158 158
 }
Please login to merge, or discard this patch.