@@ -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 | } |
@@ -272,7 +272,7 @@ discard block |
||
| 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{ |
|
| 275 | + } else{ |
|
| 276 | 276 | $info_content = json_decode($zip->getFromName('info'),true); |
| 277 | 277 | }; |
| 278 | 278 | $zip->open($path); |
@@ -289,10 +289,10 @@ discard block |
||
| 289 | 289 | $problem = EloquentProblemModel::find($form->pid); |
| 290 | 290 | if(!empty($problem)){ |
| 291 | 291 | $pcode = $problem->pcode; |
| 292 | - }else{ |
|
| 292 | + } else{ |
|
| 293 | 293 | $pcode = $form->pcode; |
| 294 | 294 | } |
| 295 | - }else{ |
|
| 295 | + } else{ |
|
| 296 | 296 | $pcode = $form->pcode; |
| 297 | 297 | } |
| 298 | 298 | |
@@ -17,17 +17,17 @@ |
||
| 17 | 17 | |
| 18 | 18 | public function submissions() |
| 19 | 19 | { |
| 20 | - return $this->hasMany('App\Models\Eloquent\Submission','pid','pid'); |
|
| 20 | + return $this->hasMany('App\Models\Eloquent\Submission', 'pid', 'pid'); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | public function problemSamples() |
| 24 | 24 | { |
| 25 | - return $this->hasMany('App\Models\Eloquent\ProblemSample','pid','pid'); |
|
| 25 | + return $this->hasMany('App\Models\Eloquent\ProblemSample', 'pid', 'pid'); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | public function getProblemStatusAttribute() |
| 29 | 29 | { |
| 30 | - if(Auth::check()){ |
|
| 30 | + if (Auth::check()) { |
|
| 31 | 31 | $prob_status=(new OutdatedSubmissionModel())->getProblemStatus($this->pid, Auth::user()->id); |
| 32 | 32 | if (empty($prob_status)) { |
| 33 | 33 | return [ |
@@ -7,8 +7,8 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Pastebin extends Model |
| 9 | 9 | { |
| 10 | - protected $table = 'pastebin'; |
|
| 11 | - protected $primaryKey = 'pbid'; |
|
| 10 | + protected $table='pastebin'; |
|
| 11 | + protected $primaryKey='pbid'; |
|
| 12 | 12 | |
| 13 | 13 | protected $fillable=[ |
| 14 | 14 | 'lang', 'title', 'user_id', 'expired_at', 'content', 'code' |
@@ -8,9 +8,9 @@ |
||
| 8 | 8 | { |
| 9 | 9 | protected $table='problem_sample'; |
| 10 | 10 | protected $primaryKey='psid'; |
| 11 | - protected $fillable = ['sample_input', 'sample_output']; |
|
| 11 | + protected $fillable=['sample_input', 'sample_output']; |
|
| 12 | 12 | |
| 13 | 13 | public function problem() { |
| 14 | - return $this->belongTo('App\Models\Eloquent\Problem','pid','pid'); |
|
| 14 | + return $this->belongTo('App\Models\Eloquent\Problem', 'pid', 'pid'); |
|
| 15 | 15 | } |
| 16 | 16 | } |