@@ -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(); |
@@ -120,14 +120,14 @@ discard block |
||
120 | 120 | ])->join("problem", "problem.pid", "=", "submission.pid")->select('pcode')->distinct()->get()->all(); |
121 | 121 | $ret["solvedCount"]=count($ret["solved"]); |
122 | 122 | // Casual |
123 | - $ret["rank"]=Cache::tags(['rank',$ret["id"]])->get("rank", "N/A"); |
|
124 | - $ret["rankTitle"]=Cache::tags(['rank',$ret["id"]])->get("title", "Recruit"); |
|
123 | + $ret["rank"]=Cache::tags(['rank', $ret["id"]])->get("rank", "N/A"); |
|
124 | + $ret["rankTitle"]=Cache::tags(['rank', $ret["id"]])->get("title", "Recruit"); |
|
125 | 125 | $ret["rankTitleColor"]=RankModel::getColor($ret["rankTitle"]); |
126 | 126 | // Professional |
127 | 127 | $ret["professionalTitle"]=RankModel::getProfessionalTitle($ret["professional_rate"]); |
128 | 128 | $ret["professionalTitleColor"]=RankModel::getProfessionalColor($ret["professionalTitle"]); |
129 | 129 | // Administration Group |
130 | - $ret["admin"]=$uid==1?1:0; |
|
130 | + $ret["admin"]=$uid==1 ? 1 : 0; |
|
131 | 131 | if (Cache::tags(['bing', 'pic'])->get(date("Y-m-d"))==null) { |
132 | 132 | $bing=new BingPhoto([ |
133 | 133 | 'locale' => 'zh-CN', |
@@ -146,26 +146,26 @@ discard block |
||
146 | 146 | * @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. |
147 | 147 | * @return string|array $result |
148 | 148 | */ |
149 | - public function getExtra($uid,$need, $secret_level = 0){ |
|
150 | - $ret = DB::table('users_extra')->where('uid',$uid)->orderBy('key')->get()->all(); |
|
151 | - $result = []; |
|
152 | - if(!empty($ret)){ |
|
153 | - if(is_string($need)){ |
|
149 | + public function getExtra($uid, $need, $secret_level=0) { |
|
150 | + $ret=DB::table('users_extra')->where('uid', $uid)->orderBy('key')->get()->all(); |
|
151 | + $result=[]; |
|
152 | + if (!empty($ret)) { |
|
153 | + if (is_string($need)) { |
|
154 | 154 | foreach ($ret as $value) { |
155 | - if(empty($value['secret_level']) || $value['secret_level'] <= $secret_level){ |
|
156 | - $key_name = $this->user_extra[$value['key']] ?? 'unknown'; |
|
157 | - if($key_name == $need){ |
|
155 | + if (empty($value['secret_level']) || $value['secret_level']<=$secret_level) { |
|
156 | + $key_name=$this->user_extra[$value['key']] ?? 'unknown'; |
|
157 | + if ($key_name==$need) { |
|
158 | 158 | return $value['value']; |
159 | 159 | } |
160 | 160 | } |
161 | 161 | } |
162 | 162 | return null; |
163 | - }else{ |
|
163 | + } else { |
|
164 | 164 | foreach ($ret as $value) { |
165 | - if(empty($value['secret_level']) || $value['secret_level'] <= $secret_level){ |
|
166 | - $key_name = $this->user_extra[$value['key']] ?? 'unknown'; |
|
167 | - if(in_array($key_name,$need)){ |
|
168 | - $result[$key_name] = $value['value']; |
|
165 | + if (empty($value['secret_level']) || $value['secret_level']<=$secret_level) { |
|
166 | + $key_name=$this->user_extra[$value['key']] ?? 'unknown'; |
|
167 | + if (in_array($key_name, $need)) { |
|
168 | + $result[$key_name]=$value['value']; |
|
169 | 169 | } |
170 | 170 | } |
171 | 171 | } |
@@ -182,26 +182,26 @@ discard block |
||
182 | 182 | * @param string|null $value the extra info will be delete when value is null |
183 | 183 | * @return mixed $result |
184 | 184 | */ |
185 | - public function setExtra($uid,$key_name,$value = null,$secret_level = -1){ |
|
186 | - $key = array_search($key_name,$this->user_extra); |
|
187 | - if($key === false){ |
|
185 | + public function setExtra($uid, $key_name, $value=null, $secret_level=-1) { |
|
186 | + $key=array_search($key_name, $this->user_extra); |
|
187 | + if ($key===false) { |
|
188 | 188 | return false; |
189 | 189 | } |
190 | - $ret = DB::table('users_extra')->where('uid',$uid)->where('key',$key)->first(); |
|
191 | - if(!empty($ret)){ |
|
190 | + $ret=DB::table('users_extra')->where('uid', $uid)->where('key', $key)->first(); |
|
191 | + if (!empty($ret)) { |
|
192 | 192 | unset($ret['id']); |
193 | - if(!is_null($value)){ |
|
194 | - $ret['value'] = $value; |
|
195 | - }else{ |
|
196 | - DB::table('users_extra')->where('uid',$uid)->where('key',$key)->delete(); |
|
193 | + if (!is_null($value)) { |
|
194 | + $ret['value']=$value; |
|
195 | + } else { |
|
196 | + DB::table('users_extra')->where('uid', $uid)->where('key', $key)->delete(); |
|
197 | 197 | return true; |
198 | 198 | } |
199 | - if($secret_level != -1){ |
|
200 | - $ret['secret_level'] = $secret_level; |
|
199 | + if ($secret_level!=-1) { |
|
200 | + $ret['secret_level']=$secret_level; |
|
201 | 201 | } |
202 | - return DB::table('users_extra')->where('uid',$uid)->where('key',$key)->update($ret); |
|
203 | - }else{ |
|
204 | - if($value === null){ |
|
202 | + return DB::table('users_extra')->where('uid', $uid)->where('key', $key)->update($ret); |
|
203 | + } else { |
|
204 | + if ($value===null) { |
|
205 | 205 | return true; |
206 | 206 | } |
207 | 207 | return DB::table('users_extra')->insertGetId( |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | 'uid' => $uid, |
210 | 210 | 'key' => $key, |
211 | 211 | 'value' => $value, |
212 | - 'secret_level' => $secret_level == -1 ? 0 : $secret_level, |
|
212 | + 'secret_level' => $secret_level==-1 ? 0 : $secret_level, |
|
213 | 213 | ] |
214 | 214 | ); |
215 | 215 | } |
@@ -221,33 +221,33 @@ discard block |
||
221 | 221 | * @param string $value the value |
222 | 222 | * @return string $result |
223 | 223 | */ |
224 | - public function findExtra($key,$value) |
|
224 | + public function findExtra($key, $value) |
|
225 | 225 | { |
226 | - $key = array_search($key,$this->user_extra); |
|
227 | - if($key){ |
|
228 | - return DB::table('users_extra')->where('key',$key)->where('value',$value)->first(); |
|
229 | - }else{ |
|
226 | + $key=array_search($key, $this->user_extra); |
|
227 | + if ($key) { |
|
228 | + return DB::table('users_extra')->where('key', $key)->where('value', $value)->first(); |
|
229 | + } else { |
|
230 | 230 | return null; |
231 | 231 | } |
232 | 232 | } |
233 | 233 | |
234 | - public function getSocialiteInfo($uid,$secret_level = -1) |
|
234 | + public function getSocialiteInfo($uid, $secret_level=-1) |
|
235 | 235 | { |
236 | - $socialites = []; |
|
236 | + $socialites=[]; |
|
237 | 237 | foreach ($this->socialite_support as $key => $value) { |
238 | - $id_keyname = $key.'_id'; |
|
239 | - $id = $this->getExtra($uid,$id_keyname); |
|
240 | - if(!empty($id)){ |
|
241 | - $info = [ |
|
238 | + $id_keyname=$key.'_id'; |
|
239 | + $id=$this->getExtra($uid, $id_keyname); |
|
240 | + if (!empty($id)) { |
|
241 | + $info=[ |
|
242 | 242 | 'id' => $id, |
243 | 243 | ]; |
244 | 244 | foreach ($value as $info_name) { |
245 | - $info_temp = $this->getExtra($uid,$key.'_'.$info_name); |
|
246 | - if($info_temp !== null){ |
|
247 | - $info[$info_name] = $info_temp; |
|
245 | + $info_temp=$this->getExtra($uid, $key.'_'.$info_name); |
|
246 | + if ($info_temp!==null) { |
|
247 | + $info[$info_name]=$info_temp; |
|
248 | 248 | } |
249 | 249 | } |
250 | - $socialites[$key] = $info; |
|
250 | + $socialites[$key]=$info; |
|
251 | 251 | } |
252 | 252 | } |
253 | 253 |