header('成绩管理') ->description('列表') ->body($this->grid()); } /** * Show interface. * * @param mixed $id * @param Content $content * @return Content */ public function show($id, Content $content) { $test = Test::where('id', $id)->first(); return $content ->header('用户成绩') ->description('详情') ->body(view('question_test', compact('test'))); } /** * 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 Test()); $grid->id('Id'); $grid->user()->name('用户'); $grid->time('用时'); $grid->paper()->name('试卷名'); $grid->mark('成绩'); $grid->school('学校'); $grid->grade('年级'); $grid->class('班级'); $grid->result('结果')->display(function ($val) { $g = count($val['list']); return "共{$g}道题,其中正确:{$val['right']}道题,错误:{$val['error']}道试题。"; }); $grid->created_at('提交时间'); $grid->disableCreateButton(); $grid->disableRowSelector(); $grid->actions(function (Grid\Displayers\Actions $actions) { // $actions->disableDelete(); $actions->disableEdit(); $actions->disableView(); $id = $actions->getKey(); $actions->prepend(' '); }); // $grid->exporter(new TestExpote()); $grid->filter(function (Grid\Filter $filter) { $filter->disableIdFilter(); $filter->where(function ($query) { $query->whereHas('user', function ($query) { $query->where('name', 'like', "%{$this->input}%"); }); }, '用户名'); $filter->in('paper_id', '试卷名')->multipleSelect(Examarg::pluck('name', 'id')); $filter->between('created_at', '提交时间')->date(); }); $grid->disableExport(); return $grid; } /** * Make a show builder. * * @param mixed $id * @return Show */ protected function detail($id) { $show = new Show(Score::findOrFail($id)); $show->id('编号'); $show->user_id('用户')->as(function () { $name1 = User::where('id', $this->user_id)->select("name")->first(); if ($name1) { return $name1['name']; } return null; }); $show->school('学校信息')->as(function () { $name1 = User::where('id', $this->user_id)->select("school_id", "class_id", "grade_id")->first(); if ($name1) { $school_name = School::where("id", $name1['school_id'])->select('name')->first(); if ($school_name) { $school_name = $school_name['name']; } $grade = Grade::where("id", $name1['grade_id'])->select('name')->first(); if ($grade) { $grade = $grade['name']; } $sclass = Sclass::where("id", $name1['sclass_id'])->select('name')->first(); if ($sclass) { $sclass = $sclass['name']; } return $school_name . '-' . $grade . '-' . $sclass; } return null; }); $show->examarg_id('试卷名称')->as(function () { $exam = Examarg::where('id', $this->examarg_id)->select('name')->first(); if ($exam) { return $exam['name']; } return ''; }); $show->exam_id('考试id')->unescape()->as(function () { $question = ''; foreach ($this->exam['exam'] as $item => $value) { $question = '题目:' . $value['q'] . '
'; foreach ($value['o'] as $ke => $opt) { $question = $question . $opt['val'] . '
'; } if ($this->grade == null) { //如果正在考试直接列出答案 $question = $question . '答案' . '
'; foreach ($value['a'] as $key => $ans) { foreach ($value['o'] as $ke => $opt) { if ($opt['num'] == $ans) { $question = $question . $opt['val']; } } } } else { $question = $question . '正确答案' . '
'; foreach ($value['a'] as $key => $ans) { foreach ($value['o'] as $ke => $opt) { if ($opt['num'] == $ans) { $question = $question . $opt['val']; } } } $question = $question . '你的答案' . '
'; foreach ($value['ya'] as $key => $ans) { foreach ($value['o'] as $ke => $opt) { if ($opt['num'] == $ans) { $question = $question . $opt['val']; } } } } } return $question; }); // $show->exam('Exam'); $show->grade('成绩')->as(function () { if ($this->grade == null) { return "考试中"; } }); $show->created_at('创建时间'); $show->updated_at('更新时间'); return $show; } /** * Make a form builder. * * @return Form */ protected function form() { $form = new Form(new Test()); $form->display('id', 'id'); return $form; } }