123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- <?php
- namespace App\Admin\Controllers;
- use App\Clocked;
- use App\Grade;
- use App\Http\Controllers\Controller;
- use App\School;
- use App\Sclass;
- 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 ClockedController extends Controller
- {
- use HasResourceActions;
- /**
- * Index interface.
- *
- * @param Content $content
- * @return Content
- */
- public function index(Content $content)
- {
- return $content
- ->header('Index')
- ->description('description')
- ->body($this->grid());
- }
- /**
- * Show interface.
- *
- * @param mixed $id
- * @param Content $content
- * @return Content
- */
- public function show($id, Content $content)
- {
- return $content
- ->header('Detail')
- ->description('description')
- ->body($this->detail($id));
- }
- /**
- * Edit interface.
- *
- * @param mixed $id
- * @param Content $content
- * @return Content
- */
- public function edit($id, Content $content)
- {
- return $content
- ->header('Edit')
- ->description('description')
- ->body($this->form()->edit($id));
- }
- /**
- * Create interface.
- *
- * @param Content $content
- * @return Content
- */
- public function create(Content $content)
- {
- return $content
- ->header('Create')
- ->description('description')
- ->body($this->form());
- }
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- $grid = new Grid(new Clocked);
- $grid->id('编号');
- $grid->filter(function ($filter) {
- // 去掉默认的id过滤器
- $filter->disableIdFilter();
- // 在这里添加字段过滤器
- $filter->where(function ($query) {
- $query->whereHas('user', function ($query) {
- $query->where('name', 'like', "%{$this->input}%");
- });
- }, '姓名');
- $filter->where(function ($query) {
- $query->whereHas('user', function ($query) {
- $query->where('sclass_id', 'like', "%{$this->input}%");
- });
- }, '班级')->select('/admin/api/getSchoolSclass');
- });
- $grid->user_name('用户编号')->display(function () {
- $name = User::where('id', $this->user_id)->select('name')->first();
- if ($name) {
- return $name['name'];
- }
- return null;
- });
- $grid->school("学校班级信息")->display(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;
- });
- $grid->answerOK('答题结果')->display(function () {
- if ($this->answer) {
- return "正确";
- }
- return "错误";
- });
- $grid->created_at('打卡时间');
- return $grid;
- }
- /**
- * Make a show builder.
- *
- * @param mixed $id
- * @return Show
- */
- protected function detail($id)
- {
- $show = new Show(Clocked::findOrFail($id));
- $show->id('编号');
- $show->user_id('用户编号');
- $show->question_id('题目编号');
- $show->answer('答题结果');
- $show->created_at('创建时间');
- $show->updated_at('更新时间');
- return $show;
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function form()
- {
- $form = new Form(new Clocked);
- $form->number('user_id', '用户编号');
- $form->number('question_id', '题目编号');
- $form->switch('answer', '答案');
- return $form;
- }
- }
|