123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- <?php
- namespace App\Admin\Controllers;
- use App\Admin\Extensions\ExcelExpoter;
- use App\Examarg;
- use App\Grade;
- use App\School;
- use App\Sclass;
- use App\Score;
- use App\Http\Controllers\Controller;
- use App\Test;
- use App\User;
- use Encore\Admin\Controllers\HasResourceActions;
- use Encore\Admin\Form;
- use Encore\Admin\Grid;
- use Encore\Admin\Layout\Content;
- use Encore\Admin\Show;
- class ScoreController 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)
- {
- $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('<a href="/admin/score/' . $id . '">
- <i class="fa fa-eye"></i>
- </a>');
- });
- // $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'] . '</br>';
- foreach ($value['o'] as $ke => $opt) {
- $question = $question . $opt['val'] . '</br>';
- }
- if ($this->grade == null) {
- //如果正在考试直接列出答案
- $question = $question . '答案' . '</br>';
- foreach ($value['a'] as $key => $ans) {
- foreach ($value['o'] as $ke => $opt) {
- if ($opt['num'] == $ans) {
- $question = $question . $opt['val'];
- }
- }
- }
- } else {
- $question = $question . '正确答案' . '</br>';
- foreach ($value['a'] as $key => $ans) {
- foreach ($value['o'] as $ke => $opt) {
- if ($opt['num'] == $ans) {
- $question = $question . $opt['val'];
- }
- }
- }
- $question = $question . '你的答案' . '</br>';
- 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;
- }
- }
|