@@ -16,7 +16,7 @@ discard block |
||
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 |
||
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 |
||
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(); |
@@ -90,7 +90,7 @@ discard block |
||
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 |
||
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 |
||
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 | } |
@@ -412,7 +412,7 @@ discard block |
||
412 | 412 | ->where(['verdict'=>'Waiting']) |
413 | 413 | ->get() |
414 | 414 | ->all(); |
415 | - foreach($ret as &$r){ |
|
415 | + foreach ($ret as &$r) { |
|
416 | 416 | $r["ocode"]=DB::table("oj")->where(["oid"=>$r["oid"]])->first()["ocode"]; |
417 | 417 | } |
418 | 418 | return $ret; |
@@ -430,15 +430,15 @@ discard block |
||
430 | 430 | if (isset($sub['verdict'])) { |
431 | 431 | $sub["color"]=$this->colorScheme[$sub['verdict']]; |
432 | 432 | } |
433 | - $result = DB::table($this->tableName)->where(['sid'=>$sid])->update($sub); |
|
434 | - |
|
435 | - $contestModel = new ContestModel(); |
|
436 | - $submission_info = DB::table($this->tableName) -> where(['sid'=>$sid]) -> get() -> first(); |
|
437 | - if ($submission_info['cid'] && $contestModel->isContestRunning($submission_info['cid'])){ |
|
438 | - $sub['pid'] = $submission_info['pid']; |
|
439 | - $sub['uid'] = $submission_info['uid']; |
|
440 | - $sub['cid'] = $submission_info['cid']; |
|
441 | - $contestModel->updateContestRankTable($submission_info['cid'],$sub); |
|
433 | + $result=DB::table($this->tableName)->where(['sid'=>$sid])->update($sub); |
|
434 | + |
|
435 | + $contestModel=new ContestModel(); |
|
436 | + $submission_info=DB::table($this->tableName) -> where(['sid'=>$sid]) -> get() -> first(); |
|
437 | + if ($submission_info['cid'] && $contestModel->isContestRunning($submission_info['cid'])) { |
|
438 | + $sub['pid']=$submission_info['pid']; |
|
439 | + $sub['uid']=$submission_info['uid']; |
|
440 | + $sub['cid']=$submission_info['cid']; |
|
441 | + $contestModel->updateContestRankTable($submission_info['cid'], $sub); |
|
442 | 442 | } |
443 | 443 | return $result; |
444 | 444 | } |
@@ -509,15 +509,15 @@ discard block |
||
509 | 509 | 'desc' |
510 | 510 | ); |
511 | 511 | |
512 | - if($filter["pcode"]){ |
|
512 | + if ($filter["pcode"]) { |
|
513 | 513 | $paginator=$paginator->where(["pcode"=>$filter["pcode"]]); |
514 | 514 | } |
515 | 515 | |
516 | - if($filter["result"]){ |
|
516 | + if ($filter["result"]) { |
|
517 | 517 | $paginator=$paginator->where(["verdict"=>$filter["result"]]); |
518 | 518 | } |
519 | 519 | |
520 | - if($filter["account"]){ |
|
520 | + if ($filter["account"]) { |
|
521 | 521 | $paginator=$paginator->where(["name"=>$filter["account"]]); |
522 | 522 | } |
523 | 523 |
@@ -35,7 +35,9 @@ |
||
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 |
@@ -32,7 +32,7 @@ discard block |
||
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 |
||
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; |
@@ -11,7 +11,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
@@ -155,7 +155,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -131,8 +131,8 @@ |
||
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"], |
@@ -132,7 +132,9 @@ |
||
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"], |
@@ -14,30 +14,30 @@ discard block |
||
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 | - $this->totParticipants = count($contestRankRaw); |
|
29 | - $members = array_column($contestRankRaw,'uid'); |
|
30 | - $ratings_temp = DB::table('group_member') |
|
25 | + private function getRecord() { |
|
26 | + $contestModel=new ContestModel(); |
|
27 | + $contestRankRaw=$contestModel->contestRank($this->cid); |
|
28 | + $this->totParticipants=count($contestRankRaw); |
|
29 | + $members=array_column($contestRankRaw, 'uid'); |
|
30 | + $ratings_temp=DB::table('group_member') |
|
31 | 31 | ->where([ |
32 | 32 | 'gid' => $this->gid, |
33 | - ])->whereIn('uid',$members) |
|
34 | - ->select('uid','ranking') |
|
33 | + ])->whereIn('uid', $members) |
|
34 | + ->select('uid', 'ranking') |
|
35 | 35 | ->get()->all(); |
36 | - $ratings = []; |
|
36 | + $ratings=[]; |
|
37 | 37 | foreach ($ratings_temp as $rating) { |
38 | - $ratings[$rating['uid']] = $rating['ranking']; |
|
38 | + $ratings[$rating['uid']]=$rating['ranking']; |
|
39 | 39 | } |
40 | - foreach($contestRankRaw as $c){ |
|
40 | + foreach ($contestRankRaw as $c) { |
|
41 | 41 | $this->contestants[]=[ |
42 | 42 | "uid"=>$c["uid"], |
43 | 43 | "points"=>$c["score"], |
@@ -46,84 +46,84 @@ discard block |
||
46 | 46 | } |
47 | 47 | } |
48 | 48 | |
49 | - private function reassignRank(){ |
|
49 | + private function reassignRank() { |
|
50 | 50 | $this->sort("points"); |
51 | - $idx = 0; |
|
52 | - $points = $this->contestants[0]["points"]; |
|
53 | - $i = 1; |
|
54 | - while($i < $this->totParticipants){ |
|
55 | - if($this->contestants[$i]["points"] < $points){ |
|
56 | - $j = $idx; |
|
57 | - while($j < $i){ |
|
58 | - $this->contestants[$j]["rank"] = $i; |
|
59 | - $j += 1; |
|
51 | + $idx=0; |
|
52 | + $points=$this->contestants[0]["points"]; |
|
53 | + $i=1; |
|
54 | + while ($i<$this->totParticipants) { |
|
55 | + if ($this->contestants[$i]["points"]<$points) { |
|
56 | + $j=$idx; |
|
57 | + while ($j<$i) { |
|
58 | + $this->contestants[$j]["rank"]=$i; |
|
59 | + $j+=1; |
|
60 | 60 | } |
61 | - $idx = $i; |
|
62 | - $points = $this->contestants[$i]["points"]; |
|
61 | + $idx=$i; |
|
62 | + $points=$this->contestants[$i]["points"]; |
|
63 | 63 | } |
64 | - $i += 1; |
|
64 | + $i+=1; |
|
65 | 65 | } |
66 | - $j = $idx; |
|
67 | - while($j < $this->totParticipants){ |
|
68 | - $this->contestants[$j]["rank"] = $this->totParticipants; |
|
69 | - $j += 1; |
|
66 | + $j=$idx; |
|
67 | + while ($j<$this->totParticipants) { |
|
68 | + $this->contestants[$j]["rank"]=$this->totParticipants; |
|
69 | + $j+=1; |
|
70 | 70 | } |
71 | 71 | } |
72 | 72 | |
73 | - private function getEloWinProbability($Ra, $Rb){ |
|
74 | - return 1.0 / (1 + pow(10, ($Rb-$Ra)/400.0)); |
|
73 | + private function getEloWinProbability($Ra, $Rb) { |
|
74 | + return 1.0 / (1+pow(10, ($Rb-$Ra) / 400.0)); |
|
75 | 75 | } |
76 | 76 | |
77 | - private function getSeed($rating){ |
|
78 | - $result = 1.0; |
|
79 | - foreach($this->contestants as $other){ |
|
80 | - $result += $this->getEloWinProbability($other["rating"], $rating); |
|
77 | + private function getSeed($rating) { |
|
78 | + $result=1.0; |
|
79 | + foreach ($this->contestants as $other) { |
|
80 | + $result+=$this->getEloWinProbability($other["rating"], $rating); |
|
81 | 81 | } |
82 | 82 | return $result; |
83 | 83 | } |
84 | 84 | |
85 | - private function getRatingToRank($rank){ |
|
85 | + private function getRatingToRank($rank) { |
|
86 | 86 | $left=1; |
87 | 87 | $right=8000; |
88 | - while($right - $left > 1){ |
|
89 | - $mid = floor(($right + $left)/2); |
|
90 | - if($this->getSeed($mid) < $rank){ |
|
91 | - $right = $mid; |
|
92 | - }else{ |
|
93 | - $left = $mid; |
|
88 | + while ($right-$left>1) { |
|
89 | + $mid=floor(($right+$left) / 2); |
|
90 | + if ($this->getSeed($mid)<$rank) { |
|
91 | + $right=$mid; |
|
92 | + } else { |
|
93 | + $left=$mid; |
|
94 | 94 | } |
95 | 95 | } |
96 | 96 | return $left; |
97 | 97 | } |
98 | 98 | |
99 | - private function sort($key){ |
|
100 | - usort($this->contestants, function ($a, $b) use ($key) { |
|
99 | + private function sort($key) { |
|
100 | + usort($this->contestants, function($a, $b) use ($key) { |
|
101 | 101 | return $b[$key] <=> $a[$key]; |
102 | 102 | }); |
103 | 103 | } |
104 | 104 | |
105 | - public function calculate(){ |
|
106 | - if(empty($this->contestants)){ |
|
105 | + public function calculate() { |
|
106 | + if (empty($this->contestants)) { |
|
107 | 107 | return; |
108 | 108 | } |
109 | 109 | |
110 | 110 | // recalc rank |
111 | 111 | $this->reassignRank(); |
112 | 112 | |
113 | - foreach($this->contestants as &$member){ |
|
114 | - $member["seed"] = 1.0; |
|
115 | - foreach($this->contestants as $other){ |
|
116 | - if($member["uid"] != $other["uid"]){ |
|
117 | - $member["seed"] += $this->getEloWinProbability($other["rating"], $member["rating"]); |
|
113 | + foreach ($this->contestants as &$member) { |
|
114 | + $member["seed"]=1.0; |
|
115 | + foreach ($this->contestants as $other) { |
|
116 | + if ($member["uid"]!=$other["uid"]) { |
|
117 | + $member["seed"]+=$this->getEloWinProbability($other["rating"], $member["rating"]); |
|
118 | 118 | } |
119 | 119 | } |
120 | 120 | } |
121 | 121 | unset($member); |
122 | 122 | |
123 | - foreach($this->contestants as &$contestant){ |
|
124 | - $midRank = sqrt($contestant["rank"] * $contestant["seed"]); |
|
125 | - $contestant["needRating"] = $this->getRatingToRank($midRank); |
|
126 | - $contestant["delta"] = floor(($contestant["needRating"] - $contestant["rating"])/2); |
|
123 | + foreach ($this->contestants as &$contestant) { |
|
124 | + $midRank=sqrt($contestant["rank"] * $contestant["seed"]); |
|
125 | + $contestant["needRating"]=$this->getRatingToRank($midRank); |
|
126 | + $contestant["delta"]=floor(($contestant["needRating"]-$contestant["rating"]) / 2); |
|
127 | 127 | } |
128 | 128 | unset($contestant); |
129 | 129 | |
@@ -131,39 +131,39 @@ discard block |
||
131 | 131 | |
132 | 132 | // DO some adjuct |
133 | 133 | // Total sum should not be more than ZERO. |
134 | - $sum = 0; |
|
134 | + $sum=0; |
|
135 | 135 | |
136 | - foreach($this->contestants as $contestant){ |
|
137 | - $sum += $contestant["delta"]; |
|
136 | + foreach ($this->contestants as $contestant) { |
|
137 | + $sum+=$contestant["delta"]; |
|
138 | 138 | } |
139 | - $inc = -floor($sum / $this->totParticipants) - 1; |
|
140 | - foreach($this->contestants as &$contestant){ |
|
141 | - $contestant["delta"] += $inc; |
|
139 | + $inc=-floor($sum / $this->totParticipants)-1; |
|
140 | + foreach ($this->contestants as &$contestant) { |
|
141 | + $contestant["delta"]+=$inc; |
|
142 | 142 | } |
143 | 143 | unset($contestant); |
144 | 144 | |
145 | 145 | // Sum of top-4*sqrt should be adjusted to ZERO. |
146 | 146 | |
147 | - $sum = 0; |
|
148 | - $zeroSumCount = min(intval(4*round(sqrt($this->totParticipants))), $this->totParticipants); |
|
147 | + $sum=0; |
|
148 | + $zeroSumCount=min(intval(4 * round(sqrt($this->totParticipants))), $this->totParticipants); |
|
149 | 149 | |
150 | - for($i=0;$i<$zeroSumCount;$i++){ |
|
151 | - $sum += $this->contestants[$i]["delta"]; |
|
150 | + for ($i=0; $i<$zeroSumCount; $i++) { |
|
151 | + $sum+=$this->contestants[$i]["delta"]; |
|
152 | 152 | } |
153 | 153 | |
154 | - $inc = min(max(-floor($sum / $zeroSumCount), -10), 0); |
|
154 | + $inc=min(max(-floor($sum / $zeroSumCount), -10), 0); |
|
155 | 155 | |
156 | - for($i=0;$i<$zeroSumCount;$i++){ |
|
157 | - $this->contestants[$i]["delta"] += $inc; |
|
156 | + for ($i=0; $i<$zeroSumCount; $i++) { |
|
157 | + $this->contestants[$i]["delta"]+=$inc; |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | return $this->validateDeltas(); |
161 | 161 | } |
162 | 162 | |
163 | - public function storage(){ |
|
163 | + public function storage() { |
|
164 | 164 | $contestants=$this->contestants; |
165 | - DB::transaction(function () use ($contestants) { |
|
166 | - foreach($contestants as $contestant){ |
|
165 | + DB::transaction(function() use ($contestants) { |
|
166 | + foreach ($contestants as $contestant) { |
|
167 | 167 | $newRating=$contestant["rating"]+$contestant["delta"]; |
168 | 168 | DB::table("group_member")->where([ |
169 | 169 | 'gid' => $this->gid, |
@@ -181,20 +181,20 @@ discard block |
||
181 | 181 | }, 5); |
182 | 182 | } |
183 | 183 | |
184 | - private function validateDeltas(){ |
|
184 | + private function validateDeltas() { |
|
185 | 185 | $this->sort("points"); |
186 | 186 | |
187 | - for($i=0;$i<$this->totParticipants;$i++){ |
|
188 | - for($j=$i+1;$j<$this->totParticipants;$j++){ |
|
189 | - if($this->contestants[$i]["rating"] > $this->contestants[$j]["rating"]){ |
|
190 | - if($this->contestants[$i]["rating"] + $this->contestants[$i]["delta"] < $this->contestants[$j]["rating"] + $this->contestants[$j]["delta"]){ |
|
187 | + for ($i=0; $i<$this->totParticipants; $i++) { |
|
188 | + for ($j=$i+1; $j<$this->totParticipants; $j++) { |
|
189 | + if ($this->contestants[$i]["rating"]>$this->contestants[$j]["rating"]) { |
|
190 | + if ($this->contestants[$i]["rating"]+$this->contestants[$i]["delta"]<$this->contestants[$j]["rating"]+$this->contestants[$j]["delta"]) { |
|
191 | 191 | Log::warning("First rating invariant failed: {$this->contestants[i]["uid"]} vs. {$this->contestants[j]["uid"]}."); |
192 | 192 | return false; |
193 | 193 | } |
194 | 194 | } |
195 | 195 | |
196 | - if($this->contestants[$i]["rating"] < $this->contestants[$j]["rating"]){ |
|
197 | - if($this->contestants[$i]["delta"] < $this->contestants[$j]["delta"]){ |
|
196 | + if ($this->contestants[$i]["rating"]<$this->contestants[$j]["rating"]) { |
|
197 | + if ($this->contestants[$i]["delta"]<$this->contestants[$j]["delta"]) { |
|
198 | 198 | Log::warning("Second rating invariant failed: {$this->contestants[i]["uid"]} vs. {$this->contestants[j]["uid"]}."); |
199 | 199 | return false; |
200 | 200 | } |
@@ -78,7 +78,7 @@ |
||
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 | } |
@@ -100,11 +100,11 @@ |
||
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); |
@@ -265,7 +265,7 @@ |
||
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( |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | $paginator=$paginator->where(["practice"=>$filter['practice']]); |
212 | 212 | } |
213 | 213 | $paginator = $paginator ->paginate(10); |
214 | - }elseif($filter['public']=='0'){ |
|
214 | + } elseif($filter['public']=='0'){ |
|
215 | 215 | $paginator=DB::table('group_member') |
216 | 216 | ->groupBy('contest.cid') |
217 | 217 | ->select('contest.*') |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | ) |
242 | 242 | ->orderBy('contest.begin_time', 'desc') |
243 | 243 | ->paginate(10); |
244 | - }else{ |
|
244 | + } else{ |
|
245 | 245 | $paginator=DB::table('group_member') |
246 | 246 | ->groupBy('contest.cid') |
247 | 247 | ->select('contest.*') |
@@ -786,19 +786,19 @@ discard block |
||
786 | 786 | if(time() < $end_time){ |
787 | 787 | if($clearance == 3){ |
788 | 788 | $contestRankRaw=Cache::tags(['contest', 'rank'])->get("contestAdmin$cid"); |
789 | - }else{ |
|
789 | + } else{ |
|
790 | 790 | $contestRankRaw=Cache::tags(['contest', 'rank'])->get($cid); |
791 | 791 | } |
792 | 792 | if(!isset($contestRankRaw)){ |
793 | 793 | $contestRankRaw=$this->contestRankCache($cid); |
794 | 794 | } |
795 | - }else{ |
|
795 | + } else{ |
|
796 | 796 | if($clearance == 3){ |
797 | 797 | $contestRankRaw=Cache::tags(['contest', 'rank'])->get("contestAdmin$cid"); |
798 | 798 | if (!isset($contestRankRaw)) { |
799 | 799 | $contestRankRaw=$this->contestRankCache($cid); |
800 | 800 | } |
801 | - }else{ |
|
801 | + } else{ |
|
802 | 802 | $contestRankRaw=$this->getContestRankFromMySQL($cid); |
803 | 803 | if(!isset($contestRankRaw)){ |
804 | 804 | $contestRankRaw=Cache::tags(['contest', 'rank'])->get($cid); |
@@ -872,7 +872,7 @@ discard block |
||
872 | 872 | return DB::table("contest_clarification")->where([ |
873 | 873 | "cid"=>$cid |
874 | 874 | ])->orderBy('create_time', 'desc')->get()->all(); |
875 | - }else{ |
|
875 | + } else{ |
|
876 | 876 | return DB::table("contest_clarification")->where([ |
877 | 877 | "cid"=>$cid |
878 | 878 | ])->where(function ($query) { |
@@ -1105,7 +1105,7 @@ discard block |
||
1105 | 1105 | "records"=>[] |
1106 | 1106 | ]; |
1107 | 1107 | } |
1108 | - }else{ |
|
1108 | + } else{ |
|
1109 | 1109 | if ($basicInfo["status_visibility"]==2) { |
1110 | 1110 | // View all |
1111 | 1111 | $paginator=DB::table("submission")->where([ |
@@ -1327,7 +1327,7 @@ discard block |
||
1327 | 1327 | if($ratingCalculator->calculate()){ |
1328 | 1328 | $ratingCalculator->storage(); |
1329 | 1329 | return true; |
1330 | - }else{ |
|
1330 | + } else{ |
|
1331 | 1331 | return false; |
1332 | 1332 | } |
1333 | 1333 | } else { |
@@ -1424,8 +1424,7 @@ discard block |
||
1424 | 1424 | Cache::tags(['contest', 'rank'])->put($cid, $ret); |
1425 | 1425 | } |
1426 | 1426 | Cache::tags(['contest', 'rank'])->put("contestAdmin$cid", $ret); |
1427 | - } |
|
1428 | - else{ |
|
1427 | + } else{ |
|
1429 | 1428 | $ret=[]; |
1430 | 1429 | $chache=[]; |
1431 | 1430 | $chache['contest_info']=DB::table("contest")->where("cid", $cid)->first(); |
@@ -1442,7 +1441,7 @@ discard block |
||
1442 | 1441 | "cid"=>$cid, |
1443 | 1442 | "audit"=>1 |
1444 | 1443 | ])->select('uid')->get()->all(); |
1445 | - }else{ |
|
1444 | + } else{ |
|
1446 | 1445 | $submissionUsers=DB::table("submission")->where([ |
1447 | 1446 | "cid"=>$cid |
1448 | 1447 | ])->where( |
@@ -1477,9 +1476,9 @@ discard block |
||
1477 | 1476 | Cache::tags(['contest', 'rank'])->put("contestAdmin$cid", $retAdmin); |
1478 | 1477 | } |
1479 | 1478 | } |
1480 | - }catch(LockTimeoutException $e){ |
|
1479 | + } catch(LockTimeoutException $e){ |
|
1481 | 1480 | Log::warning("Contest Rank Lock Timed Out"); |
1482 | - }finally{ |
|
1481 | + } finally{ |
|
1483 | 1482 | optional($lock)->release(); |
1484 | 1483 | } |
1485 | 1484 | } |
@@ -1502,7 +1501,7 @@ discard block |
||
1502 | 1501 | return 1; |
1503 | 1502 | } |
1504 | 1503 | }); |
1505 | - }else if ($contest_info["rule"]==2){ |
|
1504 | + } else if ($contest_info["rule"]==2){ |
|
1506 | 1505 | usort($ret, function ($a, $b) { |
1507 | 1506 | if ($a["score"]==$b["score"]) { |
1508 | 1507 | if ($a["solved"]==$b["solved"]) { |
@@ -1526,8 +1525,9 @@ discard block |
||
1526 | 1525 | { |
1527 | 1526 | $id = count($ret); |
1528 | 1527 | foreach($ret as $key => $r){ |
1529 | - if($r['uid'] == $uid) |
|
1530 | - $id = $key; |
|
1528 | + if($r['uid'] == $uid) { |
|
1529 | + $id = $key; |
|
1530 | + } |
|
1531 | 1531 | } |
1532 | 1532 | if ($contest_info["rule"]==1) { |
1533 | 1533 | // ACM/ICPC Mode |
@@ -1535,7 +1535,7 @@ discard block |
||
1535 | 1535 | $prob_detail = []; |
1536 | 1536 | $totPen = 0; |
1537 | 1537 | $totScore = 0; |
1538 | - }else{ |
|
1538 | + } else{ |
|
1539 | 1539 | $prob_detail = $ret[$id]['problem_detail']; |
1540 | 1540 | $totPen=$ret[$id]['penalty']; |
1541 | 1541 | $totScore=$ret[$id]['score']; |
@@ -1575,7 +1575,7 @@ discard block |
||
1575 | 1575 | $prob_detail = []; |
1576 | 1576 | $totSolved = 0; |
1577 | 1577 | $totScore = 0; |
1578 | - }else{ |
|
1578 | + } else{ |
|
1579 | 1579 | $prob_detail = $ret[$id]['problem_detail']; |
1580 | 1580 | $totSolved=$ret[$id]['solved']; |
1581 | 1581 | $totScore=$ret[$id]['score']; |
@@ -1638,18 +1638,18 @@ discard block |
||
1638 | 1638 | return false; |
1639 | 1639 | } |
1640 | 1640 | return true; |
1641 | - }else if($status === 0){ |
|
1641 | + } else if($status === 0){ |
|
1642 | 1642 | if($begin_time_new !== null){ |
1643 | 1643 | return false; |
1644 | 1644 | } |
1645 | 1645 | if($end_time_new !== null){ |
1646 | 1646 | if(strtotime($end_time_new) <= time()){ |
1647 | 1647 | return false; |
1648 | - }else{ |
|
1648 | + } else{ |
|
1649 | 1649 | return true; |
1650 | 1650 | } |
1651 | 1651 | } |
1652 | - }else{ |
|
1652 | + } else{ |
|
1653 | 1653 | return false; |
1654 | 1654 | } |
1655 | 1655 | |
@@ -1670,8 +1670,7 @@ discard block |
||
1670 | 1670 | return DB::table("contest_clarification")->where('ccid','=',$ccid)->update([ |
1671 | 1671 | "public"=>1 |
1672 | 1672 | ]); |
1673 | - } |
|
1674 | - else |
|
1673 | + } else |
|
1675 | 1674 | { |
1676 | 1675 | return DB::table("contest_clarification")->where('ccid','=',$ccid)->update([ |
1677 | 1676 | "public"=>0 |
@@ -111,8 +111,8 @@ discard block |
||
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() |
@@ -130,19 +130,19 @@ discard block |
||
130 | 130 | |
131 | 131 | public function listForSetting($gid) |
132 | 132 | { |
133 | - $uid = Auth::user()->id; |
|
134 | - $group_contests = DB::table('contest') |
|
135 | - ->where('gid',$gid) |
|
136 | - ->orderBy('begin_time','desc') |
|
133 | + $uid=Auth::user()->id; |
|
134 | + $group_contests=DB::table('contest') |
|
135 | + ->where('gid', $gid) |
|
136 | + ->orderBy('begin_time', 'desc') |
|
137 | 137 | ->get()->all(); |
138 | - $groupModel = new GroupModel(); |
|
139 | - $group_clearance = $groupModel->judgeClearance($gid,$uid); |
|
138 | + $groupModel=new GroupModel(); |
|
139 | + $group_clearance=$groupModel->judgeClearance($gid, $uid); |
|
140 | 140 | foreach ($group_contests as &$contest) { |
141 | - $contest['is_admin'] = ($contest['assign_uid'] == $uid || $group_clearance == 3); |
|
142 | - $begin_stamps = strtotime($contest['begin_time']); |
|
143 | - $end_stamps = strtotime($contest['end_time']); |
|
144 | - $contest['status'] = time() >= $end_stamps ? 1 |
|
145 | - : (time() <= $begin_stamps ? -1 : 0); |
|
141 | + $contest['is_admin']=($contest['assign_uid']==$uid || $group_clearance==3); |
|
142 | + $begin_stamps=strtotime($contest['begin_time']); |
|
143 | + $end_stamps=strtotime($contest['end_time']); |
|
144 | + $contest['status']=time()>=$end_stamps ? 1 |
|
145 | + : (time()<=$begin_stamps ? -1 : 0); |
|
146 | 146 | $contest["rule_parsed"]=$this->rule[$contest["rule"]]; |
147 | 147 | $contest["date_parsed"]=[ |
148 | 148 | "date"=>date_format(date_create($contest["begin_time"]), 'j'), |
@@ -159,9 +159,9 @@ discard block |
||
159 | 159 | // "gid"=>$gid |
160 | 160 | // ])->orderBy('begin_time', 'desc')->get()->all(); |
161 | 161 | $preQuery=DB::table($this->tableName); |
162 | - $paginator=$preQuery->where('gid','=',$gid)->orderBy('begin_time', 'desc')->paginate(10); |
|
162 | + $paginator=$preQuery->where('gid', '=', $gid)->orderBy('begin_time', 'desc')->paginate(10); |
|
163 | 163 | $contest_list=$paginator->all(); |
164 | - if(empty($contest_list)){ |
|
164 | + if (empty($contest_list)) { |
|
165 | 165 | return null; |
166 | 166 | } |
167 | 167 | |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | ])->first()["rule"]; |
187 | 187 | } |
188 | 188 | |
189 | - public function list($filter,$uid) |
|
189 | + public function list($filter, $uid) |
|
190 | 190 | { |
191 | 191 | if ($uid) { |
192 | 192 | //$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); |
@@ -210,15 +210,15 @@ discard block |
||
210 | 210 | if ($filter['practice']) { |
211 | 211 | $paginator=$paginator->where(["practice"=>$filter['practice']]); |
212 | 212 | } |
213 | - $paginator = $paginator ->paginate(10); |
|
214 | - }elseif($filter['public']=='0'){ |
|
213 | + $paginator=$paginator ->paginate(10); |
|
214 | + }elseif ($filter['public']=='0') { |
|
215 | 215 | $paginator=DB::table('group_member') |
216 | 216 | ->groupBy('contest.cid') |
217 | 217 | ->select('contest.*') |
218 | 218 | ->join('contest', 'group_member.gid', '=', 'contest.gid') |
219 | 219 | ->leftJoin('contest_participant', 'contest.cid', '=', 'contest_participant.cid') |
220 | 220 | ->where( |
221 | - function ($query) use ($filter,$uid) { |
|
221 | + function($query) use ($filter, $uid) { |
|
222 | 222 | if ($filter['rule']) { |
223 | 223 | $query=$query->where(["rule"=>$filter['rule']]); |
224 | 224 | } |
@@ -241,14 +241,14 @@ discard block |
||
241 | 241 | ) |
242 | 242 | ->orderBy('contest.begin_time', 'desc') |
243 | 243 | ->paginate(10); |
244 | - }else{ |
|
244 | + } else { |
|
245 | 245 | $paginator=DB::table('group_member') |
246 | 246 | ->groupBy('contest.cid') |
247 | 247 | ->select('contest.*') |
248 | 248 | ->join('contest', 'group_member.gid', '=', 'contest.gid') |
249 | 249 | ->leftJoin('contest_participant', 'contest.cid', '=', 'contest_participant.cid') |
250 | 250 | ->where( |
251 | - function ($query) use ($filter) { |
|
251 | + function($query) use ($filter) { |
|
252 | 252 | if ($filter['rule']) { |
253 | 253 | $query=$query->where(["rule"=>$filter['rule']]); |
254 | 254 | } |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | } |
270 | 270 | ) |
271 | 271 | ->orWhere( |
272 | - function ($query) use ($filter,$uid) { |
|
272 | + function($query) use ($filter, $uid) { |
|
273 | 273 | if ($filter['rule']) { |
274 | 274 | $query=$query->where(["rule"=>$filter['rule']]); |
275 | 275 | } |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | if ($filter['practice']) { |
316 | 316 | $paginator=$paginator->where(["practice"=>$filter['practice']]); |
317 | 317 | } |
318 | - $paginator = $paginator ->paginate(10); |
|
318 | + $paginator=$paginator ->paginate(10); |
|
319 | 319 | } |
320 | 320 | $contest_list=$paginator->all(); |
321 | 321 | foreach ($contest_list as &$c) { |
@@ -353,14 +353,14 @@ discard block |
||
353 | 353 | } |
354 | 354 | } |
355 | 355 | |
356 | - public function registContest($cid,$uid) |
|
356 | + public function registContest($cid, $uid) |
|
357 | 357 | { |
358 | 358 | $registered=DB::table("contest_participant")->where([ |
359 | 359 | "cid"=>$cid, |
360 | 360 | "uid"=>$uid |
361 | 361 | ])->first(); |
362 | 362 | |
363 | - if(empty($registered)){ |
|
363 | + if (empty($registered)) { |
|
364 | 364 | DB::table("contest_participant")->insert([ |
365 | 365 | "cid"=>$cid, |
366 | 366 | "uid"=>$uid, |
@@ -393,9 +393,9 @@ discard block |
||
393 | 393 | public function problems($cid) |
394 | 394 | { |
395 | 395 | return DB::table('contest_problem') |
396 | - ->join('problem','contest_problem.pid','=','problem.pid') |
|
397 | - ->where('cid',$cid) |
|
398 | - ->select('problem.pid as pid','pcode','number') |
|
396 | + ->join('problem', 'contest_problem.pid', '=', 'problem.pid') |
|
397 | + ->where('cid', $cid) |
|
398 | + ->select('problem.pid as pid', 'pcode', 'number') |
|
399 | 399 | ->get()->all(); |
400 | 400 | } |
401 | 401 | |
@@ -416,18 +416,18 @@ discard block |
||
416 | 416 | $end_time=strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]); |
417 | 417 | |
418 | 418 | foreach ($problemSet as &$p) { |
419 | - if($p['practice']){ |
|
420 | - $tags = DB::table("group_problem_tag") |
|
421 | - ->where('gid',$p['gid']) |
|
422 | - ->where('pid',$p['pid']) |
|
419 | + if ($p['practice']) { |
|
420 | + $tags=DB::table("group_problem_tag") |
|
421 | + ->where('gid', $p['gid']) |
|
422 | + ->where('pid', $p['pid']) |
|
423 | 423 | ->get()->all(); |
424 | - $tags_arr = []; |
|
425 | - if(!empty($tags)){ |
|
424 | + $tags_arr=[]; |
|
425 | + if (!empty($tags)) { |
|
426 | 426 | foreach ($tags as $value) { |
427 | - array_push($tags_arr,$value['tag']); |
|
427 | + array_push($tags_arr, $value['tag']); |
|
428 | 428 | } |
429 | 429 | } |
430 | - $p['tags'] = $tags_arr; |
|
430 | + $p['tags']=$tags_arr; |
|
431 | 431 | } |
432 | 432 | if ($contest_rule==1) { |
433 | 433 | $prob_stat=DB::table("submission")->select( |
@@ -688,7 +688,7 @@ discard block |
||
688 | 688 | "problem_detail" => $prob_detail |
689 | 689 | ]; |
690 | 690 | } |
691 | - usort($ret, function ($a, $b) { |
|
691 | + usort($ret, function($a, $b) { |
|
692 | 692 | if ($a["score"]==$b["score"]) { |
693 | 693 | if ($a["penalty"]==$b["penalty"]) { |
694 | 694 | return 0; |
@@ -735,7 +735,7 @@ discard block |
||
735 | 735 | "problem_detail" => $prob_detail |
736 | 736 | ]; |
737 | 737 | } |
738 | - usort($ret, function ($a, $b) { |
|
738 | + usort($ret, function($a, $b) { |
|
739 | 739 | if ($a["score"]==$b["score"]) { |
740 | 740 | if ($a["solved"]==$b["solved"]) { |
741 | 741 | return 0; |
@@ -757,7 +757,7 @@ discard block |
||
757 | 757 | return $ret; |
758 | 758 | } |
759 | 759 | |
760 | - public function contestRank($cid, $uid = 0) |
|
760 | + public function contestRank($cid, $uid=0) |
|
761 | 761 | { |
762 | 762 | // [ToDo] If the current user's in the organizer group show nick name |
763 | 763 | // [ToDo] The participants determination |
@@ -775,31 +775,31 @@ discard block |
||
775 | 775 | "gid" => $contest_info["gid"] |
776 | 776 | ])->where("role", ">", 0)->first()); |
777 | 777 | |
778 | - $clearance = $this -> judgeClearance($cid, $uid); |
|
778 | + $clearance=$this -> judgeClearance($cid, $uid); |
|
779 | 779 | |
780 | 780 | /** New Version With MySQL */ |
781 | 781 | $end_time=strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]); |
782 | 782 | |
783 | - if(time() < $end_time){ |
|
784 | - if($clearance == 3){ |
|
783 | + if (time()<$end_time) { |
|
784 | + if ($clearance==3) { |
|
785 | 785 | $contestRankRaw=Cache::tags(['contest', 'rank'])->get("contestAdmin$cid"); |
786 | - }else{ |
|
786 | + } else { |
|
787 | 787 | $contestRankRaw=Cache::tags(['contest', 'rank'])->get($cid); |
788 | 788 | } |
789 | - if(!isset($contestRankRaw)){ |
|
789 | + if (!isset($contestRankRaw)) { |
|
790 | 790 | $contestRankRaw=$this->contestRankCache($cid); |
791 | 791 | } |
792 | - }else{ |
|
793 | - if($clearance == 3){ |
|
792 | + } else { |
|
793 | + if ($clearance==3) { |
|
794 | 794 | $contestRankRaw=Cache::tags(['contest', 'rank'])->get("contestAdmin$cid"); |
795 | 795 | if (!isset($contestRankRaw)) { |
796 | 796 | $contestRankRaw=$this->contestRankCache($cid); |
797 | 797 | } |
798 | - }else{ |
|
798 | + } else { |
|
799 | 799 | $contestRankRaw=$this->getContestRankFromMySQL($cid); |
800 | - if(!isset($contestRankRaw)){ |
|
800 | + if (!isset($contestRankRaw)) { |
|
801 | 801 | $contestRankRaw=Cache::tags(['contest', 'rank'])->get($cid); |
802 | - if(!isset($contestRankRaw)){ |
|
802 | + if (!isset($contestRankRaw)) { |
|
803 | 803 | $contestRankRaw=$this->contestRankCache($cid); |
804 | 804 | } |
805 | 805 | $this->storeContestRankInMySQL($cid, $contestRankRaw); |
@@ -817,15 +817,15 @@ discard block |
||
817 | 817 | // $contestRankRaw=$this->contestRankCache($cid); |
818 | 818 | // } |
819 | 819 | // } |
820 | - if($contest_info["rule"]==1){ |
|
820 | + if ($contest_info["rule"]==1) { |
|
821 | 821 | foreach ($contestRankRaw as &$cr) { |
822 | - $solved = 0; |
|
823 | - foreach($cr['problem_detail'] as $pd){ |
|
824 | - if(!empty($pd['solved_time_parsed'])){ |
|
825 | - $solved ++; |
|
822 | + $solved=0; |
|
823 | + foreach ($cr['problem_detail'] as $pd) { |
|
824 | + if (!empty($pd['solved_time_parsed'])) { |
|
825 | + $solved++; |
|
826 | 826 | } |
827 | 827 | } |
828 | - $cr['solved'] = $solved; |
|
828 | + $cr['solved']=$solved; |
|
829 | 829 | } |
830 | 830 | } |
831 | 831 | |
@@ -874,16 +874,16 @@ discard block |
||
874 | 874 | |
875 | 875 | public function getClarificationList($cid) |
876 | 876 | { |
877 | - $uid = Auth::user()->id; |
|
878 | - $clearance = $this -> judgeClearance($cid, $uid); |
|
879 | - if($clearance == 3){ |
|
877 | + $uid=Auth::user()->id; |
|
878 | + $clearance=$this -> judgeClearance($cid, $uid); |
|
879 | + if ($clearance==3) { |
|
880 | 880 | return DB::table("contest_clarification")->where([ |
881 | 881 | "cid"=>$cid |
882 | 882 | ])->orderBy('create_time', 'desc')->get()->all(); |
883 | - }else{ |
|
883 | + } else { |
|
884 | 884 | return DB::table("contest_clarification")->where([ |
885 | 885 | "cid"=>$cid |
886 | - ])->where(function ($query) { |
|
886 | + ])->where(function($query) { |
|
887 | 887 | $query->where([ |
888 | 888 | "public"=>1 |
889 | 889 | ])->orWhere([ |
@@ -1024,7 +1024,7 @@ discard block |
||
1024 | 1024 | public function getContestRecord($cid) |
1025 | 1025 | { |
1026 | 1026 | $basicInfo=$this->basic($cid); |
1027 | - $userInfo=DB::table('group_member')->where('gid',$basicInfo["gid"])->where('uid',Auth::user()->id)->get()->first(); |
|
1027 | + $userInfo=DB::table('group_member')->where('gid', $basicInfo["gid"])->where('uid', Auth::user()->id)->get()->first(); |
|
1028 | 1028 | $problemSet_temp=DB::table("contest_problem")->join("problem", "contest_problem.pid", "=", "problem.pid")->where([ |
1029 | 1029 | "cid"=>$cid |
1030 | 1030 | ])->orderBy('ncode', 'asc')->select("ncode", "alias", "contest_problem.pid as pid", "title", "points", "tot_score")->get()->all(); |
@@ -1037,7 +1037,7 @@ discard block |
||
1037 | 1037 | $end_time=strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]); |
1038 | 1038 | $contestEnd=time()>$end_time; |
1039 | 1039 | |
1040 | - if($userInfo==null || $userInfo["role"]!=3){ |
|
1040 | + if ($userInfo==null || $userInfo["role"]!=3) { |
|
1041 | 1041 | if ($basicInfo["status_visibility"]==2) { |
1042 | 1042 | // View all |
1043 | 1043 | $paginator=DB::table("submission")->where([ |
@@ -1051,7 +1051,7 @@ discard block |
||
1051 | 1051 | "users.id", |
1052 | 1052 | "=", |
1053 | 1053 | "submission.uid" |
1054 | - )->where(function ($query) use ($frozen_time) { |
|
1054 | + )->where(function($query) use ($frozen_time) { |
|
1055 | 1055 | $query->where( |
1056 | 1056 | "submission_date", |
1057 | 1057 | "<", |
@@ -1113,7 +1113,7 @@ discard block |
||
1113 | 1113 | "records"=>[] |
1114 | 1114 | ]; |
1115 | 1115 | } |
1116 | - }else{ |
|
1116 | + } else { |
|
1117 | 1117 | if ($basicInfo["status_visibility"]==2) { |
1118 | 1118 | // View all |
1119 | 1119 | $paginator=DB::table("submission")->where([ |
@@ -1225,21 +1225,21 @@ discard block |
||
1225 | 1225 | if ($uid==0) { |
1226 | 1226 | return 0; |
1227 | 1227 | } |
1228 | - $groupModel = new GroupModel(); |
|
1228 | + $groupModel=new GroupModel(); |
|
1229 | 1229 | $contest_info=DB::table("contest")->where("cid", $cid)->first(); |
1230 | - $userInfo=DB::table('group_member')->where('gid',$contest_info["gid"])->where('uid',$uid)->get()->first(); |
|
1230 | + $userInfo=DB::table('group_member')->where('gid', $contest_info["gid"])->where('uid', $uid)->get()->first(); |
|
1231 | 1231 | |
1232 | - if(empty($contest_info)){ |
|
1232 | + if (empty($contest_info)) { |
|
1233 | 1233 | // contest not exist |
1234 | 1234 | return 0; |
1235 | 1235 | } |
1236 | 1236 | |
1237 | - if($uid == $contest_info['assign_uid'] || $groupModel->judgeClearance($contest_info['gid'],$uid) == 3){ |
|
1237 | + if ($uid==$contest_info['assign_uid'] || $groupModel->judgeClearance($contest_info['gid'], $uid)==3) { |
|
1238 | 1238 | return 3; |
1239 | 1239 | } |
1240 | 1240 | |
1241 | - $contest_started = strtotime($contest_info['begin_time']) < time(); |
|
1242 | - $contest_ended = strtotime($contest_info['end_time']) < time(); |
|
1241 | + $contest_started=strtotime($contest_info['begin_time'])<time(); |
|
1242 | + $contest_ended=strtotime($contest_info['end_time'])<time(); |
|
1243 | 1243 | if (!$contest_started) { |
1244 | 1244 | // not started or do not exist |
1245 | 1245 | return 0; |
@@ -1330,12 +1330,12 @@ discard block |
||
1330 | 1330 | public function updateProfessionalRate($cid) |
1331 | 1331 | { |
1332 | 1332 | $basic=$this->basic($cid); |
1333 | - if($basic["rated"]&&!$basic["is_rated"]){ |
|
1333 | + if ($basic["rated"] && !$basic["is_rated"]) { |
|
1334 | 1334 | $ratingCalculator=new RatingCalculator($cid); |
1335 | - if($ratingCalculator->calculate()){ |
|
1335 | + if ($ratingCalculator->calculate()) { |
|
1336 | 1336 | $ratingCalculator->storage(); |
1337 | 1337 | return true; |
1338 | - }else{ |
|
1338 | + } else { |
|
1339 | 1339 | return false; |
1340 | 1340 | } |
1341 | 1341 | } else { |
@@ -1343,14 +1343,14 @@ discard block |
||
1343 | 1343 | } |
1344 | 1344 | } |
1345 | 1345 | |
1346 | - public function contestUpdate($cid,$data,$problems) |
|
1346 | + public function contestUpdate($cid, $data, $problems) |
|
1347 | 1347 | { |
1348 | - DB::transaction(function () use ($cid, $data, $problems) { |
|
1348 | + DB::transaction(function() use ($cid, $data, $problems) { |
|
1349 | 1349 | DB::table($this->tableName) |
1350 | - ->where('cid',$cid) |
|
1350 | + ->where('cid', $cid) |
|
1351 | 1351 | ->update($data); |
1352 | 1352 | DB::table('contest_problem') |
1353 | - ->where('cid',$cid) |
|
1353 | + ->where('cid', $cid) |
|
1354 | 1354 | ->delete(); |
1355 | 1355 | foreach ($problems as $p) { |
1356 | 1356 | $pid=DB::table("problem")->where(["pcode"=>$p["pcode"]])->select("pid")->first()["pid"]; |
@@ -1368,7 +1368,7 @@ discard block |
||
1368 | 1368 | |
1369 | 1369 | public function arrangeContest($gid, $config, $problems) |
1370 | 1370 | { |
1371 | - DB::transaction(function () use ($gid, $config, $problems) { |
|
1371 | + DB::transaction(function() use ($gid, $config, $problems) { |
|
1372 | 1372 | $cid=DB::table($this->tableName)->insertGetId([ |
1373 | 1373 | "gid"=>$gid, |
1374 | 1374 | "name"=>$config["name"], |
@@ -1382,7 +1382,7 @@ discard block |
||
1382 | 1382 | "rule"=>1, //todo |
1383 | 1383 | "begin_time"=>$config["begin_time"], |
1384 | 1384 | "end_time"=>$config["end_time"], |
1385 | - "vcid"=>isset($config["vcid"])?$config["vcid"]:null, |
|
1385 | + "vcid"=>isset($config["vcid"]) ? $config["vcid"] : null, |
|
1386 | 1386 | "public"=>0, //todo |
1387 | 1387 | "registration"=>0, //todo |
1388 | 1388 | "registration_due"=>null, //todo |
@@ -1407,33 +1407,33 @@ discard block |
||
1407 | 1407 | }, 5); |
1408 | 1408 | } |
1409 | 1409 | |
1410 | - public function updateContestRankTable($cid,$sub) |
|
1410 | + public function updateContestRankTable($cid, $sub) |
|
1411 | 1411 | { |
1412 | - $lock = Cache::lock("contestrank$cid",10); |
|
1413 | - try{ |
|
1414 | - if($lock->get()){ |
|
1415 | - if(Cache::tags(['contest','rank'])->get($cid) != null){ |
|
1416 | - $chache = Cache::tags(['contest','data'])->get($cid); |
|
1417 | - $ret = Cache::tags(['contest','rank'])->get($cid); |
|
1418 | - |
|
1419 | - $id = 0; |
|
1420 | - |
|
1421 | - foreach($chache['problemSet'] as $key => $p){ |
|
1422 | - if ($p['pid'] == $sub['pid']){ |
|
1423 | - $chache['problemSet'][$key]['cpid'] = $key; |
|
1424 | - $id = $key; |
|
1412 | + $lock=Cache::lock("contestrank$cid", 10); |
|
1413 | + try { |
|
1414 | + if ($lock->get()) { |
|
1415 | + if (Cache::tags(['contest', 'rank'])->get($cid)!=null) { |
|
1416 | + $chache=Cache::tags(['contest', 'data'])->get($cid); |
|
1417 | + $ret=Cache::tags(['contest', 'rank'])->get($cid); |
|
1418 | + |
|
1419 | + $id=0; |
|
1420 | + |
|
1421 | + foreach ($chache['problemSet'] as $key => $p) { |
|
1422 | + if ($p['pid']==$sub['pid']) { |
|
1423 | + $chache['problemSet'][$key]['cpid']=$key; |
|
1424 | + $id=$key; |
|
1425 | 1425 | } |
1426 | 1426 | } |
1427 | 1427 | |
1428 | - $ret = $this->updateContestRankDetail($chache['contest_info'],$chache['problemSet'][$id],$cid,$sub['uid'],$ret); |
|
1429 | - $ret = $this->sortContestRankTable($chache['contest_info'],$cid,$ret); |
|
1428 | + $ret=$this->updateContestRankDetail($chache['contest_info'], $chache['problemSet'][$id], $cid, $sub['uid'], $ret); |
|
1429 | + $ret=$this->sortContestRankTable($chache['contest_info'], $cid, $ret); |
|
1430 | 1430 | |
1431 | - if (time() < $chache['frozen_time']){ |
|
1431 | + if (time()<$chache['frozen_time']) { |
|
1432 | 1432 | Cache::tags(['contest', 'rank'])->put($cid, $ret); |
1433 | 1433 | } |
1434 | 1434 | Cache::tags(['contest', 'rank'])->put("contestAdmin$cid", $ret); |
1435 | 1435 | } |
1436 | - else{ |
|
1436 | + else { |
|
1437 | 1437 | $ret=[]; |
1438 | 1438 | $chache=[]; |
1439 | 1439 | $chache['contest_info']=DB::table("contest")->where("cid", $cid)->first(); |
@@ -1450,7 +1450,7 @@ discard block |
||
1450 | 1450 | "cid"=>$cid, |
1451 | 1451 | "audit"=>1 |
1452 | 1452 | ])->select('uid')->get()->all(); |
1453 | - }else{ |
|
1453 | + } else { |
|
1454 | 1454 | $submissionUsers=DB::table("submission")->where([ |
1455 | 1455 | "cid"=>$cid |
1456 | 1456 | ])->where( |
@@ -1463,39 +1463,39 @@ discard block |
||
1463 | 1463 | ])->select('uid')->groupBy('uid')->get()->all(); |
1464 | 1464 | } |
1465 | 1465 | |
1466 | - $chacheAdmin = $chache; |
|
1466 | + $chacheAdmin=$chache; |
|
1467 | 1467 | |
1468 | 1468 | foreach ($submissionUsers as $s) { |
1469 | 1469 | foreach ($chache['problemSet'] as $key => $p) { |
1470 | - $p['cpid'] = $key; |
|
1471 | - $ret = $this->updateContestRankDetail($chache['contest_info'],$p,$cid,$s['uid'],$ret); |
|
1470 | + $p['cpid']=$key; |
|
1471 | + $ret=$this->updateContestRankDetail($chache['contest_info'], $p, $cid, $s['uid'], $ret); |
|
1472 | 1472 | } |
1473 | 1473 | } |
1474 | - $ret = $this->sortContestRankTable($chache['contest_info'],$cid,$ret); |
|
1474 | + $ret=$this->sortContestRankTable($chache['contest_info'], $cid, $ret); |
|
1475 | 1475 | Cache::tags(['contest', 'rank'])->put($cid, $ret); |
1476 | 1476 | |
1477 | 1477 | $retAdmin=[]; |
1478 | 1478 | foreach ($submissionUsersAdmin as $s) { |
1479 | 1479 | foreach ($chacheAdmin['problemSet'] as $key => $p) { |
1480 | - $p['cpid'] = $key; |
|
1481 | - $retAdmin = $this->updateContestRankDetail($chacheAdmin['contest_info'],$p,$cid,$s['uid'],$retAdmin); |
|
1480 | + $p['cpid']=$key; |
|
1481 | + $retAdmin=$this->updateContestRankDetail($chacheAdmin['contest_info'], $p, $cid, $s['uid'], $retAdmin); |
|
1482 | 1482 | } |
1483 | 1483 | } |
1484 | - $retAdmin = $this->sortContestRankTable($chacheAdmin['contest_info'],$cid,$retAdmin); |
|
1484 | + $retAdmin=$this->sortContestRankTable($chacheAdmin['contest_info'], $cid, $retAdmin); |
|
1485 | 1485 | Cache::tags(['contest', 'rank'])->put("contestAdmin$cid", $retAdmin); |
1486 | 1486 | } |
1487 | 1487 | } |
1488 | - }catch(LockTimeoutException $e){ |
|
1488 | + } catch (LockTimeoutException $e) { |
|
1489 | 1489 | Log::warning("Contest Rank Lock Timed Out"); |
1490 | - }finally{ |
|
1490 | + } finally { |
|
1491 | 1491 | optional($lock)->release(); |
1492 | 1492 | } |
1493 | 1493 | } |
1494 | 1494 | |
1495 | - public function sortContestRankTable($contest_info,$cid,$ret) |
|
1495 | + public function sortContestRankTable($contest_info, $cid, $ret) |
|
1496 | 1496 | { |
1497 | - if ($contest_info["rule"]==1){ |
|
1498 | - usort($ret, function ($a, $b) { |
|
1497 | + if ($contest_info["rule"]==1) { |
|
1498 | + usort($ret, function($a, $b) { |
|
1499 | 1499 | if ($a["score"]==$b["score"]) { |
1500 | 1500 | if ($a["penalty"]==$b["penalty"]) { |
1501 | 1501 | return 0; |
@@ -1510,8 +1510,8 @@ discard block |
||
1510 | 1510 | return 1; |
1511 | 1511 | } |
1512 | 1512 | }); |
1513 | - }else if ($contest_info["rule"]==2){ |
|
1514 | - usort($ret, function ($a, $b) { |
|
1513 | + } else if ($contest_info["rule"]==2) { |
|
1514 | + usort($ret, function($a, $b) { |
|
1515 | 1515 | if ($a["score"]==$b["score"]) { |
1516 | 1516 | if ($a["solved"]==$b["solved"]) { |
1517 | 1517 | return 0; |
@@ -1530,21 +1530,21 @@ discard block |
||
1530 | 1530 | return $ret; |
1531 | 1531 | } |
1532 | 1532 | |
1533 | - public function updateContestRankDetail($contest_info,$problem,$cid,$uid,$ret) |
|
1533 | + public function updateContestRankDetail($contest_info, $problem, $cid, $uid, $ret) |
|
1534 | 1534 | { |
1535 | - $id = count($ret); |
|
1536 | - foreach($ret as $key => $r){ |
|
1537 | - if($r['uid'] == $uid) |
|
1538 | - $id = $key; |
|
1535 | + $id=count($ret); |
|
1536 | + foreach ($ret as $key => $r) { |
|
1537 | + if ($r['uid']==$uid) |
|
1538 | + $id=$key; |
|
1539 | 1539 | } |
1540 | 1540 | if ($contest_info["rule"]==1) { |
1541 | 1541 | // ACM/ICPC Mode |
1542 | - if($id == count($ret)){ |
|
1543 | - $prob_detail = []; |
|
1544 | - $totPen = 0; |
|
1545 | - $totScore = 0; |
|
1546 | - }else{ |
|
1547 | - $prob_detail = $ret[$id]['problem_detail']; |
|
1542 | + if ($id==count($ret)) { |
|
1543 | + $prob_detail=[]; |
|
1544 | + $totPen=0; |
|
1545 | + $totScore=0; |
|
1546 | + } else { |
|
1547 | + $prob_detail=$ret[$id]['problem_detail']; |
|
1548 | 1548 | $totPen=$ret[$id]['penalty']; |
1549 | 1549 | $totScore=$ret[$id]['score']; |
1550 | 1550 | }; |
@@ -1579,12 +1579,12 @@ discard block |
||
1579 | 1579 | ]; |
1580 | 1580 | } elseif ($contest_info["rule"]==2) { |
1581 | 1581 | // OI Mode |
1582 | - if($id == count($ret)){ |
|
1583 | - $prob_detail = []; |
|
1584 | - $totSolved = 0; |
|
1585 | - $totScore = 0; |
|
1586 | - }else{ |
|
1587 | - $prob_detail = $ret[$id]['problem_detail']; |
|
1582 | + if ($id==count($ret)) { |
|
1583 | + $prob_detail=[]; |
|
1584 | + $totSolved=0; |
|
1585 | + $totScore=0; |
|
1586 | + } else { |
|
1587 | + $prob_detail=$ret[$id]['problem_detail']; |
|
1588 | 1588 | $totSolved=$ret[$id]['solved']; |
1589 | 1589 | $totScore=$ret[$id]['score']; |
1590 | 1590 | }; |
@@ -1617,47 +1617,47 @@ discard block |
||
1617 | 1617 | return $ret; |
1618 | 1618 | } |
1619 | 1619 | |
1620 | - public function assignMember($cid,$uid){ |
|
1620 | + public function assignMember($cid, $uid) { |
|
1621 | 1621 | return DB::table("contest")->where(["cid"=>$cid])->update([ |
1622 | 1622 | "assign_uid"=>$uid |
1623 | 1623 | ]); |
1624 | 1624 | } |
1625 | 1625 | |
1626 | - public function canUpdateContestTime($cid,$time = []) |
|
1626 | + public function canUpdateContestTime($cid, $time=[]) |
|
1627 | 1627 | { |
1628 | - $begin_time_new = $time['begin'] ?? null; |
|
1629 | - $end_time_new = $time['end'] ?? null; |
|
1628 | + $begin_time_new=$time['begin'] ?? null; |
|
1629 | + $end_time_new=$time['end'] ?? null; |
|
1630 | 1630 | |
1631 | - $hold_time = DB::table('contest') |
|
1632 | - ->where('cid',$cid) |
|
1633 | - ->select('begin_time','end_time') |
|
1631 | + $hold_time=DB::table('contest') |
|
1632 | + ->where('cid', $cid) |
|
1633 | + ->select('begin_time', 'end_time') |
|
1634 | 1634 | ->first(); |
1635 | - $begin_stamps = strtotime($hold_time['begin_time']); |
|
1636 | - $end_stamps = strtotime($hold_time['end_time']); |
|
1635 | + $begin_stamps=strtotime($hold_time['begin_time']); |
|
1636 | + $end_stamps=strtotime($hold_time['end_time']); |
|
1637 | 1637 | /* |
1638 | 1638 | -1 : have not begun |
1639 | 1639 | 0 : ing |
1640 | 1640 | 1 : end |
1641 | 1641 | */ |
1642 | - $status = time() >= $end_stamps ? 1 |
|
1643 | - : (time() <= $begin_stamps ? -1 : 0); |
|
1644 | - if($status === -1){ |
|
1645 | - if(time() > $begin_time_new){ |
|
1642 | + $status=time()>=$end_stamps ? 1 |
|
1643 | + : (time()<=$begin_stamps ? -1 : 0); |
|
1644 | + if ($status===-1) { |
|
1645 | + if (time()>$begin_time_new) { |
|
1646 | 1646 | return false; |
1647 | 1647 | } |
1648 | 1648 | return true; |
1649 | - }else if($status === 0){ |
|
1650 | - if($begin_time_new !== null){ |
|
1649 | + } else if ($status===0) { |
|
1650 | + if ($begin_time_new!==null) { |
|
1651 | 1651 | return false; |
1652 | 1652 | } |
1653 | - if($end_time_new !== null){ |
|
1654 | - if(strtotime($end_time_new) <= time()){ |
|
1653 | + if ($end_time_new!==null) { |
|
1654 | + if (strtotime($end_time_new)<=time()) { |
|
1655 | 1655 | return false; |
1656 | - }else{ |
|
1656 | + } else { |
|
1657 | 1657 | return true; |
1658 | 1658 | } |
1659 | 1659 | } |
1660 | - }else{ |
|
1660 | + } else { |
|
1661 | 1661 | return false; |
1662 | 1662 | } |
1663 | 1663 | |
@@ -1666,22 +1666,22 @@ discard block |
||
1666 | 1666 | |
1667 | 1667 | public function replyClarification($ccid, $content) |
1668 | 1668 | { |
1669 | - return DB::table("contest_clarification")->where('ccid','=',$ccid)->update([ |
|
1669 | + return DB::table("contest_clarification")->where('ccid', '=', $ccid)->update([ |
|
1670 | 1670 | "reply"=>$content |
1671 | 1671 | ]); |
1672 | 1672 | } |
1673 | 1673 | |
1674 | 1674 | public function setClarificationPublic($ccid, $public) |
1675 | 1675 | { |
1676 | - if($public) |
|
1676 | + if ($public) |
|
1677 | 1677 | { |
1678 | - return DB::table("contest_clarification")->where('ccid','=',$ccid)->update([ |
|
1678 | + return DB::table("contest_clarification")->where('ccid', '=', $ccid)->update([ |
|
1679 | 1679 | "public"=>1 |
1680 | 1680 | ]); |
1681 | 1681 | } |
1682 | 1682 | else |
1683 | 1683 | { |
1684 | - return DB::table("contest_clarification")->where('ccid','=',$ccid)->update([ |
|
1684 | + return DB::table("contest_clarification")->where('ccid', '=', $ccid)->update([ |
|
1685 | 1685 | "public"=>0 |
1686 | 1686 | ]); |
1687 | 1687 | } |
@@ -1692,63 +1692,63 @@ discard block |
||
1692 | 1692 | return Cache::tags(['contest', 'account'])->get($cid); |
1693 | 1693 | } |
1694 | 1694 | |
1695 | - public function praticeAnalysis($cid){ |
|
1696 | - $gid = DB::table('contest') |
|
1697 | - ->where('cid',$cid) |
|
1695 | + public function praticeAnalysis($cid) { |
|
1696 | + $gid=DB::table('contest') |
|
1697 | + ->where('cid', $cid) |
|
1698 | 1698 | ->first()['gid']; |
1699 | - $contestRank = $this->contestRank($cid,Auth::user()->id); |
|
1700 | - $all_problems = DB::table('problem') |
|
1701 | - ->whereIn('pid',array_column($contestRank[0]['problem_detail'],'pid')) |
|
1702 | - ->select('pid','title') |
|
1699 | + $contestRank=$this->contestRank($cid, Auth::user()->id); |
|
1700 | + $all_problems=DB::table('problem') |
|
1701 | + ->whereIn('pid', array_column($contestRank[0]['problem_detail'], 'pid')) |
|
1702 | + ->select('pid', 'title') |
|
1703 | 1703 | ->get()->all(); |
1704 | - $tags = DB::table('group_problem_tag') |
|
1704 | + $tags=DB::table('group_problem_tag') |
|
1705 | 1705 | ->where('gid', $gid) |
1706 | - ->whereIn('pid', array_column($all_problems,'pid')) |
|
1706 | + ->whereIn('pid', array_column($all_problems, 'pid')) |
|
1707 | 1707 | ->get()->all(); |
1708 | - $all_tags = array_unique(array_column($tags,'tag')); |
|
1709 | - $memberData = []; |
|
1710 | - foreach($contestRank as $member){ |
|
1711 | - $m = [ |
|
1708 | + $all_tags=array_unique(array_column($tags, 'tag')); |
|
1709 | + $memberData=[]; |
|
1710 | + foreach ($contestRank as $member) { |
|
1711 | + $m=[ |
|
1712 | 1712 | 'uid' => $member['uid'], |
1713 | 1713 | 'name' => $member['name'], |
1714 | 1714 | 'nick_name' => $member['nick_name'], |
1715 | 1715 | ]; |
1716 | - $completion = []; |
|
1717 | - foreach ($all_tags as $tag){ |
|
1718 | - $completion[$tag] = []; |
|
1716 | + $completion=[]; |
|
1717 | + foreach ($all_tags as $tag) { |
|
1718 | + $completion[$tag]=[]; |
|
1719 | 1719 | foreach ($tags as $t) { |
1720 | - if($t['tag'] == $tag){ |
|
1720 | + if ($t['tag']==$tag) { |
|
1721 | 1721 | foreach ($member['problem_detail'] as $pd) { |
1722 | - if($pd['pid'] == $t['pid']){ |
|
1723 | - $completion[$tag][$t['pid']] = $pd['solved_time_parsed'] == "" ? 0 : 1; |
|
1722 | + if ($pd['pid']==$t['pid']) { |
|
1723 | + $completion[$tag][$t['pid']]=$pd['solved_time_parsed']=="" ? 0 : 1; |
|
1724 | 1724 | } |
1725 | 1725 | } |
1726 | 1726 | } |
1727 | 1727 | } |
1728 | 1728 | } |
1729 | - $m['completion'] = $completion; |
|
1730 | - $memberData[] = $m; |
|
1729 | + $m['completion']=$completion; |
|
1730 | + $memberData[]=$m; |
|
1731 | 1731 | } |
1732 | 1732 | return $memberData; |
1733 | 1733 | } |
1734 | 1734 | |
1735 | 1735 | public function storeContestRankInMySQL($cid, $data) |
1736 | 1736 | { |
1737 | - $contestRankJson = json_encode($data); |
|
1738 | - return DB::table('contest')->where('cid','=',$cid)->update([ |
|
1737 | + $contestRankJson=json_encode($data); |
|
1738 | + return DB::table('contest')->where('cid', '=', $cid)->update([ |
|
1739 | 1739 | 'rank' => $contestRankJson |
1740 | 1740 | ]); |
1741 | 1741 | } |
1742 | 1742 | |
1743 | 1743 | public function getContestRankFromMySQL($cid) |
1744 | 1744 | { |
1745 | - $contestRankJson = DB::table('contest')->where('cid','=',$cid)->pluck('rank')->first(); |
|
1746 | - $data = json_decode($contestRankJson, true); |
|
1745 | + $contestRankJson=DB::table('contest')->where('cid', '=', $cid)->pluck('rank')->first(); |
|
1746 | + $data=json_decode($contestRankJson, true); |
|
1747 | 1747 | return $data; |
1748 | 1748 | } |
1749 | 1749 | |
1750 | 1750 | public function isVerified($cid) |
1751 | 1751 | { |
1752 | - return DB::table('contest')->where('cid','=',$cid)->pluck('verified')->first(); |
|
1752 | + return DB::table('contest')->where('cid', '=', $cid)->pluck('verified')->first(); |
|
1753 | 1753 | } |
1754 | 1754 | } |
@@ -19,11 +19,11 @@ |
||
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; |