SEnglishMagicWordMarking.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. class SEnglishMagicWordMarking extends MyActiveRecord
  3. {
  4. public static function model($className = __CLASS__)
  5. {
  6. return parent::model($className);
  7. }
  8. public function tableName()
  9. {
  10. return 'english_magic_word_marking';
  11. }
  12. public function getMarkingCount($mrId)
  13. {
  14. $sql = "select count(distinct student_id) as count from english_magic_word_marking where mw_id={$mrId};";
  15. $connect = $this->getDbConnection();
  16. $rs = $connect->createCommand($sql)->queryRow();
  17. $markCount= isset($rs['count']) ? $rs['count'] : 0;
  18. $scoreSql = "select count(distinct student_id) as count from english_magic_word_score where mw_id={$mrId};";
  19. $scoreRs = $connect->createCommand($scoreSql)->queryRow();
  20. $scoreCount = isset($scoreRs['count']) ? $scoreRs['count'] : 0;
  21. return min($scoreCount, $markCount);
  22. }
  23. public function getStuMarkingStatus($studentIds, $mrId)
  24. {
  25. $result = array();
  26. if ($studentIds) {
  27. $sql = "select distinct m.student_id from english_magic_word_marking m inner join english_magic_word_score s on m.mw_id=s.mw_id and s.student_id=m.student_id where m.mw_id={$mrId} and m.student_id IN (" . implode(',', $studentIds) . ")";
  28. $connect = $this->getDbConnection();
  29. $rs = $connect->createCommand($sql)->queryAll();
  30. if ($rs) {
  31. foreach ($rs as $item) {
  32. $result[$item['student_id']] = 1;
  33. }
  34. }
  35. }
  36. return $result;
  37. }
  38. /**
  39. * 获取单词统计表格数据
  40. * @param $mwId
  41. * @return array
  42. * @throws CException
  43. */
  44. public function getWordList($mwId)
  45. {
  46. $result = array();
  47. $sql = "select m.student_id,m.is_right,m.right_answer,m.ocr_text,m.mw_sort,m.single_word_id,s.realname
  48. from english_magic_word_marking m join student_info s on m.student_id=s.student_id where mw_id='{$mwId}';";
  49. $connect = $this->getDbConnection();
  50. $rs = $connect->createCommand($sql)->queryAll();
  51. //有派生的单词序号
  52. $wordNo = array();
  53. if ($rs) {
  54. $sql = "SELECT c.mw_group_id,c.word_list FROM `english_magic_word_card` c inner join english_magic_word w
  55. on c.mw_group_id=w.mw_group_id where w.mw_id='{$mwId}'";
  56. $connect = $this->getDbConnection();
  57. $cardData = $connect->createCommand($sql)->queryRow();
  58. $cardData = isset($cardData['word_list']) && json_decode($cardData['word_list'], true) ? json_decode($cardData['word_list'], true) : array();
  59. $wordIndex =array();
  60. $index = $wordKey=$derivativeIndex=1;
  61. //单词序号
  62. foreach ($cardData as $item) {
  63. if (isset($item['is_derivative']) && !$item['is_derivative']) {
  64. $wordIndex[$item['single_word_id']] = $index;
  65. $index++;
  66. }
  67. }
  68. //单词序号(含派生)
  69. if($wordIndex){
  70. foreach($cardData as $item){
  71. if(isset($wordIndex[$item['single_word_id']])){
  72. $no=$wordIndex[$item['single_word_id']];
  73. if($item['is_derivative']){
  74. $no.="(派生{$derivativeIndex})";
  75. $derivativeIndex++;
  76. }else{
  77. $derivativeIndex=1;
  78. }
  79. $wordNo[$wordKey]=$no;
  80. }
  81. $wordKey++;
  82. }
  83. }
  84. foreach ($rs as $item) {
  85. $mwSort =$item['mw_sort'];
  86. $result[$mwSort]['right_rate'] = '';
  87. if(!isset($result[$mwSort]['right_count'])){
  88. $result[$mwSort]['right_count'] = 0;
  89. }
  90. if($item['is_right']) {
  91. $result[$mwSort]['right_count'] += 1;
  92. }
  93. $result[$mwSort]['no'] = $item['mw_sort'];
  94. $result[$mwSort]['mw_sort'] = $item['mw_sort'];
  95. $result[$mwSort]['single_word_id'] = $item['single_word_id'];
  96. $result[$mwSort]['right_answer'] = str_replace('&nbsp;',' ',$item['right_answer']);;
  97. if(!isset($result[$mwSort]['wrong_list'])){
  98. $result[$mwSort]['wrong_list'] = '';
  99. }
  100. if (!$item['is_right']) {
  101. $result[$mwSort]['wrong_list'] .= sprintf('%s(%s) ', $item['realname'], $item['ocr_text']).',';
  102. }
  103. if (isset($result[$mwSort]['total_count'])) {
  104. $result[$mwSort]['total_count'] += 1;
  105. } else {
  106. $result[$mwSort]['total_count'] = 1;
  107. }
  108. }
  109. }
  110. $list = array_values($result);
  111. $rate = array();
  112. foreach ($list as $key => &$item) {
  113. $item['right_rate'] = $item['total_count'] ? round($item['right_count'] / $item['total_count'], 2) * 100 . '%' : 0;
  114. $item['rate'] = $item['total_count'] ? round($item['right_count'] / $item['total_count'], 2) : 0;
  115. //去掉末尾的逗号
  116. $item['wrong_list']=trim($item['wrong_list'],',');
  117. array_push($rate, $item['rate']);
  118. unset($list[$key]['total_count']);
  119. }
  120. if($list && $rate) {
  121. array_multisort($rate, SORT_DESC, $list);
  122. }
  123. if($wordNo){
  124. foreach($list as &$item){
  125. if(isset($wordNo[$item['mw_sort']]) ){
  126. $item['no']=$wordNo[$item['mw_sort']];
  127. }else{
  128. $item['no']='';
  129. }
  130. }
  131. }
  132. return $list;
  133. }
  134. /**
  135. * 获取班级学生词汇宝统计表格数据
  136. * @param $mwId
  137. * @param $classId
  138. * @return array
  139. * @throws CException
  140. */
  141. public function getStudentRateList($mwId, $classId)
  142. {
  143. $result = array();
  144. $sql = "select m.score,m.score_rate,m.words_count,s.realname,s.student_id,scr.serial_number,m.create_time,m.single_words_count
  145. from english_magic_word_score m inner join student_info s on m.student_id=s.student_id
  146. join student_class_relation as scr on scr.student_id = m.student_id and scr.class_id = '{$classId}' where mw_id='{$mwId}';";
  147. $connect = $this->getDbConnection();
  148. $rs = $connect->createCommand($sql)->queryAll();
  149. if ($rs) {
  150. foreach ($rs as $item) {
  151. $result[$item['student_id']]['right_rate'] = $item['score_rate'] . '%';
  152. $result[$item['student_id']]['student_name'] = $item['realname'];
  153. $result[$item['student_id']]['no'] = $item['serial_number'];
  154. //$result[$item['student_id']]['wrong_count'] = round((1 - $item['score_rate'] / 100) * $item['words_count']);
  155. $result[$item['student_id']]['wrong_count'] = $item['words_count'] - $item['score'] >= 0 ? $item['words_count'] - $item['score'] : 0;
  156. $result[$item['student_id']]['rate_change'] = '+0%';
  157. $result[$item['student_id']]['rate'] = $item['score_rate'];
  158. $result[$item['student_id']]['create_time'] = $item['create_time'];
  159. }
  160. }
  161. $oldestSql = "select m.student_id,m.score_rate,m.create_time from english_magic_word_score m inner join english_magic_word w
  162. on m.mw_id=w.mw_id where w.class_id={$classId} order by m.create_time asc";
  163. $oldest = $connect->createCommand($oldestSql)->queryAll();
  164. if ($oldest) {
  165. foreach ($oldest as $item) {
  166. if (isset($result[$item['student_id']])) {
  167. if (isset($result[$item['student_id']]['rate']) && isset($result[$item['student_id']]['create_time']) && $item['create_time']<$result[$item['student_id']]['create_time']) {
  168. $result[$item['student_id']]['rate_change'] = $item['score_rate'] > $result[$item['student_id']]['rate'] ? '-' . ($item['score_rate'] - $result[$item['student_id']]['rate']) . '%' : '+' . ($result[$item['student_id']]['rate'] - $item['score_rate']) . '%';
  169. }
  170. }
  171. }
  172. }
  173. $result = array_values($result);
  174. if($result) {
  175. $rate = _array_column($result, 'rate');
  176. array_multisort($rate, SORT_DESC, $result);
  177. }
  178. return $result;
  179. }
  180. }