Passed
Pull Request — master (#244)
by Chenyi
04:13
created
app/Helpers/functions.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -63,20 +63,20 @@  discard block
 block discarded – undo
63 63
     }
64 64
 }
65 65
 
66
-if (! function_exists('babel_path')) {
66
+if (!function_exists('babel_path')) {
67 67
     /**
68 68
      * Get the path to the application folder.
69 69
      *
70 70
      * @param  string  $path
71 71
      * @return string
72 72
      */
73
-    function babel_path($path = '')
73
+    function babel_path($path='')
74 74
     {
75 75
         return app('path').DIRECTORY_SEPARATOR.'Babel'.($path ? DIRECTORY_SEPARATOR.$path : $path);
76 76
     }
77 77
 }
78 78
 
79
-if (! function_exists('glob_recursive')) {
79
+if (!function_exists('glob_recursive')) {
80 80
     /**
81 81
      * Find pathnames matching a pattern recursively.
82 82
      *
@@ -84,11 +84,11 @@  discard block
 block discarded – undo
84 84
      * @param  int     $flags   Valid flags: GLOB_MARK
85 85
      * @return array|false      an array containing the matched files/directories, an empty array if no file matched or false on error.
86 86
      */
87
-    function glob_recursive($pattern, $flags = 0)
87
+    function glob_recursive($pattern, $flags=0)
88 88
     {
89
-        $files = glob($pattern, $flags);
90
-        foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
91
-            $files = array_merge($files, glob_recursive($dir.'/'.basename($pattern), $flags));
89
+        $files=glob($pattern, $flags);
90
+        foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
91
+            $files=array_merge($files, glob_recursive($dir.'/'.basename($pattern), $flags));
92 92
         }
93 93
         return $files;
94 94
     }
@@ -122,8 +122,8 @@  discard block
 block discarded – undo
122 122
     function delFile($dirName)
123 123
     {
124 124
         if (file_exists($dirName) && $handle=opendir($dirName)) {
125
-            while (false!==($item = readdir($handle))) {
126
-                if ($item!= "." && $item != "..") {
125
+            while (false!==($item=readdir($handle))) {
126
+                if ($item!="." && $item!="..") {
127 127
                     if (file_exists($dirName.'/'.$item) && is_dir($dirName.'/'.$item)) {
128 128
                         delFile($dirName.'/'.$item);
129 129
                     } else {
@@ -141,6 +141,6 @@  discard block
 block discarded – undo
141 141
 if (!function_exists('convertMarkdownToHtml')) {
142 142
     function convertMarkdownToHtml($md)
143 143
     {
144
-        return is_string($md)?Markdown::convertToHtml($md):'';
144
+        return is_string($md) ?Markdown::convertToHtml($md) : '';
145 145
     }
146 146
 }
Please login to merge, or discard this patch.
app/Http/Controllers/Contest/BoardController.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -106,8 +106,8 @@  discard block
 block discarded – undo
106 106
             ];
107 107
         }
108 108
 
109
-        $editor_left_width = $accountModel->getExtra(Auth::user()->id, 'editor_left_width');
110
-        if(empty($editor_left_width)) $editor_left_width='40';
109
+        $editor_left_width=$accountModel->getExtra(Auth::user()->id, 'editor_left_width');
110
+        if (empty($editor_left_width)) $editor_left_width='40';
111 111
 
112 112
         return view('contest.board.editor', [
113 113
             'page_title'=>"Problem Detail",
@@ -151,14 +151,14 @@  discard block
 block discarded – undo
151 151
 
152 152
         // To determine the ranking
153 153
         foreach ($contestRank as $i => &$r) {
154
-            if($i != 0) {
155
-                if($r['score'] == $contestRank[$i-1]['score'] && $r['penalty'] == $contestRank[$i-1]['penalty']){
156
-                    $r['rank'] = $contestRank[$i-1]['rank'];
157
-                }else{
158
-                    $r['rank'] = $i + 1;
154
+            if ($i!=0) {
155
+                if ($r['score']==$contestRank[$i-1]['score'] && $r['penalty']==$contestRank[$i-1]['penalty']) {
156
+                    $r['rank']=$contestRank[$i-1]['rank'];
157
+                } else {
158
+                    $r['rank']=$i+1;
159 159
                 }
160
-            }else{
161
-                $r['rank'] = 1;
160
+            } else {
161
+                $r['rank']=1;
162 162
             }
163 163
         }
164 164
         $rankFrozen=$contestModel->isFrozen($cid);
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
         ]);
279 279
     }
280 280
 
281
-    public function analysis($cid){
281
+    public function analysis($cid) {
282 282
         $contestModel=new ContestModel();
283 283
         $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
284 284
         if (!$clearance) {
Please login to merge, or discard this patch.
app/Http/Controllers/Ajax/GroupManageController.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 
37 37
         $all_data=$request->all();
38 38
 
39
-        if(($all_data['public'] ?? 0) && ($all_data['practice'] ?? 0)){
39
+        if (($all_data['public'] ?? 0) && ($all_data['practice'] ?? 0)) {
40 40
             return ResponseModel::err(4007);
41 41
         }
42 42
 
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
             return ResponseModel::err(1003);
68 68
         }
69 69
 
70
-        $cid = $contestModel->arrangeContest($all_data["gid"], [
70
+        $cid=$contestModel->arrangeContest($all_data["gid"], [
71 71
             "assign_uid"=>Auth::user()->id,
72 72
             "name"=>$all_data["name"],
73 73
             "description"=>$all_data["description"],
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
             "public"=>$all_data["public"] ?? 0,
78 78
         ], $problemSet);
79 79
 
80
-        return ResponseModel::success(200,'Successful!',$cid);
80
+        return ResponseModel::success(200, 'Successful!', $cid);
81 81
     }
82 82
 
83 83
     public function changeGroupName(Request $request)
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 
92 92
         $groupModel=new GroupModel();
93 93
         $clearance=$groupModel->judgeClearance($all_data["gid"], Auth::user()->id);
94
-        if ($clearance < 2){
94
+        if ($clearance<2) {
95 95
             return ResponseModel::err(2001);
96 96
         }
97 97
 
@@ -110,11 +110,11 @@  discard block
 block discarded – undo
110 110
 
111 111
         $groupModel=new GroupModel();
112 112
         $clearance=$groupModel->judgeClearance($all_data["gid"], Auth::user()->id);
113
-        if ($clearance < 2){
113
+        if ($clearance<2) {
114 114
             return ResponseModel::err(2001);
115 115
         }
116 116
 
117
-        if ($all_data["join_policy"] < 1 || $all_data["join_policy"] > 3){
117
+        if ($all_data["join_policy"]<1 || $all_data["join_policy"]>3) {
118 118
             return ResponseModel::err(1007);
119 119
         }
120 120
 
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
             'gid' => 'required|integer',
129 129
         ]);
130 130
 
131
-        $all_data = $request->all();
131
+        $all_data=$request->all();
132 132
 
133 133
         if (!empty($request->file('img')) && $request->file('img')->isValid()) {
134 134
             $extension=$request->file('img')->extension();
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 
141 141
         $groupModel=new GroupModel();
142 142
         $clearance=$groupModel->judgeClearance($all_data["gid"], Auth::user()->id);
143
-        if ($clearance < 2){
143
+        if ($clearance<2) {
144 144
             return ResponseModel::err(2001);
145 145
         }
146 146
 
@@ -178,18 +178,18 @@  discard block
 block discarded – undo
178 178
         $clearance=$groupModel->judgeClearance($all_data["gid"], Auth::user()->id);
179 179
         $target_clearance=$groupModel->judgeClearance($all_data["gid"], $all_data['uid']);
180 180
 
181
-        if($target_clearance == -3){
181
+        if ($target_clearance==-3) {
182 182
             return ResponseModel::err(7004);
183 183
         }
184 184
 
185
-        if($target_clearance >= $clearance || $clearance < 2 || $all_data['permission'] >= $clearance){
185
+        if ($target_clearance>=$clearance || $clearance<2 || $all_data['permission']>=$clearance) {
186 186
             return ResponseModel::err(2001);
187 187
         }
188 188
 
189 189
         $groupModel->changeClearance($all_data['uid'], $all_data["gid"], $all_data['permission']);
190 190
 
191
-        $result_info = $groupModel->userProfile($all_data['uid'],$all_data["gid"]);
192
-        return ResponseModel::success(200,null,$result_info);
191
+        $result_info=$groupModel->userProfile($all_data['uid'], $all_data["gid"]);
192
+        return ResponseModel::success(200, null, $result_info);
193 193
     }
194 194
 
195 195
     public function approveMember(Request $request)
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
         $clearance=$groupModel->judgeClearance($all_data["gid"], Auth::user()->id);
206 206
         $targetClearance=$groupModel->judgeClearance($all_data["gid"], $all_data["uid"]);
207 207
         if ($clearance>1) {
208
-            if($targetClearance!=0) {
208
+            if ($targetClearance!=0) {
209 209
                 return ResponseModel::err(7003);
210 210
             }
211 211
             $groupModel->changeClearance($all_data["uid"], $all_data["gid"], 1);
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
         $groupModel=new GroupModel();
227 227
         $clearance=$groupModel->judgeClearance($all_data["gid"], Auth::user()->id);
228 228
         $targetClearance=$groupModel->judgeClearance($all_data["gid"], $all_data["uid"]);
229
-        if ($clearance <= 1 || $clearance <= $targetClearance){
229
+        if ($clearance<=1 || $clearance<=$targetClearance) {
230 230
             return ResponseModel::err(7002);
231 231
         }
232 232
 
@@ -246,11 +246,11 @@  discard block
 block discarded – undo
246 246
 
247 247
         $groupModel=new GroupModel();
248 248
         $is_user=$groupModel->isUser($all_data["email"]);
249
-        if(!$is_user) return ResponseModel::err(2006);
249
+        if (!$is_user) return ResponseModel::err(2006);
250 250
         $clearance=$groupModel->judgeClearance($all_data["gid"], Auth::user()->id);
251
-        if($clearance<2) return ResponseModel::err(7002);
251
+        if ($clearance<2) return ResponseModel::err(7002);
252 252
         $targetClearance=$groupModel->judgeEmailClearance($all_data["gid"], $all_data["email"]);
253
-        if($targetClearance!=-3) return ResponseModel::err(7003);
253
+        if ($targetClearance!=-3) return ResponseModel::err(7003);
254 254
         $groupModel->inviteMember($all_data["gid"], $all_data["email"]);
255 255
         return ResponseModel::success(200);
256 256
     }
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
 
288 288
         $groupModel=new GroupModel();
289 289
         $clearance=$groupModel->judgeClearance($all_data["gid"], Auth::user()->id);
290
-        if ($clearance < 2){
290
+        if ($clearance<2) {
291 291
             return ResponseModel::err(2001);
292 292
         }
293 293
         $groupModel->createNotice($all_data["gid"], Auth::user()->id, $all_data["title"], $all_data["content"]);
Please login to merge, or discard this patch.
app/Models/Rating/GroupRatingCalculator.php 1 patch
Spacing   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -14,36 +14,36 @@  discard block
 block discarded – undo
14 14
     public $totParticipants=0;
15 15
     public $INITIAL_RATING=1500;
16 16
 
17
-    public function __construct($cid){
18
-        $contestModel = new ContestModel();
19
-        $this->cid = $cid;
20
-        $this->gid = $contestModel->gid($cid);
17
+    public function __construct($cid) {
18
+        $contestModel=new ContestModel();
19
+        $this->cid=$cid;
20
+        $this->gid=$contestModel->gid($cid);
21 21
         // get rank
22 22
         $this->getRecord();
23 23
     }
24 24
 
25
-    private function getRecord(){
26
-        $contestModel = new ContestModel();
27
-        $contestRankRaw = $contestModel->contestRank($this->cid);
28
-        foreach($contestRankRaw as $key => $contestRank){
29
-            if(isset($contestRank['remote']) && $contestRank['remote']){
25
+    private function getRecord() {
26
+        $contestModel=new ContestModel();
27
+        $contestRankRaw=$contestModel->contestRank($this->cid);
28
+        foreach ($contestRankRaw as $key => $contestRank) {
29
+            if (isset($contestRank['remote']) && $contestRank['remote']) {
30 30
                 unset($contestRankRaw[$key]);
31 31
             }
32 32
         }
33
-        $contestRankRaw = array_values($contestRankRaw);
34
-        $members = array_column($contestRankRaw,'uid');
35
-        $ratings_temp = DB::table('group_member')
33
+        $contestRankRaw=array_values($contestRankRaw);
34
+        $members=array_column($contestRankRaw, 'uid');
35
+        $ratings_temp=DB::table('group_member')
36 36
             ->where([
37 37
                 'gid' => $this->gid,
38
-            ])->whereIn('uid',$members)
39
-            ->select('uid','ranking')
38
+            ])->whereIn('uid', $members)
39
+            ->select('uid', 'ranking')
40 40
             ->get()->all();
41
-        $ratings = [];
41
+        $ratings=[];
42 42
         foreach ($ratings_temp as $rating) {
43
-            $ratings[$rating['uid']] = $rating['ranking'];
43
+            $ratings[$rating['uid']]=$rating['ranking'];
44 44
         }
45
-        foreach($contestRankRaw as $c){
46
-            if(!isset($ratings[$c['uid']])){
45
+        foreach ($contestRankRaw as $c) {
46
+            if (!isset($ratings[$c['uid']])) {
47 47
                 continue;
48 48
             }
49 49
             $this->contestants[]=[
@@ -52,87 +52,87 @@  discard block
 block discarded – undo
52 52
                 "rating"=>$ratings[$c['uid']],
53 53
             ];
54 54
         }
55
-        $this->totParticipants = count($this->contestants);
55
+        $this->totParticipants=count($this->contestants);
56 56
     }
57 57
 
58
-    private function reassignRank(){
58
+    private function reassignRank() {
59 59
         $this->sort("points");
60
-        $idx = 0;
61
-        $points = $this->contestants[0]["points"];
62
-        $i = 1;
63
-        while($i < $this->totParticipants){
64
-            if($this->contestants[$i]["points"] < $points){
65
-                $j = $idx;
66
-                while($j < $i){
67
-                    $this->contestants[$j]["rank"] = $i;
68
-                    $j += 1;
60
+        $idx=0;
61
+        $points=$this->contestants[0]["points"];
62
+        $i=1;
63
+        while ($i<$this->totParticipants) {
64
+            if ($this->contestants[$i]["points"]<$points) {
65
+                $j=$idx;
66
+                while ($j<$i) {
67
+                    $this->contestants[$j]["rank"]=$i;
68
+                    $j+=1;
69 69
                 }
70
-                $idx = $i;
71
-                $points = $this->contestants[$i]["points"];
70
+                $idx=$i;
71
+                $points=$this->contestants[$i]["points"];
72 72
             }
73
-            $i += 1;
73
+            $i+=1;
74 74
         }
75
-        $j = $idx;
76
-        while($j < $this->totParticipants){
77
-            $this->contestants[$j]["rank"] = $this->totParticipants;
78
-            $j += 1;
75
+        $j=$idx;
76
+        while ($j<$this->totParticipants) {
77
+            $this->contestants[$j]["rank"]=$this->totParticipants;
78
+            $j+=1;
79 79
         }
80 80
     }
81 81
 
82
-    private function getEloWinProbability($Ra, $Rb){
83
-        return 1.0 / (1 + pow(10, ($Rb-$Ra)/400.0));
82
+    private function getEloWinProbability($Ra, $Rb) {
83
+        return 1.0 / (1+pow(10, ($Rb-$Ra) / 400.0));
84 84
     }
85 85
 
86
-    private function getSeed($rating){
87
-        $result = 1.0;
88
-        foreach($this->contestants as $other){
89
-            $result += $this->getEloWinProbability($other["rating"], $rating);
86
+    private function getSeed($rating) {
87
+        $result=1.0;
88
+        foreach ($this->contestants as $other) {
89
+            $result+=$this->getEloWinProbability($other["rating"], $rating);
90 90
         }
91 91
         return $result;
92 92
     }
93 93
 
94
-    private function getRatingToRank($rank){
94
+    private function getRatingToRank($rank) {
95 95
         $left=1;
96 96
         $right=8000;
97
-        while($right - $left > 1){
98
-            $mid = floor(($right + $left)/2);
99
-            if($this->getSeed($mid) < $rank){
100
-                $right = $mid;
101
-            }else{
102
-                $left = $mid;
97
+        while ($right-$left>1) {
98
+            $mid=floor(($right+$left) / 2);
99
+            if ($this->getSeed($mid)<$rank) {
100
+                $right=$mid;
101
+            } else {
102
+                $left=$mid;
103 103
             }
104 104
         }
105 105
         return $left;
106 106
     }
107 107
 
108
-    private function sort($key){
109
-        usort($this->contestants, function ($a, $b) use ($key) {
108
+    private function sort($key) {
109
+        usort($this->contestants, function($a, $b) use ($key) {
110 110
             return $b[$key] <=> $a[$key];
111 111
         });
112 112
     }
113 113
 
114
-    public function calculate(){
115
-        if(empty($this->contestants)){
114
+    public function calculate() {
115
+        if (empty($this->contestants)) {
116 116
             return;
117 117
         }
118 118
 
119 119
         // recalc rank
120 120
         $this->reassignRank();
121 121
 
122
-        foreach($this->contestants as &$member){
123
-            $member["seed"] = 1.0;
124
-            foreach($this->contestants as $other){
125
-                if($member["uid"] != $other["uid"]){
126
-                    $member["seed"] += $this->getEloWinProbability($other["rating"], $member["rating"]);
122
+        foreach ($this->contestants as &$member) {
123
+            $member["seed"]=1.0;
124
+            foreach ($this->contestants as $other) {
125
+                if ($member["uid"]!=$other["uid"]) {
126
+                    $member["seed"]+=$this->getEloWinProbability($other["rating"], $member["rating"]);
127 127
                 }
128 128
             }
129 129
         }
130 130
         unset($member);
131 131
 
132
-        foreach($this->contestants as &$contestant){
133
-            $midRank = sqrt($contestant["rank"] * $contestant["seed"]);
134
-            $contestant["needRating"] = $this->getRatingToRank($midRank);
135
-            $contestant["delta"] = floor(($contestant["needRating"] - $contestant["rating"])/2);
132
+        foreach ($this->contestants as &$contestant) {
133
+            $midRank=sqrt($contestant["rank"] * $contestant["seed"]);
134
+            $contestant["needRating"]=$this->getRatingToRank($midRank);
135
+            $contestant["delta"]=floor(($contestant["needRating"]-$contestant["rating"]) / 2);
136 136
         }
137 137
         unset($contestant);
138 138
 
@@ -140,39 +140,39 @@  discard block
 block discarded – undo
140 140
 
141 141
         // DO some adjuct
142 142
         // Total sum should not be more than ZERO.
143
-        $sum = 0;
143
+        $sum=0;
144 144
 
145
-        foreach($this->contestants as $contestant){
146
-            $sum += $contestant["delta"];
145
+        foreach ($this->contestants as $contestant) {
146
+            $sum+=$contestant["delta"];
147 147
         }
148
-        $inc = -floor($sum / $this->totParticipants) - 1;
149
-        foreach($this->contestants as &$contestant){
150
-            $contestant["delta"] += $inc;
148
+        $inc=-floor($sum / $this->totParticipants)-1;
149
+        foreach ($this->contestants as &$contestant) {
150
+            $contestant["delta"]+=$inc;
151 151
         }
152 152
         unset($contestant);
153 153
 
154 154
         // Sum of top-4*sqrt should be adjusted to ZERO.
155 155
 
156
-        $sum = 0;
157
-        $zeroSumCount = min(intval(4*round(sqrt($this->totParticipants))), $this->totParticipants);
156
+        $sum=0;
157
+        $zeroSumCount=min(intval(4 * round(sqrt($this->totParticipants))), $this->totParticipants);
158 158
 
159
-        for($i=0;$i<$zeroSumCount;$i++){
160
-            $sum += $this->contestants[$i]["delta"];
159
+        for ($i=0; $i<$zeroSumCount; $i++) {
160
+            $sum+=$this->contestants[$i]["delta"];
161 161
         }
162 162
 
163
-        $inc = min(max(-floor($sum / $zeroSumCount), -10), 0);
163
+        $inc=min(max(-floor($sum / $zeroSumCount), -10), 0);
164 164
 
165
-        for($i=0;$i<$zeroSumCount;$i++){
166
-            $this->contestants[$i]["delta"] += $inc;
165
+        for ($i=0; $i<$zeroSumCount; $i++) {
166
+            $this->contestants[$i]["delta"]+=$inc;
167 167
         }
168 168
 
169 169
         return $this->validateDeltas();
170 170
     }
171 171
 
172
-    public function storage(){
172
+    public function storage() {
173 173
         $contestants=$this->contestants;
174
-        DB::transaction(function () use ($contestants) {
175
-            foreach($contestants as $contestant){
174
+        DB::transaction(function() use ($contestants) {
175
+            foreach ($contestants as $contestant) {
176 176
                 $newRating=$contestant["rating"]+$contestant["delta"];
177 177
                 DB::table("group_member")->where([
178 178
                     'gid' => $this->gid,
@@ -190,20 +190,20 @@  discard block
 block discarded – undo
190 190
         }, 5);
191 191
     }
192 192
 
193
-    private function validateDeltas(){
193
+    private function validateDeltas() {
194 194
         $this->sort("points");
195 195
 
196
-        for($i=0;$i<$this->totParticipants;$i++){
197
-            for($j=$i+1;$j<$this->totParticipants;$j++){
198
-                if($this->contestants[$i]["rating"] > $this->contestants[$j]["rating"]){
199
-                    if($this->contestants[$i]["rating"] + $this->contestants[$i]["delta"] < $this->contestants[$j]["rating"] + $this->contestants[$j]["delta"]){
196
+        for ($i=0; $i<$this->totParticipants; $i++) {
197
+            for ($j=$i+1; $j<$this->totParticipants; $j++) {
198
+                if ($this->contestants[$i]["rating"]>$this->contestants[$j]["rating"]) {
199
+                    if ($this->contestants[$i]["rating"]+$this->contestants[$i]["delta"]<$this->contestants[$j]["rating"]+$this->contestants[$j]["delta"]) {
200 200
                         Log::warning("First rating invariant failed: {$this->contestants[$i]["uid"]} vs. {$this->contestants[$j]["uid"]}.");
201 201
                         return false;
202 202
                     }
203 203
                 }
204 204
 
205
-                if($this->contestants[$i]["rating"] < $this->contestants[$j]["rating"]){
206
-                    if($this->contestants[$i]["delta"] < $this->contestants[$j]["delta"]){
205
+                if ($this->contestants[$i]["rating"]<$this->contestants[$j]["rating"]) {
206
+                    if ($this->contestants[$i]["delta"]<$this->contestants[$j]["delta"]) {
207 207
                         Log::warning("Second rating invariant failed: {$this->contestants[$i]["uid"]} vs.  {$this->contestants[$j]["uid"]}.");
208 208
                         return false;
209 209
                     }
Please login to merge, or discard this patch.
app/Exports/GroupAnalysisExport.php 1 patch
Spacing   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -16,16 +16,16 @@  discard block
 block discarded – undo
16 16
     private $member_data;
17 17
     private $config;
18 18
 
19
-    public function __construct($data, $config = [])
19
+    public function __construct($data, $config=[])
20 20
     {
21
-        if ($config['mode'] == 'contest') {
22
-            $this->contest_data = $data['contest_data'];
23
-            $this->member_data = $data['member_data'];
21
+        if ($config['mode']=='contest') {
22
+            $this->contest_data=$data['contest_data'];
23
+            $this->member_data=$data['member_data'];
24 24
         } else {
25
-            $this->member_data = $data['member_data'];
26
-            $this->tag_problems = $data['tag_problems'];
25
+            $this->member_data=$data['member_data'];
26
+            $this->tag_problems=$data['tag_problems'];
27 27
         }
28
-        $this->config = $config;
28
+        $this->config=$config;
29 29
     }
30 30
 
31 31
     /**
@@ -34,9 +34,9 @@  discard block
 block discarded – undo
34 34
     public function registerEvents(): array
35 35
     {
36 36
         return [
37
-            AfterSheet::class => function (AfterSheet $event) {
38
-                if ($this->config['mode'] === 'contest') {
39
-                    $mergeCell = ['A1:A2','B1:E1'];
37
+            AfterSheet::class => function(AfterSheet $event) {
38
+                if ($this->config['mode']==='contest') {
39
+                    $mergeCell=['A1:A2', 'B1:E1'];
40 40
                     foreach ($this->contest_data as $c) {
41 41
                         array_push($mergeCell, $this->mergeCellColumnNext());
42 42
                     }
@@ -51,46 +51,46 @@  discard block
 block discarded – undo
51 51
     */
52 52
     public function collection()
53 53
     {
54
-        $maxium = $this->config['maxium'] ?? false;
55
-        $percent = $this->config['percent'] ?? false;
54
+        $maxium=$this->config['maxium'] ?? false;
55
+        $percent=$this->config['percent'] ?? false;
56 56
 
57
-        if ($this->config['mode'] == 'contest') {
58
-            $row_1 = ['Member','Total','','',''];
59
-            $row_2 = ['','Elo','Rank','Solved','Penalty'];
57
+        if ($this->config['mode']=='contest') {
58
+            $row_1=['Member', 'Total', '', '', ''];
59
+            $row_2=['', 'Elo', 'Rank', 'Solved', 'Penalty'];
60 60
             foreach ($this->contest_data as $contest) {
61
-                array_push($row_1, $contest['name'], '','');
62
-                array_push($row_2, 'Rank','Solved', 'Penalty');
61
+                array_push($row_1, $contest['name'], '', '');
62
+                array_push($row_2, 'Rank', 'Solved', 'Penalty');
63 63
             }
64
-            $data = [$row_1,$row_2];
64
+            $data=[$row_1, $row_2];
65 65
             foreach ($this->member_data as $member) {
66
-                $display_name = $member['name'];
66
+                $display_name=$member['name'];
67 67
                 if (!empty($member['nick_name'])) {
68
-                    $display_name .= ' ('.$member['nick_name'].')';
68
+                    $display_name.=' ('.$member['nick_name'].')';
69 69
                 }
70
-                $row = [
70
+                $row=[
71 71
                     $display_name,
72 72
                     $member['elo'],
73 73
                     !empty($member['rank_ave']) ? round($member['rank_ave'], 1) : '-',
74
-                    $percent === 'true'  ? ($member['problem_all'] != 0 ? round($member['solved_all'] / $member['problem_all'] * 100, 1) : '-'). ' %'
75
-                            : ($maxium === 'true'  ? $member['solved_all'] . ' / ' . $member['problem_all'] : $member['solved_all']),
74
+                    $percent==='true' ? ($member['problem_all']!=0 ? round($member['solved_all'] / $member['problem_all'] * 100, 1) : '-').' %'
75
+                            : ($maxium==='true' ? $member['solved_all'].' / '.$member['problem_all'] : $member['solved_all']),
76 76
                     round($member['penalty']),
77 77
                 ];
78 78
                 foreach ($this->contest_data as $contest) {
79 79
                     if (in_array($contest['cid'], array_keys($member['contest_detial']))) {
80
-                        $contest_detial = $member['contest_detial'][$contest['cid']];
80
+                        $contest_detial=$member['contest_detial'][$contest['cid']];
81 81
                         array_push(
82 82
                             $row,
83 83
                             $contest_detial['rank'],
84
-                            $percent === 'true' ? (round($contest_detial['solved'] / $contest_detial['problems'] * 100, 1) . ' %')
85
-                                    : ($maxium === 'true' ? $contest_detial['solved'].' / '.$contest_detial['problems'] : $contest_detial['solved']),
84
+                            $percent==='true' ? (round($contest_detial['solved'] / $contest_detial['problems'] * 100, 1).' %')
85
+                                    : ($maxium==='true' ? $contest_detial['solved'].' / '.$contest_detial['problems'] : $contest_detial['solved']),
86 86
                             round($contest_detial['penalty'])
87 87
                         );
88 88
                     } else {
89 89
                         array_push(
90 90
                             $row,
91 91
                             '-',
92
-                            $percent === 'true' ? '- %'
93
-                                    : ($maxium === 'true' ? '- / -' : ' - '),
92
+                            $percent==='true' ? '- %'
93
+                                    : ($maxium==='true' ? '- / -' : ' - '),
94 94
                             0
95 95
                         );
96 96
                     }
@@ -98,27 +98,27 @@  discard block
 block discarded – undo
98 98
                 array_push($data, $row);
99 99
             }
100 100
         } else {
101
-            $row_1 = ['Member'];
102
-            $row_2 = [''];
101
+            $row_1=['Member'];
102
+            $row_2=[''];
103 103
             foreach ($this->tag_problems as $tag => $tag_problem_set) {
104 104
                 array_push($row_1, $tag);
105 105
                 array_push($row_2, 'Solved');
106 106
             }
107
-            $data = [$row_1,$row_2];
107
+            $data=[$row_1, $row_2];
108 108
             foreach ($this->member_data as $member) {
109
-                $display_name = $member['name'];
109
+                $display_name=$member['name'];
110 110
                 if (!empty($member['nick_name'])) {
111
-                    $display_name .= ' ('.$member['nick_name'].')';
111
+                    $display_name.=' ('.$member['nick_name'].')';
112 112
                 }
113
-                $row = [
113
+                $row=[
114 114
                     $display_name,
115 115
                 ];
116 116
                 foreach ($member['completion'] as $tag => $tag_completion) {
117
-                    $count = count($tag_completion);
118
-                    $solved = eval('return '.join('+', array_values($tag_completion)).';');
117
+                    $count=count($tag_completion);
118
+                    $solved=eval('return '.join('+', array_values($tag_completion)).';');
119 119
                     array_push(
120 120
                         $row,
121
-                        $percent === 'true' ? (round($solved / $count * 100, 1) . ' %') : ($maxium  === 'true' ? $solved .' / '.$count : $solved)
121
+                        $percent==='true' ? (round($solved / $count * 100, 1).' %') : ($maxium==='true' ? $solved.' / '.$count : $solved)
122 122
                     );
123 123
                 }
124 124
                 array_push($data, $row);
@@ -129,33 +129,33 @@  discard block
 block discarded – undo
129 129
 
130 130
     private function mergeCellColumnNext()
131 131
     {
132
-        static $columns = [
133
-            [2],[4]
132
+        static $columns=[
133
+            [2], [4]
134 134
         ];
135
-        $columns_str = ['',''];
136
-        $chars = str_split('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
135
+        $columns_str=['', ''];
136
+        $chars=str_split('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
137 137
         foreach ($columns as $key => &$column) {
138
-            $column[0] += 3;
139
-            if ($column[0] > 25) {
138
+            $column[0]+=3;
139
+            if ($column[0]>25) {
140 140
                 if (isset($column[1])) {
141
-                    $column[1] += 1;
142
-                    if ($column[1] > 25) {
141
+                    $column[1]+=1;
142
+                    if ($column[1]>25) {
143 143
                         if (isset($column[2])) {
144
-                            $column[2] += 1;
144
+                            $column[2]+=1;
145 145
                         } else {
146
-                            $column[2] = 0;
146
+                            $column[2]=0;
147 147
                         }
148 148
                     }
149 149
                 } else {
150
-                    $column[1] = 0;
150
+                    $column[1]=0;
151 151
                 }
152 152
             }
153
-            $columns_str[$key] = '';
154
-            $reverse_column = array_reverse($column);
153
+            $columns_str[$key]='';
154
+            $reverse_column=array_reverse($column);
155 155
             foreach ($reverse_column as $ord) {
156
-                $columns_str[$key] .= $chars[$ord];
156
+                $columns_str[$key].=$chars[$ord];
157 157
             }
158
-            $columns_str[$key] .= '1';
158
+            $columns_str[$key].='1';
159 159
         }
160 160
         return $columns_str[0].':'.$columns_str[1];
161 161
     }
Please login to merge, or discard this patch.
app/Babel/Submit/Curl.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -18,11 +18,11 @@  discard block
 block discarded – undo
18 18
 
19 19
     public function login($all_data)
20 20
     {
21
-        if(isset($all_data["url"]))    $url = $all_data["url"];       else throw new Exception("url is not exist in all_data");
22
-        if(isset($all_data["data"]))   $data = $all_data["data"];     else throw new Exception("data is not exist in all_data");
23
-        if(isset($all_data["oj"]))     $oj = $all_data["oj"];         else throw new Exception("oj is not exist in all_data");
24
-        if(isset($all_data["ret"]))    $ret = $all_data["ret"];       else $ret = 'false';
25
-        if(isset($all_data["handle"])) $handle = $all_data["handle"]; else $handle = "default";
21
+        if (isset($all_data["url"]))    $url=$all_data["url"]; else throw new Exception("url is not exist in all_data");
22
+        if (isset($all_data["data"]))   $data=$all_data["data"]; else throw new Exception("data is not exist in all_data");
23
+        if (isset($all_data["oj"]))     $oj=$all_data["oj"]; else throw new Exception("oj is not exist in all_data");
24
+        if (isset($all_data["ret"]))    $ret=$all_data["ret"]; else $ret='false';
25
+        if (isset($all_data["handle"])) $handle=$all_data["handle"]; else $handle="default";
26 26
 
27 27
         $datapost=curl_init();
28 28
         $headers=array("Expect:");
@@ -54,12 +54,12 @@  discard block
 block discarded – undo
54 54
 
55 55
     public function grab_page($all_data)
56 56
     {
57
-        if(isset($all_data["site"]))    $site = $all_data["site"];          else throw new Exception("site is not exist in all_data");
58
-        if(isset($all_data["oj"]))      $oj = $all_data["oj"];              else throw new Exception("oj is not exist in all_data");
59
-        if(isset($all_data["headers"])) $headers = $all_data["headers"];    else $headers = [];
60
-        if(isset($all_data["handle"]))  $handle = $all_data["handle"];      else $handle = "default";
61
-        if(isset($all_data["follow"]))  $follow = $all_data["follow"];      else $follow = false;
62
-        if(isset($all_data["vcid"]))  $vcid = $all_data["vcid"];      else $vcid = "";
57
+        if (isset($all_data["site"]))    $site=$all_data["site"]; else throw new Exception("site is not exist in all_data");
58
+        if (isset($all_data["oj"]))      $oj=$all_data["oj"]; else throw new Exception("oj is not exist in all_data");
59
+        if (isset($all_data["headers"])) $headers=$all_data["headers"]; else $headers=[];
60
+        if (isset($all_data["handle"]))  $handle=$all_data["handle"]; else $handle="default";
61
+        if (isset($all_data["follow"]))  $follow=$all_data["follow"]; else $follow=false;
62
+        if (isset($all_data["vcid"]))  $vcid=$all_data["vcid"]; else $vcid="";
63 63
 
64 64
         $handle=urlencode($handle);
65 65
 
@@ -86,16 +86,16 @@  discard block
 block discarded – undo
86 86
 
87 87
     public function post_data($all_data)
88 88
     {
89
-        if(isset($all_data["site"]))         $site = $all_data["site"];                 else throw new Exception("site is not exist in all_data");
90
-        if(isset($all_data["data"]))         $data = $all_data["data"];                 else throw new Exception("data is not exist in all_data");
91
-        if(isset($all_data["oj"]))           $oj = $all_data["oj"];                     else throw new Exception("oj is not exist in all_data");
92
-        if(isset($all_data["ret"]))          $ret = $all_data["ret"];                   else $ret = false;
93
-        if(isset($all_data["follow"]))       $follow = $all_data["follow"];             else $follow = true;
94
-        if(isset($all_data["returnHeader"])) $returnHeader = $all_data["returnHeader"]; else $returnHeader = true;
95
-        if(isset($all_data["postJson"]))     $postJson = $all_data["postJson"];         else $postJson = false;
96
-        if(isset($all_data["extraHeaders"])) $extraHeaders = $all_data["extraHeaders"]; else $extraHeaders = [];
97
-        if(isset($all_data["handle"]))       $handle = $all_data["handle"];             else $handle = "default";
98
-        if(isset($all_data["vcid"]))  $vcid = $all_data["vcid"];      else $vcid = "";
89
+        if (isset($all_data["site"]))         $site=$all_data["site"]; else throw new Exception("site is not exist in all_data");
90
+        if (isset($all_data["data"]))         $data=$all_data["data"]; else throw new Exception("data is not exist in all_data");
91
+        if (isset($all_data["oj"]))           $oj=$all_data["oj"]; else throw new Exception("oj is not exist in all_data");
92
+        if (isset($all_data["ret"]))          $ret=$all_data["ret"]; else $ret=false;
93
+        if (isset($all_data["follow"]))       $follow=$all_data["follow"]; else $follow=true;
94
+        if (isset($all_data["returnHeader"])) $returnHeader=$all_data["returnHeader"]; else $returnHeader=true;
95
+        if (isset($all_data["postJson"]))     $postJson=$all_data["postJson"]; else $postJson=false;
96
+        if (isset($all_data["extraHeaders"])) $extraHeaders=$all_data["extraHeaders"]; else $extraHeaders=[];
97
+        if (isset($all_data["handle"]))       $handle=$all_data["handle"]; else $handle="default";
98
+        if (isset($all_data["vcid"]))  $vcid=$all_data["vcid"]; else $vcid="";
99 99
 
100 100
         $handle=urlencode($handle);
101 101
 
Please login to merge, or discard this patch.
app/Http/Controllers/Ajax/GroupController.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -69,9 +69,9 @@  discard block
 block discarded – undo
69 69
         $all_data=$request->all();
70 70
 
71 71
         $groupModel=new GroupModel();
72
-        if($all_data["gcode"]=="create") return ResponseModel::err(7005);
72
+        if ($all_data["gcode"]=="create") return ResponseModel::err(7005);
73 73
         $is_group=$groupModel->isGroup($all_data["gcode"]);
74
-        if($is_group) return ResponseModel::err(7006);
74
+        if ($is_group) return ResponseModel::err(7006);
75 75
 
76 76
         $allow_extension=['jpg', 'png', 'jpeg', 'gif', 'bmp'];
77 77
         if (!empty($request->file('img')) && $request->file('img')->isValid()) {
@@ -100,20 +100,20 @@  discard block
 block discarded – undo
100 100
 
101 101
         $groupModel=new GroupModel();
102 102
         $clearance=$groupModel->judgeClearance($all_data["gid"], Auth::user()->id);
103
-        if ($clearance > 0) {
104
-            switch($all_data['mode']){
103
+        if ($clearance>0) {
104
+            switch ($all_data['mode']) {
105 105
                 case 'contest':
106
-                    $ret = $groupModel->groupMemberPracticeContestStat($all_data["gid"]);
106
+                    $ret=$groupModel->groupMemberPracticeContestStat($all_data["gid"]);
107 107
                 break;
108 108
                 case 'tag':
109
-                    $ret = $groupModel->groupMemberPracticeTagStat($all_data["gid"]);
109
+                    $ret=$groupModel->groupMemberPracticeTagStat($all_data["gid"]);
110 110
                 break;
111 111
                 default:
112 112
                     return ResponseModel::err(1007);
113 113
                 break;
114 114
             }
115 115
 
116
-            return ResponseModel::success(200,null,$ret);
116
+            return ResponseModel::success(200, null, $ret);
117 117
         }
118 118
         return ResponseModel::err(7002);
119 119
     }
@@ -129,10 +129,10 @@  discard block
 block discarded – undo
129 129
 
130 130
         $groupModel=new GroupModel();
131 131
         $clearance=$groupModel->judgeClearance($all_data["gid"], Auth::user()->id);
132
-        if($clearance <= 0){
132
+        if ($clearance<=0) {
133 133
             return ResponseModel::err(7002);
134 134
         }
135
-        $ret = $groupModel->getEloChangeLog($all_data['gid'],$all_data['uid']);
136
-        return ResponseModel::success(200,null,$ret);
135
+        $ret=$groupModel->getEloChangeLog($all_data['gid'], $all_data['uid']);
136
+        return ResponseModel::success(200, null, $ret);
137 137
     }
138 138
 }
Please login to merge, or discard this patch.
app/Models/GroupModel.php 1 patch
Spacing   +105 added lines, -105 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
     }
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
     public function details($gcode)
116 116
     {
117 117
         $basic_info=DB::table($this->tableName)->where(["gcode"=>$gcode])->first();
118
-        if(empty($basic_info)) return [];
118
+        if (empty($basic_info)) return [];
119 119
         $basic_info["members"]=$this->countGroupMembers($basic_info["gid"]);
120 120
         $basic_info["tags"]=$this->getGroupTags($basic_info["gid"]);
121 121
         $basic_info["create_time_foramt"]=date_format(date_create($basic_info["create_time"]), 'M jS, Y');
@@ -132,10 +132,10 @@  discard block
 block discarded – undo
132 132
     public function userProfile($uid, $gid)
133 133
     {
134 134
         $info=DB::table("group_member")
135
-        ->join('users','users.id','=','group_member.uid')
135
+        ->join('users', 'users.id', '=', 'group_member.uid')
136 136
         ->where(["gid"=>$gid, "uid"=>$uid])
137 137
         ->where("role", ">", 0)
138
-        ->select('avatar','describes','email','gid','uid','name','nick_name','professional_rate','role','sub_group')
138
+        ->select('avatar', 'describes', 'email', 'gid', 'uid', 'name', 'nick_name', 'professional_rate', 'role', 'sub_group')
139 139
         ->first();
140 140
         if (!empty($info)) {
141 141
             $info["role_parsed"]=$this->role[$info["role"]];
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
         foreach ($user_list as &$u) {
164 164
             $u["role_parsed"]=$this->role[$u["role"]];
165 165
             $u["role_color"]=$this->role_color[$u["role"]];
166
-            if(is_null($u["sub_group"])) $u["sub_group"]="None";
166
+            if (is_null($u["sub_group"])) $u["sub_group"]="None";
167 167
         }
168 168
         return $user_list;
169 169
     }
@@ -224,16 +224,16 @@  discard block
 block discarded – undo
224 224
         ])->where("role", ">", 0)->count();
225 225
     }
226 226
 
227
-    public function problemTags($gid,$pid = -1)
227
+    public function problemTags($gid, $pid=-1)
228 228
     {
229
-        if($pid == -1){
230
-            $tags =  DB::table('group_problem_tag')
229
+        if ($pid==-1) {
230
+            $tags=DB::table('group_problem_tag')
231 231
             ->select('tag')
232
-            ->where('gid',$gid)
232
+            ->where('gid', $gid)
233 233
             ->distinct()
234 234
             ->get()->all();
235
-        }else{
236
-            $tags =  DB::table('group_problem_tag')
235
+        } else {
236
+            $tags=DB::table('group_problem_tag')
237 237
             ->select('tag')
238 238
             ->where('gid', $gid)
239 239
             ->where('pid', $pid)
@@ -241,10 +241,10 @@  discard block
 block discarded – undo
241 241
             ->get()->all();
242 242
         }
243 243
 
244
-        $tags_arr = [];
245
-        if(!empty($tags)){
244
+        $tags_arr=[];
245
+        if (!empty($tags)) {
246 246
             foreach ($tags as $value) {
247
-                array_push($tags_arr,$value['tag']);
247
+                array_push($tags_arr, $value['tag']);
248 248
             }
249 249
         }
250 250
         return $tags_arr;
@@ -252,28 +252,28 @@  discard block
 block discarded – undo
252 252
 
253 253
     public function problems($gid)
254 254
     {
255
-        $contestModel = new ContestModel();
256
-        $problems = DB::table('contest_problem')
257
-        ->join('contest','contest_problem.cid', '=', 'contest.cid')
258
-        ->join('problem','contest_problem.pid', '=', 'problem.pid' )
255
+        $contestModel=new ContestModel();
256
+        $problems=DB::table('contest_problem')
257
+        ->join('contest', 'contest_problem.cid', '=', 'contest.cid')
258
+        ->join('problem', 'contest_problem.pid', '=', 'problem.pid')
259 259
         ->select('contest_problem.cid as cid', 'problem.pid as pid', 'pcode', 'title')
260
-        ->where('contest.gid',$gid)
261
-        ->where('contest.practice',1)
262
-        ->orderBy('contest.create_time','desc')
260
+        ->where('contest.gid', $gid)
261
+        ->where('contest.practice', 1)
262
+        ->orderBy('contest.create_time', 'desc')
263 263
         ->distinct()
264 264
         ->get()->all();
265
-        $user_id = Auth::user()->id;
266
-        foreach($problems as $key => $value){
267
-            if($contestModel->judgeClearance($value['cid'],$user_id) != 3){
265
+        $user_id=Auth::user()->id;
266
+        foreach ($problems as $key => $value) {
267
+            if ($contestModel->judgeClearance($value['cid'], $user_id)!=3) {
268 268
                 unset($problems[$key]);
269
-            }else{
270
-                $problems[$key]['tags'] = $this->problemTags($gid,$value['pid']);
269
+            } else {
270
+                $problems[$key]['tags']=$this->problemTags($gid, $value['pid']);
271 271
             }
272 272
         }
273 273
         return $problems;
274 274
     }
275 275
 
276
-    public function problemAddTag($gid,$pid,$tag)
276
+    public function problemAddTag($gid, $pid, $tag)
277 277
     {
278 278
         return DB::table("group_problem_tag")->insert([
279 279
             "gid"=>$gid,
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
         ]);
283 283
     }
284 284
 
285
-    public function problemRemoveTag($gid,$pid,$tag)
285
+    public function problemRemoveTag($gid, $pid, $tag)
286 286
     {
287 287
         return DB::table("group_problem_tag")->where([
288 288
             "gid"=>$gid,
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
     public function judgeEmailClearance($gid, $email)
328 328
     {
329 329
         $user=DB::table("users")->where(["email"=>$email])->first();
330
-        if(empty($user)) return -4;
330
+        if (empty($user)) return -4;
331 331
         $ret=DB::table("group_member")->where([
332 332
             "gid"=>$gid,
333 333
             "uid"=>$user["id"],
@@ -418,20 +418,20 @@  discard block
 block discarded – undo
418 418
 
419 419
     public function groupMemberPracticeContestStat($gid)
420 420
     {
421
-        $contestModel = new ContestModel();
421
+        $contestModel=new ContestModel();
422 422
 
423
-        $allPracticeContest = DB::table('contest')
423
+        $allPracticeContest=DB::table('contest')
424 424
             ->where([
425 425
                 'gid' => $gid,
426 426
                 'practice' => 1,
427 427
             ])
428
-            ->select('cid','name')
428
+            ->select('cid', 'name')
429 429
             ->get()->all();
430
-        $user_list = $this->userList($gid);
430
+        $user_list=$this->userList($gid);
431 431
 
432
-        $memberData = [];
432
+        $memberData=[];
433 433
         foreach ($user_list as $u) {
434
-            $memberData[$u['uid']] = [
434
+            $memberData[$u['uid']]=[
435 435
                 'name' => $u['name'],
436 436
                 'nick_name' => $u['nick_name'],
437 437
                 'elo' => $u['ranking'],
@@ -442,61 +442,61 @@  discard block
 block discarded – undo
442 442
             ];
443 443
         }
444 444
         foreach ($allPracticeContest as $c) {
445
-            $contestRankRaw = $contestModel->contestRank($c['cid']);
446
-            foreach($contestRankRaw as $key => $contestRank){
447
-                if(isset($contestRank['remote']) && $contestRank['remote']){
445
+            $contestRankRaw=$contestModel->contestRank($c['cid']);
446
+            foreach ($contestRankRaw as $key => $contestRank) {
447
+                if (isset($contestRank['remote']) && $contestRank['remote']) {
448 448
                     unset($contestRankRaw[$key]);
449 449
                 }
450 450
             }
451
-            $contestRank = array_values($contestRankRaw);
452
-            $problemsCount = DB::table('contest_problem')
453
-                ->where('cid',$c['cid'])
451
+            $contestRank=array_values($contestRankRaw);
452
+            $problemsCount=DB::table('contest_problem')
453
+                ->where('cid', $c['cid'])
454 454
                 ->count();
455
-            $index = 1;
456
-            $rank = 1;
457
-            $last_cr = [];
458
-            $last_rank = 1;
455
+            $index=1;
456
+            $rank=1;
457
+            $last_cr=[];
458
+            $last_rank=1;
459 459
             foreach ($contestRank as $cr) {
460
-                $last_rank = $index;
461
-                if(!empty($last_cr)){
462
-                    if($cr['solved'] == $last_cr['solved'] && $cr['penalty'] == $last_cr['penalty'] ){
463
-                        $rank = $last_rank;
464
-                    }else{
465
-                        $rank = $index;
466
-                        $last_rank = $rank;
460
+                $last_rank=$index;
461
+                if (!empty($last_cr)) {
462
+                    if ($cr['solved']==$last_cr['solved'] && $cr['penalty']==$last_cr['penalty']) {
463
+                        $rank=$last_rank;
464
+                    } else {
465
+                        $rank=$index;
466
+                        $last_rank=$rank;
467 467
                     }
468 468
                 }
469
-                if(in_array($cr['uid'],array_keys($memberData))) {
470
-                    $memberData[$cr['uid']]['solved_all'] += $cr['solved'];
471
-                    $memberData[$cr['uid']]['problem_all'] += $problemsCount;
472
-                    $memberData[$cr['uid']]['penalty'] += $cr['penalty'];
473
-                    $memberData[$cr['uid']]['contest_detial'][$c['cid']] = [
469
+                if (in_array($cr['uid'], array_keys($memberData))) {
470
+                    $memberData[$cr['uid']]['solved_all']+=$cr['solved'];
471
+                    $memberData[$cr['uid']]['problem_all']+=$problemsCount;
472
+                    $memberData[$cr['uid']]['penalty']+=$cr['penalty'];
473
+                    $memberData[$cr['uid']]['contest_detial'][$c['cid']]=[
474 474
                         'rank' => $rank,
475 475
                         'solved' => $cr['solved'],
476 476
                         'problems' => $problemsCount,
477 477
                         'penalty' => $cr['penalty']
478 478
                     ];
479 479
                 }
480
-                $last_cr = $cr;
480
+                $last_cr=$cr;
481 481
                 $index++;
482 482
             }
483 483
         }
484
-        $new_memberData = [];
484
+        $new_memberData=[];
485 485
         foreach ($memberData as $uid => $data) {
486
-            $contest_count = 0;
487
-            $rank_sum = 0;
486
+            $contest_count=0;
487
+            $rank_sum=0;
488 488
             foreach ($data['contest_detial'] as $cid => $c) {
489
-                $rank_sum += $c['rank'];
490
-                $contest_count += 1;
489
+                $rank_sum+=$c['rank'];
490
+                $contest_count+=1;
491 491
             }
492
-            $temp = $data;
493
-            $temp['uid'] = $uid;
494
-            if($contest_count != 0){
495
-                $temp['rank_ave'] = $rank_sum/$contest_count;
492
+            $temp=$data;
493
+            $temp['uid']=$uid;
494
+            if ($contest_count!=0) {
495
+                $temp['rank_ave']=$rank_sum / $contest_count;
496 496
             }
497
-            array_push($new_memberData,$temp);
497
+            array_push($new_memberData, $temp);
498 498
         }
499
-        $ret = [
499
+        $ret=[
500 500
             'contest_list' => $allPracticeContest,
501 501
             'member_data' => $new_memberData
502 502
         ];
@@ -505,58 +505,58 @@  discard block
 block discarded – undo
505 505
 
506 506
     public function groupMemberPracticeTagStat($gid)
507 507
     {
508
-        $tags = $this->problemTags($gid);
509
-        $tag_problems = [];
508
+        $tags=$this->problemTags($gid);
509
+        $tag_problems=[];
510 510
 
511
-        $user_list = $this->userList($gid);
511
+        $user_list=$this->userList($gid);
512 512
         foreach ($tags as $tag) {
513
-            $tag_problems[$tag] = DB::table('problem')
514
-                ->join('group_problem_tag','problem.pid','=','group_problem_tag.pid')
513
+            $tag_problems[$tag]=DB::table('problem')
514
+                ->join('group_problem_tag', 'problem.pid', '=', 'group_problem_tag.pid')
515 515
                 ->where([
516 516
                     'group_problem_tag.gid' => $gid,
517 517
                     'tag' => $tag
518 518
                 ])
519
-                ->select('group_problem_tag.pid as pid','pcode','title')
519
+                ->select('group_problem_tag.pid as pid', 'pcode', 'title')
520 520
                 ->get()->all();
521 521
         }
522
-        $all_problems = [];
522
+        $all_problems=[];
523 523
         foreach ($tag_problems as &$tag_problem_set) {
524 524
             foreach ($tag_problem_set as $problem) {
525
-                $all_problems[$problem['pid']] = $problem;
525
+                $all_problems[$problem['pid']]=$problem;
526 526
             }
527
-            $tag_problem_set = array_column($tag_problem_set,'pid');
527
+            $tag_problem_set=array_column($tag_problem_set, 'pid');
528 528
         }
529
-        $submission_data =  DB::table('submission')
530
-            ->whereIn('pid',array_keys($all_problems))
531
-            ->whereIn('uid',array_column($user_list,'uid'))
532
-            ->where('verdict','Accepted')
533
-            ->select('pid','uid')
529
+        $submission_data=DB::table('submission')
530
+            ->whereIn('pid', array_keys($all_problems))
531
+            ->whereIn('uid', array_column($user_list, 'uid'))
532
+            ->where('verdict', 'Accepted')
533
+            ->select('pid', 'uid')
534 534
             ->get()->all();
535 535
 
536
-        $memberData = [];
536
+        $memberData=[];
537 537
         foreach ($user_list as $member) {
538
-            $completion = [];
539
-            foreach($tag_problems as $tag => $problems) {
540
-                $completion[$tag] = [];
538
+            $completion=[];
539
+            foreach ($tag_problems as $tag => $problems) {
540
+                $completion[$tag]=[];
541 541
                 foreach ($problems as $problem) {
542
-                    $is_accepted = 0;
542
+                    $is_accepted=0;
543 543
                     foreach ($submission_data as $sd) {
544
-                        if($sd['pid'] == $problem && $sd['uid'] == $member['uid']){
545
-                            $is_accepted = 1;
544
+                        if ($sd['pid']==$problem && $sd['uid']==$member['uid']) {
545
+                            $is_accepted=1;
546 546
                             break;
547 547
                         }
548 548
                     }
549
-                    $completion[$tag][$problem] = $is_accepted;
549
+                    $completion[$tag][$problem]=$is_accepted;
550 550
                 }
551 551
             }
552
-            array_push($memberData,[
552
+            array_push($memberData, [
553 553
                 'uid' => $member['uid'],
554 554
                 'name' => $member['name'],
555 555
                 'nick_name' => $member['nick_name'],
556 556
                 'completion' => $completion,
557 557
             ]);
558 558
         }
559
-        $ret = [
559
+        $ret=[
560 560
             'all_problems' => $all_problems,
561 561
             'tag_problems' => $tag_problems,
562 562
             'member_data' => $memberData
@@ -567,29 +567,29 @@  discard block
 block discarded – undo
567 567
     public function refreshElo($gid)
568 568
     {
569 569
         DB::table('group_rated_change_log')
570
-            ->where('gid',$gid)
570
+            ->where('gid', $gid)
571 571
             ->delete();
572 572
         DB::table('group_member')
573
-            ->where('gid',$gid)
573
+            ->where('gid', $gid)
574 574
             ->update([
575 575
                 'ranking' => 1500
576 576
             ]);
577
-        $contests = DB::table('contest')
577
+        $contests=DB::table('contest')
578 578
             ->where([
579 579
                 'gid' => $gid,
580 580
                 'practice' => 1
581 581
             ])
582
-            ->where('end_time','<',date("Y-m-d H:i:s"))
582
+            ->where('end_time', '<', date("Y-m-d H:i:s"))
583 583
             ->select('cid')
584 584
             ->orderBy('end_time')
585 585
             ->get()->all();
586 586
 
587
-        if(empty($contests)) {
587
+        if (empty($contests)) {
588 588
             return true;
589 589
         }
590 590
 
591 591
         foreach ($contests as $contest) {
592
-            $calc = new GroupRatingCalculator($contest['cid']);
592
+            $calc=new GroupRatingCalculator($contest['cid']);
593 593
             $calc->calculate();
594 594
             $calc->storage();
595 595
         }
@@ -597,10 +597,10 @@  discard block
 block discarded – undo
597 597
         return true;
598 598
     }
599 599
 
600
-    public function getEloChangeLog($gid,$uid)
600
+    public function getEloChangeLog($gid, $uid)
601 601
     {
602 602
         return DB::table('group_rated_change_log')
603
-            ->join('contest','group_rated_change_log.cid','=','contest.cid')
603
+            ->join('contest', 'group_rated_change_log.cid', '=', 'contest.cid')
604 604
             ->where([
605 605
                 'group_rated_change_log.gid' => $gid,
606 606
                 'group_rated_change_log.uid' => $uid
Please login to merge, or discard this patch.