Passed
Pull Request — master (#583)
by
unknown
10:53
created
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.
app/Http/Controllers/Auth/VerificationController.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@
 block discarded – undo
44 44
     {
45 45
         return $request->user()->hasVerifiedEmail()
46 46
                         ? redirect($this->redirectPath())
47
-                        : view('auth.verify',[
47
+                        : view('auth.verify', [
48 48
                             'page_title'=>"Verify Email",
49 49
                             'site_title'=>config("app.name"),
50 50
                             'navigation' => "Account"
Please login to merge, or discard this patch.
app/Admin/Controllers/ProblemController.php 1 patch
Spacing   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -143,11 +143,11 @@  discard block
 block discarded – undo
143 143
      *
144 144
      * @return Form
145 145
      */
146
-    protected function form($create = false)
146
+    protected function form($create=false)
147 147
     {
148 148
         $form=new Form(new EloquentProblemModel);
149 149
         $form->model()->makeVisible('password');
150
-        $form->tab('Basic', function(Form $form){
150
+        $form->tab('Basic', function(Form $form) {
151 151
             $form->text('pid')->readonly();
152 152
             $form->text('pcode')->rules('required');
153 153
             $form->text('title')->rules('required');
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
             $form->simplemde('input');
158 158
             $form->simplemde('output');
159 159
             $form->simplemde('note');
160
-            $form->hasMany('problemSamples', 'samples', function (Form\NestedForm $form) {
160
+            $form->hasMany('problemSamples', 'samples', function(Form\NestedForm $form) {
161 161
                 $form->textarea('sample_input', 'sample input')->rows(3);
162 162
                 $form->textarea('sample_output', 'sample output')->rows(3);
163 163
                 $form->textarea('sample_note', 'sample note')->rows(3);
@@ -167,10 +167,10 @@  discard block
 block discarded – undo
167 167
                 $table->textarea('sample_output', 'sample output');
168 168
                 $table->textarea('sample_note', 'sample note');
169 169
             }); */
170
-            $ojs_temp = EloquentOJModel::select('oid', 'name')->get()->all();
171
-            $ojs = [];
172
-            foreach($ojs_temp as $v){
173
-                $ojs[$v->oid] = $v->name;
170
+            $ojs_temp=EloquentOJModel::select('oid', 'name')->get()->all();
171
+            $ojs=[];
172
+            foreach ($ojs_temp as $v) {
173
+                $ojs[$v->oid]=$v->name;
174 174
             }
175 175
             $form->select('oj', 'OJ')->options($ojs)->default(1)->rules('required');
176 176
             /* $form->display('update_date'); */
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
                     0 => 'NO',
190 190
                     1 => 'YES',
191 191
                 ])->default(0)->rules('required');
192
-            $form->clang('spj_src','SPJ Source Code');
192
+            $form->clang('spj_src', 'SPJ Source Code');
193 193
             $form->file('test_case')->rules('required');
194 194
             $form->ignore(['test_case']);
195 195
 
@@ -211,125 +211,125 @@  discard block
 block discarded – undo
211 211
                 $tools->append('<a href="/'.config('admin.route.prefix').'/problems/import" class="btn btn-sm btn-success" style="margin-right:1rem"><i class="MDI file-powerpoint-box"></i>&nbsp;&nbsp;Import from file</a>');
212 212
             });
213 213
         } */
214
-        $form->saving(function (Form $form){
215
-            $err = function ($msg, $title = 'Test case file parse faild.') {
216
-                $error = new MessageBag([
214
+        $form->saving(function(Form $form) {
215
+            $err=function($msg, $title='Test case file parse faild.') {
216
+                $error=new MessageBag([
217 217
                     'title'   => $title,
218 218
                     'message' => $msg,
219 219
                 ]);
220 220
                 return back()->with(compact('error'));
221 221
             };
222
-            $pcode = $form->pcode;
223
-            $p = EloquentProblemModel::where('pcode',$pcode)->first();
222
+            $pcode=$form->pcode;
223
+            $p=EloquentProblemModel::where('pcode', $pcode)->first();
224 224
             //check pcode has been token.
225
-            $pid = $form->pid ?? null;
226
-            if(!empty($p) && $p->pid != $pid){
225
+            $pid=$form->pid ?? null;
226
+            if (!empty($p) && $p->pid!=$pid) {
227 227
                 $err('Pcode has been token', 'Error occur.');
228 228
             }
229
-            $test_case = \request()->file('test_case');
229
+            $test_case=\request()->file('test_case');
230 230
             //Make sure the user enters SPJ_SRc in spj problem.
231
-            if($form->spj && empty($form->spj_src)) {
231
+            if ($form->spj && empty($form->spj_src)) {
232 232
                 $err('The SPJ problem must provide spj_src', 'create problem error');
233 233
             }
234 234
             //check info file. Try to generate if it does not exist.
235
-            $info_content = [];
236
-            if(!empty($test_case)){
237
-                if($test_case->extension() != 'zip'){
235
+            $info_content=[];
236
+            if (!empty($test_case)) {
237
+                if ($test_case->extension()!='zip') {
238 238
                     $err('You must upload a zip file iuclude test case info and content.');
239 239
                 }
240
-                $path = $test_case->path();
241
-                $zip = new ZipArchive;
242
-                if($zip->open($path) !== true) {
240
+                $path=$test_case->path();
241
+                $zip=new ZipArchive;
242
+                if ($zip->open($path)!==true) {
243 243
                     $err('You must upload a zip file without encrypt and can open successfully.');
244 244
                 };
245
-                $info_content = [];
246
-                if(($zip->getFromName('info')) === false){
247
-                    if(!$form->spj){
248
-                        $info_content = [
245
+                $info_content=[];
246
+                if (($zip->getFromName('info'))===false) {
247
+                    if (!$form->spj) {
248
+                        $info_content=[
249 249
                             'spj' => false,
250 250
                             'test_cases' => []
251 251
                         ];
252
-                        $files = [];
253
-                        for ($i = 0; $i < $zip->numFiles; $i++) {
254
-                            $filename = $zip->getNameIndex($i);
255
-                            $files[] = $filename;
252
+                        $files=[];
253
+                        for ($i=0; $i<$zip->numFiles; $i++) {
254
+                            $filename=$zip->getNameIndex($i);
255
+                            $files[]=$filename;
256 256
                         }
257
-                        $files_in = array_filter($files, function ($filename) {
258
-                            return strpos('.in', $filename) != -1;
257
+                        $files_in=array_filter($files, function($filename) {
258
+                            return strpos('.in', $filename)!=-1;
259 259
                         });
260 260
                         sort($files_in);
261
-                        $testcase_index = 1;
262
-                        foreach($files_in as $filename_in){
263
-                            $filename = basename($filename_in, '.in');
264
-                            $filename_out = $filename.'.out';
265
-                            if(($zip->getFromName($filename_out)) === false) {
261
+                        $testcase_index=1;
262
+                        foreach ($files_in as $filename_in) {
263
+                            $filename=basename($filename_in, '.in');
264
+                            $filename_out=$filename.'.out';
265
+                            if (($zip->getFromName($filename_out))===false) {
266 266
                                 continue;
267 267
                             }
268
-                            $test_case_in = preg_replace('~(*BSR_ANYCRLF)\R~',"\n", $zip->getFromName($filename_in));
269
-                            $test_case_out = preg_replace('~(*BSR_ANYCRLF)\R~',"\n", $zip->getFromName($filename_out));
270
-                            $info_content['test_cases']["{$testcase_index}"] = [
268
+                            $test_case_in=preg_replace('~(*BSR_ANYCRLF)\R~', "\n", $zip->getFromName($filename_in));
269
+                            $test_case_out=preg_replace('~(*BSR_ANYCRLF)\R~', "\n", $zip->getFromName($filename_out));
270
+                            $info_content['test_cases']["{$testcase_index}"]=[
271 271
                                 'input_size' => strlen($test_case_in),
272 272
                                 'input_name' => $filename_in,
273 273
                                 'output_size' => strlen($test_case_out),
274 274
                                 'output_name' => $filename_out,
275 275
                                 'stripped_output_md5' => md5(utf8_encode(rtrim($test_case_out)))
276 276
                             ];
277
-                            $testcase_index += 1;
277
+                            $testcase_index+=1;
278 278
                         }
279
-                    }else{
280
-                        $info_content = [
279
+                    } else {
280
+                        $info_content=[
281 281
                             'spj' => true,
282 282
                             'test_cases' => []
283 283
                         ];
284
-                        $files = [];
285
-                        for ($i = 0; $i < $zip->numFiles; $i++) {
286
-                            $filename = $zip->getNameIndex($i);
287
-                            $files[] = $filename;
284
+                        $files=[];
285
+                        for ($i=0; $i<$zip->numFiles; $i++) {
286
+                            $filename=$zip->getNameIndex($i);
287
+                            $files[]=$filename;
288 288
                         }
289
-                        $files_in = array_filter($files, function ($filename) {
290
-                            return strpos($filename, '.in') !== false;
289
+                        $files_in=array_filter($files, function($filename) {
290
+                            return strpos($filename, '.in')!==false;
291 291
                         });
292 292
                         sort($files_in);
293
-                        $testcase_index = 1;
294
-                        foreach($files_in as $filename_in){
295
-                            $test_case_in = $zip->getFromName($filename_in);
296
-                            $info_content['test_cases']["{$testcase_index}"] = [
293
+                        $testcase_index=1;
294
+                        foreach ($files_in as $filename_in) {
295
+                            $test_case_in=$zip->getFromName($filename_in);
296
+                            $info_content['test_cases']["{$testcase_index}"]=[
297 297
                                 'input_size' => strlen($test_case_in),
298 298
                                 'input_name' => $filename_in
299 299
                             ];
300
-                            $testcase_index += 1;
300
+                            $testcase_index+=1;
301 301
                         }
302 302
                     }
303 303
                     $zip->addFromString('info', json_encode($info_content));
304 304
                     $zip->close();
305 305
                     //$err('The zip files must include a file named info including info of test cases, and the format can see ZsgsDesign/NOJ wiki.');
306
-                }else{
307
-                    $info_content = json_decode($zip->getFromName('info'),true);
306
+                } else {
307
+                    $info_content=json_decode($zip->getFromName('info'), true);
308 308
                 };
309 309
                 $zip->open($path);
310 310
                 //If there is an INFO file, check that the contents of the file match the actual situation
311
-                $test_cases = $info_content['test_cases'];
311
+                $test_cases=$info_content['test_cases'];
312 312
                 //dd($test_cases);
313
-                foreach($test_cases as $index => $case) {
314
-                    if(!isset($case['input_name']) || (!$form->spj && !isset($case['output_name']))) {
313
+                foreach ($test_cases as $index => $case) {
314
+                    if (!isset($case['input_name']) || (!$form->spj && !isset($case['output_name']))) {
315 315
                         $err("Test case index {$index}: configuration missing input/output files name.");
316 316
                     }
317
-                    if($zip->getFromName($case['input_name']) === false || (!$form->spj && $zip->getFromName($case['output_name']) === false)) {
317
+                    if ($zip->getFromName($case['input_name'])===false || (!$form->spj && $zip->getFromName($case['output_name'])===false)) {
318 318
                         $err("Test case index {$index}: missing input/output files that record in the configuration.");
319 319
                     }
320 320
                 }
321
-                if(!empty($form->pid)){
322
-                    $problem = EloquentProblemModel::find($form->pid);
323
-                    if(!empty($problem)){
324
-                        $pcode = $problem->pcode;
325
-                    }else{
326
-                        $pcode = $form->pcode;
321
+                if (!empty($form->pid)) {
322
+                    $problem=EloquentProblemModel::find($form->pid);
323
+                    if (!empty($problem)) {
324
+                        $pcode=$problem->pcode;
325
+                    } else {
326
+                        $pcode=$form->pcode;
327 327
                     }
328
-                }else{
329
-                    $pcode = $form->pcode;
328
+                } else {
329
+                    $pcode=$form->pcode;
330 330
                 }
331 331
 
332
-                if(Storage::exists(base_path().'/storage/test_case/'.$pcode)){
332
+                if (Storage::exists(base_path().'/storage/test_case/'.$pcode)) {
333 333
                     Storage::deleteDirectory(base_path().'/storage/test_case/'.$pcode);
334 334
                 }
335 335
                 Storage::makeDirectory(base_path().'/storage/test_case/'.$pcode);
@@ -337,19 +337,19 @@  discard block
 block discarded – undo
337 337
 
338 338
             }
339 339
             //Set the spj-related data
340
-            if($form->spj){
341
-                $form->spj_lang = 'c';
342
-                $form->spj_version = "{$form->pcode}#".time();
340
+            if ($form->spj) {
341
+                $form->spj_lang='c';
342
+                $form->spj_version="{$form->pcode}#".time();
343 343
             }
344 344
             //Set default data
345
-            $form->tot_score = count($info_content['test_cases']);
346
-            $form->markdown = true;
347
-            $form->input_type = 'standard input';
348
-            $form->output_type = 'standard output';
349
-            $form->solved_count = 0;
350
-            $form->difficulty = -1;
351
-            $form->partial = 1;
352
-            $form->file = 0;
345
+            $form->tot_score=count($info_content['test_cases']);
346
+            $form->markdown=true;
347
+            $form->input_type='standard input';
348
+            $form->output_type='standard output';
349
+            $form->solved_count=0;
350
+            $form->difficulty=-1;
351
+            $form->partial=1;
352
+            $form->file=0;
353 353
         });
354 354
         return $form;
355 355
     }
Please login to merge, or discard this patch.