Passed
Pull Request — master (#216)
by Chenyi
04:17
created
app/Http/Controllers/Ajax/AccountController.php 2 patches
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 class AccountController extends Controller
17 17
 {
18 18
 
19
-    public function updateAvatar(Request $request){
19
+    public function updateAvatar(Request $request) {
20 20
         $isValid=$request->file('avatar')->isValid();
21 21
         if ($isValid) {
22 22
             $extension=$request->file('avatar')->extension();
@@ -43,13 +43,13 @@  discard block
 block discarded – undo
43 43
         }
44 44
     }
45 45
 
46
-    public function changeBasicInfo(Request $request){
46
+    public function changeBasicInfo(Request $request) {
47 47
         // if(!$request->has('username')){
48 48
         //     return ResponseModel::err(1003);
49 49
         // }
50 50
         // $username = $request->input('username');
51
-        $describes = $request->input('describes');
52
-        if(strlen($describes) > 255){
51
+        $describes=$request->input('describes');
52
+        if (strlen($describes)>255) {
53 53
             return ResponseModel::err(1006);
54 54
         }
55 55
         // $old_username=Auth::user()->name;
@@ -58,79 +58,79 @@  discard block
 block discarded – undo
58 58
         // }
59 59
         $user=Auth::user();
60 60
         // $user->name = $username;
61
-        $user->describes = $describes;
61
+        $user->describes=$describes;
62 62
         $user->save();
63 63
         return ResponseModel::success();
64 64
     }
65 65
 
66
-    public function changePassword(Request $request){
67
-        if(!$request->has('old_password') || !$request->has('new_password') || !$request->has('confirm_password')){
66
+    public function changePassword(Request $request) {
67
+        if (!$request->has('old_password') || !$request->has('new_password') || !$request->has('confirm_password')) {
68 68
             return ResponseModel::err(1003);
69 69
         }
70
-        $old_password = $request->input('old_password');
71
-        $new_password = $request->input('new_password');
72
-        $confirm_password = $request->input('confirm_password');
73
-        if($new_password != $confirm_password){
70
+        $old_password=$request->input('old_password');
71
+        $new_password=$request->input('new_password');
72
+        $confirm_password=$request->input('confirm_password');
73
+        if ($new_password!=$confirm_password) {
74 74
             return ResponseModel::err(2004);
75 75
         }
76
-        if(strlen($new_password) < 8 || strlen($old_password) < 8){
76
+        if (strlen($new_password)<8 || strlen($old_password)<8) {
77 77
             return ResponseModel::err(1006);
78 78
         }
79
-        $user = Auth::user();
80
-        if(!Hash::check($old_password, $user->password)){
79
+        $user=Auth::user();
80
+        if (!Hash::check($old_password, $user->password)) {
81 81
             return ResponseModel::err(2005);
82 82
         }
83
-        $user->password = Hash::make($new_password);
83
+        $user->password=Hash::make($new_password);
84 84
         $user->save();
85 85
         return ResponseModel::success();
86 86
     }
87 87
 
88
-    public function checkEmailCooldown(Request $request){
89
-        $last_send = $request->session()->get('last_email_send');
90
-        if(empty($last_send) || time() - $last_send >= 300){
91
-            $request->session()->put('last_email_send',time());
92
-            return ResponseModel::success(200,null,0);
93
-        }else{
94
-            $cooldown =  300 - (time() - $last_send);
95
-            return ResponseModel::success(200,null,$cooldown);
88
+    public function checkEmailCooldown(Request $request) {
89
+        $last_send=$request->session()->get('last_email_send');
90
+        if (empty($last_send) || time()-$last_send>=300) {
91
+            $request->session()->put('last_email_send', time());
92
+            return ResponseModel::success(200, null, 0);
93
+        } else {
94
+            $cooldown=300-(time()-$last_send);
95
+            return ResponseModel::success(200, null, $cooldown);
96 96
         }
97 97
     }
98 98
 
99
-    public function changeExtraInfo(Request $request){
100
-        $input = $request->input();
101
-        $allow_change = ['gender','contact','school','country','location'];
102
-        foreach($input as $key => $value){
103
-            if(!in_array($key,$allow_change)){
99
+    public function changeExtraInfo(Request $request) {
100
+        $input=$request->input();
101
+        $allow_change=['gender', 'contact', 'school', 'country', 'location'];
102
+        foreach ($input as $key => $value) {
103
+            if (!in_array($key, $allow_change)) {
104 104
                 return ResponseModel::error(1007);
105 105
             }
106 106
         }
107
-        $account_model = new AccountModel();
108
-        $user_id = Auth::user()->id;
107
+        $account_model=new AccountModel();
108
+        $user_id=Auth::user()->id;
109 109
         foreach ($input as $key => $value) {
110
-            if(strlen($value) != 0){
111
-                $account_model->setExtra($user_id,$key,$value,0);
112
-            }else{
113
-                $account_model->setExtra($user_id,$key,null);
110
+            if (strlen($value)!=0) {
111
+                $account_model->setExtra($user_id, $key, $value, 0);
112
+            } else {
113
+                $account_model->setExtra($user_id, $key, null);
114 114
             }
115 115
         }
116 116
         return ResponseModel::success();
117 117
     }
118 118
 
119
-    public function saveEditorWidth(Request $request){
120
-        $input = $request->input();
121
-        $allow_change = ['editor_left_width'];
122
-        foreach($input as $key => $value){
123
-            if(!in_array($key,$allow_change)){
119
+    public function saveEditorWidth(Request $request) {
120
+        $input=$request->input();
121
+        $allow_change=['editor_left_width'];
122
+        foreach ($input as $key => $value) {
123
+            if (!in_array($key, $allow_change)) {
124 124
                 return ResponseModel::error(1007);
125 125
             }
126 126
         }
127
-        $account_model = new AccountModel();
128
-        $user_id = Auth::user()->id;
127
+        $account_model=new AccountModel();
128
+        $user_id=Auth::user()->id;
129 129
         foreach ($input as $key => $value) {
130
-            if(strlen($value) != 0){
131
-                $account_model->setExtra($user_id,$key,$value,0);
132
-            }else{
133
-                $account_model->setExtra($user_id,$key,null);
130
+            if (strlen($value)!=0) {
131
+                $account_model->setExtra($user_id, $key, $value, 0);
132
+            } else {
133
+                $account_model->setExtra($user_id, $key, null);
134 134
             }
135 135
         }
136 136
         return ResponseModel::success();
Please login to merge, or discard this patch.
Braces   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
         if(empty($last_send) || time() - $last_send >= 300){
91 91
             $request->session()->put('last_email_send',time());
92 92
             return ResponseModel::success(200,null,0);
93
-        }else{
93
+        } else{
94 94
             $cooldown =  300 - (time() - $last_send);
95 95
             return ResponseModel::success(200,null,$cooldown);
96 96
         }
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
         foreach ($input as $key => $value) {
110 110
             if(strlen($value) != 0){
111 111
                 $account_model->setExtra($user_id,$key,$value,0);
112
-            }else{
112
+            } else{
113 113
                 $account_model->setExtra($user_id,$key,null);
114 114
             }
115 115
         }
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
         foreach ($input as $key => $value) {
130 130
             if(strlen($value) != 0){
131 131
                 $account_model->setExtra($user_id,$key,$value,0);
132
-            }else{
132
+            } else{
133 133
                 $account_model->setExtra($user_id,$key,null);
134 134
             }
135 135
         }
Please login to merge, or discard this patch.
app/Babel/Submit/Submitter.php 2 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -35,7 +35,9 @@
 block discarded – undo
35 35
         ];
36 36
 
37 37
         $submitter=self::create($this->post_data["oj"], $sub, $all_data);
38
-        if(!is_null($submitter)) $submitter->submit();
38
+        if(!is_null($submitter)) {
39
+            $submitter->submit();
40
+        }
39 41
 
40 42
         // insert submission
41 43
 
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
         ];
33 33
 
34 34
         $submitter=self::create($this->post_data["oj"], $sub, $all_data);
35
-        if(!is_null($submitter)) $submitter->submit();
35
+        if (!is_null($submitter)) $submitter->submit();
36 36
 
37 37
         // insert submission
38 38
 
@@ -40,16 +40,16 @@  discard block
 block discarded – undo
40 40
         $submission->updateSubmission($this->post_data["sid"], $sub);
41 41
     }
42 42
 
43
-    public static function create($oj,& $sub, $all_data) {
43
+    public static function create($oj, & $sub, $all_data) {
44 44
         $submitterProvider="Submitter";
45 45
         try {
46 46
             $BabelConfig=json_decode(file_get_contents(babel_path("Extension/$oj/babel.json")), true);
47 47
             $submitterProvider=$BabelConfig["provider"]["submitter"];
48
-        } catch(ErrorException $e) {
49
-        } catch(Exception $e) {
48
+        } catch (ErrorException $e) {
49
+        } catch (Exception $e) {
50 50
         }
51
-        $className = "App\\Babel\\Extension\\$oj\\$submitterProvider";
52
-        if(class_exists($className)) {
51
+        $className="App\\Babel\\Extension\\$oj\\$submitterProvider";
52
+        if (class_exists($className)) {
53 53
             return new $className($sub, $all_data);
54 54
         } else {
55 55
             return null;
Please login to merge, or discard this patch.
app/Models/AccountModel.php 2 patches
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 
12 12
 class AccountModel extends Model
13 13
 {
14
-    private $user_extra = [
14
+    private $user_extra=[
15 15
         0     => 'gender',
16 16
         1     => 'contact',
17 17
         2     => 'school',
@@ -26,11 +26,11 @@  discard block
 block discarded – undo
26 26
         1004  => 'github_token',
27 27
     ];
28 28
 
29
-    private $socialite_support = [
29
+    private $socialite_support=[
30 30
         //use the form "platform_id" for unique authentication
31 31
         //such as github_id
32 32
         'github' => [
33
-            'email','nickname','homepage','token'
33
+            'email', 'nickname', 'homepage', 'token'
34 34
         ],
35 35
     ];
36 36
 
@@ -48,8 +48,8 @@  discard block
 block discarded – undo
48 48
     public function feed($uid=null)
49 49
     {
50 50
         $ret=[];
51
-        $solution=DB::table("problem_solution")->join("problem","problem.pid","=","problem_solution.pid")->where(["uid"=>$uid,"audit"=>1])->select("problem.pid as pid","pcode","title","problem_solution.created_at as created_at")->orderBy("problem_solution.created_at","DESC")->get()->all();
52
-        foreach($solution as &$s){
51
+        $solution=DB::table("problem_solution")->join("problem", "problem.pid", "=", "problem_solution.pid")->where(["uid"=>$uid, "audit"=>1])->select("problem.pid as pid", "pcode", "title", "problem_solution.created_at as created_at")->orderBy("problem_solution.created_at", "DESC")->get()->all();
52
+        foreach ($solution as &$s) {
53 53
             $s["type"]="event";
54 54
             $s["color"]="wemd-orange";
55 55
             $s["icon"]="comment-check-outline";
@@ -115,14 +115,14 @@  discard block
 block discarded – undo
115 115
         ])->join("problem", "problem.pid", "=", "submission.pid")->select('pcode')->distinct()->get()->all();
116 116
         $ret["solvedCount"]=count($ret["solved"]);
117 117
         // Casual
118
-        $ret["rank"]=Cache::tags(['rank',$ret["id"]])->get("rank", "N/A");
119
-        $ret["rankTitle"]=Cache::tags(['rank',$ret["id"]])->get("title");
118
+        $ret["rank"]=Cache::tags(['rank', $ret["id"]])->get("rank", "N/A");
119
+        $ret["rankTitle"]=Cache::tags(['rank', $ret["id"]])->get("title");
120 120
         $ret["rankTitleColor"]=RankModel::getColor($ret["rankTitle"]);
121 121
         // Professional
122 122
         $ret["professionalTitle"]=RankModel::getProfessionalTitle($ret["professional_rate"]);
123 123
         $ret["professionalTitleColor"]=RankModel::getProfessionalColor($ret["professionalTitle"]);
124 124
         // Administration Group
125
-        $ret["admin"]=$uid==1?1:0;
125
+        $ret["admin"]=$uid==1 ? 1 : 0;
126 126
         if (Cache::tags(['bing', 'pic'])->get(date("Y-m-d"))==null) {
127 127
             $bing=new BingPhoto([
128 128
                 'locale' => 'zh-CN',
@@ -141,26 +141,26 @@  discard block
 block discarded – undo
141 141
      * @param string|array $need An array is returned when an array is passed in,Only one value is returned when a string is passed in.
142 142
      * @return string|array $result
143 143
      */
144
-    public function getExtra($uid,$need, $secret_level = 0){
145
-        $ret = DB::table('users_extra')->where('uid',$uid)->orderBy('key')->get()->all();
146
-        $result = [];
147
-        if(!empty($ret)){
148
-            if(is_string($need)){
144
+    public function getExtra($uid, $need, $secret_level=0) {
145
+        $ret=DB::table('users_extra')->where('uid', $uid)->orderBy('key')->get()->all();
146
+        $result=[];
147
+        if (!empty($ret)) {
148
+            if (is_string($need)) {
149 149
                 foreach ($ret as $value) {
150
-                    if(empty($value['secret_level']) || $value['secret_level'] <= $secret_level){
151
-                        $key_name = $this->user_extra[$value['key']] ?? 'unknown';
152
-                        if($key_name == $need){
150
+                    if (empty($value['secret_level']) || $value['secret_level']<=$secret_level) {
151
+                        $key_name=$this->user_extra[$value['key']] ?? 'unknown';
152
+                        if ($key_name==$need) {
153 153
                             return $value['value'];
154 154
                         }
155 155
                     }
156 156
                 }
157 157
                 return null;
158
-            }else{
158
+            } else {
159 159
                 foreach ($ret as $value) {
160
-                    if(empty($value['secret_level']) || $value['secret_level'] <= $secret_level){
161
-                        $key_name = $this->user_extra[$value['key']] ?? 'unknown';
162
-                        if(in_array($key_name,$need)){
163
-                            $result[$key_name] = $value['value'];
160
+                    if (empty($value['secret_level']) || $value['secret_level']<=$secret_level) {
161
+                        $key_name=$this->user_extra[$value['key']] ?? 'unknown';
162
+                        if (in_array($key_name, $need)) {
163
+                            $result[$key_name]=$value['value'];
164 164
                         }
165 165
                     }
166 166
                 }
@@ -177,26 +177,26 @@  discard block
 block discarded – undo
177 177
      * @param string|null $value the extra info will be delete when value is null
178 178
      * @return mixed $result
179 179
      */
180
-    public function setExtra($uid,$key_name,$value = null,$secret_level = -1){
181
-        $key = array_search($key_name,$this->user_extra);
182
-        if($key === false){
180
+    public function setExtra($uid, $key_name, $value=null, $secret_level=-1) {
181
+        $key=array_search($key_name, $this->user_extra);
182
+        if ($key===false) {
183 183
             return false;
184 184
         }
185
-        $ret = DB::table('users_extra')->where('uid',$uid)->where('key',$key)->first();
186
-        if(!empty($ret)){
185
+        $ret=DB::table('users_extra')->where('uid', $uid)->where('key', $key)->first();
186
+        if (!empty($ret)) {
187 187
             unset($ret['id']);
188
-            if(!is_null($value)){
189
-                $ret['value'] = $value;
190
-            }else{
191
-                DB::table('users_extra')->where('uid',$uid)->where('key',$key)->delete();
188
+            if (!is_null($value)) {
189
+                $ret['value']=$value;
190
+            } else {
191
+                DB::table('users_extra')->where('uid', $uid)->where('key', $key)->delete();
192 192
                 return true;
193 193
             }
194
-            if($secret_level != -1){
195
-                $ret['secret_level'] = $secret_level;
194
+            if ($secret_level!=-1) {
195
+                $ret['secret_level']=$secret_level;
196 196
             }
197
-            return DB::table('users_extra')->where('uid',$uid)->where('key',$key)->update($ret);
198
-        }else{
199
-            if($value === null){
197
+            return DB::table('users_extra')->where('uid', $uid)->where('key', $key)->update($ret);
198
+        } else {
199
+            if ($value===null) {
200 200
                 return true;
201 201
             }
202 202
             return DB::table('users_extra')->insertGetId(
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
                     'uid' => $uid,
205 205
                     'key' => $key,
206 206
                     'value' => $value,
207
-                    'secret_level' => $secret_level == -1 ? 0 : $secret_level,
207
+                    'secret_level' => $secret_level==-1 ? 0 : $secret_level,
208 208
                 ]
209 209
             );
210 210
         }
@@ -216,31 +216,31 @@  discard block
 block discarded – undo
216 216
      * @param string $value the value
217 217
      * @return string $result
218 218
      */
219
-    public function findExtra($key,$value){
220
-        $key = array_search($key,$this->user_extra);
221
-        if($key){
222
-            return DB::table('users_extra')->where('key',$key)->where('value',$value)->first();
223
-        }else{
219
+    public function findExtra($key, $value) {
220
+        $key=array_search($key, $this->user_extra);
221
+        if ($key) {
222
+            return DB::table('users_extra')->where('key', $key)->where('value', $value)->first();
223
+        } else {
224 224
             return null;
225 225
         }
226 226
     }
227 227
 
228
-    public function getSocialiteInfo($uid,$secret_level = -1){
229
-        $socialites = [];
228
+    public function getSocialiteInfo($uid, $secret_level=-1) {
229
+        $socialites=[];
230 230
         foreach ($this->socialite_support as $key => $value) {
231
-            $id_keyname = $key.'_id';
232
-            $id = $this->getExtra($uid,$id_keyname);
233
-            if(!empty($id)){
234
-                $info = [
231
+            $id_keyname=$key.'_id';
232
+            $id=$this->getExtra($uid, $id_keyname);
233
+            if (!empty($id)) {
234
+                $info=[
235 235
                     'id' => $id,
236 236
                 ];
237 237
                 foreach ($value as $info_name) {
238
-                    $info_temp = $this->getExtra($uid,$key.'_'.$info_name);
239
-                    if($info_temp !== null){
240
-                        $info[$info_name] = $info_temp;
238
+                    $info_temp=$this->getExtra($uid, $key.'_'.$info_name);
239
+                    if ($info_temp!==null) {
240
+                        $info[$info_name]=$info_temp;
241 241
                     }
242 242
                 }
243
-                $socialites[$key] = $info;
243
+                $socialites[$key]=$info;
244 244
             }
245 245
         }
246 246
 
Please login to merge, or discard this patch.
Braces   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
                     }
156 156
                 }
157 157
                 return null;
158
-            }else{
158
+            } else{
159 159
                 foreach ($ret as $value) {
160 160
                     if(empty($value['secret_level']) || $value['secret_level'] <= $secret_level){
161 161
                         $key_name = $this->user_extra[$value['key']] ?? 'unknown';
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
             unset($ret['id']);
188 188
             if(!is_null($value)){
189 189
                 $ret['value'] = $value;
190
-            }else{
190
+            } else{
191 191
                 DB::table('users_extra')->where('uid',$uid)->where('key',$key)->delete();
192 192
                 return true;
193 193
             }
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
                 $ret['secret_level'] = $secret_level;
196 196
             }
197 197
             return DB::table('users_extra')->where('uid',$uid)->where('key',$key)->update($ret);
198
-        }else{
198
+        } else{
199 199
             if($value === null){
200 200
                 return true;
201 201
             }
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
         $key = array_search($key,$this->user_extra);
221 221
         if($key){
222 222
             return DB::table('users_extra')->where('key',$key)->where('value',$value)->first();
223
-        }else{
223
+        } else{
224 224
             return null;
225 225
         }
226 226
     }
Please login to merge, or discard this patch.
app/Http/Controllers/ProblemController.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -131,8 +131,8 @@
 block discarded – undo
131 131
             ];
132 132
         }
133 133
 
134
-        $editor_left_width = $account->getExtra(Auth::user()->id, 'editor_left_width');
135
-        if(empty($editor_left_width)) $editor_left_width='40';
134
+        $editor_left_width=$account->getExtra(Auth::user()->id, 'editor_left_width');
135
+        if (empty($editor_left_width)) $editor_left_width='40';
136 136
 
137 137
         return is_null($prob_detail) ?  redirect("/problem") : view('problem.editor', [
138 138
                                             'page_title'=>$prob_detail["title"],
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -132,7 +132,9 @@
 block discarded – undo
132 132
         }
133 133
 
134 134
         $editor_left_width = $account->getExtra(Auth::user()->id, 'editor_left_width');
135
-        if(empty($editor_left_width)) $editor_left_width='40';
135
+        if(empty($editor_left_width)) {
136
+            $editor_left_width='40';
137
+        }
136 138
 
137 139
         return is_null($prob_detail) ?  redirect("/problem") : view('problem.editor', [
138 140
                                             'page_title'=>$prob_detail["title"],
Please login to merge, or discard this patch.
app/Models/Rating/GroupRatingCalculator.php 2 patches
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@
 block discarded – undo
78 78
             $mid = floor(($right + $left)/2);
79 79
             if($this->getSeed($mid) < $rank){
80 80
                 $right = $mid;
81
-            }else{
81
+            } else{
82 82
                 $left = $mid;
83 83
             }
84 84
         }
Please login to merge, or discard this patch.
Spacing   +84 added lines, -84 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
-        $this->totParticipants = count($contestRankRaw);
35
-        $members = array_column($contestRankRaw,'uid');
36
-        $ratings_temp = DB::table('group_member')
33
+        $contestRankRaw=array_values($contestRankRaw);
34
+        $this->totParticipants=count($contestRankRaw);
35
+        $members=array_column($contestRankRaw, 'uid');
36
+        $ratings_temp=DB::table('group_member')
37 37
             ->where([
38 38
                 'gid' => $this->gid,
39
-            ])->whereIn('uid',$members)
40
-            ->select('uid','ranking')
39
+            ])->whereIn('uid', $members)
40
+            ->select('uid', 'ranking')
41 41
             ->get()->all();
42
-        $ratings = [];
42
+        $ratings=[];
43 43
         foreach ($ratings_temp as $rating) {
44
-            $ratings[$rating['uid']] = $rating['ranking'];
44
+            $ratings[$rating['uid']]=$rating['ranking'];
45 45
         }
46
-        foreach($contestRankRaw as $c){
46
+        foreach ($contestRankRaw as $c) {
47 47
             $this->contestants[]=[
48 48
                 "uid"=>$c["uid"],
49 49
                 "points"=>$c["score"],
@@ -52,84 +52,84 @@  discard block
 block discarded – undo
52 52
         }
53 53
     }
54 54
 
55
-    private function reassignRank(){
55
+    private function reassignRank() {
56 56
         $this->sort("points");
57
-        $idx = 0;
58
-        $points = $this->contestants[0]["points"];
59
-        $i = 1;
60
-        while($i < $this->totParticipants){
61
-            if($this->contestants[$i]["points"] < $points){
62
-                $j = $idx;
63
-                while($j < $i){
64
-                    $this->contestants[$j]["rank"] = $i;
65
-                    $j += 1;
57
+        $idx=0;
58
+        $points=$this->contestants[0]["points"];
59
+        $i=1;
60
+        while ($i<$this->totParticipants) {
61
+            if ($this->contestants[$i]["points"]<$points) {
62
+                $j=$idx;
63
+                while ($j<$i) {
64
+                    $this->contestants[$j]["rank"]=$i;
65
+                    $j+=1;
66 66
                 }
67
-                $idx = $i;
68
-                $points = $this->contestants[$i]["points"];
67
+                $idx=$i;
68
+                $points=$this->contestants[$i]["points"];
69 69
             }
70
-            $i += 1;
70
+            $i+=1;
71 71
         }
72
-        $j = $idx;
73
-        while($j < $this->totParticipants){
74
-            $this->contestants[$j]["rank"] = $this->totParticipants;
75
-            $j += 1;
72
+        $j=$idx;
73
+        while ($j<$this->totParticipants) {
74
+            $this->contestants[$j]["rank"]=$this->totParticipants;
75
+            $j+=1;
76 76
         }
77 77
     }
78 78
 
79
-    private function getEloWinProbability($Ra, $Rb){
80
-        return 1.0 / (1 + pow(10, ($Rb-$Ra)/400.0));
79
+    private function getEloWinProbability($Ra, $Rb) {
80
+        return 1.0 / (1+pow(10, ($Rb-$Ra) / 400.0));
81 81
     }
82 82
 
83
-    private function getSeed($rating){
84
-        $result = 1.0;
85
-        foreach($this->contestants as $other){
86
-            $result += $this->getEloWinProbability($other["rating"], $rating);
83
+    private function getSeed($rating) {
84
+        $result=1.0;
85
+        foreach ($this->contestants as $other) {
86
+            $result+=$this->getEloWinProbability($other["rating"], $rating);
87 87
         }
88 88
         return $result;
89 89
     }
90 90
 
91
-    private function getRatingToRank($rank){
91
+    private function getRatingToRank($rank) {
92 92
         $left=1;
93 93
         $right=8000;
94
-        while($right - $left > 1){
95
-            $mid = floor(($right + $left)/2);
96
-            if($this->getSeed($mid) < $rank){
97
-                $right = $mid;
98
-            }else{
99
-                $left = $mid;
94
+        while ($right-$left>1) {
95
+            $mid=floor(($right+$left) / 2);
96
+            if ($this->getSeed($mid)<$rank) {
97
+                $right=$mid;
98
+            } else {
99
+                $left=$mid;
100 100
             }
101 101
         }
102 102
         return $left;
103 103
     }
104 104
 
105
-    private function sort($key){
106
-        usort($this->contestants, function ($a, $b) use ($key) {
105
+    private function sort($key) {
106
+        usort($this->contestants, function($a, $b) use ($key) {
107 107
             return $b[$key] <=> $a[$key];
108 108
         });
109 109
     }
110 110
 
111
-    public function calculate(){
112
-        if(empty($this->contestants)){
111
+    public function calculate() {
112
+        if (empty($this->contestants)) {
113 113
             return;
114 114
         }
115 115
 
116 116
         // recalc rank
117 117
         $this->reassignRank();
118 118
 
119
-        foreach($this->contestants as &$member){
120
-            $member["seed"] = 1.0;
121
-            foreach($this->contestants as $other){
122
-                if($member["uid"] != $other["uid"]){
123
-                    $member["seed"] += $this->getEloWinProbability($other["rating"], $member["rating"]);
119
+        foreach ($this->contestants as &$member) {
120
+            $member["seed"]=1.0;
121
+            foreach ($this->contestants as $other) {
122
+                if ($member["uid"]!=$other["uid"]) {
123
+                    $member["seed"]+=$this->getEloWinProbability($other["rating"], $member["rating"]);
124 124
                 }
125 125
             }
126 126
         }
127 127
         unset($member);
128 128
 
129
-        foreach($this->contestants as &$contestant){
130
-            $midRank = sqrt($contestant["rank"] * $contestant["seed"]);
131
-            $contestant["needRating"] = $this->getRatingToRank($midRank);
132
-            $contestant["delta"] = floor(($contestant["needRating"] - $contestant["rating"])/2);
129
+        foreach ($this->contestants as &$contestant) {
130
+            $midRank=sqrt($contestant["rank"] * $contestant["seed"]);
131
+            $contestant["needRating"]=$this->getRatingToRank($midRank);
132
+            $contestant["delta"]=floor(($contestant["needRating"]-$contestant["rating"]) / 2);
133 133
         }
134 134
         unset($contestant);
135 135
 
@@ -137,39 +137,39 @@  discard block
 block discarded – undo
137 137
 
138 138
         // DO some adjuct
139 139
         // Total sum should not be more than ZERO.
140
-        $sum = 0;
140
+        $sum=0;
141 141
 
142
-        foreach($this->contestants as $contestant){
143
-            $sum += $contestant["delta"];
142
+        foreach ($this->contestants as $contestant) {
143
+            $sum+=$contestant["delta"];
144 144
         }
145
-        $inc = -floor($sum / $this->totParticipants) - 1;
146
-        foreach($this->contestants as &$contestant){
147
-            $contestant["delta"] += $inc;
145
+        $inc=-floor($sum / $this->totParticipants)-1;
146
+        foreach ($this->contestants as &$contestant) {
147
+            $contestant["delta"]+=$inc;
148 148
         }
149 149
         unset($contestant);
150 150
 
151 151
         // Sum of top-4*sqrt should be adjusted to ZERO.
152 152
 
153
-        $sum = 0;
154
-        $zeroSumCount = min(intval(4*round(sqrt($this->totParticipants))), $this->totParticipants);
153
+        $sum=0;
154
+        $zeroSumCount=min(intval(4 * round(sqrt($this->totParticipants))), $this->totParticipants);
155 155
 
156
-        for($i=0;$i<$zeroSumCount;$i++){
157
-            $sum += $this->contestants[$i]["delta"];
156
+        for ($i=0; $i<$zeroSumCount; $i++) {
157
+            $sum+=$this->contestants[$i]["delta"];
158 158
         }
159 159
 
160
-        $inc = min(max(-floor($sum / $zeroSumCount), -10), 0);
160
+        $inc=min(max(-floor($sum / $zeroSumCount), -10), 0);
161 161
 
162
-        for($i=0;$i<$zeroSumCount;$i++){
163
-            $this->contestants[$i]["delta"] += $inc;
162
+        for ($i=0; $i<$zeroSumCount; $i++) {
163
+            $this->contestants[$i]["delta"]+=$inc;
164 164
         }
165 165
 
166 166
         return $this->validateDeltas();
167 167
     }
168 168
 
169
-    public function storage(){
169
+    public function storage() {
170 170
         $contestants=$this->contestants;
171
-        DB::transaction(function () use ($contestants) {
172
-            foreach($contestants as $contestant){
171
+        DB::transaction(function() use ($contestants) {
172
+            foreach ($contestants as $contestant) {
173 173
                 $newRating=$contestant["rating"]+$contestant["delta"];
174 174
                 DB::table("group_member")->where([
175 175
                     'gid' => $this->gid,
@@ -187,20 +187,20 @@  discard block
 block discarded – undo
187 187
         }, 5);
188 188
     }
189 189
 
190
-    private function validateDeltas(){
190
+    private function validateDeltas() {
191 191
         $this->sort("points");
192 192
 
193
-        for($i=0;$i<$this->totParticipants;$i++){
194
-            for($j=$i+1;$j<$this->totParticipants;$j++){
195
-                if($this->contestants[$i]["rating"] > $this->contestants[$j]["rating"]){
196
-                    if($this->contestants[$i]["rating"] + $this->contestants[$i]["delta"] < $this->contestants[$j]["rating"] + $this->contestants[$j]["delta"]){
193
+        for ($i=0; $i<$this->totParticipants; $i++) {
194
+            for ($j=$i+1; $j<$this->totParticipants; $j++) {
195
+                if ($this->contestants[$i]["rating"]>$this->contestants[$j]["rating"]) {
196
+                    if ($this->contestants[$i]["rating"]+$this->contestants[$i]["delta"]<$this->contestants[$j]["rating"]+$this->contestants[$j]["delta"]) {
197 197
                         Log::warning("First rating invariant failed: {$this->contestants[$i]["uid"]} vs. {$this->contestants[$j]["uid"]}.");
198 198
                         return false;
199 199
                     }
200 200
                 }
201 201
 
202
-                if($this->contestants[$i]["rating"] < $this->contestants[$j]["rating"]){
203
-                    if($this->contestants[$i]["delta"] < $this->contestants[$j]["delta"]){
202
+                if ($this->contestants[$i]["rating"]<$this->contestants[$j]["rating"]) {
203
+                    if ($this->contestants[$i]["delta"]<$this->contestants[$j]["delta"]) {
204 204
                         Log::warning("Second rating invariant failed: {$this->contestants[$i]["uid"]} vs.  {$this->contestants[$j]["uid"]}.");
205 205
                         return false;
206 206
                     }
Please login to merge, or discard this patch.
app/Models/CompilerModel.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -100,11 +100,11 @@
 block discarded – undo
100 100
 
101 101
     public static function add($row)
102 102
     {
103
-        if(self::checkExist([
103
+        if (self::checkExist([
104 104
             "oid"=>$row["oid"],
105 105
             "lcode"=>$row["lcode"],
106 106
             "deleted"=>0
107
-        ])){
107
+        ])) {
108 108
             throw new Exception("Duplicate Language Code");
109 109
         }
110 110
         return DB::table('compiler')->insert($row);
Please login to merge, or discard this patch.
app/Models/ContestModel.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -265,7 +265,7 @@
 block discarded – undo
265 265
                             $query=$query->where(["practice"=>$filter['practice']]);
266 266
                         }
267 267
                         $query->where('public', 1)
268
-                              ->where('audit_status', 1);
268
+                                ->where('audit_status', 1);
269 269
                     }
270 270
                 )
271 271
                 ->orWhere(
Please login to merge, or discard this patch.
Braces   +24 added lines, -25 removed lines patch added patch discarded remove patch
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
                     $paginator=$paginator->where(["practice"=>$filter['practice']]);
225 225
                 }
226 226
                 $paginator = $paginator ->paginate(10);
227
-            }elseif($filter['public']=='0'){
227
+            } elseif($filter['public']=='0'){
228 228
                 $paginator=DB::table('group_member')
229 229
                 ->groupBy('contest.cid')
230 230
                 ->select('contest.*')
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
                 )
255 255
                 ->orderBy('contest.begin_time', 'desc')
256 256
                 ->paginate(10);
257
-            }else{
257
+            } else{
258 258
                 $paginator=DB::table('group_member')
259 259
                 ->groupBy('contest.cid')
260 260
                 ->select('contest.*')
@@ -797,13 +797,13 @@  discard block
 block discarded – undo
797 797
         if(time() < $end_time){
798 798
             if($clearance == 3){
799 799
                 $contestRankRaw=Cache::tags(['contest', 'rank'])->get("contestAdmin$cid");
800
-            }else{
800
+            } else{
801 801
                 $contestRankRaw=Cache::tags(['contest', 'rank'])->get($cid);
802 802
             }
803 803
             if(!isset($contestRankRaw)){
804 804
                 $contestRankRaw=$this->contestRankCache($cid);
805 805
             }
806
-        }else{
806
+        } else{
807 807
             if($clearance == 3){
808 808
                 $contestRankRaw=Cache::tags(['contest', 'rank'])->get("contestAdmin$cid");
809 809
                 if (!isset($contestRankRaw)) {
@@ -813,7 +813,7 @@  discard block
 block discarded – undo
813 813
                         $this->storeContestRankInMySQL($cid, $contestRankRaw);
814 814
                     }
815 815
                 }
816
-            }else{
816
+            } else{
817 817
                 $contestRankRaw=$this->getContestRankFromMySQL($cid);
818 818
                 if(!isset($contestRankRaw)){
819 819
                     $contestRankRaw=Cache::tags(['contest', 'rank'])->get($cid);
@@ -898,7 +898,7 @@  discard block
 block discarded – undo
898 898
             return DB::table("contest_clarification")->where([
899 899
                 "cid"=>$cid
900 900
             ])->orderBy('create_time', 'desc')->get()->all();
901
-        }else{
901
+        } else{
902 902
             return DB::table("contest_clarification")->where([
903 903
                 "cid"=>$cid
904 904
             ])->where(function ($query) {
@@ -1135,7 +1135,7 @@  discard block
 block discarded – undo
1135 1135
                     "records"=>[]
1136 1136
                 ];
1137 1137
             }
1138
-        }else{
1138
+        } else{
1139 1139
             if ($basicInfo["status_visibility"]==2) {
1140 1140
                 // View all
1141 1141
                 $paginator=DB::table("submission")->where([
@@ -1357,7 +1357,7 @@  discard block
 block discarded – undo
1357 1357
             if($ratingCalculator->calculate()){
1358 1358
                 $ratingCalculator->storage();
1359 1359
                 return true;
1360
-            }else{
1360
+            } else{
1361 1361
                 return false;
1362 1362
             }
1363 1363
         } else {
@@ -1406,7 +1406,7 @@  discard block
 block discarded – undo
1406 1406
             $contestRankRaw = $this->contestRankCache($cid);
1407 1407
             Cache::tags(['contest', 'rank'])->put($cid, $contestRankRaw);
1408 1408
             Cache::tags(['contest', 'rank'])->put("contestAdmin$cid", $contestRankRaw);
1409
-        }else{
1409
+        } else{
1410 1410
             DB::table($this->tableName)
1411 1411
                 ->where('cid',$cid)
1412 1412
                 ->update($data);
@@ -1506,8 +1506,7 @@  discard block
 block discarded – undo
1506 1506
                     if(time() > $chache['end_time']){
1507 1507
                         $this->storeContestRankInMySQL($cid, $ret);
1508 1508
                     }
1509
-                }
1510
-                else{
1509
+                } else{
1511 1510
                     $ret=[];
1512 1511
                     $chache=[];
1513 1512
                     $chache['contest_info']=DB::table("contest")->where("cid", $cid)->first();
@@ -1522,7 +1521,7 @@  discard block
 block discarded – undo
1522 1521
                             "cid"=>$cid,
1523 1522
                             "audit"=>1
1524 1523
                         ])->select('uid')->get()->all();
1525
-                    }else{
1524
+                    } else{
1526 1525
                         $submissionUsers=DB::table("submission")->where([
1527 1526
                             "cid"=>$cid
1528 1527
                         ])->where(
@@ -1557,9 +1556,9 @@  discard block
 block discarded – undo
1557 1556
                     Cache::tags(['contest', 'rank'])->put("contestAdmin$cid", $retAdmin);
1558 1557
                 }
1559 1558
             }
1560
-        }catch(LockTimeoutException $e){
1559
+        } catch(LockTimeoutException $e){
1561 1560
             Log::warning("Contest Rank Lock Timed Out");
1562
-        }finally{
1561
+        } finally{
1563 1562
             optional($lock)->release();
1564 1563
         }
1565 1564
     }
@@ -1582,7 +1581,7 @@  discard block
 block discarded – undo
1582 1581
                     return 1;
1583 1582
                 }
1584 1583
             });
1585
-        }else if ($contest_info["rule"]==2){
1584
+        } else if ($contest_info["rule"]==2){
1586 1585
             usort($ret, function ($a, $b) {
1587 1586
                 if ($a["score"]==$b["score"]) {
1588 1587
                     if ($a["solved"]==$b["solved"]) {
@@ -1606,8 +1605,9 @@  discard block
 block discarded – undo
1606 1605
     {
1607 1606
         $id = count($ret);
1608 1607
         foreach($ret as $key => $r){
1609
-            if($r['uid'] == $uid)
1610
-                $id = $key;
1608
+            if($r['uid'] == $uid) {
1609
+                            $id = $key;
1610
+            }
1611 1611
         }
1612 1612
         if ($contest_info["rule"]==1) {
1613 1613
             // ACM/ICPC Mode
@@ -1615,7 +1615,7 @@  discard block
 block discarded – undo
1615 1615
                 $prob_detail = [];
1616 1616
                 $totPen = 0;
1617 1617
                 $totScore = 0;
1618
-            }else{
1618
+            } else{
1619 1619
                 $prob_detail = $ret[$id]['problem_detail'];
1620 1620
                 $totPen=$ret[$id]['penalty'];
1621 1621
                 $totScore=$ret[$id]['score'];
@@ -1670,7 +1670,7 @@  discard block
 block discarded – undo
1670 1670
                 $prob_detail = [];
1671 1671
                 $totSolved = 0;
1672 1672
                 $totScore = 0;
1673
-            }else{
1673
+            } else{
1674 1674
                 $prob_detail = $ret[$id]['problem_detail'];
1675 1675
                 $totSolved=$ret[$id]['solved'];
1676 1676
                 $totScore=$ret[$id]['score'];
@@ -1733,18 +1733,18 @@  discard block
 block discarded – undo
1733 1733
                 return false;
1734 1734
             }
1735 1735
             return true;
1736
-        }else if($status === 0){
1736
+        } else if($status === 0){
1737 1737
             if($begin_time_new !== null){
1738 1738
                 return false;
1739 1739
             }
1740 1740
             if($end_time_new !== null){
1741 1741
                 if(strtotime($end_time_new) <= time()){
1742 1742
                     return false;
1743
-                }else{
1743
+                } else{
1744 1744
                     return true;
1745 1745
                 }
1746 1746
             }
1747
-        }else{
1747
+        } else{
1748 1748
             return false;
1749 1749
         }
1750 1750
 
@@ -1765,8 +1765,7 @@  discard block
 block discarded – undo
1765 1765
             return DB::table("contest_clarification")->where('ccid','=',$ccid)->update([
1766 1766
                 "public"=>1
1767 1767
             ]);
1768
-        }
1769
-        else
1768
+        } else
1770 1769
         {
1771 1770
             return DB::table("contest_clarification")->where('ccid','=',$ccid)->update([
1772 1771
                 "public"=>0
@@ -1789,7 +1788,7 @@  discard block
 block discarded – undo
1789 1788
             ->whereIn('pid',array_column($contestRank[0]['problem_detail'],'pid'))
1790 1789
             ->select('pid','title')
1791 1790
             ->get()->all();
1792
-        }else{
1791
+        } else{
1793 1792
             $all_problems = [];
1794 1793
         }
1795 1794
         $tags = DB::table('group_problem_tag')
Please login to merge, or discard this patch.
Spacing   +200 added lines, -200 removed lines patch added patch discarded remove patch
@@ -111,8 +111,8 @@  discard block
 block discarded – undo
111 111
 
112 112
     public function gcode($cid)
113 113
     {
114
-        $gid = $this->gid($cid);
115
-        return DB::table('group')->where('gid','=',$gid)->first()["gcode"];
114
+        $gid=$this->gid($cid);
115
+        return DB::table('group')->where('gid', '=', $gid)->first()["gcode"];
116 116
     }
117 117
 
118 118
     public function runningContest()
@@ -137,19 +137,19 @@  discard block
 block discarded – undo
137 137
 
138 138
     public function listForSetting($gid)
139 139
     {
140
-        $uid = Auth::user()->id;
141
-        $group_contests = DB::table('contest')
142
-            ->where('gid',$gid)
143
-            ->orderBy('begin_time','desc')
140
+        $uid=Auth::user()->id;
141
+        $group_contests=DB::table('contest')
142
+            ->where('gid', $gid)
143
+            ->orderBy('begin_time', 'desc')
144 144
             ->get()->all();
145
-        $groupModel = new GroupModel();
146
-        $group_clearance = $groupModel->judgeClearance($gid,$uid);
145
+        $groupModel=new GroupModel();
146
+        $group_clearance=$groupModel->judgeClearance($gid, $uid);
147 147
         foreach ($group_contests as &$contest) {
148
-            $contest['is_admin'] = ($contest['assign_uid'] == $uid || $group_clearance == 3);
149
-            $contest['begin_stamps'] = strtotime($contest['begin_time']);
150
-            $contest['end_stamps'] = strtotime($contest['end_time']);
151
-            $contest['status'] = time() >= $contest['end_stamps'] ? 1
152
-                : (time() <= $contest['begin_stamps'] ? -1 : 0);
148
+            $contest['is_admin']=($contest['assign_uid']==$uid || $group_clearance==3);
149
+            $contest['begin_stamps']=strtotime($contest['begin_time']);
150
+            $contest['end_stamps']=strtotime($contest['end_time']);
151
+            $contest['status']=time()>=$contest['end_stamps'] ? 1
152
+                : (time()<=$contest['begin_stamps'] ? -1 : 0);
153 153
             $contest["rule_parsed"]=$this->rule[$contest["rule"]];
154 154
             $contest["date_parsed"]=[
155 155
                 "date"=>date_format(date_create($contest["begin_time"]), 'j'),
@@ -157,11 +157,11 @@  discard block
 block discarded – undo
157 157
             ];
158 158
             $contest["length"]=$this->calcLength($contest["begin_time"], $contest["end_time"]);
159 159
         }
160
-        usort($group_contests,function($a,$b){
161
-            if($a['is_admin'] == $b['is_admin']){
162
-                return $b['begin_stamps'] - $a['begin_stamps'];
160
+        usort($group_contests, function($a, $b) {
161
+            if ($a['is_admin']==$b['is_admin']) {
162
+                return $b['begin_stamps']-$a['begin_stamps'];
163 163
             }
164
-            return $b['is_admin'] - $a['is_admin'];
164
+            return $b['is_admin']-$a['is_admin'];
165 165
         });
166 166
         return $group_contests;
167 167
     }
@@ -172,9 +172,9 @@  discard block
 block discarded – undo
172 172
         //     "gid"=>$gid
173 173
         // ])->orderBy('begin_time', 'desc')->get()->all();
174 174
         $preQuery=DB::table($this->tableName);
175
-        $paginator=$preQuery->where('gid','=',$gid)->orderBy('begin_time', 'desc')->paginate(10);
175
+        $paginator=$preQuery->where('gid', '=', $gid)->orderBy('begin_time', 'desc')->paginate(10);
176 176
         $contest_list=$paginator->all();
177
-        if(empty($contest_list)){
177
+        if (empty($contest_list)) {
178 178
             return null;
179 179
         }
180 180
 
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
         ])->first()["rule"];
200 200
     }
201 201
 
202
-    public function list($filter,$uid)
202
+    public function list($filter, $uid)
203 203
     {
204 204
         if ($uid) {
205 205
             //$paginator=DB::select('SELECT DISTINCT contest.* FROM group_member inner join contest on group_member.gid=contest.gid left join contest_participant on contest.cid=contest_participant.cid where (public=1 and audit=1) or (group_member.uid=:uid and group_member.role>0 and (contest_participant.uid=:uidd or ISNULL(contest_participant.uid)) and (registration=0 or (registration=1 and not ISNULL(contest_participant.uid))))',["uid"=>$uid,"uidd"=>$uid])->paginate(10);
@@ -223,15 +223,15 @@  discard block
 block discarded – undo
223 223
                 if ($filter['practice']) {
224 224
                     $paginator=$paginator->where(["practice"=>$filter['practice']]);
225 225
                 }
226
-                $paginator = $paginator ->paginate(10);
227
-            }elseif($filter['public']=='0'){
226
+                $paginator=$paginator ->paginate(10);
227
+            }elseif ($filter['public']=='0') {
228 228
                 $paginator=DB::table('group_member')
229 229
                 ->groupBy('contest.cid')
230 230
                 ->select('contest.*')
231 231
                 ->join('contest', 'group_member.gid', '=', 'contest.gid')
232 232
                 ->leftJoin('contest_participant', 'contest.cid', '=', 'contest_participant.cid')
233 233
                 ->where(
234
-                    function ($query) use ($filter,$uid) {
234
+                    function($query) use ($filter, $uid) {
235 235
                         if ($filter['rule']) {
236 236
                             $query=$query->where(["rule"=>$filter['rule']]);
237 237
                         }
@@ -254,14 +254,14 @@  discard block
 block discarded – undo
254 254
                 )
255 255
                 ->orderBy('contest.begin_time', 'desc')
256 256
                 ->paginate(10);
257
-            }else{
257
+            } else {
258 258
                 $paginator=DB::table('group_member')
259 259
                 ->groupBy('contest.cid')
260 260
                 ->select('contest.*')
261 261
                 ->join('contest', 'group_member.gid', '=', 'contest.gid')
262 262
                 ->leftJoin('contest_participant', 'contest.cid', '=', 'contest_participant.cid')
263 263
                 ->where(
264
-                    function ($query) use ($filter) {
264
+                    function($query) use ($filter) {
265 265
                         if ($filter['rule']) {
266 266
                             $query=$query->where(["rule"=>$filter['rule']]);
267 267
                         }
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
                     }
283 283
                 )
284 284
                 ->orWhere(
285
-                    function ($query) use ($filter,$uid) {
285
+                    function($query) use ($filter, $uid) {
286 286
                         if ($filter['rule']) {
287 287
                             $query=$query->where(["rule"=>$filter['rule']]);
288 288
                         }
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
             if ($filter['practice']) {
329 329
                 $paginator=$paginator->where(["practice"=>$filter['practice']]);
330 330
             }
331
-            $paginator = $paginator ->paginate(10);
331
+            $paginator=$paginator ->paginate(10);
332 332
         }
333 333
         $contest_list=$paginator->all();
334 334
         foreach ($contest_list as &$c) {
@@ -366,14 +366,14 @@  discard block
 block discarded – undo
366 366
         }
367 367
     }
368 368
 
369
-    public function registContest($cid,$uid)
369
+    public function registContest($cid, $uid)
370 370
     {
371 371
         $registered=DB::table("contest_participant")->where([
372 372
             "cid"=>$cid,
373 373
             "uid"=>$uid
374 374
         ])->first();
375 375
 
376
-        if(empty($registered)){
376
+        if (empty($registered)) {
377 377
             DB::table("contest_participant")->insert([
378 378
                 "cid"=>$cid,
379 379
                 "uid"=>$uid,
@@ -406,9 +406,9 @@  discard block
 block discarded – undo
406 406
     public function problems($cid)
407 407
     {
408 408
         return DB::table('contest_problem')
409
-            ->join('problem','contest_problem.pid','=','problem.pid')
410
-            ->where('cid',$cid)
411
-            ->select('problem.pid as pid','pcode','number')
409
+            ->join('problem', 'contest_problem.pid', '=', 'problem.pid')
410
+            ->where('cid', $cid)
411
+            ->select('problem.pid as pid', 'pcode', 'number')
412 412
             ->orderBy('number')
413 413
             ->get()->all();
414 414
     }
@@ -430,18 +430,18 @@  discard block
 block discarded – undo
430 430
         $end_time=strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]);
431 431
 
432 432
         foreach ($problemSet as &$p) {
433
-            if($p['practice']){
434
-                $tags = DB::table("group_problem_tag")
435
-                ->where('gid',$p['gid'])
436
-                ->where('pid',$p['pid'])
433
+            if ($p['practice']) {
434
+                $tags=DB::table("group_problem_tag")
435
+                ->where('gid', $p['gid'])
436
+                ->where('pid', $p['pid'])
437 437
                 ->get()->all();
438
-                $tags_arr = [];
439
-                if(!empty($tags)){
438
+                $tags_arr=[];
439
+                if (!empty($tags)) {
440 440
                     foreach ($tags as $value) {
441
-                        array_push($tags_arr,$value['tag']);
441
+                        array_push($tags_arr, $value['tag']);
442 442
                     }
443 443
                 }
444
-                $p['tags'] = $tags_arr;
444
+                $p['tags']=$tags_arr;
445 445
             }
446 446
             if ($contest_rule==1) {
447 447
                 $prob_stat=DB::table("submission")->select(
@@ -702,7 +702,7 @@  discard block
 block discarded – undo
702 702
                     "problem_detail" => $prob_detail
703 703
                 ];
704 704
             }
705
-            usort($ret, function ($a, $b) {
705
+            usort($ret, function($a, $b) {
706 706
                 if ($a["score"]==$b["score"]) {
707 707
                     if ($a["penalty"]==$b["penalty"]) {
708 708
                         return 0;
@@ -749,7 +749,7 @@  discard block
 block discarded – undo
749 749
                     "problem_detail" => $prob_detail
750 750
                 ];
751 751
             }
752
-            usort($ret, function ($a, $b) {
752
+            usort($ret, function($a, $b) {
753 753
                 if ($a["score"]==$b["score"]) {
754 754
                     if ($a["solved"]==$b["solved"]) {
755 755
                         return 0;
@@ -771,7 +771,7 @@  discard block
 block discarded – undo
771 771
         return $ret;
772 772
     }
773 773
 
774
-    public function contestRank($cid, $uid = 0)
774
+    public function contestRank($cid, $uid=0)
775 775
     {
776 776
         // [ToDo] If the current user's in the organizer group show nick name
777 777
         // [ToDo] The participants determination
@@ -789,35 +789,35 @@  discard block
 block discarded – undo
789 789
             "gid" => $contest_info["gid"]
790 790
         ])->where("role", ">", 0)->first());
791 791
 
792
-        $clearance = $this -> judgeClearance($cid, $uid);
792
+        $clearance=$this -> judgeClearance($cid, $uid);
793 793
 
794 794
         /** New Version With MySQL */
795 795
         $end_time=strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]);
796 796
 
797
-        if(time() < $end_time){
798
-            if($clearance == 3){
797
+        if (time()<$end_time) {
798
+            if ($clearance==3) {
799 799
                 $contestRankRaw=Cache::tags(['contest', 'rank'])->get("contestAdmin$cid");
800
-            }else{
800
+            } else {
801 801
                 $contestRankRaw=Cache::tags(['contest', 'rank'])->get($cid);
802 802
             }
803
-            if(!isset($contestRankRaw)){
803
+            if (!isset($contestRankRaw)) {
804 804
                 $contestRankRaw=$this->contestRankCache($cid);
805 805
             }
806
-        }else{
807
-            if($clearance == 3){
806
+        } else {
807
+            if ($clearance==3) {
808 808
                 $contestRankRaw=Cache::tags(['contest', 'rank'])->get("contestAdmin$cid");
809 809
                 if (!isset($contestRankRaw)) {
810 810
                     $contestRankRaw=$this->getContestRankFromMySQL($cid);
811
-                    if(!isset($contestRankRaw)){
811
+                    if (!isset($contestRankRaw)) {
812 812
                         $contestRankRaw=$this->contestRankCache($cid);
813 813
                         $this->storeContestRankInMySQL($cid, $contestRankRaw);
814 814
                     }
815 815
                 }
816
-            }else{
816
+            } else {
817 817
                 $contestRankRaw=$this->getContestRankFromMySQL($cid);
818
-                if(!isset($contestRankRaw)){
818
+                if (!isset($contestRankRaw)) {
819 819
                     $contestRankRaw=Cache::tags(['contest', 'rank'])->get($cid);
820
-                    if(!isset($contestRankRaw)){
820
+                    if (!isset($contestRankRaw)) {
821 821
                         $contestRankRaw=$this->contestRankCache($cid);
822 822
                     }
823 823
                     $this->storeContestRankInMySQL($cid, $contestRankRaw);
@@ -835,15 +835,15 @@  discard block
 block discarded – undo
835 835
         //         $contestRankRaw=$this->contestRankCache($cid);
836 836
         //     }
837 837
         // }
838
-        if($contest_info["rule"]==1){
838
+        if ($contest_info["rule"]==1) {
839 839
             foreach ($contestRankRaw as &$cr) {
840
-                $solved = 0;
841
-                foreach($cr['problem_detail'] as $pd){
842
-                    if(!empty($pd['solved_time_parsed'])){
843
-                        $solved ++;
840
+                $solved=0;
841
+                foreach ($cr['problem_detail'] as $pd) {
842
+                    if (!empty($pd['solved_time_parsed'])) {
843
+                        $solved++;
844 844
                     }
845 845
                 }
846
-                $cr['solved'] = $solved;
846
+                $cr['solved']=$solved;
847 847
             }
848 848
         }
849 849
 
@@ -892,16 +892,16 @@  discard block
 block discarded – undo
892 892
 
893 893
     public function getClarificationList($cid)
894 894
     {
895
-        $uid = Auth::user()->id;
896
-        $clearance = $this -> judgeClearance($cid, $uid);
897
-        if($clearance == 3){
895
+        $uid=Auth::user()->id;
896
+        $clearance=$this -> judgeClearance($cid, $uid);
897
+        if ($clearance==3) {
898 898
             return DB::table("contest_clarification")->where([
899 899
                 "cid"=>$cid
900 900
             ])->orderBy('create_time', 'desc')->get()->all();
901
-        }else{
901
+        } else {
902 902
             return DB::table("contest_clarification")->where([
903 903
                 "cid"=>$cid
904
-            ])->where(function ($query) {
904
+            ])->where(function($query) {
905 905
                 $query->where([
906 906
                     "public"=>1
907 907
                 ])->orWhere([
@@ -1046,7 +1046,7 @@  discard block
 block discarded – undo
1046 1046
     public function getContestRecord($cid)
1047 1047
     {
1048 1048
         $basicInfo=$this->basic($cid);
1049
-        $userInfo=DB::table('group_member')->where('gid',$basicInfo["gid"])->where('uid',Auth::user()->id)->get()->first();
1049
+        $userInfo=DB::table('group_member')->where('gid', $basicInfo["gid"])->where('uid', Auth::user()->id)->get()->first();
1050 1050
         $problemSet_temp=DB::table("contest_problem")->join("problem", "contest_problem.pid", "=", "problem.pid")->where([
1051 1051
             "cid"=>$cid
1052 1052
         ])->orderBy('ncode', 'asc')->select("ncode", "alias", "contest_problem.pid as pid", "title", "points", "tot_score")->get()->all();
@@ -1059,7 +1059,7 @@  discard block
 block discarded – undo
1059 1059
         $end_time=strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]);
1060 1060
         $contestEnd=time()>$end_time;
1061 1061
 
1062
-        if($userInfo==null || $userInfo["role"]!=3){
1062
+        if ($userInfo==null || $userInfo["role"]!=3) {
1063 1063
             if ($basicInfo["status_visibility"]==2) {
1064 1064
                 // View all
1065 1065
                 $paginator=DB::table("submission")->where([
@@ -1073,7 +1073,7 @@  discard block
 block discarded – undo
1073 1073
                     "users.id",
1074 1074
                     "=",
1075 1075
                     "submission.uid"
1076
-                )->where(function ($query) use ($frozen_time) {
1076
+                )->where(function($query) use ($frozen_time) {
1077 1077
                     $query->where(
1078 1078
                         "submission_date",
1079 1079
                         "<",
@@ -1135,7 +1135,7 @@  discard block
 block discarded – undo
1135 1135
                     "records"=>[]
1136 1136
                 ];
1137 1137
             }
1138
-        }else{
1138
+        } else {
1139 1139
             if ($basicInfo["status_visibility"]==2) {
1140 1140
                 // View all
1141 1141
                 $paginator=DB::table("submission")->where([
@@ -1247,21 +1247,21 @@  discard block
 block discarded – undo
1247 1247
         if ($uid==0) {
1248 1248
             return 0;
1249 1249
         }
1250
-        $groupModel = new GroupModel();
1250
+        $groupModel=new GroupModel();
1251 1251
         $contest_info=DB::table("contest")->where("cid", $cid)->first();
1252
-        $userInfo=DB::table('group_member')->where('gid',$contest_info["gid"])->where('uid',$uid)->get()->first();
1252
+        $userInfo=DB::table('group_member')->where('gid', $contest_info["gid"])->where('uid', $uid)->get()->first();
1253 1253
 
1254
-        if(empty($contest_info)){
1254
+        if (empty($contest_info)) {
1255 1255
             // contest not exist
1256 1256
             return 0;
1257 1257
         }
1258 1258
 
1259
-        if($uid == $contest_info['assign_uid'] || $groupModel->judgeClearance($contest_info['gid'],$uid) == 3){
1259
+        if ($uid==$contest_info['assign_uid'] || $groupModel->judgeClearance($contest_info['gid'], $uid)==3) {
1260 1260
             return 3;
1261 1261
         }
1262 1262
 
1263
-        $contest_started = strtotime($contest_info['begin_time']) < time();
1264
-        $contest_ended = strtotime($contest_info['end_time']) < time();
1263
+        $contest_started=strtotime($contest_info['begin_time'])<time();
1264
+        $contest_ended=strtotime($contest_info['end_time'])<time();
1265 1265
         if (!$contest_started) {
1266 1266
             // not started or do not exist
1267 1267
             return 0;
@@ -1352,12 +1352,12 @@  discard block
 block discarded – undo
1352 1352
     public function updateProfessionalRate($cid)
1353 1353
     {
1354 1354
         $basic=$this->basic($cid);
1355
-        if($basic["rated"]&&!$basic["is_rated"]){
1355
+        if ($basic["rated"] && !$basic["is_rated"]) {
1356 1356
             $ratingCalculator=new RatingCalculator($cid);
1357
-            if($ratingCalculator->calculate()){
1357
+            if ($ratingCalculator->calculate()) {
1358 1358
                 $ratingCalculator->storage();
1359 1359
                 return true;
1360
-            }else{
1360
+            } else {
1361 1361
                 return false;
1362 1362
             }
1363 1363
         } else {
@@ -1365,26 +1365,26 @@  discard block
 block discarded – undo
1365 1365
         }
1366 1366
     }
1367 1367
 
1368
-    public function contestUpdate($cid,$data,$problems)
1368
+    public function contestUpdate($cid, $data, $problems)
1369 1369
     {
1370
-        if($problems !== false){
1371
-            $old_problmes = array_column(
1370
+        if ($problems!==false) {
1371
+            $old_problmes=array_column(
1372 1372
                 DB::table('contest_problem')
1373
-                ->where('cid',$cid)
1373
+                ->where('cid', $cid)
1374 1374
                 ->get()->all(),
1375 1375
                 'pid'
1376 1376
             );
1377
-            DB::transaction(function () use ($cid, $data, $problems,$old_problmes) {
1377
+            DB::transaction(function() use ($cid, $data, $problems, $old_problmes) {
1378 1378
                 DB::table($this->tableName)
1379
-                    ->where('cid',$cid)
1379
+                    ->where('cid', $cid)
1380 1380
                     ->update($data);
1381 1381
                 DB::table('contest_problem')
1382
-                    ->where('cid',$cid)
1382
+                    ->where('cid', $cid)
1383 1383
                     ->delete();
1384
-                $new_problems = [];
1384
+                $new_problems=[];
1385 1385
                 foreach ($problems as $p) {
1386 1386
                     $pid=DB::table("problem")->where(["pcode"=>$p["pcode"]])->select("pid")->first()["pid"];
1387
-                    array_push($new_problems,$pid);
1387
+                    array_push($new_problems, $pid);
1388 1388
                     DB::table("contest_problem")->insert([
1389 1389
                         "cid"=>$cid,
1390 1390
                         "number"=>$p["number"],
@@ -1394,29 +1394,29 @@  discard block
 block discarded – undo
1394 1394
                         "points"=>$p["points"]
1395 1395
                     ]);
1396 1396
                 }
1397
-                foreach($old_problmes as $op) {
1398
-                    if(!in_array($op,$new_problems)){
1397
+                foreach ($old_problmes as $op) {
1398
+                    if (!in_array($op, $new_problems)) {
1399 1399
                         DB::table('submission')
1400
-                            ->where('cid',$cid)
1401
-                            ->where('pid',$op)
1400
+                            ->where('cid', $cid)
1401
+                            ->where('pid', $op)
1402 1402
                             ->delete();
1403 1403
                     }
1404 1404
                 }
1405 1405
             }, 5);
1406
-            $contestRankRaw = $this->contestRankCache($cid);
1406
+            $contestRankRaw=$this->contestRankCache($cid);
1407 1407
             Cache::tags(['contest', 'rank'])->put($cid, $contestRankRaw);
1408 1408
             Cache::tags(['contest', 'rank'])->put("contestAdmin$cid", $contestRankRaw);
1409
-        }else{
1409
+        } else {
1410 1410
             DB::table($this->tableName)
1411
-                ->where('cid',$cid)
1411
+                ->where('cid', $cid)
1412 1412
                 ->update($data);
1413 1413
         }
1414 1414
     }
1415 1415
 
1416
-    public function contestUpdateProblem($cid,$problems)
1416
+    public function contestUpdateProblem($cid, $problems)
1417 1417
     {
1418 1418
         DB::table('contest_problem')
1419
-                ->where('cid',$cid)
1419
+                ->where('cid', $cid)
1420 1420
                 ->delete();
1421 1421
         foreach ($problems as $p) {
1422 1422
             DB::table("contest_problem")->insertGetId([
@@ -1432,7 +1432,7 @@  discard block
 block discarded – undo
1432 1432
 
1433 1433
     public function arrangeContest($gid, $config, $problems)
1434 1434
     {
1435
-        DB::transaction(function () use ($gid, $config, $problems) {
1435
+        DB::transaction(function() use ($gid, $config, $problems) {
1436 1436
             $cid=DB::table($this->tableName)->insertGetId([
1437 1437
                 "gid"=>$gid,
1438 1438
                 "name"=>$config["name"],
@@ -1446,7 +1446,7 @@  discard block
 block discarded – undo
1446 1446
                 "rule"=>1, //todo
1447 1447
                 "begin_time"=>$config["begin_time"],
1448 1448
                 "end_time"=>$config["end_time"],
1449
-                "vcid"=>isset($config["vcid"])?$config["vcid"]:null,
1449
+                "vcid"=>isset($config["vcid"]) ? $config["vcid"] : null,
1450 1450
                 "public"=>0, //todo
1451 1451
                 "registration"=>0, //todo
1452 1452
                 "registration_due"=>null, //todo
@@ -1454,7 +1454,7 @@  discard block
 block discarded – undo
1454 1454
                 "froze_length"=>0, //todo
1455 1455
                 "status_visibility"=>2, //todo
1456 1456
                 "create_time"=>date("Y-m-d H:i:s"),
1457
-                "crawled" => isset($config['vcid'])?$config['crawled'] : null,
1457
+                "crawled" => isset($config['vcid']) ? $config['crawled'] : null,
1458 1458
                 "audit_status"=>1                       //todo
1459 1459
             ]);
1460 1460
 
@@ -1472,13 +1472,13 @@  discard block
 block discarded – undo
1472 1472
         }, 5);
1473 1473
     }
1474 1474
 
1475
-    public function updateContestRankTable($cid,$sub)
1475
+    public function updateContestRankTable($cid, $sub)
1476 1476
     {
1477
-        $lock = Cache::lock("contestrank$cid",10);
1478
-        try{
1479
-            if($lock->get()){
1480
-                if(Cache::tags(['contest','rank'])->get($cid) != null){
1481
-                    $ret = Cache::tags(['contest','rank'])->get($cid);
1477
+        $lock=Cache::lock("contestrank$cid", 10);
1478
+        try {
1479
+            if ($lock->get()) {
1480
+                if (Cache::tags(['contest', 'rank'])->get($cid)!=null) {
1481
+                    $ret=Cache::tags(['contest', 'rank'])->get($cid);
1482 1482
                     $chache=[];
1483 1483
                     $chache['contest_info']=DB::table("contest")->where("cid", $cid)->first();
1484 1484
                     $chache['problemSet']=DB::table("contest_problem")->join("problem", "contest_problem.pid", "=", "problem.pid")->where([
@@ -1487,27 +1487,27 @@  discard block
 block discarded – undo
1487 1487
                     $chache['frozen_time']=DB::table("contest")->where(["cid"=>$cid])->select(DB::raw("UNIX_TIMESTAMP(end_time)-froze_length as frozen_time"))->first()["frozen_time"];
1488 1488
                     $chache['end_time']=strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]);
1489 1489
 
1490
-                    $id = 0;
1490
+                    $id=0;
1491 1491
 
1492
-                    foreach($chache['problemSet'] as $key => $p){
1493
-                        if ($p['pid'] == $sub['pid']){
1494
-                            $chache['problemSet'][$key]['cpid'] = $key;
1495
-                            $id = $key;
1492
+                    foreach ($chache['problemSet'] as $key => $p) {
1493
+                        if ($p['pid']==$sub['pid']) {
1494
+                            $chache['problemSet'][$key]['cpid']=$key;
1495
+                            $id=$key;
1496 1496
                         }
1497 1497
                     }
1498 1498
 
1499
-                    $ret = $this->updateContestRankDetail($chache['contest_info'],$chache['problemSet'][$id],$cid,$sub['uid'],$ret);
1500
-                    $ret = $this->sortContestRankTable($chache['contest_info'],$cid,$ret);
1499
+                    $ret=$this->updateContestRankDetail($chache['contest_info'], $chache['problemSet'][$id], $cid, $sub['uid'], $ret);
1500
+                    $ret=$this->sortContestRankTable($chache['contest_info'], $cid, $ret);
1501 1501
 
1502
-                    if (time() < $chache['frozen_time']){
1502
+                    if (time()<$chache['frozen_time']) {
1503 1503
                         Cache::tags(['contest', 'rank'])->put($cid, $ret);
1504 1504
                     }
1505 1505
                     Cache::tags(['contest', 'rank'])->put("contestAdmin$cid", $ret);
1506
-                    if(time() > $chache['end_time']){
1506
+                    if (time()>$chache['end_time']) {
1507 1507
                         $this->storeContestRankInMySQL($cid, $ret);
1508 1508
                     }
1509 1509
                 }
1510
-                else{
1510
+                else {
1511 1511
                     $ret=[];
1512 1512
                     $chache=[];
1513 1513
                     $chache['contest_info']=DB::table("contest")->where("cid", $cid)->first();
@@ -1522,7 +1522,7 @@  discard block
 block discarded – undo
1522 1522
                             "cid"=>$cid,
1523 1523
                             "audit"=>1
1524 1524
                         ])->select('uid')->get()->all();
1525
-                    }else{
1525
+                    } else {
1526 1526
                         $submissionUsers=DB::table("submission")->where([
1527 1527
                             "cid"=>$cid
1528 1528
                         ])->where(
@@ -1535,39 +1535,39 @@  discard block
 block discarded – undo
1535 1535
                         ])->select('uid')->groupBy('uid')->get()->all();
1536 1536
                     }
1537 1537
 
1538
-                    $chacheAdmin = $chache;
1538
+                    $chacheAdmin=$chache;
1539 1539
 
1540 1540
                     foreach ($submissionUsers as $s) {
1541 1541
                         foreach ($chache['problemSet'] as $key => $p) {
1542
-                            $p['cpid'] = $key;
1543
-                            $ret = $this->updateContestRankDetail($chache['contest_info'],$p,$cid,$s['uid'],$ret);
1542
+                            $p['cpid']=$key;
1543
+                            $ret=$this->updateContestRankDetail($chache['contest_info'], $p, $cid, $s['uid'], $ret);
1544 1544
                         }
1545 1545
                     }
1546
-                    $ret = $this->sortContestRankTable($chache['contest_info'],$cid,$ret);
1546
+                    $ret=$this->sortContestRankTable($chache['contest_info'], $cid, $ret);
1547 1547
                     Cache::tags(['contest', 'rank'])->put($cid, $ret);
1548 1548
 
1549 1549
                     $retAdmin=[];
1550 1550
                     foreach ($submissionUsersAdmin as $s) {
1551 1551
                         foreach ($chacheAdmin['problemSet'] as $key => $p) {
1552
-                            $p['cpid'] = $key;
1553
-                            $retAdmin = $this->updateContestRankDetail($chacheAdmin['contest_info'],$p,$cid,$s['uid'],$retAdmin);
1552
+                            $p['cpid']=$key;
1553
+                            $retAdmin=$this->updateContestRankDetail($chacheAdmin['contest_info'], $p, $cid, $s['uid'], $retAdmin);
1554 1554
                         }
1555 1555
                     }
1556
-                    $retAdmin = $this->sortContestRankTable($chacheAdmin['contest_info'],$cid,$retAdmin);
1556
+                    $retAdmin=$this->sortContestRankTable($chacheAdmin['contest_info'], $cid, $retAdmin);
1557 1557
                     Cache::tags(['contest', 'rank'])->put("contestAdmin$cid", $retAdmin);
1558 1558
                 }
1559 1559
             }
1560
-        }catch(LockTimeoutException $e){
1560
+        } catch (LockTimeoutException $e) {
1561 1561
             Log::warning("Contest Rank Lock Timed Out");
1562
-        }finally{
1562
+        } finally {
1563 1563
             optional($lock)->release();
1564 1564
         }
1565 1565
     }
1566 1566
 
1567
-    public function sortContestRankTable($contest_info,$cid,$ret)
1567
+    public function sortContestRankTable($contest_info, $cid, $ret)
1568 1568
     {
1569
-        if ($contest_info["rule"]==1){
1570
-            usort($ret, function ($a, $b) {
1569
+        if ($contest_info["rule"]==1) {
1570
+            usort($ret, function($a, $b) {
1571 1571
                 if ($a["score"]==$b["score"]) {
1572 1572
                     if ($a["penalty"]==$b["penalty"]) {
1573 1573
                         return 0;
@@ -1582,8 +1582,8 @@  discard block
 block discarded – undo
1582 1582
                     return 1;
1583 1583
                 }
1584 1584
             });
1585
-        }else if ($contest_info["rule"]==2){
1586
-            usort($ret, function ($a, $b) {
1585
+        } else if ($contest_info["rule"]==2) {
1586
+            usort($ret, function($a, $b) {
1587 1587
                 if ($a["score"]==$b["score"]) {
1588 1588
                     if ($a["solved"]==$b["solved"]) {
1589 1589
                         return 0;
@@ -1602,21 +1602,21 @@  discard block
 block discarded – undo
1602 1602
         return $ret;
1603 1603
     }
1604 1604
 
1605
-    public function updateContestRankDetail($contest_info,$problem,$cid,$uid,$ret)
1605
+    public function updateContestRankDetail($contest_info, $problem, $cid, $uid, $ret)
1606 1606
     {
1607
-        $id = count($ret);
1608
-        foreach($ret as $key => $r){
1609
-            if($r['uid'] == $uid)
1610
-                $id = $key;
1607
+        $id=count($ret);
1608
+        foreach ($ret as $key => $r) {
1609
+            if ($r['uid']==$uid)
1610
+                $id=$key;
1611 1611
         }
1612 1612
         if ($contest_info["rule"]==1) {
1613 1613
             // ACM/ICPC Mode
1614
-            if($id == count($ret)){
1615
-                $prob_detail = [];
1616
-                $totPen = 0;
1617
-                $totScore = 0;
1618
-            }else{
1619
-                $prob_detail = $ret[$id]['problem_detail'];
1614
+            if ($id==count($ret)) {
1615
+                $prob_detail=[];
1616
+                $totPen=0;
1617
+                $totScore=0;
1618
+            } else {
1619
+                $prob_detail=$ret[$id]['problem_detail'];
1620 1620
                 $totPen=$ret[$id]['penalty'];
1621 1621
                 $totScore=$ret[$id]['score'];
1622 1622
             };
@@ -1634,7 +1634,7 @@  discard block
 block discarded – undo
1634 1634
                 "uid"=>$uid,
1635 1635
             ])->orderBy('submission_date', 'desc')->first();
1636 1636
     
1637
-            if ($ac_times<=1 && isset($last_record) && $last_record['verdict']!="Waiting" && $last_record['verdict']!="Submission Error" && $last_record['verdict']!="System Error"){
1637
+            if ($ac_times<=1 && isset($last_record) && $last_record['verdict']!="Waiting" && $last_record['verdict']!="Submission Error" && $last_record['verdict']!="System Error") {
1638 1638
                 $prob_stat=$this->contestProblemInfoACM($cid, $problem["pid"], $uid);
1639 1639
 
1640 1640
                 $prob_detail[$problem['cpid']]=[
@@ -1666,12 +1666,12 @@  discard block
 block discarded – undo
1666 1666
             }
1667 1667
         } elseif ($contest_info["rule"]==2) {
1668 1668
             // OI Mode
1669
-            if($id == count($ret)){
1670
-                $prob_detail = [];
1671
-                $totSolved = 0;
1672
-                $totScore = 0;
1673
-            }else{
1674
-                $prob_detail = $ret[$id]['problem_detail'];
1669
+            if ($id==count($ret)) {
1670
+                $prob_detail=[];
1671
+                $totSolved=0;
1672
+                $totScore=0;
1673
+            } else {
1674
+                $prob_detail=$ret[$id]['problem_detail'];
1675 1675
                 $totSolved=$ret[$id]['solved'];
1676 1676
                 $totScore=$ret[$id]['score'];
1677 1677
             };
@@ -1704,47 +1704,47 @@  discard block
 block discarded – undo
1704 1704
         return $ret;
1705 1705
     }
1706 1706
 
1707
-    public function assignMember($cid,$uid){
1707
+    public function assignMember($cid, $uid) {
1708 1708
         return DB::table("contest")->where(["cid"=>$cid])->update([
1709 1709
             "assign_uid"=>$uid
1710 1710
         ]);
1711 1711
     }
1712 1712
 
1713
-    public function canUpdateContestTime($cid,$time = [])
1713
+    public function canUpdateContestTime($cid, $time=[])
1714 1714
     {
1715
-        $begin_time_new = $time['begin'] ?? null;
1716
-        $end_time_new = $time['end'] ?? null;
1715
+        $begin_time_new=$time['begin'] ?? null;
1716
+        $end_time_new=$time['end'] ?? null;
1717 1717
 
1718
-        $hold_time = DB::table('contest')
1719
-            ->where('cid',$cid)
1720
-            ->select('begin_time','end_time')
1718
+        $hold_time=DB::table('contest')
1719
+            ->where('cid', $cid)
1720
+            ->select('begin_time', 'end_time')
1721 1721
             ->first();
1722
-        $begin_stamps = strtotime($hold_time['begin_time']);
1723
-        $end_stamps = strtotime($hold_time['end_time']);
1722
+        $begin_stamps=strtotime($hold_time['begin_time']);
1723
+        $end_stamps=strtotime($hold_time['end_time']);
1724 1724
         /*
1725 1725
         -1 : have not begun
1726 1726
          0 : ing
1727 1727
          1 : end
1728 1728
         */
1729
-        $status = time() >= $end_stamps ? 1
1730
-                : (time() <= $begin_stamps ? -1 : 0);
1731
-        if($status === -1){
1732
-            if(time() > $begin_time_new){
1729
+        $status=time()>=$end_stamps ? 1
1730
+                : (time()<=$begin_stamps ? -1 : 0);
1731
+        if ($status===-1) {
1732
+            if (time()>$begin_time_new) {
1733 1733
                 return false;
1734 1734
             }
1735 1735
             return true;
1736
-        }else if($status === 0){
1737
-            if($begin_time_new !== null){
1736
+        } else if ($status===0) {
1737
+            if ($begin_time_new!==null) {
1738 1738
                 return false;
1739 1739
             }
1740
-            if($end_time_new !== null){
1741
-                if(strtotime($end_time_new) <= time()){
1740
+            if ($end_time_new!==null) {
1741
+                if (strtotime($end_time_new)<=time()) {
1742 1742
                     return false;
1743
-                }else{
1743
+                } else {
1744 1744
                     return true;
1745 1745
                 }
1746 1746
             }
1747
-        }else{
1747
+        } else {
1748 1748
             return false;
1749 1749
         }
1750 1750
 
@@ -1753,22 +1753,22 @@  discard block
 block discarded – undo
1753 1753
 
1754 1754
     public function replyClarification($ccid, $content)
1755 1755
     {
1756
-        return DB::table("contest_clarification")->where('ccid','=',$ccid)->update([
1756
+        return DB::table("contest_clarification")->where('ccid', '=', $ccid)->update([
1757 1757
             "reply"=>$content
1758 1758
         ]);
1759 1759
     }
1760 1760
 
1761 1761
     public function setClarificationPublic($ccid, $public)
1762 1762
     {
1763
-        if($public)
1763
+        if ($public)
1764 1764
         {
1765
-            return DB::table("contest_clarification")->where('ccid','=',$ccid)->update([
1765
+            return DB::table("contest_clarification")->where('ccid', '=', $ccid)->update([
1766 1766
                 "public"=>1
1767 1767
             ]);
1768 1768
         }
1769 1769
         else
1770 1770
         {
1771
-            return DB::table("contest_clarification")->where('ccid','=',$ccid)->update([
1771
+            return DB::table("contest_clarification")->where('ccid', '=', $ccid)->update([
1772 1772
                 "public"=>0
1773 1773
             ]);
1774 1774
         }
@@ -1779,67 +1779,67 @@  discard block
 block discarded – undo
1779 1779
         return Cache::tags(['contest', 'account'])->get($cid);
1780 1780
     }
1781 1781
 
1782
-    public function praticeAnalysis($cid){
1783
-        $gid = DB::table('contest')
1784
-            ->where('cid',$cid)
1782
+    public function praticeAnalysis($cid) {
1783
+        $gid=DB::table('contest')
1784
+            ->where('cid', $cid)
1785 1785
             ->first()['gid'];
1786
-        $contestRank = $this->contestRank($cid,Auth::user()->id);
1787
-        if(!empty($contestRank)){
1788
-            $all_problems = DB::table('problem')
1789
-            ->whereIn('pid',array_column($contestRank[0]['problem_detail'],'pid'))
1790
-            ->select('pid','title')
1786
+        $contestRank=$this->contestRank($cid, Auth::user()->id);
1787
+        if (!empty($contestRank)) {
1788
+            $all_problems=DB::table('problem')
1789
+            ->whereIn('pid', array_column($contestRank[0]['problem_detail'], 'pid'))
1790
+            ->select('pid', 'title')
1791 1791
             ->get()->all();
1792
-        }else{
1793
-            $all_problems = [];
1792
+        } else {
1793
+            $all_problems=[];
1794 1794
         }
1795
-        $tags = DB::table('group_problem_tag')
1795
+        $tags=DB::table('group_problem_tag')
1796 1796
             ->where('gid', $gid)
1797
-            ->whereIn('pid', array_column($all_problems,'pid'))
1797
+            ->whereIn('pid', array_column($all_problems, 'pid'))
1798 1798
             ->get()->all();
1799
-        $all_tags = array_unique(array_column($tags,'tag'));
1800
-        $memberData = [];
1801
-        foreach($contestRank as $member){
1802
-            $m = [
1799
+        $all_tags=array_unique(array_column($tags, 'tag'));
1800
+        $memberData=[];
1801
+        foreach ($contestRank as $member) {
1802
+            $m=[
1803 1803
                 'uid' => $member['uid'],
1804 1804
                 'name' => $member['name'],
1805 1805
                 'nick_name' => $member['nick_name'],
1806 1806
             ];
1807
-            $completion = [];
1808
-            foreach ($all_tags as $tag){
1809
-                $completion[$tag] = [];
1807
+            $completion=[];
1808
+            foreach ($all_tags as $tag) {
1809
+                $completion[$tag]=[];
1810 1810
                 foreach ($tags as $t) {
1811
-                    if($t['tag'] == $tag){
1811
+                    if ($t['tag']==$tag) {
1812 1812
                         foreach ($member['problem_detail'] as $pd) {
1813
-                            if($pd['pid'] == $t['pid']){
1814
-                                $completion[$tag][$t['pid']] = $pd['solved_time_parsed'] == "" ? 0 : 1;
1813
+                            if ($pd['pid']==$t['pid']) {
1814
+                                $completion[$tag][$t['pid']]=$pd['solved_time_parsed']=="" ? 0 : 1;
1815 1815
                             }
1816 1816
                         }
1817 1817
                     }
1818 1818
                 }
1819 1819
             }
1820
-            $m['completion'] = $completion;
1821
-            $memberData[] = $m;
1820
+            $m['completion']=$completion;
1821
+            $memberData[]=$m;
1822 1822
         }
1823 1823
         return $memberData;
1824 1824
     }
1825 1825
 
1826 1826
     public function storeContestRankInMySQL($cid, $data)
1827 1827
     {
1828
-        $contestRankJson = json_encode($data);
1829
-        return DB::table('contest')->where('cid','=',$cid)->update([
1828
+        $contestRankJson=json_encode($data);
1829
+        return DB::table('contest')->where('cid', '=', $cid)->update([
1830 1830
             'rank' => $contestRankJson
1831 1831
         ]);
1832 1832
     }
1833 1833
 
1834 1834
     public function getContestRankFromMySQL($cid)
1835 1835
     {
1836
-        $contestRankJson = DB::table('contest')->where('cid','=',$cid)->pluck('rank')->first();
1837
-        $data = json_decode($contestRankJson, true);
1836
+        $contestRankJson=DB::table('contest')->where('cid', '=', $cid)->pluck('rank')->first();
1837
+        $data=json_decode($contestRankJson, true);
1838 1838
         return $data;
1839 1839
     }
1840 1840
 
1841 1841
     public function isVerified($cid)
1842 1842
     {
1843
-        return DB::table('contest')->where('cid','=',$cid)->pluck('verified')->first();
1843
+        return DB::table('contest')->where('cid', '=', $cid)->pluck('verified')->first();
1844 1844
     }
1845 1845
 }
Please login to merge, or discard this patch.
app/Babel/Synchronize/Synchronizer.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,11 +19,11 @@
 block discarded – undo
19 19
         try {
20 20
             $BabelConfig=json_decode(file_get_contents(babel_path("Extension/$oj/babel.json")), true);
21 21
             $synchronizerProvider=$BabelConfig["provider"]["synchronizer"];
22
-        } catch(ErrorException $e) {
23
-        } catch(Exception $e) {
22
+        } catch (ErrorException $e) {
23
+        } catch (Exception $e) {
24 24
         }
25
-        $className = "App\\Babel\\Extension\\$oj\\$synchronizerProvider";
26
-        if(class_exists($className)) {
25
+        $className="App\\Babel\\Extension\\$oj\\$synchronizerProvider";
26
+        if (class_exists($className)) {
27 27
             return new $className($all_data);
28 28
         } else {
29 29
             return null;
Please login to merge, or discard this patch.
app/Babel/Install/InstallerBase.php 2 patches
Braces   +27 added lines, -15 removed lines patch added patch discarded remove patch
@@ -23,8 +23,12 @@  discard block
 block discarded – undo
23 23
         $babelConfig=json_decode(file_get_contents(babel_path("Extension/$ocode/babel.json")),true);
24 24
 
25 25
         // support __cur__ variables
26
-        if($babelConfig["version"]=="__cur__") $babelConfig["version"]=explode("-",version())[0];
27
-        if($babelConfig["require"]["NOJ"]=="__cur__") $babelConfig["require"]["NOJ"]=explode("-",version())[0];
26
+        if($babelConfig["version"]=="__cur__") {
27
+            $babelConfig["version"]=explode("-",version())[0];
28
+        }
29
+        if($babelConfig["require"]["NOJ"]=="__cur__") {
30
+            $babelConfig["require"]["NOJ"]=explode("-",version())[0];
31
+        }
28 32
 
29 33
         // check version info
30 34
         if(!isset($babelConfig["version"]) || is_null($babelConfig["version"]) || trim($babelConfig["version"])==""){
@@ -120,11 +124,11 @@  discard block
 block discarded – undo
120 124
         try {
121 125
             if (isset($babelConfig["custom"]["css"]) && !is_null($babelConfig["custom"]["css"]) && trim($babelConfig["custom"]["css"])!="") {
122 126
                 $cssPath=babel_path("Extension/$ocode/".$babelConfig["custom"]["css"]);
123
-            }else{
127
+            } else{
124 128
                 $cssPath=null;
125 129
             }
126 130
             $this->applyCustom($ocode, $cssPath);
127
-        }catch(Exception $e){
131
+        } catch(Exception $e){
128 132
             DB::rollback();
129 133
             $this->command->line("\n  <bg=red;fg=white> Unable to add an custom css for this extension, aborting. </>\n");
130 134
             return;
@@ -136,7 +140,7 @@  discard block
 block discarded – undo
136 140
             $imgPath=babel_path("Extension/$ocode/".$babelConfig["icon"]);
137 141
             $storePath=$this->applyIcon($ocode, $imgPath);
138 142
             OJModel::updateOJ($this->oid,["logo"=>$storePath]);
139
-        }catch(Exception $e){
143
+        } catch(Exception $e){
140 144
             DB::rollback();
141 145
             $this->command->line("\n  <bg=red;fg=white> Unable to add an icon for this extension, aborting. </>\n");
142 146
             return;
@@ -178,22 +182,30 @@  discard block
 block discarded – undo
178 182
                     "available"=>1,
179 183
                     "deleted"=>0
180 184
                 ]);
181
-            }elseif($m["method"]=="modify"){
185
+            } elseif($m["method"]=="modify"){
182 186
                 $modifyItem=[];
183
-                if(isset($m["compability"])) $modifyItem["comp"]=$m["compability"];
184
-                if(isset($m["language"])) $modifyItem["lang"]=$m["language"];
185
-                if(isset($m["icon"])) $modifyItem["icon"]=$m["icon"];
186
-                if(isset($m["display"])) $modifyItem["display_name"]=$m["display"];
187
+                if(isset($m["compability"])) {
188
+                    $modifyItem["comp"]=$m["compability"];
189
+                }
190
+                if(isset($m["language"])) {
191
+                    $modifyItem["lang"]=$m["language"];
192
+                }
193
+                if(isset($m["icon"])) {
194
+                    $modifyItem["icon"]=$m["icon"];
195
+                }
196
+                if(isset($m["display"])) {
197
+                    $modifyItem["display_name"]=$m["display"];
198
+                }
187 199
                 CompilerModel::modify([
188 200
                     "oid"=>$this->oid,
189 201
                     "lcode"=>$m["code"],
190 202
                 ], $modifyItem);
191
-            }elseif($m["method"]=="remove"){
203
+            } elseif($m["method"]=="remove"){
192 204
                 CompilerModel::remove([
193 205
                     "oid"=>$this->oid,
194 206
                     "lcode"=>$m["code"],
195 207
                 ]);
196
-            }else{
208
+            } else{
197 209
                 continue;
198 210
             }
199 211
         }
@@ -205,7 +217,7 @@  discard block
 block discarded – undo
205 217
         $storePath=base_path("public/static/img/oj/$ocode/");
206 218
         if(is_dir($storePath)) {
207 219
             $this->delFile($storePath);
208
-        }else{
220
+        } else{
209 221
             mkdir($storePath);
210 222
         }
211 223
         file_put_contents($storePath.basename($imgPath),file_get_contents($imgPath));
@@ -220,7 +232,7 @@  discard block
 block discarded – undo
220 232
         }
221 233
         if (is_null($cssPath)) {
222 234
             file_put_contents($storePath."$ocode.css", "\/*Silence is Golden*\/");
223
-        }else {
235
+        } else {
224 236
             file_put_contents($storePath."$ocode.css", file_get_contents($cssPath));
225 237
         }
226 238
     }
@@ -231,7 +243,7 @@  discard block
 block discarded – undo
231 243
                 if($item!= "." && $item != ".."){
232 244
                     if(file_exists($dirName.'/'.$item) && is_dir($dirName.'/'.$item)){
233 245
                         delFile($dirName.'/'.$item);
234
-                    }else{
246
+                    } else{
235 247
                         if(unlink($dirName.'/'.$item)){
236 248
                             return true;
237 249
                         }
Please login to merge, or discard this patch.
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -20,34 +20,34 @@  discard block
 block discarded – undo
20 20
     {
21 21
         $this->command->line("Installing <fg=green>$ocode</>");
22 22
 
23
-        $babelConfig=json_decode(file_get_contents(babel_path("Extension/$ocode/babel.json")),true);
23
+        $babelConfig=json_decode(file_get_contents(babel_path("Extension/$ocode/babel.json")), true);
24 24
 
25 25
         // support __cur__ variables
26
-        if($babelConfig["version"]=="__cur__") $babelConfig["version"]=explode("-",version())[0];
27
-        if($babelConfig["require"]["NOJ"]=="__cur__") $babelConfig["require"]["NOJ"]=explode("-",version())[0];
26
+        if ($babelConfig["version"]=="__cur__") $babelConfig["version"]=explode("-", version())[0];
27
+        if ($babelConfig["require"]["NOJ"]=="__cur__") $babelConfig["require"]["NOJ"]=explode("-", version())[0];
28 28
 
29 29
         // check version info
30
-        if(!isset($babelConfig["version"]) || is_null($babelConfig["version"]) || trim($babelConfig["version"])==""){
30
+        if (!isset($babelConfig["version"]) || is_null($babelConfig["version"]) || trim($babelConfig["version"])=="") {
31 31
             $this->command->line("\n  <bg=red;fg=white> Lack version info, aborting. </>\n");
32 32
             return;
33 33
         }
34 34
 
35 35
         // check require info
36
-        if(!isset($babelConfig["require"]["NOJ"]) || is_null($babelConfig["require"]["NOJ"]) || trim($babelConfig["require"]["NOJ"])==""){
36
+        if (!isset($babelConfig["require"]["NOJ"]) || is_null($babelConfig["require"]["NOJ"]) || trim($babelConfig["require"]["NOJ"])=="") {
37 37
             $this->command->line("\n  <bg=red;fg=white> Lack NOJ compability info, aborting. </>\n");
38 38
             return;
39 39
         }
40 40
 
41 41
         // check requirement
42 42
         try {
43
-            if(!($this->versionParser->parse($babelConfig["require"]["NOJ"])->complies(new Version(explode("-",version())[0])))){
44
-                if(!$this->command->option('ignore-platform-reqs')){
43
+            if (!($this->versionParser->parse($babelConfig["require"]["NOJ"])->complies(new Version(explode("-", version())[0])))) {
44
+                if (!$this->command->option('ignore-platform-reqs')) {
45 45
                     $this->command->line("Your Current NOJ Version <fg=yellow>".version()."</> doesn't support the following extension: ");
46 46
                     $this->command->line("  - <fg=green>$ocode</> requires NOJ version <fg=yellow>{$babelConfig['require']['NOJ']}</>");
47 47
                     return;
48 48
                 }
49 49
             }
50
-        } catch(InvalidVersionException $e) {
50
+        } catch (InvalidVersionException $e) {
51 51
             $this->command->line("\n  <bg=red;fg=white> Illegal Compability Info, aborting. </>\n");
52 52
             return;
53 53
         }
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
         $info=OJModel::basic(OJModel::oid($ocode));
59 59
 
60 60
         // if there isn't, create one
61
-        if(empty($info)){
61
+        if (empty($info)) {
62 62
             $this->oid=OJModel::insertOJ([
63 63
                 "ocode"=>$babelConfig["code"],
64 64
                 "name"=>$babelConfig["name"],
@@ -72,17 +72,17 @@  discard block
 block discarded – undo
72 72
             // check legal version format
73 73
             try {
74 74
                 $currentVersion=new Version($babelConfig["version"]);
75
-            } catch(InvalidVersionException $e) {
75
+            } catch (InvalidVersionException $e) {
76 76
                 DB::rollback();
77 77
                 $this->command->line("\n  <bg=red;fg=white> Illegal Version Info, aborting. </>\n");
78 78
                 return;
79 79
             }
80 80
 
81 81
             // check there is a not null version
82
-            if(isset($info["version"]) && !is_null($info["version"]) && trim($info["version"])!=""){
82
+            if (isset($info["version"]) && !is_null($info["version"]) && trim($info["version"])!="") {
83 83
                 try {
84 84
                     $installedVersion=new Version($info["version"]);
85
-                } catch(InvalidVersionException $e) {
85
+                } catch (InvalidVersionException $e) {
86 86
                     DB::rollback();
87 87
                     $this->command->line("\n  <bg=red;fg=white> Illegal Version Info, aborting. </>\n");
88 88
                     return;
@@ -101,15 +101,15 @@  discard block
 block discarded – undo
101 101
 
102 102
         // retrieve compiler config and then import it
103 103
         $installed_timestamp=0;
104
-        if(isset($info["compiler_timestamp"]) && !is_null($info["compiler_timestamp"]) && trim($info["compiler_timestamp"])!=""){
104
+        if (isset($info["compiler_timestamp"]) && !is_null($info["compiler_timestamp"]) && trim($info["compiler_timestamp"])!="") {
105 105
             $installed_timestamp=intval($info["compiler_timestamp"]);
106 106
         }
107 107
         $latest_timestamp=$installed_timestamp;
108
-        $ConpilerConfig = glob(babel_path("Extension/$ocode/compiler/*.*"));
109
-        foreach($ConpilerConfig as $file) {
110
-            if(intval(basename($file)) > $installed_timestamp) {
108
+        $ConpilerConfig=glob(babel_path("Extension/$ocode/compiler/*.*"));
109
+        foreach ($ConpilerConfig as $file) {
110
+            if (intval(basename($file))>$installed_timestamp) {
111 111
                 try {
112
-                    $this->commitCompiler($file,json_decode(file_get_contents($file), true));
112
+                    $this->commitCompiler($file, json_decode(file_get_contents($file), true));
113 113
                     $latest_timestamp=intval(basename($file));
114 114
                 } catch (Exception $e) {
115 115
                     DB::rollback();
@@ -124,11 +124,11 @@  discard block
 block discarded – undo
124 124
         try {
125 125
             if (isset($babelConfig["custom"]["css"]) && !is_null($babelConfig["custom"]["css"]) && trim($babelConfig["custom"]["css"])!="") {
126 126
                 $cssPath=babel_path("Extension/$ocode/".$babelConfig["custom"]["css"]);
127
-            }else{
127
+            } else {
128 128
                 $cssPath=null;
129 129
             }
130 130
             $this->applyCustom($ocode, $cssPath);
131
-        }catch(Exception $e){
131
+        } catch (Exception $e) {
132 132
             DB::rollback();
133 133
             $this->command->line("\n  <bg=red;fg=white> Unable to add an custom css for this extension, aborting. </>\n");
134 134
             return;
@@ -136,11 +136,11 @@  discard block
 block discarded – undo
136 136
 
137 137
 
138 138
         // import icon
139
-        try{
139
+        try {
140 140
             $imgPath=babel_path("Extension/$ocode/".$babelConfig["icon"]);
141 141
             $storePath=$this->applyIcon($ocode, $imgPath);
142
-            OJModel::updateOJ($this->oid,["logo"=>$storePath]);
143
-        }catch(Exception $e){
142
+            OJModel::updateOJ($this->oid, ["logo"=>$storePath]);
143
+        } catch (Exception $e) {
144 144
             DB::rollback();
145 145
             $this->command->line("\n  <bg=red;fg=white> Unable to add an icon for this extension, aborting. </>\n");
146 146
             return;
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
     protected function _uninstall($ocode)
158 158
     {
159 159
         $this->command->line("<fg=red>Warning: Removing an installed and already-used extension may cause severe consequences, including lossing user submission, problem data and contests regaring or involving the usage of this extension. </>");
160
-        if ($this->command->confirm("Are you sure you want to uninstall $ocode?")){
160
+        if ($this->command->confirm("Are you sure you want to uninstall $ocode?")) {
161 161
             //uninstall
162 162
             OJModel::removeOJ(["ocode"=>$ocode]);
163 163
             $this->command->line("Already removed <fg=green>$ocode</>");
@@ -167,16 +167,16 @@  discard block
 block discarded – undo
167 167
     public function __construct($class)
168 168
     {
169 169
         $this->command=$class;
170
-        $this->versionParser = new VersionConstraintParser();
170
+        $this->versionParser=new VersionConstraintParser();
171 171
     }
172 172
 
173 173
 
174
-    protected function commitCompiler($path,$json)
174
+    protected function commitCompiler($path, $json)
175 175
     {
176 176
         $this->command->line("<fg=yellow>Migrating: </>$path");
177 177
         $modifications=$json["modifications"];
178
-        foreach($modifications as $m){
179
-            if($m["method"]=="add"){
178
+        foreach ($modifications as $m) {
179
+            if ($m["method"]=="add") {
180 180
                 CompilerModel::add([
181 181
                     "oid"=>$this->oid,
182 182
                     "comp"=>$m["compability"],
@@ -187,22 +187,22 @@  discard block
 block discarded – undo
187 187
                     "available"=>1,
188 188
                     "deleted"=>0
189 189
                 ]);
190
-            }elseif($m["method"]=="modify"){
190
+            }elseif ($m["method"]=="modify") {
191 191
                 $modifyItem=[];
192
-                if(isset($m["compability"])) $modifyItem["comp"]=$m["compability"];
193
-                if(isset($m["language"])) $modifyItem["lang"]=$m["language"];
194
-                if(isset($m["icon"])) $modifyItem["icon"]=$m["icon"];
195
-                if(isset($m["display"])) $modifyItem["display_name"]=$m["display"];
192
+                if (isset($m["compability"])) $modifyItem["comp"]=$m["compability"];
193
+                if (isset($m["language"])) $modifyItem["lang"]=$m["language"];
194
+                if (isset($m["icon"])) $modifyItem["icon"]=$m["icon"];
195
+                if (isset($m["display"])) $modifyItem["display_name"]=$m["display"];
196 196
                 CompilerModel::modify([
197 197
                     "oid"=>$this->oid,
198 198
                     "lcode"=>$m["code"],
199 199
                 ], $modifyItem);
200
-            }elseif($m["method"]=="remove"){
200
+            }elseif ($m["method"]=="remove") {
201 201
                 CompilerModel::remove([
202 202
                     "oid"=>$this->oid,
203 203
                     "lcode"=>$m["code"],
204 204
                 ]);
205
-            }else{
205
+            } else {
206 206
                 continue;
207 207
             }
208 208
         }
@@ -212,42 +212,42 @@  discard block
 block discarded – undo
212 212
     protected function applyIcon($ocode, $imgPath)
213 213
     {
214 214
         $storePath=base_path("public/static/img/oj/$ocode/");
215
-        if(is_dir($storePath)) {
215
+        if (is_dir($storePath)) {
216 216
             $this->delFile($storePath);
217
-        }else{
217
+        } else {
218 218
             mkdir($storePath);
219 219
         }
220
-        file_put_contents($storePath.basename($imgPath),file_get_contents($imgPath));
220
+        file_put_contents($storePath.basename($imgPath), file_get_contents($imgPath));
221 221
         return "/static/img/oj/$ocode/".basename($imgPath);
222 222
     }
223 223
 
224 224
     protected function applyCustom($ocode, $cssPath)
225 225
     {
226 226
         $storePath=base_path("public/static/css/oj/");
227
-        if(!is_dir($storePath)) {
227
+        if (!is_dir($storePath)) {
228 228
             mkdir($storePath);
229 229
         }
230 230
         if (is_null($cssPath)) {
231 231
             file_put_contents($storePath."$ocode.css", "\/*Silence is Golden*\/");
232
-        }else {
232
+        } else {
233 233
             file_put_contents($storePath."$ocode.css", file_get_contents($cssPath));
234 234
         }
235 235
     }
236 236
 
237
-    private function delFile($dirName){
238
-        if(file_exists($dirName) && $handle=opendir($dirName)){
239
-            while(false!==($item = readdir($handle))){
240
-                if($item!= "." && $item != ".."){
241
-                    if(file_exists($dirName.'/'.$item) && is_dir($dirName.'/'.$item)){
237
+    private function delFile($dirName) {
238
+        if (file_exists($dirName) && $handle=opendir($dirName)) {
239
+            while (false!==($item=readdir($handle))) {
240
+                if ($item!="." && $item!="..") {
241
+                    if (file_exists($dirName.'/'.$item) && is_dir($dirName.'/'.$item)) {
242 242
                         delFile($dirName.'/'.$item);
243
-                    }else{
244
-                        if(unlink($dirName.'/'.$item)){
243
+                    } else {
244
+                        if (unlink($dirName.'/'.$item)) {
245 245
                             return true;
246 246
                         }
247 247
                     }
248 248
                 }
249 249
             }
250
-            closedir( $handle);
250
+            closedir($handle);
251 251
         }
252 252
     }
253 253
 }
Please login to merge, or discard this patch.