@@ -18,28 +18,28 @@ discard block |
||
18 | 18 | const CREATED_AT=null; |
19 | 19 | |
20 | 20 | //Repository function |
21 | - public function participants($ignore_frozen = true) |
|
21 | + public function participants($ignore_frozen=true) |
|
22 | 22 | { |
23 | - if($this->registration){ |
|
24 | - $participants = ContestParticipant::where('cid',$this->cid)->get(); |
|
23 | + if ($this->registration) { |
|
24 | + $participants=ContestParticipant::where('cid', $this->cid)->get(); |
|
25 | 25 | $participants->load('user'); |
26 | - $users = new EloquentCollection; |
|
26 | + $users=new EloquentCollection; |
|
27 | 27 | foreach ($participants as $participant) { |
28 | - $user = $participant->user; |
|
28 | + $user=$participant->user; |
|
29 | 29 | $users->add($user); |
30 | 30 | } |
31 | 31 | return $users->unique(); |
32 | - }else{ |
|
32 | + } else { |
|
33 | 33 | $this->load('submissions.user'); |
34 | - if($ignore_frozen){ |
|
35 | - $frozen_time = $this->frozen_time; |
|
36 | - $submissions = $this->submissions()->where('submission_date','<',$frozen_time)->get(); |
|
37 | - }else{ |
|
38 | - $submissions = $this->submissions; |
|
34 | + if ($ignore_frozen) { |
|
35 | + $frozen_time=$this->frozen_time; |
|
36 | + $submissions=$this->submissions()->where('submission_date', '<', $frozen_time)->get(); |
|
37 | + } else { |
|
38 | + $submissions=$this->submissions; |
|
39 | 39 | } |
40 | - $users = new EloquentCollection; |
|
40 | + $users=new EloquentCollection; |
|
41 | 41 | foreach ($submissions as $submission) { |
42 | - $user = $submission->user; |
|
42 | + $user=$submission->user; |
|
43 | 43 | $users->add($user); |
44 | 44 | } |
45 | 45 | return $users->unique(); |
@@ -49,18 +49,18 @@ discard block |
||
49 | 49 | // Repository/Service? function |
50 | 50 | public function rankRefresh() |
51 | 51 | { |
52 | - $ret = []; |
|
53 | - $participants = $this->participants(); |
|
54 | - $contest_problems = $this->problems; |
|
52 | + $ret=[]; |
|
53 | + $participants=$this->participants(); |
|
54 | + $contest_problems=$this->problems; |
|
55 | 55 | $contest_problems->load('problem'); |
56 | - if($this->rule == 1){ |
|
56 | + if ($this->rule==1) { |
|
57 | 57 | // ACM/ICPC Mode |
58 | 58 | foreach ($participants as $participant) { |
59 | 59 | $prob_detail=[]; |
60 | 60 | $totPen=0; |
61 | 61 | $totScore=0; |
62 | 62 | foreach ($contest_problems as $contest_problem) { |
63 | - $prob_stat = $contest_problem->userStatus($participant); |
|
63 | + $prob_stat=$contest_problem->userStatus($participant); |
|
64 | 64 | $prob_detail[]=[ |
65 | 65 | 'ncode'=>$contest_problem->ncode, |
66 | 66 | 'pid'=>$contest_problem->pid, |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | "problem_detail" => $prob_detail |
87 | 87 | ]; |
88 | 88 | } |
89 | - usort($ret, function ($a, $b) { |
|
89 | + usort($ret, function($a, $b) { |
|
90 | 90 | if ($a["score"]==$b["score"]) { |
91 | 91 | if ($a["penalty"]==$b["penalty"]) { |
92 | 92 | return 0; |
@@ -103,53 +103,53 @@ discard block |
||
103 | 103 | }); |
104 | 104 | Cache::tags(['contest', 'rank'])->put($this->cid, $ret, 60); |
105 | 105 | return $ret; |
106 | - }else{ |
|
106 | + } else { |
|
107 | 107 | // IO Mode |
108 | - $c = new OutdatedContestModel(); |
|
108 | + $c=new OutdatedContestModel(); |
|
109 | 109 | return $c->contestRankCache($this->cid); |
110 | 110 | } |
111 | 111 | } |
112 | 112 | |
113 | 113 | public function clarifications() |
114 | 114 | { |
115 | - return $this->hasMany('App\Models\Eloquent\ContestClarification','cid','cid'); |
|
115 | + return $this->hasMany('App\Models\Eloquent\ContestClarification', 'cid', 'cid'); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | public function problems() |
119 | 119 | { |
120 | - return $this->hasMany('App\Models\Eloquent\ContestProblem','cid','cid'); |
|
120 | + return $this->hasMany('App\Models\Eloquent\ContestProblem', 'cid', 'cid'); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | public function submissions() |
124 | 124 | { |
125 | - return $this->hasMany('App\Models\Eloquent\Submission','cid','cid'); |
|
125 | + return $this->hasMany('App\Models\Eloquent\Submission', 'cid', 'cid'); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | public function group() |
129 | 129 | { |
130 | - return $this->hasOne('App\Models\Eloquent\Group','gid','gid'); |
|
130 | + return $this->hasOne('App\Models\Eloquent\Group', 'gid', 'gid'); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | public function getFrozenTimeAttribute() |
134 | 134 | { |
135 | - $end_time = strtotime($this->end_time); |
|
136 | - return $end_time - $this->froze_length; |
|
135 | + $end_time=strtotime($this->end_time); |
|
136 | + return $end_time-$this->froze_length; |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | public function getIsEndAttribute() |
140 | 140 | { |
141 | - return strtotime($this->end_time) < time(); |
|
141 | + return strtotime($this->end_time)<time(); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | public static function getProblemSet($cid, $renderLatex=false) |
145 | 145 | { |
146 | 146 | $ret=[]; |
147 | - $problemset=ContestProblemModel::where('cid', $cid)->orderBy('number','asc')->get(); |
|
148 | - foreach($problemset as $problem){ |
|
147 | + $problemset=ContestProblemModel::where('cid', $cid)->orderBy('number', 'asc')->get(); |
|
148 | + foreach ($problemset as $problem) { |
|
149 | 149 | $problemDetail=ProblemModel::find($problem->pid); |
150 | 150 | $problemRet=(new OutdatedProblemModel())->detail($problemDetail->pcode); |
151 | - if ($renderLatex){ |
|
152 | - foreach (['description','input','output','note'] as $section){ |
|
151 | + if ($renderLatex) { |
|
152 | + foreach (['description', 'input', 'output', 'note'] as $section) { |
|
153 | 153 | $problemRet['parsed'][$section]=latex2Image($problemRet['parsed'][$section]); |
154 | 154 | } |
155 | 155 | } |
@@ -163,6 +163,6 @@ discard block |
||
163 | 163 | |
164 | 164 | public function isJudgingComplete() |
165 | 165 | { |
166 | - return $this->submissions->whereIn('verdict',['Waiting','Pending'])->count()==0; |
|
166 | + return $this->submissions->whereIn('verdict', ['Waiting', 'Pending'])->count()==0; |
|
167 | 167 | } |
168 | 168 | } |
@@ -11,7 +11,7 @@ discard block |
||
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 |
||
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 |
||
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"; |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | public function generateContestAccount($cid, $ccode, $num) |
62 | 62 | { |
63 | 63 | $ret=[]; |
64 | - $starting=DB::table("users")->where('prefix','=',$ccode)->count(); |
|
64 | + $starting=DB::table("users")->where('prefix', '=', $ccode)->count(); |
|
65 | 65 | $contestModel=new ContestModel(); |
66 | 66 | for ($i=1; $i<=$num; $i++) { |
67 | 67 | $pass=$this->generatePassword(); |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | |
110 | 110 | public function detail($uid) |
111 | 111 | { |
112 | - if (filter_var($uid, FILTER_VALIDATE_INT) === false) { |
|
112 | + if (filter_var($uid, FILTER_VALIDATE_INT)===false) { |
|
113 | 113 | return null; |
114 | 114 | } |
115 | 115 | $ret=DB::table("users")->where(["id"=>$uid])->first(); |
@@ -129,14 +129,14 @@ discard block |
||
129 | 129 | ])->join("problem", "problem.pid", "=", "submission.pid")->select('pcode')->distinct()->get()->all(); |
130 | 130 | $ret["solvedCount"]=count($ret["solved"]); |
131 | 131 | // Casual |
132 | - $ret["rank"]=Cache::tags(['rank',$ret["id"]])->get("rank", "N/A"); |
|
133 | - $ret["rankTitle"]=Cache::tags(['rank',$ret["id"]])->get("title", "Recruit"); |
|
132 | + $ret["rank"]=Cache::tags(['rank', $ret["id"]])->get("rank", "N/A"); |
|
133 | + $ret["rankTitle"]=Cache::tags(['rank', $ret["id"]])->get("title", "Recruit"); |
|
134 | 134 | $ret["rankTitleColor"]=RankModel::getColor($ret["rankTitle"]); |
135 | 135 | // Professional |
136 | 136 | $ret["professionalTitle"]=RankModel::getProfessionalTitle($ret["professional_rate"]); |
137 | 137 | $ret["professionalTitleColor"]=RankModel::getProfessionalColor($ret["professionalTitle"]); |
138 | 138 | // Administration Group |
139 | - $ret["admin"]=$uid==1?1:0; |
|
139 | + $ret["admin"]=$uid==1 ? 1 : 0; |
|
140 | 140 | if (Cache::tags(['bing', 'pic'])->get(date("Y-m-d"))==null) { |
141 | 141 | $bing=new BingPhoto([ |
142 | 142 | 'locale' => 'zh-CN', |
@@ -155,26 +155,26 @@ discard block |
||
155 | 155 | * @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. |
156 | 156 | * @return string|array $result |
157 | 157 | */ |
158 | - public function getExtra($uid,$need, $secret_level = 0){ |
|
159 | - $ret = DB::table('users_extra')->where('uid',$uid)->orderBy('key')->get()->all(); |
|
160 | - $result = []; |
|
161 | - if(!empty($ret)){ |
|
162 | - if(is_string($need)){ |
|
158 | + public function getExtra($uid, $need, $secret_level=0) { |
|
159 | + $ret=DB::table('users_extra')->where('uid', $uid)->orderBy('key')->get()->all(); |
|
160 | + $result=[]; |
|
161 | + if (!empty($ret)) { |
|
162 | + if (is_string($need)) { |
|
163 | 163 | foreach ($ret as $value) { |
164 | - if(empty($value['secret_level']) || $value['secret_level'] <= $secret_level){ |
|
165 | - $key_name = $this->user_extra[$value['key']] ?? 'unknown'; |
|
166 | - if($key_name == $need){ |
|
164 | + if (empty($value['secret_level']) || $value['secret_level']<=$secret_level) { |
|
165 | + $key_name=$this->user_extra[$value['key']] ?? 'unknown'; |
|
166 | + if ($key_name==$need) { |
|
167 | 167 | return $value['value']; |
168 | 168 | } |
169 | 169 | } |
170 | 170 | } |
171 | 171 | return null; |
172 | - }else{ |
|
172 | + } else { |
|
173 | 173 | foreach ($ret as $value) { |
174 | - if(empty($value['secret_level']) || $value['secret_level'] <= $secret_level){ |
|
175 | - $key_name = $this->user_extra[$value['key']] ?? 'unknown'; |
|
176 | - if(in_array($key_name,$need)){ |
|
177 | - $result[$key_name] = $value['value']; |
|
174 | + if (empty($value['secret_level']) || $value['secret_level']<=$secret_level) { |
|
175 | + $key_name=$this->user_extra[$value['key']] ?? 'unknown'; |
|
176 | + if (in_array($key_name, $need)) { |
|
177 | + $result[$key_name]=$value['value']; |
|
178 | 178 | } |
179 | 179 | } |
180 | 180 | } |
@@ -191,26 +191,26 @@ discard block |
||
191 | 191 | * @param string|null $value the extra info will be delete when value is null |
192 | 192 | * @return mixed $result |
193 | 193 | */ |
194 | - public function setExtra($uid,$key_name,$value = null,$secret_level = -1){ |
|
195 | - $key = array_search($key_name,$this->user_extra); |
|
196 | - if($key === false){ |
|
194 | + public function setExtra($uid, $key_name, $value=null, $secret_level=-1) { |
|
195 | + $key=array_search($key_name, $this->user_extra); |
|
196 | + if ($key===false) { |
|
197 | 197 | return false; |
198 | 198 | } |
199 | - $ret = DB::table('users_extra')->where('uid',$uid)->where('key',$key)->first(); |
|
200 | - if(!empty($ret)){ |
|
199 | + $ret=DB::table('users_extra')->where('uid', $uid)->where('key', $key)->first(); |
|
200 | + if (!empty($ret)) { |
|
201 | 201 | unset($ret['id']); |
202 | - if(!is_null($value)){ |
|
203 | - $ret['value'] = $value; |
|
204 | - }else{ |
|
205 | - DB::table('users_extra')->where('uid',$uid)->where('key',$key)->delete(); |
|
202 | + if (!is_null($value)) { |
|
203 | + $ret['value']=$value; |
|
204 | + } else { |
|
205 | + DB::table('users_extra')->where('uid', $uid)->where('key', $key)->delete(); |
|
206 | 206 | return true; |
207 | 207 | } |
208 | - if($secret_level != -1){ |
|
209 | - $ret['secret_level'] = $secret_level; |
|
208 | + if ($secret_level!=-1) { |
|
209 | + $ret['secret_level']=$secret_level; |
|
210 | 210 | } |
211 | - return DB::table('users_extra')->where('uid',$uid)->where('key',$key)->update($ret); |
|
212 | - }else{ |
|
213 | - if($value === null){ |
|
211 | + return DB::table('users_extra')->where('uid', $uid)->where('key', $key)->update($ret); |
|
212 | + } else { |
|
213 | + if ($value===null) { |
|
214 | 214 | return true; |
215 | 215 | } |
216 | 216 | return DB::table('users_extra')->insertGetId( |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | 'uid' => $uid, |
219 | 219 | 'key' => $key, |
220 | 220 | 'value' => $value, |
221 | - 'secret_level' => $secret_level == -1 ? 0 : $secret_level, |
|
221 | + 'secret_level' => $secret_level==-1 ? 0 : $secret_level, |
|
222 | 222 | ] |
223 | 223 | ); |
224 | 224 | } |
@@ -230,33 +230,33 @@ discard block |
||
230 | 230 | * @param string $value the value |
231 | 231 | * @return string $result |
232 | 232 | */ |
233 | - public function findExtra($key,$value) |
|
233 | + public function findExtra($key, $value) |
|
234 | 234 | { |
235 | - $key = array_search($key,$this->user_extra); |
|
236 | - if($key){ |
|
237 | - return DB::table('users_extra')->where('key',$key)->where('value',$value)->first(); |
|
238 | - }else{ |
|
235 | + $key=array_search($key, $this->user_extra); |
|
236 | + if ($key) { |
|
237 | + return DB::table('users_extra')->where('key', $key)->where('value', $value)->first(); |
|
238 | + } else { |
|
239 | 239 | return null; |
240 | 240 | } |
241 | 241 | } |
242 | 242 | |
243 | - public function getSocialiteInfo($uid,$secret_level = -1) |
|
243 | + public function getSocialiteInfo($uid, $secret_level=-1) |
|
244 | 244 | { |
245 | - $socialites = []; |
|
245 | + $socialites=[]; |
|
246 | 246 | foreach ($this->socialite_support as $key => $value) { |
247 | - $id_keyname = $key.'_id'; |
|
248 | - $id = $this->getExtra($uid,$id_keyname); |
|
249 | - if(!empty($id)){ |
|
250 | - $info = [ |
|
247 | + $id_keyname=$key.'_id'; |
|
248 | + $id=$this->getExtra($uid, $id_keyname); |
|
249 | + if (!empty($id)) { |
|
250 | + $info=[ |
|
251 | 251 | 'id' => $id, |
252 | 252 | ]; |
253 | 253 | foreach ($value as $info_name) { |
254 | - $info_temp = $this->getExtra($uid,$key.'_'.$info_name); |
|
255 | - if($info_temp !== null){ |
|
256 | - $info[$info_name] = $info_temp; |
|
254 | + $info_temp=$this->getExtra($uid, $key.'_'.$info_name); |
|
255 | + if ($info_temp!==null) { |
|
256 | + $info[$info_name]=$info_temp; |
|
257 | 257 | } |
258 | 258 | } |
259 | - $socialites[$key] = $info; |
|
259 | + $socialites[$key]=$info; |
|
260 | 260 | } |
261 | 261 | } |
262 | 262 |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function render($request, Exception $exception) |
48 | 48 | { |
49 | - if(!env("APP_DEBUG") && $request->is('api/*')) { |
|
49 | + if (!env("APP_DEBUG") && $request->is('api/*')) { |
|
50 | 50 | return response(json_encode([ |
51 | 51 | 'success' => false, |
52 | 52 | 'message' => 'Server Error', |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | 'msg' => 'Server Error', |
57 | 57 | 'data'=>[] |
58 | 58 | ] |
59 | - ]),500)->header('Content-Type','application/json'); |
|
59 | + ]), 500)->header('Content-Type', 'application/json'); |
|
60 | 60 | }; |
61 | 61 | return parent::render($request, $exception); |
62 | 62 | } |
@@ -64,20 +64,20 @@ discard block |
||
64 | 64 | } |
65 | 65 | } |
66 | 66 | |
67 | -if (! function_exists('babel_path')) { |
|
67 | +if (!function_exists('babel_path')) { |
|
68 | 68 | /** |
69 | 69 | * Get the path to the application folder. |
70 | 70 | * |
71 | 71 | * @param string $path |
72 | 72 | * @return string |
73 | 73 | */ |
74 | - function babel_path($path = '') |
|
74 | + function babel_path($path='') |
|
75 | 75 | { |
76 | 76 | return app('path').DIRECTORY_SEPARATOR.'Babel'.($path ? DIRECTORY_SEPARATOR.$path : $path); |
77 | 77 | } |
78 | 78 | } |
79 | 79 | |
80 | -if (! function_exists('glob_recursive')) { |
|
80 | +if (!function_exists('glob_recursive')) { |
|
81 | 81 | /** |
82 | 82 | * Find pathnames matching a pattern recursively. |
83 | 83 | * |
@@ -85,11 +85,11 @@ discard block |
||
85 | 85 | * @param int $flags Valid flags: GLOB_MARK |
86 | 86 | * @return array|false an array containing the matched files/directories, an empty array if no file matched or false on error. |
87 | 87 | */ |
88 | - function glob_recursive($pattern, $flags = 0) |
|
88 | + function glob_recursive($pattern, $flags=0) |
|
89 | 89 | { |
90 | - $files = glob($pattern, $flags); |
|
91 | - foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) { |
|
92 | - $files = array_merge($files, glob_recursive($dir.'/'.basename($pattern), $flags)); |
|
90 | + $files=glob($pattern, $flags); |
|
91 | + foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) { |
|
92 | + $files=array_merge($files, glob_recursive($dir.'/'.basename($pattern), $flags)); |
|
93 | 93 | } |
94 | 94 | return $files; |
95 | 95 | } |
@@ -123,8 +123,8 @@ discard block |
||
123 | 123 | function delFile($dirName) |
124 | 124 | { |
125 | 125 | if (file_exists($dirName) && $handle=opendir($dirName)) { |
126 | - while (false!==($item = readdir($handle))) { |
|
127 | - if ($item!= "." && $item != "..") { |
|
126 | + while (false!==($item=readdir($handle))) { |
|
127 | + if ($item!="." && $item!="..") { |
|
128 | 128 | if (file_exists($dirName.'/'.$item) && is_dir($dirName.'/'.$item)) { |
129 | 129 | delFile($dirName.'/'.$item); |
130 | 130 | } else { |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | if (!function_exists('convertMarkdownToHtml')) { |
143 | 143 | function convertMarkdownToHtml($md) |
144 | 144 | { |
145 | - return is_string($md)?Markdown::convertToHtml($md):''; |
|
145 | + return is_string($md) ?Markdown::convertToHtml($md) : ''; |
|
146 | 146 | } |
147 | 147 | } |
148 | 148 | |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | $periods[$j]=__("helper.time.singular.$periods[$j]"); |
187 | 187 | } |
188 | 188 | |
189 | - return __("helper.time.formatter",[ |
|
189 | + return __("helper.time.formatter", [ |
|
190 | 190 | "time" => $difference, |
191 | 191 | "unit" => $periods[$j], |
192 | 192 | "tense" => $tense, |
@@ -211,18 +211,18 @@ discard block |
||
211 | 211 | if (!function_exists('latex2Image')) { |
212 | 212 | function latex2Image($content) |
213 | 213 | { |
214 | - $callback = function ($matches) use (&$patch, &$display) { |
|
215 | - [$url,$width,$height]=LatexModel::info("$patch$matches[1]$patch"); |
|
214 | + $callback=function($matches) use (&$patch, &$display) { |
|
215 | + [$url, $width, $height]=LatexModel::info("$patch$matches[1]$patch"); |
|
216 | 216 | return "<img src=\"$url\" style=\"display: $display;\" class=\"rendered-tex\" width=\"$width\" height=\"$height\">"; |
217 | 217 | }; |
218 | - $patch = '$'; |
|
219 | - $display = 'inline-block'; |
|
220 | - $content = preg_replace_callback('/\\$\\$\\$(.*?)\\$\\$\\$/', $callback, $content); |
|
221 | - $content = preg_replace_callback('/\\\\\\((.*?)\\\\\\)/', $callback, $content); |
|
222 | - $patch = '$$'; |
|
223 | - $display = 'block'; |
|
224 | - $content = preg_replace_callback('/\\$\\$(.*?)\\$\\$/', $callback, $content); |
|
225 | - $content = preg_replace_callback('/\\\\\\[(.*?)\\\\\\]/', $callback, $content); |
|
218 | + $patch='$'; |
|
219 | + $display='inline-block'; |
|
220 | + $content=preg_replace_callback('/\\$\\$\\$(.*?)\\$\\$\\$/', $callback, $content); |
|
221 | + $content=preg_replace_callback('/\\\\\\((.*?)\\\\\\)/', $callback, $content); |
|
222 | + $patch='$$'; |
|
223 | + $display='block'; |
|
224 | + $content=preg_replace_callback('/\\$\\$(.*?)\\$\\$/', $callback, $content); |
|
225 | + $content=preg_replace_callback('/\\\\\\[(.*?)\\\\\\]/', $callback, $content); |
|
226 | 226 | return $content; |
227 | 227 | } |
228 | 228 | } |
@@ -80,7 +80,7 @@ |
||
80 | 80 | "spj_compile_config" => null, |
81 | 81 | "spj_src" => null |
82 | 82 | ]; |
83 | - if($probBasic["spj"] && $probBasic["spj_version"]){ |
|
83 | + if ($probBasic["spj"] && $probBasic["spj_version"]) { |
|
84 | 84 | $submit_data["spj_version"]=$probBasic["spj_version"]; |
85 | 85 | $submit_data["spj_config"]=$probBasic["spj_lang"]; |
86 | 86 | $submit_data["spj_compile_config"]=[ |
@@ -27,22 +27,22 @@ discard block |
||
27 | 27 | 'cid' => 'required|integer', |
28 | 28 | 'uid' => 'required|integer' |
29 | 29 | ]); |
30 | - $cid = $request->input('cid'); |
|
31 | - $uid = $request->input('uid'); |
|
30 | + $cid=$request->input('cid'); |
|
31 | + $uid=$request->input('uid'); |
|
32 | 32 | |
33 | - $groupModel = new GroupModel(); |
|
34 | - $contestModel = new ContestModel(); |
|
33 | + $groupModel=new GroupModel(); |
|
34 | + $contestModel=new ContestModel(); |
|
35 | 35 | |
36 | - $contest_info = $contestModel->basic($cid); |
|
37 | - if($contestModel->judgeClearance($cid,Auth::user()->id) != 3){ |
|
36 | + $contest_info=$contestModel->basic($cid); |
|
37 | + if ($contestModel->judgeClearance($cid, Auth::user()->id)!=3) { |
|
38 | 38 | return ResponseModel::err(2001); |
39 | 39 | } |
40 | 40 | |
41 | - if($groupModel->judgeClearance($contest_info['gid'],$uid) < 2){ |
|
41 | + if ($groupModel->judgeClearance($contest_info['gid'], $uid)<2) { |
|
42 | 42 | return ResponseModel::err(7004); |
43 | 43 | } |
44 | 44 | |
45 | - $contestModel->assignMember($cid,$uid); |
|
45 | + $contestModel->assignMember($cid, $uid); |
|
46 | 46 | return ResponseModel::success(200); |
47 | 47 | } |
48 | 48 | |
@@ -51,30 +51,30 @@ discard block |
||
51 | 51 | $request->validate([ |
52 | 52 | 'cid' => 'required|integer', |
53 | 53 | ]); |
54 | - $cid = $request->input('cid'); |
|
54 | + $cid=$request->input('cid'); |
|
55 | 55 | |
56 | - $contestModel = new ContestModel(); |
|
57 | - $groupModel = new GroupModel(); |
|
56 | + $contestModel=new ContestModel(); |
|
57 | + $groupModel=new GroupModel(); |
|
58 | 58 | |
59 | - $contest_problems = $contestModel->problems($cid); |
|
60 | - $contest_detail = $contestModel->basic($cid); |
|
61 | - $contest_detail['problems'] = $contest_problems; |
|
62 | - $assign_uid = $contest_detail['assign_uid']; |
|
63 | - $clearance = $contestModel->judgeClearance($cid,Auth::user()->id); |
|
64 | - if($clearance != 3){ |
|
59 | + $contest_problems=$contestModel->problems($cid); |
|
60 | + $contest_detail=$contestModel->basic($cid); |
|
61 | + $contest_detail['problems']=$contest_problems; |
|
62 | + $assign_uid=$contest_detail['assign_uid']; |
|
63 | + $clearance=$contestModel->judgeClearance($cid, Auth::user()->id); |
|
64 | + if ($clearance!=3) { |
|
65 | 65 | return ResponseModel::err(2001); |
66 | 66 | } |
67 | - if($assign_uid != 0){ |
|
68 | - $assignee = $groupModel->userProfile($assign_uid,$contest_detail['gid']); |
|
69 | - }else{ |
|
70 | - $assignee = null; |
|
67 | + if ($assign_uid!=0) { |
|
68 | + $assignee=$groupModel->userProfile($assign_uid, $contest_detail['gid']); |
|
69 | + } else { |
|
70 | + $assignee=null; |
|
71 | 71 | } |
72 | - $ret = [ |
|
72 | + $ret=[ |
|
73 | 73 | 'contest_info' => $contest_detail, |
74 | 74 | 'assignee' => $assignee, |
75 | - 'is_admin' => $clearance == 3, |
|
75 | + 'is_admin' => $clearance==3, |
|
76 | 76 | ]; |
77 | - return ResponseModel::success(200,null,$ret); |
|
77 | + return ResponseModel::success(200, null, $ret); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | public function rejudge(Request $request) |
@@ -109,15 +109,15 @@ discard block |
||
109 | 109 | 'end_time' => 'required|date|after:begin_time', |
110 | 110 | 'description' => 'string' |
111 | 111 | ]); |
112 | - $all_data = $request->all(); |
|
113 | - $cid = $all_data['cid']; |
|
112 | + $all_data=$request->all(); |
|
113 | + $cid=$all_data['cid']; |
|
114 | 114 | |
115 | - $contestModel = new ContestModel(); |
|
116 | - if($contestModel->judgeClearance($all_data['cid'],Auth::user()->id) != 3){ |
|
115 | + $contestModel=new ContestModel(); |
|
116 | + if ($contestModel->judgeClearance($all_data['cid'], Auth::user()->id)!=3) { |
|
117 | 117 | return ResponseModel::err(2001); |
118 | 118 | } |
119 | 119 | |
120 | - if($contestModel->remainingTime($cid) > 0){ |
|
120 | + if ($contestModel->remainingTime($cid)>0) { |
|
121 | 121 | $problems=explode(",", $all_data["problems"]); |
122 | 122 | if (count($problems)>26) { |
123 | 123 | return ResponseModel::err(4002); |
@@ -134,32 +134,32 @@ discard block |
||
134 | 134 | ]; |
135 | 135 | } |
136 | 136 | } |
137 | - $allow_update = ['name','description','begin_time','end_time', 'status_visibility']; |
|
137 | + $allow_update=['name', 'description', 'begin_time', 'end_time', 'status_visibility']; |
|
138 | 138 | |
139 | - foreach($all_data as $key => $value){ |
|
140 | - if(!in_array($key,$allow_update)){ |
|
139 | + foreach ($all_data as $key => $value) { |
|
140 | + if (!in_array($key, $allow_update)) { |
|
141 | 141 | unset($all_data[$key]); |
142 | 142 | } |
143 | 143 | } |
144 | - $contestModel->contestUpdate($cid,$all_data,$problemSet); |
|
144 | + $contestModel->contestUpdate($cid, $all_data, $problemSet); |
|
145 | 145 | return ResponseModel::success(200); |
146 | - }else{ |
|
147 | - $allow_update = ['name','description']; |
|
146 | + } else { |
|
147 | + $allow_update=['name', 'description']; |
|
148 | 148 | |
149 | - foreach($all_data as $key => $value){ |
|
150 | - if(!in_array($key,$allow_update)){ |
|
149 | + foreach ($all_data as $key => $value) { |
|
150 | + if (!in_array($key, $allow_update)) { |
|
151 | 151 | unset($all_data[$key]); |
152 | 152 | } |
153 | 153 | } |
154 | - $contestModel->contestUpdate($cid,$all_data,false); |
|
155 | - return ResponseModel::success(200,' |
|
154 | + $contestModel->contestUpdate($cid, $all_data, false); |
|
155 | + return ResponseModel::success(200, ' |
|
156 | 156 | Successful! However, only the name and description of the match can be changed for the match that has been finished. |
157 | 157 | '); |
158 | 158 | } |
159 | 159 | |
160 | 160 | } |
161 | 161 | |
162 | - public function issueAnnouncement(Request $request){ |
|
162 | + public function issueAnnouncement(Request $request) { |
|
163 | 163 | $request->validate([ |
164 | 164 | 'cid' => 'required|integer', |
165 | 165 | 'title' => 'required|string|max:250', |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | } |
180 | 180 | } |
181 | 181 | |
182 | - public function replyClarification(Request $request){ |
|
182 | + public function replyClarification(Request $request) { |
|
183 | 183 | $request->validate([ |
184 | 184 | 'cid' => 'required|integer', |
185 | 185 | 'ccid' => 'required|integer', |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | } |
200 | 200 | } |
201 | 201 | |
202 | - public function setClarificationPublic(Request $request){ |
|
202 | + public function setClarificationPublic(Request $request) { |
|
203 | 203 | $request->validate([ |
204 | 204 | 'cid' => 'required|integer', |
205 | 205 | 'ccid' => 'required|integer', |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | $groupModel=new GroupModel(); |
233 | 233 | $contestModel=new ContestModel(); |
234 | 234 | $verified=$contestModel->isVerified($all_data["cid"]); |
235 | - if(!$verified){ |
|
235 | + if (!$verified) { |
|
236 | 236 | return ResponseModel::err(2001); |
237 | 237 | } |
238 | 238 | $gid=$contestModel->gid($all_data["cid"]); |
@@ -253,18 +253,18 @@ discard block |
||
253 | 253 | $request->validate([ |
254 | 254 | 'cid' => 'required|integer', |
255 | 255 | ]); |
256 | - $cid = $request->input('cid'); |
|
257 | - $contestModel = new ContestModel(); |
|
258 | - if($contestModel->judgeClearance($cid,Auth::user()->id) != 3){ |
|
256 | + $cid=$request->input('cid'); |
|
257 | + $contestModel=new ContestModel(); |
|
258 | + if ($contestModel->judgeClearance($cid, Auth::user()->id)!=3) { |
|
259 | 259 | return ResponseModel::err(2001); |
260 | 260 | } |
261 | - if($contestModel->remainingTime($cid) >= 0){ |
|
261 | + if ($contestModel->remainingTime($cid)>=0) { |
|
262 | 262 | return ResponseModel::err(4008); |
263 | 263 | } |
264 | - if($contestModel->basic($cid)['froze_length'] == 0){ |
|
264 | + if ($contestModel->basic($cid)['froze_length']==0) { |
|
265 | 265 | return ResponseModel::err(4009); |
266 | 266 | } |
267 | - $data = $contestModel->getScrollBoardData($cid); |
|
267 | + $data=$contestModel->getScrollBoardData($cid); |
|
268 | 268 | return ResponseModel::success(200, null, $data); |
269 | 269 | } |
270 | 270 | |
@@ -273,20 +273,20 @@ discard block |
||
273 | 273 | $request->validate([ |
274 | 274 | "cid"=>"required|integer", |
275 | 275 | ]); |
276 | - $cid = $request->input('cid'); |
|
276 | + $cid=$request->input('cid'); |
|
277 | 277 | $groupModel=new GroupModel(); |
278 | 278 | $contestModel=new ContestModel(); |
279 | - if($contestModel->judgeClearance($cid,Auth::user()->id) != 3){ |
|
279 | + if ($contestModel->judgeClearance($cid, Auth::user()->id)!=3) { |
|
280 | 280 | return ResponseModel::err(2001); |
281 | 281 | } |
282 | 282 | |
283 | 283 | $zip_name=$contestModel->zipName($cid); |
284 | - if(!(Storage::disk("private")->exists("contestCodeZip/$cid/".$cid.".zip"))){ |
|
285 | - $contestModel->GenerateZip("contestCodeZip/$cid/",$cid,"contestCode/$cid/",$zip_name); |
|
284 | + if (!(Storage::disk("private")->exists("contestCodeZip/$cid/".$cid.".zip"))) { |
|
285 | + $contestModel->GenerateZip("contestCodeZip/$cid/", $cid, "contestCode/$cid/", $zip_name); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | $files=Storage::disk("private")->files("contestCodeZip/$cid/"); |
289 | - response()->download(base_path("/storage/app/private/".$files[0]),$zip_name,[ |
|
289 | + response()->download(base_path("/storage/app/private/".$files[0]), $zip_name, [ |
|
290 | 290 | "Content-Transfer-Encoding" => "binary", |
291 | 291 | "Content-Type"=>"application/octet-stream", |
292 | 292 | "filename"=>$zip_name |
@@ -299,10 +299,10 @@ discard block |
||
299 | 299 | $request->validate([ |
300 | 300 | "cid"=>"required|integer", |
301 | 301 | ]); |
302 | - $cid = $request->input('cid'); |
|
302 | + $cid=$request->input('cid'); |
|
303 | 303 | $contestModel=new ContestModel(); |
304 | 304 | |
305 | - if($contestModel->judgeClearance($cid,Auth::user()->id) != 3){ |
|
305 | + if ($contestModel->judgeClearance($cid, Auth::user()->id)!=3) { |
|
306 | 306 | return ResponseModel::err(2001); |
307 | 307 | } |
308 | 308 | $name=$contestModel->basic($cid)["name"]; |
@@ -317,17 +317,17 @@ discard block |
||
317 | 317 | "config.cover"=>"required", |
318 | 318 | "config.advice"=>"required", |
319 | 319 | ]); |
320 | - $cid = $request->input('cid'); |
|
321 | - $config = [ |
|
320 | + $cid=$request->input('cid'); |
|
321 | + $config=[ |
|
322 | 322 | 'cover'=>$request->input('config.cover')=='true', |
323 | 323 | 'advice'=>$request->input('config.advice')=='true' |
324 | 324 | ]; |
325 | 325 | $contestModel=new ContestModel(); |
326 | - if ($contestModel->judgeClearance($cid,Auth::user()->id) != 3){ |
|
326 | + if ($contestModel->judgeClearance($cid, Auth::user()->id)!=3) { |
|
327 | 327 | return ResponseModel::err(2001); |
328 | 328 | } |
329 | - if(!is_null(Cache::tags(['contest', 'admin', 'PDFGenerate'])->get($cid))) return ResponseModel::err(8001); |
|
330 | - $generateProcess=new GeneratePDF($cid,$config); |
|
329 | + if (!is_null(Cache::tags(['contest', 'admin', 'PDFGenerate'])->get($cid))) return ResponseModel::err(8001); |
|
330 | + $generateProcess=new GeneratePDF($cid, $config); |
|
331 | 331 | dispatch($generateProcess)->onQueue('normal'); |
332 | 332 | Cache::tags(['contest', 'admin', 'PDFGenerate'])->put($cid, $generateProcess->getJobStatusId()); |
333 | 333 | return ResponseModel::success(200, null, [ |
@@ -340,13 +340,13 @@ discard block |
||
340 | 340 | $request->validate([ |
341 | 341 | "cid"=>"required|integer" |
342 | 342 | ]); |
343 | - $cid = $request->input('cid'); |
|
343 | + $cid=$request->input('cid'); |
|
344 | 344 | $contestModel=new ContestModel(); |
345 | - if ($contestModel->judgeClearance($cid,Auth::user()->id) != 3){ |
|
345 | + if ($contestModel->judgeClearance($cid, Auth::user()->id)!=3) { |
|
346 | 346 | return ResponseModel::err(2001); |
347 | 347 | } |
348 | - if(!is_null(Cache::tags(['contest', 'admin', 'anticheat'])->get($cid))) return ResponseModel::err(8001); |
|
349 | - if(EloquentContestModel::find($cid)->isJudgingComplete()) { |
|
348 | + if (!is_null(Cache::tags(['contest', 'admin', 'anticheat'])->get($cid))) return ResponseModel::err(8001); |
|
349 | + if (EloquentContestModel::find($cid)->isJudgingComplete()) { |
|
350 | 350 | $anticheatProcess=new AntiCheat($cid); |
351 | 351 | dispatch($anticheatProcess)->onQueue('normal'); |
352 | 352 | Cache::tags(['contest', 'admin', 'anticheat'])->put($cid, $anticheatProcess->getJobStatusId()); |
@@ -16,10 +16,10 @@ |
||
16 | 16 | public function view($code) |
17 | 17 | { |
18 | 18 | $detail=Pastebin::where('code', $code)->first(); |
19 | - if(is_null($detail)){ |
|
19 | + if (is_null($detail)) { |
|
20 | 20 | return abort('404'); |
21 | 21 | } |
22 | - if(!is_null($detail->expired_at) && strtotime($detail->expired_at) < strtotime(date("y-m-d h:i:s"))){ |
|
22 | + if (!is_null($detail->expired_at) && strtotime($detail->expired_at)<strtotime(date("y-m-d h:i:s"))) { |
|
23 | 23 | Pastebin::where('code', $code)->delete(); |
24 | 24 | return abort('404'); |
25 | 25 | } |
@@ -143,11 +143,11 @@ discard block |
||
143 | 143 | * |
144 | 144 | * @return Form |
145 | 145 | */ |
146 | - protected function form($create = false) |
|
146 | + protected function form($create=false) |
|
147 | 147 | { |
148 | 148 | $form=new Form(new EloquentProblemModel); |
149 | 149 | $form->model()->makeVisible('password'); |
150 | - $form->tab('Basic', function(Form $form){ |
|
150 | + $form->tab('Basic', function(Form $form) { |
|
151 | 151 | $form->text('pid')->readonly(); |
152 | 152 | $form->text('pcode')->rules('required'); |
153 | 153 | $form->text('title')->rules('required'); |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | $form->simplemde('input'); |
158 | 158 | $form->simplemde('output'); |
159 | 159 | $form->simplemde('note'); |
160 | - $form->hasMany('problemSamples', 'samples', function (Form\NestedForm $form) { |
|
160 | + $form->hasMany('problemSamples', 'samples', function(Form\NestedForm $form) { |
|
161 | 161 | $form->textarea('sample_input', 'sample input')->rows(3); |
162 | 162 | $form->textarea('sample_output', 'sample output')->rows(3); |
163 | 163 | $form->textarea('sample_note', 'sample note')->rows(3); |
@@ -167,10 +167,10 @@ discard block |
||
167 | 167 | $table->textarea('sample_output', 'sample output'); |
168 | 168 | $table->textarea('sample_note', 'sample note'); |
169 | 169 | }); */ |
170 | - $ojs_temp = EloquentOJModel::select('oid', 'name')->get()->all(); |
|
171 | - $ojs = []; |
|
172 | - foreach($ojs_temp as $v){ |
|
173 | - $ojs[$v->oid] = $v->name; |
|
170 | + $ojs_temp=EloquentOJModel::select('oid', 'name')->get()->all(); |
|
171 | + $ojs=[]; |
|
172 | + foreach ($ojs_temp as $v) { |
|
173 | + $ojs[$v->oid]=$v->name; |
|
174 | 174 | } |
175 | 175 | $form->select('oj', 'OJ')->options($ojs)->default(1)->rules('required'); |
176 | 176 | $form->select('Hide')->options([ |
@@ -194,12 +194,12 @@ discard block |
||
194 | 194 | ->options([ |
195 | 195 | 0 => 'NO', |
196 | 196 | 1 => 'YES', |
197 | - ])->when(0, function (Form $form) { |
|
198 | - })->when(1, function (Form $form) { |
|
197 | + ])->when(0, function(Form $form) { |
|
198 | + })->when(1, function(Form $form) { |
|
199 | 199 | // $form->clang('spj_src','SPJ Source Code')->rules('required'); |
200 | 200 | // Admin::script("CodeMirror.fromTextArea(document.getElementById(\"spj_src\"), {'mode':'text/x-csrc','lineNumbers':true,'matchBrackets':true});"); |
201 | 201 | })->rules('required'); |
202 | - $form->clang('spj_src','SPJ Source Code'); |
|
202 | + $form->clang('spj_src', 'SPJ Source Code'); |
|
203 | 203 | $form->file('test_case')->rules('required'); |
204 | 204 | $form->ignore(['test_case']); |
205 | 205 | }); |
@@ -208,107 +208,107 @@ discard block |
||
208 | 208 | $tools->append('<a href="/'.config('admin.route.prefix').'/problems/import" class="btn btn-sm btn-success" style="margin-right:1rem"><i class="MDI file-powerpoint-box"></i> Import from file</a>'); |
209 | 209 | }); |
210 | 210 | } */ |
211 | - $form->saving(function (Form $form){ |
|
212 | - $err = function ($msg) { |
|
213 | - $error = new MessageBag([ |
|
211 | + $form->saving(function(Form $form) { |
|
212 | + $err=function($msg) { |
|
213 | + $error=new MessageBag([ |
|
214 | 214 | 'title' => 'Test case file parse faild.', |
215 | 215 | 'message' => $msg, |
216 | 216 | ]); |
217 | 217 | return back()->with(compact('error')); |
218 | 218 | }; |
219 | - $pcode = $form->pcode; |
|
220 | - $p = EloquentProblemModel::where('pcode',$pcode)->first(); |
|
221 | - $pid = $form->pid ?? null; |
|
222 | - if(!empty($p) && $p->pid != $pid){ |
|
223 | - $error = new MessageBag([ |
|
219 | + $pcode=$form->pcode; |
|
220 | + $p=EloquentProblemModel::where('pcode', $pcode)->first(); |
|
221 | + $pid=$form->pid ?? null; |
|
222 | + if (!empty($p) && $p->pid!=$pid) { |
|
223 | + $error=new MessageBag([ |
|
224 | 224 | 'title' => 'Error occur.', |
225 | 225 | 'message' => 'Pcode has been token', |
226 | 226 | ]); |
227 | 227 | return back()->with(compact('error')); |
228 | 228 | } |
229 | - $test_case = \request()->file('test_case'); |
|
230 | - if(!empty($test_case)){ |
|
231 | - if($test_case->extension() != 'zip'){ |
|
229 | + $test_case=\request()->file('test_case'); |
|
230 | + if (!empty($test_case)) { |
|
231 | + if ($test_case->extension()!='zip') { |
|
232 | 232 | $err('You must upload a zip file iuclude test case info and content.'); |
233 | 233 | } |
234 | - $path = $test_case->path(); |
|
235 | - $zip = new ZipArchive; |
|
236 | - if($zip->open($path) !== true) { |
|
234 | + $path=$test_case->path(); |
|
235 | + $zip=new ZipArchive; |
|
236 | + if ($zip->open($path)!==true) { |
|
237 | 237 | $err('You must upload a zip file without encrypt and can open successfully.'); |
238 | 238 | }; |
239 | - $info_content = []; |
|
240 | - if(($zip->getFromName('info')) === false){ |
|
241 | - $info_content = [ |
|
239 | + $info_content=[]; |
|
240 | + if (($zip->getFromName('info'))===false) { |
|
241 | + $info_content=[ |
|
242 | 242 | 'spj' => false, |
243 | 243 | 'test_cases' => [] |
244 | 244 | ]; |
245 | - $files = []; |
|
246 | - for ($i = 0; $i < $zip->numFiles; $i++) { |
|
247 | - $filename = $zip->getNameIndex($i); |
|
248 | - $files[] = $filename; |
|
245 | + $files=[]; |
|
246 | + for ($i=0; $i<$zip->numFiles; $i++) { |
|
247 | + $filename=$zip->getNameIndex($i); |
|
248 | + $files[]=$filename; |
|
249 | 249 | } |
250 | - $files_in = array_filter($files, function ($filename) { |
|
251 | - return strpos('.in', $filename) != -1; |
|
250 | + $files_in=array_filter($files, function($filename) { |
|
251 | + return strpos('.in', $filename)!=-1; |
|
252 | 252 | }); |
253 | 253 | sort($files_in); |
254 | - $testcase_index = 1; |
|
255 | - foreach($files_in as $filename_in){ |
|
256 | - $filename = basename($filename_in, '.in'); |
|
257 | - $filename_out = $filename.'.out'; |
|
258 | - if(($zip->getFromName($filename_out)) === false) { |
|
254 | + $testcase_index=1; |
|
255 | + foreach ($files_in as $filename_in) { |
|
256 | + $filename=basename($filename_in, '.in'); |
|
257 | + $filename_out=$filename.'.out'; |
|
258 | + if (($zip->getFromName($filename_out))===false) { |
|
259 | 259 | continue; |
260 | 260 | } |
261 | - $test_case_in = $zip->getFromName($filename_in); |
|
262 | - $test_case_out = $zip->getFromName($filename_out); |
|
263 | - $info_content['test_cases']["{$testcase_index}"] = [ |
|
261 | + $test_case_in=$zip->getFromName($filename_in); |
|
262 | + $test_case_out=$zip->getFromName($filename_out); |
|
263 | + $info_content['test_cases']["{$testcase_index}"]=[ |
|
264 | 264 | 'input_size' => strlen($test_case_in), |
265 | 265 | 'input_name' => $filename_in, |
266 | 266 | 'output_size' => strlen($test_case_out), |
267 | 267 | 'output_name' => $filename_out, |
268 | 268 | 'stripped_output_md5' => md5(utf8_encode(rtrim($test_case_out))) |
269 | 269 | ]; |
270 | - $testcase_index += 1; |
|
270 | + $testcase_index+=1; |
|
271 | 271 | } |
272 | 272 | $zip->addFromString('info', json_encode($info_content)); |
273 | 273 | $zip->close(); |
274 | 274 | //$err('The zip files must include a file named info including info of test cases, and the format can see ZsgsDesign/NOJ wiki.'); |
275 | - }else{ |
|
276 | - $info_content = json_decode($zip->getFromName('info'),true); |
|
275 | + } else { |
|
276 | + $info_content=json_decode($zip->getFromName('info'), true); |
|
277 | 277 | }; |
278 | 278 | $zip->open($path); |
279 | - $test_cases = $info_content['test_cases']; |
|
280 | - foreach($test_cases as $index => $case) { |
|
281 | - if(!isset($case['input_name']) || !isset($case['output_name'])) { |
|
279 | + $test_cases=$info_content['test_cases']; |
|
280 | + foreach ($test_cases as $index => $case) { |
|
281 | + if (!isset($case['input_name']) || !isset($case['output_name'])) { |
|
282 | 282 | $err("Test case index {$index}: configuration missing input/output files name."); |
283 | 283 | } |
284 | - if($zip->getFromName($case['input_name']) === false || $zip->getFromName($case['output_name']) === false ) { |
|
284 | + if ($zip->getFromName($case['input_name'])===false || $zip->getFromName($case['output_name'])===false) { |
|
285 | 285 | $err("Test case index {$index}: missing input/output files that record in the configuration."); |
286 | 286 | } |
287 | 287 | } |
288 | - if(!empty($form->pid)){ |
|
289 | - $problem = EloquentProblemModel::find($form->pid); |
|
290 | - if(!empty($problem)){ |
|
291 | - $pcode = $problem->pcode; |
|
292 | - }else{ |
|
293 | - $pcode = $form->pcode; |
|
288 | + if (!empty($form->pid)) { |
|
289 | + $problem=EloquentProblemModel::find($form->pid); |
|
290 | + if (!empty($problem)) { |
|
291 | + $pcode=$problem->pcode; |
|
292 | + } else { |
|
293 | + $pcode=$form->pcode; |
|
294 | 294 | } |
295 | - }else{ |
|
296 | - $pcode = $form->pcode; |
|
295 | + } else { |
|
296 | + $pcode=$form->pcode; |
|
297 | 297 | } |
298 | 298 | |
299 | - if(Storage::exists(base_path().'/storage/test_case/'.$pcode)){ |
|
299 | + if (Storage::exists(base_path().'/storage/test_case/'.$pcode)) { |
|
300 | 300 | Storage::deleteDirectory(base_path().'/storage/test_case/'.$pcode); |
301 | 301 | } |
302 | 302 | Storage::makeDirectory(base_path().'/storage/test_case/'.$pcode); |
303 | 303 | $zip->extractTo(base_path().'/storage/test_case/'.$pcode.'/'); |
304 | 304 | |
305 | 305 | } |
306 | - $form->markdown = true; |
|
307 | - $form->input_type = 'standard input'; |
|
308 | - $form->output_type = 'standard output'; |
|
309 | - $form->solved_count = 0; |
|
310 | - $form->difficulty = -1; |
|
311 | - $form->file = 0; |
|
306 | + $form->markdown=true; |
|
307 | + $form->input_type='standard input'; |
|
308 | + $form->output_type='standard output'; |
|
309 | + $form->solved_count=0; |
|
310 | + $form->difficulty=-1; |
|
311 | + $form->file=0; |
|
312 | 312 | }); |
313 | 313 | return $form; |
314 | 314 | } |
@@ -22,13 +22,13 @@ discard block |
||
22 | 22 | $ret=[]; |
23 | 23 | $marketspaceRaw=self::getRemote(); |
24 | 24 | $marketspace=[]; |
25 | - foreach($marketspaceRaw["packages"] as $extension){ |
|
25 | + foreach ($marketspaceRaw["packages"] as $extension) { |
|
26 | 26 | $marketspace[$extension["name"]]=$extension; |
27 | 27 | } |
28 | 28 | |
29 | 29 | $localList=self::getLocal(); |
30 | 30 | |
31 | - foreach($localList as $extension){ |
|
31 | + foreach ($localList as $extension) { |
|
32 | 32 | $temp=[ |
33 | 33 | "details"=>$extension, |
34 | 34 | "status"=>0, |
@@ -37,30 +37,30 @@ discard block |
||
37 | 37 | "settings"=>null, |
38 | 38 | "available"=>null |
39 | 39 | ]; |
40 | - $temp["details"]["typeParsed"]=$temp["details"]["type"]=="virtual-judge"?"VirtualJudge":"OnlineJudge"; |
|
40 | + $temp["details"]["typeParsed"]=$temp["details"]["type"]=="virtual-judge" ? "VirtualJudge" : "OnlineJudge"; |
|
41 | 41 | try { |
42 | 42 | if ($extension["version"]=='__cur__') { |
43 | 43 | $extension["version"]=explode("-", version())[0]; |
44 | 44 | } |
45 | 45 | $downloadedVersion=new Version($extension["version"]); |
46 | 46 | |
47 | - if(isset($marketspace[$extension["name"]])){ |
|
47 | + if (isset($marketspace[$extension["name"]])) { |
|
48 | 48 | //remote extension, else is local extension |
49 | 49 | $remoteVersion=new Version($marketspace[$extension["name"]]["version"]); |
50 | 50 | $temp["updatable"]=$remoteVersion->isGreaterThan($downloadedVersion); |
51 | 51 | $temp["details"]["official"]=$marketspace[$extension["name"]]["official"]; |
52 | - } else{ |
|
52 | + } else { |
|
53 | 53 | $temp["updatable"]=false; |
54 | 54 | $temp["details"]["official"]=0; |
55 | 55 | } |
56 | 56 | |
57 | 57 | $installedConfig=OJ::where(["ocode"=>$extension["code"]])->first(); |
58 | - if (is_null($installedConfig)){ |
|
58 | + if (is_null($installedConfig)) { |
|
59 | 59 | $temp["status"]=1; |
60 | 60 | } else { |
61 | 61 | $temp["version"]=$installedConfig->version; // local installed version |
62 | 62 | $installedVersion=new Version($temp["version"]); |
63 | - if ($downloadedVersion->isGreaterThan($installedVersion)){ |
|
63 | + if ($downloadedVersion->isGreaterThan($installedVersion)) { |
|
64 | 64 | $temp["status"]=1; |
65 | 65 | } else { |
66 | 66 | $temp["status"]=2; |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | $temp["settings"]=false; |
69 | 69 | $temp["available"]=$installedConfig->status; |
70 | 70 | } |
71 | - }catch (Throwable $e){ |
|
71 | + } catch (Throwable $e) { |
|
72 | 72 | continue; |
73 | 73 | } |
74 | 74 | $ret[]=$temp; |
@@ -80,8 +80,8 @@ discard block |
||
80 | 80 | { |
81 | 81 | $ret=[]; |
82 | 82 | $marketspaceRaw=self::getRemote(); |
83 | - if(empty($marketspaceRaw)) return []; |
|
84 | - foreach($marketspaceRaw["packages"] as $extension){ |
|
83 | + if (empty($marketspaceRaw)) return []; |
|
84 | + foreach ($marketspaceRaw["packages"] as $extension) { |
|
85 | 85 | $temp=[ |
86 | 86 | "details"=>$extension, |
87 | 87 | "status"=>0, |
@@ -90,11 +90,11 @@ discard block |
||
90 | 90 | "settings"=>null, |
91 | 91 | "available"=>null |
92 | 92 | ]; |
93 | - $temp["details"]["typeParsed"]=$temp["details"]["type"]=="virtual-judge"?"VirtualJudge":"OnlineJudge"; |
|
93 | + $temp["details"]["typeParsed"]=$temp["details"]["type"]=="virtual-judge" ? "VirtualJudge" : "OnlineJudge"; |
|
94 | 94 | try { |
95 | 95 | try { |
96 | 96 | $BabelConfig=json_decode(file_get_contents(babel_path("Extension/{$extension['code']}/babel.json")), true); |
97 | - }catch (Throwable $e){ |
|
97 | + } catch (Throwable $e) { |
|
98 | 98 | $BabelConfig=[]; |
99 | 99 | } |
100 | 100 | if (!empty($BabelConfig)) { |
@@ -106,12 +106,12 @@ discard block |
||
106 | 106 | $temp["updatable"]=$remoteVersion->isGreaterThan($downloadedVersion); |
107 | 107 | |
108 | 108 | $installedConfig=OJ::where(["ocode"=>$extension["code"]])->first(); |
109 | - if (is_null($installedConfig)){ |
|
109 | + if (is_null($installedConfig)) { |
|
110 | 110 | $temp["status"]=1; |
111 | 111 | } else { |
112 | 112 | $temp["version"]=$installedConfig->version; // local installed version |
113 | 113 | $installedVersion=new Version($temp["version"]); |
114 | - if ($downloadedVersion->isGreaterThan($installedVersion)){ |
|
114 | + if ($downloadedVersion->isGreaterThan($installedVersion)) { |
|
115 | 115 | $temp["status"]=1; |
116 | 116 | } else { |
117 | 117 | $temp["status"]=2; |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | $temp["available"]=$installedConfig->status; |
121 | 121 | } |
122 | 122 | } |
123 | - }catch (Throwable $e){ |
|
123 | + } catch (Throwable $e) { |
|
124 | 124 | continue; |
125 | 125 | } |
126 | 126 | $ret[]=$temp; |
@@ -132,11 +132,11 @@ discard block |
||
132 | 132 | public static function getLocal() |
133 | 133 | { |
134 | 134 | $ret=[]; |
135 | - $dirs = array_filter(glob(babel_path("Extension/*")), 'is_dir'); |
|
136 | - foreach($dirs as $d){ |
|
135 | + $dirs=array_filter(glob(babel_path("Extension/*")), 'is_dir'); |
|
136 | + foreach ($dirs as $d) { |
|
137 | 137 | $extension=basename($d); |
138 | 138 | $BabelConfig=json_decode(file_get_contents(babel_path("Extension/$extension/babel.json")), true); |
139 | - if($extension==$BabelConfig["code"]) $ret[]=$BabelConfig; |
|
139 | + if ($extension==$BabelConfig["code"]) $ret[]=$BabelConfig; |
|
140 | 140 | } |
141 | 141 | return $ret; |
142 | 142 | } |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | { |
146 | 146 | try { |
147 | 147 | return json_decode(file_get_contents(config('babel.mirror')."/babel.json"), true); |
148 | - }catch(Throwable $e){ |
|
148 | + } catch (Throwable $e) { |
|
149 | 149 | return []; |
150 | 150 | } |
151 | 151 | } |
@@ -153,10 +153,10 @@ discard block |
||
153 | 153 | public static function remoteDetail($code) |
154 | 154 | { |
155 | 155 | $babelConfig=self::getRemote(); |
156 | - if(empty($babelConfig)) return []; |
|
156 | + if (empty($babelConfig)) return []; |
|
157 | 157 | $babelConfigPackages=$babelConfig["packages"]; |
158 | - foreach($babelConfigPackages as $package) { |
|
159 | - if($package["code"]==$code) return $package; |
|
158 | + foreach ($babelConfigPackages as $package) { |
|
159 | + if ($package["code"]==$code) return $package; |
|
160 | 160 | } |
161 | 161 | return []; |
162 | 162 | } |