@@ -39,7 +39,7 @@ |
||
39 | 39 | $groupModel=new GroupModel(); |
40 | 40 | $contestModel=new ContestModel(); |
41 | 41 | $basic_info=$groupModel->details($gcode); |
42 | - if(empty($basic_info)) return Redirect::route('group_index'); |
|
42 | + if (empty($basic_info)) return Redirect::route('group_index'); |
|
43 | 43 | $my_profile=$groupModel->userProfile(Auth::user()->id, $basic_info["gid"]); |
44 | 44 | $clearance=$groupModel->judgeClearance($basic_info["gid"], Auth::user()->id); |
45 | 45 | $member_list=$groupModel->userList($basic_info["gid"]); |
@@ -39,7 +39,9 @@ |
||
39 | 39 | $groupModel=new GroupModel(); |
40 | 40 | $contestModel=new ContestModel(); |
41 | 41 | $basic_info=$groupModel->details($gcode); |
42 | - if(empty($basic_info)) return Redirect::route('group_index'); |
|
42 | + if(empty($basic_info)) { |
|
43 | + return Redirect::route('group_index'); |
|
44 | + } |
|
43 | 45 | $my_profile=$groupModel->userProfile(Auth::user()->id, $basic_info["gid"]); |
44 | 46 | $clearance=$groupModel->judgeClearance($basic_info["gid"], Auth::user()->id); |
45 | 47 | $member_list=$groupModel->userList($basic_info["gid"]); |
@@ -153,7 +153,7 @@ |
||
153 | 153 | ->where( |
154 | 154 | function ($query) { |
155 | 155 | $query->where('public', 1) |
156 | - ->where('audit_status', 1); |
|
156 | + ->where('audit_status', 1); |
|
157 | 157 | } |
158 | 158 | ) |
159 | 159 | ->orWhere( |
@@ -124,9 +124,9 @@ discard block |
||
124 | 124 | // "gid"=>$gid |
125 | 125 | // ])->orderBy('begin_time', 'desc')->get()->all(); |
126 | 126 | $preQuery=DB::table($this->tableName); |
127 | - $paginator=$preQuery->where('gid','=',$gid)->orderBy('begin_time', 'desc')->paginate(10); |
|
127 | + $paginator=$preQuery->where('gid', '=', $gid)->orderBy('begin_time', 'desc')->paginate(10); |
|
128 | 128 | $contest_list=$paginator->all(); |
129 | - if(empty($contest_list)){ |
|
129 | + if (empty($contest_list)) { |
|
130 | 130 | return null; |
131 | 131 | } |
132 | 132 | |
@@ -161,13 +161,13 @@ discard block |
||
161 | 161 | ->join('contest', 'group_member.gid', '=', 'contest.gid') |
162 | 162 | ->leftJoin('contest_participant', 'contest.cid', '=', 'contest_participant.cid') |
163 | 163 | ->where( |
164 | - function ($query) { |
|
164 | + function($query) { |
|
165 | 165 | $query->where('public', 1) |
166 | 166 | ->where('audit_status', 1); |
167 | 167 | } |
168 | 168 | ) |
169 | 169 | ->orWhere( |
170 | - function ($query) use ($uid) { |
|
170 | + function($query) use ($uid) { |
|
171 | 171 | $query->where('group_member.uid', $uid) |
172 | 172 | ->where('group_member.role', '>', 0); |
173 | 173 | // ->where(function ($query) use ($uid) { |
@@ -232,14 +232,14 @@ discard block |
||
232 | 232 | } |
233 | 233 | } |
234 | 234 | |
235 | - public function registContest($cid,$uid) |
|
235 | + public function registContest($cid, $uid) |
|
236 | 236 | { |
237 | 237 | $registered=DB::table("contest_participant")->where([ |
238 | 238 | "cid"=>$cid, |
239 | 239 | "uid"=>$uid |
240 | 240 | ])->first(); |
241 | 241 | |
242 | - if(empty($registered)){ |
|
242 | + if (empty($registered)) { |
|
243 | 243 | DB::table("contest_participant")->insert([ |
244 | 244 | "cid"=>$cid, |
245 | 245 | "uid"=>$uid, |
@@ -540,7 +540,7 @@ discard block |
||
540 | 540 | "problem_detail" => $prob_detail |
541 | 541 | ]; |
542 | 542 | } |
543 | - usort($ret, function ($a, $b) { |
|
543 | + usort($ret, function($a, $b) { |
|
544 | 544 | if ($a["score"]==$b["score"]) { |
545 | 545 | if ($a["penalty"]==$b["penalty"]) { |
546 | 546 | return 0; |
@@ -587,7 +587,7 @@ discard block |
||
587 | 587 | "problem_detail" => $prob_detail |
588 | 588 | ]; |
589 | 589 | } |
590 | - usort($ret, function ($a, $b) { |
|
590 | + usort($ret, function($a, $b) { |
|
591 | 591 | if ($a["score"]==$b["score"]) { |
592 | 592 | if ($a["solved"]==$b["solved"]) { |
593 | 593 | return 0; |
@@ -680,7 +680,7 @@ discard block |
||
680 | 680 | { |
681 | 681 | return DB::table("contest_clarification")->where([ |
682 | 682 | "cid"=>$cid |
683 | - ])->where(function ($query) { |
|
683 | + ])->where(function($query) { |
|
684 | 684 | $query->where([ |
685 | 685 | "public"=>1 |
686 | 686 | ])->orWhere([ |
@@ -833,7 +833,7 @@ discard block |
||
833 | 833 | "users.id", |
834 | 834 | "=", |
835 | 835 | "submission.uid" |
836 | - )->where(function ($query) use ($frozen_time) { |
|
836 | + )->where(function($query) use ($frozen_time) { |
|
837 | 837 | $query->where( |
838 | 838 | "submission_date", |
839 | 839 | "<", |
@@ -1026,12 +1026,12 @@ discard block |
||
1026 | 1026 | public function updateProfessionalRate($cid) |
1027 | 1027 | { |
1028 | 1028 | $basic=$this->basic($cid); |
1029 | - if($basic["rated"]&&!$basic["is_rated"]){ |
|
1029 | + if ($basic["rated"] && !$basic["is_rated"]) { |
|
1030 | 1030 | $ratingCalculator=new RatingCalculator($cid); |
1031 | - if($ratingCalculator->calculate()){ |
|
1031 | + if ($ratingCalculator->calculate()) { |
|
1032 | 1032 | $ratingCalculator->storage(); |
1033 | 1033 | return true; |
1034 | - }else{ |
|
1034 | + } else { |
|
1035 | 1035 | return false; |
1036 | 1036 | } |
1037 | 1037 | } else { |
@@ -1041,7 +1041,7 @@ discard block |
||
1041 | 1041 | |
1042 | 1042 | public function arrangeContest($gid, $config, $problems) |
1043 | 1043 | { |
1044 | - DB::transaction(function () use ($gid, $config, $problems) { |
|
1044 | + DB::transaction(function() use ($gid, $config, $problems) { |
|
1045 | 1045 | $cid=DB::table($this->tableName)->insertGetId([ |
1046 | 1046 | "gid"=>$gid, |
1047 | 1047 | "name"=>$config["name"], |
@@ -1077,31 +1077,31 @@ discard block |
||
1077 | 1077 | }, 5); |
1078 | 1078 | } |
1079 | 1079 | |
1080 | - public function updateContestRankTable($cid,$sub){ |
|
1081 | - $lock = Cache::lock("contestrank$cid",10); |
|
1082 | - try{ |
|
1083 | - if($lock->get()){ |
|
1084 | - if(Cache::tags(['contest','rank'])->get($cid) != null){ |
|
1085 | - $chache = Cache::tags(['contest','data'])->get($cid); |
|
1086 | - $ret = Cache::tags(['contest','rank'])->get($cid); |
|
1087 | - if (time() > $chache['frozen_time']) |
|
1080 | + public function updateContestRankTable($cid, $sub) { |
|
1081 | + $lock=Cache::lock("contestrank$cid", 10); |
|
1082 | + try { |
|
1083 | + if ($lock->get()) { |
|
1084 | + if (Cache::tags(['contest', 'rank'])->get($cid)!=null) { |
|
1085 | + $chache=Cache::tags(['contest', 'data'])->get($cid); |
|
1086 | + $ret=Cache::tags(['contest', 'rank'])->get($cid); |
|
1087 | + if (time()>$chache['frozen_time']) |
|
1088 | 1088 | return; |
1089 | 1089 | |
1090 | - $id = 0; |
|
1090 | + $id=0; |
|
1091 | 1091 | |
1092 | - foreach($chache['problemSet'] as $key => $p){ |
|
1093 | - if ($p['pid'] == $sub['pid']){ |
|
1094 | - $chache['problemSet'][$key]['cpid'] = $key; |
|
1095 | - $id = $key; |
|
1092 | + foreach ($chache['problemSet'] as $key => $p) { |
|
1093 | + if ($p['pid']==$sub['pid']) { |
|
1094 | + $chache['problemSet'][$key]['cpid']=$key; |
|
1095 | + $id=$key; |
|
1096 | 1096 | } |
1097 | 1097 | } |
1098 | 1098 | |
1099 | - $ret = $this->updateContestRankDetail($chache['contest_info'],$chache['problemSet'][$id],$cid,$sub['uid'],$ret); |
|
1100 | - $ret = $this->sortContestRankTable($chache['contest_info'],$cid,$ret); |
|
1099 | + $ret=$this->updateContestRankDetail($chache['contest_info'], $chache['problemSet'][$id], $cid, $sub['uid'], $ret); |
|
1100 | + $ret=$this->sortContestRankTable($chache['contest_info'], $cid, $ret); |
|
1101 | 1101 | |
1102 | 1102 | Cache::tags(['contest', 'rank'])->put($cid, $ret); |
1103 | 1103 | } |
1104 | - else{ |
|
1104 | + else { |
|
1105 | 1105 | $ret=[]; |
1106 | 1106 | $chache=[]; |
1107 | 1107 | $chache['contest_info']=DB::table("contest")->where("cid", $cid)->first(); |
@@ -1118,7 +1118,7 @@ discard block |
||
1118 | 1118 | "cid"=>$cid, |
1119 | 1119 | "audit"=>1 |
1120 | 1120 | ])->select('uid')->get()->all(); |
1121 | - }else{ |
|
1121 | + } else { |
|
1122 | 1122 | $submissionUsers=DB::table("submission")->where([ |
1123 | 1123 | "cid"=>$cid |
1124 | 1124 | ])->where( |
@@ -1129,24 +1129,24 @@ discard block |
||
1129 | 1129 | } |
1130 | 1130 | foreach ($submissionUsers as $s) { |
1131 | 1131 | foreach ($chache['problemSet'] as $key => $p) { |
1132 | - $p['cpid'] = $key; |
|
1133 | - $ret = $this->updateContestRankDetail($chache['contest_info'],$p,$cid,$s['uid'],$ret); |
|
1132 | + $p['cpid']=$key; |
|
1133 | + $ret=$this->updateContestRankDetail($chache['contest_info'], $p, $cid, $s['uid'], $ret); |
|
1134 | 1134 | } |
1135 | 1135 | } |
1136 | - $ret = $this->sortContestRankTable($chache['contest_info'],$cid,$ret); |
|
1136 | + $ret=$this->sortContestRankTable($chache['contest_info'], $cid, $ret); |
|
1137 | 1137 | Cache::tags(['contest', 'rank'])->put($cid, $ret); |
1138 | 1138 | } |
1139 | 1139 | } |
1140 | - }catch(LockTimeoutException $e){ |
|
1140 | + } catch (LockTimeoutException $e) { |
|
1141 | 1141 | Log::warning("Contest Rank Lock Timed Out"); |
1142 | - }finally{ |
|
1142 | + } finally { |
|
1143 | 1143 | optional($lock)->release(); |
1144 | 1144 | } |
1145 | 1145 | } |
1146 | 1146 | |
1147 | - public function sortContestRankTable($contest_info,$cid,$ret){ |
|
1148 | - if ($contest_info["rule"]==1){ |
|
1149 | - usort($ret, function ($a, $b) { |
|
1147 | + public function sortContestRankTable($contest_info, $cid, $ret) { |
|
1148 | + if ($contest_info["rule"]==1) { |
|
1149 | + usort($ret, function($a, $b) { |
|
1150 | 1150 | if ($a["score"]==$b["score"]) { |
1151 | 1151 | if ($a["penalty"]==$b["penalty"]) { |
1152 | 1152 | return 0; |
@@ -1161,8 +1161,8 @@ discard block |
||
1161 | 1161 | return 1; |
1162 | 1162 | } |
1163 | 1163 | }); |
1164 | - }else if ($contest_info["rule"]==2){ |
|
1165 | - usort($ret, function ($a, $b) { |
|
1164 | + } else if ($contest_info["rule"]==2) { |
|
1165 | + usort($ret, function($a, $b) { |
|
1166 | 1166 | if ($a["score"]==$b["score"]) { |
1167 | 1167 | if ($a["solved"]==$b["solved"]) { |
1168 | 1168 | return 0; |
@@ -1181,15 +1181,15 @@ discard block |
||
1181 | 1181 | return $ret; |
1182 | 1182 | } |
1183 | 1183 | |
1184 | - public function updateContestRankDetail($contest_info,$problem,$cid,$uid,$ret){ |
|
1185 | - $id = count($ret); |
|
1186 | - foreach($ret as $key => $r){ |
|
1187 | - if($r['uid'] == $uid) |
|
1188 | - $id = $key; |
|
1184 | + public function updateContestRankDetail($contest_info, $problem, $cid, $uid, $ret) { |
|
1185 | + $id=count($ret); |
|
1186 | + foreach ($ret as $key => $r) { |
|
1187 | + if ($r['uid']==$uid) |
|
1188 | + $id=$key; |
|
1189 | 1189 | } |
1190 | 1190 | if ($contest_info["rule"]==1) { |
1191 | 1191 | // ACM/ICPC Mode |
1192 | - $prob_detail = $ret[$id]['problem_detail']; |
|
1192 | + $prob_detail=$ret[$id]['problem_detail']; |
|
1193 | 1193 | $totPen=$ret[$id]['penalty']; |
1194 | 1194 | $totScore=$ret[$id]['score']; |
1195 | 1195 | |
@@ -1223,7 +1223,7 @@ discard block |
||
1223 | 1223 | ]; |
1224 | 1224 | } elseif ($contest_info["rule"]==2) { |
1225 | 1225 | // OI Mode |
1226 | - $prob_detail = $ret[$id]['problem_detail']; |
|
1226 | + $prob_detail=$ret[$id]['problem_detail']; |
|
1227 | 1227 | $totScore=$ret[$id]['score']; |
1228 | 1228 | $totSolved=$ret[$id]['solved']; |
1229 | 1229 |
@@ -1031,7 +1031,7 @@ discard block |
||
1031 | 1031 | if($ratingCalculator->calculate()){ |
1032 | 1032 | $ratingCalculator->storage(); |
1033 | 1033 | return true; |
1034 | - }else{ |
|
1034 | + } else{ |
|
1035 | 1035 | return false; |
1036 | 1036 | } |
1037 | 1037 | } else { |
@@ -1084,8 +1084,9 @@ discard block |
||
1084 | 1084 | if(Cache::tags(['contest','rank'])->get($cid) != null){ |
1085 | 1085 | $chache = Cache::tags(['contest','data'])->get($cid); |
1086 | 1086 | $ret = Cache::tags(['contest','rank'])->get($cid); |
1087 | - if (time() > $chache['frozen_time']) |
|
1088 | - return; |
|
1087 | + if (time() > $chache['frozen_time']) { |
|
1088 | + return; |
|
1089 | + } |
|
1089 | 1090 | |
1090 | 1091 | $id = 0; |
1091 | 1092 | |
@@ -1100,8 +1101,7 @@ discard block |
||
1100 | 1101 | $ret = $this->sortContestRankTable($chache['contest_info'],$cid,$ret); |
1101 | 1102 | |
1102 | 1103 | Cache::tags(['contest', 'rank'])->put($cid, $ret); |
1103 | - } |
|
1104 | - else{ |
|
1104 | + } else{ |
|
1105 | 1105 | $ret=[]; |
1106 | 1106 | $chache=[]; |
1107 | 1107 | $chache['contest_info']=DB::table("contest")->where("cid", $cid)->first(); |
@@ -1118,7 +1118,7 @@ discard block |
||
1118 | 1118 | "cid"=>$cid, |
1119 | 1119 | "audit"=>1 |
1120 | 1120 | ])->select('uid')->get()->all(); |
1121 | - }else{ |
|
1121 | + } else{ |
|
1122 | 1122 | $submissionUsers=DB::table("submission")->where([ |
1123 | 1123 | "cid"=>$cid |
1124 | 1124 | ])->where( |
@@ -1137,9 +1137,9 @@ discard block |
||
1137 | 1137 | Cache::tags(['contest', 'rank'])->put($cid, $ret); |
1138 | 1138 | } |
1139 | 1139 | } |
1140 | - }catch(LockTimeoutException $e){ |
|
1140 | + } catch(LockTimeoutException $e){ |
|
1141 | 1141 | Log::warning("Contest Rank Lock Timed Out"); |
1142 | - }finally{ |
|
1142 | + } finally{ |
|
1143 | 1143 | optional($lock)->release(); |
1144 | 1144 | } |
1145 | 1145 | } |
@@ -1161,7 +1161,7 @@ discard block |
||
1161 | 1161 | return 1; |
1162 | 1162 | } |
1163 | 1163 | }); |
1164 | - }else if ($contest_info["rule"]==2){ |
|
1164 | + } else if ($contest_info["rule"]==2){ |
|
1165 | 1165 | usort($ret, function ($a, $b) { |
1166 | 1166 | if ($a["score"]==$b["score"]) { |
1167 | 1167 | if ($a["solved"]==$b["solved"]) { |
@@ -1184,8 +1184,9 @@ discard block |
||
1184 | 1184 | public function updateContestRankDetail($contest_info,$problem,$cid,$uid,$ret){ |
1185 | 1185 | $id = count($ret); |
1186 | 1186 | foreach($ret as $key => $r){ |
1187 | - if($r['uid'] == $uid) |
|
1188 | - $id = $key; |
|
1187 | + if($r['uid'] == $uid) { |
|
1188 | + $id = $key; |
|
1189 | + } |
|
1189 | 1190 | } |
1190 | 1191 | if ($contest_info["rule"]==1) { |
1191 | 1192 | // ACM/ICPC Mode |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | $all_data=$request->all(); |
45 | 45 | |
46 | 46 | $contestModel=new ContestModel(); |
47 | - return $contestModel->updateProfessionalRate($all_data["cid"])?ResponseModel::success(200):ResponseModel::err(1001); |
|
47 | + return $contestModel->updateProfessionalRate($all_data["cid"]) ?ResponseModel::success(200) : ResponseModel::err(1001); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | public function requestClarification(Request $request) |
@@ -101,16 +101,16 @@ discard block |
||
101 | 101 | $groupModel=new GroupModel(); |
102 | 102 | $basic=$contestModel->basic($all_data["cid"]); |
103 | 103 | |
104 | - if(!$basic["registration"]){ |
|
104 | + if (!$basic["registration"]) { |
|
105 | 105 | return ResponseModel::err(4003); |
106 | 106 | } |
107 | - if(strtotime($basic["registration_due"])<time()){ |
|
107 | + if (strtotime($basic["registration_due"])<time()) { |
|
108 | 108 | return ResponseModel::err(4004); |
109 | 109 | } |
110 | - if(!$basic["registant_type"]){ |
|
110 | + if (!$basic["registant_type"]) { |
|
111 | 111 | return ResponseModel::err(4005); |
112 | 112 | } |
113 | - if($basic["registant_type"]==1 && !$groupModel->isMember($basic["gid"], Auth::user()->id)){ |
|
113 | + if ($basic["registant_type"]==1 && !$groupModel->isMember($basic["gid"], Auth::user()->id)) { |
|
114 | 114 | return ResponseModel::err(4005); |
115 | 115 | } |
116 | 116 |
@@ -153,7 +153,7 @@ |
||
153 | 153 | $ret['secret_level'] = $secret_level; |
154 | 154 | } |
155 | 155 | DB::table('users_extra')->where('uid',$uid)->where('key',$key)->update($ret); |
156 | - }else{ |
|
156 | + } else{ |
|
157 | 157 | return DB::table('users_extra')->insertGetId( |
158 | 158 | [ |
159 | 159 | 'uid' => $uid, |
@@ -25,8 +25,8 @@ discard block |
||
25 | 25 | public function feed($uid=null) |
26 | 26 | { |
27 | 27 | $ret=[]; |
28 | - $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(); |
|
29 | - foreach($solution as &$s){ |
|
28 | + $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(); |
|
29 | + foreach ($solution as &$s) { |
|
30 | 30 | $s["type"]="event"; |
31 | 31 | $s["color"]="wemd-orange"; |
32 | 32 | $s["icon"]="comment-check-outline"; |
@@ -92,14 +92,14 @@ discard block |
||
92 | 92 | ])->join("problem", "problem.pid", "=", "submission.pid")->select('pcode')->distinct()->get()->all(); |
93 | 93 | $ret["solvedCount"]=count($ret["solved"]); |
94 | 94 | // Casual |
95 | - $ret["rank"]=Cache::tags(['rank',$ret["id"]])->get("rank", "N/A"); |
|
96 | - $ret["rankTitle"]=Cache::tags(['rank',$ret["id"]])->get("title"); |
|
95 | + $ret["rank"]=Cache::tags(['rank', $ret["id"]])->get("rank", "N/A"); |
|
96 | + $ret["rankTitle"]=Cache::tags(['rank', $ret["id"]])->get("title"); |
|
97 | 97 | $ret["rankTitleColor"]=RankModel::getColor($ret["rankTitle"]); |
98 | 98 | // Professional |
99 | 99 | $ret["professionalTitle"]=RankModel::getProfessionalTitle($ret["professional_rate"]); |
100 | 100 | $ret["professionalTitleColor"]=RankModel::getProfessionalColor($ret["professionalTitle"]); |
101 | 101 | // Administration Group |
102 | - $ret["admin"]=$uid==1?1:0; |
|
102 | + $ret["admin"]=$uid==1 ? 1 : 0; |
|
103 | 103 | if (Cache::tags(['bing', 'pic'])->get(date("Y-m-d"))==null) { |
104 | 104 | $bing=new BingPhoto([ |
105 | 105 | 'locale' => 'zh-CN', |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | return $ret; |
112 | 112 | } |
113 | 113 | |
114 | - public function getExtraInfo($uid,$secret_level = 0){ |
|
115 | - $ret = DB::table('users_extra')->where('uid',$uid)->get()->all(); |
|
116 | - $key_meaning = [ |
|
114 | + public function getExtraInfo($uid, $secret_level=0) { |
|
115 | + $ret=DB::table('users_extra')->where('uid', $uid)->get()->all(); |
|
116 | + $key_meaning=[ |
|
117 | 117 | 0 => 'gender', |
118 | 118 | 1 => 'contact', |
119 | 119 | 2 => 'school', |
@@ -121,20 +121,20 @@ discard block |
||
121 | 121 | 4 => 'location', |
122 | 122 | 5 => 'editor_left_width', |
123 | 123 | ]; |
124 | - $result = []; |
|
125 | - if(!empty($ret)){ |
|
124 | + $result=[]; |
|
125 | + if (!empty($ret)) { |
|
126 | 126 | foreach ($ret as $value) { |
127 | - if(empty($value['secret_level']) || $value['secret_level'] <= $secret_level){ |
|
128 | - $key_name = $key_meaning[$value['key']] ?? 'unknown'; |
|
129 | - $result[$key_name] = $value['value']; |
|
127 | + if (empty($value['secret_level']) || $value['secret_level']<=$secret_level) { |
|
128 | + $key_name=$key_meaning[$value['key']] ?? 'unknown'; |
|
129 | + $result[$key_name]=$value['value']; |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | } |
133 | 133 | return $result; |
134 | 134 | } |
135 | 135 | |
136 | - public function setExtraInfo($uid,$key_name,$value = null,$secret_level = -1){ |
|
137 | - $key_value = [ |
|
136 | + public function setExtraInfo($uid, $key_name, $value=null, $secret_level=-1) { |
|
137 | + $key_value=[ |
|
138 | 138 | 'gender' => 0, |
139 | 139 | 'contact' => 1, |
140 | 140 | 'school' => 2, |
@@ -143,31 +143,31 @@ discard block |
||
143 | 143 | 'editor_left_width' => 5, |
144 | 144 | //TODO... |
145 | 145 | ]; |
146 | - $key = $key_value[$key_name]; |
|
147 | - $ret = DB::table('users_extra')->where('uid',$uid)->where('key',$key)->first(); |
|
148 | - if(!empty($ret)){ |
|
146 | + $key=$key_value[$key_name]; |
|
147 | + $ret=DB::table('users_extra')->where('uid', $uid)->where('key', $key)->first(); |
|
148 | + if (!empty($ret)) { |
|
149 | 149 | unset($ret['id']); |
150 | - if(!is_null($value)){ |
|
151 | - $ret['value'] = $value; |
|
150 | + if (!is_null($value)) { |
|
151 | + $ret['value']=$value; |
|
152 | 152 | } |
153 | - if($secret_level != -1){ |
|
154 | - $ret['secret_level'] = $secret_level; |
|
153 | + if ($secret_level!=-1) { |
|
154 | + $ret['secret_level']=$secret_level; |
|
155 | 155 | } |
156 | - DB::table('users_extra')->where('uid',$uid)->where('key',$key)->update($ret); |
|
157 | - }else{ |
|
156 | + DB::table('users_extra')->where('uid', $uid)->where('key', $key)->update($ret); |
|
157 | + } else { |
|
158 | 158 | return DB::table('users_extra')->insertGetId( |
159 | 159 | [ |
160 | 160 | 'uid' => $uid, |
161 | 161 | 'key' => $key, |
162 | 162 | 'value' => $value, |
163 | - 'secret_level' => $secret_level == -1 ? 0 : $secret_level, |
|
163 | + 'secret_level' => $secret_level==-1 ? 0 : $secret_level, |
|
164 | 164 | ] |
165 | 165 | ); |
166 | 166 | } |
167 | 167 | } |
168 | 168 | |
169 | - public function unsetExtraInfoIfExist($uid,$key_name){ |
|
170 | - $key_value = [ |
|
169 | + public function unsetExtraInfoIfExist($uid, $key_name) { |
|
170 | + $key_value=[ |
|
171 | 171 | 'gender' => 0, |
172 | 172 | 'contact' => 1, |
173 | 173 | 'school' => 2, |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | 'editor_left_width' => 5, |
177 | 177 | //TODO... |
178 | 178 | ]; |
179 | - $key = $key_value[$key_name]; |
|
180 | - $ret = DB::table('users_extra')->where('uid',$uid)->where('key',$key)->delete(); |
|
179 | + $key=$key_value[$key_name]; |
|
180 | + $ret=DB::table('users_extra')->where('uid', $uid)->where('key', $key)->delete(); |
|
181 | 181 | } |
182 | 182 | } |
@@ -53,7 +53,7 @@ |
||
53 | 53 | if (!function_exists('emailVerified')) { |
54 | 54 | function emailVerified() |
55 | 55 | { |
56 | - if(Auth::check()){ |
|
56 | + if (Auth::check()) { |
|
57 | 57 | return !is_null(Auth::user()->email_verified_at); |
58 | 58 | } |
59 | 59 |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | $accountModel=new AccountModel(); |
29 | 29 | $info=$accountModel->detail(Auth::user()->id); |
30 | 30 | $feed=$accountModel->feed(Auth::user()->id); |
31 | - $extraInfo = $accountModel->getExtraInfo(Auth::user()->id,100); |
|
31 | + $extraInfo=$accountModel->getExtraInfo(Auth::user()->id, 100); |
|
32 | 32 | return view("account.dashboard", [ |
33 | 33 | 'page_title'=>"DashBoard", |
34 | 34 | 'site_title'=>"NOJ", |
@@ -45,10 +45,10 @@ discard block |
||
45 | 45 | { |
46 | 46 | $accountModel=new AccountModel(); |
47 | 47 | $info=$accountModel->detail(Auth::user()->id); |
48 | - if(!empty(session('last_email_send'))){ |
|
49 | - $email_cooldown = 300 - (time() - session('last_email_send')); |
|
48 | + if (!empty(session('last_email_send'))) { |
|
49 | + $email_cooldown=300-(time()-session('last_email_send')); |
|
50 | 50 | } |
51 | - $extraInfo = $accountModel->getExtraInfo(Auth::user()->id,100); |
|
51 | + $extraInfo=$accountModel->getExtraInfo(Auth::user()->id, 100); |
|
52 | 52 | return view("account.dashboard", [ |
53 | 53 | 'page_title'=>"Settings", |
54 | 54 | 'site_title'=>"NOJ", |
@@ -28,7 +28,7 @@ |
||
28 | 28 | $accountModel=new AccountModel(); |
29 | 29 | $info=$accountModel->detail($uid); |
30 | 30 | $feed=$accountModel->feed($uid); |
31 | - $extraInfo = $accountModel->getExtraInfo($uid,0); |
|
31 | + $extraInfo=$accountModel->getExtraInfo($uid, 0); |
|
32 | 32 | return view("account.dashboard", [ |
33 | 33 | 'page_title'=>$info["name"], |
34 | 34 | 'site_title'=>"NOJ", |
@@ -79,7 +79,9 @@ discard block |
||
79 | 79 | public function details($gcode) |
80 | 80 | { |
81 | 81 | $basic_info=DB::table($this->tableName)->where(["gcode"=>$gcode])->first(); |
82 | - if(empty($basic_info)) return []; |
|
82 | + if(empty($basic_info)) { |
|
83 | + return []; |
|
84 | + } |
|
83 | 85 | $basic_info["members"]=$this->countGroupMembers($basic_info["gid"]); |
84 | 86 | $basic_info["tags"]=$this->getGroupTags($basic_info["gid"]); |
85 | 87 | $basic_info["create_time_foramt"]=date_format(date_create($basic_info["create_time"]), 'M jS, Y'); |
@@ -120,7 +122,9 @@ discard block |
||
120 | 122 | foreach ($user_list as &$u) { |
121 | 123 | $u["role_parsed"]=$this->role[$u["role"]]; |
122 | 124 | $u["role_color"]=$this->role_color[$u["role"]]; |
123 | - if(is_null($u["sub_group"])) $u["sub_group"]="None"; |
|
125 | + if(is_null($u["sub_group"])) { |
|
126 | + $u["sub_group"]="None"; |
|
127 | + } |
|
124 | 128 | } |
125 | 129 | return $user_list; |
126 | 130 | } |
@@ -78,13 +78,13 @@ discard block |
||
78 | 78 | |
79 | 79 | public function changeGroupName($gid, $GroupName) |
80 | 80 | { |
81 | - return DB::table("group")->where('gid',$gid)->update([ |
|
81 | + return DB::table("group")->where('gid', $gid)->update([ |
|
82 | 82 | "name"=>$GroupName |
83 | 83 | ]); |
84 | 84 | } |
85 | 85 | |
86 | - public function changeJoinPolicy($gid, $JoinPolicy){ |
|
87 | - return DB::table("group")->where('gid',$gid)->update([ |
|
86 | + public function changeJoinPolicy($gid, $JoinPolicy) { |
|
87 | + return DB::table("group")->where('gid', $gid)->update([ |
|
88 | 88 | "join_policy"=>$JoinPolicy |
89 | 89 | ]); |
90 | 90 | } |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | public function details($gcode) |
93 | 93 | { |
94 | 94 | $basic_info=DB::table($this->tableName)->where(["gcode"=>$gcode])->first(); |
95 | - if(empty($basic_info)) return []; |
|
95 | + if (empty($basic_info)) return []; |
|
96 | 96 | $basic_info["members"]=$this->countGroupMembers($basic_info["gid"]); |
97 | 97 | $basic_info["tags"]=$this->getGroupTags($basic_info["gid"]); |
98 | 98 | $basic_info["create_time_foramt"]=date_format(date_create($basic_info["create_time"]), 'M jS, Y'); |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | foreach ($user_list as &$u) { |
134 | 134 | $u["role_parsed"]=$this->role[$u["role"]]; |
135 | 135 | $u["role_color"]=$this->role_color[$u["role"]]; |
136 | - if(is_null($u["sub_group"])) $u["sub_group"]="None"; |
|
136 | + if (is_null($u["sub_group"])) $u["sub_group"]="None"; |
|
137 | 137 | } |
138 | 138 | return $user_list; |
139 | 139 | } |
@@ -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->setExtraInfo($user_id,$key,$value,0); |
|
112 | - }else{ |
|
113 | - $account_model->unsetExtraInfoIfExist($user_id,$key); |
|
110 | + if (strlen($value)!=0) { |
|
111 | + $account_model->setExtraInfo($user_id, $key, $value, 0); |
|
112 | + } else { |
|
113 | + $account_model->unsetExtraInfoIfExist($user_id, $key); |
|
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->setExtraInfo($user_id,$key,$value,0); |
|
132 | - }else{ |
|
133 | - $account_model->unsetExtraInfoIfExist($user_id,$key); |
|
130 | + if (strlen($value)!=0) { |
|
131 | + $account_model->setExtraInfo($user_id, $key, $value, 0); |
|
132 | + } else { |
|
133 | + $account_model->unsetExtraInfoIfExist($user_id, $key); |
|
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->setExtraInfo($user_id,$key,$value,0); |
112 | - }else{ |
|
112 | + } else{ |
|
113 | 113 | $account_model->unsetExtraInfoIfExist($user_id,$key); |
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->setExtraInfo($user_id,$key,$value,0); |
132 | - }else{ |
|
132 | + } else{ |
|
133 | 133 | $account_model->unsetExtraInfoIfExist($user_id,$key); |
134 | 134 | } |
135 | 135 | } |