1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Admin\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Models\ProblemModel; |
6
|
|
|
use App\Models\Eloquent\SolutionModel as EloquentSolutionModel; |
7
|
|
|
use App\Http\Controllers\Controller; |
8
|
|
|
use Encore\Admin\Controllers\HasResourceActions; |
9
|
|
|
use Encore\Admin\Form; |
10
|
|
|
use Encore\Admin\Grid; |
11
|
|
|
use Encore\Admin\Layout\Content; |
12
|
|
|
use Encore\Admin\Show; |
13
|
|
|
|
14
|
|
|
class SolutionController extends Controller |
15
|
|
|
{ |
16
|
|
|
use HasResourceActions; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Index interface. |
20
|
|
|
* |
21
|
|
|
* @param Content $content |
22
|
|
|
* @return Content |
23
|
|
|
*/ |
24
|
|
|
public function index(Content $content) |
25
|
|
|
{ |
26
|
|
|
return $content |
27
|
|
|
->header('Solutions') |
28
|
|
|
->description('all solutions') |
29
|
|
|
->body($this->grid()->render()); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Show interface. |
34
|
|
|
* |
35
|
|
|
* @param mixed $id |
36
|
|
|
* @param Content $content |
37
|
|
|
* @return Content |
38
|
|
|
*/ |
39
|
|
|
public function show($id, Content $content) |
40
|
|
|
{ |
41
|
|
|
return $content |
42
|
|
|
->header('Solution Detail') |
43
|
|
|
->description('the detail of solutions') |
44
|
|
|
->body($this->detail($id)); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Edit interface. |
49
|
|
|
* |
50
|
|
|
* @param mixed $id |
51
|
|
|
* @param Content $content |
52
|
|
|
* @return Content |
53
|
|
|
*/ |
54
|
|
|
public function edit($id, Content $content) |
55
|
|
|
{ |
56
|
|
|
return $content |
57
|
|
|
->header('Edit Solutions') |
58
|
|
|
->description('edit the detail of solutions') |
59
|
|
|
->body($this->form()->edit($id)); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Create interface. |
64
|
|
|
* |
65
|
|
|
* @param Content $content |
66
|
|
|
* @return Content |
67
|
|
|
*/ |
68
|
|
|
public function create(Content $content) |
69
|
|
|
{ |
70
|
|
|
return $content |
71
|
|
|
->header('Create New Solution') |
72
|
|
|
->description('create a new solution') |
73
|
|
|
->body($this->form()); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Make a grid builder. |
78
|
|
|
* |
79
|
|
|
* @return Grid |
80
|
|
|
*/ |
81
|
|
|
protected function grid() |
82
|
|
|
{ |
83
|
|
|
$grid=new Grid(new EloquentSolutionModel); |
84
|
|
|
$grid->psoid("ID")->sortable(); |
85
|
|
|
$grid->uid("Uid")->editable(); |
86
|
|
|
$grid->pid("Pid")->editable(); |
87
|
|
|
$grid->content("Content")->display(function($content) { |
88
|
|
|
$contentParsed=clean(convertMarkdownToHtml($content)); |
89
|
|
|
return "$contentParsed"; |
90
|
|
|
}); |
91
|
|
|
$grid->audit("Audit")->editable('select', [0 => 'Waiting', 1 => 'Accepted', 2 => 'Declined']); |
92
|
|
|
$grid->votes("Votes"); |
93
|
|
|
$grid->filter(function(Grid\Filter $filter) { |
94
|
|
|
$filter->disableIdFilter(); |
95
|
|
|
$filter->equal('uid'); |
96
|
|
|
$filter->equal('pid'); |
97
|
|
|
$filter->equal('audit')->radio([ |
98
|
|
|
'' => 'All', |
99
|
|
|
'0' => 'Waiting', |
100
|
|
|
'1' => 'Accepted', |
101
|
|
|
'2' => 'Declined', |
102
|
|
|
]); |
103
|
|
|
}); |
104
|
|
|
$grid->expandFilter(); |
105
|
|
|
return $grid; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Make a show builder. |
110
|
|
|
* |
111
|
|
|
* @param mixed $id |
112
|
|
|
* @return Show |
113
|
|
|
*/ |
114
|
|
|
protected function detail($id) |
115
|
|
|
{ |
116
|
|
|
$show=new Show(EloquentSolutionModel::findOrFail($id)); |
117
|
|
|
return $show; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Make a form builder. |
122
|
|
|
* |
123
|
|
|
* @return Form |
124
|
|
|
*/ |
125
|
|
|
protected function form() |
126
|
|
|
{ |
127
|
|
|
$form=new Form(new EloquentSolutionModel); |
128
|
|
|
$form->model()->makeVisible('password'); |
129
|
|
|
$form->tab('Basic', function(Form $form) { |
130
|
|
|
$form->display("psoid"); |
131
|
|
|
$form->text("uid")->rules('required'); |
132
|
|
|
$form->text("pid")->rules('required'); |
133
|
|
|
$form->text("content")->rules('required'); |
134
|
|
|
$form->text("audit")->rules('required'); |
135
|
|
|
$form->text("votes")->rules('required'); |
136
|
|
|
$form->display("created_at"); |
137
|
|
|
$form->display("updated_at"); |
138
|
|
|
$form->select('partial', 'Partial Score')->options([ |
139
|
|
|
0 => "No", |
140
|
|
|
1 => "Yes" |
141
|
|
|
])->rules('required'); |
142
|
|
|
$form->select('markdown', 'Markdown Support')->options([ |
143
|
|
|
0 => "No", |
144
|
|
|
1 => "Yes" |
145
|
|
|
])->rules('required'); |
146
|
|
|
}); |
147
|
|
|
return $form; |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|