controllerObj = $controllerObj; $documentRoot = Yii::app()->basePath . "/../"; require_once($documentRoot."lib/plugins/topic-html/vendor/autoload.php"); } /** * 生成PDF返回PDF地址 * @param $schoolId * @param $examId * @param $productType * @param $subjectId * @param int $force * @param int $viewHtml * @return array */ public function getTeachingPdf($schoolId,$examId,$productType,$subjectId,$force = 0,$viewHtml = 0) { if (!$schoolId) { $this->errorMsg(0, '学校ID不正确!'); } $this->schoolId = $schoolId; if(!$examId || !is_numeric($examId)){ $this->errorMsg(0, '考试ID参数不正确!'); } if (!$this->error) { $force = $viewHtml ? 1 : 0; if (is_cli()) { $force = 1; } $this->examId = $examId; $this->subjectId = $productType; $this->productType = $productType; //教师版记录初始化 SExamTeachingProduct::model()->initialize($examId,$productType,$subjectId); $this->examObj = new SExamTeachingProduct(); $examInfo = $this->examObj->getTeachingInfo($examId); if(!$examInfo){ $this->errorMsg(0, '没有考试信息!'); } } if (!$this->error) { if($examInfo['subject_id']){ $this->subjectId = $examInfo['subject_id']; $this->examGroupId = $examInfo['exam_group_id']; $this->classId = $examInfo['class_id']; } $pdfurl = $examInfo['pdf_path']; $res = array();//生成pdf命令结果 if(strpos($examInfo['pdf_path'],'http') !== false){ $force = 0; }else{ $force = 1; } if ($examInfo['pdf_path'] && !$force) { //文件已生成不再生成 $result = array( 'status' => 0, 'error' => '', 'is_create' => 1, 'pdf_url' => $pdfurl, 'pdf_path' => '', 'file_name' => sprintf("%s_%s_方法宝教学宝",$examInfo['exam_name'],$examInfo['class_name']) ); return $result; } } if (!$this->error) { $paperObj = new SPaper(); $ptrObj = new SPaperTopicRelation(); $this->sprObj = new SStudentPaperRelation(); $this->sptRsObj = new SStudentPaperTopicRs(); /**************************** 一、班级情况分析 ***********************************/ //当前考试需要的数据 $actionRs = $this->curExamNeedData($this->sprObj ,$paperObj); if ($actionRs) { list($paperId, $paperScore, $examStuScore, $absentStu) = $actionRs; } //上次考试需要的数据 if (!$this->error) { $actionRs = $this->preExamNeedData($examInfo,$this->sprObj,$paperObj); if ($actionRs) { list($prePaperScore, $preExamStuScore, $preAbsent) = $actionRs; } } //班级排名得分率人数等数据 if (!$this->error) { $classAnalyseArr = $this->getClassAnalyse($paperScore,$examStuScore,$prePaperScore, $preExamStuScore, $absentStu, $preAbsent); } //大幅进步,大幅退步,前5名和后5名($needStudentArr:得分大于0的学生) if (!$this->error) { list($largeOrderArr,$needStudentArr) = $this->getLargeOrder($examStuScore,$preExamStuScore,$absentStu,$preAbsent); } unset($preExamStuScore); /**************************** 二、考试情况分析 ***********************************/ $is_qxk_page = (isset($examInfo["qxk_paper_id"]) && $examInfo["qxk_paper_id"])?1:0; if (!$this->error) { $paperTopicInfo = $ptrObj->getPaperInfo($paperId); if(!$paperTopicInfo){ $this->errorMsg(0, '没有试卷题数据!'); }else{ $topicScoreArr = array(); foreach ($paperTopicInfo as $item) { $topicScoreArr[$item['topic_id']] = $item['score']; } $tplDataArr = json_decode($examInfo['tpl_data'], true); //$topicNoArr = $this->getTopicNoArr($paperTopicInfo, $tplDataArr); $changeDoTopicNoArr = $this->getChangeDoToicNoArr($paperTopicInfo, $tplDataArr); $topicNoArr = SPaperTopicRelation::model()->getPaperTopicDetailById($paperId,$tplDataArr,$is_qxk_page,$changeDoTopicNoArr); $topicIdsArr = array_keys($topicNoArr); $this->paperTopicIds = $topicIdsArr; unset($paperTopicInfo); } } // 学生得分 if (!$this->error) { $stuRsArr = $this->sptRsObj->getStudentRsOnePaper($paperId); if(!$stuRsArr){ $this->errorMsg(0, '没有学生做题数据!'); } } if (!$this->error) { $paperAnalyseArr = $this->paperAnalyse($topicNoArr,$stuRsArr,$needStudentArr,$topicScoreArr,$changeDoTopicNoArr); } /**************************** 三、知识点掌握情况 ***********************************/ //TODO 题型方法考察情况 if (!$this->error) { $topicInfoArr = $this->getTopicInfoArr($topicNoArr); } // if (!$this->error) { // $kpsAnalyseArr = $this->kpsAnalyse($topicInfoArr,$topicScoreArr,$topicNoArr,$stuRsArr,$needStudentArr); // } /**************************** 客观题得分 ***********************************/ if(!$this->error){ $answerScoreDetail = $this->objectTopicDetail($paperId,$examInfo, $this->paperTopicIds,$topicNoArr); } /**************************** 四、试卷讲评 ***********************************/ if (!$this->error) { $paperCommentsArr = $this->paperComments($needStudentArr,$stuRsArr,$topicScoreArr,$topicInfoArr,$topicNoArr); } if(!$this->error){ list($methodAnalyseArr,$methodTopics,$methodOfTopic) = $this->methodAnalyse($topicInfoArr,$paperCommentsArr); } /**************************** 四、方法对应题信息 ***********************************/ if(!$this->error){ $methodTopics = $this->getTopicInfoArr($methodTopics,1); } /************ 格式化试题*************/ $_topicInfoArr = array(); $_methodTopicArr = array(); $topicCss=$this->getTopicHtmlArr($_topicInfoArr, $topicInfoArr); $this->getTopicHtmlArr($_methodTopicArr, $methodTopics); /******************* 方法训练数据 ************/ if(!$this->error){ $methodPractice = array_slice($methodAnalyseArr,0,6); foreach ($methodPractice as &$item){ if(!empty($item['classic_topic_ids'])){ foreach ($item['classic_topic_ids'] as $topic_id){ $item['classic_topic_ids'][$topic_id] = isset($_methodTopicArr[$topic_id])?$_methodTopicArr[$topic_id]:array(); } self::arrayM_desc_sort($item['classic_topic_ids'], 'difficulty_degree'); } } } /**************************** 五、共性题 ***********************************/ if(!$this->error){ $commonTopics = $this->commonTopic($topicNoArr); if(empty($commonTopics)){ $this->errorMsg(0, '共性题未生成!'); } } /************ 同学优解*************/ if(!$this->error){ $besetAnswer = $this->bestAnswer($examInfo,$paperId,$this->controllerObj->schoolGroupId,$is_qxk_page); } /**************************** 生产HTML和PDF ***********************************/ if (!$this->error) { //学生名称 $stuInfoObj = new SStudentInfo(); $stuNameArr = $stuInfoObj->getStudentNames(array_keys($needStudentArr)); $classObj = new SClass(); $className = $classObj->getClassName($this->classId); $data = array(); $data['className'] = $className; $data['examInfo'] = $examInfo; $data['stuNameArr'] = $stuNameArr; $data['classAnalyseArr'] = $classAnalyseArr; $data['largeOrderArr'] = $largeOrderArr; $data['paperAnalyseArr'] = $paperAnalyseArr; $data['paperCommentsArr'] = $paperCommentsArr; $data['topicInfoArr'] = $_topicInfoArr; $data['stuNameArr'] = $stuNameArr; $data['methodAnalyseArr'] = $methodAnalyseArr; $data['commonTopics'] = $commonTopics; $data['answer_score_details'] = $answerScoreDetail; $data['methodTopicArr'] = $_methodTopicArr; $data['methodOfTopic'] = $methodOfTopic; $data['excellent_solution'] = $besetAnswer; $data['methodPractice'] = $methodPractice; $data['zsyas2Url'] = $this->getDomain(); $data['topicCss'] = $topicCss; $html = $this->controllerObj->renderPartial("/productexam/teach_method", $data, true); // if (is_cli()) { // $html = $this->controllerObj->viewRender("teach_physics", $data, true); // }else{ // if ($viewHtml) { // $this->controllerObj->renderPartial("teaching/teach_physics",$data);exit(); // }else{ // $html = $this->controllerObj->renderPartial("teaching/teach_physics", $data, true); // } // } unset($data); $actionRs = $this->htmlToPdf($res,$html,$className,$examInfo['exam_name']); if ($actionRs) { list($pdfurl, $pdfpath) = $actionRs; } } } if(!(isset($pdfurl) && $pdfurl && fileGetContents($pdfurl))){ $this->error[] = '文件尚未生成!!'.(!empty($res)?',错误信息:'.json_encode($res):''); } $result = array( 'status' => 1, 'error' => '', 'is_create' => 0, 'pdf_url' => '', 'pdf_path' => '', 'file_name' => sprintf("%s_%s_方法宝教学宝",$examInfo['exam_name'],$examInfo['class_name']) ); if (!$this->error) { $result['status'] = 0; $result['is_create'] = 1; $result['pdf_url'] = $pdfurl; $result['pdf_path'] = $pdfpath; }else{ $result['error'] = implode(',',$this->error); } return $result; } /** * @param $topicInfoArr * @param $topicDetailArr * @return string */ protected function getTopicHtmlArr(&$topicInfoArr, &$topicDetailArr) { $topicHtmlObj = new \TopicHtml\TopicArr\TopicHtmlArr(); $topicHtmlObj->setIsShowAnswerParse(false); $topicCssObj = new \TopicHtml\TopicArr\TopicCss(); $topicCssObj->setTopicFontSize('7.5pt'); //选择题题干和选项是否分离 $topicCss = $topicCssObj->getTopicCss(); foreach ($topicDetailArr as $topic_id => $topicInfo) { $topicInfoArr[$topic_id] = $topicHtmlObj->getTopicHtmlArr($topicInfo); unset($topicInfo); } if (!$topicCss) { $this->errorMsg(0, '获取试题样式失败'); return ''; } return $topicCss; } /** * 当前考试需要的数据 * @param $examObj * @param $examInfo * @param $sprObj * @param $paperObj */ private function curExamNeedData(&$sprObj,&$paperObj) { $error = array(); $examId = $this->examId; //试卷关联学生 $sprInfoArr = $sprObj->getStudentExamInfo(array($examId)); if(!$sprInfoArr){ $error[] = '考试没有学生数据!'; } if (!$error) { $examStuScore = array();//考试关联学生得分 $absentStu = array();//缺考学生 $paperId = 0; foreach($sprInfoArr as $key => $value){ $studentId = $value['student_id']; $paperId = $value['paper_id']; $examStuScore[$studentId] = $value['scoring']; if(empty($value['is_feedback'])) { $absentStu[$studentId] = $value['student_id']; } unset($sprInfoArr[$key]); } unset($sprInfoArr); //试卷总分 $paperScore = $paperObj->getPaperScore(array($paperId)); if(!$paperScore){ $error[] = '试卷总分不正确!'; } if (!$examStuScore) { $error[] = '没有当前班级数据!'; } } if ($error) { $this->errorMsg(0, implode(',', $error)); return false; }else{ return array($paperId,$paperScore, $examStuScore,$absentStu); } } /** * 上次考试需要的数据 * @param $examInfo * @param $examObj * @param $sprObj * @param $paperObj * @return array|boolean */ private function preExamNeedData($examInfo,$sprObj,$paperObj) { $error = array(); //$examId = $this->examId; //获取当前考试的上一次考试数据 //$cepObj = new SClassExamPrinter(); //$preInfo = $cepObj->getPreExamId($examId,$examInfo['subject_id'],$examInfo['class_id']); if(in_array($examInfo['subject_id'], Yii::app()->params['mathSubjectId'])) { $subjectCondition = ' e.subject_id in ('.implode(',',Yii::app()->params['mathSubjectId']).')'; }else { $subjectCondition = ' e.subject_id = '.$examInfo['subject_id']; } $sql = "SELECT e.exam_id, p.paper_id FROM exam e JOIN paper p ON p.exam_id = e.exam_id WHERE {$subjectCondition} and e.class_id = '" . $examInfo['class_id'] . "' AND e.complete_time < '" . $examInfo['complete_time'] . "' AND e.status = '1' ORDER BY e.create_time DESC LIMIT 1"; $preInfo = $this->getSchoolDbObj()->createCommand($sql)->queryRow(); $preExamId = isset($preInfo['exam_id'])?$preInfo['exam_id']:''; $prePaperScore = 0; $examRelPaper = array(); $preExamStuScore = array();//考试关联学生得分 $preAbsent = array(); if($preExamId){ $sprInfoArr = $sprObj->getStudentExamInfo(array($preExamId)); if(!$sprInfoArr){ $error[] = '考试没有关联学生数据!'; } if (!$error) { foreach($sprInfoArr as $key => $value){ if(empty($value['is_feedback'])) { $preAbsent[$value['student_id']] = $value['student_id']; } $studentId = $value['student_id']; $examRelPaper[$value['exam_id']] = $value['paper_id']; $preExamStuScore[$studentId] = $value['scoring']; unset($sprInfoArr[$key]); } unset($sprInfoArr); if($examRelPaper){ $prePaperScore = $paperObj->getPaperScore(array_values($examRelPaper)); } if(!$prePaperScore){ $error[] = '试卷总分不正确!'; } } } if ($error) { $this->errorMsg(0, implode(',', $error)); return false; }else{ return array($prePaperScore, $preExamStuScore,$preAbsent); } } /** * 班级排名得分率人数等数据 * @param $paperScore * @param $examStuScore * @return array */ private function getClassAnalyse($paperScore,&$examStuScore,$prePaperScore, &$preExamStuScore, $absentStu, $preAbsent) { $error = array(); $classAnalyArr = array( 'exam_stu_num' => 0,//参加考试人数 'miss_stu_num' => 0,//缺考考人数 'avg_score_rate' => 0,//学生平均得分率 'pre_avg_rate_diff' => 0,//较上次考试平均得分率上升或下降 'avg_scoring' => 0,//学生平均分 'max_scoring' => 0,//最高分 'min_scoring' => 0,//最低分 'full_scoring' => 0,//满分 'pass_rate' => 0,//及格率 'pass_rate_gt_90' => 0,//其中得分率90%以上的有x人 ); $passStuNum = 0;//及格人数 $classAnalyArr['miss_stu_num'] = count($absentStu); //缺考人数 foreach ($examStuScore as $stuId => $stuScoring) { if (!isset($absentStu[$stuId])) { $classAnalyArr['exam_stu_num']++; } if ($stuScoring > $classAnalyArr['max_scoring']) { $classAnalyArr['max_scoring'] = $stuScoring; } if(!isset($absentStu[$stuId])){ if ($classAnalyArr['min_scoring'] == 0) { $classAnalyArr['min_scoring'] = $stuScoring; } if ($stuScoring < $classAnalyArr['min_scoring']) { $classAnalyArr['min_scoring'] = $stuScoring; } } $scoring_rate = ($stuScoring / $paperScore) * 100; if ($scoring_rate >= 60) { $passStuNum++; } if ($scoring_rate > 90) { $classAnalyArr['pass_rate_gt_90']++; } } if (!$classAnalyArr['exam_stu_num']) { $error[] = '班级没有得分大于0的学生!'; } if (!$error) { $classAnalyArr['pass_rate'] = number_format($passStuNum / $classAnalyArr['exam_stu_num'], 4) * 100; $classAnalyArr['full_scoring'] = $paperScore; $classAnalyArr['avg_score_rate'] = number_format(array_sum($examStuScore) / ($classAnalyArr['exam_stu_num'] * $paperScore), 4) * 100; $classAnalyArr['avg_scoring'] = number_format(array_sum($examStuScore) / $classAnalyArr['exam_stu_num'], 1); //上一次班级平均得分率 if ($preExamStuScore) { $preExamStuNum = 0;//上次参加考试人数 foreach ($preExamStuScore as $stuId => $stuScoring) { if (!isset($preAbsent[$stuId])) { $preExamStuNum++; } } //上次平均得分率 if ($preExamStuNum) { $preAvgScoreRate = number_format(array_sum($preExamStuScore) / ($preExamStuNum * $prePaperScore), 4) * 100; }else{ $preAvgScoreRate = 0; } $classAnalyArr['pre_avg_rate_diff'] = $classAnalyArr['avg_score_rate'] - $preAvgScoreRate; } } if ($error) { $this->errorMsg(0, implode(',', $error)); return false; }else{ return $classAnalyArr; } } /** * 考试分析,大幅进步,大幅退步,前5名和后5名 * @param $examStuScore * @param $preExamStuScore * @param $absentStu * @param $preAbsent * @return array */ private function getLargeOrder($examStuScore,$preExamStuScore,$absentStu, $preAbsent){ $largeOrderArr = array( 'font_five' => array(),//班级前五名 'back_five' => array(),//班级后五名 'stu_diff_order' => array(),//名次提升或下降 'stu_order' => array(),//学生名次 'increase_stu' => array(),//大幅进步五名 'reduce_stu' => array(),//大幅退步五名 ); //得分数组(得分>0) $scoringArr = array(); $needStudentArr = array();//得分大于0的学生 foreach ($examStuScore as $stuId => $stuScoring) { if (!isset($absentStu[$stuId])) { $scoringArr[] = $stuScoring; $needStudentArr[$stuId] = $stuId; } } //学生排名 $stuOrderArr = array(); foreach($examStuScore as $stuId => $stuScoring){ if(!isset($absentStu[$stuId])){ $stuOrderArr[$stuId] = $this->getOrder($stuScoring,$scoringArr); } } if($stuOrderArr){ asort($stuOrderArr); } //$diffNum = ceil(count($stuOrderArr)*0.2); $diffNum = 1; //班级前五名 //前5名和后5名 $font5 = $back5 = array(); $i = 1; foreach($stuOrderArr as $stuId => $order){ if($i <= 5){ $font5[$stuId] = $order; }else{ break; } $i++; } $largeOrderArr['font_five'] = $font5; $i = 1; //删除前5排名 // $_stuOrderArr = $stuOrderArr; // foreach($_stuOrderArr as $k => $order){ // if(isset($font5[$k])){ // unset($_stuOrderArr[$k]); // } // } arsort($stuOrderArr); foreach($stuOrderArr as $stuId => $order){ if($i <= 5){ $back5[$stuId] = $order; }else{ break; } $i++; } $largeOrderArr['back_five'] = $back5; /////大幅进步,退步 //上次得分数组(>0) $preScoringArr = array(); foreach ($preExamStuScore as $stuId => $stuScoring) { if (!isset($preAbsent[$stuId])) { $preScoringArr[] = $stuScoring; } } //上次考试学生排名 $preStuOrderArr = array(); foreach($preExamStuScore as $stuId => $stuScoring){ if(isset($preAbsent[$stuId])) continue; $preStuOrderArr[$stuId] = $this->getOrder($stuScoring,$preScoringArr); } if($preStuOrderArr){ asort($preStuOrderArr); } if($preStuOrderArr){ $interOrderArr = array_intersect_key($stuOrderArr,$preStuOrderArr); if(!$interOrderArr){ $interOrderArr = $stuOrderArr; } }else{ $interOrderArr = array(); } $increaseArr = $reduceArr = array(); $stuDiffOrder = array(); if($interOrderArr){ foreach($stuOrderArr as $stuId => $order){ if(isset($interOrderArr[$stuId]) && isset($preStuOrderArr[$stuId])){ $stuDiffOrder[$stuId] = -($order - $preStuOrderArr[$stuId]); }else{ $stuDiffOrder[$stuId] = 0; } } arsort($stuDiffOrder); foreach($stuDiffOrder as $stuId => $num){ if($num >= $diffNum){ $increaseArr[] = $stuId; } } $increaseArr = array_slice($increaseArr,0,5,true); asort($stuDiffOrder); foreach($stuDiffOrder as $stuId => $num){ if($num <= -$diffNum){ $reduceArr[] = $stuId; } } $reduceArr = array_slice($reduceArr,0,5,true); }else{ $increaseArr = array_slice($stuOrderArr,0,5,true); $reduceArr = array(); } $largeOrderArr['stu_diff_order'] = $stuDiffOrder; $largeOrderArr['stu_order'] = $stuOrderArr; $largeOrderArr['increase_stu'] = $increaseArr; $largeOrderArr['reduce_stu'] = $reduceArr; return array($largeOrderArr,$needStudentArr); } /** * 获取排名 * @param $ele * @param $arr * @return false|int|string */ private function getOrder($ele,$arr){ $orderRs = 0; if($arr){ arsort($arr); $arr = array_values($arr); $index = array_search($ele,$arr); $orderRs = $index + 1; } return $orderRs; } /** * 试卷情况分析 * @param $topicNoArr * @param $stuRsArr * @param $needStudentArr * @param $topicScoreArr * @param $changeDoTopicNoArr * @return array */ private function paperAnalyse(&$topicNoArr,&$stuRsArr,$needStudentArr,$topicScoreArr,&$changeDoTopicNoArr) { //$changeTopicStuNum选做题实际做题人数 $changeTopicStuNum = $paperAnalyseArr = array(); $topicWrongNumArr = array();//题答错人数 $hasRsTopicIds = array(); //参与作答的题 foreach ($needStudentArr as $stuId) { if(!(isset($stuRsArr[$stuId])) && $stuRsArr[$stuId]) continue; foreach ($stuRsArr[$stuId] as $topicId => $rs) { if (!isset($topicWrongNumArr[$topicId])) { $topicWrongNumArr[$topicId] = 0; } if ($rs['scoring'] < $topicScoreArr[$topicId]) { $topicWrongNumArr[$topicId]++; } $hasRsTopicIds[$topicId] = $topicId; if(!empty($changeDoTopicNoArr) && isset($changeDoTopicNoArr["list"][$topicId])){//选做题实际做题人数 if (!isset($changeTopicStuNum[$topicId])) { $changeTopicStuNum[$topicId] = 0; } $changeTopicStuNum[$topicId] ++; } } } $stuTotalNum = count($needStudentArr);//学生总人数 foreach ($topicNoArr as $topicId => $no) { if(isset($hasRsTopicIds[$topicId])) { $wrongNum = isset($topicWrongNumArr[$topicId]) ? $topicWrongNumArr[$topicId] : 0; if(!empty($changeDoTopicNoArr) && isset($changeDoTopicNoArr["list"][$topicId]) && isset($changeTopicStuNum[$topicId])){ $countStuTotalNum = $changeTopicStuNum[$topicId];//选做题实际做题人数 }else{ $countStuTotalNum = $stuTotalNum;//正常题目的人数 } $paperAnalyseArr[] = array( 'no' => $no, 'wrong_num' => $wrongNum, 'wrong_rate' => number_format($wrongNum / $countStuTotalNum, 4) * 100, ); }else{ unset($topicNoArr[$topicId]); } } return $paperAnalyseArr; } /** * 获取题内容 * @param $topicNoArr * @param $isMissing 是否允许缺题 1允许0不允许 * @return array|false */ private function getTopicInfoArr($topicNoArr,$isMissing=0) { $error = array(); $topicIds = array_keys($topicNoArr); $topicDetails = array(); $topics = $this->apiBrainPost('/topic/batchAll', array('topicIds' => $topicIds,'subjectId' => $this->subjectId,'params'=>array('isFormat'=>0,'isThird'=>1)),25,true); if(!$topics|| !is_array($topics)){ $this->errorMsg(0, "试题内容获取失败!"); return false; } foreach ($topics as $topic){ $topicDetails[number_format($topic['id'], 0, '', '')] = $topic; } if (!$error) { $diff_id_arr = array(); foreach ($topicNoArr as $topicId => $v) { if (!isset($topicDetails[$topicId])) { $diff_id_arr[] = $topicId; } } if (!empty($diff_id_arr)) { $error[] = "没有试题内容!(" . implode(',', $diff_id_arr) . ")"; } } if ($error && $isMissing==0) { $this->errorMsg(0, implode(',', $error)); return false; }else{ return $topicDetails; } } /** * 题型方法掌握情况 * @param $topicInfoArr * @param $paperCommentsArr * @return array */ public function methodAnalyse(&$topicInfoArr,$paperCommentsArr) { $topicArr = array(); foreach ($paperCommentsArr as $item){ $topicArr[$item['topic_id']] = $item; } //题型方法对应题 list($methodsTopics,$methodOfTopic) = $this->methodTopics($topicInfoArr); //题型方法信息 $topics = array(); if($methodsTopics) { list($methodInfos, $topics) = $this->methodInfos(array_keys($methodsTopics)); } //题型方法得分率 foreach ($methodsTopics as $methodId=>$methodsTopic){ $own = 0; $full = 0; foreach ($methodsTopic as $methodTopicId){ $own += $topicArr[$methodTopicId]['stu_score_total']; $full += $topicArr[$methodTopicId]['topic_score_total']; if(isset($topicArr[$methodTopicId])) { $methodInfos[$methodId]['topicRs'][$methodTopicId] = $topicArr[$methodTopicId]; } } //$methodInfos[$methodId]['rate'] = $full ? number_format($own/$full,4)*100 : 0; $methodInfos[$methodId]['rate'] = $full ? number_format(($own/$full)*100, 2) : 0; $methodInfos[$methodId]['star'] = $this->getStarNum($methodInfos[$methodId]['rate']); $methodInfos[$methodId]['methodId'] = $methodId; } $methodAnalyse = array(); if($methodInfos){ arrayMsort($methodInfos, 'rate'); foreach ($methodInfos as $methodInfo){ $methodAnalyse[$methodInfo['methodId']] = $methodInfo; } } return array($methodAnalyse,$topics,$methodOfTopic); } /** * 试卷讲评 * @param $needStudentArr * @param $stuRsArr * @param $topicScoreArr * @param $topicInfoArr * @param $topicNoArr * @return array */ private function paperComments(&$needStudentArr,&$stuRsArr,$topicScoreArr,&$topicInfoArr,$topicNoArr) { $paperCommentsArr = array(); // $_paperCommentsArr = array( // 'topic_no' => 0,//试题序号 // 'class_scoring_rate' => 0,//班级得分率 // 'grade_scoring_rate' => 0,//年级得分率 // 'wrong_stu_arr' => 0,//答错学生 // 'right_stu_num' => 0,//答对学生数 // 'push_topic_id' => 0,//推送题ID // ); //试题对应的所有学生得分 $topicScoringArr = array();//试题得分 $topicTotalScoreArr = array();//试题总分 $wrongStuArr = array();//答错学生 $rightStuNumArr = array();//答对学生数 foreach ($stuRsArr as $stuId => $stuTopicRs) { foreach ($stuTopicRs as $topicId => $stuRs) { if(!isset($needStudentArr[$stuId])) continue; if (!isset($topicScoringArr[$topicId])) { $topicScoringArr[$topicId] = 0; } $topicScoringArr[$topicId] += $stuRs['scoring']; if (!isset($topicTotalScoreArr[$topicId])) { $topicTotalScoreArr[$topicId] = 0; } $topicTotalScoreArr[$topicId] += isset($topicScoreArr[$topicId]) ? $topicScoreArr[$topicId] : 0; //答错学生 if ($stuRs['scoring'] == $topicScoreArr[$topicId]) { if (!isset($rightStuNumArr[$topicId])) { $rightStuNumArr[$topicId] = 0; } $rightStuNumArr[$topicId]++; }else{ if (!isset($wrongStuArr[$topicId])) { $wrongStuArr[$topicId] = array(); } $wrongStuArr[$topicId][$stuId] = $stuId; } } } //班级得分率 $classScoringRateArr = array(); foreach ($topicScoringArr as $topicId => $scoring) { $classScoringRateArr[$topicId] = $this->numberFormat($scoring / $topicTotalScoreArr[$topicId], 2) * 100; } //年级得分率 //$gradeScoringRateArr = $this->getGradeScoringRate($topicScoreArr); foreach ($topicNoArr as $topicId => $topicNo) { $_wrongStuArr = isset($wrongStuArr[$topicId]) ? $wrongStuArr[$topicId] : array(); $paperCommentsArr[$topicId] = array( 'topic_id' => $topicId, 'topic_no' => $topicNo, 'class_scoring_rate' => isset($classScoringRateArr[$topicId])?$classScoringRateArr[$topicId]:0, //'grade_scoring_rate' => isset($gradeScoringRateArr[$topicId])?$gradeScoringRateArr[$topicId]:0, 'wrong_stu_arr' => array_keys($_wrongStuArr), 'wrong_stu_num' => count($_wrongStuArr), 'right_stu_num' => isset($rightStuNumArr[$topicId])?$rightStuNumArr[$topicId]:0, 'stu_score_total' => isset($topicScoringArr[$topicId]) ? $topicScoringArr[$topicId] : 0, 'topic_score_total' => isset($topicTotalScoreArr[$topicId]) ? $topicTotalScoreArr[$topicId] : 0 ); } return $paperCommentsArr; } /** * 年级得分率 * @param $topicScoreArr 试题分数 * @param $topicScoringArr 试题得分(初始值是班级得分) * @param $topicTotalScoreArr 试题总分分(初始值是班级总分) * @return array */ private function getGradeScoringRate($topicScoreArr) { $gradeScoringRateArr = array(); $examIds = $this->examObj->getExamIds($this->examGroupId); $needStuArr = array();//得分大于0的学生 $paperIds = array(); if($examIds){ //试卷关联学生 $sprInfoArr = $this->sprObj->getStudentExamInfo($examIds); if ($sprInfoArr) { foreach ($sprInfoArr as $sprInfo) { if ($sprInfo['scoring'] > 0) { $needStuArr[$sprInfo['student_id']] = $sprInfo['student_id']; $paperIds[$sprInfo['paper_id']] = $sprInfo['paper_id']; } } } unset($sprInfoArr); } $topicScoringArr = array(); $topicTotalScoreArr = array(); if ($paperIds) { foreach ($paperIds as $paperId) { $_stuRsArr = $this->sptRsObj->getStudentRsOnePaper($paperId); if(!$_stuRsArr){ continue; } foreach ($_stuRsArr as $stuId => $stuTopicRs) { foreach ($stuTopicRs as $topicId => $stuRs) { if(!isset($needStuArr[$stuId])) continue; if (!isset($topicScoringArr[$topicId])) { $topicScoringArr[$topicId] = 0; } $topicScoringArr[$topicId] += $stuRs['scoring']; if (!isset($topicTotalScoreArr[$topicId])) { $topicTotalScoreArr[$topicId] = 0; } $topicTotalScoreArr[$topicId] += isset($topicScoreArr[$topicId]) ? $topicScoreArr[$topicId] : 0; } unset($stuTopicRs); } unset($_stuRsArr); } } //年级得分率 foreach ($topicScoringArr as $topicId => $scoring) { $gradeScoringRateArr[$topicId] = number_format($scoring / $topicTotalScoreArr[$topicId], 2) * 100; } return $gradeScoringRateArr; } /** * hmtl生产PDF * @param $res * @param $html * @param $className * @param $examName * @return boolean|array */ private function htmlToPdf($res,&$html,$className,$examName) { $error = array(); $examId = $this->examId; $htmlpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/academicr/'; //存放生成的HTML路径 $pdfpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/academicr/' . $this->schoolId . "/"; //存放生成的PDF路径 $pdfurl = '/upload/tmpDir/academicr/' . $this->schoolId . "/"; if (!is_dir($htmlpath)) { if (!mkdir($htmlpath, 0777, true)) { $error[] = 'Create directory fail: ' . $htmlpath; } } if (!is_dir($pdfpath)) { if (!mkdir($pdfpath, 0777, true)) { $error[] = 'Create directory fail: ' . $pdfpath; } } if (!$error) { $locale='en_US.UTF-8'; // 或 $locale='zh_CN.UTF-8'; setlocale(LC_ALL,$locale); putenv('LC_ALL='.$locale); $htmlpath .= $examId . '-'. $this->productType . ".html"; $f = fopen($htmlpath, "w"); fwrite($f, $html); fclose($f); $htmlurl = '/upload/tmpDir/academicr/' . $examId. '-'. $this->productType . ".html"; //访问HTML的路径 $server = Yii::app()->params['phantomjs_server']; $js = 'html2pdf_math.js'; $htmlurl = $this->getDomain() . $htmlurl; $pdffname = $this->classId . "-" . $examId . "-". $this->productType .".pdf"; $pdfpath = $pdfpath . $pdffname; $pdfurl = $pdfurl . $pdffname; $schoolInfo = $this->controllerObj->schoolInfo; $schoolName = isset($schoolInfo['school_name'])?$schoolInfo['school_name']:''; $commond = $server . " " . Yii::app()->basePath . '/../js/'.$js . " " . " {$htmlurl}" . " {$pdfpath}" . " 176mm*250mm '{$schoolName} {$className}+++ +++时间:".date('Y-m-d')." 教学宝'"; exec($commond, $res, $code); } if(isset($res) && isset($res[0])){ $isBool = false; foreach($res as $msg){ if (strpos($msg, 'succeed') !== false){ $isBool = true; } } if ($isBool) {//命令返回成功 if (file_exists($pdfpath)) { // $pdfurl=iconv("GBK", "UTF-8",$pdfurl); $repdf = $examId . ".pdf"; $rename = 'zsyas2/academicr/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/'. uniqid() . '.' . $repdf; $ucloud = new HuaweiCloud(); $uploadInfo = $ucloud->putFile($rename, $pdfpath); if ($uploadInfo['status'] == 0) { $pdfurl = $this->getDomain() . $pdfurl; $this->getSchoolDbObj()->createCommand()->update("exam_teaching_product", array("is_create_html"=>1,"html_path"=>$htmlpath,"pdf_path" => $pdfurl, "pdf_create_time" => time(), "is_create_pdf" => 1), "exam_id = '{$examId}' and product_type={$this->productType}"); }else{ $pdfurl = $uploadInfo['url']; $this->getSchoolDbObj()->createCommand()->update("exam_teaching_product", array("is_create_html"=>1,"html_path"=>$htmlpath,"pdf_path" => $pdfurl, "pdf_create_time" => time(), "is_create_pdf" => 1), "exam_id = '{$examId}' and product_type={$this->productType}"); //批量生产不生产PDF if (!is_cli()) { @unlink($pdfpath); } } @unlink($htmlpath); } else { $this->getSchoolDbObj()->createCommand()->update("exam_teaching_product", array("pdf_path" => "", "pdf_create_time" => 0, "is_create_pdf" => 0), "exam_id = '{$examId}' and product_type={$this->productType}"); @unlink($htmlpath); $error[] = 'PDF文件未找到! '; } } else { @unlink($htmlpath); $error[] = 'PDF创建失败!,错误信息:(' . json_encode($res) . ') '; } }else{ Curl::post(Yii::app()->params['handle_log_api'], array( "exam_group_id" => (string)$this->examGroupId, "operate_project" => 'zsyas2', "school_id" => $this->schoolId, "title" => '下载教师讲案', "operate_account" => is_cli()?'':Yii::app()->session['coachInfo']['coach_name'], "operate_method" => $this->controllerObj->action, "operate_url" => $this->controllerObj->getRoute(), "operate_sql" => '', "operate_param" =>json_encode(array('post'=>array("examId"=>$examId,"pdf"=>array("commond"=>$commond,"res"=>$res,"code"=>$code),"htmlurl"=>''))), )); $error[] = 'PDF创建失败! '; } if ($error) { $this->errorMsg(0, implode(',', $error)); return false; }else{ return array($pdfurl,$pdfpath); } } /** * 调题的接口 * @param $path * @param $arr * @param int $type * @return bool|mixed */ public function apiBrainPost($path, $arr, $timeout=25,$is_array = false) { $ch = @curl_init(); $result = FALSE; if ($ch) { $data = json_encode($arr); $url = Yii::app()->params['api'][0]['prefix'] . $path; $username = Yii::app()->params['api'][0]['username']; $password = Yii::app()->params['api'][0]['password']; curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password); // 不输出头部 curl_setopt($ch, CURLOPT_HEADER, 0); // curl_exec 获取到的内容不直接输出, 而是返回 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_TIMEOUT,$timeout); // 请求重启路由器的地址 传参 进行重启 curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, 'Api Client/1.0.0 (chengfei@liancaitech.com)'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: '. strlen($data), )); if( !curl_errno($ch)) { $result = json_decode(curl_exec($ch),$is_array); } // 释放资源 curl_close($ch); } return $result; } public function getDomain() { if (is_cli()) { return Yii::app()->params['zsyas2_url']; }else{ return Yii::app()->request->hostInfo; } } /** * 错误信息 * @param $status * @param $msg */ private function errorMsg($status,$msg) { $this->error[] = $msg; // echo json_encode(array("status" => $status, "error" => $msg)); // exit; } /** * 学校数据库连接对象 * @return mixed */ protected function getSchoolDbObj() { if (is_cli()) { return $this->controllerObj->getSchConnObj(); }else{ return $this->controllerObj->sConn; } } /** * 数组格式化 * @param $num 小数 * @param $bat 小数位数 * @return float|int */ private function numberFormat($num,$bat) { $pow = pow(10, $bat); $num = $num * $pow; $num = floor($num) / $pow; return $num; } /** * 获取题型方法对应题id集 * @param $topicInfos * @return array */ private function methodTopics($topicInfos){ $res = array(); $methodOfTopic = array(); foreach ($topicInfos as $key=>$topicInfo){ if(isset($topicInfo['affiliate'])){ foreach ($topicInfo['affiliate'] as $item){ if($item['field_key'] == 'tag_3_209' && !empty($item['field_value'])){ $methodIds = explode('|', $item['field_value']); foreach ($methodIds as $methodId){ $res[$methodId][] = $key; $methodOfTopic[$key][] = $methodId; } break; } } } } if(empty($res) || empty($methodOfTopic)){ $error[] = '未获取到题方法数据'; } return array($res,$methodOfTopic); } /** * 获取题型方法信息 * @param $methodIds * @return array|boolean */ private function methodInfos($methodIds){ $rs = $this->apiBrainPost('/all_content/detail', array('catalogIds' => $methodIds),25,true); if(isset($rs['status']) && $rs['status']==1){ $methodDetails = $rs['data']; }else{ $error[] = '题型方法数据为空! '; return false; } $methods = array(); $topicIds = array(); foreach ($methodDetails as $detail){ if(isset($detail['column_id'])){ switch ($detail['column_id']){ case self::FULLTEXT_COLUMN_ID: //方法释义文本 $methods[$detail['catalog_id']]['name'] = $detail['catalog_name']; $methods[$detail['catalog_id']]['content'] = \TopicHtml\Topic\Image::resetImgSizeNoTopic($detail['content']); break; case self::CLASSIC_COLUMN_ID: //典型例题文本 $methods[$detail['catalog_id']]['name'] = $detail['catalog_name']; $methods[$detail['catalog_id']]['classic_content'] = \TopicHtml\Topic\Image::resetImgSizeNoTopic($detail['content']); break; case self::SPECIAL_COLUMN_ID: //方法专练 $methods[$detail['catalog_id']]['name'] = $detail['catalog_name']; $methods[$detail['catalog_id']]['classic_topic_ids'][number_format($detail['topic_id'], 0, '', '')] = number_format($detail['topic_id'], 0, '', ''); $topicIds[number_format($detail['topic_id'], 0, '', '')] = number_format($detail['topic_id'], 0, '', ''); break; default: $methods[$detail['catalog_id']]['name'] = $detail['catalog_name']; break; } } } return array($methods,$topicIds); } /** * 获取共性题数据 * topicNoArr题号 * @return array */ private function commonTopic($topicNoArr = array()) { $rs = SProductCommonTopic::model()->getCommonTopic($this->examId); if(empty($rs)){ $error[] = '未生成共性题! '; } $commonTopics = array(); foreach ($rs as $item){ $commonTopics[$item['template_id']]['topic_id'] = $item['template_id']; if(isset($topicNoArr[$item['template_id']])){ $commonTopics[$item['template_id']]['topic_no'] = $topicNoArr[$item['template_id']]; }else{ $commonTopics[$item['template_id']]['topic_no'] = $item['template_no']; } } return $commonTopics; } /** * 客观题答题详细 * @param $paperId * @param $examInfo * @param $paperTopicIds * @param $topicNoArr 题号 * @return array */ private function objectTopicDetail($paperId, $examInfo, $paperTopicIds,$topicNoArr){ $answer_score_details = array(); $query = SPaperTopicRelation::model()->getStudentRs($paperId); if ($query) { //转换试卷中每道题目的序号 foreach ($query as $k => $v) { $no = isset($topicNoArr[$v["topic_id"]])?$topicNoArr[$v["topic_id"]]:$v["order"]; //客观题答案明细 //import_score_type; 1 成绩导入流程 0-正常扫描 if($v['type'] == 1 && !$examInfo['import_score_type']){//单选题 if(!isset($answer_score_details[$v['topic_id']])){ $answer_score_details[$v['topic_id']] = array(); $answer_score_details[$v['topic_id']]['answer'] = ''; $answer_score_details[$v['topic_id']]['option']['A'] = 0; $answer_score_details[$v['topic_id']]['option']['B'] = 0; $answer_score_details[$v['topic_id']]['option']['C'] = 0; $answer_score_details[$v['topic_id']]['option']['D'] = 0; $answer_score_details[$v['topic_id']]['order'] = $no; } if(isset($answer_score_details[$v['topic_id']]['option'][$v['answer']])){ $answer_score_details[$v['topic_id']]['option'][$v['answer']]++; } } if((in_array($v['type'],array(2,11)) && !$examInfo['import_score_type']) || ($examInfo['qxk_paper_id'] && $v['type']==3)){//多选不定项 $v_answer = str_replace(',','',$v['answer']); if(!isset($answer_score_details[$v['topic_id']])){ $answer_score_details[$v['topic_id']] = array(); $answer_score_details[$v['topic_id']]['answer'] = ''; $answer_score_details[$v['topic_id']]['order'] = $no; } if(isset($answer_score_details[$v['topic_id']]['option'][$v_answer])){ $answer_score_details[$v['topic_id']]['option'][$v_answer]++; }else{ $answer_score_details[$v['topic_id']]['option'][$v_answer] = 1; } } } } $topicDetails=array(); $topicItems_1 = $this->apiBrainPost('/topic/batchAll', array('topicIds' =>$paperTopicIds)); if (isset($topicItems_1->error)) { $error[] = $topicItems_1->error; } elseif (! $topicItems_1) { $error[] = 'Error in pumping system[2]'; } else { foreach ($topicItems_1 as $topicItem) { $topicDetails[$topicItem->id] = (object)$topicItem; } } if ($topicDetails) { foreach ($topicDetails as $k => $v) { $v=(array)$v; $v['id'] = (string)$v['id']; if(isset($v['items'][0])){ $v['items'][0]=(array)$v['items'][0]; $v['items'][0]['options']=(array)$v['items'][0]['options']; if (isset($v['items']) && isset($v['items'][0]) && isset($v['items'][0]['options'])) { foreach ($v['items'][0]['options'] as $key => $val) { $val=(array)$val; if(isset($answer_score_details[$v['id']]) && $val['option_correct'] == 1){ $answer_score_details[$v['id']]['answer'] .= $this->numToLetter($key + 1); } } } } } } $new_answer_score_details = array(); //整理客观题明细数据 if($answer_score_details){ $a = 0; foreach($answer_score_details as $k=>$v){ if(isset($v['option']) && $v['option']){ foreach($v['option'] as $option_type=>$option_count){ $new_answer_score_details[$a]['id'] = $k; $new_answer_score_details[$a]['order'] = $v['order']; $new_answer_score_details[$a]['answer'] = $v['answer']?$v['answer']:''; $new_answer_score_details[$a]['option'] = $option_type; $new_answer_score_details[$a]['option_count'] = $option_count; $a++; } } } } return $new_answer_score_details; } public function numToLetter($number) { $letters = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'); $number = (int) $number; $result = ''; if ($number >= 1 AND $number <= 26) { $result = $letters[$number - 1]; } return $result; } /** 获取方法得分率星级 * @param $rate * @return int */ private function getStarNum($rate) { if ($rate >= 80 && $rate <= 100) { $starNum = 5; }elseif($rate >= 60 && $rate < 80){ $starNum = 4; }elseif($rate >= 40 && $rate < 60){ $starNum = 3; }elseif($rate >= 20 && $rate < 40){ $starNum = 2; }else{ $starNum = 1; } return $starNum; } //多维数组降序排序 static function arrayM_desc_sort(&$data,$field) { $regions = _array_column($data, $field); utf8_array_asort($regions); array_multisort($regions, SORT_DESC, $data); } /** * 同学优解 * @param $examInfo * @param $paperId * @param $groupId * @param $isQxk是否全学科试卷 * @return array * @throws CDbException * @throws CException */ public function bestAnswer($examInfo, $paperId, $groupId,$isQxk=0){ if($isQxk){ $typeArr =array(8,9); }else{ $typeArr =array(7,17,27); } //获取考试试题对应优解分数 $topic_sql = "select topic_id,score from paper_topic_relation where paper_id = '{$paperId}' and type in (".join(",",$typeArr).")"; $topic_sql_rs = $this->getSchoolDbObj()->createCommand($topic_sql)->queryAll(); $fine_topic_score = array(); foreach ($topic_sql_rs as $item){ $fine_topic_score[$item['topic_id']] = 0.7*$item['score']; } $static_url_data = Yii::app()->params['static_url'][$groupId]; //获取同学优解(优先取marking_special_answer 没有再取student_paper_topic_rs) $excellent_solution = array(); $sql = "select paper_id,student_id,sptr_id,topic_id,clazz_id from marking_special_answer where paper_id = '{$paperId}' and type = 2"; $special_data = $this->getSchoolDbObj()->createCommand($sql)->queryAll(); if($special_data){ foreach($special_data as $k=>$v){ if(!isset($excellent_solution[(string)$v['topic_id']])){ $temp_class_id = $v["clazz_id"]; $temp_student_id = $v["student_id"]; $temp_sptr_id = $v["sptr_id"]; //获取班级名称 $sql = "select class_name from class where class_id = '{$temp_class_id}'"; $class_data = $this->getSchoolDbObj()->createCommand($sql)->queryRow(); if($class_data){ $excellent_solution[(string)$v['topic_id']]['class_name'] = $class_data['class_name']; } //获取学生姓名 $sql = "select realname from student_info where student_id = '{$temp_student_id}'"; $student_data = $this->getSchoolDbObj()->createCommand($sql)->queryRow(); if($student_data){ $excellent_solution[(string)$v['topic_id']]['student_name'] = $student_data['realname']; } //获取学生答案 $sql = "select answer_url from student_paper_topic_rs where id = '{$temp_sptr_id}'"; // if(empty($codeNow)){ // $sql = "select answer_url from student_paper_topic_rs where id = '{$temp_sptr_id}'"; // }else{ // $sql = "select answer_url from student_paper_topic_rs_".$codeNow." where id = '{$temp_sptr_id}'"; // } $sptr_data = $this->getSchoolDbObj()->createCommand($sql)->queryRow(); if($sptr_data){ if(strpos($sptr_data['answer_url'],'http') !== false){ $answer_url = $sptr_data['answer_url']; }else{ $answer_url = $static_url_data.$sptr_data['answer_url']; } $excellent_solution[(string)$v['topic_id']]['answer_url'] = $answer_url; } } } //解答题没有全部标记的情况 $sql = "select topic_id,student_id,scoring,type,answer_url from student_paper_topic_rs where paper_id = '{$paperId}' and type in (".join(",",$typeArr).") order by type asc,topic_id asc,scoring desc"; // if(empty($codeNow)){ // $sql = "select topic_id,student_id,scoring,type,answer_url from student_paper_topic_rs where paper_id = '{$paperId}' and type in (7,17,27) order by type asc,topic_id asc,scoring desc"; // }else{ // $sql = "select topic_id,student_id,scoring,type,answer_url from student_paper_topic_rs_".$codeNow." where paper_id = '{$paperId}' and type in (7,17,27) order by type asc,topic_id asc,scoring desc"; // } $excellent_data = $this->getSchoolDbObj()->createCommand($sql)->queryAll(); if($excellent_data){ foreach($excellent_data as $k=>$v){ if(!isset($excellent_solution[(string)$v['topic_id']])){ if($v['answer_url'] && $v['scoring']>$fine_topic_score[$v['topic_id']]){ $temp_student_id = $v["student_id"]; $excellent_solution[(string)$v['topic_id']]['student_id'] = $v['student_id']; if(strpos($v['answer_url'],'http') !== false){ $answer_url = $v['answer_url']; }else{ $answer_url = $static_url_data.$v['answer_url']; } $excellent_solution[(string)$v['topic_id']]['answer_url'] = $answer_url; //获取学生姓名 $sql = "select realname from student_info where student_id = '{$temp_student_id}'"; $student_data = $this->getSchoolDbObj()->createCommand($sql)->queryRow(); if($student_data){ $excellent_solution[(string)$v['topic_id']]['student_name'] = $student_data['realname']; } $excellent_solution[(string)$v['topic_id']]['class_name'] = $examInfo['class_name']; } } } } }else{ //没有标的话取student_paper_topic_rs $sql = "select topic_id,student_id,scoring,type,answer_url from student_paper_topic_rs where paper_id = '{$paperId}' and type in (".join(",",$typeArr).") order by type asc,topic_id asc,scoring desc"; // if(empty($codeNow)){ // $sql = "select topic_id,student_id,scoring,type,answer_url from student_paper_topic_rs where paper_id = '{$paperId}' and type in (7,17,27) order by type asc,topic_id asc,scoring desc"; // }else{ // $sql = "select topic_id,student_id,scoring,type,answer_url from student_paper_topic_rs_".$codeNow." where paper_id = '{$paperId}' and type in (7,17,27) order by type asc,topic_id asc,scoring desc"; // } $excellent_data = $this->getSchoolDbObj()->createCommand($sql)->queryAll(); if($excellent_data){ foreach($excellent_data as $k=>$v){ if(!isset($excellent_solution[(string)$v['topic_id']])){ if($v['answer_url'] && $v['scoring']>$fine_topic_score[$v['topic_id']]){ $temp_student_id = $v["student_id"]; $excellent_solution[(string)$v['topic_id']]['student_id'] = $v['student_id']; if(strpos($v['answer_url'],'http') !== false){ $answer_url = $v['answer_url']; }else{ $answer_url = $static_url_data.$v['answer_url']; } $excellent_solution[(string)$v['topic_id']]['answer_url'] = $answer_url; //获取学生姓名 $sql = "select realname from student_info where student_id = '{$temp_student_id}'"; $student_data = $this->getSchoolDbObj()->createCommand($sql)->queryRow(); if($student_data){ $excellent_solution[(string)$v['topic_id']]['student_name'] = $student_data['realname']; } $excellent_solution[(string)$v['topic_id']]['class_name'] = $examInfo['class_name']; } } } } } return $excellent_solution; } /** * 获取选做题题号 * @param $info 题号 * @param $tpl_data_arr exam tpl_data数组 */ private function getChangeDoToicNoArr(&$info,$tplDataArr) { $topicNoArr = array(); foreach ($info as $item) { $topicNoArr[$item['topic_id']] = $item['order']; } asort($topicNoArr); $topicIdsArr = array_keys($topicNoArr); $changeDoToicNo = array( "list" => array(),//详情 "gather"=> array(),//汇总 ); //选做题题号 if (isset($tplDataArr['new_items']) && $tplDataArr['new_items']) { foreach (array_values($tplDataArr['new_items']) as $key => $item) { if (isset($topicIdsArr[$key]) && isset($item['sameAliasNo']) && $item['sameAliasNo']>0) { $topic_id = $topicIdsArr[$key]; $no =$item['alias']; $changeDoToicNo["list"][$topic_id]["sameAliasNo"] = $item['sameAliasNo'];//选做题组id $changeDoToicNo["list"][$topic_id]["smTopicLen"] = $item['smTopicLen'];//选做题组必做数量 $changeDoToicNo["list"][$topic_id]["no"] = $no;//选做题组必做数量 $changeDoToicNo["gather"][$item['sameAliasNo']][] = $topic_id; } } } asort($changeDoToicNo); return $changeDoToicNo; } }