1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234 |
- <?php
- class TeachingJunior
- {
- private $subjectId;
- private $schoolId = 0;
- private $examId = 0;
- private $classId = 0;
- private $examGroupId = 0;
- private $error = array();
- private $controllerObj = null;//controller对象
- private $examObj = null;
- private $sprObj = null;
- private $sptRsObj = null;
- //TODO 全学科题库 题型方法对应栏目id
- const FULLTEXT_COLUMN_ID = 163; //方法解读富文本
- const CLASSIC_COLUMN_ID = 224; //典型例题
- const SPECIAL_COLUMN_ID = 225; //方法专练
- const DIFFICULT_COLUMN_ID = 227; //难度
- //题型方法难度
- static $difficult = array(
- 719 => '简单',
- 720 => '中等',
- 721 => '难'
- );
- public function __construct(&$controllerObj)
- {
- $this->controllerObj = $controllerObj;
- }
- /**
- * 生成PDF返回PDF地址
- * @param $schoolId
- * @param $examId
- * @param int $force
- * @param int $viewHtml
- * @param int $isWb
- * @return array
- */
- public function getTeachingPdf($schoolId,$examId,$force = 0,$viewHtml = 0, $isWb = 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->examObj = new Exam();
- $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['academicr_pdf_path'];
- $res = array();//生成pdf命令结果
- // if(strpos($examInfo['academicr_pdf_path'],'http') !== false){
- // if(!file_get_contents($examInfo['academicr_pdf_path'])){
- // $force = 1;
- // }
- // }else{
- // $force = 1;
- // }
- //
- // if ($examInfo['academicr_pdf_path'] && !$force) {
- // //文件已生成不再生成
- // $result = array(
- // 'status' => 0,
- // 'error' => '',
- // 'is_create' => 1,
- // 'pdf_url' => $pdfurl,
- // 'pdf_path' => '',
- // );
- //
- // 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) = $actionRs;
- }
- //上次考试需要的数据
- if (!$this->error) {
- $actionRs = $this->preExamNeedData($examInfo,$this->sprObj,$paperObj);
- if ($actionRs) {
- list($prePaperScore, $preExamStuScore) = $actionRs;
- }
- }
- //班级排名得分率人数等数据
- if (!$this->error) {
- $classAnalyseArr = $this->getClassAnalyse($paperScore,$examStuScore,$prePaperScore, $preExamStuScore);
- }
- //大幅进步,大幅退步,前5名和后5名($needStudentArr:得分大于0的学生)
- if (!$this->error) {
- list($largeOrderArr,$needStudentArr) = $this->getLargeOrder($examStuScore,$preExamStuScore);
- }
- unset($preExamStuScore);
- /**************************** 二、考试情况分析 ***********************************/
- 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);
- 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);
- }
- /**************************** 三、知识点掌握情况 ***********************************/
- //TODO 题型方法考察情况
- if (!$this->error) {
- $topicInfoArr = $this->getTopicInfoArr($topicNoArr);
- }
- // if (!$this->error) {
- // $kpsAnalyseArr = $this->kpsAnalyse($topicInfoArr,$topicScoreArr,$topicNoArr,$stuRsArr,$needStudentArr);
- // }
- /**************************** 四、试卷讲评 ***********************************/
- if (!$this->error) {
- $paperCommentsArr = $this->paperComments($needStudentArr,$stuRsArr,$topicScoreArr,$topicInfoArr,$topicNoArr);
- }
- if(!$this->error){
- list($methodAnalyseArr,$methodTopics) = $this->methodAnalyse($topicInfoArr,$paperCommentsArr);
- }
- /**************************** 五、共性题 ***********************************/
- if(!$this->error){
- list($commonMethods,$commonTopicIds) = $this->commonTopic($methodAnalyseArr);
- $commonTopics = $commonTopicIds + $methodTopics;
- $commonTopics = $this->getTopicInfoArr($commonTopics);
- }
- /**************************** 生产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['commonMethods'] = $commonMethods;
- $data['zsyas2Url'] = $this->getDomain();
- $data['isWb'] = $isWb;
- $html = $this->controllerObj->renderPartial("/junior/teach", $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[] = '文件尚未生成!!,错题信息:'.(isset($res)?json_encode($res):'');
- }
- $result = array(
- 'status' => 1,
- 'error' => '',
- 'is_create' => 0,
- 'pdf_url' => '',
- 'pdf_path' => '',
- );
- 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 $info 试卷题数据
- * @param $tpl_data_arr exam tpl_data数组
- */
- private function getTopicNoArr(&$info,$tplDataArr)
- {
- $topicNoArr = array();
- foreach ($info as $item) {
- $topicNoArr[$item['topic_id']] = $item['order'];
- }
- asort($topicNoArr);
- $topicIdsArr = array_keys($topicNoArr);
- //选做题题号
- if (isset($tplDataArr['new_items']) && $tplDataArr['new_items']) {
- foreach (array_values($tplDataArr['new_items']) as $key => $item) {
- if (isset($topicIdsArr[$key])) {
- $topic_id = $topicIdsArr[$key];
- $no = preg_replace('/[A-Za-z]+/','' ,$item['alias']);
- $topicNoArr[$topic_id] = $no;
- }
- }
- }
- return $topicNoArr;
- }
- /**
- * 判断PDF是否存在
- * @param $pdf_path
- * @return bool
- */
- private function check_pdf($pdf_path) {
- if (substr($pdf_path, strlen($pdf_path) - 4, 4) == ".pdf") {
- if (file_exists($pdf_path)) {
- return true;
- }
- }
- return false;
- }
- /**
- * 当前考试需要的数据
- * @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();//考试关联学生得分
- $paperId = 0;
- foreach($sprInfoArr as $key => $value){
- $studentId = $value['student_id'];
- $paperId = $value['paper_id'];
- $examStuScore[$studentId] = $value['scoring'];
- 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);
- }
- }
- /**
- * 上次考试需要的数据
- * @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']);
- $preExamId = isset($preInfo['exam_id'])?$preInfo['exam_id']:'';
- $prePaperScore = 0;
- $examRelPaper = array();
- $preExamStuScore = array();//考试关联学生得分
- if($preExamId){
- $sprInfoArr = $sprObj->getStudentExamInfo(array($preExamId));
- if(!$sprInfoArr){
- $error[] = '考试没有关联学生数据!';
- }
- if (!$error) {
- foreach($sprInfoArr as $key => $value){
- $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);
- }
- }
- /**
- * 班级排名得分率人数等数据
- * @param $paperScore
- * @param $examStuScore
- * @return array
- */
- private function getClassAnalyse($paperScore,&$examStuScore,$prePaperScore, &$preExamStuScore)
- {
- $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;//及格人数
- foreach ($examStuScore as $stuId => $stuScoring) {
- if ($stuScoring > 0) {
- $classAnalyArr['exam_stu_num']++;
- }else{
- $classAnalyArr['miss_stu_num']++;
- continue;
- }
- if ($stuScoring > $classAnalyArr['max_scoring']) {
- $classAnalyArr['max_scoring'] = $stuScoring;
- }
- 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'] = $this->numberFormat($passStuNum / $classAnalyArr['exam_stu_num'], 4) * 100;
- $classAnalyArr['full_scoring'] = $paperScore;
- $classAnalyArr['avg_score_rate'] = $this->numberFormat(array_sum($examStuScore) / ($classAnalyArr['exam_stu_num'] * $paperScore), 4) * 100;
- $classAnalyArr['avg_scoring'] = $this->numberFormat(array_sum($examStuScore) / $classAnalyArr['exam_stu_num'], 1);
- //上一次班级平均得分率
- if ($preExamStuScore) {
- $preExamStuNum = 0;//上次参加考试人数
- foreach ($preExamStuScore as $stuId => $stuScoring) {
- if ($stuScoring > 0) {
- $preExamStuNum++;
- }
- }
- //上次平均得分率
- if ($preExamStuNum) {
- $preAvgScoreRate = $this->numberFormat(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
- * @return array
- */
- private function getLargeOrder($examStuScore,$preExamStuScore){
- $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 ($stuScoring > 0) {
- $scoringArr[] = $stuScoring;
- $needStudentArr[$stuId] = $stuId;
- }
- }
- //学生排名
- $stuOrderArr = array();
- foreach($examStuScore as $stuId => $stuScoring){
- if($stuScoring > 0){
- $stuOrderArr[$stuId] = $this->getOrder($stuScoring,$scoringArr);
- }
- }
- if($stuOrderArr){
- asort($stuOrderArr);
- }
- $diffNum = ceil(count($stuOrderArr)*0.2);
- //班级前五名
- //前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 ($stuScoring > 0) {
- $preScoringArr[] = $stuScoring;
- }
- }
- //上次考试学生排名
- $preStuOrderArr = array();
- foreach($preExamStuScore as $stuId => $stuScoring){
- if(!$stuScoring) 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
- * @return array
- */
- private function paperAnalyse($topicNoArr,&$stuRsArr,$needStudentArr,$topicScoreArr)
- {
- $paperAnalyseArr = array();
- $topicWrongNumArr = 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]++;
- }
- }
- }
- $stuTotalNum = count($needStudentArr);//学生总人数
- foreach ($topicNoArr as $topicId => $no) {
- $wrongNum = isset($topicWrongNumArr[$topicId]) ? $topicWrongNumArr[$topicId] : 0;
- $paperAnalyseArr[] = array(
- 'no' => $no,
- 'wrong_num' => $wrongNum,
- 'wrong_rate' => $this->numberFormat($wrongNum / $stuTotalNum, 4) * 100,
- );
- }
- return $paperAnalyseArr;
- }
- /**
- * 获取题内容
- * @param $topicNoArr
- * @return array|false
- */
- private function getTopicInfoArr($topicNoArr)
- {
- $error = array();
- $topicIds = array_keys($topicNoArr);
- $topicDetails = $this->apiBrainPost('/topic/batchAll', array('topicIds' => $topicIds,'subjectId' => $this->subjectId,'params'=>array('isFormat'=>1,'isThird'=>1)),25,true);
- 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) {
- $this->errorMsg(0, implode(',', $error));
- return false;
- }else{
- return $topicDetails;
- }
- }
- /**
- * 题型方法掌握情况
- * @param $topicInfoArr
- * @param $paperCommentsArr
- * @return array
- */
- public function methodAnalyse(&$topicInfoArr,$paperCommentsArr)
- {
- $topicArr = $methodInfos=$topics=array();
- foreach ($paperCommentsArr as $item){
- $topicArr[$item['topic_id']] = $item;
- }
- //题型方法对应题
- $methodsTopics = $this->methodTopics($topicInfoArr);
- //判断题型方法是否为空
- if(!$methodsTopics){
- return array($methodInfos,$topics);
- }
- //题型方法信息
- list($methodInfos,$topics) = $this->methodInfos(array_keys($methodsTopics));
- //题型方法得分率
- foreach ($methodsTopics as $methodId=>$methodsTopic){
- $own = 0;
- $full = 0;
- foreach ($methodsTopic as $methodTopicId){
- $own += $topicArr[$methodTopicId]['class_scoring_rate'];
- $full += 100;
- if(isset($topicArr[$methodTopicId])) {
- $methodInfos[$methodId]['topicRs'][$methodTopicId] = $topicArr[$methodTopicId];
- }
- }
- $methodInfos[$methodId]['rate'] = $full ? number_format($own/$full,2)*100 : 0;
- }
- return array($methodInfos,$topics);
- }
- /**
- * 试卷讲评
- * @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[] = 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,
- );
- }
- 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] = $this->numberFormat($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 . ".html";
- $f = fopen($htmlpath, "w");
- fwrite($f, $html);
- fclose($f);
- $htmlurl = '/upload/tmpDir/academicr/' . $examId . ".html"; //访问HTML的路径
- $server = Yii::app()->params['phantomjs_server'];
- $js = 'html2pdf.js';
- $htmlurl = $this->getDomain() . $htmlurl;
- $pdffname = $this->classId . "-" . $examId . ".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}"
- . " A4 '{$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", array("academicr_pdf_path" => $pdfurl, "academicr_pdf_time" => time(), "is_academicr_pdf" => 1), "exam_id = '{$examId}'");
- }else{
- $pdfurl = $uploadInfo['url'];
- $this->getSchoolDbObj()->createCommand()->update("exam", array("academicr_pdf_path" => $pdfurl, "academicr_pdf_time" => time(), "is_academicr_pdf" => 1), "exam_id = '{$examId}'");
- //批量生产不生产PDF
- if (!is_cli()) {
- @unlink($pdfpath);
- }
- }
- @unlink($htmlpath);
- } else {
- $this->getSchoolDbObj()->createCommand()->update("exam", array("academicr_pdf_path" => "", "academicr_pdf_time" => 0, "is_academicr_pdf" => 0), "exam_id = '{$examId}'");
- @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();
- foreach ($topicInfos as $key=>$topicInfo){
- if(isset($topicInfo['affiliate'])){
- foreach ($topicInfo['affiliate'] as $item){
- if($item['field_key'] == 'tag_41_175' && !empty($item['field_value'])){
- $methodIds = explode('|', $item['field_value']);
- foreach ($methodIds as $methodId){
- $res[$methodId][] = $key;
- }
- break;
- }
- }
- }
- }
- if(empty($res)){
- $error[] = '未获取到题型方法数据';
- }
- return $res;
- }
- /**
- * 获取题型方法信息
- * @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();
- $difficult = static::$difficult;
- 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'] = $detail['content'];
- break;
- case self::CLASSIC_COLUMN_ID:
- $methods[$detail['catalog_id']]['name'] = $detail['catalog_name'];
- $methods[$detail['catalog_id']]['classic_topic_ids'][] = number_format($detail['topic_id'], 0, '', '');
- $topicIds[number_format($detail['topic_id'], 0, '', '')] = number_format($detail['topic_id'], 0, '', '');
- break;
- case self::DIFFICULT_COLUMN_ID:
- $methods[$detail['catalog_id']]['name'] = $detail['catalog_name'];
- $methods[$detail['catalog_id']]['difficult'] = isset($difficult[$detail['column_detail_id']]) ? $difficult[$detail['column_detail_id']] : '简单';
- break;
- default:
- $methods[$detail['catalog_id']]['name'] = $detail['catalog_name'];
- break;
- }
- }
- }
- return array($methods,$topicIds);
- }
- /**
- * 获取共性题数据
- * @return array
- */
- private function commonTopic()
- {
- $model = new SJuniorMathCommonTopic();
- $rs = $model->getCommonTopic($this->examId,$this->classId);
- if(empty($rs)){
- $error[] = '未生成共性题! ';
- }
- $common = array();
- $topicIds = array();
- if($rs) {
- foreach ($rs as $item) {
- $topicIds[$item['topic_id']] = $item['topic_id'];
- $common[(string)$item['tymhd_id']][] = $item['topic_id'];
- }
- }
- return array($common,$topicIds);
- }
- }
|