SExamProductStatus.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. class SExamProductStatus extends MyActiveRecord
  3. {
  4. public static function model($className = __CLASS__)
  5. {
  6. return parent::model($className);
  7. }
  8. public function tableName()
  9. {
  10. return 'exam_product_status';
  11. }
  12. /**
  13. * 产品列表
  14. * @param array $condition
  15. * @param array $orderBy
  16. * @param int $type
  17. * @param int $pageSize
  18. * @return array
  19. * @throws CException
  20. */
  21. public function getProductList($condition = array(), $orderBy = array("er.create_time desc"), $type, $pageSize = 10){
  22. $condition = $this->condition($condition);
  23. $orderBy = $this->orderBy($orderBy);
  24. $sCon = $this->getDbConnection();
  25. $handle =$sCon->createCommand("
  26. select cep.*, c.class_name, e.subject_id, e.name as exam_name,e.is_new, e.tpl_index, e.tpl_data, e.upload_status, e.create_time,e.complete_time, e.is_display, eg.mark_type,eg.upload_status as group_upload_status, eg.mark_status,e.exam_group_id,p.tpl_doc_src,p.paper_id
  27. from class as c
  28. join exam as e on e.class_id = c.class_id
  29. join class_exam_printer as cep on cep.class_id = c.class_id and cep.exam_id = e.exam_id
  30. JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id
  31. join paper as p on p.exam_id = e.exam_id
  32. {$condition}
  33. group by class_id, exam_id, type
  34. {$orderBy}
  35. ")->query();
  36. $rs = $this->paging($sCon, $handle, $pageSize);
  37. if($rs['rs']){
  38. $studentClassModel = new SStudentClassRelation();
  39. foreach($rs['rs'] as $k=>$v){
  40. $rs['rs'][$k]['totalCount'] = 0;
  41. $rs['rs'][$k]['pdfCount'] = 0;
  42. $rs['rs'][$k]['isDown'] = 0;
  43. $rs['rs'][$k]['downTime'] = '';
  44. $rs['rs'][$k]['type_name'] = '';
  45. $exam_id = $v['exam_id'];
  46. $sql = "select SUM(CASE WHEN is_create_pdf = 1 THEN 1 ELSE 0 END) AS pdfCount from exam_product_status where product_type = {$type} and exam_id = '{$exam_id}'";
  47. $countArr = $sCon->createCommand($sql)->queryRow();
  48. if($countArr){
  49. $rs['rs'][$k]['totalCount'] = $studentClassModel->getRelationsByClassId_Status_0_count($v['class_id']);
  50. $rs['rs'][$k]['pdfCount'] = isset($countArr['pdfCount'])?$countArr['pdfCount']:0;
  51. }
  52. $sql = "select download_time from exam_product_status where product_type = {$type} and exam_id = '{$exam_id}' and is_download = 1 order by download_time desc limit 1";
  53. $isDownArr = $sCon->createCommand($sql)->queryRow();
  54. if($isDownArr){
  55. $rs['rs'][$k]['isDown'] = 1;
  56. $rs['rs'][$k]['downTime'] = isset($isDownArr['download_time'])?date("Y-m-d H:i",$isDownArr['download_time']):'';
  57. }
  58. }
  59. }
  60. return $rs;
  61. }
  62. //分页获取学生数据
  63. public function getStudentsByPages(){
  64. $result = array();
  65. $sql = "select count(0) as count from student_info";
  66. $connect = $this->getDbConnection();
  67. $countArr = $connect->createCommand($sql)->queryRow();
  68. if($countArr && $countArr['count']){
  69. $count = $countArr['count'];
  70. $limit = 10000;
  71. $page = ceil($count/$limit);
  72. $_sql = "select * from student_info";
  73. for($a = 1;$a <= $page;$a++){
  74. $offset = ($a - 1)*$limit;
  75. $_sqls = $_sql." limit {$offset},{$limit}";
  76. $data = $connect->createCommand($_sqls)->queryAll();
  77. foreach($data as $k=>$v){
  78. $result['school_student_info'][$v['student_id']] = $v;
  79. $result['school_student_names'][$v['student_id']] = $v['realname'];
  80. }
  81. unset($data);
  82. }
  83. }
  84. return $result;
  85. }
  86. public function condition($condition = array()){
  87. return $condition ? " where ".implode(" and ", $condition) : "";
  88. }
  89. public function orderBy($orderBy = array()){
  90. return $orderBy ? " order by ".implode(",", $orderBy) : "";
  91. }
  92. public function paging($conn, $handle, $pageSize){
  93. $pager = new CPagination($handle->rowCount, $pageSize);
  94. $handle = $conn->createCommand($handle->queryString." limit :offset, :limit");
  95. $handle->bindValue(":offset", $pager->currentPage * $pager->pageSize);
  96. $handle->bindValue(":limit", $pager->pageSize);
  97. $rs = $handle->queryAll();
  98. return array("rs" => $rs, "pager" => $pager);
  99. }
  100. }