123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- class SExamProductStatus extends MyActiveRecord
- {
- public static function model($className = __CLASS__)
- {
- return parent::model($className);
- }
- public function tableName()
- {
- return 'exam_product_status';
- }
- /**
- * 产品列表
- * @param array $condition
- * @param array $orderBy
- * @param int $type
- * @param int $pageSize
- * @return array
- * @throws CException
- */
- public function getProductList($condition = array(), $orderBy = array("er.create_time desc"), $type, $pageSize = 10){
- $condition = $this->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);
- }
- }
|