RoomGrade.php 3.5 KB

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