ThirdAcademicrBatchCommand.php 184 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819
  1. <?php
  2. class ThirdAcademicrBatchCommand extends CConsoleCommand {
  3. public $conn;
  4. public $sConn;
  5. public function init() {
  6. parent::init();
  7. @ini_set('memory_limit', '1024M');
  8. set_time_limit(0);
  9. }
  10. public $authUsername = '';
  11. public $subjectId;
  12. private $typeName=array('1'=>'选择题','11'=>'不定项选择题','5'=>'填空题','7'=>'解答题','17'=>'选做解答题');
  13. private $logicTypeName;
  14. private $imgArr = array();
  15. private $isThird = 0;
  16. public function actionIndex($YII_ENV='development'){
  17. // echo YII_ENV;exit;
  18. if(YII_ENV == "production"){
  19. $file_html_url = "http://zsyas2.zhixinhuixue.com";
  20. }else{
  21. if(YII_ENV == 'development'){
  22. $file_html_url = "http://xbas2.dev.xiaoben.com";
  23. }else{
  24. $file_html_url = "http://xbas2.testing.xiaoben.com";
  25. }
  26. }
  27. //连接业务库
  28. $conn = $this->getDbConnection(Yii::app()->params["default_server"]['addr'], Yii::app()->params["default_db"]['name'], Yii::app()->params["default_server"]['username'], Yii::app()->params["default_server"]['password']);
  29. if($conn){
  30. $this->conn = $conn;
  31. $time = time();
  32. //获取要生成教师讲案的数据
  33. $sql = "select id,school_id,exam_group_id,class_ids,subject_id,is_labelled from download_table_setting where download_type = 3 and status = 1 and error_msg = '' and subject_id not in (3,6,51) and is_labelled=0 order by create_time asc limit 1";
  34. $result_all = $this->conn->createCommand($sql)->queryAll();
  35. //超过20分钟默认生成失败
  36. $sql = "update download_table_setting set status = 3,error_msg ='系统错误,建议单个生成' where status = 4 and error_msg = '' and update_time <".($time-1200);
  37. $this->conn->createCommand($sql)->execute();
  38. if($result_all){
  39. foreach($result_all as $v_data_k=>$v_data){
  40. if($v_data_k > 0){
  41. break;
  42. }
  43. $sql = "update download_table_setting set update_time = {$time},status=4 where id ={$v_data['id']}";
  44. $this->conn->createCommand($sql)->execute();
  45. $error = array();
  46. $pdfArr = array();
  47. $is_success = 0;
  48. $force=1;
  49. try{
  50. if($v_data['class_ids'] && $v_data['school_id'] && $v_data['exam_group_id']){
  51. //连接学校库
  52. $sql = "select database_host,database_user,database_password,database_name,group_id from `database` where school_id = '{$v_data['school_id']}'";
  53. $conn = $this->getDbConnection(Yii::app()->params["default_server"]['addr'], Yii::app()->params["default_db"]['name'], Yii::app()->params["default_server"]['username'], Yii::app()->params["default_server"]['password']);
  54. if($conn){
  55. $this->conn = $conn;
  56. }else{
  57. echo "连接业务库失败\n";
  58. $error[] = "连接业务库失败";
  59. continue;
  60. }
  61. $result_one = $this->conn->createCommand($sql)->queryRow();
  62. if($result_one){
  63. $school_group_id = $result_one["group_id"];
  64. if (!is_numeric($school_group_id)){
  65. $school_group_id = 0;
  66. }
  67. $sConn = $this->getDbConnection($result_one["database_host"],$result_one["database_name"], $result_one["database_user"],$result_one["database_password"]);
  68. if($sConn){
  69. $this->sConn = $sConn;
  70. echo '连接学校ID'.$v_data['school_id']."成功\n";
  71. $null_data = 1;
  72. $pdfNames = array();
  73. echo '开始获取任务ID'.$v_data['id']."的数据\n";
  74. $classIds = explode(",", $v_data["class_ids"]);
  75. if($classIds){
  76. foreach($classIds as $classId) {
  77. $this->sConn->active = false;
  78. $sConn = $this->getDbConnection($result_one["database_host"], $result_one["database_name"], $result_one["database_user"], $result_one["database_password"]);
  79. $this->sConn = $sConn;
  80. echo "开始获取classId=" . $classId . "的数据\n";
  81. $sql = "select class_name from class where class_id = '{$classId}'";
  82. $data_one = $this->sConn->createCommand($sql)->queryRow();
  83. if($data_one){
  84. $className = $data_one['class_name'];
  85. }else{
  86. $className = "";
  87. }
  88. $sql = "select exam_id,name from exam where exam_group_id = '{$v_data["exam_group_id"]}' and class_id = '{$classId}'";
  89. $data_one = $this->sConn->createCommand($sql)->queryRow();
  90. $examId=$data_one['exam_id'];
  91. $examName = $data_one["name"];
  92. $sql = "select e.exam_group_id,e.class_id,e.subject_id,eg.is_third,e.name as exam_name,e.academicr_pdf_path,e.academicr_pdf_time,p.paper_id,e.is_academicr_pdf,c.class_name,e.tpl_index,e.tpl_data,e.is_fine_paper,academicr_common_practice,eg.qxk_paper_id from exam as e left join class as c on c.class_id=e.class_id left join exam_group as eg on e.exam_group_id=eg.exam_group_id left join paper as p on p.exam_id=e.exam_id where e.exam_id = {$examId}";
  93. $examInfo=$this->sConn->createCommand($sql)->queryRow();
  94. if($examInfo['subject_id']){
  95. $this->subjectId = $examInfo['subject_id'];
  96. }
  97. $subjectId = $this->subjectId;
  98. $this->logicTypeName = getSubjectTopicType($subjectId);
  99. $pdfpath = str_replace("protected", "", Yii::app()->basePath) . $examInfo['academicr_pdf_path'];
  100. $pdfurl = $examInfo['academicr_pdf_path'];
  101. $res = array();//生成pdf命令结果
  102. if(strpos($examInfo['academicr_pdf_path'],'http') !== false){
  103. if(!file_get_contents($examInfo['academicr_pdf_path'])){
  104. $force = 1;
  105. }
  106. }else{
  107. $force = 1;
  108. }
  109. $getTopicTypeRelate = $this->getTopicTypeRelate();
  110. $batch_subject_id = $subjectId;
  111. if($batch_subject_id == 8 && $examInfo['qxk_paper_id']){
  112. $batch_subject_id = 0;
  113. }
  114. if (!$examInfo['academicr_pdf_path'] || $examInfo['is_academicr_pdf'] == 0 || $force) {
  115. $examGroupId = $examInfo['exam_group_id'];
  116. $arr=$this->sConn->createCommand("select topic_upload,answer_upload,template_type from third_multi_template where exam_group_id='{$examGroupId}'")->queryAll();
  117. // if($subjectId == 8 && $examInfo['is_third'] == 1){
  118. if($subjectId == 8 && $examInfo['is_third'] == 1 && !$examInfo['qxk_paper_id']){
  119. $isUpload = 0;
  120. if($arr){
  121. foreach ($arr as $k => $v){
  122. $arr[$v['template_type']]=$v;
  123. }
  124. foreach ($arr as $k => $v){
  125. if($k == 1 && $v['topic_upload'] == 1){
  126. $isUpload++;
  127. }elseif($k == 2 && $v['answer_upload'] == 1){
  128. $isUpload++;
  129. }
  130. }
  131. }
  132. //精品试卷不用上传试题和答案,第三方需要
  133. if($examInfo['is_fine_paper'] <= 0 && $isUpload != 2){
  134. echo "试卷试题或答案没上传!\n";
  135. $error[] = $className."试卷试题或答案没上传!";
  136. continue;
  137. }
  138. }elseif($subjectId == 12 && $examInfo['is_third'] == 1){
  139. $isUpload = 0;
  140. if($arr){
  141. foreach ($arr as $k => $v){
  142. $arr[$v['template_type']]=$v;
  143. }
  144. foreach ($arr as $k => $v){
  145. if($k == 1 && $v['topic_upload'] == 1){
  146. $isUpload++;
  147. }elseif($k == 2 && $v['answer_upload'] == 1){
  148. $isUpload++;
  149. }
  150. }
  151. }
  152. if($isUpload != 2){
  153. echo "试卷试题或答案没上传!\n";
  154. continue;
  155. }
  156. }
  157. $sql = "select exam_id from exam where exam_group_id = {$examGroupId}";
  158. $examIds = $this->sConn->createCommand($sql)->queryColumn();
  159. $isThird = $this->getExamIsTird($examGroupId,$examId);
  160. $this->isThird = $isThird;
  161. //去除没有上传成绩的学生
  162. $ptrInfo = $stuIdsArr = array();
  163. if($examIds){
  164. $stuIdsArr = $this->getHasScoreStu($examIds);
  165. $ptrInfo = $this->getStudentExamInfo($examIds);
  166. }
  167. if(!$ptrInfo){
  168. echo "考试没有数据!\n";
  169. $error[] = $className."考试没有数据!";
  170. continue;
  171. }
  172. $paperIds = array();
  173. foreach($ptrInfo as $value){
  174. $paperIds[$value['exam_id']] = $value['paper_id'];
  175. }
  176. //试卷总分
  177. $paperScore = $this->getPaperScore($paperIds);
  178. if(!$paperScore){
  179. echo "试卷总分不正确!\n";
  180. $error[] = $className."试卷总分不正确!";
  181. continue;
  182. }
  183. /**************************** 一、班级情况分析 ***********************************/
  184. //获取当前考试的上一次考试数据
  185. $examDate = $this->getExamTime($examId);
  186. $sql = "select cep.exam_id,e.exam_group_id from class_exam_printer as cep left join exam as e on e.exam_id = cep.exam_id where e.subject_id = {$examInfo['subject_id']} and cep.add_time < {$examDate} and e.class_id = {$examInfo['class_id']} and cep.type = 0 and e.status = 1 order by add_time desc";
  187. $preInfo= $this->sConn->createCommand($sql)->queryRow();
  188. $preExamId = isset($preInfo['exam_id'])?$preInfo['exam_id']:'';
  189. $preExamGroupId = isset($preInfo['exam_group_id'])?$preInfo['exam_group_id']:'';
  190. $prePaperScore = 0;
  191. $preStuIdsArr = array();
  192. if($preExamId){
  193. $sql = "select exam_id from exam where exam_group_id = {$preExamGroupId}";
  194. $preExamIds = $this->sConn->createCommand($sql)->queryColumn();
  195. //去除没有上传成绩的学生
  196. $prePtrInfo = array();
  197. if($preExamIds){
  198. $preStuIdsArr = $this->getHasScoreStu($preExamIds);
  199. $prePtrInfo = $this->getStudentExamInfo($preExamIds);
  200. }
  201. $prePaperIds = array();
  202. foreach($prePtrInfo as $value){
  203. $prePaperIds[$value['exam_id']] = $value['paper_id'];
  204. }
  205. if($prePaperIds){
  206. $prePaperScore = $this->getPaperScore($prePaperIds);
  207. }
  208. }else{
  209. $prePtrInfo = array();
  210. }
  211. if(!$prePaperScore && $prePtrInfo){
  212. echo "试卷总分不正确!\n";
  213. $error[] = $className."试卷总分不正确!";
  214. continue;
  215. }
  216. if(isset($paperIds[$examId])){
  217. $paperId = $paperIds[$examId];
  218. }else{
  219. echo "试卷id没有考试信息!\n";
  220. $error[] = $className."试卷id没有考试信息!";
  221. continue;
  222. }
  223. //班级排名得分率人数等数据
  224. $classAnalyData = $this->getClassAnalyse($examId,$ptrInfo,$paperScore,$preExamId,$prePtrInfo,$prePaperScore,$stuIdsArr,$preStuIdsArr);
  225. //大幅进步,大幅退步,前5名和后5名
  226. $largeOrderData = $this->getLargeOrder($examId,$ptrInfo,$preExamId,$prePtrInfo,$stuIdsArr,$preStuIdsArr);
  227. $sutName = isset($largeOrderData['stu_name'])?$largeOrderData['stu_name']:array();
  228. $sutOrder = isset($largeOrderData['stu_order'])?$largeOrderData['stu_order']:array();
  229. unset($ptrInfo);
  230. unset($prePtrInfo);
  231. /**************************** 二、考试情况分析 ***********************************/
  232. //试卷题对应的题号,分数
  233. list($largeTopicType,$largeTopicMethod) = $this->getPaperLargeTopicInfo($paperId);
  234. list($smallTopicScore,$smallTopicNo,$topicScore,$topicNo,$topicType,$topicLogicType,$topicRelLarge,$topicRelMethod,$topicTypeRelNo,$topicRelTopicCount) = $this->getPaperTopicInfo2($paperId,$largeTopicType,$subjectId,$examInfo);
  235. if(!$topicScore){
  236. echo "没有试卷题数据!\n";
  237. $error[] = $className."没有试卷题数据!";
  238. continue;
  239. }
  240. $stuRs = $this->getStudentRs($paperIds);
  241. if(!$stuRs){
  242. echo "没有学生做题数据!\n";
  243. $error[] = $className."没有学生做题数据!";
  244. continue;
  245. }
  246. $typeMasterData = $this->getTopicTypeAnaly($stuRs,$topicScore,$topicNo,$paperId,$topicLogicType,$topicRelLarge,$smallTopicNo);
  247. //英语全学科判断
  248. if($subjectId == 8 && $examInfo['qxk_paper_id']){
  249. $newTopicTypeRelNo = array();
  250. foreach($topicTypeRelNo as $topic_type=>$topic_data){
  251. if(isset($getTopicTypeRelate[$topic_type])){
  252. $newTopicTypeRelNo[$getTopicTypeRelate[$topic_type]] = $topic_data;
  253. }else{
  254. $newTopicTypeRelNo[$topic_type] = $topic_data;
  255. }
  256. }
  257. $topicTypeRelNo = $newTopicTypeRelNo;
  258. }
  259. //班级高频错题 统计班级得分率小于50%的题目
  260. $high_rate_wrong_topic = array();
  261. if($typeMasterData['type_name_arr']){
  262. foreach($typeMasterData['type_name_arr'] as $large_type=>$type_name){
  263. if(isset($topicTypeRelNo[$large_type])){
  264. $high_rate_wrong_topic[$large_type] = array(array(),array(),array(),array(),array());
  265. foreach($topicTypeRelNo[$large_type] as $topic_id=>$topic_no){
  266. $topic_class_rate = isset($typeMasterData['topic_class_rate'][$topic_id]) ? $typeMasterData['topic_class_rate'][$topic_id] : 0;
  267. if($topic_class_rate <= 10){
  268. $high_rate_wrong_topic[$large_type][0][] = $smallTopicNo[$topic_id];
  269. }elseif($topic_class_rate>10 && ($topic_class_rate<=20)){
  270. $high_rate_wrong_topic[$large_type][1][] = $smallTopicNo[$topic_id];
  271. }elseif($topic_class_rate>20 && ($topic_class_rate<=30)){
  272. $high_rate_wrong_topic[$large_type][2][] = $smallTopicNo[$topic_id];
  273. }elseif($topic_class_rate>30 && ($topic_class_rate<=40)){
  274. $high_rate_wrong_topic[$large_type][3][] = $smallTopicNo[$topic_id];
  275. }elseif($topic_class_rate>40 && ($topic_class_rate<=50)){
  276. $high_rate_wrong_topic[$large_type][4][] = $smallTopicNo[$topic_id];
  277. }
  278. }
  279. }
  280. }
  281. }
  282. $typeMasterData['high_rate_wrong_topic'] = $high_rate_wrong_topic;
  283. $typeRateImgUrl = array();
  284. /**************************** 三、考点掌握情况 ***********************************/
  285. //题信息
  286. $topicIds = array_keys($topicNo);
  287. $tplData = array();
  288. if($examInfo['tpl_data']){
  289. $tplData = $examInfo['tpl_data'];
  290. if($tplData && !is_array($tplData)){
  291. $tplData = json_decode($tplData,true);
  292. }
  293. }
  294. $isNewEnglish = (isset($tplData['isNewEnglish']) && $tplData['isNewEnglish'] == 1)?1:0;
  295. $_params = array('isFormat' => $subjectId == 8 ? 0 : 1 , 'isTird' => $isThird ,'isNewEnglish' => $isNewEnglish,'isNoReplaceLable'=>1);
  296. $topicDetails = $this->apiBrainPost('/topic/batchAll', array('topicIds' => $topicIds,'subjectId' => $batch_subject_id ,'params' => $_params),25,true);
  297. unset($tplData);
  298. $methodName = array();
  299. $largeTopicScore = array();
  300. if (!$topicDetails) {
  301. echo "获取接口batchALL无数据!\n";
  302. $error[] = $className."获取接口batchALL无数据!";
  303. continue;
  304. } elseif (isset($topicDetails['status']) && $topicDetails['status']==0) {
  305. echo $topicDetails['error'][0]."\n";
  306. $error[] = $className.$topicDetails['error'][0];
  307. continue;
  308. }else{
  309. if ($subjectId == 8) {
  310. $tempDetials = array();
  311. if($examInfo['qxk_paper_id']){
  312. $topicDetails = $this->quanTopicDetail($topicDetails);
  313. }
  314. foreach ($topicDetails as $detail) {
  315. //范文
  316. //语篇
  317. $keyWords = array();
  318. if(isset($getTopicTypeRelate[$detail['type_id']])){
  319. $detail['type_id'] = $getTopicTypeRelate[$detail['type_id']];
  320. }
  321. if (in_array($detail['type_id'], array(2, 3, 4, 5))) {
  322. $wordsIds = array();
  323. $wordInfoArr = array();
  324. if (isset($detail['key_words_levels']) && $detail['key_words_levels']) {
  325. $key_words_level = $detail['key_words_levels'];
  326. $class = array();
  327. foreach ($key_words_level as $val) {
  328. $class[] = $val['level'];
  329. }
  330. array_multisort($class, SORT_DESC, $key_words_level);
  331. $_new_key_words = $key_words_level;
  332. $word_content = array();
  333. foreach ($_new_key_words as $item) {
  334. $word_content[] = '"' . $item['name'] . '"';
  335. }
  336. if ($word_content) {
  337. $wordInfoArr = $this->getWord(array('content' => $word_content, 'type_id' => array(1, 2), 'core_words' => 1,'status'=>1));
  338. $topic_word_level = array();
  339. foreach ($wordInfoArr as $word_id => $word_info) {
  340. $level = isset($word_info['levels']) ? $word_info['levels'] : 0;
  341. $topic_word_level[$word_id] = $level;
  342. }
  343. arsort($topic_word_level);
  344. foreach ($topic_word_level as $word_id => $level) {
  345. if (count($wordsIds) <= 10) {
  346. $wordsIds[] = $word_id;
  347. }
  348. }
  349. }
  350. }
  351. if ($wordsIds) {
  352. foreach ($wordsIds as $w_id) {
  353. if (isset($wordInfoArr[$w_id])) {
  354. $keyWords[] = $wordInfoArr[$w_id];
  355. }
  356. }
  357. $keyWords = $this->handleWordClass($keyWords);
  358. }
  359. }
  360. $detail['key_words'] = $keyWords;
  361. if($examInfo['qxk_paper_id']){
  362. $detail['key_words'] = isset($detail['new_key_words'])?$detail['new_key_words']:array();
  363. }
  364. //替换序号
  365. // if (in_array($detail['type_id'], array(2,4,5,6,9, 10, 11, 12, 14))) {
  366. // $this->replaceTitle($detail['title'],$detail['id'],$topicRelLarge,$smallTopicNo);
  367. // }
  368. $detail['title'] = str_replace('&nbsp;',' ',$detail['title']);
  369. $tempDetials[(string)$detail['id']] = $detail;
  370. }
  371. $topicDetails = $tempDetials;
  372. unset($tempDetials);
  373. //大题分数
  374. foreach ($topicRelLarge as $small_id => $large_id) {
  375. if (!isset($largeTopicScore[$large_id])) {
  376. $largeTopicScore[$large_id] = 0;
  377. }
  378. $largeTopicScore[$large_id] += $topicScore[$small_id];
  379. }
  380. }
  381. }
  382. $diff_id_arr = array_diff($topicIds, array_keys($topicDetails));
  383. if ($diff_id_arr) {
  384. //todo 发送消息到补提
  385. echo "没有试题内容!\n";
  386. $error[] = $className."没有试题内容!";
  387. continue;
  388. }
  389. //1.薄弱考点统计
  390. //2.薄弱考点掌握较差学生名单
  391. //3.班级排名后25%学生的薄弱考点
  392. $pramas = array($smallTopicScore,$smallTopicNo,$paperId,$topicType,$topicLogicType,$topicRelLarge,$topicRelMethod,$largeTopicMethod,$sutName,$sutOrder,$methodName);
  393. $methodCount = array();
  394. //4.考点掌握情况变化趋势
  395. //生成图片
  396. if(false){
  397. $_classRate = array();
  398. $examDate = $this->getExamTime($examId);
  399. $sql = "select cep.exam_id,cep.add_time from class_exam_printer as cep left join exam as e on e.exam_id = cep.exam_id where e.subject_id = {$examInfo['subject_id']} and cep.add_time <= {$examDate} and e.class_id = {$examInfo['class_id']} and cep.type = 0 and e.status = 1 order by add_time desc limit 3";
  400. $thirdExam= $this->sConn->createCommand($sql)->queryAll();
  401. if(count($thirdExam) > 3){
  402. $thirdExamIds = array();
  403. $examTime = array();
  404. foreach($thirdExam as $value){
  405. $thirdExamIds[] = $value['exam_id'];
  406. $examTime[$value['exam_id']] = $value['add_time'];
  407. }
  408. list($paperRelExam,$exmaRelPaper) = $this->getPaperIdsByExamIds($thirdExamIds);
  409. $_topicScore = array();
  410. $_topicMethod = array();
  411. $_stuRs = array();
  412. if($paperRelExam){
  413. $sql = "select topic_id,stem_id,`no`,score,type,method_ids from paper_topic_relation where paper_id in (".implode(',',$paperRelExam).") and is_delete = 0 order by `no`";
  414. $thirdPaperInfo=$this->sConn->createCommand($sql)->queryAll();
  415. foreach ($thirdPaperInfo as $item) {
  416. $_topicScore[$item['topic_id']] = $item['score'];
  417. $_topicMethod[$item['topic_id']] = explode(',',$item['method_ids']);
  418. }
  419. $_stuRs = $this->getStudentRs($paperRelExam);
  420. }
  421. $_scoring = $_score = array();
  422. foreach ($_stuRs as $stuId => $stuR) {
  423. foreach ($stuR as $tId => $item) {
  424. $pId = $item['paper_id'];
  425. $eId = isset($exmaRelPaper[$pId])?$exmaRelPaper[$pId]:0;
  426. $eTime = isset($examTime[$eId])?$examTime[$eId]:0;
  427. if(!$eTime) continue;
  428. $_tScore = isset($_topicScore[$tId])?$_topicScore[$tId]:0;
  429. if(isset($_topicMethod[$tId]) && $_topicMethod[$tId]){
  430. foreach ($_topicMethod[$tId] as $mId){
  431. if(!$mId){
  432. continue;
  433. }
  434. if(!isset($_scoring[$eTime])){
  435. $_scoring[$eTime] = array();
  436. }
  437. if(!isset($_scoring[$eTime][$mId])){
  438. $_scoring[$eTime][$mId] = 0;
  439. }
  440. $_scoring[$eTime][$mId] += $item['scoring'];
  441. if(!isset($_score[$eTime])){
  442. $_score[$eTime] = array();
  443. }
  444. if(!isset($_score[$eTime][$mId])){
  445. $_score[$eTime][$mId] = 0;
  446. }
  447. $_score[$eTime][$mId] += $_tScore;
  448. }
  449. }
  450. }
  451. }
  452. foreach($_scoring as $eTime => $scorings){
  453. if(!isset($_classRate[$eTime])){
  454. $_classRate[$eTime] = array();
  455. }
  456. foreach($scorings as $mId => $scoring){
  457. if(isset($_score[$eTime]) && isset($_score[$eTime][$mId]) && $_score[$eTime][$mId]){
  458. $_classRate[$eTime][$mId] = round($scoring/$_score[$eTime][$mId],4) * 100;
  459. }else{
  460. $_classRate[$eTime][$mId] = 0;
  461. }
  462. }
  463. }
  464. }
  465. ksort($_classRate);
  466. //三次考试同一考点的得分率
  467. $timeMethodRate = array();
  468. foreach($_classRate as $time => $rates){
  469. foreach($rates as $mId => $rate){
  470. if(!isset($timeMethodRate[$mId])){
  471. $timeMethodRate[$mId] = array();
  472. }
  473. $timeMethodRate[$mId][] = $rate;
  474. $timeMethodRate[$mId][] = $rate;
  475. $timeMethodRate[$mId][] = $rate;
  476. }
  477. }
  478. //取出符合规则的三个考点
  479. $rateCompare = array();
  480. foreach ($timeMethodRate as $mId => $rates) {
  481. $rate_1 = $rates[2] - $rates[1];
  482. $rate_2 = $rates[1] - $rates[0];
  483. $rateCompare[$mId] = $rate_1 - $rate_2;
  484. }
  485. arsort($rateCompare);
  486. $rateCompare = array_slice($rateCompare,0,3,true);
  487. $timeMethodRate = array();
  488. foreach($_classRate as $time => $rates){
  489. foreach($rates as $mId => $rate){
  490. if(isset($rateCompare[$mId])){
  491. if(!isset($timeMethodRate[$mId])){
  492. $timeMethodRate[$mId] = array();
  493. }
  494. $timeMethodRate[$mId][] = $rate;
  495. }
  496. }
  497. }
  498. $imgPath = str_replace("protected", "", Yii::app()->basePath) . 'assets/temp_img/';
  499. $urlPath = Yii::app()->request->hostInfo . '/assets/temp_img/';
  500. $methodRatePath= $imgPath.$examId ."_rate.png";
  501. $methodRateUrl = $urlPath.$examId ."_rate.png";
  502. $this->imgArr[] = $methodRatePath;
  503. if(count($timeMethodRate) >= 3){
  504. $this->getImage($methodRatePath,$timeMethodRate);
  505. }
  506. if(!file_exists($methodRatePath)){
  507. $methodRateUrl = '';
  508. }
  509. }else{
  510. $methodRateUrl = '';
  511. }
  512. /**************************** 四、试卷讲评 ***********************************/
  513. //选择题
  514. $choinceIds = $this->getChoiceIds($topicType,$topicLogicType,$subjectId,$examInfo['tpl_index']);
  515. //试题年级和班级得分率,答对和答错人数
  516. $topicRateStu = $this->getTopicRateWrongPerson($stuRs,$topicScore,$paperId,$stuIdsArr,$topicRelLarge,$choinceIds,$sutName,$topicLogicType);
  517. $common_practice = array();
  518. $commonTopicDetail = array();
  519. $check = 1;
  520. if($subjectId == 8){
  521. $sql = "select custom_config from product_class_relation pcr join product_setting ps on pcr.ps_id=ps.ps_id where pcr.class_id={$classId} and product_type=6 and ps.subject_id = {$subjectId}";
  522. $config =$this->sConn->createCommand($sql)->queryRow();
  523. if ($config) {
  524. $configArr = json_decode($config['custom_config'],true);
  525. $setting = $configArr['setting'];
  526. $check = isset($setting['variantTrainingOfCommonProblems']) ? $setting['variantTrainingOfCommonProblems'] : 1;
  527. }
  528. if ($check) {
  529. if($examInfo['academicr_common_practice']){
  530. $common_push_all_topics = array();
  531. $common_practice = json_decode($examInfo['academicr_common_practice'],true);
  532. foreach($common_practice as $type=>$cp_info){
  533. if($type == 'min_rate_text' || $type == 'common_extra'){
  534. $t_ids = _array_column($cp_info,'topic_id');
  535. $common_push_all_topics = array_merge($common_push_all_topics,$t_ids);
  536. }else{
  537. foreach($cp_info as $topic_type=>$t_info){
  538. $t_ids = _array_column($t_info,'topic_id');
  539. $common_push_all_topics = array_merge($common_push_all_topics,$t_ids);
  540. }
  541. }
  542. }
  543. }else{
  544. //20211221新逻辑:学生提分宝不生成共性问题的话 教师讲案直接不生成
  545. echo "没有生成共性题!\n";
  546. $error[] = $className."没有生成共性题!";
  547. continue;
  548. $common_wrong_topic = $this->getCommonPractice($topicDetails,$topicRateStu['large_topic_score'],$stuRs,$largeTopicType,$topicRateStu['large_contain_score']);
  549. list($common_practice,$common_push_all_topics) = $common_wrong_topic;
  550. $sql = "update exam set academicr_common_practice = '".json_encode($common_practice)."' where exam_id={$examId}";
  551. $this->sConn->createCommand($sql)->execute();
  552. }
  553. if($common_push_all_topics){
  554. $commonTopicDetail = $this->apiBrainPost('/topic/batchAll', array('topicIds' => array_values($common_push_all_topics),'subjectId' => $batch_subject_id ,'params' => array('isNoReplaceLable'=>1)),25,true);
  555. if (!$commonTopicDetail) {
  556. echo "获取接口batchALL无数据!\n";
  557. $error[] = $className."获取接口batchALL无数据!";
  558. continue;
  559. } elseif (isset($commonTopicDetail['status']) && $commonTopicDetail['status']==0) {
  560. echo $commonTopicDetail['error'][0]."\n";
  561. $error[] = $className.$commonTopicDetail['error'][0];
  562. continue;
  563. }else{
  564. $tempDetials = array();
  565. if($examInfo['qxk_paper_id']){
  566. $commonTopicDetail = $this->quanTopicDetail($commonTopicDetail);
  567. }
  568. foreach ($commonTopicDetail as $detail) {
  569. if(isset($getTopicTypeRelate[$detail['type_id']])){
  570. $detail['type_id'] = $getTopicTypeRelate[$detail['type_id']];
  571. }
  572. $tempDetials[(string)$detail['id']] = $detail;
  573. }
  574. $commonTopicDetail = $tempDetials;
  575. }
  576. }
  577. }
  578. }
  579. $topicTypeScore = array();
  580. if($subjectId == 8){
  581. //题型重新按照组卷顺序排序
  582. $new_type_name_arr = array();
  583. $new_high_rate_wrong_topic = array();
  584. $new_class_rate = array();
  585. $new_type_order = array_keys($topicTypeRelNo);
  586. if($new_type_order){
  587. foreach($new_type_order as $new_type){
  588. if(isset($this->logicTypeName) && isset($this->logicTypeName[$new_type]) && $this->logicTypeName[$new_type]){
  589. $new_type_name_arr[$new_type] = $this->logicTypeName[$new_type];
  590. }else{
  591. $new_type_name_arr[$new_type] = '';
  592. }
  593. if(isset($typeMasterData['high_rate_wrong_topic']) && $typeMasterData['high_rate_wrong_topic'] && isset($typeMasterData['high_rate_wrong_topic'][$new_type])){
  594. $new_high_rate_wrong_topic[$new_type] = $typeMasterData['high_rate_wrong_topic'][$new_type];
  595. }
  596. if(isset($typeMasterData['class_rate']) && $typeMasterData['class_rate'] && isset($typeMasterData['class_rate'][$new_type])){
  597. $new_class_rate[$new_type] = $typeMasterData['class_rate'][$new_type];
  598. }
  599. }
  600. }
  601. if($new_type_name_arr){
  602. $typeMasterData['type_name_arr'] = $new_type_name_arr;
  603. }
  604. if($new_high_rate_wrong_topic){
  605. $typeMasterData['high_rate_wrong_topic'] = $new_high_rate_wrong_topic;
  606. }
  607. if($new_class_rate){
  608. $typeMasterData['class_rate'] = $new_class_rate;
  609. }
  610. //获取题型对应题目关系
  611. $typeToTopicIds = array();
  612. if($topicDetails){
  613. foreach($topicDetails as $topicIdTemp=>$topicDetailTemp){
  614. if(isset($topicDetailTemp['type_id']) && $topicDetailTemp['type_id']){
  615. $typeToTopicIds[$topicDetailTemp['type_id']][] = (string)$topicIdTemp;
  616. }
  617. }
  618. }
  619. //增加班级题型得分表
  620. if($topicTypeRelNo){
  621. foreach($topicTypeRelNo as $typeTemp=>$topicNoDataTemp){
  622. if($topicNoDataTemp){
  623. $topicTypeScore[$typeTemp]['score'] = 0;
  624. $topicTypeScore[$typeTemp]['class_score'] = 0;
  625. $topicTypeScore[$typeTemp]['grade_score'] = 0;
  626. $topicTypeScore[$typeTemp]['diff_score'] = 0;
  627. $topicTypeScore[$typeTemp]['no'] = '';
  628. $tempClassScore = $tempGradeScore = $tempClassCount = $tempGradeCount = 0;
  629. $tempClassStuIds = $tempGradeStuIds = array();
  630. if(isset($topicRateStu) && $topicRateStu && isset($topicRateStu['large_topic_score']) && $topicRateStu['large_topic_score']){
  631. foreach($topicRateStu['large_topic_score'] as $stuIdTemp=>$stuScoreTemp){
  632. foreach($stuScoreTemp as $tempTopicIdK=>$tempTopicIdV){
  633. if(isset($typeToTopicIds[$typeTemp]) && $typeToTopicIds[$typeTemp] && in_array((string)$tempTopicIdK,$typeToTopicIds[$typeTemp],true)){
  634. if(isset($sutName[$stuIdTemp])){//本班
  635. $tempClassScore += (isset($tempTopicIdV['scoring']) && $tempTopicIdV['scoring']) ? $tempTopicIdV['scoring']:0;
  636. // $tempClassCount ++;
  637. $tempClassStuIds[] = (string)$stuIdTemp;
  638. }
  639. $tempGradeScore += (isset($tempTopicIdV['scoring']) && $tempTopicIdV['scoring']) ? $tempTopicIdV['scoring']:0;
  640. // $tempGradeCount ++;
  641. $tempGradeStuIds[] = (string)$stuIdTemp;
  642. }
  643. }
  644. }
  645. }
  646. if($tempClassStuIds){
  647. $tempClassCount = count(array_unique($tempClassStuIds));
  648. $topicTypeScore[$typeTemp]['class_score'] = round($tempClassScore/$tempClassCount,1);
  649. }
  650. if($tempGradeStuIds){
  651. $tempGradeCount = count(array_unique($tempGradeStuIds));
  652. $topicTypeScore[$typeTemp]['grade_score'] = round($tempGradeScore/$tempGradeCount,1);
  653. }
  654. $topicTypeScore[$typeTemp]['diff_score'] = round($topicTypeScore[$typeTemp]['class_score'] - $topicTypeScore[$typeTemp]['grade_score'],1);
  655. if(isset($typeToTopicIds[$typeTemp]) && $typeToTopicIds[$typeTemp]){
  656. foreach($typeToTopicIds[$typeTemp] as $bigTopicTemp){
  657. if(isset($largeTopicScore[$bigTopicTemp]) && $largeTopicScore[$bigTopicTemp]){
  658. $topicTypeScore[$typeTemp]['score'] += $largeTopicScore[$bigTopicTemp];
  659. }
  660. }
  661. }
  662. $topicNoValue = array_values($topicNoDataTemp);
  663. if(count($topicNoValue) == 1){
  664. $topicTypeScore[$typeTemp]['no'] = $topicNoValue[0];
  665. }else{
  666. $topicTypeScore[$typeTemp]['no'] = min($topicNoValue).'-'.max($topicNoValue);
  667. }
  668. }
  669. }
  670. }
  671. }
  672. $data = array();
  673. $data['examInfo'] = $examInfo;
  674. $data['classAnalyData'] = $classAnalyData;
  675. $data['largeOrderData'] = $largeOrderData;
  676. $data['typeMasterData'] = $typeMasterData;
  677. $data['typeRateImg'] = $typeRateImgUrl;
  678. $data['methodCount'] = $methodCount;
  679. $data['topicDetails'] = $topicDetails;
  680. $data['paperTopicNo'] = $topicNo;
  681. $data['smallTopicNo'] = $smallTopicNo;
  682. $data['topicTypeRelNo'] = $topicTypeRelNo;
  683. $data['topicRateStu'] = $topicRateStu;
  684. $data['methodRateUrl'] = $methodRateUrl;
  685. $data['subjectId'] = $subjectId;
  686. $data['isThird'] = $isThird;
  687. $data['sutName'] = $sutName;
  688. $data['methodName'] = $methodName;
  689. $data['logicTypeName'] = $this->logicTypeName;
  690. $data['topic_score'] = $largeTopicScore;
  691. $data['topic_rel_topic_count'] = $topicRelTopicCount;
  692. $data['common_practice'] = $common_practice;
  693. $data['common_topic_detail'] = $commonTopicDetail;
  694. $data['topicTypeScore'] = $topicTypeScore;
  695. if ($subjectId == 8) {
  696. // $html_name = 'en_teach_batch';
  697. $html_name = 'en_teach';
  698. }else{
  699. $html_name = 'teach_batch';
  700. }
  701. $data['className'] = $className;
  702. $data['imgUrl'] = $file_html_url;
  703. $html = $this->viewRender($html_name, $data);
  704. unset($data);
  705. $htmlpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/academicr/'; //存放生成的HTML路径
  706. $pdfpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/academicr/' . $v_data['school_id'] . "/"; //存放生成的PDF路径
  707. $pdfurl = '/upload/tmpDir/academicr/' . $v_data['school_id'] . "/";
  708. if (!is_dir($htmlpath)) {
  709. if (!mkdir($htmlpath, 0777, true)) {
  710. exit('Create directory fail: ' . $htmlpath);
  711. }else{
  712. exec('chown -R www:www '.$htmlpath);
  713. }
  714. }if (!is_dir($pdfpath)) {
  715. if (!mkdir($pdfpath, 0777, true)) {
  716. exit('Create directory fail1: ' . $pdfpath);
  717. }else{
  718. exec('chown -R www:www '.$pdfpath);
  719. }
  720. }
  721. $htmlpath.=$examId . ".html";
  722. $f = fopen($htmlpath, "w");
  723. fwrite($f, $html);
  724. fclose($f);
  725. $htmlurl = '/upload/tmpDir/academicr/' . $examId . ".html"; //访问HTML的路径
  726. if (Yii::app()->basePath == "D:\wamp64\www\zsyas2\protected") {//本地的basePath
  727. $htmlurl = " http://zsyas2.com" . '/'.$examId.'.html';
  728. $pdffname=$classId."-".$examId.".pdf";
  729. $pdfpath = $pdfpath . $pdffname;
  730. $pdfurl = $pdfurl . $pdffname;
  731. $commond = Yii::app()->params['phantomjs'] . " "
  732. . Yii::app()->params['html2pdf'] . " "
  733. . " {$htmlurl}"
  734. . " {$pdfpath}"
  735. . " 176mm*250mm ''";
  736. } else {
  737. $server = Yii::app()->params['phantomjs_server'];
  738. $js = 'html2pdf.js';
  739. if ($subjectId == 8){
  740. $server = Yii::app()->params['phantomjs_server_en'];
  741. $js = 'html2pdf_en.js';
  742. }
  743. //$htmlurl = "http://" . $_SERVER['SERVER_NAME'] . $htmlurl;
  744. $htmlurl = $file_html_url . $htmlurl;
  745. $pdffname=$classId."-".$examId.".pdf";
  746. $pdfpath = $pdfpath . $pdffname;
  747. $pdfurl = $pdfurl . $pdffname;
  748. $commond = $server . " "
  749. . Yii::app()->basePath . '/../js/'.$js . " "
  750. . " {$htmlurl}"
  751. . " {$pdfpath}"
  752. . " 176mm*250mm ''";
  753. }
  754. // debug($commond);
  755. exec($commond, $res, $code);
  756. if(isset($res[0])){
  757. $isBool = false;
  758. foreach($res as $msg){
  759. if (strpos($msg, 'succeed') !== false){
  760. $isBool = true;
  761. }
  762. }
  763. if ($isBool) {//命令返回成功
  764. if (file_exists($pdfpath)) {
  765. $repdf = $examId.".pdf";
  766. $rename = 'zsyas2/academicr/'.$v_data['school_id'].'/'. date('Y') . '/' . date('m') . '/' . date('d').'/'. uniqid() . '.' . $repdf;
  767. $ucloud = new Qcloud();
  768. $uploadInfo = $ucloud->putFile($rename, $pdfpath);
  769. //html路径
  770. $htmlName = 'zsyas2/academicr/'.$v_data['school_id'].'/'. date('Y') . '/' . date('m') . '/' . date('d').'/'. uniqid() . '.' . $examId.'.html';
  771. $uploadHtmlInfo = $ucloud->putFile($htmlName, $htmlpath);
  772. if ($uploadInfo['status'] == 0) {
  773. echo "PDF文件上传失败\n";
  774. $error[] = $className."PDF文件上传失败";
  775. }else{
  776. $tmpHtmlUrl = '';
  777. if ($uploadHtmlInfo['status'] != 0) {
  778. $tmpHtmlUrl = $uploadHtmlInfo['url'];
  779. }
  780. $pdfurl = $uploadInfo['url'];
  781. $this->sConn->createCommand()->update("exam", array("academicr_html_path"=>$tmpHtmlUrl,"academicr_pdf_path" => $pdfurl, "academicr_pdf_time" => time(), "is_academicr_pdf" => 1), "exam_id = '{$examId}'");
  782. $pdfArr[] = $pdfpath;
  783. $pdfNames[] = $className;
  784. }
  785. @unlink($htmlpath);
  786. } else {
  787. $this->sConn->createCommand()->update("exam", array("academicr_pdf_path" => "", "academicr_pdf_time" => 0, "is_academicr_pdf" => 0), "exam_id = '{$examId}'");
  788. @unlink($htmlpath);
  789. echo json_encode(array("status" => 1, "error" => "PDF文件未找到!"));
  790. exit;
  791. }
  792. } else {
  793. @unlink($htmlpath);
  794. echo json_encode(array("status" => 1, "error" => "PDF创建失败!",'exec_rs'=>json_encode($res)));
  795. exit;
  796. }
  797. }else{
  798. echo "PDF创建失败!\n";
  799. $error[] = $className."PDF创建失败!";
  800. }
  801. }else{
  802. $pdfArr[] = $pdfpath;
  803. $pdfNames[] = $className;
  804. }
  805. }
  806. }
  807. foreach($pdfArr as $k=>$v){
  808. if(strpos($v,'http') !== false){
  809. $new_dir_url = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/academicr_batch/'.$v_data['exam_group_id']."/".$v_data['id']."/";
  810. if (!is_dir($new_dir_url)) {
  811. if (!mkdir($new_dir_url, 0777, true)) {
  812. echo 'Create directory fail1: ' . $new_dir_url. "\n";
  813. }else{
  814. exec('chown -R www:www '.$new_dir_url);
  815. }
  816. }
  817. $new_file_url = $this->downImgRar($v,$new_dir_url,$k);
  818. $pdfArr[$k] = $new_file_url;
  819. // echo $new_file_url;exit;
  820. }
  821. }
  822. //var_dump($pdfArr);exit;
  823. $this->conn->active = false;
  824. $conn = $this->getDbConnection(Yii::app()->params["default_server"]['addr'], Yii::app()->params["default_db"]['name'], Yii::app()->params["default_server"]['username'], Yii::app()->params["default_server"]['password']);
  825. $this->conn = $conn;
  826. if($pdfArr){
  827. echo "开始压缩文件\n";
  828. if($pdfArr){
  829. echo $examName.'pdf生成成功!'. "\n";
  830. // $report_name = $class_name.$year."年度报告.zip";
  831. $filepath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/academicr_batch/'.$v_data['exam_group_id']."/".$v_data['id']."/"; //存放生成的PDF路径
  832. if (!is_dir($filepath)) {
  833. if (!mkdir($filepath, 0777, true)) {
  834. echo 'Create directory fail1: ' . $filepath. "\n";
  835. }else{
  836. exec('chown -R www:www '.$filepath);
  837. }
  838. }
  839. $examName = iconv("UTF-8","GBK//IGNORE",$examName);
  840. $filename = dirname(dirname(dirname(__FILE__))).'/upload/tmpDir/academicr_batch/'.$v_data['exam_group_id']."/".$v_data['id']."/".$v_data['exam_group_id'].".zip"; //最终生成的文件名(含路径)
  841. $zip = new ZipArchive();//使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释
  842. if ($zip->open($filename, ZIPARCHIVE::OVERWRITE)!==TRUE) {
  843. echo $examName.'zip生成失败!'. "\n";
  844. }else{
  845. foreach ($pdfArr as $k=>$val) {
  846. // $pdfNames[$k] = iconv("UTF-8","GBK//IGNORE",$pdfNames[$k]);
  847. $pdfname = '-'.$pdfNames[$k].'-教师讲案';
  848. $pdfname = iconv("UTF-8","GBK//IGNORE",$pdfname);
  849. $res=$zip->addFile($val,$examName.$pdfname.'.pdf');
  850. //@unlink($pdfArr[$k]);
  851. }
  852. $zip->close();//关闭
  853. foreach($pdfArr as $k=>$val){
  854. @unlink($val);
  855. }
  856. //生成完成
  857. // $filename = addslashes($filename);
  858. $time = time();
  859. $filename = $this->characet($filename);
  860. $ucloud = new Qcloud();
  861. $filename = iconv("UTF-8","GBK//IGNORE",$filename);
  862. $examName = $this->characet($examName);
  863. $meg = $ucloud->putFile('zsyas2/academicr_batch/'.$v_data['exam_group_id'].'/'.$v_data['id'].'/'.$examName.'.zip',$filename);
  864. if($meg['status'] == 0){
  865. $error[] = $className.$meg['msg'];
  866. }else{
  867. $url = $meg['url'];
  868. $url = str_replace("%2F","/",$url);
  869. $sql = "update download_table_setting set status = 2,zip_url = '{$url}',update_time = {$time} where id = {$v_data['id']}";
  870. $this->conn->createCommand($sql)->execute();
  871. $is_success = 1;
  872. echo $examName.'zip生成成功!'. "\n";
  873. }
  874. @unlink($filename);
  875. }
  876. }else{
  877. echo 'pdf生成失败!'. "\n";
  878. }
  879. }
  880. }else{
  881. echo '连接学校ID'.$v_data['school_id']."失败\n";
  882. continue;
  883. }
  884. }else{
  885. echo '暂无学校ID'.$v_data['school_id']."的信息\n";
  886. continue;
  887. }
  888. $this->sConn->active = false;
  889. }
  890. if(!$is_success){
  891. if($error){
  892. $time = time();
  893. $sql = "update download_table_setting set error_msg='".implode(",",$error)."',update_time = {$time},status=3 where id = {$v_data['id']}";
  894. $this->conn->createCommand($sql)->execute();
  895. echo $examName.'zip生成失败!'. "\n";
  896. }else{
  897. $time = time();
  898. $sql = "update download_table_setting set update_time = {$time},status=3 where id = {$v_data['id']}";
  899. $this->conn->createCommand($sql)->execute();
  900. echo $examName.'zip生成失败!'. "\n";
  901. }
  902. }else{
  903. if($error){
  904. $time = time();
  905. $sql = "update download_table_setting set error_msg='".implode(",",$error)."',update_time = {$time} where id = {$v_data['id']}";
  906. $this->conn->createCommand($sql)->execute();
  907. }
  908. }
  909. // $this->conn->active = false;
  910. }catch(Exception $e){
  911. // $sql = "update download_table_setting set status=3,error_msg='系统异常' where id = {$v_data['id']}";
  912. //$this->conn->createCommand($sql)->execute();
  913. echo $e->getMessage();
  914. }
  915. }
  916. }else{
  917. echo "暂无要生成的数据\n";
  918. }
  919. $this->conn->active = false;
  920. }else{
  921. echo "连接业务库失败\n";
  922. }
  923. }
  924. function characet($data){
  925. if( !empty($data) ){
  926. $fileType = mb_detect_encoding($data , array('UTF-8','GBK','LATIN1','BIG5')) ;
  927. if( $fileType != 'UTF-8'){
  928. $data = mb_convert_encoding($data ,'utf-8' , $fileType);
  929. }
  930. }
  931. return $data;
  932. }
  933. public function apiPost($path, $arr, $type = 0)
  934. {
  935. $ch = @curl_init();
  936. $result = FALSE;
  937. if ($ch) {
  938. $data = json_encode($arr);
  939. $url = Yii::app()->params['api'][$type]['prefix'] . $path;
  940. $username = Yii::app()->params['api'][$type]['username'];
  941. $password = Yii::app()->params['api'][$type]['password'];
  942. // Digest认证
  943. curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  944. curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
  945. // 不输出头部
  946. curl_setopt($ch, CURLOPT_HEADER, 0);
  947. // curl_exec 获取到的内容不直接输出, 而是返回
  948. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  949. // 请求重启路由器的地址 传参 进行重启
  950. curl_setopt($ch, CURLOPT_URL, $url);
  951. curl_setopt($ch, CURLOPT_USERAGENT, 'Api Client/1.0.0 (chengfei@liancaitech.com)');
  952. curl_setopt($ch, CURLOPT_POST, 1);
  953. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  954. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  955. 'Content-Type: application/json',
  956. 'Content-Length: ' . strlen($data),
  957. ));
  958. if (!curl_errno($ch)) {
  959. $result = json_decode(curl_exec($ch));
  960. }
  961. // 释放资源
  962. curl_close($ch);
  963. }
  964. return $result;
  965. }
  966. /**
  967. * 处理接口返回的数据
  968. * @param $res
  969. * @return array
  970. */
  971. public function handleRes($res){
  972. $result = array(
  973. 'status' => 0,
  974. 'data' => array(),
  975. 'msg' => '暂无数据',
  976. );
  977. if($res){
  978. $res = json_decode($res,true);
  979. if(isset($res['errCode']) && $res['errCode'] == '00'){
  980. $result['status'] = 1;
  981. $result['data'] = isset($res['data'])?$res['data']:array();
  982. $result['msg'] = $res['errMsg'];
  983. }else{
  984. if(isset($res['errMsg'])){
  985. $result['msg'] = $res['errMsg'];
  986. }
  987. }
  988. }
  989. unset($res);
  990. return $result;
  991. }
  992. function file_exists($url)
  993. {
  994. $ch = curl_init();
  995. $timeout = 10;
  996. curl_setopt($ch, CURLOPT_URL, $url);
  997. curl_setopt($ch, CURLOPT_HEADER, 1);
  998. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  999. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  1000. $contents = curl_exec($ch);
  1001. if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 404) {
  1002. return false;
  1003. }
  1004. return true;
  1005. // $ch = curl_init();
  1006. // curl_setopt ($ch, CURLOPT_URL, $url);
  1007. // //不下载
  1008. // curl_setopt($ch, CURLOPT_NOBODY, 1);
  1009. // //设置超时
  1010. // curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 3);
  1011. // curl_setopt($ch, CURLOPT_TIMEOUT, 3);
  1012. // //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  1013. // curl_exec($ch);
  1014. // $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  1015. // if($http_code == 200) {
  1016. // return true;
  1017. // }
  1018. // return false;
  1019. }
  1020. public function viewRender($viewName, $data)
  1021. {
  1022. extract($data, EXTR_PREFIX_SAME,'data');
  1023. ob_start();
  1024. ob_implicit_flush(0);
  1025. $filePath=dirname(dirname(dirname(__FILE__))).'/protected/views/teaching/'.$viewName . '.php';
  1026. require($filePath);
  1027. return ob_get_clean();
  1028. }
  1029. public function getDbConnection($database_host,$database_name,$database_user,$database_password)
  1030. {
  1031. if($database_host && $database_name && $database_user && $database_password){
  1032. $myDbDsn = 'mysql:host=' . $database_host . ';dbname=' . $database_name;
  1033. $my_connection = new CDbConnection($myDbDsn, $database_user, $database_password);
  1034. $my_connection->emulatePrepare = true;
  1035. $my_connection->enableProfiling = true;
  1036. $my_connection->enableParamLogging = true;
  1037. $myDbDsn = null;
  1038. return $my_connection;
  1039. }else{
  1040. return null;
  1041. }
  1042. }
  1043. private function img_process($img)
  1044. {
  1045. $widthArr = array();
  1046. $heightArr = array();
  1047. $width = '';
  1048. $height = '';
  1049. if (preg_match('/[\s\'"]width\s*:\s*(\d+\.*\d*)\s*([a-zA-Z]+)*/si',$img,$widthArr)) {
  1050. $width = $this->length_process($widthArr);
  1051. } else {
  1052. if (preg_match('/[\s\'"]width\s*=\s*[\'"]\s*(\d+\.*\d*)\s*([a-zA-Z]+)*;?[\'"]/si',$img,$widthArr)) {
  1053. $width = $this->length_process($widthArr);
  1054. }
  1055. }
  1056. if ($width) {
  1057. $width = "width=".$width;
  1058. }
  1059. if (preg_match('/[\s\'"]height\s*:\s*(\d+\.*\d*)\s*([a-zA-Z]+)*/si',$img,$heightArr)) {
  1060. $height = $this->length_process($heightArr);
  1061. } else {
  1062. if (preg_match('/[\s\'"]height\s*=\s*[\'"]\s*(\d+\.*\d*)\s*([a-zA-Z]+)*;?[\'"]/si',$img,$heightArr)) {
  1063. $height = $this->length_process($heightArr);
  1064. }
  1065. }
  1066. if ($height) {
  1067. $height = "height=".$height;
  1068. }
  1069. $return_img = preg_replace('/<img[^>]*[\s]+(src[\s]*=[\s]*(([\"]([^\"]*)[\"])|([\']([^\']*)[\'])|([^\s]*)))([^>]*>)/si',"<img ".$width." ".$height." $1 />",$img);
  1070. return $return_img;
  1071. }
  1072. private function length_process($length_arr){
  1073. $length = 0.6*$length_arr[1];
  1074. $unit_keys = array_keys($this->units);
  1075. if (isset($length_arr[2])) {
  1076. //将直接连接单位改为 单位换算
  1077. if(in_array($length_arr[2],$unit_keys)){
  1078. $length = $length*$this->units[$length_arr[2]];
  1079. }else {
  1080. $length .= $length_arr[2];
  1081. }
  1082. }
  1083. return $length;
  1084. }
  1085. public function getCodeByExamId($examId){
  1086. $code = 0;
  1087. $sql = "select s.status,s.refer_code from exam e join semester s on e.semester_id = s.semester_id where e.exam_id = '{$examId}'";
  1088. $data_sem = $this->sConn->createCommand($sql)->queryRow();
  1089. if($data_sem && $data_sem['status'] != 1){
  1090. $code = $data_sem['refer_code']?$data_sem['refer_code']:0;
  1091. }
  1092. return $code;
  1093. }
  1094. private function check_pdf($pdf_path) {
  1095. if (substr($pdf_path, strlen($pdf_path) - 4, 4) == ".pdf") {
  1096. if (file_exists($pdf_path)) {
  1097. return true;
  1098. }
  1099. }
  1100. return false;
  1101. }
  1102. function get_version($class_id)
  1103. {
  1104. if($class_id){
  1105. $sql = 'select show_level,pcr.set_type from product_class_relation pcr join class c on pcr.class_id=c.class_id join product_setting ps on pcr.ps_id=ps.ps_id where c.class_id='.$class_id;
  1106. $product_res = $this->sConn->createCommand($sql)->queryRow();
  1107. if (!$product_res) { //没有找到班级与设置的关系表
  1108. $sql = 'select wb_isp_version from class where class_id='.$class_id;
  1109. $res = $this->sConn->createCommand($sql)->queryRow();
  1110. return $res['wb_isp_version'];
  1111. } else {
  1112. if ($product_res['set_type'] == 1) { //如果是错题本,还是找以前的配置
  1113. $sql = 'select wb_isp_version from class where class_id='.$class_id;
  1114. $res = $this->sConn->createCommand($sql)->queryRow();
  1115. return $res['wb_isp_version'];
  1116. } else{
  1117. return $product_res['show_level'];
  1118. }
  1119. }
  1120. }
  1121. return 0;
  1122. }
  1123. function get_level_rule($class_id)
  1124. {
  1125. if($class_id){
  1126. $sql = 'select level_rule,pcr.set_type from product_class_relation pcr join class c on pcr.class_id=c.class_id join product_setting ps on pcr.ps_id=ps.ps_id where c.class_id='.$class_id;
  1127. $product_res = $this->sConn->createCommand($sql)->queryRow();
  1128. if (!$product_res) { //没有找到班级与设置的关系表
  1129. return 0;
  1130. } else {
  1131. return $product_res['level_rule'];
  1132. }
  1133. }
  1134. return 0;
  1135. }
  1136. function transferOrders($paperIds)
  1137. {
  1138. $sql = 'select paper_id,topic_id,type,`order` from paper_topic_relation where paper_id in ('.implode(',',$paperIds).') order by paper_id, type asc,`order` asc';
  1139. $paper_topcic_relation_res = $this->sConn->createCommand($sql)->queryAll();
  1140. $sql = 'select tpl_index,tpl_data,paper_id from exam e join paper p on e.exam_id = p.exam_id where p.paper_id in ('.implode(',',$paperIds).')' ;
  1141. $tpl_index_res = $this->sConn->createCommand($sql)->queryAll();
  1142. $tpl_index_arr = array();
  1143. $tpl_data_arr = array();
  1144. foreach ($tpl_index_res as $v) {
  1145. $tpl_index_arr[$v['paper_id']] = $v['tpl_index'];
  1146. if($v['tpl_data']){
  1147. $tplData = json_decode($v['tpl_data'],true);
  1148. if($tplData){
  1149. $tplstatus = 0;
  1150. if(isset($tplData['tplstatus'])){
  1151. $tpl_data_arr[$v['paper_id']] = $tplData['tplstatus'];
  1152. }else{
  1153. $tpl_data_arr[$v['paper_id']] = 0;
  1154. }
  1155. }
  1156. }
  1157. }
  1158. $paper_topcic_relation_arr = array();
  1159. foreach ( $paper_topcic_relation_res as $v) {
  1160. $paper_id = $v['paper_id'];
  1161. $type = $v['type'];
  1162. $order = $v['order'];
  1163. $topic_id = $v['topic_id'];
  1164. if (!isset($paper_topcic_relation_arr[$paper_id])) {
  1165. $paper_topcic_relation_arr[$paper_id] = array();
  1166. }
  1167. $paper_topcic_relation_arr[$paper_id][] = array(
  1168. 'type' => $type,
  1169. 'order' => $order,
  1170. 'topic_id'=>$topic_id
  1171. );
  1172. }
  1173. $paper_topic_no_arr = array();
  1174. foreach ($paper_topcic_relation_arr as $paper_id => $paper_topic_relation) {
  1175. $tpl_index = $tpl_index_arr[$paper_id];
  1176. $tplstatus = isset($tpl_data_arr[$paper_id])?$tpl_data_arr[$paper_id]:0;
  1177. $paper_topic_no_arr[$paper_id] =$this->topic_number($paper_topic_relation,$tpl_index,$tplstatus);
  1178. }
  1179. return $paper_topic_no_arr;
  1180. }
  1181. function topic_number($paper_topcic_relation_arr, $tpl_index,$tplstatus)
  1182. {
  1183. $topic_no_arr = array(); //每道题的序号
  1184. if ($tpl_index == 10 || $tpl_index == 1010 || $tplstatus == 3 || $tplstatus == 4) { //10,1010 表示江苏那个有a,b,c,d选做题的模板,编号不能按表里的编号来
  1185. $prefix_no = 0;
  1186. $num = 0;
  1187. $index_arr = array('A','B','C','D','E');
  1188. $_order = 0;
  1189. foreach($paper_topcic_relation_arr as $v) {
  1190. if (!$prefix_no && $v['type'] == 17) {
  1191. $_order += 1; //序号加1
  1192. $prefix_no = $_order;
  1193. $topic_no_arr[$v['topic_id']] = $prefix_no.'A';
  1194. } elseif ($prefix_no && $v['type'] == 17) {
  1195. $num += 1;
  1196. $topic_no_arr[$v['topic_id']] = $prefix_no.$index_arr[$num];
  1197. }
  1198. if ($v['type'] == 27) {
  1199. $prefix_no += 1;
  1200. $topic_no_arr[$v['topic_id']] = $prefix_no;
  1201. }
  1202. if ($v['type'] != 17 && $v['type'] != 27){
  1203. $_order += 1;
  1204. $topic_no_arr[$v['topic_id']] = $_order;
  1205. }
  1206. }
  1207. } else { //其他模板都是根据order就行
  1208. $_order = 0;
  1209. foreach ($paper_topcic_relation_arr as $v) {
  1210. $_order += 1;
  1211. $topic_no_arr[$v['topic_id']] = $_order;
  1212. }
  1213. }
  1214. return $topic_no_arr;
  1215. }
  1216. private function topicProcess($html) {
  1217. if (preg_match_all('/(<img[^>]*[\s]+)((src)[\s]*=[\s]*(([\"]([^\"]*)[\"])|([\']([^\']*)[\'])|([^\s]*)))([^>]*>)/si', $html, $arr)) {
  1218. foreach ($arr[0] as $v) {
  1219. $process_str = $this->img_process($v);
  1220. ;
  1221. $html = str_replace($v, $process_str, $html);
  1222. }
  1223. }
  1224. $html = preg_replace('/style\s*=\s*(([\"]([^\"]*)[\"])|([\']([^\']*)[\']))/si', '', $html);
  1225. $html = preg_replace('/<p\s*>/', '', $html);
  1226. $html = preg_replace('/<\/p>/', '', $html);
  1227. $html = preg_replace('/<br\/*>/', '', $html);
  1228. $html = preg_replace('/<big\s*>/', '', $html);
  1229. $html = preg_replace('/<\/big>/', '', $html);
  1230. $html = str_replace("&nbsp;", '', $html);
  1231. return $html;
  1232. }
  1233. public function formatDetails($topicBatches) {
  1234. $optionIndex = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K');
  1235. $topicDetails = array();
  1236. foreach ($topicBatches AS $topic) {
  1237. $topic = (object) $topic;
  1238. $type = $topic->type_id;
  1239. 6 == $type && $type = 5; //6表示多空题,多空题也是5
  1240. $topicDetails[$topic->id] = array();
  1241. $topicDetails[$topic->id]['type'] = $type;
  1242. $topicDetails[$topic->id]['methods'] = ''; //考点
  1243. $topicDetails[$topic->id]['method_id_arr'] = ''; //考点id数组
  1244. $topicDetails[$topic->id]['kps'] = ''; //知识点
  1245. $topicDetails[$topic->id]['queBody'] = $this->topicProcess($topic->title); //题目详情
  1246. $topicDetails[$topic->id]['options'] = '';
  1247. $topicDetails[$topic->id]['parse_video_qrcode'] = isset($topic->parse_video_qrcode) ? $topic->parse_video_qrcode : '';
  1248. $topicDetails[$topic->id]['answer'] = ''; //每题的正确答案
  1249. $topicDetails[$topic->id]['analysis'] = $this->topicProcess($topic->parse_content); //答题解析
  1250. $topicDetails[$topic->id]['teacher_tips'] = $this->topicProcess($topic->teacher_tips); //名师点评
  1251. $topicDetails[$topic->id]['difficulty_degree'] = isset($topic->difficulty_degree) ? $topic->difficulty_degree : null;
  1252. $topicDetails[$topic->id]['difficulty'] = $topic->difficulty;
  1253. $_methods = array();
  1254. $_method_id_arr = array();
  1255. if ($topic->specials) {
  1256. foreach ($topic->specials AS $_method) {
  1257. $_method = (object) $_method;
  1258. if ($_method->method_name) {
  1259. $_methods[] = $_method->method_name;
  1260. }
  1261. if (isset($_method->method_id)) {
  1262. $_method_id_arr[] = $_method->method_id;
  1263. }
  1264. }
  1265. $topicDetails[$topic->id]['methods'] = implode('|', array_unique($_methods)); //考点
  1266. $topicDetails[$topic->id]['method_id_arr'] = $_method_id_arr;
  1267. }
  1268. $_kps = array();
  1269. if (isset($topic->kps) && $topic->kps) {
  1270. foreach ($topic->kps as $_kp) {
  1271. $_kp = (object) $_kp;
  1272. if ($_kp->kp_name) {
  1273. $_kps[$_kp->kp_id] = $_kp->kp_name;
  1274. }
  1275. }
  1276. $topicDetails[$topic->id]['kps'] = $_kps; //考点
  1277. }
  1278. if ($topic->type_id == 1) { //选择题有选项
  1279. if ($topic->items) {
  1280. if (isset($topic->items[0])) {
  1281. $topic->items[0] = (object) $topic->items[0];
  1282. if (isset($topic->items[0]->options)) {
  1283. $options = $topic->items[0]->options;
  1284. if ($options) {
  1285. $_tmp_options = array();
  1286. foreach ($options AS $_optionIndex => $_option) {
  1287. $_option = (object) $_option;
  1288. $_tmp_options[$_optionIndex] = $this->topicProcess($_option->option_content);
  1289. if ($_option->option_correct) {
  1290. $topicDetails[$topic->id]['answer'] = $this->topicProcess($optionIndex[$_optionIndex]);
  1291. }
  1292. }
  1293. $_list_type = (int) $topic->items[0]->list_type;
  1294. $topicDetails[$topic->id]['options'] = $this->option_process($_tmp_options, $_list_type);
  1295. }
  1296. }
  1297. }
  1298. }
  1299. } else {
  1300. if ($topic->items) {
  1301. if (isset($topic->items[0])) {
  1302. $topic->items[0] = (object) $topic->items[0];
  1303. if (isset($topic->items[0]->options)) {
  1304. $options = $topic->items[0]->options;
  1305. if ($options) {
  1306. $_answer = '';
  1307. foreach ($options as $v) {
  1308. $_option = (object) $v;
  1309. if (trim($_answer) != '') {
  1310. $_answer .= ' ; ';
  1311. }
  1312. $_answer .= $_option->option_content;
  1313. }
  1314. $topicDetails[$topic->id]['answer'] = $this->topicProcess($_answer);
  1315. }
  1316. }
  1317. }
  1318. }
  1319. }
  1320. }
  1321. return $topicDetails;
  1322. }
  1323. private function option_process($options, $list_type) {
  1324. $option_index = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
  1325. if ($list_type == 0) { //纵向排列,即1行1个
  1326. $option_str = "";
  1327. foreach ($options as $key => $option) {
  1328. $option_str.="<li class='fl lis-one'>$option_index[$key].$option</li>";
  1329. }
  1330. } elseif ($list_type == 1) { //横向排列,即1行4个
  1331. $option_str = "";
  1332. foreach ($options as $key => $option) {
  1333. $option_str.="<li class='fl lis-four'>$option_index[$key].$option</li>";
  1334. }
  1335. } elseif ($list_type == 2) { //1行2个
  1336. $option_str = "";
  1337. foreach ($options as $key => $option) {
  1338. if ($key % 2 == 0) {
  1339. $option1 = $options[$key];
  1340. $option_str2 = "<li class='fl lis-two'>$option_index[$key].$option1</li>";
  1341. $key1 = $key + 1;
  1342. if (isset($options[$key1])) {
  1343. $option2 = $options[$key1];
  1344. $option_str2.="<li class='fl lis-two'>$option_index[$key1].$option2</li>";
  1345. }
  1346. $option_str.=$option_str2;
  1347. } else {
  1348. continue;
  1349. }
  1350. }
  1351. }
  1352. return $option_str;
  1353. }
  1354. public function numToUpper($number)
  1355. {
  1356. $number = substr($number, 0, 2);
  1357. $arr = array('零', '一', '二', '三', '四', '五', '六', '七', '八', '九');
  1358. if (strlen($number) == 1) {
  1359. $result = $arr[$number];
  1360. } else {
  1361. if ($number == 10) {
  1362. $result = '十';
  1363. } else {
  1364. if ($number < 20) {
  1365. $result = '十';
  1366. } else {
  1367. $result = $arr[substr($number, 0, 1)] .'十';
  1368. }
  1369. if (substr($number, 1, 1) != '0') {
  1370. $result .= $arr[substr($number, 1, 1)];
  1371. }
  1372. }
  1373. }
  1374. return $result;
  1375. }
  1376. public function numToLetter($number)
  1377. {
  1378. $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');
  1379. $number = (int)$number;
  1380. $result = '';
  1381. if ($number >= 1 AND $number <= 26) {
  1382. $result = $letters[$number - 1];
  1383. }
  1384. return $result;
  1385. }
  1386. //远程路径,名称,文件后缀
  1387. function downImgRar($url,$rename,$name){
  1388. $ch = curl_init($url);
  1389. curl_setopt($ch, CURLOPT_HEADER, 0);
  1390. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1391. curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
  1392. $rawdata=curl_exec ($ch);
  1393. curl_close ($ch);
  1394. // 使用中文文件名需要转码
  1395. $fp = fopen($rename.$name.".pdf",'w');
  1396. fwrite($fp, $rawdata);
  1397. fclose($fp);
  1398. // 返回路径
  1399. return $rename.$name.".pdf";
  1400. }
  1401. //题类型掌握情况
  1402. private function getTopicTypeAnaly(&$stuRs,$topicScore,$topicNo,$paperId,$topicLogicType,$topicRelLarge,$smallTopicNo){
  1403. $result = array();
  1404. $getTopicTypeRelate = $this->getTopicTypeRelate();
  1405. $gradeRate = $classRate = array();//班级和年级得分率
  1406. $stuTypeWrong = array();//题型答错人数
  1407. $typeTopicNo = array();//题型对应的题号
  1408. $typeMasterDegree = array();//题型掌握水平
  1409. $typeName = $this->typeName;
  1410. $logicTypeName = $this->logicTypeName;
  1411. $gradeScoreArr = $classScoreArr = array();
  1412. $gradeScoring = $classScoring = array();
  1413. $_gradeScore = $_classScore= array();
  1414. $_gradeScoring = $_classScoring = array();
  1415. $typeNameArr = array();
  1416. $allClassScore = $allClassScoring = array();
  1417. $paperScoreSum = array();
  1418. //优化strcmp($paperId ,$value['paper_id']) == 0
  1419. $paperIndexArr = array();
  1420. foreach($stuRs as $stuId => $rs){
  1421. foreach($rs as $value){
  1422. $paperIndexArr[$value['paper_id']] = 0;
  1423. }
  1424. }
  1425. if ($paperIndexArr) {
  1426. $paperIndexArr = array_keys($paperIndexArr);
  1427. $paperIndexArr = array_flip($paperIndexArr);
  1428. }
  1429. //当前paper_id的索引
  1430. $curPaperIndex = isset($paperIndexArr[$paperId]) ? $paperIndexArr[$paperId] : false;
  1431. foreach($stuRs as $stuId => $rs){
  1432. foreach ($rs as $k => $value){
  1433. $tId = $value['topic_id'];
  1434. $t_score = isset($topicScore[$value['topic_id']])?$topicScore[$value['topic_id']]:0;
  1435. if(isset($topicLogicType[$value['topic_id']]) && $topicLogicType[$value['topic_id']] > 0){
  1436. $type = $topicLogicType[$value['topic_id']];
  1437. if ($this->subjectId == 9) {
  1438. $typeArr = explode('_',$type);
  1439. if(count($typeArr) > 1){
  1440. $type = $typeArr[0];
  1441. }
  1442. }
  1443. if($this->subjectId == 8){
  1444. if(isset($getTopicTypeRelate[$type])){
  1445. $type = $getTopicTypeRelate[$type];
  1446. }
  1447. }
  1448. $typeNameArr[$type] = isset($logicTypeName[$type])?$logicTypeName[$type]:'';
  1449. }else{
  1450. $type = $value['type'];
  1451. $typeNameArr[$type] = isset($typeName[$type])?$typeName[$type]:'';
  1452. }
  1453. if(!isset($gradeScoring[$type])){
  1454. $gradeScoring[$type] = array();
  1455. }
  1456. $gradeScoring[$type][] = $value['scoring'];
  1457. if(!isset($gradeScoreArr[$type])){
  1458. $gradeScoreArr[$type] = 0;
  1459. }
  1460. $gradeScoreArr[$type] += $t_score;
  1461. if(!isset($_gradeScoring[$tId])){
  1462. $_gradeScoring[$tId] = 0;
  1463. }
  1464. $_gradeScoring[$tId] += $value['scoring'];
  1465. if(!isset($_gradeScore[$tId])){
  1466. $_gradeScore[$tId] = 0;
  1467. }
  1468. $_gradeScore[$tId] += $t_score;
  1469. //当前班级
  1470. // if(strcmp($paperId ,$value['paper_id']) == 0){
  1471. if(isset($paperIndexArr[$value['paper_id']]) && $paperId !== false && $paperIndexArr[$value['paper_id']] == $curPaperIndex){
  1472. if(!isset($classScoring[$type])){
  1473. $classScoring[$type] = 0;
  1474. }
  1475. $classScoring[$type] += $value['scoring'];
  1476. if(!isset($classScoreArr[$type])){
  1477. $classScoreArr[$type] = 0;
  1478. }
  1479. $classScoreArr[$type] += $t_score;
  1480. if(!isset($stuTypeWrong[$type])){
  1481. $stuTypeWrong[$type] = array();
  1482. }
  1483. if(!isset($stuTypeWrong[$type][$stuId])){
  1484. $stuTypeWrong[$type][$stuId] = array(
  1485. 'scoring' => 0,
  1486. 'score' => 0,
  1487. );
  1488. }
  1489. $stuTypeWrong[$type][$stuId]['scoring'] += $value['scoring'];
  1490. $stuTypeWrong[$type][$stuId]['score'] += $t_score;
  1491. if(!isset($typeTopicNo[$type])){
  1492. $typeTopicNo[$type] = array();
  1493. }
  1494. //小题得分率
  1495. if(!isset($_classScoring[$tId])){
  1496. $_classScoring[$tId] = 0;
  1497. }
  1498. $_classScoring[$tId] += $value['scoring'];
  1499. if(!isset($_classScore[$tId])){
  1500. $_classScore[$tId] = 0;
  1501. }
  1502. $_classScore[$tId] += $t_score;
  1503. if(!isset($typeTopicNo[$type])){
  1504. $typeTopicNo[$type] = array();
  1505. }
  1506. // if(isset($topicNo[$value['topic_id']])){
  1507. // $typeTopicNo[$type][] = $topicNo[$value['topic_id']];
  1508. // }
  1509. }
  1510. //所以班级
  1511. $pId = $value['paper_id'];
  1512. if(!isset($allClassScoring[$pId])){
  1513. $allClassScoring[$pId] = array();
  1514. }
  1515. if(!isset($allClassScoring[$pId][$type])){
  1516. $allClassScoring[$pId][$type] = 0;
  1517. }
  1518. $allClassScoring[$pId][$type] += $value['scoring'];
  1519. if(!isset($allClassScore[$pId])){
  1520. $allClassScore[$pId] = array();
  1521. }
  1522. if(!isset($allClassScore[$pId][$type])){
  1523. $allClassScore[$pId][$type] = 0;
  1524. }
  1525. $allClassScore[$pId][$type] += $t_score;
  1526. if(!isset($paperScoreSum[$pId])){
  1527. $paperScoreSum[$pId] = 0;
  1528. }
  1529. $paperScoreSum[$pId] += $t_score;
  1530. }
  1531. }
  1532. //年级得分率
  1533. foreach($gradeScoring as $type => $scorings){
  1534. if(isset($gradeScoreArr[$type]) && $gradeScoreArr[$type]){
  1535. $gradeRate[$type] = round(array_sum($scorings)/$gradeScoreArr[$type],2) * 100;
  1536. }else{
  1537. $gradeRate[$type] = 0;
  1538. }
  1539. }
  1540. //班级得分率
  1541. foreach ($classScoring as $type => $scoring){
  1542. if(isset($classScoreArr[$type]) && $classScoreArr[$type] > 0){
  1543. $classRate[$type] = round($scoring/$classScoreArr[$type],2) * 100;
  1544. }else{
  1545. $classRate[$type] = 0;
  1546. }
  1547. }
  1548. //小题
  1549. //年级得分率
  1550. $_gradeRate = array();
  1551. foreach($_gradeScoring as $tId => $scoring){
  1552. if(isset($_gradeScore[$tId]) && $_gradeScore[$tId]){
  1553. $_gradeRate[$tId] = round($scoring/$_gradeScore[$tId],2) * 100;
  1554. }else{
  1555. $_gradeRate[$tId] = 0;
  1556. }
  1557. }
  1558. //班级得分率
  1559. $_classRate = array();
  1560. foreach ($_classScoring as $tId => $scoring){
  1561. if(isset($_classScore[$tId]) && $_classScore[$tId] > 0){
  1562. $_classRate[$tId] = round($scoring/$_classScore[$tId],2) * 100;
  1563. }else{
  1564. $_classRate[$tId] = 0;
  1565. }
  1566. }
  1567. //题型对应题号排序
  1568. foreach($typeTopicNo as $type => $nos){
  1569. asort($nos);
  1570. $typeTopicNo[$type] = array_unique($nos);
  1571. }
  1572. //题型掌握水平: 85%包括85%以上,5星;75%-85%,包括75%,4星。65%-75%,包括65%,3星;55%-65%,包括55%,2星;55%以下1星。
  1573. foreach($classRate as $type => $rate){
  1574. if($rate >= 85){
  1575. $typeMasterDegree[$type] = 5;
  1576. }elseif($rate < 85 && $rate >= 75){
  1577. $typeMasterDegree[$type] = 4;
  1578. }elseif($rate < 75 && $rate >= 65){
  1579. $typeMasterDegree[$type] = 3;
  1580. }elseif($rate < 65 && $rate >= 55){
  1581. $typeMasterDegree[$type] = 2;
  1582. }else{
  1583. $typeMasterDegree[$type] = 1;
  1584. }
  1585. }
  1586. //所有班级得分率
  1587. $allClassRate = array();
  1588. foreach ($allClassScoring as $pId => $scoringArr){
  1589. foreach ($scoringArr as $type => $scoring){
  1590. if(isset($allClassScore[$pId]) && isset($allClassScore[$pId][$type]) && $allClassScore[$pId][$type] > 0){
  1591. $allClassRate[$pId][$type] = round($scoring/$allClassScore[$pId][$type],4) * 100;
  1592. }else{
  1593. $allClassRate[$pId][$type] = 0;
  1594. }
  1595. }
  1596. }
  1597. //班级题型/试卷总分
  1598. $typePaperRate = array();
  1599. foreach ($allClassScoring as $pId => $scoringArr){
  1600. foreach ($scoringArr as $type => $scoring){
  1601. $paperScore = isset($paperScoreSum[$pId])?$paperScoreSum[$pId]:0;
  1602. if($paperScore > 0){
  1603. $typePaperRate[$pId][$type] = round($scoring/$paperScore,4) * 100;
  1604. }else{
  1605. $typePaperRate[$pId][$type] = 0;
  1606. }
  1607. }
  1608. }
  1609. //题型答错人数
  1610. foreach ($stuTypeWrong as $type => $stuScore){
  1611. $wrongNum = 0;
  1612. foreach ($stuScore as $stuId => $score){
  1613. if($score['score'] != $score['scoring']){
  1614. $wrongNum++;
  1615. }
  1616. }
  1617. $stuTypeWrong[$type] = $wrongNum;
  1618. }
  1619. $result['class_rate'] = $classRate;
  1620. $result['grade_rate'] = $gradeRate;
  1621. $result['all_class_rate'] = $allClassRate;
  1622. $result['type_paper_rate'] = $typePaperRate;
  1623. $result['stu_type_wrong'] = $stuTypeWrong;
  1624. $result['type_topic_no'] = $typeTopicNo;
  1625. $result['type_master_degree'] = $typeMasterDegree;
  1626. $result['type_name_arr'] = $typeNameArr;
  1627. $result['topic_grade_rate'] = $_gradeRate;
  1628. $result['topic_class_rate'] = $_classRate;
  1629. return $result;
  1630. }
  1631. //共性问题变式训练
  1632. protected function getCommonPractice($paper_topic_detail,$stu_score_info,$stu_topic_rs,$large_topic_type_arr,$large_contain){
  1633. $class_wrong_topic = array();
  1634. $cls_grammar_topic = array();
  1635. $texturl_topic = array();
  1636. $common_push_topic = array();
  1637. $topic_method_arr = array();
  1638. $_push_all_topics = array();
  1639. $paper_topics = array_keys($large_topic_type_arr);
  1640. foreach($paper_topic_detail as $topic_id=>$detail){
  1641. if(in_array($detail['type_id'],array(2,3,4,5,6,7,18,19))){
  1642. $topic_method_arr[$topic_id] = isset($detail['specials']) ? _array_column($detail['specials'],'method_id') : array();
  1643. if(isset($detail['slave'])){
  1644. foreach($detail['slave'] as $slave){
  1645. if(isset($slave['topic_slave_id'])){
  1646. $topic_method_arr[$slave['topic_slave_id']] = isset($slave['method_names']) ? _array_column($slave['method_names'],'method_id') : array();
  1647. }
  1648. }
  1649. }
  1650. }
  1651. }
  1652. foreach($stu_score_info as $stu_id=>$score_info){
  1653. foreach($score_info as $large_topic_id=>$scoring){
  1654. if(isset($large_topic_type_arr[$large_topic_id])){
  1655. if(in_array($large_topic_type_arr[$large_topic_id],array(2,3,4,5))){
  1656. if(!isset($class_wrong_topic[$large_topic_id])){
  1657. $class_wrong_topic[$large_topic_id] = array('scoring'=>0,'score'=>0);
  1658. }
  1659. $_scoring = $class_wrong_topic[$large_topic_id]['scoring'];
  1660. $_score = $class_wrong_topic[$large_topic_id]['score'];
  1661. $class_wrong_topic[$large_topic_id] = array('scoring'=>($scoring['scoring']+$_scoring),'score'=>($scoring['score']+$_score));
  1662. }elseif(in_array($large_topic_type_arr[$large_topic_id],array(18,19))){
  1663. $small_topic = $large_contain[$large_topic_id];
  1664. $stu_topic_info = isset($stu_topic_rs[$stu_id]) ? $stu_topic_rs[$stu_id] : array();
  1665. if($stu_topic_info){
  1666. foreach($small_topic as $small_topic_id=>$score){
  1667. if(!isset($cls_grammar_topic[$large_topic_type_arr[$large_topic_id]][$small_topic_id])){
  1668. $cls_grammar_topic[$large_topic_type_arr[$large_topic_id]][$small_topic_id] = array('scoring'=>0,'score'=>0);
  1669. }
  1670. $stu_scoring = $stu_topic_info[$small_topic_id];
  1671. $_scoring = $cls_grammar_topic[$large_topic_type_arr[$large_topic_id]][$small_topic_id]['scoring'];
  1672. $_score = $cls_grammar_topic[$large_topic_type_arr[$large_topic_id]][$small_topic_id]['score'];
  1673. $cls_grammar_topic[$large_topic_type_arr[$large_topic_id]][$small_topic_id] = array('scoring'=>($stu_scoring['scoring']+$_scoring),'score'=>($score+$_score));
  1674. }
  1675. }
  1676. }elseif(in_array($large_topic_type_arr[$large_topic_id],array(6,7))){
  1677. $texturl_topic[] = $large_topic_id;
  1678. }
  1679. }
  1680. }
  1681. }
  1682. $class_score_rate = array();
  1683. foreach($class_wrong_topic as $large_topic_id=>$score_info){
  1684. $score_rate = $this->scoreRate($score_info['scoring'],$score_info['score']);
  1685. $class_score_rate[$large_topic_id] = $score_rate;
  1686. }
  1687. if ($class_score_rate) {
  1688. asort($class_score_rate);
  1689. reset($class_score_rate);
  1690. $push_text_topic = key($class_score_rate);
  1691. $text_detail = $paper_topic_detail[$push_text_topic];
  1692. $kps = _array_column($text_detail['specials'],'method_id');
  1693. $text_level = isset($text_detail['text_level']) ? $text_detail['text_level'] : 5;
  1694. $cloze_type = 0;
  1695. if ($text_detail['type_id'] == 2) {
  1696. $cloze_type = count($text_detail['slave']) == 15 ? 1 : 2;
  1697. }
  1698. $rules = array();
  1699. $rules[] = array(
  1700. 'type' => $text_detail['type_id'],
  1701. 'size' => 600,
  1702. 'cloze_type' => $cloze_type
  1703. );
  1704. $params_eng = array();
  1705. $params_eng['subjectId'] = 10;
  1706. $params_eng['rules'] = $rules;
  1707. $params_eng['inMethodIds'] = $kps;
  1708. $params_eng['isAudit'] = 2;
  1709. $params_eng['notInTopicIds'] = $paper_topics;
  1710. $type_topic_arr = $this->apiBrainPost('/relation_english/extract', $params_eng,25,true);
  1711. if(isset($type_topic_arr[$text_detail['type_id']])){
  1712. $all_topic = array();
  1713. $extract_topics = $type_topic_arr[$text_detail['type_id']];
  1714. while($text_level>0){
  1715. if ($extract_topics[$text_level]) {
  1716. $all_topic = $extract_topics[$text_level];
  1717. break;
  1718. }
  1719. $text_level--;
  1720. }
  1721. if($all_topic){
  1722. $push_topic_key = array_rand($all_topic,1);
  1723. $common_push_topic['min_rate_text'][$text_detail['type_id']] = array('topic_id'=>$all_topic[$push_topic_key],'topic_type'=>$text_detail['type_id']);
  1724. $_push_all_topics[$all_topic[$push_topic_key]] = $all_topic[$push_topic_key];
  1725. }
  1726. }
  1727. }
  1728. $grammar_rules = array();
  1729. //班级错误率在50%及以上的
  1730. $grammar_score_rate = array();
  1731. $grammar_method = array();
  1732. foreach($cls_grammar_topic as $type=>$cgt_info){
  1733. foreach($cgt_info as $small_topic_id=>$score_info){
  1734. $score_rate = $this->scoreRate($score_info['scoring'],$score_info['score'],true);
  1735. if($score_rate<50){
  1736. $grammar_score_rate[$type][$small_topic_id] = isset($topic_method_arr[$small_topic_id]) ? $topic_method_arr[$small_topic_id] : array();
  1737. }
  1738. }
  1739. }
  1740. $topic_count = array('19'=>10,'18'=>0);
  1741. foreach($grammar_score_rate as $type=>$gsr){
  1742. if($type == 6 || $type == 19){
  1743. $type = 19;
  1744. }
  1745. $grammar_rules[$type] = array(
  1746. 'type' => 19,
  1747. 'size' => 600
  1748. );
  1749. if(!isset($grammar_method[$type])){
  1750. $grammar_method[$type] = array();
  1751. }
  1752. foreach($gsr as $item){
  1753. if($type == 18){
  1754. $topic_count[18] ++;
  1755. }
  1756. $grammar_method[$type] = array_merge($grammar_method[$type],$item);
  1757. }
  1758. }
  1759. //$read_base_obj = new ReadBase();
  1760. foreach($grammar_rules as $type=>$gr){
  1761. $rules = array();
  1762. $rules[] = array(
  1763. 'type' => $type,
  1764. 'size' => 600
  1765. );
  1766. $params_eng = array();
  1767. $params_eng['subjectId'] = 10;
  1768. $params_eng['rules'] = $rules;
  1769. $params_eng['inMethodIds'] = isset($grammar_method[$type]) ? $grammar_method[$type] : array();
  1770. $params_eng['notInTopicIds'] = $paper_topics;
  1771. $type_topic_arr = $this->apiBrainPost('/relation_english/extract', $params_eng,25,true);
  1772. if($type_topic_arr){
  1773. if(isset($type_topic_arr[$type]) && $type_topic_arr[$type]){
  1774. $topics = reset($type_topic_arr[$type]);
  1775. $push_topic_key = array_rand($topics,$topic_count[$type]);
  1776. foreach($push_topic_key as $key){
  1777. $_push_all_topics[$topics[$key]] = $topics[$key];
  1778. $common_push_topic['common_grammar_topic'][$type][] = array('topic_id'=>$topics[$key],'topic_type'=>$type);
  1779. }
  1780. }
  1781. }
  1782. }
  1783. $texturl_topic = array_unique($texturl_topic);
  1784. foreach($texturl_topic as $t_id){
  1785. $rules = array();
  1786. $rules[] = array(
  1787. 'type' => $paper_topic_detail[$t_id]['type_id'],
  1788. 'size' => 600
  1789. );
  1790. $params_eng = array();
  1791. $params_eng['subjectId'] = 10;
  1792. $params_eng['rules'] = $rules;
  1793. $params_eng['inMethodIds'] = isset($topic_method_arr[$t_id]) ? $topic_method_arr[$t_id] : array();
  1794. $params_eng['notInTopicIds'] = $paper_topics;
  1795. $type_topic_arr = $this->apiBrainPost('/relation_english/extract', $params_eng,25,true);
  1796. if($type_topic_arr){
  1797. if(isset($type_topic_arr[$paper_topic_detail[$t_id]['type_id']]) && $type_topic_arr[$paper_topic_detail[$t_id]['type_id']]){
  1798. $topics = reset($type_topic_arr[$paper_topic_detail[$t_id]['type_id']]);
  1799. if($topics){
  1800. $push_topic_key = array_rand($topics,1);
  1801. $_push_all_topics[$topics[$push_topic_key]] = $topics[$push_topic_key];
  1802. $common_push_topic['common_extra'][$paper_topic_detail[$t_id]['type_id']] = array('topic_id'=>$topics[$push_topic_key],'topic_type'=>$paper_topic_detail[$t_id]['type_id']);
  1803. }
  1804. }
  1805. }
  1806. }
  1807. return array($common_push_topic,$_push_all_topics);
  1808. }
  1809. /**
  1810. * 班级排名得分率人数等数据
  1811. * @param $examId
  1812. * @param $ptrInfo
  1813. * @param $paperScore
  1814. * @param $preExamId
  1815. * @param $prePtrInfo
  1816. * @param $prePaperScore
  1817. * @return array
  1818. */
  1819. private function getClassAnalyse($examId,&$ptrInfo,$paperScore,$preExamId,&$prePtrInfo,$prePaperScore,&$stuIdsArr,&$preStuIdsArr){
  1820. $result = array();
  1821. $gradePerson = $classPerson = 0;//参考人数
  1822. $gradeAbsentPerson = $classAbsentPerson = 0;//缺考人数
  1823. $gradeOrder = $classOrder = 0; //排名
  1824. $gradeAvgScore = $classAvgScore = 0; //平均分
  1825. $gradeScoreRate = $classScoreRate = 0; //得分率
  1826. $gradeFineRate = $classFineRate = 0; //优秀率 80%
  1827. $gradePassRate = $classPassRate = 0; //合格率 60%
  1828. $gradeLowRate = $classLowRate = 0; //低分率 30%
  1829. $angData = array(
  1830. 'class_num' => 0,//班级数量
  1831. 'order' => 0,
  1832. 'absent_person' => 0,
  1833. 'exam_person' => 0,
  1834. 'avg_score' => 0,
  1835. 'score_rate' => 0,
  1836. 'fine_rate' => 0,
  1837. 'pass_rate' => 0,
  1838. 'low_rate' => 0,
  1839. );
  1840. $result['grade'] = $result['class'] = $angData;
  1841. $gradeScoring = $classScoring = array();
  1842. $gradeScoringSum = array();//年级中每个考试的得分和
  1843. // $classScoringSum = 0;//考试得分和
  1844. $gradeStuScoringRate = $classStuScoringRate = array();//学生得分率
  1845. foreach($ptrInfo as $value){
  1846. $stuIds = isset($stuIdsArr[$value['exam_id']])?$stuIdsArr[$value['exam_id']]:array();
  1847. if(!isset($gradeScoringSum[$value['exam_id']])){
  1848. $gradeScoringSum[$value['exam_id']] = 0;
  1849. }
  1850. if(inArray($value['student_id'],$stuIds)){
  1851. $gradeScoringSum[$value['exam_id']] += $value['scoring'];
  1852. $gradeScoring[] = $value['scoring'];
  1853. $gradeStuScoringRate[] = round($value['scoring']/$paperScore,4)*100;
  1854. $gradePerson++;
  1855. }
  1856. if(!inArray($value['student_id'],$stuIds)){
  1857. $gradeAbsentPerson++;
  1858. }
  1859. // if($examId == $value['exam_id']){
  1860. if(strcmp($examId ,$value['exam_id']) == 0){
  1861. if(inArray($value['student_id'],$stuIds)){
  1862. // $classScoringSum += $value['scoring'];
  1863. $classScoring[] = $value['scoring'];
  1864. $classStuScoringRate[] = round($value['scoring']/$paperScore,4)*100;
  1865. $classPerson++;
  1866. }
  1867. if(!inArray($value['student_id'],$stuIds)){
  1868. $classAbsentPerson++;
  1869. }
  1870. }
  1871. }
  1872. unset($ptrInfo);
  1873. $result['class']['class_num'] = count($gradeScoringSum);
  1874. $result['grade']['exam_person'] = $gradePerson;
  1875. $result['grade']['absent_person'] = $gradeAbsentPerson;
  1876. $result['class']['exam_person'] = $classPerson;
  1877. $result['class']['absent_person'] = $classAbsentPerson;
  1878. //排名
  1879. if($gradeScoringSum){
  1880. $scoringArr = array();
  1881. foreach($gradeScoringSum as $eId => $scoring){
  1882. $stuCount = isset($stuIdsArr[$eId])?count($stuIdsArr[$eId]):0;
  1883. if($stuCount){
  1884. $scoringArr[$eId] = round($scoring/$stuCount,2);
  1885. }
  1886. }
  1887. if(isset($scoringArr[$examId])){
  1888. $classOrder = $this->getOrder($scoringArr[$examId],$scoringArr);
  1889. }else{
  1890. $classOrder = 0;
  1891. }
  1892. }
  1893. $result['class']['order'] = $classOrder;
  1894. //平均分,得分率
  1895. $count = count($gradeScoring);
  1896. if($count > 0){
  1897. $gradeAvgScore = round(array_sum($gradeScoring)/$count,2);//平均分
  1898. $gradeScoreRate = round(array_sum($gradeScoring)/($paperScore*$count),4)*100;//得分率
  1899. }else{
  1900. $gradeAvgScore = 0;
  1901. $gradeScoreRate = 0;
  1902. }
  1903. $result['grade']['avg_score'] = $gradeAvgScore;
  1904. $result['grade']['score_rate'] = $gradeScoreRate;
  1905. $count = count($classScoring);
  1906. if($count > 0){
  1907. $classAvgScore = round(array_sum($classScoring)/$count,2);
  1908. $classScoreRate = round(array_sum($classScoring)/($paperScore*$count),4)*100;//得分率
  1909. }else{
  1910. $classAvgScore = 0;
  1911. $classScoreRate = 0;
  1912. }
  1913. $result['class']['avg_score'] = $classAvgScore;
  1914. $result['class']['score_rate'] = $classScoreRate;
  1915. //优秀率,合格率,低分率
  1916. // $gradeFineRate = $classFineRate = 0; //优秀率 85%
  1917. // $gradePassRate = $classPassRate = 0; //合格率 60%
  1918. // $gradeLowRate = $classLowRate = 0; //低分率 30%
  1919. $tempFineNum = $tempPassNum = $tempLowNum = 0;
  1920. $rateCount = count($gradeStuScoringRate);
  1921. foreach($gradeStuScoringRate as $scoringRate){
  1922. if($scoringRate >= 85){
  1923. $tempFineNum++;
  1924. }
  1925. if($scoringRate >= 60){
  1926. $tempPassNum++;
  1927. }
  1928. if($scoringRate <= 30){
  1929. $tempLowNum++;
  1930. }
  1931. }
  1932. $gradeFineRate = round($tempFineNum/$rateCount,4) * 100;
  1933. $gradePassRate = round($tempPassNum/$rateCount,4) * 100;
  1934. $gradeLowRate = round($tempLowNum/$rateCount,4) * 100;
  1935. $result['grade']['fine_rate'] = $gradeFineRate;
  1936. $result['grade']['pass_rate'] = $gradePassRate;
  1937. $result['grade']['low_rate'] = $gradeLowRate;
  1938. $tempFineNum = $tempPassNum = $tempLowNum = 0;
  1939. $rateCount = count($classStuScoringRate);
  1940. foreach($classStuScoringRate as $scoringRate){
  1941. if($scoringRate >= 85){
  1942. $tempFineNum++;
  1943. }
  1944. if($scoringRate >= 60){
  1945. $tempPassNum++;
  1946. }
  1947. if($scoringRate <= 30){
  1948. $tempLowNum++;
  1949. }
  1950. }
  1951. if($rateCount){
  1952. $classFineRate = round($tempFineNum/$rateCount,4) * 100;
  1953. $classPassRate = round($tempPassNum/$rateCount,4) * 100;
  1954. $classLowRate = round($tempLowNum/$rateCount,4) * 100;
  1955. }else{
  1956. $classFineRate = 0;
  1957. $classPassRate = 0;
  1958. $classLowRate = 0;
  1959. }
  1960. $result['class']['fine_rate'] = $classFineRate;
  1961. $result['class']['pass_rate'] = $classPassRate;
  1962. $result['class']['low_rate'] = $classLowRate;
  1963. /**************** 提升数据 ******************/
  1964. $result['class']['order_increase'] = 0;
  1965. $result['class']['rate_increase'] = 0;
  1966. $result['class']['fine_rate_increase'] = 0;
  1967. if($prePtrInfo){
  1968. $preClassStuScoringRate = array();
  1969. $preGradeScoringSum = array();
  1970. $preClassScoringSum = 0;
  1971. $preClassScoring = array();
  1972. if($prePtrInfo){
  1973. foreach($prePtrInfo as $value){
  1974. $stuIds = isset($preStuIdsArr[$value['exam_id']])?$preStuIdsArr[$value['exam_id']]:array();
  1975. if(!isset($preGradeScoringSum[$value['exam_id']])){
  1976. $preGradeScoringSum[$value['exam_id']] = 0;
  1977. }
  1978. if(inArray($value['student_id'],$stuIds)){
  1979. $preGradeScoringSum[$value['exam_id']] += $value['scoring'];
  1980. }
  1981. // if($preExamId == $value['exam_id']){
  1982. if(strcmp($preExamId ,$value['exam_id']) == 0){
  1983. if(inArray($value['student_id'],$stuIds)){
  1984. $preClassScoringSum += $value['scoring'];
  1985. $preClassScoring[] = $value['scoring'];
  1986. $preClassStuScoringRate[] = round($value['scoring']/$prePaperScore,4)*100;
  1987. }
  1988. }
  1989. }
  1990. }
  1991. //上一次考试排名
  1992. if($gradeScoringSum){
  1993. $scoringArr = array();
  1994. foreach($preGradeScoringSum as $eId => $scoring){
  1995. $stuCount = isset($preStuIdsArr[$eId])?count($preStuIdsArr[$eId]):0;
  1996. if($stuCount){
  1997. $scoringArr[$eId] = round($scoring/$stuCount,2);
  1998. }
  1999. }
  2000. if(isset($scoringArr[$preExamId])){
  2001. $preClassOrder = $this->getOrder($scoringArr[$preExamId],$scoringArr);
  2002. }else{
  2003. $preClassOrder = 0;
  2004. }
  2005. $result['class']['order_increase'] = -($classOrder - $preClassOrder);
  2006. }
  2007. $count = count($preClassScoring);
  2008. if($count > 0){
  2009. $preClassScoreRate = round(array_sum($preClassScoring)/($prePaperScore*$count),4)*100;//得分率
  2010. $result['class']['rate_increase'] = $classScoreRate - $preClassScoreRate;
  2011. }
  2012. $tempFineNum = 0;
  2013. $rateCount = count($preClassStuScoringRate);
  2014. foreach($preClassStuScoringRate as $scoringRate){
  2015. if($scoringRate >= 85){
  2016. $tempFineNum++;
  2017. }
  2018. }
  2019. if($rateCount){
  2020. $preClassFineRate = round($tempFineNum/$rateCount,4) * 100;
  2021. }else{
  2022. $preClassFineRate = 0;
  2023. }
  2024. $result['class']['fine_rate_increase'] = $classFineRate - $preClassFineRate;
  2025. }
  2026. return $result;
  2027. }
  2028. /**
  2029. * 大幅进步,大幅退步,前5名和后5名
  2030. * @param $examId
  2031. * @param $ptrInfo
  2032. * @param $paperScore
  2033. * @param $preExamId
  2034. * @param $prePtrInfo
  2035. * @param $prePaperScore
  2036. */
  2037. private function getLargeOrder($examId,&$ptrInfo,$preExamId,&$prePtrInfo,&$stuIdsArr,&$preStuIdsArr){
  2038. $result = array();
  2039. $stuOrderArr = $this->getStudentOrder($examId,$ptrInfo,$stuIdsArr);
  2040. $diffNum = ceil(count($stuOrderArr)*0.2);
  2041. if($prePtrInfo){
  2042. $preStuOrderArr = $this->getStudentOrder($preExamId,$prePtrInfo,$preStuIdsArr);
  2043. }else{
  2044. $preStuOrderArr = array();
  2045. }
  2046. if($preStuOrderArr){
  2047. $interOrderArr = array_intersect_key($stuOrderArr,$preStuOrderArr);
  2048. if(!$interOrderArr){
  2049. $interOrderArr = $stuOrderArr;
  2050. }
  2051. }else{
  2052. $interOrderArr = array();
  2053. }
  2054. //大幅进步,退步
  2055. $increaseArr = $reduceArr = array();
  2056. $stuDiffOrder = array();
  2057. if($interOrderArr){
  2058. foreach($stuOrderArr as $stuId => $order){
  2059. if(isset($interOrderArr[$stuId]) && isset($preStuOrderArr[$stuId])){
  2060. $stuDiffOrder[$stuId] = -($order - $preStuOrderArr[$stuId]);
  2061. }else{
  2062. $stuDiffOrder[$stuId] = 0;
  2063. }
  2064. }
  2065. arsort($stuDiffOrder);
  2066. foreach($stuDiffOrder as $stuId => $num){
  2067. if($num >= $diffNum){
  2068. $increaseArr[] = $stuId;
  2069. }
  2070. }
  2071. $increaseArr = array_slice($increaseArr,0,5,true);
  2072. asort($stuDiffOrder);
  2073. foreach($stuDiffOrder as $stuId => $num){
  2074. if($num <= -$diffNum){
  2075. $reduceArr[] = $stuId;
  2076. }
  2077. }
  2078. $reduceArr = array_slice($reduceArr,0,5,true);
  2079. }else{
  2080. $increaseArr = array_slice($stuOrderArr,0,5,true);
  2081. $reduceArr = array();
  2082. }
  2083. $result['stu_diff_order'] = $stuDiffOrder;
  2084. $result['stu_order'] = $stuOrderArr;
  2085. $result['increase_stu'] = $increaseArr;
  2086. $result['reduce_stu'] = $reduceArr;
  2087. //前5名和后5名
  2088. $font5 = $back5 = array();
  2089. $i = 1;
  2090. $fonrt5_order = array();
  2091. foreach($stuOrderArr as $stuId => $order){
  2092. if($i <= 5){
  2093. $font5[] = $stuId;
  2094. $fonrt5_order[] = $order;
  2095. }else{
  2096. break;
  2097. }
  2098. $i++;
  2099. }
  2100. $result['font_five'] = $font5;
  2101. $i = 1;
  2102. //删除前5排名
  2103. $_stuOrderArr = $stuOrderArr;
  2104. foreach($_stuOrderArr as $k => $order){
  2105. if(in_array($order,$fonrt5_order)){
  2106. unset($_stuOrderArr[$k]);
  2107. }
  2108. }
  2109. arsort($_stuOrderArr);
  2110. foreach($_stuOrderArr as $stuId => $order){
  2111. if($i <= 5){
  2112. $back5[] = $stuId;
  2113. }else{
  2114. break;
  2115. }
  2116. $i++;
  2117. }
  2118. $result['back_five'] = $back5;
  2119. //学生名称
  2120. $stuName = $this->getStudentNames(array_keys($stuOrderArr));
  2121. $result['stu_name'] = $stuName;
  2122. unset($stuOrderArr);
  2123. return $result;
  2124. }
  2125. function getStudentNames($studentIds){
  2126. $result = array();
  2127. $students = $this->sConn->createCommand("select student_id,realname,id_number from student_info where student_id in(".implode(',',$studentIds).") ")->queryAll();
  2128. if ($students)
  2129. {
  2130. foreach ($students AS $student)
  2131. {
  2132. $id_str = '';
  2133. if($student['id_number']){
  2134. $id_str = substr($student['id_number'],-4,4);
  2135. }
  2136. $result[$student['student_id']] = $student['realname'].$id_str;
  2137. }
  2138. }
  2139. return $result;
  2140. }
  2141. /**
  2142. * 调题的接口
  2143. * @param $path
  2144. * @param $arr
  2145. * @param int $type
  2146. * @return bool|mixed
  2147. */
  2148. public function apiBrainPost($path, $arr, $timeout=25,$is_array = false)
  2149. {
  2150. $ch = @curl_init();
  2151. $result = FALSE;
  2152. if ($ch)
  2153. {
  2154. $data = json_encode($arr);
  2155. $url = Yii::app()->params['api'][0]['prefix'] . $path;
  2156. $username = Yii::app()->params['api'][0]['username'];
  2157. $password = Yii::app()->params['api'][0]['password'];
  2158. curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  2159. curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
  2160. // 不输出头部
  2161. curl_setopt($ch, CURLOPT_HEADER, 0);
  2162. // curl_exec 获取到的内容不直接输出, 而是返回
  2163. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  2164. curl_setopt($ch, CURLOPT_TIMEOUT,$timeout);
  2165. // 请求重启路由器的地址 传参 进行重启
  2166. curl_setopt($ch, CURLOPT_URL, $url);
  2167. curl_setopt($ch, CURLOPT_USERAGENT, 'Api Client/1.0.0 (chengfei@liancaitech.com)');
  2168. curl_setopt($ch, CURLOPT_POST, 1);
  2169. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  2170. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  2171. 'Content-Type: application/json',
  2172. 'Content-Length: '. strlen($data),
  2173. ));
  2174. if( !curl_errno($ch))
  2175. {
  2176. $result = json_decode(curl_exec($ch),$is_array);
  2177. }
  2178. // 释放资源
  2179. curl_close($ch);
  2180. }
  2181. return $result;
  2182. }
  2183. /**
  2184. * 获取学生排名
  2185. * @param $examId
  2186. * @param $ptrInfo
  2187. * @return array
  2188. */
  2189. private function getStudentOrder($examId,&$ptrInfo,&$stuIdsArr){
  2190. $stuOrderArr = array();
  2191. $stuScoring = array();
  2192. foreach($ptrInfo as $value){
  2193. // if($examId == $value['exam_id']){
  2194. if(strcmp($examId ,$value['exam_id']) == 0){
  2195. $stuIds = isset($stuIdsArr[$value['exam_id']])?$stuIdsArr[$value['exam_id']]:array();
  2196. if(inArray($value['student_id'],$stuIds)){
  2197. $stuScoring[$value['student_id']] = $value['scoring'];
  2198. }
  2199. }
  2200. }
  2201. $scoringArr = array_values($stuScoring);
  2202. foreach($stuScoring as $stuId => $scoring){
  2203. $stuOrderArr[$stuId] = $this->getOrder($scoring,$scoringArr);
  2204. }
  2205. if($stuOrderArr){
  2206. asort($stuOrderArr);
  2207. }
  2208. return $stuOrderArr;
  2209. }
  2210. /**
  2211. * 获取排名
  2212. * @param $ele
  2213. * @param $arr
  2214. * @return false|int|string
  2215. */
  2216. private function getOrder($ele,$arr){
  2217. $orderRs = 0;
  2218. if($arr){
  2219. arsort($arr);
  2220. $arr = array_values($arr);
  2221. $index = array_search($ele,$arr);
  2222. $orderRs = $index + 1;
  2223. }
  2224. return $orderRs;
  2225. }
  2226. //替换序号
  2227. private function replaceTitle(&$title,$topicId,$topicRelLarge,$smallTopicNo)
  2228. {
  2229. // $str = '<img src="http://zsytk2.zhixinhuixue.com/static/images/4.gif" _src="http://zsytk2.zhixinhuixue.com/static/images/4.gif" class="tiankong" data-num="3">';
  2230. $topicNoArr = array();
  2231. foreach ($topicRelLarge as $small_id => $large_id) {
  2232. if ($topicId == $large_id && isset($smallTopicNo[$small_id])) {
  2233. $topicNoArr[] = $smallTopicNo[$small_id];
  2234. }
  2235. }
  2236. $imgArr = array();
  2237. $pattern="/<img[\s\S]*?src\s*=\s*[\"|\'](.*?)[\"|\'][\s\S]*?>/";
  2238. preg_match_all($pattern,$title,$match);
  2239. if (isset($match[0]) && $match[0]) {
  2240. foreach ($match[0] as $img) {
  2241. $pattern="/data-num=[\"|\'](\d{0,2})[\"|\']/";
  2242. preg_match_all($pattern,$img,$match);
  2243. if (isset($match[0]) && isset($match[1]) && isset($match[1][0])) {
  2244. $imgArr[$match[1][0]] = $img;
  2245. }
  2246. }
  2247. }
  2248. if (count($imgArr) == count($topicNoArr)) {
  2249. asort($topicNoArr);
  2250. $searchArr = $replaceArr = array();
  2251. foreach ($topicNoArr as $key => $no) {
  2252. $searchArr[] = isset($imgArr[$key]) ? $imgArr[$key] : '';
  2253. $replaceArr[] = ' ('.$no.') ';
  2254. }
  2255. $title = str_replace($searchArr, $replaceArr, $title);
  2256. }
  2257. }
  2258. //获取词汇
  2259. private function getWord($condition){
  2260. $wordsInfo = array();
  2261. // $params = array(
  2262. // '_id' => array('$in' => array_values($word_ids))
  2263. // );
  2264. //
  2265. // return IspMongo::selectMongo('english_single',$params);
  2266. $rs = $this->apiBrainPost('/zsytk2/getIspInfo', array('condition'=>$condition,'table' => 'en_single_word' ,'isAll' => 1),25,true);
  2267. if (isset($rs['status']) && $rs['status']==1 && isset($rs['data']) && $rs['data']) {
  2268. foreach ($rs['data'] as $v) {
  2269. $wordsInfo[$v['single_word_id']] = $v;
  2270. }
  2271. }
  2272. return $wordsInfo;
  2273. }
  2274. public function getExamIsTird($examGroupId,$examId){
  2275. if(!$examGroupId){
  2276. if($examId){
  2277. $_sql = "SELECT exam_group_id FROM exam where exam_id = ".$examId;
  2278. $exam_info = $this->sConn->createCommand($_sql)->queryRow();
  2279. if(isset($exam_info['exam_group_id']) && $exam_info['exam_group_id']){
  2280. $examGroupId = $exam_info['exam_group_id'];
  2281. }
  2282. }
  2283. }
  2284. $sql="SELECT `is_third` FROM `exam_group` WHERE exam_group_id = {$examGroupId}" ;
  2285. $res = $this->sConn->createCommand($sql)->queryRow();
  2286. if($res && isset($res['is_third'])){
  2287. return $res['is_third']?1:0;
  2288. }else{
  2289. return false;
  2290. }
  2291. }
  2292. public function getHasScoreStu($examIds){
  2293. $studentIds = array();
  2294. $sql = "select student_id,exam_id from student_paper_topic_rs as sptr join paper as p on sptr.paper_id = p.paper_id where p.exam_id in (".implode(',',$examIds).") and handlerIndex = 1";
  2295. $info = $this->sConn->createCommand($sql)->queryAll();
  2296. if($info){
  2297. foreach($info as $value){
  2298. if(!isset($studentIds[$value['exam_id']])){
  2299. $studentIds[$value['exam_id']] = array();
  2300. }
  2301. $studentIds[$value['exam_id']][$value['student_id']] = $value['student_id'];
  2302. }
  2303. foreach($studentIds as $eId => $stuIds){
  2304. $studentIds[$eId] = array_keys($stuIds);
  2305. }
  2306. unset($info);
  2307. }
  2308. return $studentIds;
  2309. }
  2310. /**
  2311. * 获取试卷题信息
  2312. * @param $examIds
  2313. * @return array|CDbDataReader
  2314. */
  2315. public function getStudentExamInfo($examIds){
  2316. $info = array();
  2317. if($examIds){
  2318. $sql = "select student_id,is_del,paper_id,exam_id,scoring,is_feedback,is_three_isp_download,is_two_isp_download from student_paper_relation where exam_id in (".implode(',',$examIds).") ";
  2319. $info = $this->sConn->createCommand($sql)->queryAll();
  2320. if($info){
  2321. return $info;
  2322. }
  2323. }
  2324. return $info;
  2325. }
  2326. public function getPaperScore($paperIds){
  2327. $score = 0;
  2328. if($paperIds && is_array($paperIds)){
  2329. $paperIds = array_values($paperIds);
  2330. $sql = "select score from paper where paper_id = {$paperIds[0]}";
  2331. $score = $this->sConn->createCommand($sql)->queryScalar();
  2332. }
  2333. return $score;
  2334. }
  2335. public function getPreExamId($examId,$subjectId,$classId){
  2336. $examDate = $this->getExamTime($examId);
  2337. $sql = "select cep.exam_id,e.exam_group_id from class_exam_printer as cep left join exam as e on e.exam_id = cep.exam_id where e.subject_id = {$subjectId} and cep.add_time < {$examDate} and e.class_id = {$classId} and cep.type = 0 and e.status = 1 order by add_time desc";
  2338. return $this->sConn->createCommand($sql)->queryRow();
  2339. }
  2340. public function getExamTime($examId){
  2341. $sql = "select add_time from class_exam_printer where exam_id = {$examId} and type = 0";
  2342. return $this->sConn->createCommand($sql)->queryScalar();
  2343. }
  2344. /**
  2345. * 获取多个试卷学生做题记录
  2346. * @param $paperIds
  2347. * @return array
  2348. */
  2349. public function getStudentRs($paperIds){
  2350. $newInfo = array();
  2351. $_countSql = "select count(0) AS count from student_paper_topic_rs where paper_id in (".implode(',',$paperIds).") and handlerIndex = 1";
  2352. $counTinfo = $this->sConn->createCommand($_countSql)->queryRow();
  2353. $count = 0;
  2354. if(isset($counTinfo['count'])){
  2355. $count = $counTinfo['count'];
  2356. }else{
  2357. return $newInfo;
  2358. }
  2359. $limit = 20000;
  2360. $page = ceil($count/$limit);
  2361. $__sql = "select student_id,paper_id,`topic_id`,`type`,is_right,handlerIndex,answer,answer_url,scoring from student_paper_topic_rs where paper_id in (".implode(',',$paperIds).") and handlerIndex = 1";
  2362. for($i = 0;$i < $page ;$i++){
  2363. $offset = $i * $limit;
  2364. $sql = $__sql." limit {$offset},{$limit}";
  2365. $info = $this->sConn->createCommand($sql)->queryAll();
  2366. if($info){
  2367. foreach($info as $value){
  2368. $temp['paper_id'] = $value['paper_id'];
  2369. $temp['topic_id'] = $value['topic_id'];
  2370. $temp['type'] = $value['type'];
  2371. $temp['is_right'] = $value['is_right'];
  2372. $temp['handlerIndex'] = $value['handlerIndex'];
  2373. if($value['type'] == 1 || $value['type'] == 11){
  2374. $temp['answer'] = $value['answer'];
  2375. }else{
  2376. $temp['answer'] = $value['answer_url'];
  2377. }
  2378. $temp['scoring'] = $value['scoring'];
  2379. $newInfo[$value['student_id']][$value['topic_id']] = $temp;
  2380. }
  2381. }
  2382. unset($info);
  2383. }
  2384. return $newInfo;
  2385. }
  2386. /**
  2387. * 获取试卷大题题信息
  2388. * @param $paperId
  2389. * @return array
  2390. */
  2391. public function getPaperLargeTopicInfo($paperId){
  2392. $sql = "select large_topic_id,logic_type,logic_type_second,method_ids from paper_topic_large where paper_id = {$paperId}";
  2393. $info = $this->sConn->createCommand($sql)->queryAll();
  2394. $logicType = array();
  2395. $largeTopicMethod = array();
  2396. if($info){
  2397. foreach($info as $value){
  2398. if($value['logic_type_second'] > 0){
  2399. $value['logic_type'] .= '_'.$value['logic_type_second'];
  2400. }
  2401. $logicType[$value['large_topic_id']] = $value['logic_type'];
  2402. $largeTopicMethod[$value['large_topic_id']] = explode(',',$value['method_ids']);
  2403. }
  2404. unset($info);
  2405. }
  2406. return array($logicType,$largeTopicMethod);
  2407. }
  2408. /**
  2409. * 获取试卷题信息
  2410. * @param $paperId
  2411. * @return array|CDbDataReader
  2412. */
  2413. public function getPaperInfo($paperId){
  2414. $sql = "select topic_id,stem_id,`no`,score,`type`,method_ids,`order` from paper_topic_relation where paper_id = {$paperId} and is_delete = 0 order by `no`";
  2415. return $this->sConn->createCommand($sql)->queryAll();
  2416. }
  2417. /**
  2418. * 获取试卷题信息
  2419. * @param $paperId
  2420. * @param $largeTopicType
  2421. * @return array
  2422. */
  2423. public function getPaperTopicInfo2($paperId,$largeTopicType,$subjectId,$examInfo){
  2424. if($paperId){
  2425. $info = $this->getPaperInfo($paperId);
  2426. $aliasTopicNoArr = $this->getAliasTopicNo($info, $examInfo['tpl_data']);
  2427. $topicScore = array();//题总分
  2428. $smallTopicScore = array();//小题总分
  2429. $topicNoArr = array();//题号
  2430. $smallTopicNoArr = array();//小题题号
  2431. $topicType = array();//题对应的题类型
  2432. $topicLogicType = array();//题对应的逻辑题类型
  2433. $topicRelLarge = array();//题id对应的大题id
  2434. $topicRelMethod = array();//题id对应的考点
  2435. $topicTypeRelNo = array();//题型对应的题号
  2436. $topicNoSection = array();//英语和语文大题对应的区间
  2437. $paperTopicNo = array();
  2438. $topicRelTopicCount = array();//大题对应的小题数量
  2439. if($info){
  2440. $no = 0;
  2441. $p_no = 1;
  2442. $typeArr = array('A','B','C','D');
  2443. $typeNo = 0;
  2444. $p_typeNo = 0;
  2445. foreach($info as $value){
  2446. $t_id = $value['topic_id'];
  2447. if (isset($aliasTopicNoArr[$t_id]) && $aliasTopicNoArr[$t_id]) {
  2448. $value['no'] = $aliasTopicNoArr[$t_id];
  2449. }
  2450. $smallTopicScore[$t_id] = $value['score'];
  2451. $smallTopicNoArr[$t_id] = $value['no'];
  2452. if($value['stem_id'] > 0){
  2453. $t_id = $value['stem_id'];
  2454. }
  2455. //题号
  2456. if($value['stem_id'] > 0){
  2457. if(!isset($topicNoArr[$t_id])){
  2458. $paperTopicNo[$t_id] = $p_no;
  2459. $p_no++;
  2460. }
  2461. }else{
  2462. if($value['type'] == 17 || $value['type'] == 27){
  2463. $topicNoArr[$t_id] = $p_no.(isset($typeArr[$p_typeNo])?$typeArr[$p_typeNo]:'A');
  2464. $p_typeNo++;
  2465. }else{
  2466. $topicNoArr[$t_id] = $p_no;
  2467. $p_no++;
  2468. }
  2469. }
  2470. if($value['type'] == 17 || $value['type'] == 27){
  2471. $topicNoArr[$t_id] = $no.(isset($typeArr[$typeNo])?$typeArr[$typeNo]:'A');
  2472. $typeNo++;
  2473. }else{
  2474. $topicNoArr[$t_id] = $no;
  2475. $no++;
  2476. }
  2477. //题型对应的题号
  2478. if(isset($largeTopicType[$t_id]) && $largeTopicType[$t_id]){
  2479. $t_type = (int)$largeTopicType[$t_id];
  2480. }else{
  2481. $t_type = $value['type'];
  2482. }
  2483. if(!isset($topicTypeRelNo[$t_type])){
  2484. $topicTypeRelNo[$t_type] = array();
  2485. }
  2486. if(!inArray($no,$topicTypeRelNo[$t_type])){
  2487. $topicTypeRelNo[$t_type][$value['topic_id']] = $no;
  2488. }
  2489. //题分数
  2490. if(!isset($topicScore[$value['topic_id']])){
  2491. $topicScore[$value['topic_id']] = 0;
  2492. }
  2493. $topicScore[$value['topic_id']] += $value['score'];
  2494. //题对应的题类型
  2495. $topicType[$value['topic_id']] = $value['type'];
  2496. //题对应的逻辑题类型
  2497. if(isset($largeTopicType[$t_id])){
  2498. $topicLogicType[$value['topic_id']] = $largeTopicType[$t_id];
  2499. }else{
  2500. $topicLogicType[$value['topic_id']] = 0;
  2501. }
  2502. //题id对应的大题id
  2503. $topicRelLarge[$value['topic_id']] = $value['stem_id'];
  2504. //题对应的知识点
  2505. $topicRelMethod[$value['topic_id']] = explode(',',$value['method_ids']);
  2506. //英语和语文大题对应的区间
  2507. if(!isset($topicNoSection[$t_id])){
  2508. $topicNoSection[$t_id] = array();
  2509. }
  2510. $topicNoSection[$t_id][] = $value['no'];
  2511. //小题数量
  2512. if (!isset($topicRelTopicCount[$t_id])) {
  2513. $topicRelTopicCount[$t_id] = 0;
  2514. }
  2515. $topicRelTopicCount[$t_id]++;
  2516. }
  2517. }
  2518. }
  2519. unset($info);
  2520. $tempSection = array();
  2521. foreach($topicNoSection as $t_id => $v){
  2522. $v_count = count($v);
  2523. if($v_count > 1){
  2524. asort($v);
  2525. $tempSection[$t_id] = $v[0].'-'.$v[$v_count - 1];
  2526. }else{
  2527. $tempSection[$t_id] = current($v);
  2528. }
  2529. }
  2530. $topicNoArr = $tempSection;
  2531. unset($tempSection);
  2532. unset($topicNoSection);
  2533. // if(inArray($paperType,array(0,1,2))){
  2534. //
  2535. // }else{
  2536. // $topicNoArr = $paperTopicNo;
  2537. // $smallTopicNoArr = array();
  2538. // }
  2539. return array($smallTopicScore,$smallTopicNoArr,$topicScore,$topicNoArr,$topicType,$topicLogicType,$topicRelLarge,$topicRelMethod,$topicTypeRelNo,$topicRelTopicCount);
  2540. }
  2541. /**
  2542. * 别名题号
  2543. * @param $paperTopicInfo
  2544. * @param $tplData
  2545. * @return array
  2546. */
  2547. private function getAliasTopicNo($paperTopicInfo,$tplData)
  2548. {
  2549. $orderRelTopicId = array();
  2550. foreach ($paperTopicInfo as $info) {
  2551. $orderRelTopicId[$info['order']] = strval($info['topic_id']);
  2552. }
  2553. $aliasTopicNoArr = array();
  2554. if ($tplData) {
  2555. $tplDataArr = json_decode($tplData, true);
  2556. if (isset($tplDataArr['new_items'])) {
  2557. foreach ($tplDataArr['new_items'] as $item) {
  2558. if (isset($item['id'])) {
  2559. if(!isset($orderRelTopicId[$item['id']])) continue;
  2560. $aliasTopicNoArr[$orderRelTopicId[$item['id']]] = $item['alias'];
  2561. }
  2562. }
  2563. }
  2564. }
  2565. return $aliasTopicNoArr;
  2566. }
  2567. /**
  2568. * 获取考试对应的试卷id
  2569. * @param $examIds
  2570. * @return array
  2571. */
  2572. public function getPaperIdsByExamIds($examIds){
  2573. $paperIds = $examRelIds = array();
  2574. if($examIds && is_array($examIds)){
  2575. $sql = "select paper_id,exam_id from paper where exam_id in (".implode(',',$examIds).")";
  2576. $paperInfo = $this->sConn->createCommand($sql)->queryAll();
  2577. if($paperInfo){
  2578. foreach ($paperInfo as $item) {
  2579. $paperIds[$item['exam_id']] = $item['paper_id'];
  2580. $examRelIds[$item['paper_id']] = $item['exam_id'];
  2581. }
  2582. }
  2583. }
  2584. return array($paperIds,$examRelIds);
  2585. }
  2586. protected function getImage($ratePath,$timeMethodRate){
  2587. /* Create and populate the pData object */
  2588. $MyData = new pData();
  2589. $i = 1;
  2590. foreach($timeMethodRate as $arr){
  2591. $MyData->addPoints($arr,"Probe {$i}");
  2592. $i++;
  2593. if($i > 3){
  2594. break;
  2595. }
  2596. }
  2597. // $MyData->addPoints(array(4,1,2,12,8,3),"Probe 1");
  2598. // $MyData->addPoints(array(3,12,15,8,5,5),"Probe 2");
  2599. // $MyData->addPoints(array(2,7,5,18,19,22),"Probe 3");
  2600. $MyData->setSerieTicks("Probe 2",4);
  2601. $MyData->setSerieWeight("Probe 3",2);
  2602. $MyData->setAxisName(0,"得分率");
  2603. $MyData->addPoints(array("上上次","上次","本次"),"Labels");
  2604. $MyData->setSerieDescription("Labels","Months");
  2605. $MyData->setAbscissa("Labels");
  2606. $MyData->setSerieShape(0,SERIE_SHAPE_TRIANGLE);
  2607. /* Create the pChart object */
  2608. $myPicture = new pImage(700,230,$MyData);
  2609. /* Turn of Antialiasing */
  2610. $myPicture->Antialias = FALSE;
  2611. /* Add a border to the picture */
  2612. $myPicture->drawRectangle(0,0,699,229,array("R"=>0,"G"=>0,"B"=>0));
  2613. /* Write the chart title */
  2614. $myPicture->setFontProperties(array("FontName"=>str_replace("protected", "", Yii::app()->basePath)."fonts/pChart/msyh.ttf","FontSize"=>11));
  2615. $myPicture->drawText(150,35,"考点掌握情况变化趋势",array("FontSize"=>12,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
  2616. /* Set the default font */
  2617. $myPicture->setFontProperties(array("FontName"=>str_replace("protected", "", Yii::app()->basePath)."fonts/pChart/msyh.ttf","FontSize"=>8));
  2618. /* Define the chart area */
  2619. $myPicture->setGraphArea(60,40,650,200);
  2620. /* Draw the scale */
  2621. $scaleSettings = array("XMargin"=>10,"YMargin"=>10,"Floating"=>TRUE,"GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE);
  2622. $myPicture->drawScale($scaleSettings);
  2623. /* Turn on Antialiasing */
  2624. $myPicture->Antialias = false;
  2625. /* Draw the line chart */
  2626. // $myPicture->drawLineChart();
  2627. $myPicture->drawLineChart(array("ForceColor"=>true, "ForceR"=>0,"ForceG"=>0,"ForceB"=>0, "ForceAlpha"=>80));
  2628. $myPicture->drawPlotChart(array("DisplayValues"=>TRUE,"PlotBorder"=>TRUE,"BorderSize"=>2,"Surrounding"=>-60,"BorderAlpha"=>80));
  2629. /* Write the chart legend */
  2630. $myPicture->drawLegend(510,20,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));
  2631. /* Render the picture (choose the best way) */
  2632. // $myPicture->autoOutput($ratePath);die;
  2633. $myPicture->render($ratePath);
  2634. }
  2635. /**
  2636. * 获取试卷选择题id
  2637. * @param $topic_type_arr
  2638. * @param $topic_logic_type_arr
  2639. * @param $is_has_large
  2640. */
  2641. protected function getChoiceIds($topic_type_arr,$topic_logic_type_arr,$subject_id,$paper_type)
  2642. {
  2643. $choice_ids = array();
  2644. $type_arr = array();
  2645. if (inArray($paper_type, array(0, 1, 2))) {
  2646. if ($subject_id == 12) {//物理
  2647. $type_arr = array(1, 4, 5, 8, 9);
  2648. } elseif ($subject_id == 13) {//化学
  2649. $type_arr = array(1);
  2650. } elseif ($subject_id == 14) {//生物
  2651. $type_arr = array(1, 3, 4);
  2652. } elseif ($subject_id == 15) {//政治
  2653. $type_arr = array(1, 3, 4, 6, 7);
  2654. } elseif ($subject_id == 16) {//历史
  2655. $type_arr = array(1);
  2656. } elseif ($subject_id == 17) {//地理
  2657. $type_arr = array(1, 3, 4);
  2658. }
  2659. } else {
  2660. $type_arr = array(1, 11);
  2661. }
  2662. foreach ($topic_logic_type_arr as $t_id => $type) {
  2663. if (inArray($type, $type_arr)) {
  2664. $choice_ids[] = $t_id;
  2665. }
  2666. }
  2667. //
  2668. $diff_topic = array_diff(array_keys($topic_logic_type_arr), $choice_ids);
  2669. if ($diff_topic) {
  2670. foreach ($topic_type_arr as $t_id => $item) {
  2671. if (inArray($t_id, $diff_topic) && inArray($item, array(1, 11))) {
  2672. $choice_ids[] = $t_id;
  2673. }
  2674. }
  2675. }
  2676. return $choice_ids;
  2677. }
  2678. /**
  2679. * 试题年级和班级得分率,答对和答错人数
  2680. * @param $stuRs
  2681. * @param $topicScore
  2682. * @param $paperId
  2683. * @return array
  2684. */
  2685. public function getTopicRateWrongPerson(&$stuRs,$topicScore,$paperId,&$stuIdsArr,$topicRelLarge,$choinceIds,$sutName,$topicLogicType){
  2686. $gradeRate = $classRate = array();//班级和年级得分率
  2687. $wrongStu = $rightStu = array();//答对答错人数
  2688. $isChoiceTopic = array();
  2689. $stuNormalIds = array();
  2690. foreach($stuIdsArr as $stuIds){
  2691. foreach ($stuIds as $stuId) {
  2692. $stuNormalIds[$stuId] = 0;
  2693. }
  2694. }
  2695. $gradeScoring = $classScoring = array();
  2696. $gradeScore = $classScore= array();
  2697. $doneTopicNum = array();//每题做题总人数
  2698. $stuScoring = $stuScore= array();
  2699. $classTopicScoring = array();//班级题得分
  2700. $choiceTopicWrong = array();//单选题答错统计
  2701. $stuLargeTopicScore = array();//学生大题得分统计
  2702. $largeContainScore = array();
  2703. $readingTopicIds = array();
  2704. $readingWrongStu = array();
  2705. //优化strcmp($paperId ,$value['paper_id']) == 0
  2706. $paperIndexArr = array();
  2707. foreach($stuRs as $stuId => $rs){
  2708. foreach($rs as $value){
  2709. $paperIndexArr[$value['paper_id']] = 0;
  2710. }
  2711. }
  2712. if ($paperIndexArr) {
  2713. $paperIndexArr = array_keys($paperIndexArr);
  2714. $paperIndexArr = array_flip($paperIndexArr);
  2715. }
  2716. //当前paper_id的索引
  2717. $curPaperIndex = isset($paperIndexArr[$paperId]) ? $paperIndexArr[$paperId] : false;
  2718. //阅读理解选项显示答错学生姓名
  2719. foreach ($topicLogicType as $tId=>$logicType) {
  2720. if ($logicType == 3) {
  2721. $readingTopicIds[] = $tId;
  2722. }
  2723. }
  2724. foreach($stuRs as $stuId => $rs){
  2725. if(!isset($stuNormalIds[$stuId])){
  2726. continue;
  2727. }
  2728. foreach ($rs as $k => $value){
  2729. if(isset($topicRelLarge[$value['topic_id']]) && $topicRelLarge[$value['topic_id']] > 0){
  2730. $t_id = $topicRelLarge[$value['topic_id']];
  2731. }else{
  2732. $t_id = $value['topic_id'];
  2733. }
  2734. if(!isset($largeContainScore[$t_id])){
  2735. $largeContainScore[$t_id] = array();
  2736. }
  2737. $largeContainScore[$t_id][$value['topic_id']] = $topicScore[$value['topic_id']];
  2738. if(!isset($stuLargeTopicScore[$stuId][$t_id])){
  2739. $stuLargeTopicScore[$stuId][$t_id] = array('scoring'=>0,'score'=>0);
  2740. }
  2741. $stuLargeTopicScore[$stuId][$t_id]['scoring'] += $value['scoring'];
  2742. $stuLargeTopicScore[$stuId][$t_id]['score'] += $topicScore[$value['topic_id']];
  2743. $t_score = isset($topicScore[$value['topic_id']])?$topicScore[$value['topic_id']]:0;
  2744. if(!isset($gradeScoring[$t_id])){
  2745. $gradeScoring[$t_id] = 0;
  2746. }
  2747. $gradeScoring[$t_id] += $value['scoring'];
  2748. if(!isset($gradeScore[$t_id])){
  2749. $gradeScore[$t_id] = 0;
  2750. }
  2751. $gradeScore[$t_id] += $t_score;
  2752. // if(strcmp($paperId,$value['paper_id']) == 0){
  2753. if(isset($paperIndexArr[$value['paper_id']]) && $paperId !== false && $paperIndexArr[$value['paper_id']] == $curPaperIndex){
  2754. if(!isset($classScoring[$t_id])){
  2755. $classScoring[$t_id] = 0;
  2756. }
  2757. $classScoring[$t_id] += $value['scoring'];
  2758. if(!isset($classScore[$t_id])){
  2759. $classScore[$t_id] = 0;
  2760. }
  2761. $classScore[$t_id] += $t_score;
  2762. if(!isset($wrongStu[$t_id])){
  2763. $wrongStu[$t_id] = array();
  2764. }
  2765. // if($t_score != $value['scoring']){
  2766. // $wrongStu[$t_id][] = $stuId;
  2767. // }
  2768. if(!isset($doneTopicNum[$t_id])){
  2769. $doneTopicNum[$t_id] = array();
  2770. }
  2771. $doneTopicNum[$t_id][] = $stuId;
  2772. //学生得分率
  2773. if(!isset($stuScoring[$stuId])){
  2774. $stuScoring[$stuId] = array();
  2775. }
  2776. if(!isset($stuScoring[$stuId][$t_id])){
  2777. $stuScoring[$stuId][$t_id] = 0;
  2778. }
  2779. $stuScoring[$stuId][$t_id] += $value['scoring'];
  2780. if(!isset($stuScore[$stuId])){
  2781. $stuScore[$stuId] = array();
  2782. }
  2783. if(!isset($stuScore[$stuId][$t_id])){
  2784. $stuScore[$stuId][$t_id] = 0;
  2785. }
  2786. $stuScore[$stuId][$t_id] += $t_score;
  2787. //班级平均得分
  2788. if (!isset($classTopicScoring[$t_id])) {
  2789. $classTopicScoring[$t_id] = array();
  2790. }
  2791. $classTopicScoring[$t_id][] = $value['scoring'];
  2792. //统计单选题答错人数
  2793. if (isset($topicLogicType[$t_id]) && $topicLogicType[$t_id] == 1) {
  2794. if ($value['is_right'] != 1 && in_array($value['answer'],array('A','B','C','D','E'))) {
  2795. if (!isset($choiceTopicWrong[$t_id])) {
  2796. $choiceTopicWrong[$t_id] = array();
  2797. }
  2798. if (!isset($choiceTopicWrong[$t_id][$value['answer']])) {
  2799. $choiceTopicWrong[$t_id][$value['answer']] = 0;
  2800. }
  2801. $choiceTopicWrong[$t_id][$value['answer']]++;
  2802. }
  2803. }
  2804. }
  2805. if (in_array($value['topic_id'],$readingTopicIds)) {
  2806. if (empty($value['is_right']) && $value['answer']) {
  2807. if (!isset($readingWrongStu[$value['topic_id']])) {
  2808. $readingWrongStu[$value['topic_id']][$value['answer']] = array();
  2809. }
  2810. if (isset($sutName[$stuId])) {
  2811. $readingWrongStu[$value['topic_id']][$value['answer']][] = $sutName[$stuId];
  2812. }
  2813. }
  2814. }
  2815. }
  2816. }
  2817. //年级得分率
  2818. foreach($gradeScoring as $tId => $scorings){
  2819. if(isset($gradeScore[$tId]) && $gradeScore[$tId] > 0){
  2820. $gradeRate[$tId] = round($scorings/$gradeScore[$tId],4) * 100;
  2821. }else{
  2822. $gradeRate[$tId] = 0;
  2823. }
  2824. }
  2825. //班级得分率
  2826. foreach ($classScoring as $tId => $scoring){
  2827. if(isset($classScore[$tId]) && $classScore[$tId] > 0){
  2828. $classRate[$tId] = round($scoring/$classScore[$tId],4) * 100;
  2829. }else{
  2830. $classRate[$tId] = 0;
  2831. }
  2832. }
  2833. //答错人数
  2834. foreach ($stuScore as $stuId => $tScores){
  2835. if(isset($stuScoring[$stuId])){
  2836. foreach ($tScores as $tId => $score){
  2837. $_scoring = isset($stuScoring[$stuId][$tId])?$stuScoring[$stuId][$tId]:0;
  2838. if($score != $_scoring){
  2839. $wrongStu[$tId][] = $stuId;
  2840. }
  2841. }
  2842. }
  2843. }
  2844. if($wrongStu){
  2845. foreach($wrongStu as $key => $stuIds){
  2846. $stuIds = array_unique($stuIds);
  2847. $wrongStu[$key] = count($stuIds);
  2848. if(isset($doneTopicNum[$key])){
  2849. $_stuIds = array_unique($doneTopicNum[$key]);
  2850. $rightStu[$key] = count($_stuIds) - $wrongStu[$key];
  2851. }
  2852. }
  2853. }
  2854. //题得分率低于70%的学
  2855. $rateLess70 = array();
  2856. if($stuScoring){
  2857. foreach($stuScoring as $stuId => $tScoring){
  2858. $stuScoreArr = isset($stuScore[$stuId])?$stuScore[$stuId]:array();
  2859. foreach ($tScoring as $tId => $scoring){
  2860. if(!isset($rateLess70[$tId])){
  2861. $rateLess70[$tId] = array();
  2862. }
  2863. if(isset($stuScoreArr[$tId]) && $stuScoreArr[$tId] > 0){
  2864. $tempRate = round($scoring/$stuScoreArr[$tId],4) * 100;
  2865. }else{
  2866. $tempRate = 0;
  2867. }
  2868. if(inArray($tId,$choinceIds)){
  2869. if($tempRate < 100 && !inArray($stuId,$rateLess70[$tId])){
  2870. $rateLess70[$tId][] = $stuId;
  2871. }
  2872. $isChoiceTopic[] = $tId;
  2873. }else{
  2874. if($tempRate < 70 && !inArray($stuId,$rateLess70[$tId])){
  2875. $rateLess70[$tId][] = $stuId;
  2876. }
  2877. }
  2878. }
  2879. }
  2880. }
  2881. foreach ($rateLess70 as $tId => $stuIds){
  2882. $nameArr = array();
  2883. foreach ($stuIds as $stuId){
  2884. $nameArr[] = isset($sutName[$stuId])?$sutName[$stuId]:'';
  2885. }
  2886. $rateLess70[$tId] = implode('、',$nameArr);
  2887. }
  2888. //大题对应的小题个数
  2889. $large_rel_count = array();
  2890. foreach ($topicRelLarge as $tId => $ltId) {
  2891. if (!isset($large_rel_count[$ltId])) {
  2892. $large_rel_count[$ltId] = 0;
  2893. }
  2894. $large_rel_count[$ltId]++;
  2895. }
  2896. //班级平均分
  2897. $classTopicAvg = array();
  2898. foreach ($classTopicScoring as $tId => $scorings) {
  2899. if ($scorings) {
  2900. $classTopicAvg[$tId] = round(array_sum($scorings) / (count($scorings)/$large_rel_count[$tId]),2);
  2901. }else{
  2902. $classTopicAvg[$tId] = 0;
  2903. }
  2904. }
  2905. unset($classTopicScoring);
  2906. //低于班级平均分
  2907. $rateLessAvg = array();
  2908. if($stuScoring){
  2909. foreach($stuScoring as $stuId => $tScoring){
  2910. foreach ($tScoring as $tId => $scoring){
  2911. if(!isset($rateLessAvg[$tId])){
  2912. $rateLessAvg[$tId] = array();
  2913. }
  2914. if(isset($classTopicAvg[$tId]) && $scoring < $classTopicAvg[$tId]){
  2915. $rateLessAvg[$tId][$stuId] = $scoring;
  2916. }
  2917. }
  2918. }
  2919. }
  2920. foreach ($rateLessAvg as $tId => $stuScoring){
  2921. if ($stuScoring) {
  2922. asort($stuScoring);
  2923. $nameArr = array();
  2924. foreach ($stuScoring as $stuId => $scoring){
  2925. $nameArr[] = isset($sutName[$stuId])?$sutName[$stuId]:'';
  2926. }
  2927. $rateLessAvg[$tId] = implode('、',$nameArr);
  2928. }else{
  2929. $rateLessAvg[$tId] = '';
  2930. }
  2931. }
  2932. foreach ($readingWrongStu as $tId=>$val){
  2933. foreach ($val as $option=>$stuArr) {
  2934. $readingWrongStu[$tId][$option] = implode('、',$stuArr);
  2935. }
  2936. }
  2937. $result = array();
  2938. $result['grade_rate'] = $gradeRate;
  2939. $result['class_rate'] = $classRate;
  2940. $result['wrong_stu'] = $wrongStu;
  2941. $result['right_stu'] = $rightStu;
  2942. $result['rate_less_70'] = $rateLess70;
  2943. $result['rate_less_avg'] = $rateLessAvg;
  2944. $result['is_choice_topic'] = $isChoiceTopic;
  2945. $result['choice_topic_wrong'] = $choiceTopicWrong;
  2946. $result['large_topic_score'] = $stuLargeTopicScore;
  2947. $result['large_contain_score'] = $largeContainScore;
  2948. $result['reading_wrong_stu'] = $readingWrongStu;
  2949. $gradeScoring = $classScoring = array();
  2950. $gradeScore = $classScore= array();
  2951. $doneTopicNum = array();//每题做题总人数
  2952. unset($gradeScoring);
  2953. unset($classScoring);
  2954. unset($gradeScore);
  2955. unset($classScore);
  2956. unset($doneTopicNum);
  2957. unset($stuScoring);
  2958. unset($stuScore);
  2959. return $result;
  2960. }
  2961. function scoreRate($scoring,$total_score,$is_per = false)
  2962. {
  2963. if ($total_score > 0) {
  2964. if ($is_per) {
  2965. $pre_rate = 100;
  2966. $decimal = 4;
  2967. }else{
  2968. $pre_rate = 1;
  2969. $decimal = 2;
  2970. }
  2971. return round($scoring/$total_score,$decimal)*$pre_rate;
  2972. }else{
  2973. return 0;
  2974. }
  2975. }
  2976. private function handleWordClass($keyWords){
  2977. $word_ids = _array_column($keyWords,'single_word_id');
  2978. $rs = $this->apiBrainPost('/zsytk2/getIspInfo', array('condition'=>array('single_word_id'=>$word_ids),'table' => 'en_single_word_label' ,'isAll' => 1),25,true);
  2979. if (isset($rs['status']) && $rs['status']==1 && isset($rs['data']) && $rs['data']) {
  2980. $label_ids = array();
  2981. $swm_ids = array();
  2982. foreach ($rs['data'] as $key=>$v) {
  2983. if ($v['label_type_id'] == 3) {
  2984. unset($rs['data'][$key]);
  2985. }
  2986. if ($v['label_type_id'] == 7) {
  2987. $label_ids[] = $v['label_id'];
  2988. $swm_ids[] = $v['swm_id'];
  2989. }
  2990. }
  2991. $rel = array();
  2992. if ($label_ids) {
  2993. $label_rs = $this->apiBrainPost('/zsytk2/getIspInfo', array('condition'=>array('label_id'=>$label_ids),'table' => 'en_label' ,'isAll' => 1),25,true);
  2994. if (isset($label_rs['status']) && $label_rs['status']==1 && isset($label_rs['data']) && $label_rs['data']) {
  2995. $rel = array();
  2996. foreach ($label_rs['data'] as $v) {
  2997. $rel[$v['label_id']] = $v['content'];
  2998. }
  2999. }
  3000. }
  3001. foreach ($rs['data'] as &$item) {
  3002. $item['content'] = isset($rel[$item['label_id']]) ? $rel[$item['label_id']] : '';
  3003. }
  3004. unset($item);
  3005. $new_swm_res = array();
  3006. if ($swm_ids) {
  3007. $swm_rs = $this->apiBrainPost('/zsytk2/getIspInfo', array('condition'=>array('swm_id'=>$swm_ids),'table' => 'en_single_word_mean' ,'isAll' => 1),25,true);
  3008. if (isset($swm_rs['status']) && $swm_rs['status']==1 && isset($swm_rs['data']) && $swm_rs['data']) {
  3009. foreach ($swm_rs['data'] as $item) {
  3010. $new_swm_res[$item['swm_id']] = $item;
  3011. }
  3012. }
  3013. }
  3014. $new_res = array();
  3015. $res = $rs['data'];
  3016. foreach($res as $res_val){
  3017. $s_id = $res_val['single_word_id'];
  3018. if (!isset($new_res[$s_id])) {
  3019. $new_res[$s_id] = array('con_str'=>'','swm_ids'=>array(),'single_word_id'=>$s_id);
  3020. }
  3021. $new_res[$s_id]['con_str'] .= $res_val['content'];
  3022. $new_res[$s_id]['swm_ids'][] = $res_val['swm_id'];
  3023. if ($res_val['swm_id']) {
  3024. $new_res[$s_id]['swm_con'][$res_val['swm_id']] = $res_val['content'];
  3025. }
  3026. }
  3027. $_tmp_res = array();
  3028. foreach ($new_res as $tmp) {
  3029. $single_id = $tmp['single_word_id'];
  3030. $swm_ids = array_filter($tmp['swm_ids']);
  3031. if (!isset($_tmp_res[$single_id])) {
  3032. $_tmp_res[$single_id] = '';
  3033. }
  3034. if ($swm_ids) {
  3035. foreach ($swm_ids as $_id) {
  3036. if (isset($new_swm_res[$_id])){
  3037. $_tmp_res[$single_id] .= ' '.$tmp['swm_con'][$_id]." {$new_swm_res[$_id]['mean']} ";
  3038. }
  3039. }
  3040. }
  3041. }
  3042. foreach($keyWords as &$val){
  3043. $val['word_class'] = isset($new_res[$val['single_word_id']]) ? $new_res[$val['single_word_id']]['con_str'] : '';
  3044. $val['new_mean'] = isset($_tmp_res[$val['single_word_id']]) ? $_tmp_res[$val['single_word_id']] : '';
  3045. }
  3046. }
  3047. return $keyWords;
  3048. }
  3049. /**
  3050. * 英语题型新转老
  3051. */
  3052. public function getTopicTypeRelate(){
  3053. return array(
  3054. '553'=> '1',
  3055. '28'=> '1',
  3056. '554'=> '2',
  3057. '41'=> '2',
  3058. '555'=> '3',
  3059. '42'=> '3',
  3060. '281'=> '4',
  3061. '566'=> '4',
  3062. '556'=> '5',
  3063. '44'=> '5',
  3064. '563'=> '6',
  3065. '278'=> '6',
  3066. '286'=> '7',
  3067. '570'=> '7',
  3068. '47'=> '8',
  3069. '557'=> '8',
  3070. '282'=> '9',
  3071. '567'=> '9',
  3072. '279'=> '10',
  3073. '564'=> '10',
  3074. '288'=> '11',
  3075. '572'=> '11',
  3076. '285'=> '12',
  3077. '444'=> '13',
  3078. '741'=> '13',
  3079. '280'=> '14',
  3080. '565'=> '14',
  3081. '287'=> '15',
  3082. '571'=> '15',
  3083. '116' =>'17',
  3084. '562' =>'17',
  3085. '54' =>'18',
  3086. '559' =>'18',
  3087. '55' =>'19',
  3088. '560' =>'19',
  3089. '56' =>'20',
  3090. '561' =>'20',
  3091. '428'=>'21'
  3092. );
  3093. }
  3094. //全学科试题详情兼容
  3095. public function quanTopicDetail($data){
  3096. $result = array();
  3097. $answer_arr = array("A","B","C","D","E","F","G","H","I","J");
  3098. $getTopicTypeRelate = $this->getTopicTypeRelate();
  3099. if($data){
  3100. foreach($data as $k=>$v){
  3101. $temp_basic_type_id = isset($v['basic_type_id'])?$v['basic_type_id']:1;
  3102. $result[$k]['topic_id'] = $v['id'];
  3103. $result[$k]['id'] = $v['id'];
  3104. if(isset($v['bank_type']) && $v['bank_type']){
  3105. $temp_type_id = $v['bank_type'];
  3106. }else{
  3107. $temp_type_id = $v['type_id'];
  3108. }
  3109. $result[$k]['type'] = $result[$k]['type_id'] = isset($getTopicTypeRelate[$temp_type_id])?$getTopicTypeRelate[$temp_type_id]:$temp_type_id;
  3110. $result[$k]['queBody'] = $v['title'];
  3111. $result[$k]['title'] = $v['title'];
  3112. $result[$k]['analysis'] = $v['parse_content'];
  3113. $result[$k]['parse_content'] = $v['parse_content'];
  3114. $result[$k]['slave'] = array();
  3115. $result[$k]['items'] = array();
  3116. $result[$k]['answer'] = '';
  3117. $result[$k]['answer_str'] ='';
  3118. $result[$k]['key_words_levels'] = array();
  3119. $result[$k]['key_words'] = array();
  3120. $result[$k]['isp_ids'] = array();
  3121. $result[$k]['text_level'] = 0;
  3122. $result[$k]['method_id_arr'] = array();
  3123. $result[$k]['sentences_analysis'] = '';
  3124. $result[$k]['topic_solution'] = '';
  3125. $result[$k]['model_essay_point'] = '';
  3126. $result[$k]['new_key_words'] = array();
  3127. if(isset($v['kps']) && $v['kps']){
  3128. foreach($v['kps'] as $kps){
  3129. $result[$k]['method_id_arr'][] = $kps['kp_id'];
  3130. }
  3131. }
  3132. if(isset($v['affiliate']) && $v['affiliate']){
  3133. foreach($v['affiliate'] as $aff){
  3134. if(isset($aff['field_key']) && $aff['field_key']=='tag_8_118'){
  3135. $result[$k]['text_level'] = isset($aff['field_value'])?$aff['field_value']:0;
  3136. }
  3137. if(isset($aff['field_name']) && $aff['field_name']=='长难句解析'){
  3138. $result[$k]['sentences_analysis'] = $aff['field_value'];
  3139. }
  3140. if(isset($aff['field_name']) && $aff['field_name']=='审题思路'){
  3141. $result[$k]['topic_solution'] = $aff['field_value'];
  3142. }
  3143. if(isset($aff['field_name']) && $aff['field_name']=='范文亮点'){
  3144. $result[$k]['model_essay_point'] = $aff['field_value'];
  3145. }
  3146. if(isset($aff['field_name']) && $aff['field_name']=='词汇积累'){
  3147. if(isset($aff['field_value']) && $aff['field_value']){
  3148. $temp_chjl = strip_tags($aff['field_value']);
  3149. $strPattern = "/(?<=\()[^\)]+/";
  3150. preg_match_all($strPattern, $temp_chjl,$result_words);
  3151. if(isset($result_words[0]) && $result_words[0]){
  3152. $single_word_ids = $result_words[0];
  3153. $single_word_data = $this->apiBrainPost('/all_library/getSingleWords', array("single_word_id"=>$single_word_ids),25,true);
  3154. if($single_word_data && $single_word_data['data']){
  3155. $temp_single_word_data = $single_word_data['data'];
  3156. foreach($temp_single_word_data as $temp_single_word_data_k=>$temp_single_word_data_v){
  3157. $result[$k]['new_key_words'][] = array(
  3158. "content"=>isset($temp_single_word_data_v['content'])?$temp_single_word_data_v['content']:'',
  3159. "phonetic_symbol"=>isset($temp_single_word_data_v['phonetic_symbol'])?$temp_single_word_data_v['phonetic_symbol']:'',
  3160. "new_mean"=>isset($temp_single_word_data_v['mean'])?$temp_single_word_data_v['mean']:''
  3161. );
  3162. }
  3163. }
  3164. }
  3165. }
  3166. }
  3167. }
  3168. }
  3169. if(isset($v['slave']) && $v['slave']){
  3170. //七选五特殊处理
  3171. if($result[$k]['type_id'] == 5){
  3172. foreach($v['slave'] as $slave_k=>$slave_v){
  3173. if(isset($slave_v['items']) && isset($slave_v['items']['options']) && $slave_v['items']['options']){
  3174. foreach($slave_v['items']['options'] as $option_k=>$option_v){
  3175. if($option_v["option_correct"]){
  3176. $v['slave'][$slave_k]['items']['options'][$option_k] = array("option_content"=>isset($answer_arr[$option_k])?$answer_arr[$option_k]:'');
  3177. }
  3178. }
  3179. }
  3180. }
  3181. }
  3182. $result[$k]['slave'] = $v['slave'];
  3183. }else{
  3184. $result[$k]['items'] = $v['items'];
  3185. $options_arr = array();
  3186. if($v['items'] && isset($v['items'][0]) && isset($v['items'][0]['options'])){
  3187. $options_arr = $v['items'][0]['options'];
  3188. if($v['items'][0]['options'] && count($v['items'][0]['options']) == 1){
  3189. foreach($v['items'][0]['options'] as $op_v){
  3190. $result[$k]['answer'] = $op_v['option_content'];
  3191. }
  3192. }
  3193. }
  3194. $result[$k]['slave'][] = array('topic_slave_id'=>$v['id'],'items'=>array('options'=>$options_arr));
  3195. }
  3196. }
  3197. }
  3198. return $result;
  3199. }
  3200. }