ExamargController.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Exam;
  4. use App\Examarg;
  5. use App\Grade;
  6. use App\School;
  7. use App\Http\Controllers\Controller;
  8. use App\Sclass;
  9. use Encore\Admin\Controllers\HasResourceActions;
  10. use Encore\Admin\Form;
  11. use Encore\Admin\Grid;
  12. use Encore\Admin\Layout\Content;
  13. use Encore\Admin\Show;
  14. class ExamargController extends Controller
  15. {
  16. use HasResourceActions;
  17. /**
  18. * Index interface.
  19. *
  20. * @param Content $content
  21. * @return Content
  22. */
  23. public function index(Content $content)
  24. {
  25. return $content
  26. ->header('考试管理')
  27. ->description('列表')
  28. ->body($this->grid());
  29. }
  30. /**
  31. * Show interface.
  32. *
  33. * @param mixed $id
  34. * @param Content $content
  35. * @return Content
  36. */
  37. public function show($id, Content $content)
  38. {
  39. return $content
  40. ->header('考试管理')
  41. ->description('详情')
  42. ->body($this->detail($id));
  43. }
  44. /**
  45. * Edit interface.
  46. *
  47. * @param mixed $id
  48. * @param Content $content
  49. * @return Content
  50. */
  51. public function edit($id, Content $content)
  52. {
  53. return $content
  54. ->header('考试管理')
  55. ->description('编辑')
  56. ->body($this->form()->edit($id));
  57. }
  58. /**
  59. * Create interface.
  60. *
  61. * @param Content $content
  62. * @return Content
  63. */
  64. public function create(Content $content)
  65. {
  66. return $content
  67. ->header('考试管理')
  68. ->description('创建')
  69. ->body($this->form());
  70. }
  71. /**
  72. * Make a grid builder.
  73. *
  74. * @return Grid
  75. */
  76. protected function grid()
  77. {
  78. $grid = new Grid(new Examarg);
  79. $grid->id('编号');
  80. $grid->name('名称');
  81. $grid->exam_name('试卷名称')->display(function () {
  82. $name = Exam::where('id', $this->exam_id)->select('name')->first();
  83. if ($name) {
  84. return $name['name'];
  85. }
  86. return null;
  87. });
  88. $grid->exam_time('考试时长');
  89. $grid->exam_start('开考时间');
  90. $grid->exam_end('结束时间');
  91. $grid->created_at('创建时间');
  92. $grid->updated_at('更新时间');
  93. $grid->disableExport();
  94. $grid->actions(function (Grid\Displayers\Actions $actions) {
  95. $actions->disableView();
  96. });
  97. return $grid;
  98. }
  99. /**
  100. * Make a show builder.
  101. *
  102. * @param mixed $id
  103. * @return Show
  104. */
  105. protected function detail($id)
  106. {
  107. $show = new Show(Examarg::findOrFail($id));
  108. $show->id('编号');
  109. $show->exam_id('试卷编号');
  110. $show->exam_name('试卷名称')->as(function () {
  111. $name = Exam::where('id', $this->exam_id)->select("name")->first();
  112. if ($name) {
  113. return $name['name'];
  114. }
  115. });
  116. $show->exam_time('考试时长');
  117. $show->exam_start('开考时间');
  118. $show->exam_end('结束时间');
  119. $show->school_name('学校名称')->as(function () {
  120. $name = School::where('id', $this->school_id)->select("name")->first();
  121. if ($name) {
  122. return $name['name'];
  123. }
  124. });
  125. $show->grade_name('年级名称')->as(function () {
  126. $name = Grade::where('id', $this->sclass_id)->select("name")->first();
  127. if ($name) {
  128. return $name['name'];
  129. }
  130. });
  131. $show->class_name('班级名称')->unescape()->as(function () {
  132. $names = Sclass::select('name')->find($this->sclass_id);
  133. $titleshow = "";
  134. foreach ($names as $name => $value) {
  135. $titleshow = $titleshow . $value['name'] . '<br/>';
  136. }
  137. return $titleshow;
  138. });
  139. $show->created_at('创建时间');
  140. $show->updated_at('更新时间');
  141. return $show;
  142. }
  143. /**
  144. * Make a form builder.
  145. *
  146. * @return Form
  147. */
  148. protected function form()
  149. {
  150. $form = new Form(new Examarg);
  151. $form->text('name', '设置名称')->rules('required');
  152. $form->textarea('remark', '考试备注信息')->rules('required');
  153. $form->select('exam_id', '试卷名称')->options('/admin/api/getExams');
  154. $form->text('exam_time', '考试时长')->help('单位:分钟')->rules('required');
  155. $form->datetime('exam_start', '开考时间')->default(date('Y-m-d H:i:s'));
  156. $form->datetime('exam_end', '结束时间')->default(date('Y-m-d H:i:s'));
  157. $form->select('school_id', '学校')->options(
  158. School::pluck("name", 'id')
  159. )->load('sclass_id', '/admin/api/getClassApi')->rules('required');
  160. $form->select('grade_id', '年级')->options(Grade::pluck("name", 'id')->toArray())->rules('required');
  161. $form->multipleSelect('sclass_id', '班级编号')->options(Sclass::pluck("name", 'id')->toArray())->rules('required');
  162. $form->disableViewCheck();
  163. $form->disableEditingCheck();
  164. $form->disableCreatingCheck();
  165. $form->tools(function (Form\Tools $tools) {
  166. $tools->disableView();
  167. });
  168. return $form;
  169. }
  170. }