1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Models\Search; |
4
|
|
|
|
5
|
|
|
use App\Models\ContestModel; |
6
|
|
|
use Illuminate\Database\Eloquent\Model; |
7
|
|
|
use Auth; |
8
|
|
|
|
9
|
|
|
class ContestSearchModel extends Model |
10
|
|
|
{ |
11
|
|
|
protected $table='contest'; |
12
|
|
|
protected $primaryKey='cid'; |
13
|
|
|
|
14
|
|
|
private $rule=["Unknown", "ICPC", "IOI", "Custom ICPC", "Custom IOI"]; |
15
|
|
|
|
16
|
|
|
public function search($key) |
17
|
|
|
{ |
18
|
|
|
$result=[]; |
19
|
|
|
//contest name find |
20
|
|
|
if (strlen($key)>=2) { |
21
|
|
|
$ret=self::whereRaw('MATCH(`name`) AGAINST (? IN BOOLEAN MODE)', [$key]) |
22
|
|
|
->select('cid', 'gid', 'name', 'rule', 'public', 'verified', 'practice', 'rated', 'anticheated', 'begin_time', 'end_time') |
23
|
|
|
->orderBy('end_time', 'DESC') |
24
|
|
|
->limit(120) |
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)) { |
30
|
|
|
unset($ret[$c_index]); |
31
|
|
|
} |
32
|
|
|
} |
33
|
|
|
if (!empty($ret)) { |
34
|
|
|
$result+=$ret; |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
if (!empty($result)) { |
38
|
|
|
foreach ($result as &$contest) { |
39
|
|
|
$contest["rule_parsed"]=$this->rule[$contest["rule"]]; |
40
|
|
|
$contest["date_parsed"]=[ |
41
|
|
|
"date"=>date_format(date_create($contest["begin_time"]), 'j'), |
42
|
|
|
"month_year"=>date_format(date_create($contest["begin_time"]), 'M, Y'), |
43
|
|
|
]; |
44
|
|
|
$contest["length"]=$contestModel->calcLength($contest["begin_time"], $contest["end_time"]); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
unset($contest); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return $result; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|