condition($condition); $orderBy = $this->orderBy($orderBy); $sCon = $this->getDbConnection(); $handle =$sCon->createCommand(" 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 from class as c join exam as e on e.class_id = c.class_id join class_exam_printer as cep on cep.class_id = c.class_id and cep.exam_id = e.exam_id JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id join paper as p on p.exam_id = e.exam_id {$condition} group by class_id, exam_id, type {$orderBy} ")->query(); $rs = $this->paging($sCon, $handle, $pageSize); if($rs['rs']){ $studentClassModel = new SStudentClassRelation(); foreach($rs['rs'] as $k=>$v){ $rs['rs'][$k]['totalCount'] = 0; $rs['rs'][$k]['pdfCount'] = 0; $rs['rs'][$k]['isDown'] = 0; $rs['rs'][$k]['downTime'] = ''; $rs['rs'][$k]['type_name'] = ''; $exam_id = $v['exam_id']; $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}'"; $countArr = $sCon->createCommand($sql)->queryRow(); if($countArr){ $rs['rs'][$k]['totalCount'] = $studentClassModel->getRelationsByClassId_Status_0_count($v['class_id']); $rs['rs'][$k]['pdfCount'] = isset($countArr['pdfCount'])?$countArr['pdfCount']:0; } $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"; $isDownArr = $sCon->createCommand($sql)->queryRow(); if($isDownArr){ $rs['rs'][$k]['isDown'] = 1; $rs['rs'][$k]['downTime'] = isset($isDownArr['download_time'])?date("Y-m-d H:i",$isDownArr['download_time']):''; } } } return $rs; } //分页获取学生数据 public function getStudentsByPages(){ $result = array(); $sql = "select count(0) as count from student_info"; $connect = $this->getDbConnection(); $countArr = $connect->createCommand($sql)->queryRow(); if($countArr && $countArr['count']){ $count = $countArr['count']; $limit = 10000; $page = ceil($count/$limit); $_sql = "select * from student_info"; for($a = 1;$a <= $page;$a++){ $offset = ($a - 1)*$limit; $_sqls = $_sql." limit {$offset},{$limit}"; $data = $connect->createCommand($_sqls)->queryAll(); foreach($data as $k=>$v){ $result['school_student_info'][$v['student_id']] = $v; $result['school_student_names'][$v['student_id']] = $v['realname']; } unset($data); } } return $result; } public function condition($condition = array()){ return $condition ? " where ".implode(" and ", $condition) : ""; } public function orderBy($orderBy = array()){ return $orderBy ? " order by ".implode(",", $orderBy) : ""; } public function paging($conn, $handle, $pageSize){ $pager = new CPagination($handle->rowCount, $pageSize); $handle = $conn->createCommand($handle->queryString." limit :offset, :limit"); $handle->bindValue(":offset", $pager->currentPage * $pager->pageSize); $handle->bindValue(":limit", $pager->pageSize); $rs = $handle->queryAll(); return array("rs" => $rs, "pager" => $pager); } }