RoomGrade.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace app\admin\controller\exam;
  3. use addons\exam\model\QuestionModel;
  4. use app\common\controller\Backend;
  5. /**
  6. * 考场考试成绩
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class RoomGrade extends Backend
  11. {
  12. protected $noNeedRight = ['*'];
  13. /**
  14. * RoomGradeModel模型对象
  15. *
  16. * @var \app\admin\model\exam\RoomGradeModel
  17. */
  18. protected $model = null;
  19. public function _initialize()
  20. {
  21. parent::_initialize();
  22. $this->model = new \app\admin\model\exam\RoomGradeModel;
  23. $this->view->assign("isPassList", $this->model->getIsPassList());
  24. $this->view->assign("isMakeupList", $this->model->getIsMakeupList());
  25. }
  26. /**
  27. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  28. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  29. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  30. */
  31. /**
  32. * 查看
  33. */
  34. public function index()
  35. {
  36. //当前是否为关联查询
  37. $this->relationSearch = true;
  38. //设置过滤方法
  39. $this->request->filter(['strip_tags', 'trim']);
  40. if ($this->request->isAjax()) {
  41. //如果发送的来源是Selectpage,则转发到Selectpage
  42. if ($this->request->request('keyField')) {
  43. return $this->selectpage();
  44. }
  45. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  46. $list = $this->model
  47. ->with(['user', 'cate', 'room', 'paper', 'signup1'])
  48. ->where($where)
  49. ->order($sort, $order)
  50. ->paginate($limit);
  51. foreach ($list as $row) {
  52. $row->getRelation('user')->visible(['nickname']);
  53. $row->getRelation('cate')->visible(['name']);
  54. $row->getRelation('room')->visible(['name']);
  55. $row->getRelation('paper')->visible(['title']);
  56. }
  57. $result = ["total" => $list->total(), "rows" => $list->items()];
  58. return json($result);
  59. }
  60. return $this->view->fetch();
  61. }
  62. /**
  63. * 详情
  64. */
  65. public function detail($ids = null)
  66. {
  67. $row = $this->model->get($ids, ['user', 'paper', 'cate']);
  68. if (!$row) {
  69. $this->error(__('No Results were found'));
  70. }
  71. $adminIds = $this->getDataLimitAdminIds();
  72. if (is_array($adminIds)) {
  73. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  74. $this->error(__('You have no permission'));
  75. }
  76. }
  77. if (
  78. (!isset($row['question_ids']) || !$row['question_ids']) ||
  79. (!isset($row['user_answers']) || !$row['user_answers']) ||
  80. (!isset($row['configs']) || !$row['configs'])
  81. ) {
  82. $this->error('答卷数据缺少,无法查看(可能是旧版本未记录数据导致)');
  83. }
  84. $row['questions'] = QuestionModel::whereIn('id', $row['question_ids'])
  85. ->orderRaw("find_in_set(id, '" . $row['question_ids'] . "')")
  86. ->select();
  87. $row['user_answers'] = json_decode($row['user_answers'], true);
  88. $row['configs'] = json_decode($row['configs'], true);
  89. $row['createtime_text'] = date('Y-m-d H:i:s', $row['createtime']);
  90. // 及格线
  91. $row['pass_score'] = $row['pass_score'] ?: $row['paper']['pass_score'];
  92. $this->view->assign("row", $row);
  93. return $this->view->fetch();
  94. }
  95. }