@@ -20,7 +20,7 @@ |
||
20 | 20 | $router->resource('groups', GroupController::class); |
21 | 21 | $router->resource('abuses', AbuseController::class); |
22 | 22 | |
23 | - Route::group(['prefix' => 'babel'], function (Router $router) { |
|
23 | + Route::group(['prefix' => 'babel'], function(Router $router) { |
|
24 | 24 | $router->get('/', 'BabelController@index')->name('admin.babel.index'); |
25 | 25 | $router->get('installed', 'BabelController@installed')->name('admin.babel.installed'); |
26 | 26 | $router->get('marketspace', 'BabelController@marketspace')->name('admin.babel.marketspace'); |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | * |
18 | 18 | * @var string |
19 | 19 | */ |
20 | - public $title = 'Import'; |
|
20 | + public $title='Import'; |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * Handle the form request. |
@@ -28,29 +28,29 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public function handle(Request $request) |
30 | 30 | { |
31 | - $err = function ($msg) { |
|
32 | - $error = new MessageBag([ |
|
31 | + $err=function($msg) { |
|
32 | + $error=new MessageBag([ |
|
33 | 33 | 'title' => 'POEM parse failed.', |
34 | 34 | 'message' => $msg, |
35 | 35 | ]); |
36 | 36 | return back()->with(compact('error')); |
37 | 37 | }; |
38 | - $success_message = ''; |
|
38 | + $success_message=''; |
|
39 | 39 | |
40 | - $file = $request->file('Files'); |
|
41 | - if(!$file->isValid()){ |
|
40 | + $file=$request->file('Files'); |
|
41 | + if (!$file->isValid()) { |
|
42 | 42 | $err('Invalid POEM files'); |
43 | 43 | } |
44 | 44 | |
45 | - $path = $file->getRealPath(); |
|
46 | - $poetryRaw = file_get_contents($path); |
|
47 | - $parser = new POEMParser(); |
|
48 | - $poem = $parser->parse($poetryRaw); |
|
49 | - if(empty($poem)){ |
|
45 | + $path=$file->getRealPath(); |
|
46 | + $poetryRaw=file_get_contents($path); |
|
47 | + $parser=new POEMParser(); |
|
48 | + $poem=$parser->parse($poetryRaw); |
|
49 | + if (empty($poem)) { |
|
50 | 50 | $err('Malformed POEM files'); |
51 | 51 | } |
52 | 52 | |
53 | - $success_message .= " |
|
53 | + $success_message.=" |
|
54 | 54 | POEM standard : {$poem['standard']} <br /> |
55 | 55 | generator : {$poem['generator']} <br /> |
56 | 56 | url : {$poem['url']} <br /> |
@@ -58,31 +58,31 @@ discard block |
||
58 | 58 | problems: <br /> |
59 | 59 | "; |
60 | 60 | |
61 | - $memory_unit = [ |
|
61 | + $memory_unit=[ |
|
62 | 62 | 'kb' => 1, |
63 | 63 | 'mb' => 1024, |
64 | - 'gb' => 1024*1024 |
|
64 | + 'gb' => 1024 * 1024 |
|
65 | 65 | ]; |
66 | - $time_unit = [ |
|
66 | + $time_unit=[ |
|
67 | 67 | 'ms' => 1, |
68 | 68 | 's' => 1000, |
69 | 69 | 'm' => 60000, |
70 | 70 | 'h' => 3600000 |
71 | 71 | ]; |
72 | 72 | |
73 | - $prefix = 'NOJ'; |
|
74 | - $p = ProblemModel::where('pcode','like',$prefix.'%')->orderBy('pcode','desc')->select('pcode')->first(); |
|
75 | - if(empty($p)){ |
|
76 | - $count = 1000; |
|
77 | - }else{ |
|
78 | - $count = (int) str_replace($prefix,'',$p['pcode']); |
|
73 | + $prefix='NOJ'; |
|
74 | + $p=ProblemModel::where('pcode', 'like', $prefix.'%')->orderBy('pcode', 'desc')->select('pcode')->first(); |
|
75 | + if (empty($p)) { |
|
76 | + $count=1000; |
|
77 | + } else { |
|
78 | + $count=(int) str_replace($prefix, '', $p['pcode']); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | foreach ($poem['problems'] as $problem) { |
82 | 82 | //insert problem |
83 | - $title = $problem['title']; |
|
84 | - $pro = [ |
|
85 | - 'pcode' => $prefix . (++$count), |
|
83 | + $title=$problem['title']; |
|
84 | + $pro=[ |
|
85 | + 'pcode' => $prefix.(++$count), |
|
86 | 86 | 'solved_count' => 0, |
87 | 87 | 'difficulty' => -1, |
88 | 88 | 'file' => 0, |
@@ -101,49 +101,49 @@ discard block |
||
101 | 101 | 'force_raw' => $problem['extra']['forceRaw'], |
102 | 102 | 'partial' => $problem['extra']['partial'] |
103 | 103 | ]; |
104 | - $pid = ProblemModel::insertGetId($pro); |
|
104 | + $pid=ProblemModel::insertGetId($pro); |
|
105 | 105 | |
106 | 106 | //migrate sample |
107 | - $sample_count = 0; |
|
108 | - foreach($problem['sample'] as $sample){ |
|
109 | - $sam = [ |
|
107 | + $sample_count=0; |
|
108 | + foreach ($problem['sample'] as $sample) { |
|
109 | + $sam=[ |
|
110 | 110 | 'pid' => $pid, |
111 | 111 | 'sample_input' => $sample['input'], |
112 | 112 | 'sample_output' => $sample['output'], |
113 | 113 | ]; |
114 | - $psid = DB::table('problem_sample')->insert($sam); |
|
115 | - $sample_count += 1; |
|
114 | + $psid=DB::table('problem_sample')->insert($sam); |
|
115 | + $sample_count+=1; |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | //create test case file |
119 | - if(Storage::exists(storage_path().'/test_case/'.$pro['pcode'])){ |
|
119 | + if (Storage::exists(storage_path().'/test_case/'.$pro['pcode'])) { |
|
120 | 120 | Storage::deleteDirectory(storage_path().'/test_case/'.$pro['pcode']); |
121 | 121 | } |
122 | 122 | Storage::makeDirectory(storage_path().'/test_case/'.$pro['pcode']); |
123 | - $test_case_count = 0; |
|
124 | - $test_case_info = [ |
|
123 | + $test_case_count=0; |
|
124 | + $test_case_info=[ |
|
125 | 125 | 'spj' => false, |
126 | 126 | 'test_cases' => [] |
127 | 127 | ]; |
128 | - foreach($problem['testCases'] as $test_case){ |
|
129 | - $test_case_count += 1; |
|
130 | - $test_case_arr = [ |
|
128 | + foreach ($problem['testCases'] as $test_case) { |
|
129 | + $test_case_count+=1; |
|
130 | + $test_case_arr=[ |
|
131 | 131 | 'input_name' => "data{$test_case_count}.in", |
132 | 132 | 'output_name' => "data{$test_case_count}.out", |
133 | 133 | 'input_size' => strlen($test_case['input']), |
134 | 134 | 'output_size' => strlen($test_case['output']), |
135 | 135 | 'stripped_output_md5' => md5(trim($test_case['output'])) |
136 | 136 | ]; |
137 | - array_push($test_case_info['test_cases'],$test_case_arr); |
|
137 | + array_push($test_case_info['test_cases'], $test_case_arr); |
|
138 | 138 | Storage::disk('test_case')->put('/'.$pro['pcode'].'/'.$test_case_arr['input_name'], $test_case['input']); |
139 | 139 | Storage::disk('test_case')->put('/'.$pro['pcode'].'/'.$test_case_arr['output_name'], $test_case['output']); |
140 | 140 | } |
141 | 141 | Storage::disk('test_case')->put('/'.$pro['pcode'].'/info', json_encode($test_case_info)); |
142 | 142 | |
143 | 143 | //migrate solutions |
144 | - $solution_count = 0; |
|
145 | - foreach($problem['solution'] as $solution) { |
|
146 | - $s = [ |
|
144 | + $solution_count=0; |
|
145 | + foreach ($problem['solution'] as $solution) { |
|
146 | + $s=[ |
|
147 | 147 | 'uid' => 1, |
148 | 148 | 'pid' => $pid, |
149 | 149 | 'content' => '``` '.$solution['source'], |
@@ -152,10 +152,10 @@ discard block |
||
152 | 152 | 'created_at' => date('Y-m-d H:i:s') |
153 | 153 | ]; |
154 | 154 | DB::table('problem_solution')->insert($s); |
155 | - $solution_count += 1; |
|
155 | + $solution_count+=1; |
|
156 | 156 | } |
157 | 157 | |
158 | - $success_message .= ' '. |
|
158 | + $success_message.=' '. |
|
159 | 159 | $pro['pcode'].': " |
160 | 160 | '.$title.'" with |
161 | 161 | '.$sample_count.' samples, |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | '.$solution_count.' solutions |
164 | 164 | <br />'; |
165 | 165 | } |
166 | - admin_success('Import successfully',$success_message); |
|
166 | + admin_success('Import successfully', $success_message); |
|
167 | 167 | return back(); |
168 | 168 | } |
169 | 169 |
@@ -74,7 +74,7 @@ |
||
74 | 74 | $p = ProblemModel::where('pcode','like',$prefix.'%')->orderBy('pcode','desc')->select('pcode')->first(); |
75 | 75 | if(empty($p)){ |
76 | 76 | $count = 1000; |
77 | - }else{ |
|
77 | + } else{ |
|
78 | 78 | $count = (int) str_replace($prefix,'',$p['pcode']); |
79 | 79 | } |
80 | 80 |
@@ -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 | } |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | public function details($gcode) |
122 | 122 | { |
123 | 123 | $basic_info=DB::table($this->tableName)->where(["gcode"=>$gcode])->first(); |
124 | - if(empty($basic_info)) return []; |
|
124 | + if (empty($basic_info)) return []; |
|
125 | 125 | $basic_info["members"]=$this->countGroupMembers($basic_info["gid"]); |
126 | 126 | $basic_info["tags"]=$this->getGroupTags($basic_info["gid"]); |
127 | 127 | $basic_info["create_time_foramt"]=date_format(date_create($basic_info["created_at"]), 'M jS, Y'); |
@@ -138,10 +138,10 @@ discard block |
||
138 | 138 | public function userProfile($uid, $gid) |
139 | 139 | { |
140 | 140 | $info=DB::table("group_member") |
141 | - ->join('users','users.id','=','group_member.uid') |
|
141 | + ->join('users', 'users.id', '=', 'group_member.uid') |
|
142 | 142 | ->where(["gid"=>$gid, "uid"=>$uid]) |
143 | 143 | ->where("role", ">", 0) |
144 | - ->select('avatar','describes','email','gid','uid','name','nick_name','professional_rate','role','sub_group') |
|
144 | + ->select('avatar', 'describes', 'email', 'gid', 'uid', 'name', 'nick_name', 'professional_rate', 'role', 'sub_group') |
|
145 | 145 | ->first(); |
146 | 146 | if (!empty($info)) { |
147 | 147 | $info["role_parsed"]=$this->role[$info["role"]]; |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | foreach ($user_list as &$u) { |
170 | 170 | $u["role_parsed"]=$this->role[$u["role"]]; |
171 | 171 | $u["role_color"]=$this->role_color[$u["role"]]; |
172 | - if(is_null($u["sub_group"])) $u["sub_group"]="None"; |
|
172 | + if (is_null($u["sub_group"])) $u["sub_group"]="None"; |
|
173 | 173 | } |
174 | 174 | return $user_list; |
175 | 175 | } |
@@ -230,16 +230,16 @@ discard block |
||
230 | 230 | ])->where("role", ">", 0)->count(); |
231 | 231 | } |
232 | 232 | |
233 | - public function problemTags($gid,$pid = -1) |
|
233 | + public function problemTags($gid, $pid=-1) |
|
234 | 234 | { |
235 | - if($pid == -1){ |
|
236 | - $tags = DB::table('group_problem_tag') |
|
235 | + if ($pid==-1) { |
|
236 | + $tags=DB::table('group_problem_tag') |
|
237 | 237 | ->select('tag') |
238 | - ->where('gid',$gid) |
|
238 | + ->where('gid', $gid) |
|
239 | 239 | ->distinct() |
240 | 240 | ->get()->all(); |
241 | - }else{ |
|
242 | - $tags = DB::table('group_problem_tag') |
|
241 | + } else { |
|
242 | + $tags=DB::table('group_problem_tag') |
|
243 | 243 | ->select('tag') |
244 | 244 | ->where('gid', $gid) |
245 | 245 | ->where('pid', $pid) |
@@ -247,10 +247,10 @@ discard block |
||
247 | 247 | ->get()->all(); |
248 | 248 | } |
249 | 249 | |
250 | - $tags_arr = []; |
|
251 | - if(!empty($tags)){ |
|
250 | + $tags_arr=[]; |
|
251 | + if (!empty($tags)) { |
|
252 | 252 | foreach ($tags as $value) { |
253 | - array_push($tags_arr,$value['tag']); |
|
253 | + array_push($tags_arr, $value['tag']); |
|
254 | 254 | } |
255 | 255 | } |
256 | 256 | return $tags_arr; |
@@ -258,28 +258,28 @@ discard block |
||
258 | 258 | |
259 | 259 | public function problems($gid) |
260 | 260 | { |
261 | - $contestModel = new ContestModel(); |
|
262 | - $problems = DB::table('contest_problem') |
|
263 | - ->join('contest','contest_problem.cid', '=', 'contest.cid') |
|
264 | - ->join('problem','contest_problem.pid', '=', 'problem.pid' ) |
|
261 | + $contestModel=new ContestModel(); |
|
262 | + $problems=DB::table('contest_problem') |
|
263 | + ->join('contest', 'contest_problem.cid', '=', 'contest.cid') |
|
264 | + ->join('problem', 'contest_problem.pid', '=', 'problem.pid') |
|
265 | 265 | ->select('contest_problem.cid as cid', 'problem.pid as pid', 'pcode', 'title') |
266 | - ->where('contest.gid',$gid) |
|
267 | - ->where('contest.practice',1) |
|
268 | - ->orderBy('contest.created_at','desc') |
|
266 | + ->where('contest.gid', $gid) |
|
267 | + ->where('contest.practice', 1) |
|
268 | + ->orderBy('contest.created_at', 'desc') |
|
269 | 269 | ->distinct() |
270 | 270 | ->get()->all(); |
271 | - $user_id = Auth::user()->id; |
|
272 | - foreach($problems as $key => $value){ |
|
273 | - if($contestModel->judgeClearance($value['cid'],$user_id) != 3){ |
|
271 | + $user_id=Auth::user()->id; |
|
272 | + foreach ($problems as $key => $value) { |
|
273 | + if ($contestModel->judgeClearance($value['cid'], $user_id)!=3) { |
|
274 | 274 | unset($problems[$key]); |
275 | - }else{ |
|
276 | - $problems[$key]['tags'] = $this->problemTags($gid,$value['pid']); |
|
275 | + } else { |
|
276 | + $problems[$key]['tags']=$this->problemTags($gid, $value['pid']); |
|
277 | 277 | } |
278 | 278 | } |
279 | 279 | return $problems; |
280 | 280 | } |
281 | 281 | |
282 | - public function problemAddTag($gid,$pid,$tag) |
|
282 | + public function problemAddTag($gid, $pid, $tag) |
|
283 | 283 | { |
284 | 284 | return DB::table("group_problem_tag")->insert([ |
285 | 285 | "gid"=>$gid, |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | ]); |
289 | 289 | } |
290 | 290 | |
291 | - public function problemRemoveTag($gid,$pid,$tag) |
|
291 | + public function problemRemoveTag($gid, $pid, $tag) |
|
292 | 292 | { |
293 | 293 | return DB::table("group_problem_tag")->where([ |
294 | 294 | "gid"=>$gid, |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | public function judgeEmailClearance($gid, $email) |
334 | 334 | { |
335 | 335 | $user=DB::table("users")->where(["email"=>$email])->first(); |
336 | - if(empty($user)) return -4; |
|
336 | + if (empty($user)) return -4; |
|
337 | 337 | $ret=DB::table("group_member")->where([ |
338 | 338 | "gid"=>$gid, |
339 | 339 | "uid"=>$user["id"], |
@@ -424,20 +424,20 @@ discard block |
||
424 | 424 | |
425 | 425 | public function groupMemberPracticeContestStat($gid) |
426 | 426 | { |
427 | - $contestModel = new ContestModel(); |
|
427 | + $contestModel=new ContestModel(); |
|
428 | 428 | |
429 | - $allPracticeContest = DB::table('contest') |
|
429 | + $allPracticeContest=DB::table('contest') |
|
430 | 430 | ->where([ |
431 | 431 | 'gid' => $gid, |
432 | 432 | 'practice' => 1, |
433 | 433 | ]) |
434 | - ->select('cid','name') |
|
434 | + ->select('cid', 'name') |
|
435 | 435 | ->get()->all(); |
436 | - $user_list = $this->userList($gid); |
|
436 | + $user_list=$this->userList($gid); |
|
437 | 437 | |
438 | - $memberData = []; |
|
438 | + $memberData=[]; |
|
439 | 439 | foreach ($user_list as $u) { |
440 | - $memberData[$u['uid']] = [ |
|
440 | + $memberData[$u['uid']]=[ |
|
441 | 441 | 'name' => $u['name'], |
442 | 442 | 'nick_name' => $u['nick_name'], |
443 | 443 | 'elo' => $u['ranking'], |
@@ -448,61 +448,61 @@ discard block |
||
448 | 448 | ]; |
449 | 449 | } |
450 | 450 | foreach ($allPracticeContest as $c) { |
451 | - $contestRankRaw = $contestModel->contestRank($c['cid']); |
|
452 | - foreach($contestRankRaw as $key => $contestRank){ |
|
453 | - if(isset($contestRank['remote']) && $contestRank['remote']){ |
|
451 | + $contestRankRaw=$contestModel->contestRank($c['cid']); |
|
452 | + foreach ($contestRankRaw as $key => $contestRank) { |
|
453 | + if (isset($contestRank['remote']) && $contestRank['remote']) { |
|
454 | 454 | unset($contestRankRaw[$key]); |
455 | 455 | } |
456 | 456 | } |
457 | - $contestRank = array_values($contestRankRaw); |
|
458 | - $problemsCount = DB::table('contest_problem') |
|
459 | - ->where('cid',$c['cid']) |
|
457 | + $contestRank=array_values($contestRankRaw); |
|
458 | + $problemsCount=DB::table('contest_problem') |
|
459 | + ->where('cid', $c['cid']) |
|
460 | 460 | ->count(); |
461 | - $index = 1; |
|
462 | - $rank = 1; |
|
463 | - $last_cr = []; |
|
464 | - $last_rank = 1; |
|
461 | + $index=1; |
|
462 | + $rank=1; |
|
463 | + $last_cr=[]; |
|
464 | + $last_rank=1; |
|
465 | 465 | foreach ($contestRank as $cr) { |
466 | - $last_rank = $index; |
|
467 | - if(!empty($last_cr)){ |
|
468 | - if($cr['solved'] == $last_cr['solved'] && $cr['penalty'] == $last_cr['penalty'] ){ |
|
469 | - $rank = $last_rank; |
|
470 | - }else{ |
|
471 | - $rank = $index; |
|
472 | - $last_rank = $rank; |
|
466 | + $last_rank=$index; |
|
467 | + if (!empty($last_cr)) { |
|
468 | + if ($cr['solved']==$last_cr['solved'] && $cr['penalty']==$last_cr['penalty']) { |
|
469 | + $rank=$last_rank; |
|
470 | + } else { |
|
471 | + $rank=$index; |
|
472 | + $last_rank=$rank; |
|
473 | 473 | } |
474 | 474 | } |
475 | - if(in_array($cr['uid'],array_keys($memberData))) { |
|
476 | - $memberData[$cr['uid']]['solved_all'] += $cr['solved']; |
|
477 | - $memberData[$cr['uid']]['problem_all'] += $problemsCount; |
|
478 | - $memberData[$cr['uid']]['penalty'] += $cr['penalty']; |
|
479 | - $memberData[$cr['uid']]['contest_detial'][$c['cid']] = [ |
|
475 | + if (in_array($cr['uid'], array_keys($memberData))) { |
|
476 | + $memberData[$cr['uid']]['solved_all']+=$cr['solved']; |
|
477 | + $memberData[$cr['uid']]['problem_all']+=$problemsCount; |
|
478 | + $memberData[$cr['uid']]['penalty']+=$cr['penalty']; |
|
479 | + $memberData[$cr['uid']]['contest_detial'][$c['cid']]=[ |
|
480 | 480 | 'rank' => $rank, |
481 | 481 | 'solved' => $cr['solved'], |
482 | 482 | 'problems' => $problemsCount, |
483 | 483 | 'penalty' => $cr['penalty'] |
484 | 484 | ]; |
485 | 485 | } |
486 | - $last_cr = $cr; |
|
486 | + $last_cr=$cr; |
|
487 | 487 | $index++; |
488 | 488 | } |
489 | 489 | } |
490 | - $new_memberData = []; |
|
490 | + $new_memberData=[]; |
|
491 | 491 | foreach ($memberData as $uid => $data) { |
492 | - $contest_count = 0; |
|
493 | - $rank_sum = 0; |
|
492 | + $contest_count=0; |
|
493 | + $rank_sum=0; |
|
494 | 494 | foreach ($data['contest_detial'] as $cid => $c) { |
495 | - $rank_sum += $c['rank']; |
|
496 | - $contest_count += 1; |
|
495 | + $rank_sum+=$c['rank']; |
|
496 | + $contest_count+=1; |
|
497 | 497 | } |
498 | - $temp = $data; |
|
499 | - $temp['uid'] = $uid; |
|
500 | - if($contest_count != 0){ |
|
501 | - $temp['rank_ave'] = $rank_sum/$contest_count; |
|
498 | + $temp=$data; |
|
499 | + $temp['uid']=$uid; |
|
500 | + if ($contest_count!=0) { |
|
501 | + $temp['rank_ave']=$rank_sum / $contest_count; |
|
502 | 502 | } |
503 | - array_push($new_memberData,$temp); |
|
503 | + array_push($new_memberData, $temp); |
|
504 | 504 | } |
505 | - $ret = [ |
|
505 | + $ret=[ |
|
506 | 506 | 'contest_list' => $allPracticeContest, |
507 | 507 | 'member_data' => $new_memberData |
508 | 508 | ]; |
@@ -511,58 +511,58 @@ discard block |
||
511 | 511 | |
512 | 512 | public function groupMemberPracticeTagStat($gid) |
513 | 513 | { |
514 | - $tags = $this->problemTags($gid); |
|
515 | - $tag_problems = []; |
|
514 | + $tags=$this->problemTags($gid); |
|
515 | + $tag_problems=[]; |
|
516 | 516 | |
517 | - $user_list = $this->userList($gid); |
|
517 | + $user_list=$this->userList($gid); |
|
518 | 518 | foreach ($tags as $tag) { |
519 | - $tag_problems[$tag] = DB::table('problem') |
|
520 | - ->join('group_problem_tag','problem.pid','=','group_problem_tag.pid') |
|
519 | + $tag_problems[$tag]=DB::table('problem') |
|
520 | + ->join('group_problem_tag', 'problem.pid', '=', 'group_problem_tag.pid') |
|
521 | 521 | ->where([ |
522 | 522 | 'group_problem_tag.gid' => $gid, |
523 | 523 | 'tag' => $tag |
524 | 524 | ]) |
525 | - ->select('group_problem_tag.pid as pid','pcode','title') |
|
525 | + ->select('group_problem_tag.pid as pid', 'pcode', 'title') |
|
526 | 526 | ->get()->all(); |
527 | 527 | } |
528 | - $all_problems = []; |
|
528 | + $all_problems=[]; |
|
529 | 529 | foreach ($tag_problems as &$tag_problem_set) { |
530 | 530 | foreach ($tag_problem_set as $problem) { |
531 | - $all_problems[$problem['pid']] = $problem; |
|
531 | + $all_problems[$problem['pid']]=$problem; |
|
532 | 532 | } |
533 | - $tag_problem_set = array_column($tag_problem_set,'pid'); |
|
533 | + $tag_problem_set=array_column($tag_problem_set, 'pid'); |
|
534 | 534 | } |
535 | - $submission_data = DB::table('submission') |
|
536 | - ->whereIn('pid',array_keys($all_problems)) |
|
537 | - ->whereIn('uid',array_column($user_list,'uid')) |
|
538 | - ->where('verdict','Accepted') |
|
539 | - ->select('pid','uid') |
|
535 | + $submission_data=DB::table('submission') |
|
536 | + ->whereIn('pid', array_keys($all_problems)) |
|
537 | + ->whereIn('uid', array_column($user_list, 'uid')) |
|
538 | + ->where('verdict', 'Accepted') |
|
539 | + ->select('pid', 'uid') |
|
540 | 540 | ->get()->all(); |
541 | 541 | |
542 | - $memberData = []; |
|
542 | + $memberData=[]; |
|
543 | 543 | foreach ($user_list as $member) { |
544 | - $completion = []; |
|
545 | - foreach($tag_problems as $tag => $problems) { |
|
546 | - $completion[$tag] = []; |
|
544 | + $completion=[]; |
|
545 | + foreach ($tag_problems as $tag => $problems) { |
|
546 | + $completion[$tag]=[]; |
|
547 | 547 | foreach ($problems as $problem) { |
548 | - $is_accepted = 0; |
|
548 | + $is_accepted=0; |
|
549 | 549 | foreach ($submission_data as $sd) { |
550 | - if($sd['pid'] == $problem && $sd['uid'] == $member['uid']){ |
|
551 | - $is_accepted = 1; |
|
550 | + if ($sd['pid']==$problem && $sd['uid']==$member['uid']) { |
|
551 | + $is_accepted=1; |
|
552 | 552 | break; |
553 | 553 | } |
554 | 554 | } |
555 | - $completion[$tag][$problem] = $is_accepted; |
|
555 | + $completion[$tag][$problem]=$is_accepted; |
|
556 | 556 | } |
557 | 557 | } |
558 | - array_push($memberData,[ |
|
558 | + array_push($memberData, [ |
|
559 | 559 | 'uid' => $member['uid'], |
560 | 560 | 'name' => $member['name'], |
561 | 561 | 'nick_name' => $member['nick_name'], |
562 | 562 | 'completion' => $completion, |
563 | 563 | ]); |
564 | 564 | } |
565 | - $ret = [ |
|
565 | + $ret=[ |
|
566 | 566 | 'all_problems' => $all_problems, |
567 | 567 | 'tag_problems' => $tag_problems, |
568 | 568 | 'member_data' => $memberData |
@@ -572,10 +572,10 @@ discard block |
||
572 | 572 | |
573 | 573 | public function refreshAllElo() |
574 | 574 | { |
575 | - $result = []; |
|
576 | - $gids = DB::table('group')->select('gid','name')->get()->all(); |
|
575 | + $result=[]; |
|
576 | + $gids=DB::table('group')->select('gid', 'name')->get()->all(); |
|
577 | 577 | foreach ($gids as $gid) { |
578 | - $result[$gid['gid']] = [ |
|
578 | + $result[$gid['gid']]=[ |
|
579 | 579 | 'name' => $gid['name'], |
580 | 580 | 'result' => $this->refreshElo($gid['gid']), |
581 | 581 | ]; |
@@ -586,41 +586,41 @@ discard block |
||
586 | 586 | public function refreshElo($gid) |
587 | 587 | { |
588 | 588 | DB::table('group_rated_change_log') |
589 | - ->where('gid',$gid) |
|
589 | + ->where('gid', $gid) |
|
590 | 590 | ->delete(); |
591 | 591 | DB::table('group_member') |
592 | - ->where('gid',$gid) |
|
592 | + ->where('gid', $gid) |
|
593 | 593 | ->update([ |
594 | 594 | 'ranking' => 1500 |
595 | 595 | ]); |
596 | - $contests = DB::table('contest') |
|
596 | + $contests=DB::table('contest') |
|
597 | 597 | ->where([ |
598 | 598 | 'gid' => $gid, |
599 | 599 | 'practice' => 1 |
600 | 600 | ]) |
601 | - ->where('end_time','<',date("Y-m-d H:i:s")) |
|
602 | - ->select('cid','name') |
|
601 | + ->where('end_time', '<', date("Y-m-d H:i:s")) |
|
602 | + ->select('cid', 'name') |
|
603 | 603 | ->orderBy('end_time') |
604 | 604 | ->get()->all(); |
605 | 605 | |
606 | - if(empty($contests)) { |
|
606 | + if (empty($contests)) { |
|
607 | 607 | return []; |
608 | 608 | } |
609 | - $result = []; |
|
610 | - $contestModel = new ContestModel(); |
|
609 | + $result=[]; |
|
610 | + $contestModel=new ContestModel(); |
|
611 | 611 | foreach ($contests as $contest) { |
612 | - $judge_status = $contestModel->judgeOver($contest['cid']); |
|
613 | - if($judge_status['result'] == true){ |
|
614 | - $calc = new GroupRatingCalculator($contest['cid']); |
|
612 | + $judge_status=$contestModel->judgeOver($contest['cid']); |
|
613 | + if ($judge_status['result']==true) { |
|
614 | + $calc=new GroupRatingCalculator($contest['cid']); |
|
615 | 615 | $calc->calculate(); |
616 | 616 | $calc->storage(); |
617 | - $result[] = [ |
|
617 | + $result[]=[ |
|
618 | 618 | 'ret' => 'success', |
619 | 619 | 'cid' => $contest['cid'], |
620 | 620 | 'name' => $contest['name'] |
621 | 621 | ]; |
622 | - }else{ |
|
623 | - $result[] = [ |
|
622 | + } else { |
|
623 | + $result[]=[ |
|
624 | 624 | 'ret' => 'judging', |
625 | 625 | 'cid' => $contest['cid'], |
626 | 626 | 'name' => $contest['name'], |
@@ -632,23 +632,23 @@ discard block |
||
632 | 632 | return $result; |
633 | 633 | } |
634 | 634 | |
635 | - public function getEloChangeLog($gid,$uid) |
|
635 | + public function getEloChangeLog($gid, $uid) |
|
636 | 636 | { |
637 | - $ret = DB::table('group_rated_change_log') |
|
638 | - ->join('contest','group_rated_change_log.cid','=','contest.cid') |
|
637 | + $ret=DB::table('group_rated_change_log') |
|
638 | + ->join('contest', 'group_rated_change_log.cid', '=', 'contest.cid') |
|
639 | 639 | ->where([ |
640 | 640 | 'group_rated_change_log.gid' => $gid, |
641 | 641 | 'group_rated_change_log.uid' => $uid |
642 | 642 | ])->select('group_rated_change_log.cid as cid', 'contest.name as name', 'ranking', 'end_time') |
643 | 643 | ->orderBy('contest.end_time') |
644 | 644 | ->get()->all(); |
645 | - $begin = [ |
|
645 | + $begin=[ |
|
646 | 646 | 'cid' => -1, |
647 | 647 | 'name' => '', |
648 | 648 | 'ranking' => '1500', |
649 | - 'end_time' => date("Y-m-d H:i:s",(strtotime($ret[0]['end_time'] ?? time()) - 3600*24)), |
|
649 | + 'end_time' => date("Y-m-d H:i:s", (strtotime($ret[0]['end_time'] ?? time())-3600 * 24)), |
|
650 | 650 | ]; |
651 | - $ret = array_prepend($ret,$begin); |
|
651 | + $ret=array_prepend($ret, $begin); |
|
652 | 652 | return $ret; |
653 | 653 | } |
654 | 654 | } |
@@ -121,7 +121,9 @@ discard block |
||
121 | 121 | public function details($gcode) |
122 | 122 | { |
123 | 123 | $basic_info=DB::table($this->tableName)->where(["gcode"=>$gcode])->first(); |
124 | - if(empty($basic_info)) return []; |
|
124 | + if(empty($basic_info)) { |
|
125 | + return []; |
|
126 | + } |
|
125 | 127 | $basic_info["members"]=$this->countGroupMembers($basic_info["gid"]); |
126 | 128 | $basic_info["tags"]=$this->getGroupTags($basic_info["gid"]); |
127 | 129 | $basic_info["create_time_foramt"]=date_format(date_create($basic_info["created_at"]), 'M jS, Y'); |
@@ -169,7 +171,9 @@ discard block |
||
169 | 171 | foreach ($user_list as &$u) { |
170 | 172 | $u["role_parsed"]=$this->role[$u["role"]]; |
171 | 173 | $u["role_color"]=$this->role_color[$u["role"]]; |
172 | - if(is_null($u["sub_group"])) $u["sub_group"]="None"; |
|
174 | + if(is_null($u["sub_group"])) { |
|
175 | + $u["sub_group"]="None"; |
|
176 | + } |
|
173 | 177 | } |
174 | 178 | return $user_list; |
175 | 179 | } |
@@ -238,7 +242,7 @@ discard block |
||
238 | 242 | ->where('gid',$gid) |
239 | 243 | ->distinct() |
240 | 244 | ->get()->all(); |
241 | - }else{ |
|
245 | + } else{ |
|
242 | 246 | $tags = DB::table('group_problem_tag') |
243 | 247 | ->select('tag') |
244 | 248 | ->where('gid', $gid) |
@@ -272,7 +276,7 @@ discard block |
||
272 | 276 | foreach($problems as $key => $value){ |
273 | 277 | if($contestModel->judgeClearance($value['cid'],$user_id) != 3){ |
274 | 278 | unset($problems[$key]); |
275 | - }else{ |
|
279 | + } else{ |
|
276 | 280 | $problems[$key]['tags'] = $this->problemTags($gid,$value['pid']); |
277 | 281 | } |
278 | 282 | } |
@@ -333,7 +337,9 @@ discard block |
||
333 | 337 | public function judgeEmailClearance($gid, $email) |
334 | 338 | { |
335 | 339 | $user=DB::table("users")->where(["email"=>$email])->first(); |
336 | - if(empty($user)) return -4; |
|
340 | + if(empty($user)) { |
|
341 | + return -4; |
|
342 | + } |
|
337 | 343 | $ret=DB::table("group_member")->where([ |
338 | 344 | "gid"=>$gid, |
339 | 345 | "uid"=>$user["id"], |
@@ -467,7 +473,7 @@ discard block |
||
467 | 473 | if(!empty($last_cr)){ |
468 | 474 | if($cr['solved'] == $last_cr['solved'] && $cr['penalty'] == $last_cr['penalty'] ){ |
469 | 475 | $rank = $last_rank; |
470 | - }else{ |
|
476 | + } else{ |
|
471 | 477 | $rank = $index; |
472 | 478 | $last_rank = $rank; |
473 | 479 | } |
@@ -619,7 +625,7 @@ discard block |
||
619 | 625 | 'cid' => $contest['cid'], |
620 | 626 | 'name' => $contest['name'] |
621 | 627 | ]; |
622 | - }else{ |
|
628 | + } else{ |
|
623 | 629 | $result[] = [ |
624 | 630 | 'ret' => 'judging', |
625 | 631 | 'cid' => $contest['cid'], |
@@ -17,78 +17,78 @@ discard block |
||
17 | 17 | */ |
18 | 18 | public static function send($config) |
19 | 19 | { |
20 | - if(!empty($config['type'])){ |
|
21 | - if($config['type'] == 1) { //to a leader that member apply to join the group |
|
22 | - $messages = Message::where([ |
|
20 | + if (!empty($config['type'])) { |
|
21 | + if ($config['type']==1) { //to a leader that member apply to join the group |
|
22 | + $messages=Message::where([ |
|
23 | 23 | 'receiver' => $config['receiver'], |
24 | 24 | 'type' => $config['type'], |
25 | 25 | 'unread' => 1 |
26 | 26 | ])->get(); |
27 | - if(!empty($messages)) { |
|
28 | - foreach($messages as $message) { |
|
29 | - $data = json_decode($message->data,true); |
|
30 | - if($data['group']['gcode'] == $config['data']['group']['gcode']) { |
|
31 | - array_push($data['user'],$config['data']['user'][0]); |
|
32 | - $message->data = json_encode($data); |
|
27 | + if (!empty($messages)) { |
|
28 | + foreach ($messages as $message) { |
|
29 | + $data=json_decode($message->data, true); |
|
30 | + if ($data['group']['gcode']==$config['data']['group']['gcode']) { |
|
31 | + array_push($data['user'], $config['data']['user'][0]); |
|
32 | + $message->data=json_encode($data); |
|
33 | 33 | $message->save(); |
34 | 34 | return true; |
35 | 35 | } |
36 | 36 | } |
37 | 37 | } |
38 | - }elseif ($config['type'] == 2) { //to a leader that member agree to join the group |
|
39 | - $messages = Message::where([ |
|
38 | + }elseif ($config['type']==2) { //to a leader that member agree to join the group |
|
39 | + $messages=Message::where([ |
|
40 | 40 | 'receiver' => $config['receiver'], |
41 | 41 | 'type' => $config['type'], |
42 | 42 | 'unread' => 1 |
43 | 43 | ])->get(); |
44 | - if(!empty($messages)) { |
|
45 | - foreach($messages as $message) { |
|
46 | - $data = json_decode($message->data,true); |
|
47 | - if($data['group'] == $config['data']['group']) { |
|
48 | - array_push($data['user'],$config['data']['user'][0]); |
|
49 | - $message->data = json_encode($data); |
|
44 | + if (!empty($messages)) { |
|
45 | + foreach ($messages as $message) { |
|
46 | + $data=json_decode($message->data, true); |
|
47 | + if ($data['group']==$config['data']['group']) { |
|
48 | + array_push($data['user'], $config['data']['user'][0]); |
|
49 | + $message->data=json_encode($data); |
|
50 | 50 | $message->save(); |
51 | 51 | return true; |
52 | 52 | } |
53 | 53 | } |
54 | 54 | } |
55 | - }elseif ($config['type'] == 3) { //to a person that solution was passed |
|
56 | - $message = Message::where([ |
|
55 | + }elseif ($config['type']==3) { //to a person that solution was passed |
|
56 | + $message=Message::where([ |
|
57 | 57 | 'receiver' => $config['receiver'], |
58 | 58 | 'type' => $config['type'], |
59 | 59 | 'unread' => 1 |
60 | 60 | ])->first(); |
61 | - if(!empty($message)) { |
|
62 | - $data = json_decode($message->data,true); |
|
63 | - array_push($data,$config['data']); |
|
64 | - $message->data = json_encode($data); |
|
61 | + if (!empty($message)) { |
|
62 | + $data=json_decode($message->data, true); |
|
63 | + array_push($data, $config['data']); |
|
64 | + $message->data=json_encode($data); |
|
65 | 65 | $message->save(); |
66 | 66 | return true; |
67 | 67 | } |
68 | - }elseif ($config['type'] == 4) { //to a person that solution was blocked |
|
69 | - $message = Message::where([ |
|
68 | + }elseif ($config['type']==4) { //to a person that solution was blocked |
|
69 | + $message=Message::where([ |
|
70 | 70 | 'receiver' => $config['receiver'], |
71 | 71 | 'type' => $config['type'], |
72 | 72 | 'unread' => 1 |
73 | 73 | ])->first(); |
74 | - if(!empty($message)) { |
|
75 | - $data = json_decode($message->data,true); |
|
76 | - array_push($data,$config['data']); |
|
77 | - $message->data = json_encode($data); |
|
74 | + if (!empty($message)) { |
|
75 | + $data=json_decode($message->data, true); |
|
76 | + array_push($data, $config['data']); |
|
77 | + $message->data=json_encode($data); |
|
78 | 78 | $message->save(); |
79 | 79 | return true; |
80 | 80 | } |
81 | 81 | } |
82 | 82 | } |
83 | - $message = new Message; |
|
84 | - $message->sender = $config['sender']; |
|
85 | - $message->receiver = $config['receiver']; |
|
86 | - $message->title = $config['title']; |
|
87 | - if(isset($config['data']) && isset($config['type'])){ |
|
88 | - $message->type = $config['type'] ?? null; |
|
89 | - $message->data = json_encode($config['data']); |
|
90 | - }else{ |
|
91 | - $message->content = $config['content']; |
|
83 | + $message=new Message; |
|
84 | + $message->sender=$config['sender']; |
|
85 | + $message->receiver=$config['receiver']; |
|
86 | + $message->title=$config['title']; |
|
87 | + if (isset($config['data']) && isset($config['type'])) { |
|
88 | + $message->type=$config['type'] ?? null; |
|
89 | + $message->data=json_encode($config['data']); |
|
90 | + } else { |
|
91 | + $message->content=$config['content']; |
|
92 | 92 | } |
93 | 93 | /* |
94 | 94 | if(isset($config['reply'])){ |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | $message->reply = $config['allow_reply']; |
99 | 99 | } |
100 | 100 | */ |
101 | - $message->official = 1; |
|
101 | + $message->official=1; |
|
102 | 102 | $message->save(); |
103 | 103 | return true; |
104 | 104 | } |
@@ -132,9 +132,9 @@ discard block |
||
132 | 132 | { |
133 | 133 | |
134 | 134 | return static::with('sender_user') |
135 | - ->where('receiver',$uid) |
|
136 | - ->orderBy('unread','desc') |
|
137 | - ->orderBy('updated_at','desc') |
|
135 | + ->where('receiver', $uid) |
|
136 | + ->orderBy('unread', 'desc') |
|
137 | + ->orderBy('updated_at', 'desc') |
|
138 | 138 | ->paginate(15); |
139 | 139 | } |
140 | 140 | |
@@ -147,9 +147,9 @@ discard block |
||
147 | 147 | */ |
148 | 148 | public static function read($mid) |
149 | 149 | { |
150 | - $message = static::with('sender_user')->find($mid); |
|
151 | - if(!empty($message)){ |
|
152 | - $message->unread = 0; |
|
150 | + $message=static::with('sender_user')->find($mid); |
|
151 | + if (!empty($message)) { |
|
152 | + $message->unread=0; |
|
153 | 153 | $message->save(); |
154 | 154 | } |
155 | 155 | return $message; |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | */ |
165 | 165 | public static function allRead($uid) |
166 | 166 | { |
167 | - return static::where('receiver',$uid) |
|
167 | + return static::where('receiver', $uid) |
|
168 | 168 | ->update(['unread' => 0]); |
169 | 169 | } |
170 | 170 | |
@@ -192,20 +192,20 @@ discard block |
||
192 | 192 | */ |
193 | 193 | public static function remove($messages) |
194 | 194 | { |
195 | - $del_count = 0; |
|
196 | - if(is_array($messages)){ |
|
195 | + $del_count=0; |
|
196 | + if (is_array($messages)) { |
|
197 | 197 | foreach ($messages as $mid) { |
198 | - $message = static::find($mid); |
|
199 | - if(!empty($message)){ |
|
198 | + $message=static::find($mid); |
|
199 | + if (!empty($message)) { |
|
200 | 200 | $message->delete(); |
201 | - $del_count ++; |
|
201 | + $del_count++; |
|
202 | 202 | } |
203 | 203 | } |
204 | - }else{ |
|
205 | - $message = static::find($messages); |
|
206 | - if(!empty($message)){ |
|
204 | + } else { |
|
205 | + $message=static::find($messages); |
|
206 | + if (!empty($message)) { |
|
207 | 207 | $message->delete(); |
208 | - $del_count ++; |
|
208 | + $del_count++; |
|
209 | 209 | } |
210 | 210 | } |
211 | 211 | return $del_count; |
@@ -213,36 +213,36 @@ discard block |
||
213 | 213 | |
214 | 214 | public function getContentAttribute($value) |
215 | 215 | { |
216 | - if(!empty($this->type)){ |
|
217 | - $data = json_decode($this->data,true); |
|
218 | - $content = ''; |
|
219 | - if($this->type == 1) { |
|
220 | - foreach($data['user'] as $user) { |
|
221 | - $content .= "[{$user['name']}]({$user['url']}), "; |
|
216 | + if (!empty($this->type)) { |
|
217 | + $data=json_decode($this->data, true); |
|
218 | + $content=''; |
|
219 | + if ($this->type==1) { |
|
220 | + foreach ($data['user'] as $user) { |
|
221 | + $content.="[{$user['name']}]({$user['url']}), "; |
|
222 | 222 | } |
223 | - $content = substr($content,0,strlen($content)-2); |
|
224 | - $content .= " want to join your group [{$data['group']['name']}]({$data['group']['url']})"; |
|
223 | + $content=substr($content, 0, strlen($content)-2); |
|
224 | + $content.=" want to join your group [{$data['group']['name']}]({$data['group']['url']})"; |
|
225 | 225 | return $content; |
226 | - }elseif($this->type == 2) { |
|
227 | - foreach($data['user'] as $user) { |
|
228 | - $content .= "[{$user['name']}]({$user['url']}), "; |
|
226 | + }elseif ($this->type==2) { |
|
227 | + foreach ($data['user'] as $user) { |
|
228 | + $content.="[{$user['name']}]({$user['url']}), "; |
|
229 | 229 | } |
230 | - $content = substr($content,0,strlen($content)-2); |
|
231 | - $content .= " have agreed to join your group [{$data['group']['name']}]({$data['group']['url']})"; |
|
230 | + $content=substr($content, 0, strlen($content)-2); |
|
231 | + $content.=" have agreed to join your group [{$data['group']['name']}]({$data['group']['url']})"; |
|
232 | 232 | return $content; |
233 | 233 | } //todo |
234 | - }else{ |
|
234 | + } else { |
|
235 | 235 | return $value; |
236 | 236 | } |
237 | 237 | } |
238 | 238 | |
239 | 239 | public function sender_user() |
240 | 240 | { |
241 | - return $this->belongsTo('App\Models\Eloquent\UserModel','sender','id'); |
|
241 | + return $this->belongsTo('App\Models\Eloquent\UserModel', 'sender', 'id'); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | public function receiver_user() |
245 | 245 | { |
246 | - return $this->belongsTo('App\Models\Eloquent\UserModel','receiver','id'); |
|
246 | + return $this->belongsTo('App\Models\Eloquent\UserModel', 'receiver', 'id'); |
|
247 | 247 | } |
248 | 248 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | } |
36 | 36 | } |
37 | 37 | } |
38 | - }elseif ($config['type'] == 2) { //to a leader that member agree to join the group |
|
38 | + } elseif ($config['type'] == 2) { //to a leader that member agree to join the group |
|
39 | 39 | $messages = Message::where([ |
40 | 40 | 'receiver' => $config['receiver'], |
41 | 41 | 'type' => $config['type'], |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | } |
53 | 53 | } |
54 | 54 | } |
55 | - }elseif ($config['type'] == 3) { //to a person that solution was passed |
|
55 | + } elseif ($config['type'] == 3) { //to a person that solution was passed |
|
56 | 56 | $message = Message::where([ |
57 | 57 | 'receiver' => $config['receiver'], |
58 | 58 | 'type' => $config['type'], |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | $message->save(); |
66 | 66 | return true; |
67 | 67 | } |
68 | - }elseif ($config['type'] == 4) { //to a person that solution was blocked |
|
68 | + } elseif ($config['type'] == 4) { //to a person that solution was blocked |
|
69 | 69 | $message = Message::where([ |
70 | 70 | 'receiver' => $config['receiver'], |
71 | 71 | 'type' => $config['type'], |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | if(isset($config['data']) && isset($config['type'])){ |
88 | 88 | $message->type = $config['type'] ?? null; |
89 | 89 | $message->data = json_encode($config['data']); |
90 | - }else{ |
|
90 | + } else{ |
|
91 | 91 | $message->content = $config['content']; |
92 | 92 | } |
93 | 93 | /* |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | $del_count ++; |
202 | 202 | } |
203 | 203 | } |
204 | - }else{ |
|
204 | + } else{ |
|
205 | 205 | $message = static::find($messages); |
206 | 206 | if(!empty($message)){ |
207 | 207 | $message->delete(); |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | $content = substr($content,0,strlen($content)-2); |
224 | 224 | $content .= " want to join your group [{$data['group']['name']}]({$data['group']['url']})"; |
225 | 225 | return $content; |
226 | - }elseif($this->type == 2) { |
|
226 | + } elseif($this->type == 2) { |
|
227 | 227 | foreach($data['user'] as $user) { |
228 | 228 | $content .= "[{$user['name']}]({$user['url']}), "; |
229 | 229 | } |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | $content .= " have agreed to join your group [{$data['group']['name']}]({$data['group']['url']})"; |
232 | 232 | return $content; |
233 | 233 | } //todo |
234 | - }else{ |
|
234 | + } else{ |
|
235 | 235 | return $value; |
236 | 236 | } |
237 | 237 | } |
@@ -13,10 +13,10 @@ |
||
13 | 13 | protected $primaryKey='gmid'; |
14 | 14 | |
15 | 15 | public function user() { |
16 | - return $this->belongsTo('App\Models\Eloquent\UserModel','uid','id'); |
|
16 | + return $this->belongsTo('App\Models\Eloquent\UserModel', 'uid', 'id'); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | public function group() { |
20 | - return $this->belongsTo('App\Models\Eloquent\Group','gid','gid'); |
|
20 | + return $this->belongsTo('App\Models\Eloquent\Group', 'gid', 'gid'); |
|
21 | 21 | } |
22 | 22 | } |
@@ -9,13 +9,13 @@ |
||
9 | 9 | { |
10 | 10 | use SoftDeletes; |
11 | 11 | |
12 | - protected $fillable = ['group_id', 'abuse_id', 'reason', 'removed_at']; |
|
12 | + protected $fillable=['group_id', 'abuse_id', 'reason', 'removed_at']; |
|
13 | 13 | |
14 | 14 | public function abuse() { |
15 | 15 | return $this->belongsTo('\App\Models\Eloquent\Abuse'); |
16 | 16 | } |
17 | 17 | |
18 | 18 | public function group() { |
19 | - return $this->belongsTo('\App\Models\Eloquent\Group',null,'gid'); |
|
19 | + return $this->belongsTo('\App\Models\Eloquent\Group', null, 'gid'); |
|
20 | 20 | } |
21 | 21 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | public function canPass() |
28 | 28 | { |
29 | 29 | $tot=0; |
30 | - foreach($this->problems->sortBy('order') as $problem){ |
|
30 | + foreach ($this->problems->sortBy('order') as $problem) { |
|
31 | 31 | $problem=$problem->problem; |
32 | 32 | $tot+=$problem->problem_status['color']=='wemd-green-text'; |
33 | 33 | } |
@@ -41,11 +41,11 @@ discard block |
||
41 | 41 | |
42 | 42 | public function getAvailabilityAttribute() |
43 | 43 | { |
44 | - foreach(explode(',', $this->precondition) as $dojo_id){ |
|
45 | - if(blank($dojo_id)) continue; |
|
46 | - if(!DojoPass::isPassed($dojo_id)) return 'locked'; |
|
44 | + foreach (explode(',', $this->precondition) as $dojo_id) { |
|
45 | + if (blank($dojo_id)) continue; |
|
46 | + if (!DojoPass::isPassed($dojo_id)) return 'locked'; |
|
47 | 47 | } |
48 | - return $this->passed?'passed':'available'; |
|
48 | + return $this->passed ? 'passed' : 'available'; |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | } |
@@ -42,8 +42,12 @@ |
||
42 | 42 | public function getAvailabilityAttribute() |
43 | 43 | { |
44 | 44 | foreach(explode(',', $this->precondition) as $dojo_id){ |
45 | - if(blank($dojo_id)) continue; |
|
46 | - if(!DojoPass::isPassed($dojo_id)) return 'locked'; |
|
45 | + if(blank($dojo_id)) { |
|
46 | + continue; |
|
47 | + } |
|
48 | + if(!DojoPass::isPassed($dojo_id)) { |
|
49 | + return 'locked'; |
|
50 | + } |
|
47 | 51 | } |
48 | 52 | return $this->passed?'passed':'available'; |
49 | 53 | } |
@@ -26,9 +26,9 @@ |
||
26 | 26 | |
27 | 27 | public static function isPassed($dojo_id) |
28 | 28 | { |
29 | - return Auth::check()?self::where([ |
|
29 | + return Auth::check() ?self::where([ |
|
30 | 30 | "dojo_id"=>$dojo_id, |
31 | 31 | "user_id"=>Auth::user()->id, |
32 | - ])->count()>0:false; |
|
32 | + ])->count()>0 : false; |
|
33 | 33 | } |
34 | 34 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | |
11 | 11 | public function members() |
12 | 12 | { |
13 | - return $this->hasMany('App\Models\Eloquent\GroupMember', 'gid','gid'); |
|
13 | + return $this->hasMany('App\Models\Eloquent\GroupMember', 'gid', 'gid'); |
|
14 | 14 | } |
15 | 15 | |
16 | 16 | public function banneds() |
@@ -20,11 +20,11 @@ discard block |
||
20 | 20 | |
21 | 21 | public function getLeaderAttribute() |
22 | 22 | { |
23 | - return $this->members()->where('role',3)->first()->user; |
|
23 | + return $this->members()->where('role', 3)->first()->user; |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | public function getLinkAttribute() |
27 | 27 | { |
28 | - return route('group.detail',['gcode' => $this->gcode]); |
|
28 | + return route('group.detail', ['gcode' => $this->gcode]); |
|
29 | 29 | } |
30 | 30 | } |