SEnglishWriting.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. class SEnglishWriting 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_writing';
  11. }
  12. /**
  13. * 词汇宝产品列表
  14. */
  15. public function getWritingList($condition = array(), $orderBy = array("ew.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 ew.ew_id,ew.ew_group_id,ew.`name`,c.class_id,c.class_name,is_marking_all_html,marking_status,ew.reset_times,ew.create_time,ew.week_num,ews.topic_no,gu.is_write
  21. from english_writing ew join class c on ew.class_id = c.class_id join english_writing_setting ews on ew.ew_group_id = ews.ew_group_id
  22. join english_writing_guidance gu on ews.ewg_id=gu.ewg_id
  23. {$condition}
  24. group by ew.ew_id
  25. {$orderBy}
  26. ")->query();
  27. $rs = $this->paging($sCon, $handle, $pageSize);
  28. $markingModel = new SEnglishWritingMarking();
  29. if($rs['rs']){
  30. foreach($rs['rs'] as $k=>$v){
  31. $rs['rs'][$k]['totalCount'] = 0;
  32. $rs['rs'][$k]['pdfCount'] = 0;
  33. $rs['rs'][$k]['isDown'] = 0;
  34. $rs['rs'][$k]['downTime'] = '';
  35. $rs['rs'][$k]['type_name'] = '';
  36. $rs['rs'][$k]['week_no'] = $this->getWeekOrder($v['ew_id']);
  37. $week_id = $v['ew_id'];
  38. $sql = "select COUNT(student_id) AS totalCount,SUM(CASE WHEN is_week_pdf = 1 THEN 1 ELSE 0 END) AS pdfCount,SUM(CASE WHEN is_card_pdf = 1 THEN 1 ELSE 0 END) AS cardCount from english_writing_student where ew_id = '{$week_id}'";
  39. $countArr = $sCon->createCommand($sql)->queryRow();
  40. if($countArr){
  41. $rs['rs'][$k]['totalCount'] = isset($countArr['totalCount'])?$countArr['totalCount']:0;
  42. $rs['rs'][$k]['pdfCount'] = isset($countArr['pdfCount'])?$countArr['pdfCount']:0;
  43. $rs['rs'][$k]['cardCount'] = isset($countArr['cardCount'])?$countArr['cardCount']:0;
  44. $rs['rs'][$k]['markCount'] = $markingModel->getMarkingCount($week_id);
  45. }
  46. $sql = "select week_download_time from english_writing_student where ew_id = '{$week_id}' and is_week_download = 1 order by week_download_time desc limit 1";
  47. $isDownArr = $sCon->createCommand($sql)->queryRow();
  48. if($isDownArr){
  49. $rs['rs'][$k]['isDown'] = 1;
  50. $rs['rs'][$k]['downTime'] = isset($isDownArr['week_download_time'])?date("Y-m-d H:i",$isDownArr['week_download_time']):'';
  51. }
  52. }
  53. }
  54. return $rs;
  55. }
  56. public function getWeekOrder($ewId)
  57. {
  58. $ewModel = self::findByPk($ewId);
  59. if($ewModel) {
  60. $sql = "select count(*) from english_writing ew left join english_writing_setting ews on ews.ew_group_id=ew.ew_group_id where ew_id < '{$ewId}' and ews.product_type=32 and class_id = '{$ewModel['class_id']}' and year_num={$ewModel['year_num']} and week_num={$ewModel['week_num']}";
  61. $rs = $this->getDbConnection()->createCommand($sql)->queryScalar();
  62. }
  63. return isset($rs) ? $rs + 1 : 1;
  64. }
  65. //分页获取学生数据
  66. public function getStudentsByPages(){
  67. $result = array();
  68. $sql = "select count(0) as count from student_info";
  69. $connect = $this->getDbConnection();
  70. $countArr = $connect->createCommand($sql)->queryRow();
  71. if($countArr && $countArr['count']){
  72. $count = $countArr['count'];
  73. $limit = 10000;
  74. $page = ceil($count/$limit);
  75. $_sql = "select * from student_info";
  76. for($a = 1;$a <= $page;$a++){
  77. $offset = ($a - 1)*$limit;
  78. $_sqls = $_sql." limit {$offset},{$limit}";
  79. $data = $connect->createCommand($_sqls)->queryAll();
  80. foreach($data as $k=>$v){
  81. $result['school_student_info'][$v['student_id']] = $v;
  82. $result['school_student_names'][$v['student_id']] = $v['realname'];
  83. }
  84. unset($data);
  85. }
  86. }
  87. return $result;
  88. }
  89. public function condition($condition = array()){
  90. return $condition ? " where ".implode(" and ", $condition) : "";
  91. }
  92. public function orderBy($orderBy = array()){
  93. return $orderBy ? " order by ".implode(",", $orderBy) : "";
  94. }
  95. public function paging($conn, $handle, $pageSize){
  96. $pager = new CPagination($handle->rowCount, $pageSize);
  97. $handle = $conn->createCommand($handle->queryString." limit :offset, :limit");
  98. $handle->bindValue(":offset", $pager->currentPage * $pager->pageSize);
  99. $handle->bindValue(":limit", $pager->pageSize);
  100. $rs = $handle->queryAll();
  101. return array("rs" => $rs, "pager" => $pager);
  102. }
  103. }