SStudentPaperTopicRs.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. <?php
  2. /**
  3. * @author: CeeFee
  4. * @description: 班级
  5. */
  6. class SStudentPaperTopicRs extends MyActiveRecord
  7. {
  8. public static function model($className = __CLASS__)
  9. {
  10. return parent::model($className);
  11. }
  12. public function tableName()
  13. {
  14. return 'student_paper_topic_rs';
  15. }
  16. public function getRelationsByPaperId_StudentIds($paperId, $studentIds)
  17. {
  18. $result = array();
  19. if ($paperId AND is_numeric($paperId) AND $studentIds AND is_array($studentIds)) {
  20. $criteria = new CDbCriteria();
  21. $criteria->addCondition("paper_id = '" . $paperId . "' AND student_id IN (" . implode(',', $studentIds) . ")");
  22. $criteria->order = 'id ASC';
  23. $result = getAttributes($this->findAll($criteria));
  24. }
  25. return $result;
  26. }
  27. // 获取答错题的学生记录
  28. public function getWrongByStudentIds($paperId, $studentIds)
  29. {
  30. $result = array();
  31. if ($paperId AND is_numeric($paperId) AND $studentIds AND is_array($studentIds)) {
  32. $criteria = new CDbCriteria();
  33. $criteria->addCondition("paper_id = '" . $paperId . "' AND student_id IN (" . implode(',', $studentIds) . ") and is_right!=1");
  34. $criteria->order = 'student_id ASC,paper_id ASC,type ASC';
  35. $result = getAttributes($this->findAll($criteria));
  36. }
  37. return $result;
  38. }
  39. public function l_getWrongByStudentIds($paperId, $studentIds)
  40. {
  41. $result = array();
  42. if ($paperId AND is_numeric($paperId) AND $studentIds AND is_array($studentIds)) {
  43. $criteria = new CDbCriteria();
  44. $criteria->addCondition("paper_id = '" . $paperId . "' AND student_id IN (" . implode(',', $studentIds) . ")");
  45. $criteria->order = 'student_id ASC,paper_id ASC,type ASC';
  46. $result = getAttributes($this->findAll($criteria));
  47. }
  48. return $result;
  49. }
  50. // 刘红伟
  51. public function ll_getWrongByStudentIds($paperId, $studentIds)
  52. {
  53. $result = array();
  54. if ($paperId AND is_numeric($paperId) AND $studentIds AND is_array($studentIds)) {
  55. $criteria = new CDbCriteria();
  56. $criteria->addCondition("paper_id = '" . $paperId . "' AND student_id IN (" . implode(',', $studentIds) . ")");
  57. $criteria->order = 'student_id ASC,paper_id ASC,type ASC';
  58. $pager = new CPagination($this->count($criteria));
  59. $pager->pageSize = 10;
  60. $pager->applyLimit($criteria);
  61. return array('result' => $this->findAll($criteria), 'pager' => $pager);
  62. }
  63. return $result;
  64. }
  65. // 根据试卷id 学生id 试题id获取记录
  66. public function getStudentWrongRecords($paperId, $studentIds, $topicIds)
  67. {
  68. $result = array();
  69. if ($paperId AND is_numeric($paperId) AND $studentIds AND is_array($studentIds)) {
  70. $criteria = new CDbCriteria();
  71. $criteria->addCondition("paper_id = '" . $paperId . "' and student_id in (" . implode(',', $studentIds) . ") and topic_id in (" . implode(',', $topicIds) . ") and is_right!=1");
  72. $criteria->order = 'paper_id ASC,student_id ASC,topic_id ASC';
  73. $result = getAttributes($this->findAll($criteria));
  74. }
  75. return $result;
  76. }
  77. /**
  78. * 获取试卷学生做题记录
  79. * @param $paperId
  80. * @return array|CDbDataReader
  81. */
  82. public function getStudentRsOnePaper($paperId)
  83. {
  84. $newInfo = array();
  85. $sql = "select student_id,paper_id,`topic_id`,`type`,is_right,handlerIndex,answer,answer_url,scoring from " . $this->tableName() . " where paper_id = {$paperId} and handlerIndex = 1 order by `id` ";
  86. $info = $this->getCommandBuilder()->createSqlCommand($sql)->queryAll();
  87. foreach ($info as $value) {
  88. $stu_id = (string)$value['student_id'];
  89. $temp['paper_id'] = $value['paper_id'];
  90. $temp['topic_id'] = $value['topic_id'];
  91. $temp['type'] = $value['type'];
  92. $temp['is_right'] = $value['is_right'];
  93. $temp['handlerIndex'] = $value['handlerIndex'];
  94. if ($value['type'] == 1 || $value['type'] == 11) {
  95. $temp['answer'] = $value['answer'];
  96. } else {
  97. $temp['answer'] = $value['answer_url'];
  98. }
  99. $temp['scoring'] = $value['scoring'];
  100. if (!isset($newInfo[$stu_id])) {
  101. $newInfo[$stu_id] = array();
  102. }
  103. $newInfo[$stu_id][$value['topic_id']] = $temp;
  104. }
  105. unset($info);
  106. return $newInfo;
  107. }
  108. /**
  109. * 获取多个试卷学生做题记录
  110. * @param $paperIds
  111. * @return array
  112. */
  113. public function getStudentRs($paperIds)
  114. {
  115. $newInfo = array();
  116. $testStuIds = array();
  117. $_countSql = "select count(0) AS count from " . $this->tableName() . " where paper_id in (" . implode(',', $paperIds) . ") and handlerIndex = 1";
  118. $counTinfo = $this->getCommandBuilder()->createSqlCommand($_countSql)->queryRow();
  119. $count = 0;
  120. if (isset($counTinfo['count'])) {
  121. $count = $counTinfo['count'];
  122. } else {
  123. return $newInfo;
  124. }
  125. $limit = 20000;
  126. $page = ceil($count / $limit);
  127. $__sql = "select student_id,paper_id,`topic_id`,`type`,is_right,handlerIndex,answer,answer_url,scoring from " . $this->tableName() . " where paper_id in (" . implode(',', $paperIds) . ") and handlerIndex = 1 order by `paper_id` ";
  128. for ($i = 0; $i < $page; $i++) {
  129. $offset = $i * $limit;
  130. $sql = $__sql . " limit {$offset},{$limit}";
  131. $info = $this->getCommandBuilder()->createSqlCommand($sql)->queryAll();
  132. if ($info) {
  133. foreach ($info as $value) {
  134. $stu_id = (string)$value['student_id'];
  135. $temp['paper_id'] = $value['paper_id'];
  136. $temp['topic_id'] = $value['topic_id'];
  137. $temp['type'] = $value['type'];
  138. $temp['is_right'] = $value['is_right'];
  139. $temp['handlerIndex'] = $value['handlerIndex'];
  140. // if($value['type'] == 1 || $value['type'] == 11){
  141. // $temp['answer'] = $value['answer'];
  142. // }else{
  143. // $temp['answer'] = $value['answer_url'];
  144. // }
  145. if (trim($value['answer_url'])) {
  146. $temp['answer'] = $value['answer_url'];
  147. } else {
  148. $temp['answer'] = $value['answer'];
  149. }
  150. $temp['scoring'] = $value['scoring'];
  151. if (!isset($newInfo[$stu_id])) {
  152. $newInfo[$stu_id] = array();
  153. }
  154. $newInfo[$stu_id][$value['topic_id']] = $temp;
  155. $testStuIds[] = $stu_id;
  156. }
  157. }
  158. unset($info);
  159. }
  160. return $newInfo;
  161. }
  162. /**
  163. * 获取上传成绩的学生
  164. * @param $paperIds
  165. * @return array|CDbDataReader
  166. */
  167. public function getHasScoreStu($examIds)
  168. {
  169. $studentIds = array();
  170. $sql = "select student_id,exam_id from " . $this->tableName() . " as sptr join paper as p on sptr.paper_id = p.paper_id where p.exam_id in (" . implode(',', $examIds) . ") and handlerIndex = 1";
  171. $info = $this->getCommandBuilder()->createSqlCommand($sql)->queryAll();
  172. if ($info) {
  173. foreach ($info as $value) {
  174. if (!isset($studentIds[$value['exam_id']])) {
  175. $studentIds[$value['exam_id']] = array();
  176. }
  177. $studentIds[$value['exam_id']][$value['student_id']] = $value['student_id'];
  178. }
  179. foreach ($studentIds as $eId => $stuIds) {
  180. $studentIds[$eId] = array_keys($stuIds);
  181. }
  182. unset($info);
  183. }
  184. return $studentIds;
  185. }
  186. /**
  187. * 做题id获取信息
  188. * @param $ids
  189. * @return array
  190. */
  191. public function getStuRsByIds($ids)
  192. {
  193. $res = array();
  194. if ($ids) {
  195. $sql = "select id,student_id,topic_id,`answer_url`,scoring,simplify_answer_url,answer_trace from student_paper_topic_rs where id in (" . implode(',', $ids) . ") and handlerIndex = 1";
  196. $res = $this->getCommandBuilder()->createSqlCommand($sql)->queryAll();
  197. }
  198. return $res;
  199. }
  200. /** 同学优解
  201. * @param $exam
  202. * @param $codeNow
  203. * @param $staticUrl
  204. * @param $conn
  205. * @param $isQxkPage是否全学科考试1是2不是
  206. * @return array
  207. * @throws CDbException
  208. * @throws CException
  209. */
  210. public function bestAnswer($exam, $codeNow, $staticUrl, $conn, $isQxkPage = 0)
  211. {
  212. $tableName = empty($codeNow) ? "student_paper_topic_rs" : "student_paper_topic_rs_" . $codeNow;
  213. $fine_topic_score = array();
  214. $topicIds = array();
  215. $studentIds = array();
  216. $excellent_solution = array();
  217. if ($isQxkPage == 1) {//如果是全学科的题目
  218. $typeArr = array(8, 9);
  219. } else {
  220. $typeArr = array(7, 17, 27);
  221. }
  222. //获取考试试题对应优解分数
  223. $topic_sql = "select topic_id,score from paper_topic_relation where paper_id = '{$exam['paper_id']}' and type in (" . join(",", $typeArr) . ")";
  224. $topic_sql_rs = $conn->createCommand($topic_sql)->queryAll();
  225. foreach ($topic_sql_rs as $item) {
  226. $fine_topic_score[$item['topic_id']] = 0.8 * $item['score'];
  227. $topicIds[$item['topic_id']] = $item['topic_id'];
  228. }
  229. // FIXME 1:优先取本班标记得分最高的优解
  230. $sql = "select m.paper_id,m.student_id,m.sptr_id,m.topic_id,sptr.answer_url from marking_special_answer m inner join {$tableName} sptr on m.sptr_id=sptr.id where m.paper_id = '{$exam['paper_id']}' and m.type = 2 group by m.topic_id order by sptr.scoring desc";
  231. $special_data = $conn->createCommand($sql)->queryAll();
  232. foreach ($special_data as $item) {
  233. $excellent_solution[(string)$item['topic_id']] = $item;
  234. array_push($studentIds, $item['student_id']);
  235. unset($topicIds[$item['topic_id']]);
  236. }
  237. // FIXME 2:本班得分高于80%的最高分
  238. if ($topicIds) {
  239. $sql = "select paper_id,student_id,topic_id,answer_url from {$tableName} where paper_id = '{$exam['paper_id']}' and type = 2 group by topic_id order by scoring desc";
  240. $class_data = $conn->createCommand($sql)->queryAll();
  241. foreach ($class_data as $item) {
  242. if (in_array($item['topic_id'], $topicIds) && $item['topic_id'] >= $fine_topic_score[$item['topic_id']]) {
  243. array_push($studentIds, $item['student_id']);
  244. $excellent_solution[(string)$item['topic_id']] = $item;
  245. unset($topicIds[$item['topic_id']]);
  246. }
  247. }
  248. }
  249. // FIXME 3:年级标记的得分最高的优解
  250. if ($topicIds) {
  251. $sql = <<<SQL
  252. SELECT
  253. r.student_id,
  254. r.topic_id,
  255. r.scoring,
  256. r.answer_url
  257. FROM
  258. marking_special_answer m
  259. INNER JOIN student_paper_topic_rs r ON m.student_id = r.student_id
  260. INNER JOIN exam e ON e.exam_id = m.exam_id
  261. AND m.topic_id = r.topic_id AND m.paper_id=r.paper_id
  262. INNER JOIN exam_group g ON e.exam_group_id=g.exam_group_id
  263. WHERE
  264. m.exam_group_id = '{$exam['exam_group_id']}'
  265. AND m.type = 2
  266. AND e.status = 1
  267. AND IF(g.mark_type=0 OR g.import_score_type=3, e.is_backlog=1,TRUE)
  268. ORDER BY r.scoring DESC;
  269. SQL;
  270. $grade_special_data = $conn->createCommand($sql)->queryAll();
  271. foreach ($grade_special_data as $item) {
  272. if (in_array($item['topic_id'], $topicIds)) {
  273. array_push($studentIds, $item['student_id']);
  274. $excellent_solution[(string)$item['topic_id']] = $item;
  275. unset($topicIds[$item['topic_id']]);
  276. }
  277. }
  278. }
  279. //FIXME 4:年级得分高于80%的最高分
  280. $paper_ids_sql = "SELECT p.paper_id FROM paper p INNER JOIN exam e ON p.exam_id=e.exam_id INNER JOIN exam_group g ON e.exam_group_id=g.exam_group_id WHERE e.exam_group_id='{$exam['exam_group_id']}' and e.`status`=1 AND IF(g.mark_type=0 OR g.import_score_type=3, e.is_backlog=1,TRUE);";
  281. $paper_ids_res = $conn->createCommand($paper_ids_sql)->queryAll();
  282. $paper_ids = array();
  283. foreach ($paper_ids_res as $item) {
  284. $paper_ids[] = $item['paper_id'];
  285. }
  286. if (empty($paper_ids)) {
  287. $paper_ids = array($exam['paper_id']);
  288. }
  289. $paper_ids_str = implode(',', $paper_ids);
  290. if ($topicIds) {
  291. $topic_rs_sql = "select student_id,topic_id,scoring,answer_url from (select * from student_paper_topic_rs where type in (" . join(",", $typeArr) . ") and paper_id in ({$paper_ids_str}) order by scoring desc) as a group by a.topic_id;";
  292. $topic_rs = $conn->createCommand($topic_rs_sql)->queryAll();;
  293. foreach ($topic_rs as $item) {
  294. if (in_array($item['topic_id'], $topicIds) && $item['topic_id'] >= $fine_topic_score[$item['topic_id']]) {
  295. array_push($studentIds, $item['student_id']);
  296. $excellent_solution[(string)$item['topic_id']] = $item;
  297. }
  298. }
  299. }
  300. //FIXME 优解学生信息
  301. $stuInfos = array();
  302. $stu_id_str = trim(implode(',', array_unique($studentIds)), ',');
  303. $besetAnswer = array();
  304. if ($stu_id_str) {
  305. $stuSql = "SELECT s.student_id,s.realname,c.class_name FROM student_paper_relation p LEFT JOIN student_info s ON s.student_id = p.student_id LEFT JOIN class c ON p.class_id = c.class_id WHERE p.student_id IN ({$stu_id_str}) AND p.paper_id IN ({$paper_ids_str});";
  306. $stuRs = $conn->createCommand($stuSql)->queryAll();
  307. foreach ($stuRs as $stu) {
  308. $stuInfos[$stu['student_id']] = $stu;
  309. }
  310. foreach ($excellent_solution as $item) {
  311. $besetAnswer[(string)$item['topic_id']]['class_name'] = isset($stuInfos[$item['student_id']]) ? $stuInfos[$item['student_id']]['class_name'] : '';
  312. $besetAnswer[(string)$item['topic_id']]['student_name'] = isset($stuInfos[$item['student_id']]) ? $stuInfos[$item['student_id']]['realname'] : '';
  313. if (strpos($item['answer_url'], 'http') !== false) {
  314. $besetAnswer[(string)$item['topic_id']]['answer_url'] = $item['answer_url'];
  315. } else {
  316. $besetAnswer[(string)$item['topic_id']]['answer_url'] = $staticUrl . $item['answer_url'];
  317. }
  318. }
  319. }
  320. return $besetAnswer;
  321. }
  322. }