SEnglishMagicWord.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. class SEnglishMagicWord 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';
  11. }
  12. /**
  13. * 词汇宝产品列表
  14. */
  15. public function getMagicWord($condition = array(), $orderBy = array("er.create_time desc"), $pageSize = 10){
  16. $condition = $this->condition($condition);
  17. $orderBy = $this->orderBy($orderBy);
  18. $sCon = $this->getDbConnection();
  19. $handle = $sCon->createCommand("
  20. select er.mw_id,er.mw_group_id,er.`name`,c.class_id,c.class_name,ers.type,ers.practice_type,ers.scan_type,is_marking_all_html,marking_status,er.reset_times,er.create_time,er.week_num from english_magic_word er join class c on er.class_id = c.class_id join english_magic_word_setting ers on er.mw_group_id = ers.mw_group_id
  21. {$condition}
  22. group by er.mw_id
  23. {$orderBy}
  24. ")->query();
  25. $rs = $this->paging($sCon, $handle, $pageSize);
  26. $markingModel = new SEnglishMagicWordMarking();
  27. if($rs['rs']){
  28. foreach($rs['rs'] as $k=>$v){
  29. $rs['rs'][$k]['totalCount'] = 0;
  30. $rs['rs'][$k]['pdfCount'] = 0;
  31. $rs['rs'][$k]['isDown'] = 0;
  32. $rs['rs'][$k]['downTime'] = '';
  33. $rs['rs'][$k]['type_name'] = '';
  34. $rs['rs'][$k]['week_no'] = $this->getWeekOrder($v['mw_id']);
  35. $rs['rs'][$k]['is_card_complete'] = $this->isCardComplete($v['mw_id']);
  36. $week_id = $v['mw_id'];
  37. $sql = "select COUNT(student_id) AS totalCount,SUM(CASE WHEN is_week_pdf = 1 THEN 1 ELSE 0 END) AS pdfCount from english_magic_word_student where mw_id = '{$week_id}'";
  38. $countArr = $sCon->createCommand($sql)->queryRow();
  39. if($countArr){
  40. $rs['rs'][$k]['totalCount'] = isset($countArr['totalCount'])?$countArr['totalCount']:0;
  41. $rs['rs'][$k]['pdfCount'] = isset($countArr['pdfCount'])?$countArr['pdfCount']:0;
  42. $rs['rs'][$k]['markCount'] = $markingModel->getMarkingCount($week_id);
  43. }
  44. $sql = "select week_download_time from english_magic_word_student where mw_id = '{$week_id}' and is_week_download = 1 order by week_download_time desc limit 1";
  45. $isDownArr = $sCon->createCommand($sql)->queryRow();
  46. if($isDownArr){
  47. $rs['rs'][$k]['isDown'] = 1;
  48. $rs['rs'][$k]['downTime'] = isset($isDownArr['week_download_time'])?date("Y-m-d H:i",$isDownArr['week_download_time']):'';
  49. }
  50. }
  51. }
  52. return $rs;
  53. }
  54. /**
  55. * 批改后pdf是否全部生成
  56. * @param $mwId
  57. * @return bool
  58. */
  59. public function isCardComplete($mwId){
  60. $sql = "select SUM(IF(ws.is_card_pdf=1,1,0)) as pdf_count,SUM(IF(s.create_time IS NOT NULL, 1, 0)) as mark_count from english_magic_word_student ws
  61. left JOIN english_magic_word_score s on s.mw_id=ws.mw_id and s.student_id=ws.student_id
  62. where ws.mw_id='{$mwId}'";
  63. $rs = $this->getDbConnection()->createCommand($sql)->queryRow();
  64. if($rs && $rs['pdf_count']>0){
  65. return true;
  66. }else{
  67. return false;
  68. }
  69. }
  70. public function getWeekOrder($mwId)
  71. {
  72. $mwModel = self::findByPk($mwId);
  73. if($mwModel) {
  74. $sql = "select count(*) from english_magic_word em left join english_magic_word_setting ems on ems.mw_group_id=em.mw_group_id where mw_id < '{$mwId}' and ems.product_type=33 and class_id = '{$mwModel['class_id']}' and year_num={$mwModel['year_num']} and week_num={$mwModel['week_num']}";
  75. $rs = $this->getDbConnection()->createCommand($sql)->queryScalar();
  76. }
  77. return isset($rs) ? $rs + 1 : 1;
  78. }
  79. //分页获取学生数据
  80. public function getStudentsByPages(){
  81. $result = array();
  82. $sql = "select count(0) as count from student_info";
  83. $connect = $this->getDbConnection();
  84. $countArr = $connect->createCommand($sql)->queryRow();
  85. if($countArr && $countArr['count']){
  86. $count = $countArr['count'];
  87. $limit = 10000;
  88. $page = ceil($count/$limit);
  89. $_sql = "select * from student_info";
  90. for($a = 1;$a <= $page;$a++){
  91. $offset = ($a - 1)*$limit;
  92. $_sqls = $_sql." limit {$offset},{$limit}";
  93. $data = $connect->createCommand($_sqls)->queryAll();
  94. foreach($data as $k=>$v){
  95. $result['school_student_info'][$v['student_id']] = $v;
  96. $result['school_student_names'][$v['student_id']] = $v['realname'];
  97. }
  98. unset($data);
  99. }
  100. }
  101. return $result;
  102. }
  103. public function condition($condition = array()){
  104. return $condition ? " where ".implode(" and ", $condition) : "";
  105. }
  106. public function orderBy($orderBy = array()){
  107. return $orderBy ? " order by ".implode(",", $orderBy) : "";
  108. }
  109. public function paging($conn, $handle, $pageSize){
  110. $pager = new CPagination($handle->rowCount, $pageSize);
  111. $handle = $conn->createCommand($handle->queryString." limit :offset, :limit");
  112. $handle->bindValue(":offset", $pager->currentPage * $pager->pageSize);
  113. $handle->bindValue(":limit", $pager->pageSize);
  114. $rs = $handle->queryAll();
  115. return array("rs" => $rs, "pager" => $pager);
  116. }
  117. }