123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559 |
- <?php
- /**
- * Created by 上海互教教育科技有限公司.
- * User: 刘红伟
- * QQ : 454303753
- * Date: 2017/11/22 0022
- * Time: 下午 17:43
- */
- defined("ROLE_USER") or define("ROLE_USER", 1);
- defined("ROLE_SU") or define("ROLE_SU", 2);
- class NewSchoolManager extends SchoolManager{
- function __construct($coachId, $role = ROLE_USER,$pad='')
- {
- parent::__construct($coachId,$role,$pad);
- }
- /**
- * 设置试卷纸张类型
- * @param array $rs
- */
- private function setPaperSize(&$rs)
- {
- if($rs["rs"])
- {
- foreach($rs["rs"] as $key => $val)
- {
- $tplData = json_decode($val["tpl_data"], true);
- $paperSize = null;
- $examDate = null;
- if(in_array($val["tpl_index"], Yii::app()->params["custom_tpls_ids"])){
- switch($val["tpl_index"]){
- case "12":
- $paperSize = "A3";
- break;
- case "13":
- $paperSize = "A4";
- break;
- case "14":
- $paperSize = "8K";
- break;
- case "15":
- $paperSize = "16K";
- break;
- case "2012":
- $paperSize = "A3";
- break;
- case "2013":
- $paperSize = "A4";
- break;
- case "2014":
- $paperSize = "8K";
- break;
- case "2015":
- $paperSize = "16K";
- break;
- case "2016":
- $paperSize = "A3";
- break;
- case "2017":
- $paperSize = "A4";
- break;
- case "2018":
- $paperSize = "8K";
- break;
- case "2019":
- $paperSize = "16K";
- break;
- case "1012":
- $paperSize = "A3";
- break;
- case "1013":
- $paperSize = "A4";
- break;
- case "1014":
- $paperSize = "8K";
- break;
- case "1015":
- $paperSize = "16K";
- break;
- case "1016":
- $paperSize = "A3";
- break;
- case "1017":
- $paperSize = "A4";
- break;
- case "1018":
- $paperSize = "8K";
- break;
- case "1019":
- $paperSize = "16K";
- break;
- case "3012":
- $paperSize = "A3";
- break;
- case "3013":
- $paperSize = "A4";
- break;
- case "3014":
- $paperSize = "8K";
- break;
- case "3015":
- $paperSize = "16K";
- break;
- case "3016":
- $paperSize = "A3";
- break;
- case "3017":
- $paperSize = "A4";
- break;
- case "3018":
- $paperSize = "8K";
- break;
- case "3019":
- $paperSize = "16K";
- break;
- case "4012":
- $paperSize = "A3";
- break;
- case "4013":
- $paperSize = "A4";
- break;
- case "4014":
- $paperSize = "8K";
- break;
- case "4015":
- $paperSize = "16K";
- break;
- case "4016":
- $paperSize = "A3";
- break;
- case "4017":
- $paperSize = "A4";
- break;
- case "4018":
- $paperSize = "8K";
- break;
- case "4019":
- $paperSize = "16K";
- break;
- case "2011":
- $paperSize = "A3";
- break;
- case "3011":
- $paperSize = "A3";
- break;
- }
- }
- if(in_array($val["tpl_index"], Yii::app()->params["custom_tpls_ids"])){
- switch($val["tpl_index"]){
- case "16":
- $paperSize = "A3";
- break;
- case "3016":
- $paperSize = "A3";
- break;
- case "3017":
- $paperSize = "A4";
- break;
- case "3013":
- $paperSize = "A4";
- break;
- case "3007":
- $paperSize = "A3";
- break;
- case "17":
- $paperSize = "A4";
- break;
- case "18":
- $paperSize = "8K";
- break;
- case "19":
- $paperSize = "16K";
- break;
- case "2011":
- $paperSize = "A3";
- break;
- case "3011":
- $paperSize = "A3";
- break;
- }
- }
- if($tplData){
- if(!isset($tplData["examDate"]) || !($examDate = strtotime($tplData["examDate"])))
- $examDate = $val["create_time"];
- if($paperSize === null && isset($tplData["paper"]) && $tplData["paper"] == 1)
- $paperSize = "A3";
- }
- if($examDate === null)
- {
- $examDate = $val["create_time"];
- }
- if($paperSize === null)
- {
- $paperSize = "A4";
- }
- $rs["rs"][$key]["exam_time"] = $examDate;
- $rs["rs"][$key]["paper_size"] = $paperSize;
- }
- }
- return $rs;
- }
- /**
- * 获取考试列表
- * 用于:
- *
- * @param $condition
- * @param $orderBy
- * @param int $pageSize 页码
- */
- public function getPrintGroupList($condition,$orderBy,$pageSize=9)
- {
- $condition = $this->condition($condition);
- $orderBy = $this->orderBy($orderBy);
- $handle = $this->sConn->createCommand("
- select e.name as print_name,e.class_id,e.is_display,e.subject_id,e.exam_id,e.create_time,e.tpl_data,e.tpl_index,e.is_new,e.school_card_status,e.school_card_length,eg.*,c.grade
- from exam_group as eg
- left JOIN exam e ON eg.exam_group_id = e.exam_group_id and e.semester_id = {$this->semester['id']} and eg.status >0
- left join class c on c.class_id=e.class_id
- {$condition}
- group by eg.exam_group_id
- {$orderBy}
- ")->query();
- //进行分页
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- if($rs["rs"] && !empty($rs["rs"]))
- {
- return $this->setPaperSize($rs);
- }
- return $rs;
- }
- /**
- * 获取考试列表
- * 用于:个性化学习宝督学列表
- *
- * @param $condition
- * @param $orderBy
- * @param int $pageSize 页码
- */
- public function getExamGroupList($condition,$orderBy,$pageSize=9)
- {
- $condition = $this->condition($condition);
- $orderBy = $this->orderBy($orderBy);
- $sql = "select e.name,e.exam_id,e.create_time,e.tpl_data,count(e.class_id) as class_count,e.exam_group_id,eg.mark_type,e.subject_id
- from exam_group as eg
- JOIN exam e ON eg.exam_group_id = e.exam_group_id and e.semester_id = {$this->semester['id']} and eg.status >0
- join student_improve_score_plan_topics spt on e.exam_id=spt.plan_id
- {$condition}
- group by eg.exam_group_id
- {$orderBy}";
- $handle = $this->sConn->createCommand($sql)->query();
- //进行分页
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- return $rs;
- }
- /**
- * 获取已发送标注或未发送标注的考试
- * @param $is_labelled
- *
- * @return array|\CDbDataReader
- */
- public function getPaerLabelledByExam($is_labelled)
- {
- return $this->sConn->createCommand("select p.exam_id from paper as p JOIN exam as e on p.exam_id = e.exam_id where e.semester_id = {$this->semester['id']} and p.is_labelled = ".$is_labelled)->queryAll();
- }
- /**
- * 通过班级ID,获取考试信息
- * @param $class_ids
- *r
- * @return array|\CDbDataReader
- */
- public function getClassIdByExam($class_ids)
- {
- if(!$class_ids || !is_array($class_ids))
- {
- return array();
- }
- return $this->sConn->createCommand("select exam_id from exam where class_id in (".implode(',',$class_ids).")")->queryAll();
- }
- /**
- * 通过学期获取班级信息
- * @param $semesterId
- *
- * @return array|\CDbDataReader
- */
- public function getSemesterClasses($semesterId){
- $classes = array();
- if($semesterId){
- $classes = $this->sConn->createCommand("select * from class where semester_id = '{$semesterId}' and is_hide=0")->queryAll();
- }
- return $classes;
- }
- /**
- *
- * 班级考试列表
- * @param $condition
- * @param $orderBy
- * @param int $pageSize
- *
- * @return array
- */
- public function getExamsByExamGroupIdList($condition,$orderBy,$pageSize=9)
- {
- $condition = $this->condition($condition);
- $orderBy = $this->orderBy($orderBy);
- $handle = $this->sConn->createCommand("
- select exam_id,exam_group_id,semester_id,upload_status,`status`,class_id,subject_id,`name` as print_name,`type`,create_time,tpl_index,tpl_data,is_new
- from exam
- {$condition}
- {$orderBy}
- ")->query();
- //进行分页
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- if($rs["rs"] && !empty($rs["rs"]))
- {
- return $this->setPaperSize($rs);
- }
- return $rs;
- }
- /**
- * 通过老师名称获取老师与班级信息
- */
- public function getTeachersByteacherName($teacher_name){
- $teachers = array();
- $class_ids = array();
- if($teacher_name){
- $teacher_data = $this->sConn->createCommand(" select * from teacher where teacher_name LIKE '%{$teacher_name}%' ")->queryAll();
- if($teacher_data)
- {
- foreach($teacher_data as $v)
- {
- $teachers[$v['teacher_id']] = $v['teacher_id'];
- }
- if($teachers)
- {
- $class_teacher_data = $this->sConn->createCommand(" select * from teacher_class_relation where teacher_id in(".implode(',',$teachers).") and semester_id =".$this->semester['id']." ")->queryAll();
- if($class_teacher_data)
- {
- foreach($class_teacher_data as $v)
- {
- $class_ids[$v['class_id']] = $v['class_id'];
- }
- }
- }
- }
- }
- return $class_ids;
- }
- public function getBacklogList($condition = array(), $orderBy = array("add_time desc")){
- $condition = Arr::merge($condition, array("c.semester_id = '{$this->semester["id"]}'"));
- $condition = $this->condition($condition);
- $orderBy = $this->orderBy($orderBy);
- $handle =$this->sConn->createCommand("
- SELECT
- c.class_name,
- e.`name` AS exam_name,
- e.subject_id,
- e.class_id,
- e.exam_id,
- e.is_backlog,
- e.create_time,
- e.is_display,
- eg.upload_status AS group_upload_status,
- eg.mark_type,
- eg.mark_status,
- e.exam_group_id,
- eg.import_score_type
- FROM exam AS e
- JOIN `class` AS c ON e.class_id = c.class_id
- JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id
- {$condition}
- GROUP BY
- e.class_id,
- e.exam_id
- {$orderBy}");
- $rs = $handle->queryAll();
- $examsIds = $this->grouping($rs, "exam_id", true);
- $studentAnswerImg=array();
- if($examsIds){
- $paperData=$this->sConn->createCommand("select paper_id,exam_id from paper where exam_id in(".implode(',',$examsIds).")")->queryAll();
- $studentAnswerImg=array();
- $paperIds=array();
- $paperIdToExamId=array();
- if($paperData){
- foreach ($paperData as $val){
- $paperIds[]=$val['paper_id'];
- $paperIdToExamId[$val['paper_id']]=$val['exam_id'];
- }
- $sql="select count(DISTINCT student_id) as count,paper_id from student_paper_topic_rs where paper_id in(".implode(',',$paperIds).") and answer_url<>'' group by paper_id ";
- $rsImg=$this->sConn->createCommand($sql)->queryAll();
- if($rsImg){
- foreach ($rsImg as $val){
- $studentAnswerImg[$paperIdToExamId[$val['paper_id']]]=$val['count'];
- }
- }
- }
- }
- $examsIds = "'".implode("','", $examsIds)."'";
- $sprs = $this->sConn->createCommand("select exam_id, is_complete, is_feedback,is_wrongbook_pdf,is_wbisp_pdf,is_isp_pdf from student_paper_relation where exam_id in({$examsIds}) and is_del=0")->queryAll();
- $examsSprs = array();
- foreach($sprs as $key => $val){
- if(!isset($examsSprs[$val["exam_id"]]))
- $examsSprs[$val["exam_id"]] = array();
- $examsSprs[$val["exam_id"]][] = $val;
- }
- $examsStudentsCount = array();
- foreach($examsSprs as $examId => $sprs){
- $examsStudentsCount[$examId] = array(
- "is_complete_count" => 0,
- "is_uploaded_count" => 0,
- "wrongbook_pdf_count" => 0,
- "wbisp_pdf_count" => 0,
- "isp_pdf_count" => 0,
- );
- $examsStudentsCount[$examId]["students_count"] = count($sprs);
- foreach($sprs as $k => $v){
- if($v["is_complete"] == 1)
- {
- $examsStudentsCount[$examId]["is_complete_count"]++;
- }
- if($v["is_feedback"] == 1)
- {
- $examsStudentsCount[$examId]["is_uploaded_count"]++;
- }
- if($v["is_wrongbook_pdf"] == 1)
- {
- $examsStudentsCount[$examId]["wrongbook_pdf_count"]++;
- }
- if($v["is_wbisp_pdf"] == 1)
- {
- $examsStudentsCount[$examId]["wbisp_pdf_count"]++;
- }
- if($v["is_isp_pdf"] == 1)
- {
- $examsStudentsCount[$examId]["isp_pdf_count"]++;
- }
- }
- }
- foreach($rs as $key => $val){
- if(isset($examsStudentsCount[$val["exam_id"]])){
- $rs[$key]["students_count"] = $examsStudentsCount[$val["exam_id"]]["students_count"];
- $rs[$key]["is_complete_count"] = $examsStudentsCount[$val["exam_id"]]["is_complete_count"];
- $rs[$key]["is_uploaded_count"] = $examsStudentsCount[$val["exam_id"]]["is_uploaded_count"];
- $rs[$key]["wrongbook_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wrongbook_pdf_count"];
- $rs[$key]["wbisp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wbisp_pdf_count"];
- $rs[$key]["isp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["isp_pdf_count"];
- }
- else{
- $rs[$key]["students_count"] = 0;
- $rs[$key]["is_complete_count"] = 0;
- $rs[$key]["is_uploaded_count"] = 0;
- $rs[$key]["wrongbook_pdf_count"] = 0;
- $rs[$key]["wbisp_pdf_count"] = 0;
- $rs[$key]["isp_pdf_count"] = 0;
- }
- $rs[$key]["student_answer_img"] =0;
- if($val['import_score_type']){
- //导入成绩,判断图片
- if(isset($studentAnswerImg[$val['exam_id']])){
- $rs[$key]["student_answer_img"] =$studentAnswerImg[$val['exam_id']] ;
- }
- }
- }
- return $rs;
- }
- public function getPaperIdsByExamIds($examIds){
- $paperIds = array();
- if($examIds && is_array($examIds)){
- $sql = "select paper_id,exam_id from paper where exam_id in (".implode(',',$examIds).")";
- $paperInfo = $this->sConn->createCommand($sql)->queryAll();
- if($paperInfo){
- foreach ($paperInfo as $item) {
- $paperIds[] = $item['paper_id'];
- }
- }
- }
- return $paperIds;
- }
- public function getTopicWord($examGroupId){
- }
- }
|