123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- <?php
- namespace App\Admin\Controllers;
- use App\Exam;
- use App\Examarg;
- use App\Grade;
- use App\School;
- use App\Http\Controllers\Controller;
- use App\Sclass;
- use Encore\Admin\Controllers\HasResourceActions;
- use Encore\Admin\Form;
- use Encore\Admin\Grid;
- use Encore\Admin\Layout\Content;
- use Encore\Admin\Show;
- class ExamargController extends Controller
- {
- use HasResourceActions;
- /**
- * Index interface.
- *
- * @param Content $content
- * @return Content
- */
- public function index(Content $content)
- {
- return $content
- ->header('考试管理')
- ->description('列表')
- ->body($this->grid());
- }
- /**
- * Show interface.
- *
- * @param mixed $id
- * @param Content $content
- * @return Content
- */
- public function show($id, Content $content)
- {
- return $content
- ->header('考试管理')
- ->description('详情')
- ->body($this->detail($id));
- }
- /**
- * Edit interface.
- *
- * @param mixed $id
- * @param Content $content
- * @return Content
- */
- public function edit($id, Content $content)
- {
- return $content
- ->header('考试管理')
- ->description('编辑')
- ->body($this->form()->edit($id));
- }
- /**
- * Create interface.
- *
- * @param Content $content
- * @return Content
- */
- public function create(Content $content)
- {
- return $content
- ->header('考试管理')
- ->description('创建')
- ->body($this->form());
- }
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- $grid = new Grid(new Examarg);
- $grid->id('编号');
- $grid->name('名称');
- $grid->exam_name('试卷名称')->display(function () {
- $name = Exam::where('id', $this->exam_id)->select('name')->first();
- if ($name) {
- return $name['name'];
- }
- return null;
- });
- $grid->exam_time('考试时长');
- $grid->exam_start('开考时间');
- $grid->exam_end('结束时间');
- $grid->created_at('创建时间');
- $grid->updated_at('更新时间');
- $grid->disableExport();
- $grid->actions(function (Grid\Displayers\Actions $actions) {
- $actions->disableView();
- });
- return $grid;
- }
- /**
- * Make a show builder.
- *
- * @param mixed $id
- * @return Show
- */
- protected function detail($id)
- {
- $show = new Show(Examarg::findOrFail($id));
- $show->id('编号');
- $show->exam_id('试卷编号');
- $show->exam_name('试卷名称')->as(function () {
- $name = Exam::where('id', $this->exam_id)->select("name")->first();
- if ($name) {
- return $name['name'];
- }
- });
- $show->exam_time('考试时长');
- $show->exam_start('开考时间');
- $show->exam_end('结束时间');
- $show->school_name('学校名称')->as(function () {
- $name = School::where('id', $this->school_id)->select("name")->first();
- if ($name) {
- return $name['name'];
- }
- });
- $show->grade_name('年级名称')->as(function () {
- $name = Grade::where('id', $this->sclass_id)->select("name")->first();
- if ($name) {
- return $name['name'];
- }
- });
- $show->class_name('班级名称')->unescape()->as(function () {
- $names = Sclass::select('name')->find($this->sclass_id);
- $titleshow = "";
- foreach ($names as $name => $value) {
- $titleshow = $titleshow . $value['name'] . '<br/>';
- }
- return $titleshow;
- });
- $show->created_at('创建时间');
- $show->updated_at('更新时间');
- return $show;
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function form()
- {
- $form = new Form(new Examarg);
- $form->text('name', '设置名称')->rules('required');
- $form->textarea('remark', '考试备注信息')->rules('required');
- $form->select('exam_id', '试卷名称')->options('/admin/api/getExams');
- $form->text('exam_time', '考试时长')->help('单位:分钟')->rules('required');
- $form->datetime('exam_start', '开考时间')->default(date('Y-m-d H:i:s'));
- $form->datetime('exam_end', '结束时间')->default(date('Y-m-d H:i:s'));
- $form->select('school_id', '学校')->options(
- School::pluck("name", 'id')
- )->load('sclass_id', '/admin/api/getClassApi')->rules('required');
- $form->select('grade_id', '年级')->options(Grade::pluck("name", 'id')->toArray())->rules('required');
- $form->multipleSelect('sclass_id', '班级编号')->options(Sclass::pluck("name", 'id')->toArray())->rules('required');
- $form->disableViewCheck();
- $form->disableEditingCheck();
- $form->disableCreatingCheck();
- $form->tools(function (Form\Tools $tools) {
- $tools->disableView();
- });
- return $form;
- }
- }
|