@@ -52,8 +52,8 @@ discard block |
||
52 | 52 | protected function mapWebRoutes() |
53 | 53 | { |
54 | 54 | Route::middleware('web') |
55 | - ->namespace($this->namespace) |
|
56 | - ->group(base_path('routes/web.php')); |
|
55 | + ->namespace($this->namespace) |
|
56 | + ->group(base_path('routes/web.php')); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -66,8 +66,8 @@ discard block |
||
66 | 66 | protected function mapApiRoutes() |
67 | 67 | { |
68 | 68 | Route::prefix('api') |
69 | - ->middleware('api') |
|
70 | - ->namespace($this->namespace) |
|
71 | - ->group(base_path('routes/api.php')); |
|
69 | + ->middleware('api') |
|
70 | + ->namespace($this->namespace) |
|
71 | + ->group(base_path('routes/api.php')); |
|
72 | 72 | } |
73 | 73 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | $statusCode=200; |
15 | 15 | } |
16 | 16 | $output=[ |
17 | - 'ret' => $statusCode, |
|
17 | + 'ret' => $statusCode, |
|
18 | 18 | 'desc' => is_null($desc) ? self::desc($statusCode) : $desc, |
19 | 19 | 'data' => $data |
20 | 20 | ]; |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | $statusCode=1000; |
28 | 28 | } |
29 | 29 | $output=[ |
30 | - 'ret' => $statusCode, |
|
30 | + 'ret' => $statusCode, |
|
31 | 31 | 'desc' => is_null($desc) ? self::desc($statusCode) : $desc, |
32 | 32 | 'data' => $data |
33 | 33 | ]; |
@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | '451' => "Unavailable For Legal Reasons", |
45 | 45 | |
46 | 46 | '1000' => "Unspecified Response", /** Under normal condictions those errors shouldn't been displayed to end users |
47 | - * unless they attempt to do so, some submissions should be intercepted |
|
48 | - * by the frontend before the request sended |
|
49 | - */ |
|
47 | + * unless they attempt to do so, some submissions should be intercepted |
|
48 | + * by the frontend before the request sended |
|
49 | + */ |
|
50 | 50 | '1001' => "Internal Sever Error", |
51 | 51 | '1002' => "Service Currently Unavailable", |
52 | 52 | '1003' => "Missing Params", |
@@ -96,7 +96,7 @@ |
||
96 | 96 | '7002' => "Insufficient Clearance", |
97 | 97 | '7003' => "No Need to Approve", |
98 | 98 | '7004' => "Group Member Not Found", |
99 | - '7005' => "Don't play just for fun",//gcode=="create" |
|
99 | + '7005' => "Don't play just for fun", //gcode=="create" |
|
100 | 100 | '7006' => "A group with the same gcode already exists", |
101 | 101 | '7007' => "Group Problem Tag Exist", |
102 | 102 | '7008' => "The group leader cannot leave the group", |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | { |
15 | 15 | use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
16 | 16 | |
17 | - public $tries = 5; |
|
17 | + public $tries=5; |
|
18 | 18 | protected $all_data=[]; |
19 | 19 | |
20 | 20 | /** |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | |
41 | 41 | public function failed() |
42 | 42 | { |
43 | - $submissionModel = new SubmissionModel(); |
|
43 | + $submissionModel=new SubmissionModel(); |
|
44 | 44 | $submissionModel->updateSubmission($this->all_data["sid"], ["verdict"=>"Submission Error"]); |
45 | 45 | } |
46 | 46 | } |
@@ -57,14 +57,14 @@ |
||
57 | 57 | return ResponseModel::err(3002); |
58 | 58 | } |
59 | 59 | $submissionModel=new SubmissionModel(); |
60 | - if($all_data["method"]==1){ |
|
60 | + if ($all_data["method"]==1) { |
|
61 | 61 | // NOJ Share |
62 | 62 | $status=$submissionModel->share($all_data["sid"], Auth::check() ? Auth::user()->id : null); |
63 | - return empty($status)?ResponseModel::err(1001):ResponseModel::success(200, null, $status); |
|
64 | - } elseif($all_data["method"]==2){ |
|
63 | + return empty($status) ?ResponseModel::err(1001) : ResponseModel::success(200, null, $status); |
|
64 | + } elseif ($all_data["method"]==2) { |
|
65 | 65 | // Pastebin |
66 | 66 | $status=$submissionModel->sharePB($all_data["sid"], Auth::check() ? Auth::user()->id : null); |
67 | - return empty($status)?ResponseModel::err(1001):ResponseModel::success(200, null, $status); |
|
67 | + return empty($status) ?ResponseModel::err(1001) : ResponseModel::success(200, null, $status); |
|
68 | 68 | } else { |
69 | 69 | return ResponseModel::err(6002); |
70 | 70 | } |
@@ -52,9 +52,9 @@ |
||
52 | 52 | * @param string|null $token |
53 | 53 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
54 | 54 | */ |
55 | - public function showResetForm(Request $request, $token = null) |
|
55 | + public function showResetForm(Request $request, $token=null) |
|
56 | 56 | { |
57 | - return view('auth.passwords.reset',[ |
|
57 | + return view('auth.passwords.reset', [ |
|
58 | 58 | 'token' => $token, |
59 | 59 | 'email' => $request->email, |
60 | 60 | 'page_title'=>"Reset Password", |
@@ -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 | } |
@@ -17,14 +17,14 @@ discard block |
||
17 | 17 | public $totParticipants=0; |
18 | 18 | public $INITIAL_RATING=1500; |
19 | 19 | |
20 | - public function __construct($cid){ |
|
20 | + public function __construct($cid) { |
|
21 | 21 | $this->cid=$cid; |
22 | 22 | |
23 | 23 | // get rank |
24 | 24 | $this->getRecord(); |
25 | 25 | } |
26 | 26 | |
27 | - private function getRecord(){ |
|
27 | + private function getRecord() { |
|
28 | 28 | $contestRankRaw=Cache::tags(['contest', 'rank'])->get($this->cid); |
29 | 29 | |
30 | 30 | if ($contestRankRaw==null) { |
@@ -32,8 +32,8 @@ discard block |
||
32 | 32 | $contestRankRaw=$contestModel->contestRankCache($this->cid); |
33 | 33 | } |
34 | 34 | |
35 | - $this->totParticipants = count($contestRankRaw); |
|
36 | - foreach($contestRankRaw as $c){ |
|
35 | + $this->totParticipants=count($contestRankRaw); |
|
36 | + foreach ($contestRankRaw as $c) { |
|
37 | 37 | $this->contestants[]=[ |
38 | 38 | "uid"=>$c["uid"], |
39 | 39 | "points"=>$c["score"], |
@@ -42,84 +42,84 @@ discard block |
||
42 | 42 | } |
43 | 43 | } |
44 | 44 | |
45 | - private function reassignRank(){ |
|
45 | + private function reassignRank() { |
|
46 | 46 | $this->sort("points"); |
47 | - $idx = 0; |
|
48 | - $points = $this->contestants[0]["points"]; |
|
49 | - $i = 1; |
|
50 | - while($i < $this->totParticipants){ |
|
51 | - if($this->contestants[$i]["points"] < $points){ |
|
52 | - $j = $idx; |
|
53 | - while($j < $i){ |
|
54 | - $this->contestants[$j]["rank"] = $i; |
|
55 | - $j += 1; |
|
47 | + $idx=0; |
|
48 | + $points=$this->contestants[0]["points"]; |
|
49 | + $i=1; |
|
50 | + while ($i<$this->totParticipants) { |
|
51 | + if ($this->contestants[$i]["points"]<$points) { |
|
52 | + $j=$idx; |
|
53 | + while ($j<$i) { |
|
54 | + $this->contestants[$j]["rank"]=$i; |
|
55 | + $j+=1; |
|
56 | 56 | } |
57 | - $idx = $i; |
|
58 | - $points = $this->contestants[$i]["points"]; |
|
57 | + $idx=$i; |
|
58 | + $points=$this->contestants[$i]["points"]; |
|
59 | 59 | } |
60 | - $i += 1; |
|
60 | + $i+=1; |
|
61 | 61 | } |
62 | - $j = $idx; |
|
63 | - while($j < $this->totParticipants){ |
|
64 | - $this->contestants[$j]["rank"] = $this->totParticipants; |
|
65 | - $j += 1; |
|
62 | + $j=$idx; |
|
63 | + while ($j<$this->totParticipants) { |
|
64 | + $this->contestants[$j]["rank"]=$this->totParticipants; |
|
65 | + $j+=1; |
|
66 | 66 | } |
67 | 67 | } |
68 | 68 | |
69 | - private function getEloWinProbability($Ra, $Rb){ |
|
70 | - return 1.0 / (1 + pow(10, ($Rb-$Ra)/400.0)); |
|
69 | + private function getEloWinProbability($Ra, $Rb) { |
|
70 | + return 1.0 / (1+pow(10, ($Rb-$Ra) / 400.0)); |
|
71 | 71 | } |
72 | 72 | |
73 | - private function getSeed($rating){ |
|
74 | - $result = 1.0; |
|
75 | - foreach($this->contestants as $other){ |
|
76 | - $result += $this->getEloWinProbability($other["rating"], $rating); |
|
73 | + private function getSeed($rating) { |
|
74 | + $result=1.0; |
|
75 | + foreach ($this->contestants as $other) { |
|
76 | + $result+=$this->getEloWinProbability($other["rating"], $rating); |
|
77 | 77 | } |
78 | 78 | return $result; |
79 | 79 | } |
80 | 80 | |
81 | - private function getRatingToRank($rank){ |
|
81 | + private function getRatingToRank($rank) { |
|
82 | 82 | $left=1; |
83 | 83 | $right=8000; |
84 | - while($right - $left > 1){ |
|
85 | - $mid = floor(($right + $left)/2); |
|
86 | - if($this->getSeed($mid) < $rank){ |
|
87 | - $right = $mid; |
|
88 | - }else{ |
|
89 | - $left = $mid; |
|
84 | + while ($right-$left>1) { |
|
85 | + $mid=floor(($right+$left) / 2); |
|
86 | + if ($this->getSeed($mid)<$rank) { |
|
87 | + $right=$mid; |
|
88 | + } else { |
|
89 | + $left=$mid; |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | return $left; |
93 | 93 | } |
94 | 94 | |
95 | - private function sort($key){ |
|
96 | - usort($this->contestants, function ($a, $b) use ($key) { |
|
95 | + private function sort($key) { |
|
96 | + usort($this->contestants, function($a, $b) use ($key) { |
|
97 | 97 | return $b[$key] <=> $a[$key]; |
98 | 98 | }); |
99 | 99 | } |
100 | 100 | |
101 | - public function calculate(){ |
|
102 | - if(empty($this->contestants)){ |
|
101 | + public function calculate() { |
|
102 | + if (empty($this->contestants)) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | 106 | // recalc rank |
107 | 107 | $this->reassignRank(); |
108 | 108 | |
109 | - foreach($this->contestants as &$member){ |
|
110 | - $member["seed"] = 1.0; |
|
111 | - foreach($this->contestants as $other){ |
|
112 | - if($member["uid"] != $other["uid"]){ |
|
113 | - $member["seed"] += $this->getEloWinProbability($other["rating"], $member["rating"]); |
|
109 | + foreach ($this->contestants as &$member) { |
|
110 | + $member["seed"]=1.0; |
|
111 | + foreach ($this->contestants as $other) { |
|
112 | + if ($member["uid"]!=$other["uid"]) { |
|
113 | + $member["seed"]+=$this->getEloWinProbability($other["rating"], $member["rating"]); |
|
114 | 114 | } |
115 | 115 | } |
116 | 116 | } |
117 | 117 | unset($member); |
118 | 118 | |
119 | - foreach($this->contestants as &$contestant){ |
|
120 | - $midRank = sqrt($contestant["rank"] * $contestant["seed"]); |
|
121 | - $contestant["needRating"] = $this->getRatingToRank($midRank); |
|
122 | - $contestant["delta"] = floor(($contestant["needRating"] - $contestant["rating"])/2); |
|
119 | + foreach ($this->contestants as &$contestant) { |
|
120 | + $midRank=sqrt($contestant["rank"] * $contestant["seed"]); |
|
121 | + $contestant["needRating"]=$this->getRatingToRank($midRank); |
|
122 | + $contestant["delta"]=floor(($contestant["needRating"]-$contestant["rating"]) / 2); |
|
123 | 123 | } |
124 | 124 | unset($contestant); |
125 | 125 | |
@@ -127,39 +127,39 @@ discard block |
||
127 | 127 | |
128 | 128 | // DO some adjuct |
129 | 129 | // Total sum should not be more than ZERO. |
130 | - $sum = 0; |
|
130 | + $sum=0; |
|
131 | 131 | |
132 | - foreach($this->contestants as $contestant){ |
|
133 | - $sum += $contestant["delta"]; |
|
132 | + foreach ($this->contestants as $contestant) { |
|
133 | + $sum+=$contestant["delta"]; |
|
134 | 134 | } |
135 | - $inc = -floor($sum / $this->totParticipants) - 1; |
|
136 | - foreach($this->contestants as &$contestant){ |
|
137 | - $contestant["delta"] += $inc; |
|
135 | + $inc=-floor($sum / $this->totParticipants)-1; |
|
136 | + foreach ($this->contestants as &$contestant) { |
|
137 | + $contestant["delta"]+=$inc; |
|
138 | 138 | } |
139 | 139 | unset($contestant); |
140 | 140 | |
141 | 141 | // Sum of top-4*sqrt should be adjusted to ZERO. |
142 | 142 | |
143 | - $sum = 0; |
|
144 | - $zeroSumCount = min(intval(4*round(sqrt($this->totParticipants))), $this->totParticipants); |
|
143 | + $sum=0; |
|
144 | + $zeroSumCount=min(intval(4 * round(sqrt($this->totParticipants))), $this->totParticipants); |
|
145 | 145 | |
146 | - for($i=0;$i<$zeroSumCount;$i++){ |
|
147 | - $sum += $this->contestants[$i]["delta"]; |
|
146 | + for ($i=0; $i<$zeroSumCount; $i++) { |
|
147 | + $sum+=$this->contestants[$i]["delta"]; |
|
148 | 148 | } |
149 | 149 | |
150 | - $inc = min(max(-floor($sum / $zeroSumCount), -10), 0); |
|
150 | + $inc=min(max(-floor($sum / $zeroSumCount), -10), 0); |
|
151 | 151 | |
152 | - for($i=0;$i<$zeroSumCount;$i++){ |
|
153 | - $this->contestants[$i]["delta"] += $inc; |
|
152 | + for ($i=0; $i<$zeroSumCount; $i++) { |
|
153 | + $this->contestants[$i]["delta"]+=$inc; |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | return $this->validateDeltas(); |
157 | 157 | } |
158 | 158 | |
159 | - public function storage(){ |
|
159 | + public function storage() { |
|
160 | 160 | $contestants=$this->contestants; |
161 | - DB::transaction(function () use ($contestants) { |
|
162 | - foreach($contestants as $contestant){ |
|
161 | + DB::transaction(function() use ($contestants) { |
|
162 | + foreach ($contestants as $contestant) { |
|
163 | 163 | $newRating=$contestant["rating"]+$contestant["delta"]; |
164 | 164 | DB::table("users")->where([ |
165 | 165 | "id"=>$contestant["uid"] |
@@ -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 | } |
@@ -11,14 +11,14 @@ discard block |
||
11 | 11 | * |
12 | 12 | * @var string |
13 | 13 | */ |
14 | - protected $signature = 'upgrade'; |
|
14 | + protected $signature='upgrade'; |
|
15 | 15 | |
16 | 16 | /** |
17 | 17 | * The console command description. |
18 | 18 | * |
19 | 19 | * @var string |
20 | 20 | */ |
21 | - protected $description = 'Upgrade to the Latest of NOJ'; |
|
21 | + protected $description='Upgrade to the Latest of NOJ'; |
|
22 | 22 | |
23 | 23 | /** |
24 | 24 | * Create a new command instance. |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function handle() |
39 | 39 | { |
40 | - $bar = $this->output->createProgressBar(8); |
|
40 | + $bar=$this->output->createProgressBar(8); |
|
41 | 41 | $bar->setFormat("%current%/%max% [%bar%] %percent:3s%%\n<info>%message%</info>"); |
42 | 42 | |
43 | 43 | $bar->setMessage("Enable Maintenance Mode."); |
@@ -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 | } |
@@ -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 | } |
@@ -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"; |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | public function generateContestAccount($cid, $ccode, $num) |
62 | 62 | { |
63 | 63 | $ret=[]; |
64 | - $starting=DB::table("users")->where('prefix','=',$ccode)->count(); |
|
64 | + $starting=DB::table("users")->where('prefix', '=', $ccode)->count(); |
|
65 | 65 | $contestModel=new ContestModel(); |
66 | 66 | for ($i=1; $i<=$num; $i++) { |
67 | 67 | $pass=$this->generatePassword(); |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | |
110 | 110 | public function detail($uid) |
111 | 111 | { |
112 | - if (filter_var($uid, FILTER_VALIDATE_INT) === false) { |
|
112 | + if (filter_var($uid, FILTER_VALIDATE_INT)===false) { |
|
113 | 113 | return null; |
114 | 114 | } |
115 | 115 | $ret=DB::table("users")->where(["id"=>$uid])->first(); |
@@ -129,14 +129,14 @@ discard block |
||
129 | 129 | ])->join("problem", "problem.pid", "=", "submission.pid")->select('pcode')->distinct()->get()->all(); |
130 | 130 | $ret["solvedCount"]=count($ret["solved"]); |
131 | 131 | // Casual |
132 | - $ret["rank"]=Cache::tags(['rank',$ret["id"]])->get("rank", "N/A"); |
|
133 | - $ret["rankTitle"]=Cache::tags(['rank',$ret["id"]])->get("title", "Recruit"); |
|
132 | + $ret["rank"]=Cache::tags(['rank', $ret["id"]])->get("rank", "N/A"); |
|
133 | + $ret["rankTitle"]=Cache::tags(['rank', $ret["id"]])->get("title", "Recruit"); |
|
134 | 134 | $ret["rankTitleColor"]=RankModel::getColor($ret["rankTitle"]); |
135 | 135 | // Professional |
136 | 136 | $ret["professionalTitle"]=RankModel::getProfessionalTitle($ret["professional_rate"]); |
137 | 137 | $ret["professionalTitleColor"]=RankModel::getProfessionalColor($ret["professionalTitle"]); |
138 | 138 | // Administration Group |
139 | - $ret["admin"]=$uid==1?1:0; |
|
139 | + $ret["admin"]=$uid==1 ? 1 : 0; |
|
140 | 140 | if (Cache::tags(['bing', 'pic'])->get(date("Y-m-d"))==null) { |
141 | 141 | $bing=new BingPhoto([ |
142 | 142 | 'locale' => 'zh-CN', |
@@ -155,26 +155,26 @@ discard block |
||
155 | 155 | * @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. |
156 | 156 | * @return string|array $result |
157 | 157 | */ |
158 | - public function getExtra($uid,$need, $secret_level = 0){ |
|
159 | - $ret = DB::table('users_extra')->where('uid',$uid)->orderBy('key')->get()->all(); |
|
160 | - $result = []; |
|
161 | - if(!empty($ret)){ |
|
162 | - if(is_string($need)){ |
|
158 | + public function getExtra($uid, $need, $secret_level=0) { |
|
159 | + $ret=DB::table('users_extra')->where('uid', $uid)->orderBy('key')->get()->all(); |
|
160 | + $result=[]; |
|
161 | + if (!empty($ret)) { |
|
162 | + if (is_string($need)) { |
|
163 | 163 | foreach ($ret as $value) { |
164 | - if(empty($value['secret_level']) || $value['secret_level'] <= $secret_level){ |
|
165 | - $key_name = $this->user_extra[$value['key']] ?? 'unknown'; |
|
166 | - if($key_name == $need){ |
|
164 | + if (empty($value['secret_level']) || $value['secret_level']<=$secret_level) { |
|
165 | + $key_name=$this->user_extra[$value['key']] ?? 'unknown'; |
|
166 | + if ($key_name==$need) { |
|
167 | 167 | return $value['value']; |
168 | 168 | } |
169 | 169 | } |
170 | 170 | } |
171 | 171 | return null; |
172 | - }else{ |
|
172 | + } else { |
|
173 | 173 | foreach ($ret as $value) { |
174 | - if(empty($value['secret_level']) || $value['secret_level'] <= $secret_level){ |
|
175 | - $key_name = $this->user_extra[$value['key']] ?? 'unknown'; |
|
176 | - if(in_array($key_name,$need)){ |
|
177 | - $result[$key_name] = $value['value']; |
|
174 | + if (empty($value['secret_level']) || $value['secret_level']<=$secret_level) { |
|
175 | + $key_name=$this->user_extra[$value['key']] ?? 'unknown'; |
|
176 | + if (in_array($key_name, $need)) { |
|
177 | + $result[$key_name]=$value['value']; |
|
178 | 178 | } |
179 | 179 | } |
180 | 180 | } |
@@ -191,26 +191,26 @@ discard block |
||
191 | 191 | * @param string|null $value the extra info will be delete when value is null |
192 | 192 | * @return mixed $result |
193 | 193 | */ |
194 | - public function setExtra($uid,$key_name,$value = null,$secret_level = -1){ |
|
195 | - $key = array_search($key_name,$this->user_extra); |
|
196 | - if($key === false){ |
|
194 | + public function setExtra($uid, $key_name, $value=null, $secret_level=-1) { |
|
195 | + $key=array_search($key_name, $this->user_extra); |
|
196 | + if ($key===false) { |
|
197 | 197 | return false; |
198 | 198 | } |
199 | - $ret = DB::table('users_extra')->where('uid',$uid)->where('key',$key)->first(); |
|
200 | - if(!empty($ret)){ |
|
199 | + $ret=DB::table('users_extra')->where('uid', $uid)->where('key', $key)->first(); |
|
200 | + if (!empty($ret)) { |
|
201 | 201 | unset($ret['id']); |
202 | - if(!is_null($value)){ |
|
203 | - $ret['value'] = $value; |
|
204 | - }else{ |
|
205 | - DB::table('users_extra')->where('uid',$uid)->where('key',$key)->delete(); |
|
202 | + if (!is_null($value)) { |
|
203 | + $ret['value']=$value; |
|
204 | + } else { |
|
205 | + DB::table('users_extra')->where('uid', $uid)->where('key', $key)->delete(); |
|
206 | 206 | return true; |
207 | 207 | } |
208 | - if($secret_level != -1){ |
|
209 | - $ret['secret_level'] = $secret_level; |
|
208 | + if ($secret_level!=-1) { |
|
209 | + $ret['secret_level']=$secret_level; |
|
210 | 210 | } |
211 | - return DB::table('users_extra')->where('uid',$uid)->where('key',$key)->update($ret); |
|
212 | - }else{ |
|
213 | - if($value === null){ |
|
211 | + return DB::table('users_extra')->where('uid', $uid)->where('key', $key)->update($ret); |
|
212 | + } else { |
|
213 | + if ($value===null) { |
|
214 | 214 | return true; |
215 | 215 | } |
216 | 216 | return DB::table('users_extra')->insertGetId( |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | 'uid' => $uid, |
219 | 219 | 'key' => $key, |
220 | 220 | 'value' => $value, |
221 | - 'secret_level' => $secret_level == -1 ? 0 : $secret_level, |
|
221 | + 'secret_level' => $secret_level==-1 ? 0 : $secret_level, |
|
222 | 222 | ] |
223 | 223 | ); |
224 | 224 | } |
@@ -230,33 +230,33 @@ discard block |
||
230 | 230 | * @param string $value the value |
231 | 231 | * @return string $result |
232 | 232 | */ |
233 | - public function findExtra($key,$value) |
|
233 | + public function findExtra($key, $value) |
|
234 | 234 | { |
235 | - $key = array_search($key,$this->user_extra); |
|
236 | - if($key){ |
|
237 | - return DB::table('users_extra')->where('key',$key)->where('value',$value)->first(); |
|
238 | - }else{ |
|
235 | + $key=array_search($key, $this->user_extra); |
|
236 | + if ($key) { |
|
237 | + return DB::table('users_extra')->where('key', $key)->where('value', $value)->first(); |
|
238 | + } else { |
|
239 | 239 | return null; |
240 | 240 | } |
241 | 241 | } |
242 | 242 | |
243 | - public function getSocialiteInfo($uid,$secret_level = -1) |
|
243 | + public function getSocialiteInfo($uid, $secret_level=-1) |
|
244 | 244 | { |
245 | - $socialites = []; |
|
245 | + $socialites=[]; |
|
246 | 246 | foreach ($this->socialite_support as $key => $value) { |
247 | - $id_keyname = $key.'_id'; |
|
248 | - $id = $this->getExtra($uid,$id_keyname); |
|
249 | - if(!empty($id)){ |
|
250 | - $info = [ |
|
247 | + $id_keyname=$key.'_id'; |
|
248 | + $id=$this->getExtra($uid, $id_keyname); |
|
249 | + if (!empty($id)) { |
|
250 | + $info=[ |
|
251 | 251 | 'id' => $id, |
252 | 252 | ]; |
253 | 253 | foreach ($value as $info_name) { |
254 | - $info_temp = $this->getExtra($uid,$key.'_'.$info_name); |
|
255 | - if($info_temp !== null){ |
|
256 | - $info[$info_name] = $info_temp; |
|
254 | + $info_temp=$this->getExtra($uid, $key.'_'.$info_name); |
|
255 | + if ($info_temp!==null) { |
|
256 | + $info[$info_name]=$info_temp; |
|
257 | 257 | } |
258 | 258 | } |
259 | - $socialites[$key] = $info; |
|
259 | + $socialites[$key]=$info; |
|
260 | 260 | } |
261 | 261 | } |
262 | 262 |