condition($condition); $orderBy = $this->orderBy($orderBy); $con = $this->getDbConnection(); $handle = $con->createCommand(" select p.gp_id,p.name,p.reset_times,g.gp_group_id,g.setting,g.status,g.repair_info,c.grade,c.class_id,c.class_name,p.learn_tube_reset_count,p.learn_tube_reset_time,p.create_time from general_product p join general_product_setting g on g.gp_group_id=p.gp_group_id join class c on p.class_id= c.class_id {$condition} group by p.gp_id {$orderBy} ")->query(); $rs = $this->paging($this->getDbConnection(), $handle, $pageSize); if ($rs['rs']) { foreach ($rs['rs'] as $k => $v) { $setting = json_decode($v['setting'],true); $rs['rs'][$k]['totalCount'] = 0; $rs['rs'][$k]['pdfCount'] = 0; $rs['rs'][$k]['isDown'] = 0; $rs['rs'][$k]['downTime'] = ''; $rs['rs'][$k]['createType'] = isset($setting['create_type'])?$setting['create_type']:0; $gp_id = $v['gp_id']; $sql = "select COUNT(distinct s.student_id) AS totalCount,SUM(CASE WHEN s.is_create_pdf = 1 THEN 1 ELSE 0 END) AS pdfCount from general_product_student s inner join student_info i on s.student_id=i.student_id where s.gp_id = '{$gp_id}'"; $countArr = $con->createCommand($sql)->queryRow(); if ($countArr) { $rs['rs'][$k]['totalCount'] = isset($countArr['totalCount']) ? $countArr['totalCount'] : 0; $rs['rs'][$k]['pdfCount'] = isset($countArr['pdfCount']) ? $countArr['pdfCount'] : 0; } $sql = "select download_time from general_product_student where gp_id = '{$gp_id}' and is_download = 1 order by download_time desc limit 1"; $isDownArr = $con->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 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); } public function condition($condition = array()){ return $condition ? " where ".implode(" and ", $condition) : ""; } public function orderBy($orderBy = array()){ return $orderBy ? " order by ".implode(",", $orderBy) : ""; } /** * 专题超出次数的班级 * @param $gpId * @param $productType * @param $classIds * @return array * @throws CDbException * @throws CException */ public function classHistory($gpId, $productType,$classIds){ $list = array(); $rs = $this->getDbConnection()->createCommand("select g.setting,c.class_id,c.class_name from general_product p join general_product_setting g on g.gp_group_id=p.gp_group_id join class c on p.class_id= c.class_id where g.product_type={$productType} and p.class_id in ($classIds)")->queryAll(); if($rs){ foreach ($rs as $item){ $setting = json_decode($item['setting'],true); $specialId = isset($setting['pc_ids'][0]['pc_id']) ? $setting['pc_ids'][0]['pc_id'] : 0; if($specialId && $gpId==$specialId){ $list[$item['class_id']]['class_name'] = $item['class_name']; if(isset($list[$item['class_id']]['special_count'])){ $list[$item['class_id']]['special_count']++; }else{ $list[$item['class_id']]['special_count'] = 1; } } } } $limitClass = array(); if($list){ foreach ($list as $key=>$item){ if($item['special_count']>=3){ array_push($limitClass,$item['class_name']); } } } return $limitClass; } //校本纠错本班级列表 public function getCorrectClassList($gpGroupId){ $conn = $this->getDbConnection(); $sql="select gp_id,gp.class_id,c.class_name,gp.name,create_time,c.grade from general_product gp left join class c on c.class_id=gp.class_id where gp_group_id='{$gpGroupId}'"; $result=$conn->createCommand($sql)->queryAll(); return $result; } //纠错本学生 public function getCorrectStudent($gpId){ $conn = $this->getDbConnection(); $sql="select gp_id,student_id,is_create_pdf,download_time,is_download from general_product_student where gp_id='{$gpId}'"; $result=$conn->createCommand($sql)->queryAll(); return $result; } //读取纠错本配置信息 public function getGeneralSetting($gpGroupId){ $conn = $this->getDbConnection(); $sql="select setting from general_product_setting where gp_group_id='{$gpGroupId}'"; $result=$conn->createCommand($sql)->queryRow(); if($result){ return $result['setting']; }else{ return null; } } }