@@ -18,16 +18,16 @@ |
||
18 | 18 | public function handle($request, Closure $next) |
19 | 19 | { |
20 | 20 | if (Auth::check()) { |
21 | - if(isset($request->gcode)){ |
|
21 | + if (isset($request->gcode)) { |
|
22 | 22 | //group privilege |
23 | 23 | $groupModel=new GroupModel(); |
24 | - if($groupModel->judgeClearance($groupModel->gid($request->gcode), Auth::user()->id)>=2){ |
|
24 | + if ($groupModel->judgeClearance($groupModel->gid($request->gcode), Auth::user()->id)>=2) { |
|
25 | 25 | return $next($request); |
26 | 26 | } |
27 | - }elseif(isset($request->cid)) { |
|
27 | + }elseif (isset($request->cid)) { |
|
28 | 28 | //contest privilege |
29 | 29 | $contestModel=new ContestModel(); |
30 | - if($contestModel->judgeClearance($request->cid, Auth::user()->id)==3){ |
|
30 | + if ($contestModel->judgeClearance($request->cid, Auth::user()->id)==3) { |
|
31 | 31 | return $next($request); |
32 | 32 | } |
33 | 33 | } |
@@ -24,7 +24,7 @@ |
||
24 | 24 | if($groupModel->judgeClearance($groupModel->gid($request->gcode), Auth::user()->id)>=2){ |
25 | 25 | return $next($request); |
26 | 26 | } |
27 | - }elseif(isset($request->cid)) { |
|
27 | + } elseif(isset($request->cid)) { |
|
28 | 28 | //contest privilege |
29 | 29 | $contestModel=new ContestModel(); |
30 | 30 | if($contestModel->judgeClearance($request->cid, Auth::user()->id)==3){ |
@@ -14,14 +14,14 @@ discard block |
||
14 | 14 | * |
15 | 15 | * @var string |
16 | 16 | */ |
17 | - protected $signature = 'babel:crawl {extension : The package name of the extension} {--action=crawl_problem : The action of the Crawler} {--con=all : The target problemset of the Crawler} {--cached : Whether cached or not}'; |
|
17 | + protected $signature='babel:crawl {extension : The package name of the extension} {--action=crawl_problem : The action of the Crawler} {--con=all : The target problemset of the Crawler} {--cached : Whether cached or not}'; |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * The console command description. |
21 | 21 | * |
22 | 22 | * @var string |
23 | 23 | */ |
24 | - protected $description = 'Crawl problems for a given Babel Extension to NOJ'; |
|
24 | + protected $description='Crawl problems for a given Babel Extension to NOJ'; |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Create a new command instance. |
@@ -40,10 +40,10 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function handle() |
42 | 42 | { |
43 | - $extension = $this->argument('extension'); |
|
44 | - $action = $this->option('action'); |
|
45 | - $con = $this->option('con'); |
|
46 | - $cached = $this->option('cached'); |
|
43 | + $extension=$this->argument('extension'); |
|
44 | + $action=$this->option('action'); |
|
45 | + $con=$this->option('con'); |
|
46 | + $cached=$this->option('cached'); |
|
47 | 47 | $babel=new Babel(); |
48 | 48 | $babel->crawl([ |
49 | 49 | "name" => $extension, |
@@ -17,7 +17,7 @@ |
||
17 | 17 | |
18 | 18 | public function fetch() |
19 | 19 | { |
20 | - $list=DB::table($this->table)->orderBy('post_date','desc')->get()->all(); |
|
20 | + $list=DB::table($this->table)->orderBy('post_date', 'desc')->get()->all(); |
|
21 | 21 | if (empty($list)) { |
22 | 22 | return []; |
23 | 23 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | use Illuminate\Support\Facades\DB; |
8 | 8 | use Illuminate\Support\Arr; |
9 | 9 | use App\Models\Rating\RatingCalculator; |
10 | -use Cache,Redis; |
|
10 | +use Cache, Redis; |
|
11 | 11 | |
12 | 12 | class RankModel extends Model |
13 | 13 | { |
@@ -65,28 +65,28 @@ discard block |
||
65 | 65 | |
66 | 66 | public static function getColor($rankTitle) |
67 | 67 | { |
68 | - if(is_null($rankTitle)) return ""; |
|
68 | + if (is_null($rankTitle)) return ""; |
|
69 | 69 | return self::$casualRanking[$rankTitle]; |
70 | 70 | } |
71 | 71 | |
72 | 72 | public static function getProfessionalColor($rankTitle) |
73 | 73 | { |
74 | - if(is_null($rankTitle)) return self::$professionalRanking["None"]; |
|
74 | + if (is_null($rankTitle)) return self::$professionalRanking["None"]; |
|
75 | 75 | return self::$professionalRanking[$rankTitle]; |
76 | 76 | } |
77 | 77 | |
78 | 78 | public function list($num) |
79 | 79 | { |
80 | 80 | $rankList=Cache::tags(['rank'])->get('general'); |
81 | - if($rankList==null) $rankList=[]; |
|
82 | - $rankList=array_slice($rankList,0,$num); |
|
83 | - $userInfoRaw=DB::table("users")->select("id as uid","avatar","name")->get()->all(); |
|
81 | + if ($rankList==null) $rankList=[]; |
|
82 | + $rankList=array_slice($rankList, 0, $num); |
|
83 | + $userInfoRaw=DB::table("users")->select("id as uid", "avatar", "name")->get()->all(); |
|
84 | 84 | $userInfo=[]; |
85 | - foreach($userInfoRaw as $u){ |
|
85 | + foreach ($userInfoRaw as $u) { |
|
86 | 86 | $userInfo[$u["uid"]]=$u; |
87 | 87 | } |
88 | - foreach($rankList as &$r){ |
|
89 | - $r["details"]=isset($userInfo[$r["uid"]])?$userInfo[$r["uid"]]:[]; |
|
88 | + foreach ($rankList as &$r) { |
|
89 | + $r["details"]=isset($userInfo[$r["uid"]]) ? $userInfo[$r["uid"]] : []; |
|
90 | 90 | } |
91 | 91 | // var_dump($rankList); exit(); |
92 | 92 | return $rankList; |
@@ -109,8 +109,8 @@ discard block |
||
109 | 109 | $rankSolved=$rankItem["totValue"]; |
110 | 110 | } |
111 | 111 | $rankTitle=$this->getRankTitle($rankValue); |
112 | - Cache::tags(['rank',$rankItem["uid"]])->put("rank", $rankValue, 86400); |
|
113 | - Cache::tags(['rank',$rankItem["uid"]])->put("title", $rankTitle, 86400); |
|
112 | + Cache::tags(['rank', $rankItem["uid"]])->put("rank", $rankValue, 86400); |
|
113 | + Cache::tags(['rank', $rankItem["uid"]])->put("title", $rankTitle, 86400); |
|
114 | 114 | $rankListCached[]=[ |
115 | 115 | "uid"=>$rankItem["uid"], |
116 | 116 | "rank"=>$rankValue, |
@@ -127,14 +127,14 @@ discard block |
||
127 | 127 | |
128 | 128 | public function getProfessionalRanking() |
129 | 129 | { |
130 | - $professionalRankList = []; |
|
131 | - $verifiedUsers = DB::table("users")->select("professional_rate","id as uid","avatar","name")->get()->all(); |
|
132 | - $rankIter = 0; |
|
133 | - foreach($verifiedUsers as $user) { |
|
134 | - $rankVal = $user['professional_rate']; |
|
135 | - $rankTitle = self::getProfessionalTitle($rankVal); |
|
136 | - $titleColor = self::getProfessionalColor($rankTitle); |
|
137 | - $professionalRankList[$rankIter++] = [ |
|
130 | + $professionalRankList=[]; |
|
131 | + $verifiedUsers=DB::table("users")->select("professional_rate", "id as uid", "avatar", "name")->get()->all(); |
|
132 | + $rankIter=0; |
|
133 | + foreach ($verifiedUsers as $user) { |
|
134 | + $rankVal=$user['professional_rate']; |
|
135 | + $rankTitle=self::getProfessionalTitle($rankVal); |
|
136 | + $titleColor=self::getProfessionalColor($rankTitle); |
|
137 | + $professionalRankList[$rankIter++]=[ |
|
138 | 138 | "name"=>$user["name"], |
139 | 139 | "uid"=>$user["uid"], |
140 | 140 | "avatar"=>$user["avatar"], |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | $tot+=$c; |
157 | 157 | } |
158 | 158 | foreach ($this->casualRankingPer as &$c) { |
159 | - $c=round($c*$totUsers/$tot); |
|
159 | + $c=round($c * $totUsers / $tot); |
|
160 | 160 | $cur+=$c; |
161 | 161 | $c=$cur; |
162 | 162 | } |
@@ -167,16 +167,16 @@ discard block |
||
167 | 167 | |
168 | 168 | public function getRankTitle($rankVal) |
169 | 169 | { |
170 | - foreach($this->casualRankingPer as $title=>$c){ |
|
171 | - if($rankVal<=$c) return $title; |
|
170 | + foreach ($this->casualRankingPer as $title=>$c) { |
|
171 | + if ($rankVal<=$c) return $title; |
|
172 | 172 | } |
173 | 173 | return Arr::last($this->casualRankingPer); |
174 | 174 | } |
175 | 175 | |
176 | 176 | public static function getProfessionalTitle($rankVal) |
177 | 177 | { |
178 | - foreach(self::$professionalRankingPer as $title=>$point) { |
|
179 | - if($rankVal >= $point) return $title; |
|
178 | + foreach (self::$professionalRankingPer as $title=>$point) { |
|
179 | + if ($rankVal>=$point) return $title; |
|
180 | 180 | } |
181 | 181 | return Arr::last(self::$professionalRankingPer); |
182 | 182 | } |
@@ -65,20 +65,26 @@ discard block |
||
65 | 65 | |
66 | 66 | public static function getColor($rankTitle) |
67 | 67 | { |
68 | - if(is_null($rankTitle)) return ""; |
|
68 | + if(is_null($rankTitle)) { |
|
69 | + return ""; |
|
70 | + } |
|
69 | 71 | return self::$casualRanking[$rankTitle]; |
70 | 72 | } |
71 | 73 | |
72 | 74 | public static function getProfessionalColor($rankTitle) |
73 | 75 | { |
74 | - if(is_null($rankTitle)) return self::$professionalRanking["None"]; |
|
76 | + if(is_null($rankTitle)) { |
|
77 | + return self::$professionalRanking["None"]; |
|
78 | + } |
|
75 | 79 | return self::$professionalRanking[$rankTitle]; |
76 | 80 | } |
77 | 81 | |
78 | 82 | public function list($num) |
79 | 83 | { |
80 | 84 | $rankList=Cache::tags(['rank'])->get('general'); |
81 | - if($rankList==null) $rankList=[]; |
|
85 | + if($rankList==null) { |
|
86 | + $rankList=[]; |
|
87 | + } |
|
82 | 88 | $rankList=array_slice($rankList,0,$num); |
83 | 89 | $userInfoRaw=DB::table("users")->select("id as uid","avatar","name")->get()->all(); |
84 | 90 | $userInfo=[]; |
@@ -168,7 +174,9 @@ discard block |
||
168 | 174 | public function getRankTitle($rankVal) |
169 | 175 | { |
170 | 176 | foreach($this->casualRankingPer as $title=>$c){ |
171 | - if($rankVal<=$c) return $title; |
|
177 | + if($rankVal<=$c) { |
|
178 | + return $title; |
|
179 | + } |
|
172 | 180 | } |
173 | 181 | return Arr::last($this->casualRankingPer); |
174 | 182 | } |
@@ -176,7 +184,9 @@ discard block |
||
176 | 184 | public static function getProfessionalTitle($rankVal) |
177 | 185 | { |
178 | 186 | foreach(self::$professionalRankingPer as $title=>$point) { |
179 | - if($rankVal >= $point) return $title; |
|
187 | + if($rankVal >= $point) { |
|
188 | + return $title; |
|
189 | + } |
|
180 | 190 | } |
181 | 191 | return Arr::last(self::$professionalRankingPer); |
182 | 192 | } |
@@ -14,14 +14,14 @@ discard block |
||
14 | 14 | * |
15 | 15 | * @var string |
16 | 16 | */ |
17 | - protected $signature = 'babel:sync {extension : The package name of the extension} {--vcid= : The target contest of the Crawler} {--gid=1 : The holding group}'; |
|
17 | + protected $signature='babel:sync {extension : The package name of the extension} {--vcid= : The target contest of the Crawler} {--gid=1 : The holding group}'; |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * The console command description. |
21 | 21 | * |
22 | 22 | * @var string |
23 | 23 | */ |
24 | - protected $description = 'Crawl contests for a given Babel Extension to NOJ'; |
|
24 | + protected $description='Crawl contests for a given Babel Extension to NOJ'; |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Create a new command instance. |
@@ -40,16 +40,16 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function handle() |
42 | 42 | { |
43 | - $extension = $this->argument('extension'); |
|
44 | - $vcid = $this->option('vcid'); |
|
45 | - $gid = $this->option('gid'); |
|
46 | - $className = "App\\Babel\\Extension\\$extension\\Synchronizer"; |
|
47 | - $all_data = [ |
|
43 | + $extension=$this->argument('extension'); |
|
44 | + $vcid=$this->option('vcid'); |
|
45 | + $gid=$this->option('gid'); |
|
46 | + $className="App\\Babel\\Extension\\$extension\\Synchronizer"; |
|
47 | + $all_data=[ |
|
48 | 48 | 'oj'=>$extension, |
49 | 49 | 'vcid'=>$vcid, |
50 | 50 | 'gid'=>$gid, |
51 | 51 | ]; |
52 | - $Sync = new $className($all_data); |
|
52 | + $Sync=new $className($all_data); |
|
53 | 53 | $Sync->crawlContest(); |
54 | 54 | } |
55 | 55 | } |
@@ -14,14 +14,14 @@ discard block |
||
14 | 14 | * |
15 | 15 | * @var string |
16 | 16 | */ |
17 | - protected $signature = 'babel:rerank {extension : The package name of the extension} {--vcid= : The target contest of the Crawler} {--gid=1 : The holding group} {--cid= : The NOJ contest}'; |
|
17 | + protected $signature='babel:rerank {extension : The package name of the extension} {--vcid= : The target contest of the Crawler} {--gid=1 : The holding group} {--cid= : The NOJ contest}'; |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * The console command description. |
21 | 21 | * |
22 | 22 | * @var string |
23 | 23 | */ |
24 | - protected $description = 'Refresh Rank from a remote contest'; |
|
24 | + protected $description='Refresh Rank from a remote contest'; |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Create a new command instance. |
@@ -40,18 +40,18 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function handle() |
42 | 42 | { |
43 | - $extension = $this->argument('extension'); |
|
44 | - $vcid = $this->option('vcid'); |
|
45 | - $gid = $this->option('gid'); |
|
46 | - $cid = $this->option('cid'); |
|
47 | - $className = "App\\Babel\\Extension\\$extension\\Synchronizer"; |
|
48 | - $all_data = [ |
|
43 | + $extension=$this->argument('extension'); |
|
44 | + $vcid=$this->option('vcid'); |
|
45 | + $gid=$this->option('gid'); |
|
46 | + $cid=$this->option('cid'); |
|
47 | + $className="App\\Babel\\Extension\\$extension\\Synchronizer"; |
|
48 | + $all_data=[ |
|
49 | 49 | 'oj'=>$extension, |
50 | 50 | 'vcid'=>$vcid, |
51 | 51 | 'gid'=>$gid, |
52 | 52 | 'cid'=>$cid, |
53 | 53 | ]; |
54 | - $Sync = new $className($all_data); |
|
54 | + $Sync=new $className($all_data); |
|
55 | 55 | $Sync->crawlRank(); |
56 | 56 | } |
57 | 57 | } |
@@ -114,7 +114,9 @@ discard block |
||
114 | 114 | public function details($gcode) |
115 | 115 | { |
116 | 116 | $basic_info=DB::table($this->tableName)->where(["gcode"=>$gcode])->first(); |
117 | - if(empty($basic_info)) return []; |
|
117 | + if(empty($basic_info)) { |
|
118 | + return []; |
|
119 | + } |
|
118 | 120 | $basic_info["members"]=$this->countGroupMembers($basic_info["gid"]); |
119 | 121 | $basic_info["tags"]=$this->getGroupTags($basic_info["gid"]); |
120 | 122 | $basic_info["create_time_foramt"]=date_format(date_create($basic_info["create_time"]), 'M jS, Y'); |
@@ -162,7 +164,9 @@ discard block |
||
162 | 164 | foreach ($user_list as &$u) { |
163 | 165 | $u["role_parsed"]=$this->role[$u["role"]]; |
164 | 166 | $u["role_color"]=$this->role_color[$u["role"]]; |
165 | - if(is_null($u["sub_group"])) $u["sub_group"]="None"; |
|
167 | + if(is_null($u["sub_group"])) { |
|
168 | + $u["sub_group"]="None"; |
|
169 | + } |
|
166 | 170 | } |
167 | 171 | return $user_list; |
168 | 172 | } |
@@ -231,7 +235,7 @@ discard block |
||
231 | 235 | ->where('gid',$gid) |
232 | 236 | ->distinct() |
233 | 237 | ->get()->all(); |
234 | - }else{ |
|
238 | + } else{ |
|
235 | 239 | $tags = DB::table('group_problem_tag') |
236 | 240 | ->select('tag') |
237 | 241 | ->where('gid', $gid) |
@@ -265,7 +269,7 @@ discard block |
||
265 | 269 | foreach($problems as $key => $value){ |
266 | 270 | if($contestModel->judgeClearance($value['cid'],$user_id) != 3){ |
267 | 271 | unset($problems[$key]); |
268 | - }else{ |
|
272 | + } else{ |
|
269 | 273 | $problems[$key]['tags'] = $this->problemTags($gid,$value['pid']); |
270 | 274 | } |
271 | 275 | } |
@@ -326,7 +330,9 @@ discard block |
||
326 | 330 | public function judgeEmailClearance($gid, $email) |
327 | 331 | { |
328 | 332 | $user=DB::table("users")->where(["email"=>$email])->first(); |
329 | - if(empty($user)) return -4; |
|
333 | + if(empty($user)) { |
|
334 | + return -4; |
|
335 | + } |
|
330 | 336 | $ret=DB::table("group_member")->where([ |
331 | 337 | "gid"=>$gid, |
332 | 338 | "uid"=>$user["id"], |
@@ -58,10 +58,10 @@ discard block |
||
58 | 58 | foreach ($trending_groups as &$t) { |
59 | 59 | $t["members"]=$this->countGroupMembers($t["gid"]); |
60 | 60 | } |
61 | - usort($trending_groups, function ($a, $b) { |
|
61 | + usort($trending_groups, function($a, $b) { |
|
62 | 62 | return $b["members"]<=>$a["members"]; |
63 | 63 | }); |
64 | - Cache::tags(['group'])->put('trending', array_slice($trending_groups,0,12), 3600*24); |
|
64 | + Cache::tags(['group'])->put('trending', array_slice($trending_groups, 0, 12), 3600 * 24); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | public function userGroups($uid) |
@@ -101,13 +101,13 @@ discard block |
||
101 | 101 | |
102 | 102 | public function changeGroupName($gid, $GroupName) |
103 | 103 | { |
104 | - return DB::table("group")->where('gid',$gid)->update([ |
|
104 | + return DB::table("group")->where('gid', $gid)->update([ |
|
105 | 105 | "name"=>$GroupName |
106 | 106 | ]); |
107 | 107 | } |
108 | 108 | |
109 | - public function changeJoinPolicy($gid, $JoinPolicy){ |
|
110 | - return DB::table("group")->where('gid',$gid)->update([ |
|
109 | + public function changeJoinPolicy($gid, $JoinPolicy) { |
|
110 | + return DB::table("group")->where('gid', $gid)->update([ |
|
111 | 111 | "join_policy"=>$JoinPolicy |
112 | 112 | ]); |
113 | 113 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | public function details($gcode) |
116 | 116 | { |
117 | 117 | $basic_info=DB::table($this->tableName)->where(["gcode"=>$gcode])->first(); |
118 | - if(empty($basic_info)) return []; |
|
118 | + if (empty($basic_info)) return []; |
|
119 | 119 | $basic_info["members"]=$this->countGroupMembers($basic_info["gid"]); |
120 | 120 | $basic_info["tags"]=$this->getGroupTags($basic_info["gid"]); |
121 | 121 | $basic_info["create_time_foramt"]=date_format(date_create($basic_info["create_time"]), 'M jS, Y'); |
@@ -132,10 +132,10 @@ discard block |
||
132 | 132 | public function userProfile($uid, $gid) |
133 | 133 | { |
134 | 134 | $info=DB::table("group_member") |
135 | - ->join('users','users.id','=','group_member.uid') |
|
135 | + ->join('users', 'users.id', '=', 'group_member.uid') |
|
136 | 136 | ->where(["gid"=>$gid, "uid"=>$uid]) |
137 | 137 | ->where("role", ">", 0) |
138 | - ->select('avatar','describes','email','gid','uid','name','nick_name','professional_rate','role','sub_group') |
|
138 | + ->select('avatar', 'describes', 'email', 'gid', 'uid', 'name', 'nick_name', 'professional_rate', 'role', 'sub_group') |
|
139 | 139 | ->first(); |
140 | 140 | if (!empty($info)) { |
141 | 141 | $info["role_parsed"]=$this->role[$info["role"]]; |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | foreach ($user_list as &$u) { |
164 | 164 | $u["role_parsed"]=$this->role[$u["role"]]; |
165 | 165 | $u["role_color"]=$this->role_color[$u["role"]]; |
166 | - if(is_null($u["sub_group"])) $u["sub_group"]="None"; |
|
166 | + if (is_null($u["sub_group"])) $u["sub_group"]="None"; |
|
167 | 167 | } |
168 | 168 | return $user_list; |
169 | 169 | } |
@@ -224,16 +224,16 @@ discard block |
||
224 | 224 | ])->where("role", ">", 0)->count(); |
225 | 225 | } |
226 | 226 | |
227 | - public function problemTags($gid,$pid = -1) |
|
227 | + public function problemTags($gid, $pid=-1) |
|
228 | 228 | { |
229 | - if($pid == -1){ |
|
230 | - $tags = DB::table('group_problem_tag') |
|
229 | + if ($pid==-1) { |
|
230 | + $tags=DB::table('group_problem_tag') |
|
231 | 231 | ->select('tag') |
232 | - ->where('gid',$gid) |
|
232 | + ->where('gid', $gid) |
|
233 | 233 | ->distinct() |
234 | 234 | ->get()->all(); |
235 | - }else{ |
|
236 | - $tags = DB::table('group_problem_tag') |
|
235 | + } else { |
|
236 | + $tags=DB::table('group_problem_tag') |
|
237 | 237 | ->select('tag') |
238 | 238 | ->where('gid', $gid) |
239 | 239 | ->where('pid', $pid) |
@@ -241,10 +241,10 @@ discard block |
||
241 | 241 | ->get()->all(); |
242 | 242 | } |
243 | 243 | |
244 | - $tags_arr = []; |
|
245 | - if(!empty($tags)){ |
|
244 | + $tags_arr=[]; |
|
245 | + if (!empty($tags)) { |
|
246 | 246 | foreach ($tags as $value) { |
247 | - array_push($tags_arr,$value['tag']); |
|
247 | + array_push($tags_arr, $value['tag']); |
|
248 | 248 | } |
249 | 249 | } |
250 | 250 | return $tags_arr; |
@@ -252,28 +252,28 @@ discard block |
||
252 | 252 | |
253 | 253 | public function problems($gid) |
254 | 254 | { |
255 | - $contestModel = new ContestModel(); |
|
256 | - $problems = DB::table('contest_problem') |
|
257 | - ->join('contest','contest_problem.cid', '=', 'contest.cid') |
|
258 | - ->join('problem','contest_problem.pid', '=', 'problem.pid' ) |
|
255 | + $contestModel=new ContestModel(); |
|
256 | + $problems=DB::table('contest_problem') |
|
257 | + ->join('contest', 'contest_problem.cid', '=', 'contest.cid') |
|
258 | + ->join('problem', 'contest_problem.pid', '=', 'problem.pid') |
|
259 | 259 | ->select('contest_problem.cid as cid', 'problem.pid as pid', 'pcode', 'title') |
260 | - ->where('contest.gid',$gid) |
|
261 | - ->where('contest.practice',1) |
|
262 | - ->orderBy('contest.create_time','desc') |
|
260 | + ->where('contest.gid', $gid) |
|
261 | + ->where('contest.practice', 1) |
|
262 | + ->orderBy('contest.create_time', 'desc') |
|
263 | 263 | ->distinct() |
264 | 264 | ->get()->all(); |
265 | - $user_id = Auth::user()->id; |
|
266 | - foreach($problems as $key => $value){ |
|
267 | - if($contestModel->judgeClearance($value['cid'],$user_id) != 3){ |
|
265 | + $user_id=Auth::user()->id; |
|
266 | + foreach ($problems as $key => $value) { |
|
267 | + if ($contestModel->judgeClearance($value['cid'], $user_id)!=3) { |
|
268 | 268 | unset($problems[$key]); |
269 | - }else{ |
|
270 | - $problems[$key]['tags'] = $this->problemTags($gid,$value['pid']); |
|
269 | + } else { |
|
270 | + $problems[$key]['tags']=$this->problemTags($gid, $value['pid']); |
|
271 | 271 | } |
272 | 272 | } |
273 | 273 | return $problems; |
274 | 274 | } |
275 | 275 | |
276 | - public function problemAddTag($gid,$pid,$tag) |
|
276 | + public function problemAddTag($gid, $pid, $tag) |
|
277 | 277 | { |
278 | 278 | return DB::table("group_problem_tag")->insert([ |
279 | 279 | "gid"=>$gid, |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | ]); |
283 | 283 | } |
284 | 284 | |
285 | - public function problemRemoveTag($gid,$pid,$tag) |
|
285 | + public function problemRemoveTag($gid, $pid, $tag) |
|
286 | 286 | { |
287 | 287 | return DB::table("group_problem_tag")->where([ |
288 | 288 | "gid"=>$gid, |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | public function judgeEmailClearance($gid, $email) |
328 | 328 | { |
329 | 329 | $user=DB::table("users")->where(["email"=>$email])->first(); |
330 | - if(empty($user)) return -4; |
|
330 | + if (empty($user)) return -4; |
|
331 | 331 | $ret=DB::table("group_member")->where([ |
332 | 332 | "gid"=>$gid, |
333 | 333 | "uid"=>$user["id"], |
@@ -408,20 +408,20 @@ discard block |
||
408 | 408 | |
409 | 409 | public function groupMemberPracticeContestStat($gid) |
410 | 410 | { |
411 | - $contestModel = new ContestModel(); |
|
411 | + $contestModel=new ContestModel(); |
|
412 | 412 | |
413 | - $allPracticeContest = DB::table('contest') |
|
413 | + $allPracticeContest=DB::table('contest') |
|
414 | 414 | ->where([ |
415 | 415 | 'gid' => $gid, |
416 | 416 | 'practice' => 1, |
417 | 417 | ]) |
418 | - ->select('cid','name') |
|
418 | + ->select('cid', 'name') |
|
419 | 419 | ->get()->all(); |
420 | - $user_list = $this->userList($gid); |
|
420 | + $user_list=$this->userList($gid); |
|
421 | 421 | |
422 | - $memberData = []; |
|
422 | + $memberData=[]; |
|
423 | 423 | foreach ($user_list as $u) { |
424 | - $memberData[$u['uid']] = [ |
|
424 | + $memberData[$u['uid']]=[ |
|
425 | 425 | 'name' => $u['name'], |
426 | 426 | 'nick_name' => $u['nick_name'], |
427 | 427 | 'elo' => $u['ranking'], |
@@ -432,24 +432,24 @@ discard block |
||
432 | 432 | ]; |
433 | 433 | } |
434 | 434 | foreach ($allPracticeContest as $c) { |
435 | - $contestRankRaw = $contestModel->contestRank($c['cid']); |
|
436 | - foreach($contestRankRaw as $key => $contestRank){ |
|
437 | - if(isset($contestRank['remote']) && $contestRank['remote']){ |
|
435 | + $contestRankRaw=$contestModel->contestRank($c['cid']); |
|
436 | + foreach ($contestRankRaw as $key => $contestRank) { |
|
437 | + if (isset($contestRank['remote']) && $contestRank['remote']) { |
|
438 | 438 | unset($contestRankRaw[$key]); |
439 | 439 | } |
440 | 440 | } |
441 | - $contestRank = array_values($contestRankRaw); |
|
442 | - $problemsCount = DB::table('contest_problem') |
|
443 | - ->where('cid',$c['cid']) |
|
441 | + $contestRank=array_values($contestRankRaw); |
|
442 | + $problemsCount=DB::table('contest_problem') |
|
443 | + ->where('cid', $c['cid']) |
|
444 | 444 | ->count(); |
445 | - $rank = 0; |
|
445 | + $rank=0; |
|
446 | 446 | foreach ($contestRank as $cr) { |
447 | 447 | $rank++; |
448 | - if(in_array($cr['uid'],array_keys($memberData))) { |
|
449 | - $memberData[$cr['uid']]['solved_all'] += $cr['solved']; |
|
450 | - $memberData[$cr['uid']]['problem_all'] += $problemsCount; |
|
451 | - $memberData[$cr['uid']]['penalty'] += $cr['penalty']; |
|
452 | - $memberData[$cr['uid']]['contest_detial'][$c['cid']] = [ |
|
448 | + if (in_array($cr['uid'], array_keys($memberData))) { |
|
449 | + $memberData[$cr['uid']]['solved_all']+=$cr['solved']; |
|
450 | + $memberData[$cr['uid']]['problem_all']+=$problemsCount; |
|
451 | + $memberData[$cr['uid']]['penalty']+=$cr['penalty']; |
|
452 | + $memberData[$cr['uid']]['contest_detial'][$c['cid']]=[ |
|
453 | 453 | 'rank' => $rank, |
454 | 454 | 'solved' => $cr['solved'], |
455 | 455 | 'problems' => $problemsCount, |
@@ -458,22 +458,22 @@ discard block |
||
458 | 458 | } |
459 | 459 | } |
460 | 460 | } |
461 | - $new_memberData = []; |
|
461 | + $new_memberData=[]; |
|
462 | 462 | foreach ($memberData as $uid => $data) { |
463 | - $contest_count = 0; |
|
464 | - $rank_sum = 0; |
|
463 | + $contest_count=0; |
|
464 | + $rank_sum=0; |
|
465 | 465 | foreach ($data['contest_detial'] as $cid => $c) { |
466 | - $rank_sum += $c['rank']; |
|
467 | - $contest_count += 1; |
|
466 | + $rank_sum+=$c['rank']; |
|
467 | + $contest_count+=1; |
|
468 | 468 | } |
469 | - $temp = $data; |
|
470 | - $temp['uid'] = $uid; |
|
471 | - if($contest_count != 0){ |
|
472 | - $temp['rank_ave'] = $rank_sum/$contest_count; |
|
469 | + $temp=$data; |
|
470 | + $temp['uid']=$uid; |
|
471 | + if ($contest_count!=0) { |
|
472 | + $temp['rank_ave']=$rank_sum / $contest_count; |
|
473 | 473 | } |
474 | - array_push($new_memberData,$temp); |
|
474 | + array_push($new_memberData, $temp); |
|
475 | 475 | } |
476 | - $ret = [ |
|
476 | + $ret=[ |
|
477 | 477 | 'contest_list' => $allPracticeContest, |
478 | 478 | 'member_data' => $new_memberData |
479 | 479 | ]; |
@@ -482,58 +482,58 @@ discard block |
||
482 | 482 | |
483 | 483 | public function groupMemberPracticeTagStat($gid) |
484 | 484 | { |
485 | - $tags = $this->problemTags($gid); |
|
486 | - $tag_problems = []; |
|
485 | + $tags=$this->problemTags($gid); |
|
486 | + $tag_problems=[]; |
|
487 | 487 | |
488 | - $user_list = $this->userList($gid); |
|
488 | + $user_list=$this->userList($gid); |
|
489 | 489 | foreach ($tags as $tag) { |
490 | - $tag_problems[$tag] = DB::table('problem') |
|
491 | - ->join('group_problem_tag','problem.pid','=','group_problem_tag.pid') |
|
490 | + $tag_problems[$tag]=DB::table('problem') |
|
491 | + ->join('group_problem_tag', 'problem.pid', '=', 'group_problem_tag.pid') |
|
492 | 492 | ->where([ |
493 | 493 | 'group_problem_tag.gid' => $gid, |
494 | 494 | 'tag' => $tag |
495 | 495 | ]) |
496 | - ->select('group_problem_tag.pid as pid','pcode','title') |
|
496 | + ->select('group_problem_tag.pid as pid', 'pcode', 'title') |
|
497 | 497 | ->get()->all(); |
498 | 498 | } |
499 | - $all_problems = []; |
|
499 | + $all_problems=[]; |
|
500 | 500 | foreach ($tag_problems as &$tag_problem_set) { |
501 | 501 | foreach ($tag_problem_set as $problem) { |
502 | - $all_problems[$problem['pid']] = $problem; |
|
502 | + $all_problems[$problem['pid']]=$problem; |
|
503 | 503 | } |
504 | - $tag_problem_set = array_column($tag_problem_set,'pid'); |
|
504 | + $tag_problem_set=array_column($tag_problem_set, 'pid'); |
|
505 | 505 | } |
506 | - $submission_data = DB::table('submission') |
|
507 | - ->whereIn('pid',array_keys($all_problems)) |
|
508 | - ->whereIn('uid',array_column($user_list,'uid')) |
|
509 | - ->where('verdict','Accepted') |
|
510 | - ->select('pid','uid') |
|
506 | + $submission_data=DB::table('submission') |
|
507 | + ->whereIn('pid', array_keys($all_problems)) |
|
508 | + ->whereIn('uid', array_column($user_list, 'uid')) |
|
509 | + ->where('verdict', 'Accepted') |
|
510 | + ->select('pid', 'uid') |
|
511 | 511 | ->get()->all(); |
512 | 512 | |
513 | - $memberData = []; |
|
513 | + $memberData=[]; |
|
514 | 514 | foreach ($user_list as $member) { |
515 | - $completion = []; |
|
516 | - foreach($tag_problems as $tag => $problems) { |
|
517 | - $completion[$tag] = []; |
|
515 | + $completion=[]; |
|
516 | + foreach ($tag_problems as $tag => $problems) { |
|
517 | + $completion[$tag]=[]; |
|
518 | 518 | foreach ($problems as $problem) { |
519 | - $is_accepted = 0; |
|
519 | + $is_accepted=0; |
|
520 | 520 | foreach ($submission_data as $sd) { |
521 | - if($sd['pid'] == $problem && $sd['uid'] == $member['uid']){ |
|
522 | - $is_accepted = 1; |
|
521 | + if ($sd['pid']==$problem && $sd['uid']==$member['uid']) { |
|
522 | + $is_accepted=1; |
|
523 | 523 | break; |
524 | 524 | } |
525 | 525 | } |
526 | - $completion[$tag][$problem] = $is_accepted; |
|
526 | + $completion[$tag][$problem]=$is_accepted; |
|
527 | 527 | } |
528 | 528 | } |
529 | - array_push($memberData,[ |
|
529 | + array_push($memberData, [ |
|
530 | 530 | 'uid' => $member['uid'], |
531 | 531 | 'name' => $member['name'], |
532 | 532 | 'nick_name' => $member['nick_name'], |
533 | 533 | 'completion' => $completion, |
534 | 534 | ]); |
535 | 535 | } |
536 | - $ret = [ |
|
536 | + $ret=[ |
|
537 | 537 | 'all_problems' => $all_problems, |
538 | 538 | 'tag_problems' => $tag_problems, |
539 | 539 | 'member_data' => $memberData |
@@ -544,29 +544,29 @@ discard block |
||
544 | 544 | public function refreshElo($gid) |
545 | 545 | { |
546 | 546 | DB::table('group_rated_change_log') |
547 | - ->where('gid',$gid) |
|
547 | + ->where('gid', $gid) |
|
548 | 548 | ->delete(); |
549 | 549 | DB::table('group_member') |
550 | - ->where('gid',$gid) |
|
550 | + ->where('gid', $gid) |
|
551 | 551 | ->update([ |
552 | 552 | 'ranking' => 1500 |
553 | 553 | ]); |
554 | - $contests = DB::table('contest') |
|
554 | + $contests=DB::table('contest') |
|
555 | 555 | ->where([ |
556 | 556 | 'gid' => $gid, |
557 | 557 | 'practice' => 1 |
558 | 558 | ]) |
559 | - ->where('end_time','<',date("Y-m-d H:i:s")) |
|
559 | + ->where('end_time', '<', date("Y-m-d H:i:s")) |
|
560 | 560 | ->select('cid') |
561 | 561 | ->orderBy('end_time') |
562 | 562 | ->get()->all(); |
563 | 563 | |
564 | - if(empty($contests)) { |
|
564 | + if (empty($contests)) { |
|
565 | 565 | return true; |
566 | 566 | } |
567 | 567 | |
568 | 568 | foreach ($contests as $contest) { |
569 | - $calc = new GroupRatingCalculator($contest['cid']); |
|
569 | + $calc=new GroupRatingCalculator($contest['cid']); |
|
570 | 570 | $calc->calculate(); |
571 | 571 | $calc->storage(); |
572 | 572 | } |
@@ -23,34 +23,34 @@ |
||
23 | 23 | if (!$request->has('search_key')) { |
24 | 24 | return ResponseModel::err(1003); |
25 | 25 | } |
26 | - $key = $request->input('search_key'); |
|
27 | - $all_result = []; |
|
28 | - $search_from = [ |
|
26 | + $key=$request->input('search_key'); |
|
27 | + $all_result=[]; |
|
28 | + $search_from=[ |
|
29 | 29 | 'users' => \App\Models\Search\UserSearchModel::class, |
30 | 30 | 'problems' => \App\Models\Search\ProblemSearchModel::class, |
31 | 31 | 'contests' => \App\Models\Search\ContestSearchModel::class, |
32 | 32 | 'groups' => \App\Models\Search\GroupSearchModel::class, |
33 | 33 | ]; |
34 | 34 | foreach ($search_from as $name => $model_class) { |
35 | - if(class_exists($model_class)){ |
|
36 | - $model = new $model_class(); |
|
37 | - if(!method_exists($model,'search')){ |
|
38 | - $all_result[$name] = [ |
|
35 | + if (class_exists($model_class)) { |
|
36 | + $model=new $model_class(); |
|
37 | + if (!method_exists($model, 'search')) { |
|
38 | + $all_result[$name]=[ |
|
39 | 39 | 'code' => -1, |
40 | 40 | 'msg' => 'cannot find search method in '.$model_class |
41 | 41 | ]; |
42 | 42 | continue; |
43 | 43 | } |
44 | - $result = $model->search($key); |
|
45 | - $all_result[$name] = $result; |
|
46 | - }else{ |
|
47 | - $all_result[$name] = [ |
|
44 | + $result=$model->search($key); |
|
45 | + $all_result[$name]=$result; |
|
46 | + } else { |
|
47 | + $all_result[$name]=[ |
|
48 | 48 | 'code' => -1, |
49 | 49 | 'msg' => 'cannot find class named '.$model_class |
50 | - ];; |
|
50 | + ]; ; |
|
51 | 51 | continue; |
52 | 52 | } |
53 | 53 | } |
54 | - return ResponseModel::success(200,'Successful',$all_result); |
|
54 | + return ResponseModel::success(200, 'Successful', $all_result); |
|
55 | 55 | } |
56 | 56 | } |
@@ -43,7 +43,7 @@ |
||
43 | 43 | } |
44 | 44 | $result = $model->search($key); |
45 | 45 | $all_result[$name] = $result; |
46 | - }else{ |
|
46 | + } else{ |
|
47 | 47 | $all_result[$name] = [ |
48 | 48 | 'code' => -1, |
49 | 49 | 'msg' => 'cannot find class named '.$model_class |
@@ -91,7 +91,7 @@ |
||
91 | 91 | { |
92 | 92 | $serverList=DB::table("judge_server")->where(["oid"=>$oid])->get()->all(); |
93 | 93 | foreach ($serverList as &$server) { |
94 | - $server["status_parsed"]=is_null($server["status"])?self::$status["-1"]:self::$status[$server["status"]]; |
|
94 | + $server["status_parsed"]=is_null($server["status"]) ?self::$status["-1"] : self::$status[$server["status"]]; |
|
95 | 95 | } |
96 | 96 | return $serverList; |
97 | 97 | } |