@@ -65,7 +65,7 @@ |
||
65 | 65 | { |
66 | 66 | $problem=new ProblemModel(); |
67 | 67 | $prob_detail=$problem->detail($pcode); |
68 | - if(blank($prob_detail) || $problem->isHidden($prob_detail["pid"])) { |
|
68 | + if (blank($prob_detail) || $problem->isHidden($prob_detail["pid"])) { |
|
69 | 69 | return redirect("/problem"); |
70 | 70 | } |
71 | 71 | if ($problem->isBlocked($prob_detail["pid"])) { |
@@ -214,14 +214,14 @@ |
||
214 | 214 | }); |
215 | 215 | }); |
216 | 216 | |
217 | - $form->saving(function (Form $form) { |
|
218 | - if($form->public) { |
|
219 | - $form->practice = 0; |
|
217 | + $form->saving(function(Form $form) { |
|
218 | + if ($form->public) { |
|
219 | + $form->practice=0; |
|
220 | 220 | } else { |
221 | - $form->verified = 0; |
|
222 | - $form->rated = 0; |
|
223 | - $form->anticheated = 0; |
|
224 | - $form->featured = 0; |
|
221 | + $form->verified=0; |
|
222 | + $form->rated=0; |
|
223 | + $form->anticheated=0; |
|
224 | + $form->featured=0; |
|
225 | 225 | } |
226 | 226 | }); |
227 | 227 |
@@ -321,9 +321,9 @@ discard block |
||
321 | 321 | public function createHomework(Request $request) |
322 | 322 | { |
323 | 323 | try { |
324 | - $all = $request->all(); |
|
325 | - $all['currently_at'] = strtotime('now'); |
|
326 | - $validator = Validator::make($all, [ |
|
324 | + $all=$request->all(); |
|
325 | + $all['currently_at']=strtotime('now'); |
|
326 | + $validator=Validator::make($all, [ |
|
327 | 327 | 'title' => 'required|string|min:1|max:100', |
328 | 328 | 'description' => 'required|string|min:1|max:65535', |
329 | 329 | 'ended_at' => 'required|date|after:currently_at', |
@@ -342,29 +342,29 @@ discard block |
||
342 | 342 | throw new Exception($validator->errors()->first()); |
343 | 343 | } |
344 | 344 | |
345 | - if (count($request->problems) > 26) { |
|
345 | + if (count($request->problems)>26) { |
|
346 | 346 | throw new Exception('Please include no more than 26 problems.'); |
347 | 347 | } |
348 | 348 | |
349 | - if (count($request->problems) < 1) { |
|
349 | + if (count($request->problems)<1) { |
|
350 | 350 | throw new Exception('Please include at least one problem.'); |
351 | 351 | } |
352 | 352 | |
353 | - $proceedProblems = $request->problems; |
|
354 | - $proceedProblemCodes = []; |
|
353 | + $proceedProblems=$request->problems; |
|
354 | + $proceedProblemCodes=[]; |
|
355 | 355 | |
356 | 356 | foreach ($proceedProblems as &$problem) { |
357 | 357 | if (!is_array($problem)) { |
358 | 358 | throw new Exception('Each problem object must be an array.'); |
359 | 359 | } |
360 | 360 | |
361 | - $problem['pcode'] = mb_strtoupper(trim($problem['pcode'])); |
|
361 | + $problem['pcode']=mb_strtoupper(trim($problem['pcode'])); |
|
362 | 362 | |
363 | - if(array_search($problem['pcode'], $proceedProblemCodes) !== false) { |
|
363 | + if (array_search($problem['pcode'], $proceedProblemCodes)!==false) { |
|
364 | 364 | throw new Exception("Duplicate Problem"); |
365 | 365 | } |
366 | 366 | |
367 | - $validator = Validator::make($problem, [ |
|
367 | + $validator=Validator::make($problem, [ |
|
368 | 368 | 'pcode' => 'required|string|min:1|max:100', |
369 | 369 | // 'alias' => 'required|string|min:0|max:100|nullable', |
370 | 370 | // 'points' => 'required|integer|gte:1', |
@@ -378,17 +378,17 @@ discard block |
||
378 | 378 | throw new Exception($validator->errors()->first()); |
379 | 379 | } |
380 | 380 | |
381 | - $proceedProblemCodes[] = $problem['pcode']; |
|
381 | + $proceedProblemCodes[]=$problem['pcode']; |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | unset($problem); |
385 | 385 | |
386 | - $problemsDict = Problem::whereIn('pcode', $proceedProblemCodes)->select('pid', 'pcode')->get()->pluck('pid', 'pcode'); |
|
386 | + $problemsDict=Problem::whereIn('pcode', $proceedProblemCodes)->select('pid', 'pcode')->get()->pluck('pid', 'pcode'); |
|
387 | 387 | |
388 | 388 | try { |
389 | - foreach($proceedProblems as &$proceedProblem) { |
|
390 | - $proceedProblem['pid'] = $problemsDict[$proceedProblem['pcode']]; |
|
391 | - if(blank($proceedProblem['pid'])) { |
|
389 | + foreach ($proceedProblems as &$proceedProblem) { |
|
390 | + $proceedProblem['pid']=$problemsDict[$proceedProblem['pcode']]; |
|
391 | + if (blank($proceedProblem['pid'])) { |
|
392 | 392 | throw new Exception(); |
393 | 393 | } |
394 | 394 | } |
@@ -407,14 +407,14 @@ discard block |
||
407 | 407 | ], 422); |
408 | 408 | } |
409 | 409 | |
410 | - $groupModel = new GroupModel(); |
|
411 | - $clearance = $groupModel->judgeClearance($request->gid, Auth::user()->id); |
|
412 | - if ($clearance < 2) { |
|
410 | + $groupModel=new GroupModel(); |
|
411 | + $clearance=$groupModel->judgeClearance($request->gid, Auth::user()->id); |
|
412 | + if ($clearance<2) { |
|
413 | 413 | return ResponseModel::err(2001); |
414 | 414 | } |
415 | 415 | |
416 | 416 | try { |
417 | - $homeworkInstance = Group::find($request->gid)->addHomework($request->title, $request->description, Carbon::parse($request->ended_at), $proceedProblems); |
|
417 | + $homeworkInstance=Group::find($request->gid)->addHomework($request->title, $request->description, Carbon::parse($request->ended_at), $proceedProblems); |
|
418 | 418 | } catch (Exception $e) { |
419 | 419 | return ResponseModel::err(7009); |
420 | 420 | } |
@@ -33,17 +33,17 @@ discard block |
||
33 | 33 | |
34 | 34 | public function getStatisticsAttribute() |
35 | 35 | { |
36 | - $cachedStatistics = Cache::tags(['homework', 'statistics'])->get($this->id); |
|
36 | + $cachedStatistics=Cache::tags(['homework', 'statistics'])->get($this->id); |
|
37 | 37 | |
38 | 38 | if (blank($cachedStatistics)) { |
39 | - $cachedStatistics = $this->cacheStatistics(); |
|
39 | + $cachedStatistics=$this->cacheStatistics(); |
|
40 | 40 | } |
41 | 41 | |
42 | - if ($cachedStatistics === false) { |
|
42 | + if ($cachedStatistics===false) { |
|
43 | 43 | return null; |
44 | 44 | } |
45 | 45 | |
46 | - $cachedStatistics['timestamp'] = Carbon::createFromTimestamp($cachedStatistics['timestamp']); |
|
46 | + $cachedStatistics['timestamp']=Carbon::createFromTimestamp($cachedStatistics['timestamp']); |
|
47 | 47 | |
48 | 48 | return $cachedStatistics; |
49 | 49 | } |
@@ -51,25 +51,25 @@ discard block |
||
51 | 51 | public function cacheStatistics() |
52 | 52 | { |
53 | 53 | try { |
54 | - $statistics = []; |
|
55 | - $homeworkProblems = $this->problems->sortBy('order_index'); |
|
56 | - $users = $this->group->members()->where('role', '>=', 1)->get(); |
|
57 | - $userIDArr = $users->pluck('uid'); |
|
58 | - $defaultVerdict = []; |
|
54 | + $statistics=[]; |
|
55 | + $homeworkProblems=$this->problems->sortBy('order_index'); |
|
56 | + $users=$this->group->members()->where('role', '>=', 1)->get(); |
|
57 | + $userIDArr=$users->pluck('uid'); |
|
58 | + $defaultVerdict=[]; |
|
59 | 59 | |
60 | 60 | foreach ($homeworkProblems as $homeworkProblem) { |
61 | - $statistics['problems'][] = [ |
|
61 | + $statistics['problems'][]=[ |
|
62 | 62 | 'pid' => $homeworkProblem->problem_id, |
63 | 63 | 'readable_name' => $homeworkProblem->problem->readable_name, |
64 | 64 | ]; |
65 | - $defaultVerdict[$homeworkProblem->problem_id] = [ |
|
65 | + $defaultVerdict[$homeworkProblem->problem_id]=[ |
|
66 | 66 | "icon" => "checkbox-blank-circle-outline", |
67 | 67 | "color" => "wemd-grey-text" |
68 | 68 | ]; |
69 | 69 | } |
70 | 70 | |
71 | 71 | foreach ($users as $user) { |
72 | - $statistics['data'][$user->uid] = [ |
|
72 | + $statistics['data'][$user->uid]=[ |
|
73 | 73 | 'name' => $user->user->name, |
74 | 74 | 'nick_name' => blank($user->nick_name) ? null : $user->nick_name, |
75 | 75 | 'solved' => 0, |
@@ -78,44 +78,44 @@ discard block |
||
78 | 78 | ]; |
79 | 79 | } |
80 | 80 | |
81 | - $endedAt = Carbon::parse($this->ended_at); |
|
81 | + $endedAt=Carbon::parse($this->ended_at); |
|
82 | 82 | |
83 | 83 | foreach ($homeworkProblems as $homeworkProblem) { |
84 | - $userProbIDArr = []; |
|
84 | + $userProbIDArr=[]; |
|
85 | 85 | |
86 | 86 | foreach ($homeworkProblem->problem->users_latest_submission($userIDArr->diff($userProbIDArr), null, $endedAt, ['Accepted'])->get() as $acceptedRecord) { |
87 | - $statistics['data'][$acceptedRecord['uid']]['verdict'][$homeworkProblem->problem_id] = [ |
|
87 | + $statistics['data'][$acceptedRecord['uid']]['verdict'][$homeworkProblem->problem_id]=[ |
|
88 | 88 | "icon" => "checkbox-blank-circle", |
89 | 89 | "color" => $acceptedRecord['color'] |
90 | 90 | ]; |
91 | 91 | $statistics['data'][$acceptedRecord['uid']]['solved']++; |
92 | - $userProbIDArr[] = $acceptedRecord['uid']; |
|
92 | + $userProbIDArr[]=$acceptedRecord['uid']; |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | foreach ($homeworkProblem->problem->users_latest_submission($userIDArr->diff($userProbIDArr), null, $endedAt, ['Partially Accepted'])->get() as $acceptedRecord) { |
96 | - $statistics['data'][$acceptedRecord['uid']]['verdict'][$homeworkProblem->problem_id] = [ |
|
96 | + $statistics['data'][$acceptedRecord['uid']]['verdict'][$homeworkProblem->problem_id]=[ |
|
97 | 97 | "icon" => "cisco-webex", |
98 | 98 | "color" => $acceptedRecord['color'] |
99 | 99 | ]; |
100 | 100 | $statistics['data'][$acceptedRecord['uid']]['attempted']++; |
101 | - $userProbIDArr[] = $acceptedRecord['uid']; |
|
101 | + $userProbIDArr[]=$acceptedRecord['uid']; |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | foreach ($homeworkProblem->problem->users_latest_submission($userIDArr->diff($userProbIDArr), null, $endedAt)->get() as $acceptedRecord) { |
105 | - $statistics['data'][$acceptedRecord['uid']]['verdict'][$homeworkProblem->problem_id] = [ |
|
105 | + $statistics['data'][$acceptedRecord['uid']]['verdict'][$homeworkProblem->problem_id]=[ |
|
106 | 106 | "icon" => "cisco-webex", |
107 | 107 | "color" => $acceptedRecord['color'] |
108 | 108 | ]; |
109 | 109 | $statistics['data'][$acceptedRecord['uid']]['attempted']++; |
110 | - $userProbIDArr[] = $acceptedRecord['uid']; |
|
110 | + $userProbIDArr[]=$acceptedRecord['uid']; |
|
111 | 111 | } |
112 | 112 | } |
113 | 113 | |
114 | - usort($statistics['data'], function ($a, $b) { |
|
115 | - return $b["solved"] == $a["solved"] ? $b["attempted"] <=> $a["attempted"] : $b["solved"] <=> $a["solved"]; |
|
114 | + usort($statistics['data'], function($a, $b) { |
|
115 | + return $b["solved"]==$a["solved"] ? $b["attempted"] <=> $a["attempted"] : $b["solved"] <=> $a["solved"]; |
|
116 | 116 | }); |
117 | 117 | |
118 | - $statistics['timestamp'] = time(); |
|
118 | + $statistics['timestamp']=time(); |
|
119 | 119 | Cache::tags(['homework', 'statistics'])->put($this->id, $statistics, 360); |
120 | 120 | return $statistics; |
121 | 121 | } catch (Exception $e) { |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | { |
129 | 129 | DB::beginTransaction(); |
130 | 130 | try { |
131 | - foreach($this->group->members()->where('role', '>', '0')->get() as $member) { |
|
131 | + foreach ($this->group->members()->where('role', '>', '0')->get() as $member) { |
|
132 | 132 | sendMessage([ |
133 | 133 | 'sender' => config('app.official_sender'), |
134 | 134 | 'receiver' => $member->uid, |
@@ -10,23 +10,23 @@ discard block |
||
10 | 10 | { |
11 | 11 | public static function sendRankInOutOneHundredMessageToUser($config) |
12 | 12 | { |
13 | - $message = Message::where([ |
|
13 | + $message=Message::where([ |
|
14 | 14 | 'receiver' => $config['receiver'], |
15 | 15 | 'type' => $config['type'], |
16 | 16 | 'unread' => true |
17 | 17 | ])->first(); |
18 | 18 | |
19 | 19 | if (filled($message)) { |
20 | - $data = json_decode($message->data, true); |
|
21 | - $data["currentRank"] = $config['data']["currentRank"]; |
|
20 | + $data=json_decode($message->data, true); |
|
21 | + $data["currentRank"]=$config['data']["currentRank"]; |
|
22 | 22 | |
23 | - if(SiteRank::isTopOneHundred($data["currentRank"]) === SiteRank::isTopOneHundred($data["originalRank"])) { |
|
23 | + if (SiteRank::isTopOneHundred($data["currentRank"])===SiteRank::isTopOneHundred($data["originalRank"])) { |
|
24 | 24 | $message->delete(); |
25 | 25 | return true; |
26 | 26 | } |
27 | 27 | |
28 | - $message->data = json_encode($data); |
|
29 | - $message->level = $config['level']; |
|
28 | + $message->data=json_encode($data); |
|
29 | + $message->level=$config['level']; |
|
30 | 30 | $message->save(); |
31 | 31 | return true; |
32 | 32 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | |
38 | 38 | public static function formatRankInOutOneHundredMessageToUser($data) |
39 | 39 | { |
40 | - if(SiteRank::isTopOneHundred($data["currentRank"])) { |
|
40 | + if (SiteRank::isTopOneHundred($data["currentRank"])) { |
|
41 | 41 | return self::formatUniversalMessage('message.rank.up.desc', [ |
42 | 42 | 'originalRank' => SiteRank::getRankString($data['originalRank']), |
43 | 43 | 'currentRank' => SiteRank::getRankString($data['currentRank']), |
@@ -18,9 +18,9 @@ discard block |
||
18 | 18 | { |
19 | 19 | parent::boot(); |
20 | 20 | static::updating(function($model) { |
21 | - $problem = Problem::findOrFail($model->pid); |
|
22 | - if($model->original['audit'] != $model->audit) { |
|
23 | - if($model->audit == 1) { |
|
21 | + $problem=Problem::findOrFail($model->pid); |
|
22 | + if ($model->original['audit']!=$model->audit) { |
|
23 | + if ($model->audit==1) { |
|
24 | 24 | // passed |
25 | 25 | sendMessage([ |
26 | 26 | 'sender' => config('app.official_sender'), |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | ]] |
36 | 36 | ] |
37 | 37 | ]); |
38 | - } elseif($model->audit == 2) { |
|
38 | + } elseif ($model->audit==2) { |
|
39 | 39 | // declined |
40 | 40 | sendMessage([ |
41 | 41 | 'sender' => config('app.official_sender'), |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | |
13 | 13 | class SiteRank |
14 | 14 | { |
15 | - private static $professionalRanking = [ |
|
15 | + private static $professionalRanking=[ |
|
16 | 16 | "Legendary Grandmaster" => "cm-colorful-text", |
17 | 17 | "International Grandmaster" => "wemd-pink-text", |
18 | 18 | "Grandmaster" => "wemd-red-text", |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | "Newbie" => "wemd-gray-text", |
26 | 26 | ]; |
27 | 27 | |
28 | - private static $professionalRankingPer = [ |
|
28 | + private static $professionalRankingPer=[ |
|
29 | 29 | "Legendary Grandmaster" => 3000, |
30 | 30 | "International Grandmaster" => 2600, |
31 | 31 | "Grandmaster" => 2400, |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | "Newbie" => 1, |
39 | 39 | ]; |
40 | 40 | |
41 | - private static $casualRanking = [ |
|
41 | + private static $casualRanking=[ |
|
42 | 42 | "Fleet Admiral" => "cm-colorful-text", |
43 | 43 | "Admiral" => "wemd-pink-text", |
44 | 44 | "Vice Admiral" => "wemd-red-text", |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | "Recruit" => "wemd-gray-text", |
52 | 52 | ]; |
53 | 53 | |
54 | - private static $casualRankingPer = [ |
|
54 | + private static $casualRankingPer=[ |
|
55 | 55 | "Fleet Admiral" => 1, |
56 | 56 | "Admiral" => 5, |
57 | 57 | "Vice Admiral" => 10, |
@@ -82,49 +82,49 @@ discard block |
||
82 | 82 | |
83 | 83 | public static function list($num) |
84 | 84 | { |
85 | - $rankList = Cache::tags(['rank'])->get('general'); |
|
85 | + $rankList=Cache::tags(['rank'])->get('general'); |
|
86 | 86 | if (blank($rankList)) { |
87 | - $rankList = []; |
|
87 | + $rankList=[]; |
|
88 | 88 | } |
89 | - $rankList = collect($rankList)->slice(0, $num); |
|
90 | - $userIDArr = $rankList->pluck('uid'); |
|
91 | - $userInfoRaw = User::whereIntegerInRaw('id', $userIDArr)->get(); |
|
92 | - $userInfo = []; |
|
89 | + $rankList=collect($rankList)->slice(0, $num); |
|
90 | + $userIDArr=$rankList->pluck('uid'); |
|
91 | + $userInfoRaw=User::whereIntegerInRaw('id', $userIDArr)->get(); |
|
92 | + $userInfo=[]; |
|
93 | 93 | foreach ($userInfoRaw as $u) { |
94 | - $userInfo[$u->id] = $u; |
|
94 | + $userInfo[$u->id]=$u; |
|
95 | 95 | } |
96 | - return $rankList->map(function ($item) use ($userInfo) { |
|
97 | - $item["details"] = isset($userInfo[$item["uid"]]) ? $userInfo[$item["uid"]] : []; |
|
96 | + return $rankList->map(function($item) use ($userInfo) { |
|
97 | + $item["details"]=isset($userInfo[$item["uid"]]) ? $userInfo[$item["uid"]] : []; |
|
98 | 98 | return $item; |
99 | 99 | }); |
100 | 100 | } |
101 | 101 | |
102 | - private static function getRecords(Carbon $from = null) |
|
102 | + private static function getRecords(Carbon $from=null) |
|
103 | 103 | { |
104 | - $userAcceptedRecords = Submission::select("uid", DB::raw("count(distinct pid) as solved"))->where("verdict", "Accepted"); |
|
105 | - $userCommunityRecords = ProblemSolution::select("uid", DB::raw("count(distinct pid) as community"))->where("audit", 1); |
|
106 | - if(filled($from)){ |
|
107 | - $userAcceptedRecords = $userAcceptedRecords->where("submission_date", ">", $from->timestamp); |
|
108 | - $userCommunityRecords = $userCommunityRecords->where("created_at", ">", $from); |
|
104 | + $userAcceptedRecords=Submission::select("uid", DB::raw("count(distinct pid) as solved"))->where("verdict", "Accepted"); |
|
105 | + $userCommunityRecords=ProblemSolution::select("uid", DB::raw("count(distinct pid) as community"))->where("audit", 1); |
|
106 | + if (filled($from)) { |
|
107 | + $userAcceptedRecords=$userAcceptedRecords->where("submission_date", ">", $from->timestamp); |
|
108 | + $userCommunityRecords=$userCommunityRecords->where("created_at", ">", $from); |
|
109 | 109 | } |
110 | - $userAcceptedRecords = collect($userAcceptedRecords->groupBy("uid")->get()->toArray()); |
|
111 | - $userCommunityRecords = collect($userCommunityRecords->groupBy("uid")->get()->toArray()); |
|
112 | - $totUserRecords = $userAcceptedRecords->pluck('uid')->merge($userCommunityRecords->pluck('uid'))->unique(); |
|
113 | - $rankList = []; |
|
114 | - foreach($totUserRecords as $uid) { |
|
115 | - $rankList[$uid]['uid'] = $uid; |
|
116 | - $rankList[$uid]['solved'] = 0; |
|
117 | - $rankList[$uid]['community'] = 0; |
|
118 | - $rankList[$uid]['tot'] = 0; |
|
110 | + $userAcceptedRecords=collect($userAcceptedRecords->groupBy("uid")->get()->toArray()); |
|
111 | + $userCommunityRecords=collect($userCommunityRecords->groupBy("uid")->get()->toArray()); |
|
112 | + $totUserRecords=$userAcceptedRecords->pluck('uid')->merge($userCommunityRecords->pluck('uid'))->unique(); |
|
113 | + $rankList=[]; |
|
114 | + foreach ($totUserRecords as $uid) { |
|
115 | + $rankList[$uid]['uid']=$uid; |
|
116 | + $rankList[$uid]['solved']=0; |
|
117 | + $rankList[$uid]['community']=0; |
|
118 | + $rankList[$uid]['tot']=0; |
|
119 | 119 | } |
120 | - foreach($userAcceptedRecords as $userAcceptedRecord) { |
|
121 | - $rankList[$userAcceptedRecord['uid']]['solved'] = $userAcceptedRecord['solved']; |
|
120 | + foreach ($userAcceptedRecords as $userAcceptedRecord) { |
|
121 | + $rankList[$userAcceptedRecord['uid']]['solved']=$userAcceptedRecord['solved']; |
|
122 | 122 | } |
123 | - foreach($userCommunityRecords as $userCommunityRecord) { |
|
124 | - $rankList[$userCommunityRecord['uid']]['community'] = $userCommunityRecord['community']; |
|
123 | + foreach ($userCommunityRecords as $userCommunityRecord) { |
|
124 | + $rankList[$userCommunityRecord['uid']]['community']=$userCommunityRecord['community']; |
|
125 | 125 | } |
126 | - foreach($rankList as &$rankItem) { |
|
127 | - $rankItem['tot'] = $rankItem['solved'] + $rankItem['community']; |
|
126 | + foreach ($rankList as &$rankItem) { |
|
127 | + $rankItem['tot']=$rankItem['solved']+$rankItem['community']; |
|
128 | 128 | } |
129 | 129 | unset($rankItem); |
130 | 130 | return $rankList; |
@@ -132,19 +132,19 @@ discard block |
||
132 | 132 | |
133 | 133 | private static function parseCoefficient($rankList) |
134 | 134 | { |
135 | - $activityCoefficient = self::getRecords(Carbon::parse('-1 months')); |
|
136 | - $activityCoefficientDivider = collect($activityCoefficient)->max('tot'); |
|
137 | - if(blank($activityCoefficientDivider)) { |
|
138 | - $activityCoefficientDivider = 1; |
|
135 | + $activityCoefficient=self::getRecords(Carbon::parse('-1 months')); |
|
136 | + $activityCoefficientDivider=collect($activityCoefficient)->max('tot'); |
|
137 | + if (blank($activityCoefficientDivider)) { |
|
138 | + $activityCoefficientDivider=1; |
|
139 | 139 | } |
140 | 140 | foreach ($rankList as $uid => $rankItem) { |
141 | - if(isset($activityCoefficient[$uid])){ |
|
142 | - $activityTot = $activityCoefficient[$uid]['tot']; |
|
141 | + if (isset($activityCoefficient[$uid])) { |
|
142 | + $activityTot=$activityCoefficient[$uid]['tot']; |
|
143 | 143 | } else { |
144 | - $activityTot = 0; |
|
144 | + $activityTot=0; |
|
145 | 145 | } |
146 | - $rankList[$uid]["activityCoefficient"] = ($activityTot / $activityCoefficientDivider) + 0.5; |
|
147 | - $rankList[$uid]["points"] = $rankList[$uid]["tot"] * $rankList[$uid]["activityCoefficient"]; |
|
146 | + $rankList[$uid]["activityCoefficient"]=($activityTot / $activityCoefficientDivider)+0.5; |
|
147 | + $rankList[$uid]["points"]=$rankList[$uid]["tot"] * $rankList[$uid]["activityCoefficient"]; |
|
148 | 148 | } |
149 | 149 | usort($rankList, function($a, $b) { |
150 | 150 | return $b['points'] <=> $a['points']; |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | |
155 | 155 | public static function isTopOneHundred($rank) |
156 | 156 | { |
157 | - return (1 <= $rank && $rank <= 100); |
|
157 | + return (1<=$rank && $rank<=100); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | public static function getRankString($rank) |
@@ -164,12 +164,12 @@ discard block |
||
164 | 164 | |
165 | 165 | private static function sendMessage($userID, $currentRank, $originalRank) |
166 | 166 | { |
167 | - if(self::isTopOneHundred($currentRank)) { |
|
168 | - $title = __('message.rank.up.title'); |
|
169 | - $level = 1; |
|
167 | + if (self::isTopOneHundred($currentRank)) { |
|
168 | + $title=__('message.rank.up.title'); |
|
169 | + $level=1; |
|
170 | 170 | } else { |
171 | - $title = __('message.rank.down.title'); |
|
172 | - $level = 2; |
|
171 | + $title=__('message.rank.down.title'); |
|
172 | + $level=2; |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | return sendMessage([ |
@@ -187,27 +187,27 @@ discard block |
||
187 | 187 | |
188 | 188 | public static function rankList() |
189 | 189 | { |
190 | - $originalRankList = self::list(100); |
|
190 | + $originalRankList=self::list(100); |
|
191 | 191 | Cache::tags(['rank'])->flush(); |
192 | - $rankList = self::getRecords(); |
|
193 | - $totUsers = count($rankList); |
|
194 | - if ($totUsers > 0) { |
|
192 | + $rankList=self::getRecords(); |
|
193 | + $totUsers=count($rankList); |
|
194 | + if ($totUsers>0) { |
|
195 | 195 | // $rankList = DB::select("SELECT *,solvedCount+communityCount as totValue, 1 as activityCoefficient FROM (SELECT uid,sum(solvedCount) as solvedCount,sum(communityCount) as communityCount FROM ((SELECT uid,count(DISTINCT submission.pid) as solvedCount,0 as communityCount from submission where verdict=\"Accepted\" group by uid) UNION (SELECT uid,0 as solvedCount,count(DISTINCT pid) from problem_solution where audit=1 group by uid)) as temp GROUP BY uid) as temp2 ORDER BY solvedCount+communityCount DESC"); |
196 | - $rankList = self::parseCoefficient($rankList); |
|
197 | - $rankIter = 1; |
|
198 | - $rankValue = 1; |
|
199 | - $rankSolved = -1; |
|
200 | - $rankListCached = []; |
|
196 | + $rankList=self::parseCoefficient($rankList); |
|
197 | + $rankIter=1; |
|
198 | + $rankValue=1; |
|
199 | + $rankSolved=-1; |
|
200 | + $rankListCached=[]; |
|
201 | 201 | self::procRankingPer($totUsers); |
202 | 202 | foreach ($rankList as $rankItem) { |
203 | - if ($rankSolved != $rankItem["points"]) { |
|
204 | - $rankValue = $rankIter; |
|
205 | - $rankSolved = $rankItem["points"]; |
|
203 | + if ($rankSolved!=$rankItem["points"]) { |
|
204 | + $rankValue=$rankIter; |
|
205 | + $rankSolved=$rankItem["points"]; |
|
206 | 206 | } |
207 | - $rankTitle = self::getRankTitle($rankValue); |
|
207 | + $rankTitle=self::getRankTitle($rankValue); |
|
208 | 208 | Cache::tags(['rank', $rankItem["uid"]])->put("rank", $rankValue, 86400); |
209 | 209 | Cache::tags(['rank', $rankItem["uid"]])->put("title", $rankTitle, 86400); |
210 | - $rankListCached[] = [ |
|
210 | + $rankListCached[]=[ |
|
211 | 211 | "uid" => $rankItem["uid"], |
212 | 212 | "rank" => $rankValue, |
213 | 213 | "title" => $rankTitle, |
@@ -219,36 +219,36 @@ discard block |
||
219 | 219 | $rankIter++; |
220 | 220 | } |
221 | 221 | Cache::tags(['rank'])->put("general", $rankListCached, 86400); |
222 | - $currentRankList = self::list(100); |
|
222 | + $currentRankList=self::list(100); |
|
223 | 223 | self::sendRankUpDownMessage($originalRankList, $currentRankList); |
224 | 224 | } |
225 | 225 | } |
226 | 226 | |
227 | 227 | private static function sendRankUpDownMessage($originalRankList, $currentRankList) |
228 | 228 | { |
229 | - if(blank($originalRankList) || blank($currentRankList)) { |
|
229 | + if (blank($originalRankList) || blank($currentRankList)) { |
|
230 | 230 | return; |
231 | 231 | } |
232 | 232 | |
233 | - $originalRankUID = []; |
|
234 | - foreach($originalRankList as $originalRankItem) { |
|
235 | - $originalRankUID[] = $originalRankItem['uid']; |
|
233 | + $originalRankUID=[]; |
|
234 | + foreach ($originalRankList as $originalRankItem) { |
|
235 | + $originalRankUID[]=$originalRankItem['uid']; |
|
236 | 236 | } |
237 | 237 | |
238 | - $currentRankUID = []; |
|
239 | - foreach($currentRankList as $currentRankItem) { |
|
240 | - $currentRankUID[] = $currentRankItem['uid']; |
|
238 | + $currentRankUID=[]; |
|
239 | + foreach ($currentRankList as $currentRankItem) { |
|
240 | + $currentRankUID[]=$currentRankItem['uid']; |
|
241 | 241 | } |
242 | 242 | |
243 | - foreach($originalRankList as $originalRankItem) { |
|
244 | - if(in_array($originalRankItem['uid'], $currentRankUID)) { |
|
243 | + foreach ($originalRankList as $originalRankItem) { |
|
244 | + if (in_array($originalRankItem['uid'], $currentRankUID)) { |
|
245 | 245 | continue; |
246 | 246 | } |
247 | 247 | self::sendMessage($originalRankItem['uid'], Cache::tags(['rank', $originalRankItem['uid']])->get("rank", null), $originalRankItem['rank']); |
248 | 248 | } |
249 | 249 | |
250 | - foreach($currentRankList as $currentRankItem) { |
|
251 | - if(in_array($currentRankItem['uid'], $originalRankUID)) { |
|
250 | + foreach ($currentRankList as $currentRankItem) { |
|
251 | + if (in_array($currentRankItem['uid'], $originalRankUID)) { |
|
252 | 252 | continue; |
253 | 253 | } |
254 | 254 | self::sendMessage($currentRankItem['uid'], $currentRankItem['rank'], null); |
@@ -257,14 +257,14 @@ discard block |
||
257 | 257 | |
258 | 258 | public static function getProfessionalRanking() |
259 | 259 | { |
260 | - $professionalRankList = []; |
|
261 | - $verifiedUsers = User::all(); |
|
262 | - $rankIter = 0; |
|
260 | + $professionalRankList=[]; |
|
261 | + $verifiedUsers=User::all(); |
|
262 | + $rankIter=0; |
|
263 | 263 | foreach ($verifiedUsers as $user) { |
264 | - $rankVal = $user->professional_rate; |
|
265 | - $rankTitle = self::getProfessionalTitle($rankVal); |
|
266 | - $titleColor = self::getProfessionalColor($rankTitle); |
|
267 | - $professionalRankList[$rankIter++] = [ |
|
264 | + $rankVal=$user->professional_rate; |
|
265 | + $rankTitle=self::getProfessionalTitle($rankVal); |
|
266 | + $titleColor=self::getProfessionalColor($rankTitle); |
|
267 | + $professionalRankList[$rankIter++]=[ |
|
268 | 268 | "name" => $user->name, |
269 | 269 | "uid" => $user->id, |
270 | 270 | "avatar" => $user->avatar, |
@@ -278,18 +278,18 @@ discard block |
||
278 | 278 | |
279 | 279 | private static function procRankingPer($totUsers) |
280 | 280 | { |
281 | - if ($totUsers > 0) { |
|
282 | - $tot = 0; |
|
283 | - $cur = 0; |
|
281 | + if ($totUsers>0) { |
|
282 | + $tot=0; |
|
283 | + $cur=0; |
|
284 | 284 | foreach (self::$casualRankingPer as $c) { |
285 | - $tot += $c; |
|
285 | + $tot+=$c; |
|
286 | 286 | } |
287 | 287 | foreach (self::$casualRankingPer as &$c) { |
288 | - $c = round($c * $totUsers / $tot); |
|
289 | - $cur += $c; |
|
290 | - $c = $cur; |
|
288 | + $c=round($c * $totUsers / $tot); |
|
289 | + $cur+=$c; |
|
290 | + $c=$cur; |
|
291 | 291 | } |
292 | - $c = $totUsers; |
|
292 | + $c=$totUsers; |
|
293 | 293 | unset($c); |
294 | 294 | } |
295 | 295 | } |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | public static function getRankTitle($rankVal) |
298 | 298 | { |
299 | 299 | foreach (self::$casualRankingPer as $title => $c) { |
300 | - if ($rankVal <= $c) { |
|
300 | + if ($rankVal<=$c) { |
|
301 | 301 | return $title; |
302 | 302 | } |
303 | 303 | } |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | public static function getProfessionalTitle($rankVal) |
308 | 308 | { |
309 | 309 | foreach (self::$professionalRankingPer as $title => $point) { |
310 | - if ($rankVal >= $point) { |
|
310 | + if ($rankVal>=$point) { |
|
311 | 311 | return $title; |
312 | 312 | } |
313 | 313 | } |
@@ -14,11 +14,11 @@ discard block |
||
14 | 14 | { |
15 | 15 | use SoftDeletes; |
16 | 16 | |
17 | - protected $table = 'message'; |
|
17 | + protected $table='message'; |
|
18 | 18 | |
19 | - protected $with = ['sender_user', 'receiver_user']; |
|
19 | + protected $with=['sender_user', 'receiver_user']; |
|
20 | 20 | |
21 | - public $levelMapping = [ |
|
21 | + public $levelMapping=[ |
|
22 | 22 | 0 => 'default', |
23 | 23 | 1 => 'info', |
24 | 24 | 2 => 'warning', |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | public function read() |
104 | 104 | { |
105 | 105 | if ($this->unread) { |
106 | - $this->unread = false; |
|
106 | + $this->unread=false; |
|
107 | 107 | $this->save(); |
108 | 108 | } |
109 | 109 | return $this; |
@@ -147,17 +147,17 @@ discard block |
||
147 | 147 | */ |
148 | 148 | public static function remove($messages) |
149 | 149 | { |
150 | - $del_count = 0; |
|
150 | + $del_count=0; |
|
151 | 151 | if (is_array($messages)) { |
152 | 152 | foreach ($messages as $mid) { |
153 | - $message = static::find($mid); |
|
153 | + $message=static::find($mid); |
|
154 | 154 | if (filled($message)) { |
155 | 155 | $message->delete(); |
156 | 156 | $del_count++; |
157 | 157 | } |
158 | 158 | } |
159 | 159 | } else { |
160 | - $message = static::find($messages); |
|
160 | + $message=static::find($messages); |
|
161 | 161 | if (filled($message)) { |
162 | 162 | $message->delete(); |
163 | 163 | $del_count++; |
@@ -178,9 +178,9 @@ discard block |
||
178 | 178 | public function getContentAttribute($value) |
179 | 179 | { |
180 | 180 | if (filled($this->type)) { |
181 | - $data = json_decode($this->data, true); |
|
182 | - $data['receiver'] = $this->receiver_user; |
|
183 | - $data['sender'] = $this->sender_user; |
|
181 | + $data=json_decode($this->data, true); |
|
182 | + $data['receiver']=$this->receiver_user; |
|
183 | + $data['sender']=$this->sender_user; |
|
184 | 184 | |
185 | 185 | switch (intval($this->type)) { |
186 | 186 | case 1: |
@@ -7,29 +7,29 @@ |
||
7 | 7 | |
8 | 8 | class UniversalMessager |
9 | 9 | { |
10 | - public static function sendUniversalMessage($config, $official = true) |
|
10 | + public static function sendUniversalMessage($config, $official=true) |
|
11 | 11 | { |
12 | - $message = new Message; |
|
13 | - $message->sender = $config['sender']; |
|
14 | - $message->receiver = $config['receiver']; |
|
15 | - $message->title = $config['title']; |
|
16 | - $message->level = $config['level']; |
|
12 | + $message=new Message; |
|
13 | + $message->sender=$config['sender']; |
|
14 | + $message->receiver=$config['receiver']; |
|
15 | + $message->title=$config['title']; |
|
16 | + $message->level=$config['level']; |
|
17 | 17 | if (isset($config['data']) && isset($config['type'])) { |
18 | - $message->type = $config['type'] ?? null; |
|
19 | - $message->data = json_encode($config['data']); |
|
18 | + $message->type=$config['type'] ?? null; |
|
19 | + $message->data=json_encode($config['data']); |
|
20 | 20 | } else { |
21 | - $message->content = $config['content']; |
|
21 | + $message->content=$config['content']; |
|
22 | 22 | } |
23 | - $message->official = $official; |
|
23 | + $message->official=$official; |
|
24 | 24 | $message->save(); |
25 | 25 | return true; |
26 | 26 | } |
27 | 27 | |
28 | - public static function formatUniversalMessage($key = null, $replace = [], $locale = null) |
|
28 | + public static function formatUniversalMessage($key=null, $replace=[], $locale=null) |
|
29 | 29 | { |
30 | - $replace['senderName'] = $replace['sender']->name; |
|
31 | - $replace['receiverName'] = $replace['receiver']->name; |
|
32 | - $replace['siteName'] = config('app.name'); |
|
30 | + $replace['senderName']=$replace['sender']->name; |
|
31 | + $replace['receiverName']=$replace['receiver']->name; |
|
32 | + $replace['siteName']=config('app.name'); |
|
33 | 33 | return __($key, $replace, $locale); |
34 | 34 | } |
35 | 35 | } |