Passed
Pull Request — master (#244)
by Chenyi
04:13
created
app/Models/Rating/RatingCalculator.php 1 patch
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -17,14 +17,14 @@  discard block
 block discarded – undo
17 17
     public $totParticipants=0;
18 18
     public $INITIAL_RATING=1500;
19 19
 
20
-    public function __construct($cid){
20
+    public function __construct($cid) {
21 21
         $this->cid=$cid;
22 22
 
23 23
         // get rank
24 24
         $this->getRecord();
25 25
     }
26 26
 
27
-    private function getRecord(){
27
+    private function getRecord() {
28 28
         $contestRankRaw=Cache::tags(['contest', 'rank'])->get($this->cid);
29 29
 
30 30
         if ($contestRankRaw==null) {
@@ -32,8 +32,8 @@  discard block
 block discarded – undo
32 32
             $contestRankRaw=$contestModel->contestRankCache($this->cid);
33 33
         }
34 34
 
35
-        $this->totParticipants = count($contestRankRaw);
36
-        foreach($contestRankRaw as $c){
35
+        $this->totParticipants=count($contestRankRaw);
36
+        foreach ($contestRankRaw as $c) {
37 37
             $this->contestants[]=[
38 38
                 "uid"=>$c["uid"],
39 39
                 "points"=>$c["score"],
@@ -42,84 +42,84 @@  discard block
 block discarded – undo
42 42
         }
43 43
     }
44 44
 
45
-    private function reassignRank(){
45
+    private function reassignRank() {
46 46
         $this->sort("points");
47
-        $idx = 0;
48
-        $points = $this->contestants[0]["points"];
49
-        $i = 1;
50
-        while($i < $this->totParticipants){
51
-            if($this->contestants[$i]["points"] < $points){
52
-                $j = $idx;
53
-                while($j < $i){
54
-                    $this->contestants[$j]["rank"] = $i;
55
-                    $j += 1;
47
+        $idx=0;
48
+        $points=$this->contestants[0]["points"];
49
+        $i=1;
50
+        while ($i<$this->totParticipants) {
51
+            if ($this->contestants[$i]["points"]<$points) {
52
+                $j=$idx;
53
+                while ($j<$i) {
54
+                    $this->contestants[$j]["rank"]=$i;
55
+                    $j+=1;
56 56
                 }
57
-                $idx = $i;
58
-                $points = $this->contestants[$i]["points"];
57
+                $idx=$i;
58
+                $points=$this->contestants[$i]["points"];
59 59
             }
60
-            $i += 1;
60
+            $i+=1;
61 61
         }
62
-        $j = $idx;
63
-        while($j < $this->totParticipants){
64
-            $this->contestants[$j]["rank"] = $this->totParticipants;
65
-            $j += 1;
62
+        $j=$idx;
63
+        while ($j<$this->totParticipants) {
64
+            $this->contestants[$j]["rank"]=$this->totParticipants;
65
+            $j+=1;
66 66
         }
67 67
     }
68 68
 
69
-    private function getEloWinProbability($Ra, $Rb){
70
-        return 1.0 / (1 + pow(10, ($Rb-$Ra)/400.0));
69
+    private function getEloWinProbability($Ra, $Rb) {
70
+        return 1.0 / (1+pow(10, ($Rb-$Ra) / 400.0));
71 71
     }
72 72
 
73
-    private function getSeed($rating){
74
-        $result = 1.0;
75
-        foreach($this->contestants as $other){
76
-            $result += $this->getEloWinProbability($other["rating"], $rating);
73
+    private function getSeed($rating) {
74
+        $result=1.0;
75
+        foreach ($this->contestants as $other) {
76
+            $result+=$this->getEloWinProbability($other["rating"], $rating);
77 77
         }
78 78
         return $result;
79 79
     }
80 80
 
81
-    private function getRatingToRank($rank){
81
+    private function getRatingToRank($rank) {
82 82
         $left=1;
83 83
         $right=8000;
84
-        while($right - $left > 1){
85
-            $mid = floor(($right + $left)/2);
86
-            if($this->getSeed($mid) < $rank){
87
-                $right = $mid;
88
-            }else{
89
-                $left = $mid;
84
+        while ($right-$left>1) {
85
+            $mid=floor(($right+$left) / 2);
86
+            if ($this->getSeed($mid)<$rank) {
87
+                $right=$mid;
88
+            } else {
89
+                $left=$mid;
90 90
             }
91 91
         }
92 92
         return $left;
93 93
     }
94 94
 
95
-    private function sort($key){
96
-        usort($this->contestants, function ($a, $b) use ($key) {
95
+    private function sort($key) {
96
+        usort($this->contestants, function($a, $b) use ($key) {
97 97
             return $b[$key] <=> $a[$key];
98 98
         });
99 99
     }
100 100
 
101
-    public function calculate(){
102
-        if(empty($this->contestants)){
101
+    public function calculate() {
102
+        if (empty($this->contestants)) {
103 103
             return;
104 104
         }
105 105
 
106 106
         // recalc rank
107 107
         $this->reassignRank();
108 108
 
109
-        foreach($this->contestants as &$member){
110
-            $member["seed"] = 1.0;
111
-            foreach($this->contestants as $other){
112
-                if($member["uid"] != $other["uid"]){
113
-                    $member["seed"] += $this->getEloWinProbability($other["rating"], $member["rating"]);
109
+        foreach ($this->contestants as &$member) {
110
+            $member["seed"]=1.0;
111
+            foreach ($this->contestants as $other) {
112
+                if ($member["uid"]!=$other["uid"]) {
113
+                    $member["seed"]+=$this->getEloWinProbability($other["rating"], $member["rating"]);
114 114
                 }
115 115
             }
116 116
         }
117 117
         unset($member);
118 118
 
119
-        foreach($this->contestants as &$contestant){
120
-            $midRank = sqrt($contestant["rank"] * $contestant["seed"]);
121
-            $contestant["needRating"] = $this->getRatingToRank($midRank);
122
-            $contestant["delta"] = floor(($contestant["needRating"] - $contestant["rating"])/2);
119
+        foreach ($this->contestants as &$contestant) {
120
+            $midRank=sqrt($contestant["rank"] * $contestant["seed"]);
121
+            $contestant["needRating"]=$this->getRatingToRank($midRank);
122
+            $contestant["delta"]=floor(($contestant["needRating"]-$contestant["rating"]) / 2);
123 123
         }
124 124
         unset($contestant);
125 125
 
@@ -127,39 +127,39 @@  discard block
 block discarded – undo
127 127
 
128 128
         // DO some adjuct
129 129
         // Total sum should not be more than ZERO.
130
-        $sum = 0;
130
+        $sum=0;
131 131
 
132
-        foreach($this->contestants as $contestant){
133
-            $sum += $contestant["delta"];
132
+        foreach ($this->contestants as $contestant) {
133
+            $sum+=$contestant["delta"];
134 134
         }
135
-        $inc = -floor($sum / $this->totParticipants) - 1;
136
-        foreach($this->contestants as &$contestant){
137
-            $contestant["delta"] += $inc;
135
+        $inc=-floor($sum / $this->totParticipants)-1;
136
+        foreach ($this->contestants as &$contestant) {
137
+            $contestant["delta"]+=$inc;
138 138
         }
139 139
         unset($contestant);
140 140
 
141 141
         // Sum of top-4*sqrt should be adjusted to ZERO.
142 142
 
143
-        $sum = 0;
144
-        $zeroSumCount = min(intval(4*round(sqrt($this->totParticipants))), $this->totParticipants);
143
+        $sum=0;
144
+        $zeroSumCount=min(intval(4 * round(sqrt($this->totParticipants))), $this->totParticipants);
145 145
 
146
-        for($i=0;$i<$zeroSumCount;$i++){
147
-            $sum += $this->contestants[$i]["delta"];
146
+        for ($i=0; $i<$zeroSumCount; $i++) {
147
+            $sum+=$this->contestants[$i]["delta"];
148 148
         }
149 149
 
150
-        $inc = min(max(-floor($sum / $zeroSumCount), -10), 0);
150
+        $inc=min(max(-floor($sum / $zeroSumCount), -10), 0);
151 151
 
152
-        for($i=0;$i<$zeroSumCount;$i++){
153
-            $this->contestants[$i]["delta"] += $inc;
152
+        for ($i=0; $i<$zeroSumCount; $i++) {
153
+            $this->contestants[$i]["delta"]+=$inc;
154 154
         }
155 155
 
156 156
         return $this->validateDeltas();
157 157
     }
158 158
 
159
-    public function storage(){
159
+    public function storage() {
160 160
         $contestants=$this->contestants;
161
-        DB::transaction(function () use ($contestants) {
162
-            foreach($contestants as $contestant){
161
+        DB::transaction(function() use ($contestants) {
162
+            foreach ($contestants as $contestant) {
163 163
                 $newRating=$contestant["rating"]+$contestant["delta"];
164 164
                 DB::table("users")->where([
165 165
                     "id"=>$contestant["uid"]
@@ -181,20 +181,20 @@  discard block
 block discarded – undo
181 181
         }, 5);
182 182
     }
183 183
 
184
-    private function validateDeltas(){
184
+    private function validateDeltas() {
185 185
         $this->sort("points");
186 186
 
187
-        for($i=0;$i<$this->totParticipants;$i++){
188
-            for($j=$i+1;$j<$this->totParticipants;$j++){
189
-                if($this->contestants[$i]["rating"] > $this->contestants[$j]["rating"]){
190
-                    if($this->contestants[$i]["rating"] + $this->contestants[$i]["delta"] < $this->contestants[$j]["rating"] + $this->contestants[$j]["delta"]){
187
+        for ($i=0; $i<$this->totParticipants; $i++) {
188
+            for ($j=$i+1; $j<$this->totParticipants; $j++) {
189
+                if ($this->contestants[$i]["rating"]>$this->contestants[$j]["rating"]) {
190
+                    if ($this->contestants[$i]["rating"]+$this->contestants[$i]["delta"]<$this->contestants[$j]["rating"]+$this->contestants[$j]["delta"]) {
191 191
                         Log::warning("First rating invariant failed: {$this->contestants[$i]["uid"]} vs. {$this->contestants[$j]["uid"]}.");
192 192
                         return false;
193 193
                     }
194 194
                 }
195 195
 
196
-                if($this->contestants[$i]["rating"] < $this->contestants[$j]["rating"]){
197
-                    if($this->contestants[$i]["delta"] < $this->contestants[$j]["delta"]){
196
+                if ($this->contestants[$i]["rating"]<$this->contestants[$j]["rating"]) {
197
+                    if ($this->contestants[$i]["delta"]<$this->contestants[$j]["delta"]) {
198 198
                         Log::warning("Second rating invariant failed: {$this->contestants[$i]["uid"]} vs.  {$this->contestants[$j]["uid"]}.");
199 199
                         return false;
200 200
                     }
Please login to merge, or discard this patch.
app/Models/AccountModel.php 1 patch
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 
12 12
 class AccountModel extends Model
13 13
 {
14
-    private $user_extra = [
14
+    private $user_extra=[
15 15
         0     => 'gender',
16 16
         1     => 'contact',
17 17
         2     => 'school',
@@ -26,11 +26,11 @@  discard block
 block discarded – undo
26 26
         1004  => 'github_token',
27 27
     ];
28 28
 
29
-    private $socialite_support = [
29
+    private $socialite_support=[
30 30
         //use the form "platform_id" for unique authentication
31 31
         //such as github_id
32 32
         'github' => [
33
-            'email','nickname','homepage','token'
33
+            'email', 'nickname', 'homepage', 'token'
34 34
         ],
35 35
     ];
36 36
 
@@ -48,8 +48,8 @@  discard block
 block discarded – undo
48 48
     public function feed($uid=null)
49 49
     {
50 50
         $ret=[];
51
-        $solution=DB::table("problem_solution")->join("problem","problem.pid","=","problem_solution.pid")->where(["uid"=>$uid,"audit"=>1])->select("problem.pid as pid","pcode","title","problem_solution.created_at as created_at")->orderBy("problem_solution.created_at","DESC")->get()->all();
52
-        foreach($solution as &$s){
51
+        $solution=DB::table("problem_solution")->join("problem", "problem.pid", "=", "problem_solution.pid")->where(["uid"=>$uid, "audit"=>1])->select("problem.pid as pid", "pcode", "title", "problem_solution.created_at as created_at")->orderBy("problem_solution.created_at", "DESC")->get()->all();
52
+        foreach ($solution as &$s) {
53 53
             $s["type"]="event";
54 54
             $s["color"]="wemd-orange";
55 55
             $s["icon"]="comment-check-outline";
@@ -120,14 +120,14 @@  discard block
 block discarded – undo
120 120
         ])->join("problem", "problem.pid", "=", "submission.pid")->select('pcode')->distinct()->get()->all();
121 121
         $ret["solvedCount"]=count($ret["solved"]);
122 122
         // Casual
123
-        $ret["rank"]=Cache::tags(['rank',$ret["id"]])->get("rank", "N/A");
124
-        $ret["rankTitle"]=Cache::tags(['rank',$ret["id"]])->get("title");
123
+        $ret["rank"]=Cache::tags(['rank', $ret["id"]])->get("rank", "N/A");
124
+        $ret["rankTitle"]=Cache::tags(['rank', $ret["id"]])->get("title");
125 125
         $ret["rankTitleColor"]=RankModel::getColor($ret["rankTitle"]);
126 126
         // Professional
127 127
         $ret["professionalTitle"]=RankModel::getProfessionalTitle($ret["professional_rate"]);
128 128
         $ret["professionalTitleColor"]=RankModel::getProfessionalColor($ret["professionalTitle"]);
129 129
         // Administration Group
130
-        $ret["admin"]=$uid==1?1:0;
130
+        $ret["admin"]=$uid==1 ? 1 : 0;
131 131
         if (Cache::tags(['bing', 'pic'])->get(date("Y-m-d"))==null) {
132 132
             $bing=new BingPhoto([
133 133
                 'locale' => 'zh-CN',
@@ -146,26 +146,26 @@  discard block
 block discarded – undo
146 146
      * @param string|array $need An array is returned when an array is passed in,Only one value is returned when a string is passed in.
147 147
      * @return string|array $result
148 148
      */
149
-    public function getExtra($uid,$need, $secret_level = 0){
150
-        $ret = DB::table('users_extra')->where('uid',$uid)->orderBy('key')->get()->all();
151
-        $result = [];
152
-        if(!empty($ret)){
153
-            if(is_string($need)){
149
+    public function getExtra($uid, $need, $secret_level=0) {
150
+        $ret=DB::table('users_extra')->where('uid', $uid)->orderBy('key')->get()->all();
151
+        $result=[];
152
+        if (!empty($ret)) {
153
+            if (is_string($need)) {
154 154
                 foreach ($ret as $value) {
155
-                    if(empty($value['secret_level']) || $value['secret_level'] <= $secret_level){
156
-                        $key_name = $this->user_extra[$value['key']] ?? 'unknown';
157
-                        if($key_name == $need){
155
+                    if (empty($value['secret_level']) || $value['secret_level']<=$secret_level) {
156
+                        $key_name=$this->user_extra[$value['key']] ?? 'unknown';
157
+                        if ($key_name==$need) {
158 158
                             return $value['value'];
159 159
                         }
160 160
                     }
161 161
                 }
162 162
                 return null;
163
-            }else{
163
+            } else {
164 164
                 foreach ($ret as $value) {
165
-                    if(empty($value['secret_level']) || $value['secret_level'] <= $secret_level){
166
-                        $key_name = $this->user_extra[$value['key']] ?? 'unknown';
167
-                        if(in_array($key_name,$need)){
168
-                            $result[$key_name] = $value['value'];
165
+                    if (empty($value['secret_level']) || $value['secret_level']<=$secret_level) {
166
+                        $key_name=$this->user_extra[$value['key']] ?? 'unknown';
167
+                        if (in_array($key_name, $need)) {
168
+                            $result[$key_name]=$value['value'];
169 169
                         }
170 170
                     }
171 171
                 }
@@ -182,26 +182,26 @@  discard block
 block discarded – undo
182 182
      * @param string|null $value the extra info will be delete when value is null
183 183
      * @return mixed $result
184 184
      */
185
-    public function setExtra($uid,$key_name,$value = null,$secret_level = -1){
186
-        $key = array_search($key_name,$this->user_extra);
187
-        if($key === false){
185
+    public function setExtra($uid, $key_name, $value=null, $secret_level=-1) {
186
+        $key=array_search($key_name, $this->user_extra);
187
+        if ($key===false) {
188 188
             return false;
189 189
         }
190
-        $ret = DB::table('users_extra')->where('uid',$uid)->where('key',$key)->first();
191
-        if(!empty($ret)){
190
+        $ret=DB::table('users_extra')->where('uid', $uid)->where('key', $key)->first();
191
+        if (!empty($ret)) {
192 192
             unset($ret['id']);
193
-            if(!is_null($value)){
194
-                $ret['value'] = $value;
195
-            }else{
196
-                DB::table('users_extra')->where('uid',$uid)->where('key',$key)->delete();
193
+            if (!is_null($value)) {
194
+                $ret['value']=$value;
195
+            } else {
196
+                DB::table('users_extra')->where('uid', $uid)->where('key', $key)->delete();
197 197
                 return true;
198 198
             }
199
-            if($secret_level != -1){
200
-                $ret['secret_level'] = $secret_level;
199
+            if ($secret_level!=-1) {
200
+                $ret['secret_level']=$secret_level;
201 201
             }
202
-            return DB::table('users_extra')->where('uid',$uid)->where('key',$key)->update($ret);
203
-        }else{
204
-            if($value === null){
202
+            return DB::table('users_extra')->where('uid', $uid)->where('key', $key)->update($ret);
203
+        } else {
204
+            if ($value===null) {
205 205
                 return true;
206 206
             }
207 207
             return DB::table('users_extra')->insertGetId(
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
                     'uid' => $uid,
210 210
                     'key' => $key,
211 211
                     'value' => $value,
212
-                    'secret_level' => $secret_level == -1 ? 0 : $secret_level,
212
+                    'secret_level' => $secret_level==-1 ? 0 : $secret_level,
213 213
                 ]
214 214
             );
215 215
         }
@@ -221,33 +221,33 @@  discard block
 block discarded – undo
221 221
      * @param string $value the value
222 222
      * @return string $result
223 223
      */
224
-    public function findExtra($key,$value)
224
+    public function findExtra($key, $value)
225 225
     {
226
-        $key = array_search($key,$this->user_extra);
227
-        if($key){
228
-            return DB::table('users_extra')->where('key',$key)->where('value',$value)->first();
229
-        }else{
226
+        $key=array_search($key, $this->user_extra);
227
+        if ($key) {
228
+            return DB::table('users_extra')->where('key', $key)->where('value', $value)->first();
229
+        } else {
230 230
             return null;
231 231
         }
232 232
     }
233 233
 
234
-    public function getSocialiteInfo($uid,$secret_level = -1)
234
+    public function getSocialiteInfo($uid, $secret_level=-1)
235 235
     {
236
-        $socialites = [];
236
+        $socialites=[];
237 237
         foreach ($this->socialite_support as $key => $value) {
238
-            $id_keyname = $key.'_id';
239
-            $id = $this->getExtra($uid,$id_keyname);
240
-            if(!empty($id)){
241
-                $info = [
238
+            $id_keyname=$key.'_id';
239
+            $id=$this->getExtra($uid, $id_keyname);
240
+            if (!empty($id)) {
241
+                $info=[
242 242
                     'id' => $id,
243 243
                 ];
244 244
                 foreach ($value as $info_name) {
245
-                    $info_temp = $this->getExtra($uid,$key.'_'.$info_name);
246
-                    if($info_temp !== null){
247
-                        $info[$info_name] = $info_temp;
245
+                    $info_temp=$this->getExtra($uid, $key.'_'.$info_name);
246
+                    if ($info_temp!==null) {
247
+                        $info[$info_name]=$info_temp;
248 248
                     }
249 249
                 }
250
-                $socialites[$key] = $info;
250
+                $socialites[$key]=$info;
251 251
             }
252 252
         }
253 253
 
Please login to merge, or discard this patch.
app/Http/Controllers/Ajax/SearchController.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -23,34 +23,34 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
app/Http/Controllers/Ajax/ProblemController.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -110,8 +110,8 @@  discard block
 block discarded – undo
110 110
         if (empty($basic)) {
111 111
             return ResponseModel::err(3001);
112 112
         }
113
-        $ret=$problemModel->addSolution($pid,Auth::user()->id,$content);
114
-        return $ret?ResponseModel::success(200):ResponseModel::err(3003);
113
+        $ret=$problemModel->addSolution($pid, Auth::user()->id, $content);
114
+        return $ret ?ResponseModel::success(200) : ResponseModel::err(3003);
115 115
     }
116 116
     /**
117 117
      * The Ajax Problem Solution Discussion Update.
@@ -126,8 +126,8 @@  discard block
 block discarded – undo
126 126
         $problemModel=new ProblemModel();
127 127
         $psoid=$all_data["psoid"];
128 128
         $content=$all_data["content"];
129
-        $ret=$problemModel->updateSolution($psoid,Auth::user()->id,$content);
130
-        return $ret?ResponseModel::success(200):ResponseModel::err(3004);
129
+        $ret=$problemModel->updateSolution($psoid, Auth::user()->id, $content);
130
+        return $ret ?ResponseModel::success(200) : ResponseModel::err(3004);
131 131
     }
132 132
     /**
133 133
      * The Ajax Problem Solution Discussion Delete.
@@ -141,8 +141,8 @@  discard block
 block discarded – undo
141 141
         $all_data=$request->all();
142 142
         $problemModel=new ProblemModel();
143 143
         $psoid=$all_data["psoid"];
144
-        $ret=$problemModel->removeSolution($psoid,Auth::user()->id);
145
-        return $ret?ResponseModel::success(200):ResponseModel::err(3004);
144
+        $ret=$problemModel->removeSolution($psoid, Auth::user()->id);
145
+        return $ret ?ResponseModel::success(200) : ResponseModel::err(3004);
146 146
     }
147 147
     /**
148 148
      * The Ajax Problem Solution Discussion Vote.
@@ -157,8 +157,8 @@  discard block
 block discarded – undo
157 157
         $problemModel=new ProblemModel();
158 158
         $psoid=$all_data["psoid"];
159 159
         $type=$all_data["type"];
160
-        $ret=$problemModel->voteSolution($psoid,Auth::user()->id,$type);
161
-        return $ret["ret"]?ResponseModel::success(200,null,["votes"=>$ret["votes"],"select"=>$ret["select"]]):ResponseModel::err(3004);
160
+        $ret=$problemModel->voteSolution($psoid, Auth::user()->id, $type);
161
+        return $ret["ret"] ?ResponseModel::success(200, null, ["votes"=>$ret["votes"], "select"=>$ret["select"]]) : ResponseModel::err(3004);
162 162
     }
163 163
     /**
164 164
      * The Ajax Problem Solution Submit.
@@ -251,15 +251,15 @@  discard block
 block discarded – undo
251 251
 
252 252
         $submissionData=$submissionModel->basic($all_data["sid"]);
253 253
 
254
-        if($submissionData["uid"]!=Auth::user()->id){
254
+        if ($submissionData["uid"]!=Auth::user()->id) {
255 255
             return ResponseModel::err(2001);
256 256
         }
257 257
 
258
-        if($submissionData["verdict"]!="Submission Error"){
258
+        if ($submissionData["verdict"]!="Submission Error") {
259 259
             return ResponseModel::err(6003);
260 260
         }
261 261
 
262
-        $submissionModel->updateSubmission($all_data["sid"],[
262
+        $submissionModel->updateSubmission($all_data["sid"], [
263 263
             "verdict"=>"Pending",
264 264
             "time"=>0,
265 265
             "memory"=>0
Please login to merge, or discard this patch.
app/Models/Search/GroupSearchModel.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -12,19 +12,19 @@
 block discarded – undo
12 12
 
13 13
     public function search($key)
14 14
     {
15
-        $result = [];
15
+        $result=[];
16 16
         //group name or gcode find
17
-        if(strlen($key) >= 2){
18
-            $ret = self::where(function($query) use ($key){
19
-                $query->whereRaw('MATCH(`name`) AGAINST (? IN BOOLEAN MODE)',[$key])
17
+        if (strlen($key)>=2) {
18
+            $ret=self::where(function($query) use ($key){
19
+                $query->whereRaw('MATCH(`name`) AGAINST (? IN BOOLEAN MODE)', [$key])
20 20
                     ->orWhere('gcode', $key);
21 21
                 })
22
-                ->where('public',1)
23
-                ->select('gid','gcode', 'img', 'name', 'description')
22
+                ->where('public', 1)
23
+                ->select('gid', 'gcode', 'img', 'name', 'description')
24 24
                 ->limit(120)
25 25
                 ->get()->all();
26
-            if(!empty($ret)){
27
-                $result += $ret;
26
+            if (!empty($ret)) {
27
+                $result+=$ret;
28 28
             }
29 29
         }
30 30
 
Please login to merge, or discard this patch.
app/Models/Search/ProblemSearchModel.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -13,20 +13,20 @@
 block discarded – undo
13 13
 
14 14
     public function search($key)
15 15
     {
16
-        $result = [];
17
-        if(strlen($key) >= 2){
18
-            $ret = self::where('pcode', $key)
19
-                ->orWhereRaw('MATCH(`title`) AGAINST (? IN BOOLEAN MODE)',[$key])
16
+        $result=[];
17
+        if (strlen($key)>=2) {
18
+            $ret=self::where('pcode', $key)
19
+                ->orWhereRaw('MATCH(`title`) AGAINST (? IN BOOLEAN MODE)', [$key])
20 20
                 ->select('pcode', 'title')
21 21
                 ->limit(120)
22 22
                 ->get()->all();
23
-            if(!empty($ret)){
24
-                $result += $ret;
23
+            if (!empty($ret)) {
24
+                $result+=$ret;
25 25
             }
26 26
         }
27
-        $problemModel = new ProblemModel();
27
+        $problemModel=new ProblemModel();
28 28
         foreach ($result as $p_index => $p) {
29
-            if($problemModel->isBlocked($p['pid'])){
29
+            if ($problemModel->isBlocked($p['pid'])) {
30 30
                 unset($result[$p_index]);
31 31
             }
32 32
         }
Please login to merge, or discard this patch.
app/Models/Search/ContestSearchModel.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -15,26 +15,26 @@
 block discarded – undo
15 15
 
16 16
     public function search($key)
17 17
     {
18
-        $result = [];
18
+        $result=[];
19 19
         //contest name find
20
-        if(strlen($key) >= 2){
21
-            $ret = self::whereRaw('MATCH(`name`) AGAINST (? IN BOOLEAN MODE)',[$key])
20
+        if (strlen($key)>=2) {
21
+            $ret=self::whereRaw('MATCH(`name`) AGAINST (? IN BOOLEAN MODE)', [$key])
22 22
                 ->select('cid', 'gid', 'name', 'rule', 'public', 'verified', 'practice', 'rated', 'anticheated', 'begin_time', 'end_time')
23
-                ->orderBy('end_time','DESC')
23
+                ->orderBy('end_time', 'DESC')
24 24
                 ->limit(120)
25 25
                 ->get()->all();
26
-            $user_id = Auth::user()->id;
27
-            $contestModel = new ContestModel();
28
-            foreach($ret as $c_index => $c){
29
-                if(!$contestModel->judgeClearance($c['cid'],$user_id)){
26
+            $user_id=Auth::user()->id;
27
+            $contestModel=new ContestModel();
28
+            foreach ($ret as $c_index => $c) {
29
+                if (!$contestModel->judgeClearance($c['cid'], $user_id)) {
30 30
                     unset($ret[$c_index]);
31 31
                 }
32 32
             }
33
-            if(!empty($ret)){
34
-                $result += $ret;
33
+            if (!empty($ret)) {
34
+                $result+=$ret;
35 35
             }
36 36
         }
37
-        if(!empty($result)) {
37
+        if (!empty($result)) {
38 38
             foreach ($result as &$contest) {
39 39
                 $contest["rule_parsed"]=$this->rule[$contest["rule"]];
40 40
                 $contest["date_parsed"]=[
Please login to merge, or discard this patch.
app/Models/Search/UserSearchModel.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -10,16 +10,16 @@
 block discarded – undo
10 10
 
11 11
     public function search($key)
12 12
     {
13
-        $result = [];
14
-        if(strlen($key) >= 2){
15
-            $ret = self::where('email',$key)
16
-                ->orWhereRaw('MATCH(`name`) AGAINST (? IN BOOLEAN MODE)',[$key])
17
-                ->select('id','avatar', 'name',  'describes', 'professional_rate')
18
-                ->orderBy('professional_rate','DESC')
13
+        $result=[];
14
+        if (strlen($key)>=2) {
15
+            $ret=self::where('email', $key)
16
+                ->orWhereRaw('MATCH(`name`) AGAINST (? IN BOOLEAN MODE)', [$key])
17
+                ->select('id', 'avatar', 'name', 'describes', 'professional_rate')
18
+                ->orderBy('professional_rate', 'DESC')
19 19
                 ->limit(120)
20 20
                 ->get()->all();
21
-            if(!empty($ret)){
22
-                $result += $ret;
21
+            if (!empty($ret)) {
22
+                $result+=$ret;
23 23
             }
24 24
         }
25 25
         return $result;
Please login to merge, or discard this patch.
app/Models/Babel/ExtensionModel.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -21,8 +21,8 @@  discard block
 block discarded – undo
21 21
     {
22 22
         $ret=[];
23 23
         $marketspaceRaw=self::getRemote();
24
-        if(empty($marketspaceRaw)) return [];
25
-        foreach($marketspaceRaw["packages"] as $extension){
24
+        if (empty($marketspaceRaw)) return [];
25
+        foreach ($marketspaceRaw["packages"] as $extension) {
26 26
             $temp=[
27 27
                 "details"=>$extension,
28 28
                 "status"=>0,
@@ -31,11 +31,11 @@  discard block
 block discarded – undo
31 31
                 "settings"=>null,
32 32
                 "available"=>null
33 33
             ];
34
-            $temp["details"]["typeParsed"]=$temp["details"]["type"]=="virtual-judge"?"VirtualJudge":"OnlineJudge";
34
+            $temp["details"]["typeParsed"]=$temp["details"]["type"]=="virtual-judge" ? "VirtualJudge" : "OnlineJudge";
35 35
             try {
36 36
                 try {
37 37
                     $BabelConfig=json_decode(file_get_contents(babel_path("Extension/{$extension['code']}/babel.json")), true);
38
-                }catch (Throwable $e){
38
+                } catch (Throwable $e) {
39 39
                     $BabelConfig=[];
40 40
                 }
41 41
                 if (!empty($BabelConfig)) {
@@ -47,12 +47,12 @@  discard block
 block discarded – undo
47 47
                     $temp["updatable"]=$remoteVersion->isGreaterThan($downloadedVersion);
48 48
 
49 49
                     $installedConfig=OJModel::where(["ocode"=>$extension["code"]])->first();
50
-                    if (is_null($installedConfig)){
50
+                    if (is_null($installedConfig)) {
51 51
                         $temp["status"]=1;
52 52
                     } else {
53 53
                         $temp["version"]=$installedConfig->version; // local installed version
54 54
                         $installedVersion=new Version($temp["version"]);
55
-                        if ($downloadedVersion->isGreaterThan($installedVersion)){
55
+                        if ($downloadedVersion->isGreaterThan($installedVersion)) {
56 56
                             $temp["status"]=1;
57 57
                         } else {
58 58
                             $temp["status"]=2;
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
                         $temp["available"]=$installedConfig->status;
62 62
                     }
63 63
                 }
64
-            }catch (Throwable $e){
64
+            } catch (Throwable $e) {
65 65
                 $temp["status"]=-1;
66 66
             }
67 67
             $ret[]=$temp;
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
     {
75 75
         try {
76 76
             return json_decode(file_get_contents(env("BABEL_MIRROR", "https://acm.njupt.edu.cn/babel")."/babel.json"), true);
77
-        }catch(Throwable $e){
77
+        } catch (Throwable $e) {
78 78
             return [];
79 79
         }
80 80
     }
Please login to merge, or discard this patch.