|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Models\Submission; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
6
|
|
|
use Illuminate\Support\Facades\DB; |
|
7
|
|
|
use App\Models\ContestModel; |
|
8
|
|
|
use App\Models\CompilerModel; |
|
9
|
|
|
|
|
10
|
|
|
class SubmissionModel extends Model |
|
11
|
|
|
{ |
|
12
|
|
|
protected $tableName='submission'; |
|
13
|
|
|
protected $table='submission'; |
|
14
|
|
|
protected $primaryKey='sid'; |
|
15
|
|
|
protected $extractModels=[ |
|
16
|
|
|
"ShareModel"=>null, |
|
17
|
|
|
"StatusModel"=>null |
|
18
|
|
|
]; |
|
19
|
|
|
const DELETED_AT=null; |
|
20
|
|
|
const UPDATED_AT=null; |
|
21
|
|
|
const CREATED_AT=null; |
|
22
|
|
|
|
|
23
|
|
|
public $colorScheme=[ |
|
24
|
|
|
"Waiting" => "wemd-blue-text", |
|
25
|
|
|
"Judge Error" => "wemd-black-text", |
|
26
|
|
|
"System Error" => "wemd-black-text", |
|
27
|
|
|
"Compile Error" => "wemd-orange-text", |
|
28
|
|
|
"Runtime Error" => "wemd-red-text", |
|
29
|
|
|
"Wrong Answer" => "wemd-red-text", |
|
30
|
|
|
"Time Limit Exceed" => "wemd-deep-purple-text", |
|
31
|
|
|
"Real Time Limit Exceed" => "wemd-deep-purple-text", |
|
32
|
|
|
"Accepted" => "wemd-green-text", |
|
33
|
|
|
"Memory Limit Exceed" => "wemd-deep-purple-text", |
|
34
|
|
|
"Presentation Error" => "wemd-red-text", |
|
35
|
|
|
"Submitted" => "wemd-blue-text", |
|
36
|
|
|
"Pending" => "wemd-blue-text", |
|
37
|
|
|
"Judging" => "wemd-blue-text", |
|
38
|
|
|
"Partially Accepted" => "wemd-cyan-text", |
|
39
|
|
|
'Submission Error' => 'wemd-black-text', |
|
40
|
|
|
'Output Limit Exceeded' => 'wemd-deep-purple-text', |
|
41
|
|
|
"Idleness Limit Exceed" => 'wemd-deep-purple-text' |
|
42
|
|
|
]; |
|
43
|
|
|
public $langConfig=[]; |
|
44
|
|
|
|
|
45
|
|
|
public function __construct() |
|
46
|
|
|
{ |
|
47
|
|
|
$this->extractModels["ShareNodel"]=new ShareModel($this); |
|
48
|
|
|
$this->extractModels["StatusModel"]=new StatusModel($this); |
|
49
|
|
|
$tempLangConfig=[[ |
|
50
|
|
|
"id" => "plaintext", |
|
51
|
|
|
"extensions" => [".txt", ".gitignore"], |
|
52
|
|
|
"aliases" => ["Plain Text", "text"], |
|
53
|
|
|
"mimetypes" => ["text/plain"] |
|
54
|
|
|
], [ |
|
55
|
|
|
"id" => "json", |
|
56
|
|
|
"extensions" => [".json", ".bowerrc", ".jshintrc", ".jscsrc", ".eslintrc", ".babelrc"], |
|
57
|
|
|
"aliases" => ["JSON", "json"], |
|
58
|
|
|
"mimetypes" => ["application/json"] |
|
59
|
|
|
], [ |
|
60
|
|
|
"id" => "bat", |
|
61
|
|
|
"extensions" => [".bat", ".cmd"], |
|
62
|
|
|
"aliases" => ["Batch", "bat"] |
|
63
|
|
|
], [ |
|
64
|
|
|
"id" => "coffeescript", |
|
65
|
|
|
"extensions" => [".coffee"], |
|
66
|
|
|
"aliases" => ["CoffeeScript", "coffeescript", "coffee"], |
|
67
|
|
|
"mimetypes" => ["text/x-coffeescript", "text/coffeescript"] |
|
68
|
|
|
], [ |
|
69
|
|
|
"id" => "c", |
|
70
|
|
|
"extensions" => [".c", ".h"], |
|
71
|
|
|
"aliases" => ["C", "c"] |
|
72
|
|
|
], [ |
|
73
|
|
|
"id" => "cpp", |
|
74
|
|
|
"extensions" => [".cpp", ".cc", ".cxx", ".hpp", ".hh", ".hxx"], |
|
75
|
|
|
"aliases" => ["C++", "Cpp", "cpp"] |
|
76
|
|
|
], [ |
|
77
|
|
|
"id" => "csharp", |
|
78
|
|
|
"extensions" => [".cs", ".csx", ".cake"], |
|
79
|
|
|
"aliases" => ["C#", "csharp"] |
|
80
|
|
|
], [ |
|
81
|
|
|
"id" => "csp", |
|
82
|
|
|
"extensions" => [], |
|
83
|
|
|
"aliases" => ["CSP", "csp"] |
|
84
|
|
|
], [ |
|
85
|
|
|
"id" => "css", |
|
86
|
|
|
"extensions" => [".css"], |
|
87
|
|
|
"aliases" => ["CSS", "css"], |
|
88
|
|
|
"mimetypes" => ["text/css"] |
|
89
|
|
|
], [ |
|
90
|
|
|
"id" => "dockerfile", |
|
91
|
|
|
"extensions" => [".dockerfile"], |
|
92
|
|
|
"filenames" => ["Dockerfile"], |
|
93
|
|
|
"aliases" => ["Dockerfile"] |
|
94
|
|
|
], [ |
|
95
|
|
|
"id" => "fsharp", |
|
96
|
|
|
"extensions" => [".fs", ".fsi", ".ml", ".mli", ".fsx", ".fsscript"], |
|
97
|
|
|
"aliases" => ["F#", "FSharp", "fsharp"] |
|
98
|
|
|
], [ |
|
99
|
|
|
"id" => "go", |
|
100
|
|
|
"extensions" => [".go"], |
|
101
|
|
|
"aliases" => ["Go"] |
|
102
|
|
|
], [ |
|
103
|
|
|
"id" => "handlebars", |
|
104
|
|
|
"extensions" => [".handlebars", ".hbs"], |
|
105
|
|
|
"aliases" => ["Handlebars", "handlebars"], |
|
106
|
|
|
"mimetypes" => ["text/x-handlebars-template"] |
|
107
|
|
|
], [ |
|
108
|
|
|
"id" => "html", |
|
109
|
|
|
"extensions" => [".html", ".htm", ".shtml", ".xhtml", ".mdoc", ".jsp", ".asp", ".aspx", ".jshtm"], |
|
110
|
|
|
"aliases" => ["HTML", "htm", "html", "xhtml"], |
|
111
|
|
|
"mimetypes" => ["text/html", "text/x-jshtm", "text/template", "text/ng-template"] |
|
112
|
|
|
], [ |
|
113
|
|
|
"id" => "ini", |
|
114
|
|
|
"extensions" => [".ini", ".properties", ".gitconfig"], |
|
115
|
|
|
"filenames" => ["config", ".gitattributes", ".gitconfig", ".editorconfig"], |
|
116
|
|
|
"aliases" => ["Ini", "ini"] |
|
117
|
|
|
], [ |
|
118
|
|
|
"id" => "java", |
|
119
|
|
|
"extensions" => [".java", ".jav"], |
|
120
|
|
|
"aliases" => ["Java", "java"], |
|
121
|
|
|
"mimetypes" => ["text/x-java-source", "text/x-java"] |
|
122
|
|
|
], [ |
|
123
|
|
|
"id" => "javascript", |
|
124
|
|
|
"extensions" => [".js", ".es6", ".jsx"], |
|
125
|
|
|
"firstLine" => "^#!.*\\bnode", |
|
126
|
|
|
"filenames" => ["jakefile"], |
|
127
|
|
|
"aliases" => ["JavaScript", "javascript", "js"], |
|
128
|
|
|
"mimetypes" => ["text/javascript"] |
|
129
|
|
|
], [ |
|
130
|
|
|
"id" => "less", |
|
131
|
|
|
"extensions" => [".less"], |
|
132
|
|
|
"aliases" => ["Less", "less"], |
|
133
|
|
|
"mimetypes" => ["text/x-less", "text/less"] |
|
134
|
|
|
], [ |
|
135
|
|
|
"id" => "lua", |
|
136
|
|
|
"extensions" => [".lua"], |
|
137
|
|
|
"aliases" => ["Lua", "lua"] |
|
138
|
|
|
], [ |
|
139
|
|
|
"id" => "markdown", |
|
140
|
|
|
"extensions" => [".md", ".markdown", ".mdown", ".mkdn", ".mkd", ".mdwn", ".mdtxt", ".mdtext"], |
|
141
|
|
|
"aliases" => ["Markdown", "markdown"] |
|
142
|
|
|
], [ |
|
143
|
|
|
"id" => "msdax", |
|
144
|
|
|
"extensions" => [".dax", ".msdax"], |
|
145
|
|
|
"aliases" => ["DAX", "MSDAX"] |
|
146
|
|
|
], [ |
|
147
|
|
|
"id" => "mysql", |
|
148
|
|
|
"extensions" => [], |
|
149
|
|
|
"aliases" => ["MySQL", "mysql"] |
|
150
|
|
|
], [ |
|
151
|
|
|
"id" => "objective-c", |
|
152
|
|
|
"extensions" => [".m"], |
|
153
|
|
|
"aliases" => ["Objective-C"] |
|
154
|
|
|
], [ |
|
155
|
|
|
"id" => "pgsql", |
|
156
|
|
|
"extensions" => [], |
|
157
|
|
|
"aliases" => ["PostgreSQL", "postgres", "pg", "postgre"] |
|
158
|
|
|
], [ |
|
159
|
|
|
"id" => "php", |
|
160
|
|
|
"extensions" => [".php", ".php4", ".php5", ".phtml", ".ctp"], |
|
161
|
|
|
"aliases" => ["PHP", "php"], |
|
162
|
|
|
"mimetypes" => ["application/x-php"] |
|
163
|
|
|
], [ |
|
164
|
|
|
"id" => "postiats", |
|
165
|
|
|
"extensions" => [".dats", ".sats", ".hats"], |
|
166
|
|
|
"aliases" => ["ATS", "ATS/Postiats"] |
|
167
|
|
|
], [ |
|
168
|
|
|
"id" => "powerquery", |
|
169
|
|
|
"extensions" => [".pq", ".pqm"], |
|
170
|
|
|
"aliases" => ["PQ", "M", "Power Query", "Power Query M"] |
|
171
|
|
|
], [ |
|
172
|
|
|
"id" => "powershell", |
|
173
|
|
|
"extensions" => [".ps1", ".psm1", ".psd1"], |
|
174
|
|
|
"aliases" => ["PowerShell", "powershell", "ps", "ps1"] |
|
175
|
|
|
], [ |
|
176
|
|
|
"id" => "pug", |
|
177
|
|
|
"extensions" => [".jade", ".pug"], |
|
178
|
|
|
"aliases" => ["Pug", "Jade", "jade"] |
|
179
|
|
|
], [ |
|
180
|
|
|
"id" => "python", |
|
181
|
|
|
"extensions" => [".py", ".rpy", ".pyw", ".cpy", ".gyp", ".gypi"], |
|
182
|
|
|
"aliases" => ["Python", "py"], |
|
183
|
|
|
"firstLine" => "^#!/.*\\bpython[0-9.-]*\\b" |
|
184
|
|
|
], [ |
|
185
|
|
|
"id" => "r", |
|
186
|
|
|
"extensions" => [".r", ".rhistory", ".rprofile", ".rt"], |
|
187
|
|
|
"aliases" => ["R", "r"] |
|
188
|
|
|
], [ |
|
189
|
|
|
"id" => "razor", |
|
190
|
|
|
"extensions" => [".cshtml"], |
|
191
|
|
|
"aliases" => ["Razor", "razor"], |
|
192
|
|
|
"mimetypes" => ["text/x-cshtml"] |
|
193
|
|
|
], [ |
|
194
|
|
|
"id" => "redis", |
|
195
|
|
|
"extensions" => [".redis"], |
|
196
|
|
|
"aliases" => ["redis"] |
|
197
|
|
|
], [ |
|
198
|
|
|
"id" => "redshift", |
|
199
|
|
|
"extensions" => [], |
|
200
|
|
|
"aliases" => ["Redshift", "redshift"] |
|
201
|
|
|
], [ |
|
202
|
|
|
"id" => "ruby", |
|
203
|
|
|
"extensions" => [".rb", ".rbx", ".rjs", ".gemspec", ".pp"], |
|
204
|
|
|
"filenames" => ["rakefile"], |
|
205
|
|
|
"aliases" => ["Ruby", "rb"] |
|
206
|
|
|
], [ |
|
207
|
|
|
"id" => "rust", |
|
208
|
|
|
"extensions" => [".rs", ".rlib"], |
|
209
|
|
|
"aliases" => ["Rust", "rust"] |
|
210
|
|
|
], [ |
|
211
|
|
|
"id" => "sb", |
|
212
|
|
|
"extensions" => [".sb"], |
|
213
|
|
|
"aliases" => ["Small Basic", "sb"] |
|
214
|
|
|
], [ |
|
215
|
|
|
"id" => "scss", |
|
216
|
|
|
"extensions" => [".scss"], |
|
217
|
|
|
"aliases" => ["Sass", "sass", "scss"], |
|
218
|
|
|
"mimetypes" => ["text/x-scss", "text/scss"] |
|
219
|
|
|
], [ |
|
220
|
|
|
"id" => "sol", |
|
221
|
|
|
"extensions" => [".sol"], |
|
222
|
|
|
"aliases" => ["sol", "solidity", "Solidity"] |
|
223
|
|
|
], [ |
|
224
|
|
|
"id" => "sql", |
|
225
|
|
|
"extensions" => [".sql"], |
|
226
|
|
|
"aliases" => ["SQL"] |
|
227
|
|
|
], [ |
|
228
|
|
|
"id" => "st", |
|
229
|
|
|
"extensions" => [".st", ".iecst", ".iecplc", ".lc3lib"], |
|
230
|
|
|
"aliases" => ["StructuredText", "scl", "stl"] |
|
231
|
|
|
], [ |
|
232
|
|
|
"id" => "swift", |
|
233
|
|
|
"aliases" => ["Swift", "swift"], |
|
234
|
|
|
"extensions" => [".swift"], |
|
235
|
|
|
"mimetypes" => ["text/swift"] |
|
236
|
|
|
], [ |
|
237
|
|
|
"id" => "typescript", |
|
238
|
|
|
"extensions" => [".ts", ".tsx"], |
|
239
|
|
|
"aliases" => ["TypeScript", "ts", "typescript"], |
|
240
|
|
|
"mimetypes" => ["text/typescript"] |
|
241
|
|
|
], [ |
|
242
|
|
|
"id" => "vb", |
|
243
|
|
|
"extensions" => [".vb"], |
|
244
|
|
|
"aliases" => ["Visual Basic", "vb"] |
|
245
|
|
|
], [ |
|
246
|
|
|
"id" => "xml", |
|
247
|
|
|
"extensions" => [".xml", ".dtd", ".ascx", ".csproj", ".config", ".wxi", ".wxl", ".wxs", ".xaml", ".svg", ".svgz"], |
|
248
|
|
|
"firstLine" => "(\\<\\?xml.*)|(\\<svg)|(\\<\\!doctype\\s+svg)", |
|
249
|
|
|
"aliases" => ["XML", "xml"], |
|
250
|
|
|
"mimetypes" => ["text/xml", "application/xml", "application/xaml+xml", "application/xml-dtd"] |
|
251
|
|
|
], [ |
|
252
|
|
|
"id" => "yaml", |
|
253
|
|
|
"extensions" => [".yaml", ".yml"], |
|
254
|
|
|
"aliases" => ["YAML", "yaml", "YML", "yml"], |
|
255
|
|
|
"mimetypes" => ["application/x-yaml"] |
|
256
|
|
|
], [ |
|
257
|
|
|
"id" => "scheme", |
|
258
|
|
|
"extensions" => [".scm", ".ss", ".sch", ".rkt"], |
|
259
|
|
|
"aliases" => ["scheme", "Scheme"] |
|
260
|
|
|
], [ |
|
261
|
|
|
"id" => "clojure", |
|
262
|
|
|
"extensions" => [".clj", ".clojure"], |
|
263
|
|
|
"aliases" => ["clojure", "Clojure"] |
|
264
|
|
|
], [ |
|
265
|
|
|
"id" => "shell", |
|
266
|
|
|
"extensions" => [".sh", ".bash"], |
|
267
|
|
|
"aliases" => ["Shell", "sh"] |
|
268
|
|
|
], [ |
|
269
|
|
|
"id" => "perl", |
|
270
|
|
|
"extensions" => [".pl"], |
|
271
|
|
|
"aliases" => ["Perl", "pl"] |
|
272
|
|
|
], [ |
|
273
|
|
|
"id" => "azcli", |
|
274
|
|
|
"extensions" => [".azcli"], |
|
275
|
|
|
"aliases" => ["Azure CLI", "azcli"] |
|
276
|
|
|
], [ |
|
277
|
|
|
"id" => "apex", |
|
278
|
|
|
"extensions" => [".cls"], |
|
279
|
|
|
"aliases" => ["Apex", "apex"], |
|
280
|
|
|
"mimetypes" => ["text/x-apex-source", "text/x-apex"] |
|
281
|
|
|
]]; |
|
282
|
|
|
foreach ($tempLangConfig as $t) { |
|
283
|
|
|
$this->langConfig[$t["id"]]=$t; |
|
284
|
|
|
} |
|
285
|
|
|
} |
|
286
|
|
|
|
|
287
|
|
|
public function insert($sub) |
|
288
|
|
|
{ |
|
289
|
|
|
if (strlen($sub['verdict'])==0) { |
|
290
|
|
|
$sub['verdict']="Judge Error"; |
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
$sid=DB::table($this->tableName)->insertGetId([ |
|
294
|
|
|
'time' => $sub['time'], |
|
295
|
|
|
'verdict' => $sub['verdict'], |
|
296
|
|
|
'solution' => $sub['solution'], |
|
297
|
|
|
'language' => $sub['language'], |
|
298
|
|
|
'submission_date' => $sub['submission_date'], |
|
299
|
|
|
'memory' => $sub['memory'], |
|
300
|
|
|
'uid' => $sub['uid'], |
|
301
|
|
|
'pid' => $sub['pid'], |
|
302
|
|
|
'cid' => $sub['cid'], |
|
303
|
|
|
'color' => $this->colorScheme[$sub['verdict']], |
|
304
|
|
|
'remote_id'=>$sub['remote_id'], |
|
305
|
|
|
'compile_info'=>"", |
|
306
|
|
|
'coid'=>$sub['coid'], |
|
307
|
|
|
'score'=>$sub['score'] |
|
308
|
|
|
]); |
|
309
|
|
|
|
|
310
|
|
|
return $sid; |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
|
|
public function basic($sid) |
|
314
|
|
|
{ |
|
315
|
|
|
return DB::table($this->tableName)->where(['sid'=>$sid])->first(); |
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
|
public function getJudgeStatus($sid, $uid) |
|
319
|
|
|
{ |
|
320
|
|
|
return $this->extractModels["StatusModel"]->getJudgeStatus($sid, $uid); |
|
321
|
|
|
} |
|
322
|
|
|
|
|
323
|
|
|
public function downloadCode($sid, $uid) |
|
324
|
|
|
{ |
|
325
|
|
|
return $this->extractModels["StatusModel"]->downloadCode($sid, $uid); |
|
326
|
|
|
} |
|
327
|
|
|
|
|
328
|
|
|
public function getProblemStatus($pid, $uid, $cid=null) |
|
329
|
|
|
{ |
|
330
|
|
|
return $this->extractModels["StatusModel"]->getProblaemStatus($pid, $uid, $cid); |
|
331
|
|
|
} |
|
332
|
|
|
|
|
333
|
|
|
public function getProblemSubmission($pid, $uid, $cid=null) |
|
334
|
|
|
{ |
|
335
|
|
|
$statusList=DB::table($this->tableName)->where(['pid'=>$pid, 'uid'=>$uid, 'cid'=>$cid])->orderBy('submission_date', 'desc')->limit(10)->get()->all(); |
|
336
|
|
|
return $statusList; |
|
337
|
|
|
} |
|
338
|
|
|
|
|
339
|
|
|
public function countSolution($s) |
|
340
|
|
|
{ |
|
341
|
|
|
return DB::table($this->tableName)->where(['solution'=>$s])->count(); |
|
342
|
|
|
} |
|
343
|
|
|
|
|
344
|
|
|
public function getEarliestSubmission($oid) |
|
345
|
|
|
{ |
|
346
|
|
|
return DB::table($this->tableName) ->join('problem', 'problem.pid', '=', 'submission.pid') |
|
347
|
|
|
->select("sid", "OJ as oid", "remote_id", "cid", "jid") |
|
348
|
|
|
->where(['verdict'=>'Waiting', 'OJ'=>$oid]) |
|
349
|
|
|
->orderBy("sid", "asc") |
|
350
|
|
|
->first(); |
|
351
|
|
|
} |
|
352
|
|
|
|
|
353
|
|
|
public function countEarliestWaitingSubmission($oid) |
|
354
|
|
|
{ |
|
355
|
|
|
$early_sid=$this->getEarliestSubmission($oid); |
|
356
|
|
|
if ($early_sid==null) { |
|
357
|
|
|
return 0; |
|
358
|
|
|
} |
|
359
|
|
|
$early_sid=$early_sid["sid"]; |
|
360
|
|
|
return DB::table($this->tableName) ->join('problem', 'problem.pid', '=', 'submission.pid') |
|
361
|
|
|
->where(['OJ'=>$oid]) |
|
362
|
|
|
->where("sid", ">=", $early_sid) |
|
363
|
|
|
->count(); |
|
364
|
|
|
} |
|
365
|
|
|
|
|
366
|
|
|
|
|
367
|
|
|
public function getWaitingSubmission() |
|
368
|
|
|
{ |
|
369
|
|
|
$ret=DB::table($this->tableName) ->join('problem', 'problem.pid', '=', 'submission.pid') |
|
370
|
|
|
->select("sid", "OJ as oid", "remote_id", "cid", "jid", "vcid", "problem.pid as pid") |
|
371
|
|
|
->where(['verdict'=>'Waiting']) |
|
372
|
|
|
->get() |
|
373
|
|
|
->all(); |
|
374
|
|
|
foreach($ret as &$r){ |
|
375
|
|
|
$r["ocode"]=DB::table("oj")->where(["oid"=>$r["oid"]])->first()["ocode"]; |
|
376
|
|
|
} |
|
377
|
|
|
return $ret; |
|
378
|
|
|
} |
|
379
|
|
|
|
|
380
|
|
|
public function countWaitingSubmission($oid) |
|
381
|
|
|
{ |
|
382
|
|
|
return DB::table($this->tableName) ->join('problem', 'problem.pid', '=', 'submission.pid') |
|
383
|
|
|
->where(['verdict'=>'Waiting', 'OJ'=>$oid]) |
|
384
|
|
|
->count(); |
|
385
|
|
|
} |
|
386
|
|
|
|
|
387
|
|
|
public function updateSubmission($sid, $sub) |
|
388
|
|
|
{ |
|
389
|
|
|
if (isset($sub['verdict'])) { |
|
390
|
|
|
$sub["color"]=$this->colorScheme[$sub['verdict']]; |
|
391
|
|
|
} |
|
392
|
|
|
$result = DB::table($this->tableName)->where(['sid'=>$sid])->update($sub); |
|
393
|
|
|
$contestModel = new ContestModel(); |
|
394
|
|
|
$submission_info = DB::table($this->tableName) -> where(['sid'=>$sid]) -> get() -> first(); |
|
395
|
|
|
if ($result==1 && $submission_info['cid'] && $contestModel->isContestRunning($submission_info['cid'])){ |
|
396
|
|
|
$sub['pid'] = $submission_info['pid']; |
|
397
|
|
|
$sub['uid'] = $submission_info['uid']; |
|
398
|
|
|
$sub['cid'] = $submission_info['cid']; |
|
399
|
|
|
$sub['sid'] = $sid; |
|
400
|
|
|
$contestModel->updateContestRankTable($submission_info['cid'],$sub); |
|
401
|
|
|
} |
|
402
|
|
|
return $result; |
|
403
|
|
|
} |
|
404
|
|
|
|
|
405
|
|
|
public function formatSubmitTime($date) |
|
406
|
|
|
{ |
|
407
|
|
|
$periods=["second", "minute", "hour", "day", "week", "month", "year", "decade"]; |
|
408
|
|
|
$lengths=["60", "60", "24", "7", "4.35", "12", "10"]; |
|
409
|
|
|
|
|
410
|
|
|
$now=time(); |
|
411
|
|
|
$unix_date=strtotime($date); |
|
412
|
|
|
|
|
413
|
|
|
if (empty($unix_date)) { |
|
414
|
|
|
return "Bad date"; |
|
415
|
|
|
} |
|
416
|
|
|
|
|
417
|
|
|
if ($now>$unix_date) { |
|
418
|
|
|
$difference=$now-$unix_date; |
|
419
|
|
|
$tense="ago"; |
|
420
|
|
|
} else { |
|
421
|
|
|
$difference=$unix_date-$now; |
|
422
|
|
|
$tense="from now"; |
|
423
|
|
|
} |
|
424
|
|
|
|
|
425
|
|
|
for ($j=0; $difference>=$lengths[$j] && $j<count($lengths)-1; $j++) { |
|
426
|
|
|
$difference/=$lengths[$j]; |
|
427
|
|
|
} |
|
428
|
|
|
|
|
429
|
|
|
$difference=round($difference); |
|
430
|
|
|
|
|
431
|
|
|
if ($difference!=1) { |
|
432
|
|
|
$periods[$j].="s"; |
|
433
|
|
|
} |
|
434
|
|
|
|
|
435
|
|
|
return "$difference $periods[$j] {$tense}"; |
|
436
|
|
|
} |
|
437
|
|
|
|
|
438
|
|
|
public function getRecord($filter) |
|
439
|
|
|
{ |
|
440
|
|
|
$paginator=DB::table("submission")->where([ |
|
441
|
|
|
'cid'=>null |
|
442
|
|
|
])->join( |
|
443
|
|
|
"users", |
|
444
|
|
|
"users.id", |
|
445
|
|
|
"=", |
|
446
|
|
|
"submission.uid" |
|
447
|
|
|
)->join( |
|
448
|
|
|
"problem", |
|
449
|
|
|
"problem.pid", |
|
450
|
|
|
"=", |
|
451
|
|
|
"submission.pid" |
|
452
|
|
|
)->select( |
|
453
|
|
|
"sid", |
|
454
|
|
|
"uid", |
|
455
|
|
|
"problem.pid as pid", |
|
456
|
|
|
"pcode", |
|
457
|
|
|
"name", |
|
458
|
|
|
"color", |
|
459
|
|
|
"verdict", |
|
460
|
|
|
"time", |
|
461
|
|
|
"memory", |
|
462
|
|
|
"language", |
|
463
|
|
|
"score", |
|
464
|
|
|
"submission_date", |
|
465
|
|
|
"share" |
|
466
|
|
|
)->orderBy( |
|
467
|
|
|
'submission_date', |
|
468
|
|
|
'desc' |
|
469
|
|
|
); |
|
470
|
|
|
|
|
471
|
|
|
if($filter["pcode"]){ |
|
472
|
|
|
$paginator=$paginator->where(["pcode"=>$filter["pcode"]]); |
|
473
|
|
|
} |
|
474
|
|
|
|
|
475
|
|
|
if($filter["result"]){ |
|
476
|
|
|
$paginator=$paginator->where(["verdict"=>$filter["result"]]); |
|
477
|
|
|
} |
|
478
|
|
|
|
|
479
|
|
|
if($filter["account"]){ |
|
480
|
|
|
$paginator=$paginator->where(["name"=>$filter["account"]]); |
|
481
|
|
|
} |
|
482
|
|
|
|
|
483
|
|
|
$paginator=$paginator->paginate(50); |
|
484
|
|
|
|
|
485
|
|
|
|
|
486
|
|
|
$records=$paginator->all(); |
|
487
|
|
|
foreach ($records as &$r) { |
|
488
|
|
|
$r["submission_date_parsed"]=$this->formatSubmitTime(date('Y-m-d H:i:s', $r["submission_date"])); |
|
489
|
|
|
$r["submission_date"]=date('Y-m-d H:i:s', $r["submission_date"]); |
|
490
|
|
|
$r["nick_name"]=""; |
|
491
|
|
|
} |
|
492
|
|
|
return [ |
|
493
|
|
|
"paginator"=>$paginator, |
|
494
|
|
|
"records"=>$records |
|
495
|
|
|
]; |
|
496
|
|
|
} |
|
497
|
|
|
|
|
498
|
|
|
public function share($sid, $uid) |
|
499
|
|
|
{ |
|
500
|
|
|
return $this->extractModels["ShareNodel"]->share($sid, $uid); |
|
501
|
|
|
} |
|
502
|
|
|
|
|
503
|
|
|
public function sharePB($sid, $uid) |
|
504
|
|
|
{ |
|
505
|
|
|
return $this->extractModels["ShareNodel"]->sharePB($sid, $uid); |
|
506
|
|
|
} |
|
507
|
|
|
} |
|
508
|
|
|
|