SchoolManager.php 291 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394
  1. <?php
  2. /**
  3. * @author: Rick Guo
  4. * @brief: 学校管理器
  5. */
  6. defined("ROLE_USER") or define("ROLE_USER", 1);
  7. defined("ROLE_SU") or define("ROLE_SU", 2);
  8. class SchoolManager extends Model{
  9. public $coachId;
  10. public $coach;
  11. public $coachRole;
  12. public $role;
  13. public $parentNotificationHost;
  14. public $semesterAllowToChangeDays;
  15. public $semesterAllowToChangeTime;
  16. public $apiUrl;
  17. public $topicUrl;
  18. public $topicField;
  19. public $topicCacheTime;
  20. public $chapterCacheTime;
  21. public $sTopic;
  22. //试题sections顺序 升序
  23. public $topicTypesOrder = array(
  24. "选择题" => 1,
  25. "填空题" => 2,
  26. "解答题" => 3,
  27. );
  28. public $msgs = array(
  29. "global" => array(
  30. "0" => "操作成功",
  31. "1001" => "缺少参数",
  32. "1002" => "系统错误",
  33. ),
  34. "changeSemester" => array(
  35. "2001" => "不能切换到已完成的学期",
  36. "2002" => "",
  37. "2003"=>"创建班级失败",
  38. ),
  39. "delSemester" => array(
  40. "2001" => "不能删除当前学期",
  41. "2002" => "学期已关联班级",
  42. ),
  43. "delClass" => array(
  44. "2001" => "该班级已关联学生",
  45. "2002" => "该班级已创建过考试",
  46. ),
  47. "delTeacher" => array(
  48. "2001" => "该老师已绑定班级",
  49. "2002" => "该老师已创建过周周练",
  50. ),
  51. "purgeTeacher" => array(
  52. "2001" => "该老师已绑定班级",
  53. "2002" => "该老师已创建过考试",
  54. "2003" => "该老师还有未完成的阅卷任务",
  55. "2004" => "该老师还有未处理的问题卷",
  56. ),
  57. "purgeStudent" => array(
  58. "2001" => "无法操作,该学生已存在考试数据",
  59. ),
  60. "removeStudentClassRelation" => array(
  61. "2001" => "该学生存在周周练数据",
  62. ),
  63. "replaceIspTopic" => array(
  64. "2001" => "新题目和被替换的题目相同,未替换",
  65. "2002" => "被替换的题目在该提分册不存在",
  66. "2003" => "新题目已经存在于该提分册,请选择别的题目",
  67. ),
  68. );
  69. public $inciseTables=array(
  70. 'student_paper_topic_rs',
  71. 'student_paper_relation',
  72. 'student_improve_score_plan_topics',
  73. 'student_wrong_plan_topics',
  74. 'student_upload_result'
  75. );
  76. function __construct($coachId, $role = ROLE_USER,$pad=''){
  77. parent::__construct();
  78. if($pad)
  79. {
  80. $this->role = $role;
  81. $this->parentNotificationHost = Yii::app()->params["notification_host"];
  82. $this->semesterAllowToChangeDays = !empty(Yii::app()->params["semester_allow_to_change_days"]) ? Yii::app()->params["semester_allow_to_change_days"] : 15;
  83. $this->semesterAllowToChangeTime = $this->semesterAllowToChangeDays * 24 * 3600;
  84. $this->msgs["changeSemester"]["2002"] = "只有在学期开始前{$this->semesterAllowToChangeDays}天内允许切换";
  85. $this->apiUrl = Yii::app()->params["api"][0]["prefix"];
  86. $this->topicUrl = $this->apiUrl.Yii::app()->params["topic_store"]["topic_append"];
  87. $this->topicField = Yii::app()->params["topic_store"]["topic_field"];
  88. $this->topicCacheTime = !empty(Yii::app()->params["topic_cache_time"]) ? Yii::app()->params["topic_cache_time"] : 43200;
  89. $this->topicHost = $this->apiUrl.Yii::app()->params["topic_store"]["topic_host"];
  90. $this->chapterCacheTime = !empty(Yii::app()->params["chapter_cache_time"]) ? Yii::app()->params["chapter_cache_time"] : 43200;
  91. $this->sTopic = new STopic();
  92. }else
  93. {
  94. if(!$coachId)
  95. throw new CException("助教ID不能为空");
  96. $this->coachId = $coachId;
  97. $this->role = $role;
  98. $this->coach = $this->getMyInfo();
  99. $this->coachRole = $this->coach["leader"];
  100. $this->parentNotificationHost = Yii::app()->params["notification_host"];
  101. $this->semesterAllowToChangeDays = !empty(Yii::app()->params["semester_allow_to_change_days"]) ? Yii::app()->params["semester_allow_to_change_days"] : 15;
  102. $this->semesterAllowToChangeTime = $this->semesterAllowToChangeDays * 24 * 3600;
  103. $this->msgs["changeSemester"]["2002"] = "只有在学期开始前{$this->semesterAllowToChangeDays}天内允许切换";
  104. $this->apiUrl = Yii::app()->params["api"][0]["prefix"];
  105. $this->topicUrl = $this->apiUrl.Yii::app()->params["topic_store"]["topic_append"];
  106. $this->topicField = Yii::app()->params["topic_store"]["topic_field"];
  107. $this->topicCacheTime = !empty(Yii::app()->params["topic_cache_time"]) ? Yii::app()->params["topic_cache_time"] : 43200;
  108. $this->topicHost = $this->apiUrl.Yii::app()->params["topic_store"]["topic_host"];
  109. $this->chapterCacheTime = !empty(Yii::app()->params["chapter_cache_time"]) ? Yii::app()->params["chapter_cache_time"] : 43200;
  110. $this->sTopic = new STopic();
  111. }
  112. }
  113. protected function rs($code, $action = __FUNCTION__){
  114. $rs = array();
  115. if($code !== null){
  116. if(is_array($code))
  117. $codeStr = implode(", ", $code);
  118. else
  119. $codeStr = $code;
  120. $rs = array(
  121. "code" => $codeStr,
  122. "msg" => $this->translateCode($code, $action),
  123. );
  124. }
  125. return $rs;
  126. }
  127. protected function translateCode($code, $action = __FUNCTION__, $symbol = "<br/>"){
  128. $msg = array();
  129. if($code !== null && isset($this->msgs[$action])){
  130. if(!is_array($code))
  131. $code = array($code);
  132. $i = 1;
  133. foreach($code as $val){
  134. if(isset($this->msgs[$action][(string)$val])){
  135. if($val != 0)
  136. $msg[] = "<span style='color:red'>{$this->msgs[$action][(string)$val]}</span>";
  137. else
  138. $msg[] = "<span style='color:green'>{$this->msgs[$action][(string)$val]}</span>";
  139. $i++;
  140. }
  141. }
  142. }
  143. if($msg){
  144. $msg = implode($symbol, $msg);
  145. }
  146. else
  147. $msg = "";
  148. return $msg;
  149. }
  150. public function getTeachers($orderBy = array("teacher_id asc", "teacher_name asc")){
  151. $teachers = array();
  152. $orderBy = $this->orderBy($orderBy);
  153. $rs = $this->sConn->createCommand("select * from teacher where status != 2 group by teacher_id{$orderBy}")->queryAll();
  154. if($rs)
  155. $teachers = $rs;
  156. return $teachers;
  157. }
  158. public function getTeacherAccount($teacherId){
  159. $account = array();
  160. if($teacherId){
  161. $account = $this->conn->createCommand("select * from xb_teacher where teacher_id = '{$teacherId}'")->queryRow();
  162. }
  163. return $account;
  164. }
  165. public function getTeachersAccounts($teachersIds){
  166. if(!is_array($teachersIds) || !$teachersIds)
  167. return array();
  168. $teachersIds = "'".implode("','", $teachersIds)."'";
  169. return $this->conn->createCommand("select * from xb_teacher where teacher_id in({$teachersIds})")->queryAll();
  170. }
  171. public function countTeachersAccountsPages($pageSize){
  172. if(!$pageSize)
  173. return 0;
  174. $rs = $this->conn->createCommand("select count(*) from xb_teacher")->queryRow();
  175. $rs = current($rs);
  176. return ceil($rs / $pageSize);
  177. }
  178. public function getTeachersByClassesIds($classesIds){
  179. $teachers = array();
  180. if($classesIds){
  181. $classesIds = "'".implode("','", $classesIds)."'";
  182. return $this->sConn->createCommand("
  183. select t.*, tcr.class_id,tcr.is_bzr,t.subjects,tcr.hxb_ing
  184. from teacher_class_relation as tcr
  185. join teacher as t on t.teacher_id = tcr.teacher_id
  186. where tcr.class_id in($classesIds)
  187. ")->queryAll();
  188. }
  189. return $teachers;
  190. }
  191. public function getTeachersByClassesIdsAndteacherName($classesIds,$teacher_name){
  192. $teachers = array();
  193. if($classesIds){
  194. $classesIds = "'".implode("','", $classesIds)."'";
  195. return $this->sConn->createCommand("
  196. select t.*, tcr.class_id
  197. from teacher_class_relation as tcr
  198. join teacher as t on t.teacher_id = tcr.teacher_id
  199. where tcr.class_id in($classesIds) and t.teacher_name LIKE '%{$teacher_name}%'
  200. ")->queryAll();
  201. }
  202. return $teachers;
  203. }
  204. public function getTeachersIdsByClassesIds($classesIds){
  205. $classes = $this->getTeachersByClassesIds($classesIds);
  206. return $this->grouping($classes, "teacher_id");
  207. }
  208. public function getMyInfo(){
  209. return $this->conn->createCommand("select * from coach where coach_id = '{$this->coachId}'")->queryRow();
  210. }
  211. public function getNowClassesByTeacherId($teacherId,$class_id = 0){
  212. $classes = array();
  213. if($teacherId){
  214. if($class_id >0){
  215. $classes = $this->sConn->createCommand("
  216. select c.*
  217. from teacher_class_relation as tcr
  218. join class as c on c.class_id = tcr.class_id and c.semester_id = '{$this->semester["id"]}'
  219. where tcr.teacher_id = '{$teacherId}' and c.class_id = '{$class_id}'
  220. ")->queryAll();
  221. }else{
  222. $classes = $this->sConn->createCommand("
  223. select c.*
  224. from teacher_class_relation as tcr
  225. join class as c on c.class_id = tcr.class_id and c.semester_id = '{$this->semester["id"]}'
  226. where tcr.teacher_id = '{$teacherId}' and c.is_hide=0
  227. ")->queryAll();
  228. }
  229. }
  230. return $classes;
  231. }
  232. public function getClassesByTeacherId($teacherId){
  233. $classes = array();
  234. if($teacherId){
  235. $classes = $this->sConn->createCommand("
  236. select c.*
  237. from teacher_class_relation as tcr
  238. join class as c on c.class_id = tcr.class_id
  239. where tcr.teacher_id = '{$teacherId}'
  240. ")->queryAll();
  241. }
  242. return $classes;
  243. }
  244. /**
  245. * 获取 上传试卷列表
  246. *
  247. * @author CeeFee
  248. */
  249. public function getUploadPaperList($orderBy = array("add_time DESC", "id DESC"),$subject_id=3, $pageSize = 10)
  250. {
  251. $str = '';
  252. $orderBy = $this->orderBy($orderBy);
  253. if($subject_id==3)
  254. {
  255. $str = ' subject_id in ('.implode(',',Yii::app()->params['mathSubjectId']).')';
  256. }else
  257. {
  258. $str = ' subject_id = '.$subject_id;
  259. }
  260. $handle = $this->sConn->createCommand("
  261. SELECT * FROM upload_paper WHERE {$str}
  262. {$orderBy}
  263. ")->query();
  264. $rs = $this->paging($this->sConn, $handle, $pageSize);
  265. return $rs;
  266. }
  267. public function getTeachersList($orderBy = array("teacher_name asc", "teacher_id asc"), $pageSize = 10){
  268. /*$orderBy = $this->orderBy($orderBy);
  269. $classesIds = $this->getClassesIdsByCoachId($this->coachId);
  270. $teachersIds = $this->getTeachersIdsByClassesIds($classesIds);
  271. $teachersIds = "'".implode("','", $teachersIds)."'";
  272. $handle = $this->sConn->createCommand("
  273. select * from teacher where coach_id = '{$this->coachId}' and status != 2
  274. union
  275. select * from teacher where teacher_id in({$teachersIds})
  276. {$orderBy}
  277. ")->query();*/
  278. /**
  279. * 刘红伟修改
  280. * 时间:2016-11-7
  281. */
  282. $orderBy = $this->orderBy($orderBy);
  283. /*$classesIds = $this->getClassesIdsByCoachId($this->coachId);
  284. $teachersIds = $this->getTeachersIdsByClassesIds($classesIds);
  285. $teachersIds = "'".implode("','", $teachersIds)."'";*/
  286. $handle = $this->sConn->createCommand("
  287. select * from teacher where status != 2 {$orderBy}
  288. ")->query();
  289. $rs = $this->paging($this->sConn, $handle, $pageSize);
  290. $teachersIds = $this->grouping($rs["rs"], "teacher_id");
  291. $teachersAccounts = $this->getTeachersAccounts($teachersIds);
  292. foreach($rs["rs"] as $key => $val){
  293. $rs["rs"][$key]["businessphone"] = null;
  294. $rs["rs"][$key]["class_name"] = null;
  295. foreach($teachersAccounts as $account){
  296. if($val["teacher_id"] == $account["teacher_id"]){
  297. $rs["rs"][$key]["businessphone"] = $account["phone_number"];
  298. $classes = $this->getNowClassesByTeacherId($val["teacher_id"]);
  299. $classes = $this->grouping($classes, "class_name");
  300. $classes = implode(",", $classes);
  301. $rs["rs"][$key]["class_name"] = $classes;
  302. }
  303. }
  304. }
  305. return $rs;
  306. }
  307. public function getTeachersListre($teacher_name='',$subject_id = 0,$class_id = 0,$orderBy = array("teacher_name asc", "teacher_id asc"), $pageSize = 10){
  308. /*$orderBy = $this->orderBy($orderBy);
  309. $classesIds = $this->getClassesIdsByCoachId($this->coachId);
  310. $teachersIds = $this->getTeachersIdsByClassesIds($classesIds);
  311. $teachersIds = "'".implode("','", $teachersIds)."'";
  312. $handle = $this->sConn->createCommand("
  313. select * from teacher where coach_id = '{$this->coachId}' and status != 2
  314. union
  315. select * from teacher where teacher_id in({$teachersIds})
  316. {$orderBy}
  317. ")->query();*/
  318. /**
  319. * 刘红伟修改
  320. * 时间:2016-11-7
  321. */
  322. $orderBy = $this->orderBy($orderBy);
  323. /*$classesIds = $this->getClassesIdsByCoachId($this->coachId);
  324. $teachersIds = $this->getTeachersIdsByClassesIds($classesIds);
  325. $teachersIds = "'".implode("','", $teachersIds)."'";*/
  326. $condition=array();
  327. if($teacher_name){
  328. if(is_array($teacher_name)){
  329. $condition[]="t.teacher_id in(".implode(',',$teacher_name).")";
  330. }else{
  331. $condition[]="t.teacher_name LIKE '%{$teacher_name}%'";
  332. }
  333. }
  334. if($subject_id){
  335. if(in_array($subject_id,Yii::app()->params['mathSubjectId'])){
  336. $condition[]="t.subjects in(".implode(',',Yii::app()->params['mathSubjectId']).")";
  337. }else{
  338. $condition[]="t.subjects ='{$subject_id}'";
  339. }
  340. }
  341. if($class_id){
  342. $condition[]="tr.class_id = ".$class_id." and tr. semester_id = '".$this->semester["id"]."'";
  343. $handle = $this->sConn->createCommand("
  344. select t.*,tr.class_id from teacher as t LEFT JOIN teacher_class_relation tr on t.teacher_id = tr.teacher_id where ".implode(' and ',$condition)." GROUP by t.teacher_id HAVING tr.class_id >0 order by t.add_time desc
  345. ")->query();
  346. }else{
  347. if($condition){
  348. $handle = $this->sConn->createCommand("select * from teacher t where ".implode(' and ',$condition)." {$orderBy}")->query();
  349. }else{
  350. $handle = $this->sConn->createCommand("select * from teacher {$orderBy}")->query();
  351. }
  352. }
  353. $rs = $this->paging($this->sConn, $handle, $pageSize);
  354. $teachersIds = $this->grouping($rs["rs"], "teacher_id");
  355. $teachersAccounts = $this->getTeachersAccounts($teachersIds);
  356. $teachers = array();
  357. if($teachersAccounts)
  358. {
  359. foreach($teachersAccounts as $v)
  360. {
  361. $teachers[$v['teacher_id']] = $v;
  362. }
  363. }
  364. foreach($rs["rs"] as $key => $val){
  365. $rs["rs"][$key]["businessphone"] = null;
  366. $rs["rs"][$key]["class_name"] = null;
  367. if(isset($teachers[$val["teacher_id"]]) && !empty($teachers[$val["teacher_id"]])){
  368. $rs["rs"][$key]["businessphone"] = $teachers[$val["teacher_id"]]["phone_number"];
  369. }
  370. $classes = $this->getNowClassesByTeacherId($val["teacher_id"],$class_id);
  371. if(!$classes&&$class_id){
  372. unset($rs["rs"][$key]);
  373. continue;
  374. }
  375. $classes = $this->grouping($classes, "class_name");
  376. $classes = implode(",", $classes);
  377. $rs["rs"][$key]["class_name"] = $classes;
  378. }
  379. return $rs;
  380. }
  381. public function getClasses($grade = "ALL", $orderBy = array("class_id asc", "class_name asc"), $offset = 0, $limit = -1){
  382. $classes = array();
  383. $condition = array();
  384. if(in_array($grade, array("1", "2", "3")))
  385. $condition = array("grade = '{$grade}'");
  386. else if($grade !== "ALL")
  387. return $classes;
  388. $condition = Arr::merge($condition, array("semester_id = '{$this->semester["id"]}'"));
  389. $condition = $this->condition($condition);
  390. $orderBy = $this->orderBy($orderBy);
  391. $limit = $this->limit($offset, $limit);
  392. $classes = $this->sConn->createCommand("select * from class{$condition} group by class_id{$orderBy}{$limit}")->queryAll();
  393. return $classes;
  394. }
  395. public function getClassesWithoutTheClass($classId, $orderBy = array("class_id asc", "class_name asc"), $offset = 0, $limit = -1){
  396. $classes = array();
  397. if($classId){
  398. $condition = array("semester_id = '{$this->semester["id"]}'", "class_id != '{$classId}'");
  399. $condition = $this->condition($condition);
  400. $orderBy = $this->orderBy($orderBy);
  401. $limit = $this->limit($offset, $limit);
  402. $classes = $this->sConn->createCommand("select * from class{$condition} group by class_id{$orderBy}{$limit}")->queryAll();
  403. $classes = Arr::toObj($classes);
  404. }
  405. return $classes;
  406. }
  407. public function getClassesList($condition = array(), $pageSize = 9){
  408. $condition = $this->condition($condition);
  409. $handle = $this->sConn->createCommand("
  410. select c.*
  411. from class as c
  412. {$condition}
  413. order by c.class_id desc
  414. ")->query();
  415. $rs = $this->paging($this->sConn, $handle, $pageSize);
  416. return $rs;
  417. }
  418. public function getMyClassesList($condition = array(), $pageSize = 9){
  419. $condition = Arr::merge(array("ccr.coach_id = '{$this->coachId}'"), $condition);
  420. return $this->getClassesList($condition, $pageSize);
  421. }
  422. public function getClassesDetailListre($condition = array(), $pageSize = 9){
  423. $condition = $this->condition($condition);
  424. /*$handle = $this->sConn->createCommand("
  425. select c.*, seme.semester_name as name, seme.school_year
  426. from class as c
  427. join semester as seme on seme.semester_id = c.semester_id
  428. JOIN teacher_class_relation as tc on c.class_id = tc.class_id and seme.semester_id = tc.semester_id
  429. JOIN teacher as t on tc.teacher_id = t.teacher_id
  430. {$condition}
  431. order by c.class_id desc
  432. ")->query();*/
  433. $handle = $this->sConn->createCommand("
  434. select c.*, seme.semester_name as name, seme.school_year,c.teacher_id
  435. from class as c
  436. join semester as seme on seme.semester_id = c.semester_id
  437. {$condition}
  438. order by c.sort!=0 desc,c.sort,c.class_id desc
  439. ")->query();
  440. $rs = $this->paging($this->sConn, $handle, $pageSize);
  441. if($rs["rs"]){
  442. $coachesIds = $this->grouping($rs["rs"], "coach_id");
  443. $coachesIds = array_unique($coachesIds);
  444. $coaches = $this->getCoachesByIds($coachesIds);
  445. $classesIds = $this->grouping($rs["rs"], "class_id");
  446. $classesIds = array_unique($classesIds);
  447. $teachers = $this->getTeachersByClassesIds($classesIds);
  448. foreach($rs["rs"] as $key => $val){
  449. $rs["rs"][$key]["coach_name"] = "";
  450. foreach($coaches as $coach){
  451. if($val["coach_id"] == $coach["coach_id"]){
  452. $rs["rs"][$key]["coach_name"] = $coach["coach_name"];
  453. }
  454. }
  455. }
  456. foreach($rs["rs"] as $key => $val){
  457. $rs["rs"][$key]["teachers"] = "";
  458. $rs["rs"][$key]["teachers_count"]=0;
  459. $rs["rs"][$key]["teachers_bzr"]='';
  460. foreach($teachers as $teacher){
  461. if(strcmp($val["class_id"],$teacher["class_id"])==0){
  462. $rs["rs"][$key]["teachers"] .= $teacher["teacher_name"];
  463. $rs["rs"][$key]["teachers_count"] ++;
  464. }
  465. }
  466. //读取班主任
  467. if($val['teacher_id']){
  468. $rs['rs'][$key]['teachers_bzr']=Teacher::model()->getTeacherName($val['teacher_id']);
  469. }
  470. }
  471. }
  472. return $rs;
  473. }
  474. public function getClassesDetailList($condition = array(), $pageSize = 9,$teacher_name=''){
  475. $condition = $this->condition($condition);
  476. $handle = $this->sConn->createCommand("
  477. select c.*, seme.semester_name as name, seme.school_year,c.teacher_id
  478. from class as c
  479. join semester as seme on seme.semester_id = c.semester_id
  480. {$condition}
  481. order by c.sort!=0 desc,c.sort,c.class_id desc
  482. ")->query();
  483. $rs = $this->paging($this->sConn, $handle, $pageSize);
  484. if($rs["rs"]){
  485. $coachesIds = $this->grouping($rs["rs"], "coach_id");
  486. $coachesIds = array_unique($coachesIds);
  487. $coaches = $this->getCoachesByIds($coachesIds);
  488. $classesIds = $this->grouping($rs["rs"], "class_id");
  489. $classesIds = array_unique($classesIds);
  490. if($teacher_name){
  491. $teachers = $this->getTeachersByClassesIdsAndteacherName($classesIds,$teacher_name);
  492. }else{
  493. $teachers = $this->getTeachersByClassesIds($classesIds);
  494. }
  495. foreach($rs["rs"] as $key => $val){
  496. $rs["rs"][$key]["coach_name"] = "";
  497. foreach($coaches as $coach){
  498. if($val["coach_id"] == $coach["coach_id"]){
  499. $rs["rs"][$key]["coach_name"] = $coach["coach_name"];
  500. }
  501. }
  502. $rs["rs"][$key]["teachers"] = "";
  503. foreach($teachers as $teacher){
  504. if($val["class_id"] == $teacher["class_id"]){
  505. $rs["rs"][$key]["teachers"] .= $teacher["teacher_name"];
  506. }
  507. }
  508. //读取班主任
  509. if($val['teacher_id']){
  510. $rs['rs'][$key]['teachers_bzr']=Teacher::model()->getTeacherName($val['teacher_id']);
  511. }
  512. }
  513. }
  514. return $rs;
  515. }
  516. public function getMyclassesDetailList($condition = array(), $pageSize = 9){
  517. $condition = Arr::merge(array("c.coach_id = '{$this->coachId}'"), $condition);
  518. return $this->getClassesDetailList($condition, $pageSize);
  519. }
  520. public function getCoachesByIds($coachesIds){
  521. $coaches = array();
  522. if($coachesIds && is_array($coachesIds)){
  523. $coachesIds = implode("','", $coachesIds);
  524. $coachesIds = "'{$coachesIds}'";
  525. $coaches = $this->conn->createCommand("select * from coach where coach_id in($coachesIds)")->queryAll();
  526. }
  527. return $coaches;
  528. }
  529. public function changeClassTeachersRelation($classId, $teachersIds,$semesterId=0){
  530. if($classId && $teachersIds){
  531. if(!is_array($teachersIds))
  532. $teachersIds = array($teachersIds);
  533. $values = "";
  534. foreach($teachersIds as $key => $teacherId){
  535. if(trim((string)$teacherId) == null){
  536. unset($teachersIds[$key]);
  537. continue;
  538. }
  539. $values .= ",('{$classId}', '{$teacherId}', '{$semesterId}')";
  540. }
  541. if($values){
  542. $values = "values".substr($values, 1);
  543. try{
  544. $trans = $this->sConn->beginTransaction();
  545. $this->sConn->createCommand("delete from teacher_class_relation where class_id = '{$classId}'")->execute();
  546. $this->sConn->createCommand("insert into teacher_class_relation(`class_id`, `teacher_id`, `semester_id`) {$values}")->execute();
  547. $trans->commit();
  548. $rs = true;
  549. }
  550. catch(Exception $e){
  551. $trans->rollBack();
  552. $rs = false;
  553. }
  554. return $rs;
  555. }
  556. }
  557. return false;
  558. }
  559. public function _changeClassTeachersRelation($classId, $teachersIds,$class_data = array()){
  560. if($classId && $teachersIds){
  561. if(!is_array($teachersIds))
  562. $teachersIds = array($teachersIds);
  563. $values = "";
  564. foreach($teachersIds as $key => $teacherId){
  565. if(trim((string)$teacherId) == null){
  566. unset($teachersIds[$key]);
  567. continue;
  568. }
  569. $values .= ",('{$classId}', '{$teacherId}', '{$class_data['semester_id']}')";
  570. }
  571. if(!isset($class_data['class_type'])){
  572. $class_data['class_type']=1;
  573. }
  574. if($values){
  575. $values = "values".substr($values, 1);
  576. try{
  577. $trans = $this->sConn->beginTransaction();
  578. if(isset($class_data['teacher_id'])){
  579. $this->sConn->createCommand("insert into class(`class_id`,`class_name`, `coach_id`, `semester_id`,`period`,`grade`,`level`,`wrong_book_type`,`improve_book_type`,`wb_isp_version`,`add_time`,`class_type`,`teacher_id`) VALUES (".$classId.",'".$class_data['class_name']."',".$class_data['coach_id'].",".$class_data['semester_id'].",".$class_data['period'].",".$class_data['grade'].",".$class_data['level'].",".$class_data['wrong_book_type'].",".$class_data['improve_book_type'].",".$class_data['wb_isp_version'].",".$class_data['add_time'].",".$class_data['class_type'].",".$class_data['teacher_id'].")")->execute();
  580. }else{
  581. $this->sConn->createCommand("insert into class(`class_id`,`class_name`, `coach_id`, `semester_id`,`period`,`grade`,`level`,`wrong_book_type`,`improve_book_type`,`wb_isp_version`,`add_time`,`class_type`) VALUES (".$classId.",'".$class_data['class_name']."',".$class_data['coach_id'].",".$class_data['semester_id'].",".$class_data['period'].",".$class_data['grade'].",".$class_data['level'].",".$class_data['wrong_book_type'].",".$class_data['improve_book_type'].",".$class_data['wb_isp_version'].",".$class_data['add_time'].",".$class_data['class_type'].")")->execute();
  582. }
  583. $this->sConn->createCommand("delete from teacher_class_relation where class_id = '{$classId}'")->execute();
  584. $this->sConn->createCommand("insert into teacher_class_relation(`class_id`, `teacher_id`, `semester_id`) {$values}")->execute();
  585. $trans->commit();
  586. $rs = true;
  587. }
  588. catch(Exception $e){
  589. $trans->rollBack();
  590. $rs = false;
  591. }
  592. return $rs;
  593. }
  594. }
  595. return false;
  596. }
  597. /**
  598. * @param $semesterId
  599. *
  600. * @return bool
  601. * 刘红伟
  602. * 开发时间 2016-09-29
  603. *
  604. */
  605. public function insertStudentInfoAndStudentClass($userNames,$studnetIds,$realname_array,$userno,$_IDX_array,$sex_array,$school_id,$class_id,$is_insert = 1)
  606. {
  607. $trans = $this->sConn->beginTransaction();
  608. $student_id_array = array();
  609. $sql1 = '';
  610. try {
  611. if($is_insert)
  612. {
  613. $sql1='';
  614. $sql='INSERT INTO `student_info`
  615. (`student_id`,`realname`,`sex`,`school_id`,`class_id`,`add_time`)VALUES';
  616. foreach($userNames as $username)
  617. {
  618. if(isset($studnetIds[$username]) && !empty($studnetIds[$username]))
  619. {
  620. $student_id_array[] = $studnetIds[$username];
  621. $sql1.='('.$studnetIds[$username].',"'.(isset($realname_array[$username]) && !empty($realname_array[$username])?$sex_array[$username]:'').'",'.(isset($sex_array[$username]) && !empty($sex_array[$username])?$sex_array[$username]:0).','.$school_id.','.$class_id.','.time().'),';
  622. }
  623. }
  624. $sql .= substr($sql1,0,-1).';';
  625. $this->sConn->createCommand($sql)->execute();
  626. }else
  627. {
  628. foreach($userNames as $username)
  629. {
  630. if(isset($studnetIds[$username]) && !empty($studnetIds[$username]))
  631. { $student_id_array[] = $studnetIds[$username];
  632. $sql = 'update `student_info` set realname="'.$realname_array[$username].'",sex='.$sex_array[$username].',class_id='.$class_id.',update_time='.time().' where student_id='.$studnetIds[$username].';';
  633. $this->sConn->createCommand($sql)->execute();
  634. }
  635. }
  636. }
  637. $sql1 = '';
  638. $sql = '';
  639. $this->sConn->createCommand("delete from student_class_relation where class_id =".$class_id." and student_id in (".implode(',',$student_id_array).")")->execute();
  640. $sql = 'INSERT INTO `student_class_relation`
  641. (`class_id`,`student_id`,`status`,`serial_number`,`userno`,`update_time`)VALUES';
  642. foreach($userNames as $username)
  643. {
  644. if(isset($studnetIds[$username]) && !empty($studnetIds[$username]))
  645. {
  646. $sql1 .= '(' . $class_id . ',' . $studnetIds[$username] . ',0,' . $_IDX_array[$username] . ',"' . $userno[$username] . '",' . time() . '),';
  647. }
  648. }
  649. $sql .= substr($sql1,0,-1).';';
  650. $this->sConn->createCommand($sql)->execute();
  651. $trans->commit();
  652. } catch (Exception $e) {
  653. $trans->rollBack();
  654. return false;
  655. }
  656. return true;
  657. }
  658. public function getClassByClassIds($classIds)
  659. {
  660. if(!$classIds)
  661. {
  662. return false;
  663. }
  664. $rs = $this->sConn->createCommand("
  665. select *
  666. from class
  667. where class_id in(".implode(',',$classIds).") ")->queryAll();
  668. if($rs)
  669. {
  670. return $rs;
  671. }
  672. return false;
  673. }
  674. public function updateStudentClassByClassIdAndStudentID($class_id,$student_ids)
  675. {
  676. $trans = $this->sConn->beginTransaction();
  677. try {
  678. $sql='update `student_class_relation` set status = 1 where class_id= '.$class_id;
  679. $this->sConn->createCommand($sql)->execute();
  680. $sql='update `student_info` set class_id = 0 where class_id= '.$class_id;
  681. $this->sConn->createCommand($sql)->execute();
  682. $sql='update `student_class_relation` set status = 1 where student_id in ('.implode(',',$student_ids).')';
  683. $this->sConn->createCommand($sql)->execute();
  684. $trans->commit();
  685. } catch (Exception $e) {
  686. $trans->rollBack();
  687. return false;
  688. }
  689. return true;
  690. }
  691. public function getStudentByStudentIds($studentIds){
  692. if($studentIds && is_array($studentIds))
  693. {
  694. $rs = $this->sConn->createCommand("select * from student_info where student_id in(".implode(',',$studentIds).")")->queryAll();
  695. if($rs)
  696. {
  697. return $rs;
  698. }
  699. }
  700. return false;
  701. }
  702. /**
  703. * @param $studentsIds
  704. * @param $paper_id
  705. * @param $exam_id
  706. *
  707. */
  708. public function getStudentByStudentIdsAndParperIdAndExamId($studentsIds,$paper_id,$exam_id)
  709. {
  710. $data = array();
  711. $criteria = new CDbCriteria();
  712. $criteria->addCondition('paper_id=:paper_id');
  713. $criteria->addCondition('exam_id=:exam_id');
  714. $criteria->addInCondition('student_id',$studentsIds);
  715. $criteria->addCondition('is_feedback=:is_feedback');
  716. $criteria->addCondition('is_del=:is_del');
  717. $criteria->params[':paper_id'] = $paper_id;
  718. $criteria->params[':exam_id'] = $exam_id;
  719. $criteria->params[':is_feedback'] = 1;
  720. $criteria->params[':is_del'] = 0;
  721. $rs = SStudentPaperRelation::model()->findAll($criteria);
  722. if($rs){
  723. foreach($rs as $v)
  724. {
  725. $data[] = $v->attributes;
  726. }
  727. return $rs;
  728. }
  729. return false;
  730. }
  731. public function delStudentPaperByStudentAndPaperAndExamId($studentsIds,$paper_id)
  732. {
  733. $rs=false;
  734. $trans = $this->sConn->beginTransaction();
  735. try {
  736. $this->sConn->createCommand("update student_paper_relation set is_del=1 where student_id in(".implode(',',$studentsIds).") and paper_id='".$paper_id."' ")->execute();
  737. $this->sConn->createCommand("DELETE FROM student_answer_card_online where student_id in(".implode(',',$studentsIds).") and paper_id='".$paper_id."'")->execute();
  738. // $this->sConn->createCommand("DELETE FROM student_paper_relation_property where student_id in(".implode(',',$studentsIds).") and paper_id=".$paper_id." ")->execute();
  739. $trans->commit();
  740. return true;
  741. } catch (Exception $e) {
  742. $trans->rollBack();
  743. return false;
  744. }
  745. return false;
  746. }
  747. /**
  748. * 获取班级学生
  749. * @param $class_id
  750. *
  751. * @return array|bool|\CDbDataReader
  752. */
  753. public function getClassStudentByClassId($class_id)
  754. {
  755. $rs = $this->sConn->createCommand("select * from student_class_relation where class_id=".$class_id." and status=0")->queryAll();
  756. if($rs){
  757. return $rs;
  758. }
  759. return false;
  760. }
  761. public function getClassPaperByClassAndPaper($class_id,$paper_id,$status=0)
  762. {
  763. $rs = $this->sConn->createCommand("select student_id,paper_id,class_id,exam_id from student_paper_relation where class_id=".$class_id." and paper_id=".$paper_id." and is_del=".$status)->queryAll();
  764. if($rs){
  765. return $rs;
  766. }
  767. return false;
  768. }
  769. public function getClassStudentInfoByClassId($class_id){
  770. $sql="select scr.student_id,realname,scr.class_id from student_class_relation scr join student_info si on si.student_id=scr.student_id where scr.class_id='".$class_id."' and scr.status=0";
  771. //$rs = $this->sConn->createCommand("select student_id,realname,class_id from student_info where class_id=".$class_id)->queryAll();
  772. $rs = $this->sConn->createCommand($sql)->queryAll();
  773. if($rs){
  774. return $rs;
  775. }
  776. return false;
  777. }
  778. public function getStudentByStudentIdsAndParperId($studentsIds,$paper_id,$is_del=0)
  779. {
  780. $rs = $this->sConn->createCommand("select student_id from student_paper_relation where student_id in(".$studentsIds.") and paper_id=".$paper_id." and is_del=".$is_del)->queryAll();
  781. if($rs){
  782. return $rs;
  783. }
  784. return false;
  785. }
  786. public function getStudentsByStudentIdsAndExam_ids($exam_ids,$studentsIds)
  787. {
  788. if($exam_ids && $studentsIds)
  789. {
  790. $rs = $this->sConn->createCommand("select student_id from student_paper_relation where exam_id in ( ".$exam_ids." ) and student_id in(".$studentsIds.") and is_del=0")->queryAll();
  791. if($rs){
  792. return $rs;
  793. }
  794. }
  795. return false;
  796. }
  797. public function addAndUpdateStudentPaper($class_id,$add_student,$exam_id,$semester_id,$paper_id,$student_cards=array(),$school_student_cards=array(),$exam_ids=array(),$grade=array() )
  798. {
  799. $trans = $this->sConn->beginTransaction();
  800. $sql = 'insert into `student_paper_relation` (`student_id`,`paper_id`,`class_id`,`exam_id`,`semester_id`,`student_card`,`school_student_card`,`studytrend_exam_name`)VALUES';
  801. $sql1 = '';
  802. $sqlProperty = 'insert into `student_paper_relation_property` (`student_id`,`paper_id`,`class_id`,`exam_id`,`semester_id`,`create_time`) VALUES';
  803. $sqlPV = '';
  804. try {
  805. if($add_student)
  806. {
  807. $criteria = new CDbCriteria();
  808. $criteria->addCondition('exam_id=:exam_id');
  809. $criteria->addCondition('paper_id = :paper_id');
  810. $criteria->addInCondition('student_id',$add_student);
  811. $criteria->params[':exam_id'] = $exam_id;
  812. $criteria->params[':paper_id'] = $paper_id;
  813. SStudentPaperRelation::model()->deleteAll($criteria);
  814. SStudentPaperRelationProperty::model()->deleteAll($criteria);
  815. foreach($add_student as $student_id)
  816. {
  817. $school_student_card = 0;
  818. $student_card = 0;
  819. if(isset($school_student_cards[$student_id]) && !empty($school_student_cards[$student_id]))
  820. {
  821. $school_student_card = $school_student_cards[$student_id];
  822. }
  823. if(isset($student_cards[$student_id]) && !empty($student_cards[$student_id]))
  824. {
  825. $student_card = $student_cards[$student_id];
  826. $sql1 .= '(' . $student_id . ',' . $paper_id . ','.$class_id.',' .$exam_id. ',' . $semester_id .','.$student_card.',"'.$school_student_card.'",""),';
  827. $sqlPV.= '(' . $student_id . ',' . $paper_id . ','.$class_id.',' .$exam_id. ',' . $semester_id .','.time().'),';
  828. }
  829. }
  830. $sql .= substr($sql1,0,-1).';';
  831. $sqlProperty .= substr($sqlPV,0,-1).';';
  832. $this->sConn->createCommand($sql)->execute();
  833. $this->sConn->createCommand($sqlProperty)->execute();
  834. }
  835. $trans->commit();
  836. } catch (Exception $e) {
  837. $trans->rollBack();
  838. return false;
  839. }
  840. return true;
  841. }
  842. /**
  843. * 刘红伟 end
  844. */
  845. public function semesterAllowToChange($semesterId){
  846. if($semester = $this->getSemester($semesterId)){
  847. if(is_numeric($semester["start_time"]) && ($semester["start_time"] - time()) <= $this->semesterAllowToChangeTime)
  848. return true;
  849. }
  850. return false;
  851. }
  852. public function semesterExists($semesterId){
  853. if(!$semesterId)
  854. return false;
  855. $rs = $this->sConn->createCommand("select exists(select * from semester where semester_id = '{$semesterId}')")->queryRow();
  856. $rs = current($rs);
  857. return $rs ? true : false;
  858. }
  859. public function changeSemester($semesterId){
  860. $code = 1001;
  861. if($semesterId){
  862. $code = array();
  863. if($this->role !== ROLE_SU){
  864. if($this->isPreviousSemester($semesterId))
  865. $code[] = 2001;
  866. if(!$this->semesterAllowToChange($semesterId)){
  867. $code[] = 2002;
  868. }
  869. }
  870. if($code)
  871. return $this->rs($code, __FUNCTION__);
  872. try{
  873. if($this->semesterExists($semesterId)){
  874. $trans = $this->sConn->beginTransaction();
  875. $this->sConn->createCommand("update semester set status = 0 where status = 1")->execute();
  876. $this->sConn->createCommand("update semester set status = 1 where semester_id = '{$semesterId}'")->execute();
  877. $trans->commit();
  878. $rs = true;
  879. }
  880. else
  881. $rs = false;
  882. }
  883. catch(Exception $e){
  884. $trans->rollBack();
  885. $rs = false;
  886. }
  887. if($rs){
  888. if($this->isFutureSemester($semesterId))
  889. $this->activateSemesterClassesStudentsRelations($semesterId);
  890. }
  891. $code = $rs ? 0 : 1002;
  892. }
  893. return $this->rs($code, "global");
  894. }
  895. public function getClassesTeachers($classesIds){
  896. $teachers = array();
  897. if($classesIds){
  898. $classesIds = implode(",", $classesIds);
  899. $rs = $this->sConn->createCommand("
  900. select t.teacher_name , tcr.class_id, c.level,t.subjects
  901. from teacher_class_relation as tcr
  902. join teacher as t on t.teacher_id = tcr.teacher_id
  903. join class as c on c.class_id = tcr.class_id
  904. where tcr.class_id in({$classesIds})
  905. ")->queryAll();
  906. if($rs)
  907. foreach ($rs as $val){
  908. if(isset(Yii::app()->params['subjectId'][$val['subjects']])){
  909. $teachers[(string)$val['class_id']][]=$val['teacher_name'].'('.Yii::app()->params['subjectId'][$val['subjects']].')';
  910. }else{
  911. $teachers[(string)$val['class_id']][]=$val['teacher_name'];
  912. }
  913. }
  914. }
  915. return $teachers;
  916. }
  917. public function getTeachersByclassIdsAndteacherName($classesIds,$teacher_name){
  918. $teachers = array();
  919. if($classesIds){
  920. $classesIds = implode(",", $classesIds);
  921. $rs = $this->sConn->createCommand("
  922. select group_concat(t.teacher_name) as teachers_names, tcr.class_id, c.level
  923. from teacher_class_relation as tcr
  924. join teacher as t on t.teacher_id = tcr.teacher_id
  925. join class as c on c.class_id = tcr.class_id
  926. where tcr.class_id in({$classesIds}) AND t.teacher_name LIKE '%{$teacher_name}%'
  927. group by tcr.class_id
  928. ")->queryAll();
  929. if($rs)
  930. $teachers = $rs;
  931. }
  932. return $teachers;
  933. }
  934. public function getClassPreviousStudentsList($classId, $condition = array(), $pageSize = 9, $type = "OBJ"){
  935. $rs = $this->buildEmptyPagingStruct();
  936. if($classId){
  937. $condition = Arr::merge(array("scr.class_id = '{$classId}'"), $condition);
  938. $condition = $this->condition($condition);
  939. $handle = $this->sConn->createCommand("
  940. select stu.*, scr.userno, scr.serial_number, c.class_name
  941. from student_class_relation as scr
  942. join student_info as stu on stu.student_id = scr.student_id
  943. join class as c on c.class_id = scr.class_id
  944. {$condition}
  945. group by student_id
  946. order by scr.serial_number ASC ,stu.student_id desc
  947. ")->query();
  948. $rs = $this->paging($this->sConn, $handle, $pageSize);
  949. }
  950. return $rs;
  951. }
  952. public function getClassPreviousStudentsListre($classId, $condition = array(), $pageSize = 9, $type = "OBJ"){
  953. $rs = $this->buildEmptyPagingStruct();
  954. if($classId){
  955. $condition = Arr::merge(array("scr.class_id = '{$classId}'"), $condition);
  956. $condition = $this->condition($condition);
  957. $handle = $this->sConn->createCommand("
  958. select stu.*, scr.userno, scr.serial_number, c.class_name
  959. from student_class_relation as scr
  960. join student_info as stu on stu.student_id = scr.student_id and scr.status = 0
  961. join class as c on c.class_id = scr.class_id
  962. {$condition}
  963. group by student_id
  964. order by scr.serial_number ASC ,stu.student_id desc
  965. ")->query();
  966. $rs = $this->paging($this->sConn, $handle, $pageSize);
  967. }
  968. return $rs;
  969. }
  970. public function getClassPreviousStudentsListWithAccounts($classId, $condition = array(), $pageSize = 9){
  971. $rs = $this->getClassPreviousStudentsList($classId, $condition, $pageSize, "ARR");
  972. if($rs["rs"]){
  973. foreach($rs["rs"] as $key => $val){
  974. $rs["rs"][$key]["username"] = "";
  975. $rs["rs"][$key]["status"] = null;
  976. }
  977. $studentsIds = $this->grouping($rs["rs"], "student_id");
  978. $studentsIds = implode("','", $studentsIds);
  979. $studentsIds = "'{$studentsIds}'";
  980. $accounts = $this->conn->createCommand("select * from student where student_id in({$studentsIds})")->queryAll();
  981. if($accounts){
  982. foreach($accounts as $account){
  983. foreach($rs["rs"] as $key => $val){
  984. if($val["student_id"] && $val["student_id"] == $account["student_id"]){
  985. $rs["rs"][$key]["username"] = $account["username"];
  986. $rs["rs"][$key]["status"] = $account["status"];
  987. }
  988. }
  989. }
  990. }
  991. }
  992. return $rs;
  993. }
  994. public function getClass($classId){
  995. $class = array();
  996. if($classId){
  997. $class = $this->sConn->createCommand("select * from class where class_id = '{$classId}'")->queryRow();
  998. }
  999. return $class;
  1000. }
  1001. public function getClassInfo($classId, $type = "ARR"){
  1002. $classInfo = null;
  1003. if($classId){
  1004. $classInfo = $this->sConn->createCommand("
  1005. select c.*, csr.subject_id, csr.material_id, csr.module_ids as modules_ids
  1006. from class as c
  1007. left join class_subject_relation as csr on csr.class_id = c.class_id
  1008. where c.class_id = '{$classId}'
  1009. ")->queryRow();
  1010. if($type == "OBJ"){
  1011. $classInfo = Arr::toObj($classInfo);
  1012. }
  1013. }
  1014. return $classInfo;
  1015. }
  1016. public function getClassTeachersIds($classId){
  1017. $teachersIds = array();
  1018. if($classId){
  1019. $rs = $this->sConn->createCommand("
  1020. select * from teacher_class_relation where class_id = '{$classId}' group by teacher_id
  1021. ")->queryAll();
  1022. if($rs)
  1023. $teachersIds = $this->grouping($rs, "teacher_id");
  1024. }
  1025. return $teachersIds;
  1026. }
  1027. public function semesterHasClass($semesterId){
  1028. if($semesterId){
  1029. $rs = $this->sConn->createCommand("select exists(select * from class where semester_id = '{$semesterId}')")->queryRow();
  1030. return current($rs) ? true : false;
  1031. }
  1032. return false;
  1033. }
  1034. public function classHasStudent($classId){
  1035. if(!($class = $this->getClass($classId)))
  1036. return false;
  1037. $condition = array("class_id = '{$classId}'");
  1038. if($this->isCurrentSemester($class["semester_id"]))
  1039. $condition = Arr::merge($condition, array("status = 0"));
  1040. $condition = $this->condition($condition);
  1041. $rs = $this->sConn->createCommand("select exists(select * from student_class_relation{$condition})")->queryRow();
  1042. $rs = current($rs);
  1043. return $rs ? true : false;
  1044. }
  1045. public function classHasExam($classId){
  1046. if($classId){
  1047. $rs = $this->sConn->createCommand("select exam_id,exam_group_id from exam where class_id = '{$classId}'")->queryAll();
  1048. if($rs){
  1049. return $rs;
  1050. }
  1051. }
  1052. return false;
  1053. }
  1054. public function studentHasPaper($studentId){
  1055. if($studentId){
  1056. $rs = $this->sConn->createCommand("
  1057. select exists(select * from student_paper_relation where semester_id = '{$this->semester["id"]}' and student_id = '{$studentId}' and is_del=0)
  1058. ")->queryRow();
  1059. $rs = current($rs);
  1060. return $rs ? true : false;
  1061. }
  1062. return false;
  1063. }
  1064. public function studentHasPaperInOtherSemesters($studentId){
  1065. if(!$studentId)
  1066. return false;
  1067. $rs = $this->sConn->createCommand("
  1068. select exists(select * from student_paper_relation where semester_id != '{$this->semester["id"]}' and student_id = '{$studentId}') and is_del=0
  1069. ")->queryRow();
  1070. $rs = current($rs);
  1071. return $rs ? true : false;
  1072. }
  1073. public function teacherHasBindedClass($teacherId){
  1074. if($teacherId){
  1075. $rs = $this->sConn->createCommand("select count(*) from teacher_class_relation where teacher_id = '{$teacherId}'")->queryAll();
  1076. return current(current($rs)) > 0 ? true : false;
  1077. }
  1078. return false;
  1079. }
  1080. public function teacherHasCreatedExam($teacherId){
  1081. if($teacherId){
  1082. $rs = $this->sConn->createCommand("select count(*) from exam where teacher_id = '{$teacherId}'")->queryAll();
  1083. return current(current($rs)) > 0 ? true : false;
  1084. }
  1085. return false;
  1086. }
  1087. public function teacherHasMarkingTask($teacherId){
  1088. if($teacherId){
  1089. $rs = $this->sConn->createCommand("select count(*) from marking_task where teacher_id = '{$teacherId}' AND status=0" )->queryAll();
  1090. return current(current($rs)) > 0 ? true : false;
  1091. }
  1092. return false;
  1093. }
  1094. public function teacherHasProblemMark($teacherId){
  1095. if($teacherId){
  1096. $rs = $this->sConn->createCommand("select count(*) from marking_task where teacher_id = '{$teacherId}' AND status=1 AND is_problem=1 AND problem_status=0" )->queryAll();
  1097. return current(current($rs)) > 0 ? true : false;
  1098. }
  1099. return false;
  1100. }
  1101. public function delSemester($semesterId){
  1102. $code = 1001;
  1103. if($semesterId){
  1104. $code = array();
  1105. if($this->role !== ROLE_SU){
  1106. if($this->isCurrentSemester($semesterId))
  1107. $code[] = 2001;
  1108. if($this->semesterHasClass($semesterId))
  1109. $code[] = 2002;
  1110. }
  1111. if($code)
  1112. return $this->rs($code, __FUNCTION__);
  1113. $rs = $this->sConn->createCommand("delete from semester where semester_id = '{$semesterId}'")->execute();
  1114. $code = $rs ? 0 : 1002;
  1115. }
  1116. return $this->rs($code, "global");
  1117. }
  1118. public function CoachdelClass($classId){
  1119. $code = 1001;
  1120. $hasStudent=false;
  1121. $hasExam=false;
  1122. if($classId){
  1123. $code = array();
  1124. if($this->role !== ROLE_SU){
  1125. if($this->classHasStudent($classId)){
  1126. $hasStudent=true;
  1127. $code[] = 2001;
  1128. }
  1129. if($this->classHasExam($classId)){
  1130. $code[] = 2002;
  1131. $hasExam=true;
  1132. }
  1133. }
  1134. if($hasStudent){
  1135. return $this->rs($code, 'delClass');
  1136. }else{
  1137. try{
  1138. $trans = $this->sConn->beginTransaction();
  1139. //查询班级属性
  1140. $classInfo=$this->sConn->createCommand("select class_type from class where class_id = '{$classId}' " )->queryRow();
  1141. if($hasExam){
  1142. //隐藏班级
  1143. $this->sConn->createCommand("UPDATE class SET is_hide = 1 WHERE class_id = '{$classId}'")->execute();
  1144. }else{
  1145. $this->sConn->createCommand("delete from class where class_id = '{$classId}'")->execute();
  1146. $this->sConn->createCommand("delete from class_subject_relation where class_id = '{$classId}'")->execute();
  1147. $this->sConn->createCommand("delete from teacher_class_relation where class_id = '{$classId}'")->execute();
  1148. if($classInfo['class_type']==1){
  1149. //查询行政班学生
  1150. $classStudent=$this->sConn->createCommand("select student_id from student_class_relation WHERE class_id = '{$classId}' and status=0")->queryAll();
  1151. if($classStudent){
  1152. $studentIds=array();
  1153. foreach ($classStudent as $item){
  1154. $studentIds[]=$item['student_id'];
  1155. }
  1156. $this->sConn->createCommand("update student_class_relation set status=1,operation=1 where student_id in(".implode(',',$studentIds).") and status=0")->execute();
  1157. }
  1158. }else{
  1159. $this->sConn->createCommand("UPDATE student_class_relation SET status = 1 WHERE class_id = '{$classId}'")->execute();
  1160. }
  1161. $this->sConn->createCommand("delete from product_class_relation where class_id = '{$classId}'")->execute();
  1162. }
  1163. $trans->commit();
  1164. $rs = true;
  1165. }
  1166. catch(Exception $e){
  1167. $trans->rollBack();
  1168. $rs = false;
  1169. }
  1170. $code = $rs ? 0 : 1002;
  1171. }
  1172. }
  1173. return $this->rs($code, "global");
  1174. }
  1175. public function delClass($classId){
  1176. $code = 1001;
  1177. if($classId){
  1178. $code = array();
  1179. $exam_ids = array();
  1180. $exam_group_ids = array();
  1181. $paper_ids = array();
  1182. $_exam_group_ids = array();
  1183. $exam_group = array();
  1184. //查询班级属性
  1185. $classInfo=$this->sConn->createCommand("select class_type from class where class_id = '{$classId}' " )->queryRow();
  1186. if($this->role !== ROLE_SU){
  1187. $class_exam = $this->classHasExam($classId);
  1188. if($class_exam)
  1189. {
  1190. if(count($class_exam)>2){
  1191. $code[] = 2002;
  1192. }else
  1193. {
  1194. foreach($class_exam as $v)
  1195. {
  1196. $exam_ids[$v['exam_id']] = $v['exam_id'];
  1197. $exam_group_ids[$v['exam_group_id']] = $v['exam_group_id'];
  1198. }
  1199. $papers = $this->sConn->createCommand("select paper_id from paper where exam_id IN (".implode(',',$exam_ids).")")->queryAll();
  1200. if($papers)
  1201. {
  1202. foreach($papers as $v)
  1203. {
  1204. $paper_ids[$v['paper_id']] = $v['paper_id'];
  1205. }
  1206. }
  1207. $exams = $this->sConn->createCommand("select exam_id,exam_group_id from exam where exam_group_id IN (".implode(',',$exam_group_ids).")")->queryAll();
  1208. if($exams)
  1209. {
  1210. foreach ($exams as $v)
  1211. {
  1212. $exam_group[$v['exam_group_id']][] = $v;
  1213. }
  1214. foreach($exam_group_ids as $v)
  1215. {
  1216. if(isset($exam_group[$v]) && !empty($exam_group[$v]) && count($exam_group[$v])==1){
  1217. $_exam_group_ids[] = $v['exam_group_id'];
  1218. }
  1219. }
  1220. }
  1221. }
  1222. }
  1223. }
  1224. if($code)
  1225. return $this->rs($code, __FUNCTION__);
  1226. try{
  1227. $trans = $this->sConn->beginTransaction();
  1228. $this->sConn->createCommand("delete from class where class_id = '{$classId}'")->execute();
  1229. //$this->sConn->createCommand("UPDATE student_info SET class_id = 0 WHERE class_id = '{$classId}'")->execute();
  1230. if($classInfo['class_type']==1){
  1231. //查询行政班学生
  1232. $classStudent=$this->sConn->createCommand("select student_id from student_class_relation WHERE class_id = '{$classId}' and status=0")->queryAll();
  1233. if($classStudent){
  1234. $studentIds=array();
  1235. foreach ($classStudent as $item){
  1236. $studentIds[]=$item['student_id'];
  1237. }
  1238. $this->sConn->createCommand("update student_class_relation set status=1,operation=1 where student_id in(".implode(',',$studentIds).") and status=0")->execute();
  1239. }
  1240. }else{
  1241. $this->sConn->createCommand("UPDATE student_class_relation SET status = 1,operation=1 WHERE class_id = '{$classId}'")->execute();
  1242. }
  1243. $this->sConn->createCommand("delete from class_subject_relation where class_id = '{$classId}'")->execute();
  1244. $this->sConn->createCommand("delete from teacher_class_relation where class_id = '{$classId}'")->execute();
  1245. $this->sConn->createCommand("delete from exam where class_id = '{$classId}'")->execute();
  1246. $this->sConn->createCommand("delete from student_paper_relation where class_id = '{$classId}'")->execute();
  1247. if($paper_ids)
  1248. {
  1249. $this->sConn->createCommand("delete from student_paper_topic_rs where paper_id in (".implode(',',$paper_ids).")")->execute();
  1250. }
  1251. $trans->commit();
  1252. $rs = true;
  1253. }
  1254. catch(Exception $e){
  1255. $trans->rollBack();
  1256. $rs = false;
  1257. }
  1258. $code = $rs ? 0 : 1002;
  1259. }
  1260. return $this->rs($code, "global");
  1261. }
  1262. public function delExam($examId, $type){
  1263. if($examId && $type){
  1264. return $this->sConn->createCommand("delete from exam where exam_id = '{$examId}' and type = '{$type}'")->execute();
  1265. }
  1266. return false;
  1267. }
  1268. public function studentHasBindedClass($studentId){
  1269. if(!$studentId)
  1270. return false;
  1271. $rs = $this->sConn->createCommand("select exists(select * from student_class_relation where student_id = '{$studentId}' and status = 0)")->queryRow();
  1272. $rs = current($rs);
  1273. return $rs ? true : false;
  1274. }
  1275. public function studentAccountExists($studentId){
  1276. if(!$studentId)
  1277. return false;
  1278. $rs = $this->conn->createCommand("select exists(select * from student where student_id = '{$studentId}')")->queryRow();
  1279. $rs = current($rs);
  1280. return $rs ? true : false;
  1281. }
  1282. public function purgeStudent($studentId,$auth=0,$classId=0){
  1283. $code = 1001;
  1284. $msg = '删除成功';
  1285. if($auth==0)
  1286. {
  1287. $rs = true;
  1288. $authUsername = Yii::app()->session['coachInfo']["school_id"] . '_' . Yii::app()->session['coachInfo']["coach_name"];
  1289. $http = http('service/student-delete-perm','post', $authUsername, array($studentId));
  1290. $response = formatResponse($http);
  1291. if(isset($response['data']) && $response['data']){
  1292. if($response['data'][0]['hasOrder']==1){
  1293. $rs=false;
  1294. $code = 2001;
  1295. $msg = '无法操作,该学生已存在订单数据';
  1296. }
  1297. }
  1298. if($studentId && $rs){
  1299. if($classId){
  1300. $student_paper_relation = $this->sConn->createCommand("select * from student_paper_relation where student_id = ".$studentId." and class_id='".$classId."'")->queryRow();
  1301. }else{
  1302. $student_paper_relation = $this->sConn->createCommand("select * from student_paper_relation where student_id = ".$studentId)->queryRow();
  1303. }
  1304. if(!$student_paper_relation)
  1305. {
  1306. $trans1 = $this->sConn->beginTransaction();
  1307. try{
  1308. if($classId){
  1309. $this->sConn->createCommand("update student_class_relation set status = 1,`operation`=1 where student_id = '{$studentId}' and class_id='".$classId."' and status = 0")->execute();
  1310. }else{
  1311. $this->sConn->createCommand("update student_class_relation set status = 1,`operation`=1 where student_id = '{$studentId}' and status = 0")->execute();
  1312. }
  1313. $trans1->commit();
  1314. }
  1315. catch(Exception $e){
  1316. $trans1->rollBack();
  1317. $rs = false;
  1318. $msg = '删除失败';
  1319. }
  1320. $code = $rs ? 0 : 1002;
  1321. }else
  1322. {
  1323. $code = 2001;
  1324. $msg = '无法操作,该学生已存在考试数据';
  1325. }
  1326. }else
  1327. {
  1328. $rs = false;
  1329. if(!$msg){
  1330. $msg = '删除失败';
  1331. }
  1332. $code = $rs ? 0 : 1002;
  1333. }
  1334. }else
  1335. {
  1336. $rs = true;
  1337. if($studentId){
  1338. $trans1 = $this->sConn->beginTransaction();
  1339. try{
  1340. if($classId){
  1341. $this->sConn->createCommand("update student_class_relation set status = 1,`operation`=1 where student_id = '{$studentId}' and class_id='".$classId."' and status = 0")->execute();
  1342. }else{
  1343. $this->sConn->createCommand("update student_class_relation set status = 1,`operation`=1 where student_id = '{$studentId}' and status = 0")->execute();
  1344. }
  1345. $trans1->commit();
  1346. }
  1347. catch(Exception $e){
  1348. $trans1->rollBack();
  1349. $rs = false;
  1350. $msg = '删除失败';
  1351. }
  1352. }else
  1353. {
  1354. $rs = false;
  1355. $msg = '删除失败';
  1356. }
  1357. $code = $rs ? 0 : 1002;
  1358. }
  1359. return array('code'=>$code,'msg'=>$msg);
  1360. }
  1361. public function removeStudentClassRelation($studentId, $classId){
  1362. $code = 1001;
  1363. if($studentId && $classId){
  1364. if($this->role !== ROLE_SU){
  1365. if($this->studentHasPaper($studentId))
  1366. return $this->rs(2001, __FUNCTION__);
  1367. }
  1368. $rs = $this->sConn->createCommand("delete from student_class_relation where student_id = '{$studentId}' and class_id = '{$classId}'")->execute();
  1369. $code = $rs ? 0 : 1002;
  1370. }
  1371. return $this->rs($code, "global");
  1372. }
  1373. public function teacherAccountExists($teacherId){
  1374. if(!$teacherId)
  1375. return false;
  1376. $rs = $this->conn->createCommand("select exists(select * from xb_teacher where teacher_id = '{$teacherId}')")->queryRow();
  1377. $rs = current($rs);
  1378. return $rs ? true : false;
  1379. }
  1380. public function delTeacher($teacherId){
  1381. $code = 1001;
  1382. if($teacherId){
  1383. $code = array();
  1384. if($this->role !== ROLE_SU){
  1385. if($this->teacherHasBindedClass($teacherId))
  1386. $code[] = 2001;
  1387. if($this->teacherHasCreatedExam($teacherId))
  1388. $code[] = 2002;
  1389. }
  1390. if($code)
  1391. return $this->rs($code, __FUNCTION__);
  1392. try{
  1393. $trans1 = $this->sConn->beginTransaction();
  1394. $trans2 = $this->conn->beginTransaction();
  1395. $this->conn->createCommand("update xb_teacher set status = '2' where teacher_id = '{$teacherId}'")->execute();
  1396. $this->sConn->createCommand("update teacher set status = '2' where teacher_id = '{$teacherId}'")->execute();
  1397. $this->kickTeacher($teacherId);
  1398. $trans1->commit();
  1399. $trans2->commit();
  1400. $rs = true;
  1401. }
  1402. catch(Exception $e){
  1403. $trans1->rollBack();
  1404. $trans2->rollBack();
  1405. $rs = false;
  1406. }
  1407. $code = $rs ? 0 : 1002;
  1408. }
  1409. return $this->rs($code, "global");
  1410. }
  1411. public function purgeTeacher($teacherId){
  1412. $code = 1001;
  1413. if($teacherId){
  1414. $code = array();
  1415. $teacherAccountExists = $this->teacherAccountExists($teacherId);
  1416. if($this->role !== ROLE_SU && $teacherAccountExists){
  1417. if($this->teacherHasBindedClass($teacherId))
  1418. $code[] = 2001;
  1419. if($this->teacherHasCreatedExam($teacherId))
  1420. $code[] = 2002;
  1421. if ($this->teacherHasMarkingTask($teacherId))
  1422. $code[] = 2003;
  1423. if ($this->teacherHasProblemMark($teacherId))
  1424. $code[] = 2004;
  1425. }
  1426. if($code)
  1427. return $this->rs($code, __FUNCTION__);
  1428. try{
  1429. $trans1 = $this->sConn->beginTransaction();
  1430. $trans2 = $this->conn->beginTransaction();
  1431. if($teacherAccountExists){
  1432. $this->conn->createCommand("delete from xb_teacher where teacher_id = '{$teacherId}'")->execute();
  1433. }
  1434. $this->sConn->createCommand("delete from teacher where teacher_id = '{$teacherId}'")->execute();
  1435. $this->sConn->createCommand("delete from teacher_class_relation where teacher_id = '{$teacherId}'")->execute();
  1436. $this->kickTeacher($teacherId);
  1437. $trans1->commit();
  1438. $trans2->commit();
  1439. $rs = true;
  1440. }
  1441. catch(Exception $e){
  1442. $trans1->rollBack();
  1443. $trans2->rollBack();
  1444. $rs = false;
  1445. }
  1446. $code = $rs ? 0 : 1002;
  1447. }
  1448. return $this->rs($code, "global");
  1449. }
  1450. public function getSemesters($condition = array(), $orderBy = array("start_time desc"), $offset = 0, $limit = -1){
  1451. $condition = $this->condition($condition);
  1452. $orderBy = $this->orderBy($orderBy);
  1453. $limit = $this->limit($offset, $limit);
  1454. $rs = $this->sConn->createCommand("select * from semester{$condition}{$orderBy}{$limit}")->queryAll();
  1455. return $rs;
  1456. }
  1457. public function getSemestersList($condition = array(), $orderBy = array(), $pageSize = 20){
  1458. $condition = $this->condition($condition);
  1459. $orderBy = $this->orderBy($orderBy);
  1460. $handle = $this->sConn->createCommand("select * from semester{$condition}{$orderBy}")->query();
  1461. $rs = $this->paging($this->sConn, $handle, $pageSize);
  1462. return $rs;
  1463. }
  1464. public function getSemesterIdByClassId($classId){
  1465. $semesterId = null;
  1466. $class = $this->getClass($classId);
  1467. if(!empty($class["semester_id"]))
  1468. $semesterId = $class["semester_id"];
  1469. return $semesterId;
  1470. }
  1471. public function getSemester($semesterId){
  1472. $semester = array();
  1473. if($semesterId){
  1474. $semester = $this->sConn->createCommand("select * from semester where semester_id = '{$semesterId}'")->queryRow();
  1475. }
  1476. return $semester;
  1477. }
  1478. public function getTheYearLastSemester($year){
  1479. if(!$year)
  1480. return array();
  1481. return $this->sConn->createCommand("select * from semester where school_year = '{$year}' order by start_time desc limit 1")->queryRow();
  1482. }
  1483. public function getCurrSemester(){
  1484. return $this->sConn->createCommand("select * from semester where status = '1'")->queryRow();
  1485. }
  1486. public function isCurrentSemester($semesterId){
  1487. $semester = $this->getCurrSemester();
  1488. if($semester && $semester['semester_id']==$semesterId){
  1489. return true;
  1490. }
  1491. return false;
  1492. }
  1493. public function getClassExamsList($classId, $orderBy = array("exam_id desc"), $pageSize = 9){
  1494. $rs = $this->buildEmptyPagingStruct();
  1495. if($classId){
  1496. $orderBy = $this->orderBy($orderBy);
  1497. $handle = $this->sConn->createCommand("
  1498. select e.* from exam as e where e.class_id = '{$classId}' and e.semester_id = '{$this->semester["id"]}' and e.type = 2{$orderBy}
  1499. ")->query();
  1500. $rs = $this->paging($this->sConn, $handle, $pageSize);
  1501. }
  1502. return $rs;
  1503. }
  1504. public function getExamRecordsList($examId, $orderBy = array("record_id asc"), $pageSize = 9){
  1505. $rs = array();
  1506. if($examId){
  1507. $orderBy = $this->orderBy($orderBy);
  1508. $handle = $this->sConn->createCommand("
  1509. select er.*, stu.realname
  1510. from exam_record as er
  1511. join student_info as stu on stu.student_id = er.student_id
  1512. where er.exam_id = '{$examId}'
  1513. {$orderBy}
  1514. ")->query();
  1515. $rs = $this->paging($this->sConn, $handle, $pageSize);
  1516. }
  1517. return $rs;
  1518. }
  1519. public function getExam($examId, $type = "ARR"){
  1520. $exam = array();
  1521. if($examId){
  1522. $exam = $this->sConn->createCommand("select * from exam where exam_id = '{$examId}'")->queryRow();
  1523. if($type == "OBJ"){
  1524. $exam = Arr::toObj($exam);
  1525. }
  1526. }
  1527. return $exam;
  1528. }
  1529. public function getExamClassId($examId){
  1530. if($exam = $this->getExam($examId))
  1531. return $exam["class_id"];
  1532. return null;
  1533. }
  1534. public function isClassExam($classId, $examId){
  1535. $rs = false;
  1536. if($classId && $examId){
  1537. $rs = $this->sConn->createCommand("select exists(select * from exam where exam_id = '{$examId}' and class_id = '{$classId}')")->queryRow();
  1538. $rs = current($rs) ? true : false;
  1539. }
  1540. return $rs;
  1541. }
  1542. public function studentBelongsToClass($studentId, $classId){
  1543. if($studentId && $classId){
  1544. $rs = $this->sConn->createCommand("select exists(select * from student_info where student_id = '{$studentId}' and class_id = '{$classId}')")->queryRow();
  1545. $rs = current($rs);
  1546. if($rs) return true;
  1547. }
  1548. return false;
  1549. }
  1550. public function getMyClassesIds(){
  1551. $ids = array();
  1552. $rs = $this->sConn->createCommand("select * from class where coach_id = '{$this->coachId}'")->queryAll();
  1553. if($rs){
  1554. $ids = $this->grouping($rs, "class_id");
  1555. }
  1556. return $ids;
  1557. }
  1558. public function isMyClass($classId){
  1559. if($classId){
  1560. $myClassesIds = $this->getMyClassesIds();
  1561. if(in_array($classId, $myClassesIds))
  1562. return true;
  1563. }
  1564. return false;
  1565. }
  1566. public function getExamClassesIds($examId){
  1567. $ids = array();
  1568. if($examId){
  1569. $rs = $this->sConn->createCommand("select * from exam where exam_id = '{$examId}'")->queryAll();
  1570. $ids = $this->grouping($rs, "class_id");
  1571. }
  1572. return $ids;
  1573. }
  1574. public function getParentsList($orderBy = array(), $pageSize = 9){
  1575. $handle = $this->conn->createCommand("
  1576. select pa.*
  1577. from student as stu
  1578. join parent_student_relation as psr on psr.student_id = stu.student_id
  1579. join `parent` as pa on pa.parent_id = psr.parent_id and pa.status != 2
  1580. where stu.school_id = '{$this->schoolId}'
  1581. group by pa.parent_id
  1582. ")->query();
  1583. $rs = $this->paging($this->conn, $handle, $pageSize);
  1584. return $rs;
  1585. }
  1586. public function delParentsStudentsRelations($parentsIds){
  1587. if($parentsIds){
  1588. if(!is_array($parentsIds)){
  1589. $parentsIds = array($parentsIds);
  1590. }
  1591. $ids = "";
  1592. foreach($parentsIds as $key => $val){
  1593. $ids .= ",'{$val}'";
  1594. }
  1595. $ids = substr($ids, 1);
  1596. try{
  1597. $trans = $this->sConn->beginTransaction();
  1598. $this->sConn->createCommand("delete from parent_student_relation where parent_id in({$ids})")->execute();
  1599. $trans->commit();
  1600. return true;
  1601. }
  1602. catch(Exception $e){
  1603. $trans->rollBack();
  1604. return false;
  1605. }
  1606. }
  1607. return false;
  1608. }
  1609. public function updateParent($parentId, $parentData){
  1610. $updateKeys = array("phone_number", "password", "realname", "sex", "age", "status", "last_login_time");
  1611. $insertKeys = array("phone_number");
  1612. foreach($parentData as $key => $val){
  1613. switch($key){
  1614. case "phone_number":
  1615. if(!Filter::testPhoneNumber($val))
  1616. return false;
  1617. break;
  1618. case "password":
  1619. if(strlen($val) > 18)
  1620. return false;
  1621. $parentData[$key] = md5(sha1($val));
  1622. break;
  1623. case "realname":
  1624. if(strlen($val) > 10)
  1625. return false;
  1626. break;
  1627. case "sex":
  1628. if(!in_array($val, array("0", "1", "2")))
  1629. return false;
  1630. break;
  1631. case "age":
  1632. if(!is_numeric($val) || $val < 1 || $val > 100)
  1633. return false;
  1634. break;
  1635. case "status":
  1636. if(!in_array($val, array("0", "1", "2")))
  1637. return false;
  1638. break;
  1639. case "last_login_time":
  1640. if(!is_numeric($val) || strlen($val) > 10)
  1641. return false;
  1642. break;
  1643. default:
  1644. break;
  1645. }
  1646. }
  1647. if($parentId){
  1648. $pattern = "";
  1649. foreach($parentData as $key => $val){
  1650. if(!in_array($key, $updateKeys))
  1651. continue;
  1652. $pattern .= ",`{$key}` = '{$val}'";
  1653. }
  1654. $pattern = substr($str, 1);
  1655. if($pattern)
  1656. return $this->conn->createCommand("update parent set {$pattern} where parent_id = '{$parentId}'")->execute();
  1657. }
  1658. else{
  1659. $fields = "";
  1660. $values = "";
  1661. $keys = array();
  1662. foreach($parentData as $key => $val){
  1663. if(!in_array($key, $allowKeys))
  1664. continue;
  1665. $keys[] = $key;
  1666. $fields .= ",`{$key}`";
  1667. $values .= ",'{$val}'";
  1668. }
  1669. if(array_diff($requiredKeys, $keys))
  1670. return false;
  1671. $fields .= ",`signup_time`";
  1672. $values .= ",'".time()."'";
  1673. $fields = substr($fields, 1);
  1674. $values = substr($values, 1);
  1675. return $this->conn->createCommand("insert into parent({$fields}) values({$values})")->execute();
  1676. }
  1677. return false;
  1678. }
  1679. public function addParent($parentData){
  1680. return $this->updateParent(null, $parentData);
  1681. }
  1682. public function getStudentInfo($studentId, $type = "ARRAY"){
  1683. $studentInfo = array();
  1684. if($studentId){
  1685. $studentInfo = $this->sConn->createCommand("
  1686. select stu.student_id, stu.realname, stu.sex, stu.family_tel, stu.telephone, stu.student_phone, stu.picture, stu.signature, stu.add_time,
  1687. stu.update_time,stu.is_outer, scr.userno, scr.serial_number, c.class_name, c.class_id,stu.id_number,stu.field_1,stu.field_2,stu.field_3,stu.field_4,stu.field_5
  1688. from student_info as stu
  1689. join student_class_relation as scr on scr.student_id = stu.student_id and scr.status = 0
  1690. join class as c on c.class_id = scr.class_id
  1691. where stu.student_id = '{$studentId}'
  1692. ")->queryRow();
  1693. if($type == "OBJ")
  1694. $studentInfo = Arr::toObj($studentInfo);
  1695. }
  1696. return $studentInfo;
  1697. }
  1698. public function getStudentInfoByUsername($username){
  1699. $studentInfo = array();
  1700. if($username){
  1701. $rs = $this->conn->createCommand("select * from student where username = '{$username}'")->queryAll();
  1702. if($rs){
  1703. $rs = current($rs);
  1704. $studentInfo = $this->getStudentInfo($rs["student_id"]);
  1705. }
  1706. }
  1707. return $studentInfo;
  1708. }
  1709. public function getStudentParents($studentId){
  1710. $parents = array();
  1711. if($studentId){
  1712. $parents = $this->conn->createCommand("
  1713. select pa.*, pwor.openid
  1714. from parent_student_relation as psr
  1715. join parent as pa on pa.parent_id = psr.parent_id
  1716. join parent_wechat_openid_relation as pwor on pwor.parent_id = psr.parent_id
  1717. where psr.student_id = '{$studentId}'
  1718. group by pa.parent_id
  1719. limit 0, 10
  1720. ")->queryAll();
  1721. }
  1722. return $parents;
  1723. }
  1724. public function insertExamRecord($recordData, $xls){
  1725. if((empty($recordData["exam_id"]) && !isset($_FILES)) || empty($recordData["name"]) || empty($recordData["class_id"]))
  1726. return false;
  1727. $time = time();
  1728. if(isset($xls["error"]) && $xls["error"] == 0){
  1729. $xls = $xls["file"];
  1730. $excel = new Excel();
  1731. $sheetData = $excel->read($xls);
  1732. $studentsCount = 0;
  1733. $students = array();
  1734. $studentsIds = array();
  1735. $notExistStudents = array();
  1736. $notExistStudentsCount = 0;
  1737. $incomplete = array();
  1738. $incompleteCount = 0;
  1739. $notBelongsToClass = array();
  1740. $notBelongsToClassCount = 0;
  1741. $studentsExist = array();
  1742. $studentsExistCount = 0;
  1743. foreach($sheetData as $key => $val){
  1744. $chinese = $val["B"];
  1745. $math = $val["C"];
  1746. $english = $val["D"];
  1747. $physics = $val["E"];
  1748. $chemistry = $val["F"];
  1749. $biology = $val["G"];
  1750. $politics = $val["H"];
  1751. $history = $val["I"];
  1752. $geography = $val["J"];
  1753. $classRank = $val["K"];
  1754. $gradeRank = $val["L"];
  1755. if(Str::isBlank($chinese) && Str::isBlank($math)&& Str::isBlank($english)&& Str::isBlank($physics)&& Str::isBlank($chemistry)&& Str::isBlank($biology)&& Str::isBlank($politics)&& Str::isBlank($history)&& Str::isBlank($geography)&& Str::isBlank($classRank)&& Str::isBlank($gradeRank)){
  1756. continue;
  1757. }
  1758. if(Str::isBlank($chinese) || Str::isBlank($math)|| Str::isBlank($english)|| Str::isBlank($physics)|| Str::isBlank($chemistry)|| Str::isBlank($biology)|| Str::isBlank($politics)|| Str::isBlank($history)|| Str::isBlank($geography)|| Str::isBlank($classRank)|| Str::isBlank($gradeRank)){
  1759. $studentsCount++;
  1760. $incompleteCount++;
  1761. continue;
  1762. }
  1763. $studentsCount++;
  1764. $username = (string)$val["A"];
  1765. $studentInfo = $this->getStudentInfoByUsername($username);
  1766. $studentId = $studentInfo ? $studentInfo["student_id"] : null;
  1767. if(!$studentId){
  1768. $notExistStudents[] = $username;
  1769. $notExistStudentsCount++;
  1770. continue;
  1771. }
  1772. if(!$this->studentBelongsToClass($studentId, $recordData["class_id"])){
  1773. $notBelongsToClass[] = $username;
  1774. $notBelongsToClassCount++;
  1775. continue;
  1776. }
  1777. if(in_array($studentId, $studentsIds)){
  1778. $studentsExist[] = $username;
  1779. $studentsExistCount++;
  1780. continue;
  1781. }
  1782. $studentsIds[] = $studentId;
  1783. $chinese = is_numeric($val["B"]) && $val["B"] ? $val["B"] : 0;
  1784. $math = is_numeric($val["C"]) && $val["C"] ? $val["C"] : 0;
  1785. $english = is_numeric($val["D"]) && $val["D"] ? $val["D"] : 0;
  1786. $physics = is_numeric($val["E"]) && $val["E"] ? $val["E"] : 0;
  1787. $chemistry = is_numeric($val["F"]) && $val["F"] ? $val["F"] : 0;
  1788. $biology = is_numeric($val["G"]) && $val["G"] ? $val["G"] : 0;
  1789. $politics = is_numeric($val["H"]) && $val["H"] ? $val["H"] : 0;
  1790. $history = is_numeric($val["I"]) && $val["I"] ? $val["I"] : 0;
  1791. $geography = is_numeric($val["J"]) && $val["J"] ? $val["J"] : 0;
  1792. $classRank = is_numeric($val["K"]) && $val["K"] ? $val["K"] : 0;
  1793. $gradeRank = is_numeric($val["L"]) && $val["L"] ? $val["L"] : 0;
  1794. $totalScore = $chinese + $math + $english + $physics + $chemistry + $biology + $politics + $history + $geography;
  1795. $students[$studentId]["student_id"] = $studentId;
  1796. $students[$studentId]["subject_chinese"] = $chinese;
  1797. $students[$studentId]["subject_math"] = $math;
  1798. $students[$studentId]["subject_english"] = $english;
  1799. $students[$studentId]["subject_physics"] = $physics;
  1800. $students[$studentId]["subject_chemistry"] = $chemistry;
  1801. $students[$studentId]["subject_biology"] = $biology;
  1802. $students[$studentId]["subject_history"] = $history;
  1803. $students[$studentId]["subject_politics"] = $politics;
  1804. $students[$studentId]["subject_geography"] = $geography;
  1805. $students[$studentId]["total_score"] = $totalScore;
  1806. $students[$studentId]["class_rank"] = $classRank;
  1807. $students[$studentId]["grade_rank"] = $gradeRank;
  1808. }
  1809. $failedCount = $notExistStudentsCount + $incompleteCount + $notBelongsToClassCount + $studentsExistCount;
  1810. $successCount = $studentsCount - $failedCount;
  1811. $result["global"]["msg"] = "从Excel读取了{$studentsCount}条记录,其中{$successCount}导入成功,{$failedCount}条导入失败";
  1812. $result["errors"][0]["type"] = "数据信息不完整";
  1813. $result["errors"][0]["count"] = $incompleteCount;
  1814. $result["errors"][0]["msg"] = "共有{$incompleteCount}行数据不完整,请检查";
  1815. $result["errors"][1]["type"] = "不存在该用户名的学生";
  1816. $result["errors"][1]["count"] = $notExistStudentsCount;
  1817. $notExistStudents = implode(",", $notExistStudents);
  1818. $result["errors"][1]["msg"] = "用户名为{$notExistStudents}的学生无法导入";
  1819. $result["errors"][2]["type"] = "该学生不属于本班级";
  1820. $result["errors"][2]["count"] = $notBelongsToClassCount;
  1821. $notBelongsToClass = implode(",", $notBelongsToClass);
  1822. $result["errors"][2]["msg"] = "用户名为{$notBelongsToClass}的学生无法导入";
  1823. $result["errors"][3]["type"] = "表格中有重复的学生";
  1824. $result["errors"][3]["count"] = $studentsExistCount;
  1825. $studentsExist = implode(",", $studentsExist);
  1826. $result["errors"][3]["msg"] = "用户名为{$studentsExist}的学生无法导入";
  1827. if($failedCount == $studentsCount){
  1828. $result["global"]["result"] = "失败";
  1829. return $result;
  1830. }
  1831. else if($successCount == $studentsCount){
  1832. $result["global"]["result"] = "全部成功";
  1833. unset($result["errors"][0]);
  1834. }
  1835. else{
  1836. $result["global"]["result"] = "部分成功";
  1837. }
  1838. $fields = "";
  1839. $values = array();
  1840. if($students){
  1841. if(!empty($recordData["exam_id"]))
  1842. $examId = $recordData["exam_id"];
  1843. else{
  1844. // $uuid = $this->sConn->createCommand("select RIGHT(UUID_SHORT(), 20)")->queryAll();
  1845. // $examId = current(current($uuid));
  1846. $examId=getUniqueId($this->schoolId);
  1847. }
  1848. $student = current($students);
  1849. foreach($student as $key => $val){
  1850. $fields .= ",`{$key}`";
  1851. }
  1852. $fields .= ",`record_id`";
  1853. $fields .= ",`exam_id`";
  1854. $fields .= ",`coach_id`";
  1855. $fields .= ",`add_time`";
  1856. $fields = "(".substr($fields, 1).")";
  1857. foreach($students as $studentId => $student){
  1858. $values[$studentId] = "";
  1859. foreach($student as $key => $val){
  1860. $values[$studentId] .= ",'{$val}'";
  1861. }
  1862. $uuid=getUniqueId($this->schoolId);
  1863. $values[$studentId] .= ",'{$uuid}'";
  1864. $values[$studentId] .= ",'{$examId}'";
  1865. $values[$studentId] .= ",'{$this->coachId}'";
  1866. $values[$studentId] .= ",'{$time}'";
  1867. $values[$studentId] = "(".substr($values[$studentId], 1).")";
  1868. }
  1869. if($values){
  1870. $values = implode(",", $values);
  1871. $sql = "insert into exam_record{$fields} values{$values}";
  1872. }
  1873. else{
  1874. $sql = "";
  1875. }
  1876. try{
  1877. $trans = $this->sConn->beginTransaction();
  1878. if(isset($recordData["exam_id"]) && $recordData["exam_id"]){
  1879. if(isset($recordData["name"]) && $recordData["name"])
  1880. $this->sConn->createCommand("update exam set name = '{$recordData["name"]}' where exam_id = '{$recordData["exam_id"]}'")->execute();
  1881. if($sql){
  1882. $this->sConn->createCommand("delete from exam_record where exam_id = '{$examId}'")->execute();
  1883. $this->sConn->createCommand($sql)->execute();
  1884. }
  1885. }
  1886. else if($sql){
  1887. $this->sConn->createCommand("
  1888. insert into exam(`exam_id`, `class_id`, `name`, semester_id, `type`, `status`, `create_time`)
  1889. values('{$examId}', '{$recordData["class_id"]}', '{$recordData["name"]}', '{$this->semester["id"]}', 2, 2, '{$time}')
  1890. ")->execute();
  1891. $this->sConn->createCommand($sql)->execute();
  1892. }
  1893. $trans->commit();
  1894. if($students){
  1895. foreach($students as $student){
  1896. if($parents = $this->getStudentParents($student["student_id"])){
  1897. $student = $this->getStudentInfo($student["student_id"]);
  1898. $studentName = $student ? $student["realname"] : "";
  1899. $msg = "您的孩子{$studentName}综合排名有了新的数据, 点击查看";
  1900. $redirectionPath = "home/examrecord?studentId={$student["student_id"]}";
  1901. foreach($parents as $parent){
  1902. $this->writeParentNotification($parent["parent_id"], $msg, 1, $redirectionPath);
  1903. if($parent["openid"])
  1904. send_weixin($parent["openid"], $msg, $this->parentNotificationHost."/home/examrecord?studentId={$student["student_id"]}");
  1905. }
  1906. }
  1907. }
  1908. }
  1909. return $result;
  1910. }
  1911. catch(Exception $e){
  1912. $trans->rollBack();
  1913. return false;
  1914. }
  1915. }
  1916. else if(isset($recordData["name"]) && $recordData["name"] && isset($recordData["exam_id"]) && $recordData["exam_id"])
  1917. return $this->sConn->createCommand("update exam set name = '{$recordData["name"]}' where exam_id = '{$recordData["exam_id"]}'")->execute();
  1918. return false;
  1919. }
  1920. else if(isset($recordData["name"]) && $recordData["name"] && isset($recordData["exam_id"]) && $recordData["exam_id"]){
  1921. return $this->sConn->createCommand("update exam set name = '{$recordData["name"]}' where exam_id = '{$recordData["exam_id"]}'")->execute();
  1922. }
  1923. return false;
  1924. }
  1925. public function getOrdersList($orderBy = array(), $pageSize = 9){
  1926. $orderBy = $this->orderBy($orderBy);
  1927. $handle = $this->conn->createCommand("
  1928. select ord.*
  1929. from order_school_relation as osr
  1930. join `order` as ord on ord.order_id = osr.order_id
  1931. where osr.school_id = '{$this->schoolId}'
  1932. {$orderBy}
  1933. ")->query();
  1934. $rs = $this->paging($this->conn, $handle, $pageSize);
  1935. return $rs;
  1936. }
  1937. public function writeParentNotification($parentId, $content, $type = null, $redirectionPath = ""){
  1938. if($parentId && $content){
  1939. $time = time();
  1940. $fields = "`parent_id`, `content`, `time`";
  1941. $values = "'{$parentId}', '{$content}', '{$time}'";
  1942. if($type){
  1943. $fields .= ", `type`";
  1944. $values .= ", '{$type}'";
  1945. if($type == 1 && $redirectionPath){
  1946. $fields .= ",`redirection_path`";
  1947. $values .= ",'{$redirectionPath}'";
  1948. }
  1949. }
  1950. $sql = "insert into parent_notification({$fields}) values({$values})";
  1951. return $this->conn->createCommand($sql)->execute();
  1952. }
  1953. return false;
  1954. }
  1955. public function getClassStudentsList($classId, $condition = array(), $pageSize = 9, $type = "OBJ"){
  1956. $rs = $this->buildEmptyPagingStruct();
  1957. if($classId){
  1958. $condition = Arr::merge(array("scr.class_id = '{$classId}'", "scr.status = 0"), $condition);
  1959. $condition = $this->condition($condition);
  1960. $handle = $this->sConn->createCommand("
  1961. select stu.*, scr.userno, scr.serial_number, c.grade,c.class_name
  1962. from student_class_relation as scr
  1963. join student_info as stu on stu.student_id = scr.student_id
  1964. join class as c on c.class_id = scr.class_id
  1965. {$condition}
  1966. order by serial_number asc
  1967. ")->query();
  1968. $rs = $this->paging($this->sConn, $handle, $pageSize);
  1969. }
  1970. return $rs;
  1971. }
  1972. public function getInClassStudentsList($classId, $condition = array(), $pageSize = 9, $type = "OBJ"){
  1973. $rs = $this->buildEmptyPagingStruct();
  1974. if($classId){
  1975. $condition = Arr::merge(array("scr.class_id in( ".implode(',',$classId).")", "scr.status = 0"), $condition);
  1976. $condition = $this->condition($condition);
  1977. $handle = $this->sConn->createCommand("
  1978. select stu.*, scr.userno, scr.serial_number, c.grade,c.class_name
  1979. from student_class_relation as scr
  1980. join student_info as stu on stu.student_id = scr.student_id
  1981. join class as c on c.class_id = scr.class_id
  1982. {$condition}
  1983. order by serial_number asc
  1984. ")->query();
  1985. $rs = $this->paging($this->sConn, $handle, $pageSize);
  1986. }
  1987. return $rs;
  1988. }
  1989. public function getStudents($studentsIds = array()){
  1990. $students = array();
  1991. if($studentsIds){
  1992. $studentsIds = "'".implode("','", $studentsIds)."'";
  1993. $students = $this->sConn->createCommand("
  1994. select stu.*, scr.serial_number, scr.userno
  1995. from student_info as stu
  1996. left join student_class_relation as scr on scr.student_id = stu.student_id and scr.status = 0
  1997. where stu.student_id in({$studentsIds})
  1998. order by serial_number asc
  1999. ")->queryAll();
  2000. }
  2001. return $students;
  2002. }
  2003. public function getClassStudents($classId, $condition = array(), $type = "OBJ"){
  2004. $students = array();
  2005. if($classId){
  2006. $condition = Arr::merge(array("scr.class_id = '{$classId}'", "scr.status = 0"), $condition);
  2007. $condition = $this->condition($condition);
  2008. $students = $this->sConn->createCommand("
  2009. select stu.*, scr.userno, scr.serial_number, c.class_name
  2010. from student_class_relation as scr
  2011. join student_info as stu on stu.student_id = scr.student_id
  2012. join class as c on c.class_id = scr.class_id
  2013. {$condition}
  2014. order by serial_number asc
  2015. ")->queryAll();
  2016. }
  2017. if($type == "OBJ")
  2018. $students = Arr::toObj($students);
  2019. return $students;
  2020. }
  2021. public function getClassStudentsListWithAccounts1($classId, $condition = array(), $pageSize = 9,$where=''){
  2022. $student_ids = array();
  2023. if(empty($where))
  2024. {
  2025. if(is_array($classId)){
  2026. $rs = $this->getInClassStudentsList($classId, $condition, $pageSize, "ARR");
  2027. }else{
  2028. $rs = $this->getClassStudentsList($classId, $condition, $pageSize, "ARR");
  2029. }
  2030. }else
  2031. {
  2032. $accounts = $this->conn->createCommand("select * from student where ".$where)->queryRow();
  2033. if($accounts)
  2034. {
  2035. $condition= array("stu.student_id=" . $accounts['student_id']);
  2036. if(is_array($classId)){
  2037. $rs = $this->getInClassStudentsList($classId, $condition, $pageSize, "ARR");
  2038. }else{
  2039. $rs = $this->getClassStudentsList($classId, $condition, $pageSize, "ARR");
  2040. }
  2041. }else
  2042. {
  2043. $rs["rs"] =array();
  2044. $rs['pager'] = (object)array();
  2045. $rs['pager']->rowsCount = 0;
  2046. }
  2047. }
  2048. if($rs["rs"]){
  2049. foreach($rs["rs"] as $key => $val){
  2050. $rs["rs"][$key]["username"] = "";
  2051. $rs["rs"][$key]["status"] = null;
  2052. }
  2053. $studentsIds = $this->grouping($rs["rs"], "student_id");
  2054. $studentsIds = implode("','", $studentsIds);
  2055. $studentsIds = "'{$studentsIds}'";
  2056. if($where)
  2057. {
  2058. $accounts = $this->conn->createCommand("select * from student where ".$where)->queryAll();
  2059. if($accounts){
  2060. foreach($accounts as $account){
  2061. foreach($rs["rs"] as $key => $val){
  2062. if($val["student_id"] && $val["student_id"] == $account["student_id"]){
  2063. $rs["rs"][$key]["username"] = $account["username"];
  2064. $rs["rs"][$key]["student_card"] = $account["student_card"];
  2065. $rs["rs"][$key]["school_student_card"] = $account["school_student_card"];
  2066. if(isset($account["zhixue_student_card"]))
  2067. {
  2068. $rs["rs"][$key]["zhixue_student_card"] = $account["zhixue_student_card"];
  2069. }
  2070. $rs["rs"][$key]["status"] = $account["status"];
  2071. }else
  2072. {
  2073. unset($rs["rs"][$key]);
  2074. $rs['pager']->rowsCount = 0;
  2075. }
  2076. }
  2077. }
  2078. }else
  2079. {
  2080. foreach($rs["rs"] as $key => $val){
  2081. unset($rs["rs"][$key]);
  2082. }
  2083. $rs['pager']->rowsCount = 0;
  2084. }
  2085. }else
  2086. {
  2087. $accounts = $this->conn->createCommand("select * from student where student_id in({$studentsIds})")->queryAll();
  2088. if($accounts){
  2089. foreach($accounts as $account){
  2090. foreach($rs["rs"] as $key => $val){
  2091. if($val["student_id"] && $val["student_id"] == $account["student_id"]){
  2092. $rs["rs"][$key]["username"] = $account["username"];
  2093. $rs["rs"][$key]["student_card"] = $account["student_card"];
  2094. $rs["rs"][$key]["school_student_card"] = $account["school_student_card"];
  2095. if(isset($account["zhixue_student_card"]))
  2096. {
  2097. $rs["rs"][$key]["zhixue_student_card"] = $account["zhixue_student_card"];
  2098. }
  2099. $rs["rs"][$key]["status"] = $account["status"];
  2100. }
  2101. }
  2102. }
  2103. }
  2104. }
  2105. }
  2106. return $rs;
  2107. }
  2108. public function getClassStudentsListWithAccounts($classId, $condition = array(), $pageSize = 9,$where=''){
  2109. $student_ids = array();
  2110. if(empty($where))
  2111. {
  2112. if(is_array($classId)){
  2113. $rs = $this->getInClassStudentsList($classId, $condition, $pageSize, "ARR");
  2114. }else{
  2115. $rs = $this->getClassStudentsList($classId, $condition, $pageSize, "ARR");
  2116. }
  2117. }else
  2118. {
  2119. $accounts = $this->conn->createCommand("select * from student where ".$where)->queryAll();
  2120. if($accounts)
  2121. {
  2122. $studentIdOr=array();
  2123. foreach ($accounts as $v){
  2124. $studentIdOr[]=" stu.student_id=" . $v['student_id']." ";
  2125. }
  2126. $condition= array(" (".implode(' OR ',$studentIdOr).") ","c.class_type=1");
  2127. if(is_array($classId)){
  2128. $rs = $this->getInClassStudentsList($classId, $condition, $pageSize, "ARR");
  2129. }else{
  2130. $rs = $this->getClassStudentsList($classId, $condition, $pageSize, "ARR");
  2131. }
  2132. }else
  2133. {
  2134. $rs["rs"] =array();
  2135. $rs['pager'] = (object)array();
  2136. $rs['pager']->rowsCount = 0;
  2137. }
  2138. }
  2139. //debug($rs["rs"]);
  2140. if($rs["rs"]){
  2141. foreach($rs["rs"] as $key => $val){
  2142. $rs["rs"][$key]["username"] = "";
  2143. $rs["rs"][$key]["status"] = null;
  2144. }
  2145. $studentsIds = $this->grouping($rs["rs"], "student_id");
  2146. $studentsIds = implode("','", $studentsIds);
  2147. $studentsIds = "'{$studentsIds}'";
  2148. if($where)
  2149. {
  2150. $accounts = $this->conn->createCommand("select * from student where ".$where)->queryAll();
  2151. if($accounts){
  2152. $b_student_status = array();
  2153. $b_student_card = array();
  2154. $b_student_username = array();
  2155. $b_school_student_card = array();
  2156. $b_zhixue_student_card = array();
  2157. foreach($accounts as $v)
  2158. {
  2159. $b_student_card[$v['student_id']] = $v['student_card'];
  2160. $b_student_status[$v['student_id']] = $v['status'];
  2161. $b_student_username[$v['student_id']] = $v['username'];
  2162. $b_school_student_card[$v['student_id']] = $v['school_student_card'];
  2163. $b_zhixue_student_card[$v['student_id']] = $v['zhixue_student_card'];
  2164. }
  2165. foreach($rs["rs"] as $key => $val){
  2166. if( isset($b_student_card[$val["student_id"]]) && !empty($b_student_card[$val["student_id"]])){
  2167. $rs["rs"][$key]["username"] = $b_student_username[$val["student_id"]];
  2168. $rs["rs"][$key]["student_card"] = $b_student_card[$val["student_id"]];
  2169. $rs["rs"][$key]["school_student_card"] = $b_school_student_card[$val["student_id"]];
  2170. if(isset($b_zhixue_student_card[$val["student_id"]]))
  2171. {
  2172. $rs["rs"][$key]["zhixue_student_card"] = $b_zhixue_student_card[$val["student_id"]];
  2173. }
  2174. $rs["rs"][$key]["status"] = $b_student_status[$val["student_id"]];
  2175. }else
  2176. {
  2177. unset($rs["rs"][$key]);
  2178. $rs['pager']->rowsCount = 0;
  2179. }
  2180. }
  2181. }else
  2182. {
  2183. foreach($rs["rs"] as $key => $val){
  2184. unset($rs["rs"][$key]);
  2185. }
  2186. $rs['pager']->rowsCount = 0;
  2187. }
  2188. }else
  2189. {
  2190. $accounts = $this->conn->createCommand("select * from student where student_id in ({$studentsIds})")->queryAll();
  2191. if($accounts){
  2192. $b_student_status = array();
  2193. $b_student_card = array();
  2194. $b_student_username = array();
  2195. $b_school_student_card = array();
  2196. $b_zhixue_student_card = array();
  2197. foreach($accounts as $v)
  2198. {
  2199. $b_student_card[$v['student_id']] = $v['student_card'];
  2200. $b_student_status[$v['student_id']] = $v['status'];
  2201. $b_student_username[$v['student_id']] = $v['username'];
  2202. $b_school_student_card[$v['student_id']] = $v['school_student_card'];
  2203. $b_zhixue_student_card[$v['student_id']] = $v['zhixue_student_card'];
  2204. }
  2205. foreach($rs["rs"] as $key => $val){
  2206. if( isset($b_student_card[$val["student_id"]]) && !empty($b_student_card[$val["student_id"]])){
  2207. $rs["rs"][$key]["username"] = $b_student_username[$val["student_id"]];
  2208. $rs["rs"][$key]["student_card"] = $b_student_card[$val["student_id"]];
  2209. $rs["rs"][$key]["school_student_card"] = $b_school_student_card[$val["student_id"]];
  2210. if(isset($b_zhixue_student_card[$val["student_id"]]))
  2211. {
  2212. $rs["rs"][$key]["zhixue_student_card"] = $b_zhixue_student_card[$val["student_id"]];
  2213. }
  2214. $rs["rs"][$key]["status"] = $b_student_status[$val["student_id"]];
  2215. }
  2216. }
  2217. }
  2218. }
  2219. }
  2220. return $rs;
  2221. }
  2222. public function classExamHasPaperRs($examId, $classId){
  2223. if($examId){
  2224. $rs = $this->sConn->createCommand("
  2225. select exists(
  2226. select *
  2227. from exam as e
  2228. join paper as p on p.exam_id = e.exam_id and p.paper_type = 1
  2229. join student_paper_relation as spr on spr.paper_id = p.paper_id and spr.class_id = '{$classId}'
  2230. join student_info as stu on stu.student_id = spr.student_id
  2231. join student_class_relation as scr on scr.student_id = stu.student_id and scr.class_id = '{$classId}'
  2232. where e.exam_id = '{$examId}' and (spr.scoring > 0 or spr.lost_score > 0) and spr.is_del=0
  2233. )
  2234. ")->queryRow();
  2235. $rs = current($rs);
  2236. if($rs) return true;
  2237. }
  2238. return false;
  2239. }
  2240. public function isPreviousSemester($semesterId){
  2241. if(($semester = $this->getSemester($semesterId)) && ($currSemester = $this->getCurrSemester())){
  2242. if($semester["start_time"] < $currSemester["start_time"])
  2243. return true;
  2244. }
  2245. return false;
  2246. }
  2247. public function isFutureSemester($semesterId){
  2248. return !$this->isCurrentSemester($semesterId) && !$this->isPreviousSemester($semesterId) ? true : false;
  2249. }
  2250. public function kickTeacher($teacherId){
  2251. if($teacherId){
  2252. return Redist::del(Yii::app()->session->sessionID);
  2253. }
  2254. return false;
  2255. }
  2256. public function teacherPhoneNumberExists($phoneNumber){
  2257. if($phoneNumber){
  2258. $count = $this->conn->createCommand("select exists(select * from xb_teacher where phone_number = '{$phoneNumber}')")->queryRow();
  2259. $count = current($count);
  2260. return $count ? true : false;
  2261. }
  2262. return false;
  2263. }
  2264. public function getExamRsByClass($examId, $classId, $orderBy = array(), $type = ""){
  2265. if(!$orderBy)
  2266. $orderBy = array("--scr.serial_number asc", "stu.realname asc");
  2267. $orderBy = $this->orderBy($orderBy);
  2268. $rs = $this->sConn->createCommand("
  2269. select stu.student_id, stu.realname, stu.sex, stu.class_id, scr.userno, scr.serial_number, e.exam_id as exam_id, e.name as exam_name, p.paper_name,
  2270. spr.scoring, p.score, p.paper_id, spr.wrong_count, spr.partial_right_count
  2271. from exam as e
  2272. join paper as p on p.exam_id = e.exam_id and p.paper_type = 1
  2273. join student_paper_relation as spr on spr.paper_id = p.paper_id and spr.class_id = '{$classId}'
  2274. join student_info as stu on stu.student_id = spr.student_id
  2275. join student_class_relation as scr on scr.student_id = stu.student_id and scr.class_id = '{$classId}'
  2276. where e.exam_id = '{$examId}' and spr.is_del=0
  2277. {$orderBy}
  2278. ")->queryAll();
  2279. if($rs){
  2280. Arr::sortByField($rs, "scoring", "DESC");
  2281. $previousRecord = 0;
  2282. $previousRank = 1;
  2283. foreach($rs as $key => $val){
  2284. if($val["scoring"] && $val["score"]){
  2285. $rs[$key]["right_rate"] = $val["scoring"] / $val["score"];
  2286. $rs[$key]["right_rate"] = sprintf("%.2f", $rs[$key]["right_rate"]);
  2287. }
  2288. else
  2289. $rs[$key]["right_rate"] = 0;
  2290. if($val["scoring"] && $val["score"]){
  2291. $rs[$key]["scoring_rate"] = $val["scoring"] / $val["score"];
  2292. $rs[$key]["scoring_rate"] = sprintf("%.2f", $rs[$key]["scoring_rate"]);
  2293. }
  2294. else
  2295. $rs[$key]["scoring_rate"] = 0;
  2296. $rs[$key]["wrong_count"] = $val["wrong_count"] + $val["partial_right_count"];
  2297. if($val["scoring"] == $previousRecord){
  2298. $rs[$key]["rank"] = $previousRank;
  2299. }
  2300. else{
  2301. $rs[$key]["rank"] = $key + 1;
  2302. }
  2303. $previousRecord = $val["scoring"];
  2304. $previousRank = $rs[$key]["rank"];
  2305. }
  2306. Arr::sortByField($rs, "serial_number");
  2307. }
  2308. if($type === "EXCEL"){
  2309. $array = array();
  2310. foreach($rs as $key => $val){
  2311. $array[$key] = array(
  2312. $val["serial_number"],
  2313. $val["realname"],
  2314. $val['exam_name'] . ($val["paper_name"] ? ' '.$val['paper_name'] : ''),
  2315. $val["scoring"],
  2316. $val["score"],
  2317. ($val["scoring_rate"] * 100)."%",
  2318. $val["rank"],
  2319. $val["wrong_count"],
  2320. );
  2321. }
  2322. $title = array("编号", "姓名", "试卷", "得分", "总分", "得分率", "班级名次", "错题");
  2323. array_unshift($array, $title);
  2324. $rs = $array;
  2325. }
  2326. return $rs;
  2327. }
  2328. public function serialNumberExistsInClass($serialNumber, $classId, $studentId = null){
  2329. if($serialNumber && $classId){
  2330. $condition = array("class_id = '{$classId}'", "serial_number = '{$serialNumber}'", "status = 0");
  2331. if($studentId)
  2332. $condition = Arr::merge($condition, array("student_id != '{$studentId}'"));
  2333. $condition = $this->condition($condition);
  2334. $rs = $this->sConn->createCommand("select exists(select * from student_class_relation{$condition})")->queryRow();
  2335. $rs = current($rs);
  2336. return $rs ? true : false;
  2337. }
  2338. return false;
  2339. }
  2340. public function getPrintTask($examId, $classId, $type){
  2341. if(!$examId || !$classId || !is_numeric($type))
  2342. return array();
  2343. return $this->sConn->createCommand("select * from class_exam_printer where exam_id = '{$examId}' and class_id = '{$classId}' and `type` = '{$type}'")->queryRow();
  2344. }
  2345. //获取班级多个考试
  2346. public function getClassExamAc($condition = array(), $orderBy = array("add_time desc")){
  2347. $condition = Arr::merge($condition, array("c.semester_id = '{$this->semester["id"]}'"));
  2348. $condition = $this->condition($condition);
  2349. $orderBy = $this->orderBy($orderBy);
  2350. $handle = $this->sConn->createCommand("
  2351. select e.is_academicr_pdf,e.academicr_pdf_path,e.is_topwb_pdf,e.is_new,e.is_topwb_html,cep.*, c.class_name, csr.subject_id, e.name as exam_name, e.upload_status, e.create_time,e.exam_group_id, e.is_display,e.complete_time,e.is_topwb_pdf,e.topwb_pdf_path,e.topwb_pdf_time,e.is_academicr_pdf, eg.mark_type, eg.mark_status,eg.upload_status as group_upload_status,
  2352. p.tpl_doc_src, p.answer_card_src, p.is_labelled,p.paper_id
  2353. from class as c
  2354. join class_subject_relation as csr on csr.class_id = c.class_id
  2355. join exam as e on e.class_id = c.class_id
  2356. join class_exam_printer as cep on cep.class_id = c.class_id and cep.exam_id = e.exam_id
  2357. JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id
  2358. join paper as p on p.exam_id = e.exam_id
  2359. {$condition}
  2360. group by class_id, exam_id, type
  2361. {$orderBy}
  2362. ")->queryAll();
  2363. return $handle;
  2364. }
  2365. public function getPrintListre($condition = array(), $orderBy = array("add_time desc"), $pageSize = 9){
  2366. $condition = Arr::merge($condition, array("c.semester_id = '{$this->semester["id"]}'"));
  2367. $condition = $this->condition($condition);
  2368. $orderBy = $this->orderBy($orderBy);
  2369. $handle = $this->sConn->createCommand("
  2370. select e.is_academicr_pdf,e.academicr_pdf_path,e.is_topwb_pdf,e.is_new,e.is_fine_paper,e.is_topwb_html,cep.*, c.class_name, csr.subject_id, e.name as exam_name, e.tpl_index, e.tpl_data, e.upload_status, e.create_time,e.exam_group_id, e.is_display,e.complete_time,e.is_topwb_pdf,e.topwb_pdf_path,e.topwb_pdf_time,e.is_academicr_pdf, eg.mark_type, eg.mark_status,eg.upload_status as group_upload_status,
  2371. p.tpl_doc_src, p.answer_card_src, p.is_labelled,p.paper_id,eg.is_third,c.grade,e.status,eg.is_tagging,eg.qxk_paper_id
  2372. from class as c
  2373. join class_subject_relation as csr on csr.class_id = c.class_id
  2374. join exam as e on e.class_id = c.class_id
  2375. join class_exam_printer as cep on cep.class_id = c.class_id and cep.exam_id = e.exam_id
  2376. JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id
  2377. join paper as p on p.exam_id = e.exam_id
  2378. {$condition}
  2379. group by class_id, exam_id, type
  2380. {$orderBy}
  2381. ")->query();
  2382. $rs = $this->paging($this->sConn, $handle, $pageSize);
  2383. $examsIds = $this->grouping($rs["rs"], "exam_id", true);
  2384. $examsIds = "'".implode("','", $examsIds)."'";
  2385. $sprs = $this->sConn->createCommand("select exam_id, is_complete, is_feedback,is_wrongbook_pdf,is_wbisp_pdf,is_isp_pdf from student_paper_relation where exam_id in({$examsIds}) ")->queryAll();
  2386. $examsSprs = array();
  2387. foreach($sprs as $key => $val){
  2388. if(!isset($examsSprs[$val["exam_id"]]))
  2389. $examsSprs[$val["exam_id"]] = array();
  2390. $examsSprs[$val["exam_id"]][] = $val;
  2391. }
  2392. $examsStudentsCount = array();
  2393. foreach($examsSprs as $examId => $sprs){
  2394. $examsStudentsCount[$examId] = array(
  2395. "is_complete_count" => 0,
  2396. "is_uploaded_count" => 0,
  2397. "wrongbook_pdf_count" => 0,
  2398. "wbisp_pdf_count" => 0,
  2399. "isp_pdf_count" => 0,
  2400. );
  2401. $examsStudentsCount[$examId]["students_count"] = count($sprs);
  2402. foreach($sprs as $k => $v){
  2403. if($v["is_complete"] == 1){
  2404. $examsStudentsCount[$examId]["is_complete_count"]++;
  2405. }
  2406. $examsStudentsCount[$examId]["is_uploaded_count"]++;
  2407. if($v["is_wrongbook_pdf"] == 1)
  2408. {
  2409. $examsStudentsCount[$examId]["wrongbook_pdf_count"]++;
  2410. }
  2411. if($v["is_wbisp_pdf"] == 1)
  2412. {
  2413. $examsStudentsCount[$examId]["wbisp_pdf_count"]++;
  2414. }
  2415. if($v["is_isp_pdf"] == 1)
  2416. {
  2417. $examsStudentsCount[$examId]["isp_pdf_count"]++;
  2418. }
  2419. }
  2420. }
  2421. foreach($rs["rs"] as $key => $val){
  2422. if(isset($examsStudentsCount[$val["exam_id"]])){
  2423. $rs["rs"][$key]["students_count"] = $examsStudentsCount[$val["exam_id"]]["students_count"];
  2424. $rs["rs"][$key]["is_complete_count"] = $examsStudentsCount[$val["exam_id"]]["is_complete_count"];
  2425. $rs["rs"][$key]["is_uploaded_count"] = $examsStudentsCount[$val["exam_id"]]["is_uploaded_count"];
  2426. $rs["rs"][$key]["wrongbook_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wrongbook_pdf_count"];
  2427. $rs["rs"][$key]["wbisp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wbisp_pdf_count"];
  2428. $rs["rs"][$key]["isp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["isp_pdf_count"];
  2429. }
  2430. else{
  2431. $rs["rs"][$key]["students_count"] = 0;
  2432. $rs["rs"][$key]["is_complete_count"] = 0;
  2433. $rs["rs"][$key]["is_uploaded_count"] = 0;
  2434. $rs["rs"][$key]["wrongbook_pdf_count"] = 0;
  2435. $rs["rs"][$key]["wbisp_pdf_count"] = 0;
  2436. $rs["rs"][$key]["isp_pdf_count"] = 0;
  2437. }
  2438. $tplData = json_decode($val["tpl_data"], true);
  2439. $paperSize = null;
  2440. $examDate = null;
  2441. if(in_array($val["tpl_index"], Yii::app()->params["custom_tpls_ids"])){
  2442. switch($val["tpl_index"]){
  2443. case "12":
  2444. $paperSize = "A3";
  2445. break;
  2446. case "13":
  2447. $paperSize = "A4";
  2448. break;
  2449. case "14":
  2450. $paperSize = "8K";
  2451. break;
  2452. case "15":
  2453. $paperSize = "16K";
  2454. break;
  2455. case "2012":
  2456. $paperSize = "A3";
  2457. break;
  2458. case "2013":
  2459. $paperSize = "A4";
  2460. break;
  2461. case "2014":
  2462. $paperSize = "8K";
  2463. break;
  2464. case "2015":
  2465. $paperSize = "16K";
  2466. break;
  2467. case "2016":
  2468. $paperSize = "A3";
  2469. break;
  2470. case "2017":
  2471. $paperSize = "A4";
  2472. break;
  2473. case "2018":
  2474. $paperSize = "8K";
  2475. break;
  2476. case "2019":
  2477. $paperSize = "16K";
  2478. break;
  2479. case "1012":
  2480. $paperSize = "A3";
  2481. break;
  2482. case "1013":
  2483. $paperSize = "A4";
  2484. break;
  2485. case "1014":
  2486. $paperSize = "8K";
  2487. break;
  2488. case "1015":
  2489. $paperSize = "16K";
  2490. break;
  2491. case "1016":
  2492. $paperSize = "A3";
  2493. break;
  2494. case "1017":
  2495. $paperSize = "A4";
  2496. break;
  2497. case "1018":
  2498. $paperSize = "8K";
  2499. break;
  2500. case "1019":
  2501. $paperSize = "16K";
  2502. break;
  2503. case "3012":
  2504. $paperSize = "A3";
  2505. break;
  2506. case "3016":
  2507. $paperSize = "A3";
  2508. break;
  2509. }
  2510. }
  2511. if(in_array($val["tpl_index"], Yii::app()->params["custom_tpls_ids"])){
  2512. switch($val["tpl_index"]){
  2513. case "16":
  2514. $paperSize = "A3";
  2515. break;
  2516. case "3016":
  2517. $paperSize = "A3";
  2518. break;
  2519. case "3007":
  2520. $paperSize = "A3";
  2521. break;
  2522. case "3012":
  2523. $paperSize = "A3";
  2524. break;
  2525. case "17":
  2526. $paperSize = "A4";
  2527. break;
  2528. case "18":
  2529. $paperSize = "8K";
  2530. break;
  2531. case "19":
  2532. $paperSize = "16K";
  2533. break;
  2534. }
  2535. }
  2536. if($tplData){
  2537. if(!isset($tplData["examDate"]) || !($examDate = strtotime($tplData["examDate"])))
  2538. $examDate = $val["create_time"];
  2539. if($paperSize === null && isset($tplData["paper"]) && $tplData["paper"] == 1)
  2540. $paperSize = "A3";
  2541. $rs["rs"][$key]["topic_count"] = isset($tplData['totals'])?$tplData['totals']:0;
  2542. }
  2543. if($examDate === null)
  2544. $examDate = $val["create_time"];
  2545. if($paperSize === null)
  2546. $paperSize = "A4";
  2547. $time = time();
  2548. $expireTime = $examDate + (3600 * 24 * 2);
  2549. if($time > $expireTime){
  2550. $rs["rs"][$key]["is_expired"] = true;
  2551. }
  2552. else{
  2553. $rs["rs"][$key]["is_expired"] = false;
  2554. }
  2555. $rs["rs"][$key]["exam_time"] = $examDate;
  2556. $rs["rs"][$key]["paper_size"] = $paperSize;
  2557. }
  2558. return $rs;
  2559. }
  2560. //获取下载班级
  2561. public function getDownloadClassWb($condition = array(), $orderBy = array("add_time desc")){
  2562. $condition = Arr::merge($condition, array("c.semester_id = '{$this->semester["id"]}'"));
  2563. $condition = $this->condition($condition);
  2564. $orderBy = $this->orderBy($orderBy);
  2565. $rs['rs'] = $this->sConn->createCommand("
  2566. select cep.*, c.class_name, csr.subject_id, e.name as exam_name,e.is_new, e.upload_status, e.create_time, e.is_display,eg.upload_status as group_upload_status, eg.mark_type, eg.mark_status,e.exam_group_id,p.tpl_doc_src, p.answer_card_src, p.is_labelled,p.paper_id
  2567. from class as c
  2568. join class_subject_relation as csr on csr.class_id = c.class_id
  2569. join exam as e on e.class_id = c.class_id
  2570. join class_exam_printer as cep on cep.class_id = c.class_id and cep.exam_id = e.exam_id
  2571. JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id
  2572. join paper as p on p.exam_id = e.exam_id
  2573. {$condition}
  2574. group by class_id, exam_id, type
  2575. {$orderBy}
  2576. ")->queryAll();
  2577. $examsIds = $this->grouping($rs["rs"], "exam_id", true);
  2578. $examsIds = "'".implode("','", $examsIds)."'";
  2579. $sprs = $this->sConn->createCommand("select exam_id, is_complete, is_feedback,is_wrongbook_pdf,is_wbisp_pdf,is_isp_pdf from student_paper_relation where exam_id in({$examsIds}) and is_del=0")->queryAll();
  2580. $examsSprs = array();
  2581. foreach($sprs as $key => $val){
  2582. if(!isset($examsSprs[$val["exam_id"]]))
  2583. $examsSprs[$val["exam_id"]] = array();
  2584. $examsSprs[$val["exam_id"]][] = $val;
  2585. }
  2586. $examsStudentsCount = array();
  2587. foreach($examsSprs as $examId => $sprs){
  2588. $examsStudentsCount[$examId] = array(
  2589. "is_complete_count" => 0,
  2590. "is_uploaded_count" => 0,
  2591. "wrongbook_pdf_count" => 0,
  2592. "wbisp_pdf_count" => 0,
  2593. "isp_pdf_count" => 0,
  2594. );
  2595. $examsStudentsCount[$examId]["students_count"] = count($sprs);
  2596. foreach($sprs as $k => $v){
  2597. if($v["is_complete"] == 1)
  2598. {
  2599. $examsStudentsCount[$examId]["is_complete_count"]++;
  2600. }
  2601. if($v["is_feedback"] == 1)
  2602. {
  2603. $examsStudentsCount[$examId]["is_uploaded_count"]++;
  2604. }
  2605. if($v["is_wrongbook_pdf"] == 1)
  2606. {
  2607. $examsStudentsCount[$examId]["wrongbook_pdf_count"]++;
  2608. }
  2609. if($v["is_wbisp_pdf"] == 1)
  2610. {
  2611. $examsStudentsCount[$examId]["wbisp_pdf_count"]++;
  2612. }
  2613. if($v["is_isp_pdf"] == 1)
  2614. {
  2615. $examsStudentsCount[$examId]["isp_pdf_count"]++;
  2616. }
  2617. }
  2618. }
  2619. foreach($rs["rs"] as $key => $val){
  2620. if(isset($examsStudentsCount[$val["exam_id"]])){
  2621. $rs["rs"][$key]["students_count"] = $examsStudentsCount[$val["exam_id"]]["students_count"];
  2622. $rs["rs"][$key]["is_complete_count"] = $examsStudentsCount[$val["exam_id"]]["is_complete_count"];
  2623. $rs["rs"][$key]["is_uploaded_count"] = $examsStudentsCount[$val["exam_id"]]["is_uploaded_count"];
  2624. $rs["rs"][$key]["wrongbook_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wrongbook_pdf_count"];
  2625. $rs["rs"][$key]["wbisp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wbisp_pdf_count"];
  2626. $rs["rs"][$key]["isp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["isp_pdf_count"];
  2627. }
  2628. else{
  2629. $rs["rs"][$key]["students_count"] = 0;
  2630. $rs["rs"][$key]["is_complete_count"] = 0;
  2631. $rs["rs"][$key]["is_uploaded_count"] = 0;
  2632. $rs["rs"][$key]["wrongbook_pdf_count"] = 0;
  2633. $rs["rs"][$key]["wbisp_pdf_count"] = 0;
  2634. $rs["rs"][$key]["isp_pdf_count"] = 0;
  2635. }
  2636. }
  2637. return $rs["rs"];
  2638. }
  2639. public function getPrintList($condition = array(), $orderBy = array("add_time desc"), $pageSize = 9){
  2640. $condition = Arr::merge($condition, array("c.semester_id = '{$this->semester["id"]}'"));
  2641. $condition = $this->condition($condition);
  2642. $orderBy = $this->orderBy($orderBy);
  2643. $handle = $this->sConn->createCommand("
  2644. select cep.*, c.class_name, csr.subject_id, e.name as exam_name,e.is_new, e.tpl_index, e.tpl_data, e.upload_status, e.create_time, e.is_display,eg.upload_status as group_upload_status, eg.mark_type, eg.mark_status,e.exam_group_id,p.tpl_doc_src, p.answer_card_src, p.is_labelled,p.paper_id
  2645. from class as c
  2646. join class_subject_relation as csr on csr.class_id = c.class_id
  2647. join exam as e on e.class_id = c.class_id
  2648. join class_exam_printer as cep on cep.class_id = c.class_id and cep.exam_id = e.exam_id
  2649. JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id
  2650. join paper as p on p.exam_id = e.exam_id
  2651. {$condition}
  2652. group by class_id, exam_id, type
  2653. {$orderBy}
  2654. ")->query();
  2655. $rs = $this->paging($this->sConn, $handle, $pageSize);
  2656. $examsIds = $this->grouping($rs["rs"], "exam_id", true);
  2657. $examsIds = "'".implode("','", $examsIds)."'";
  2658. $sprs = $this->sConn->createCommand("select exam_id, is_complete, is_feedback,is_wrongbook_pdf,is_wbisp_pdf,is_isp_pdf from student_paper_relation where exam_id in({$examsIds}) and is_del=0")->queryAll();
  2659. $examsSprs = array();
  2660. foreach($sprs as $key => $val){
  2661. if(!isset($examsSprs[$val["exam_id"]]))
  2662. $examsSprs[$val["exam_id"]] = array();
  2663. $examsSprs[$val["exam_id"]][] = $val;
  2664. }
  2665. $examsStudentsCount = array();
  2666. foreach($examsSprs as $examId => $sprs){
  2667. $examsStudentsCount[$examId] = array(
  2668. "is_complete_count" => 0,
  2669. "is_uploaded_count" => 0,
  2670. "wrongbook_pdf_count" => 0,
  2671. "wbisp_pdf_count" => 0,
  2672. "isp_pdf_count" => 0,
  2673. );
  2674. $examsStudentsCount[$examId]["students_count"] = count($sprs);
  2675. foreach($sprs as $k => $v){
  2676. if($v["is_complete"] == 1)
  2677. {
  2678. $examsStudentsCount[$examId]["is_complete_count"]++;
  2679. }
  2680. if($v["is_feedback"] == 1)
  2681. {
  2682. $examsStudentsCount[$examId]["is_uploaded_count"]++;
  2683. }
  2684. if($v["is_wrongbook_pdf"] == 1)
  2685. {
  2686. $examsStudentsCount[$examId]["wrongbook_pdf_count"]++;
  2687. }
  2688. if($v["is_wbisp_pdf"] == 1)
  2689. {
  2690. $examsStudentsCount[$examId]["wbisp_pdf_count"]++;
  2691. }
  2692. if($v["is_isp_pdf"] == 1)
  2693. {
  2694. $examsStudentsCount[$examId]["isp_pdf_count"]++;
  2695. }
  2696. }
  2697. }
  2698. foreach($rs["rs"] as $key => $val){
  2699. if(isset($examsStudentsCount[$val["exam_id"]])){
  2700. $rs["rs"][$key]["students_count"] = $examsStudentsCount[$val["exam_id"]]["students_count"];
  2701. $rs["rs"][$key]["is_complete_count"] = $examsStudentsCount[$val["exam_id"]]["is_complete_count"];
  2702. $rs["rs"][$key]["is_uploaded_count"] = $examsStudentsCount[$val["exam_id"]]["is_uploaded_count"];
  2703. $rs["rs"][$key]["wrongbook_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wrongbook_pdf_count"];
  2704. $rs["rs"][$key]["wbisp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wbisp_pdf_count"];
  2705. $rs["rs"][$key]["isp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["isp_pdf_count"];
  2706. }
  2707. else{
  2708. $rs["rs"][$key]["students_count"] = 0;
  2709. $rs["rs"][$key]["is_complete_count"] = 0;
  2710. $rs["rs"][$key]["is_uploaded_count"] = 0;
  2711. $rs["rs"][$key]["wrongbook_pdf_count"] = 0;
  2712. $rs["rs"][$key]["wbisp_pdf_count"] = 0;
  2713. $rs["rs"][$key]["isp_pdf_count"] = 0;
  2714. }
  2715. $tplData = json_decode($val["tpl_data"], true);
  2716. $paperSize = null;
  2717. $examDate = null;
  2718. if(in_array($val["tpl_index"], Yii::app()->params["custom_tpls_ids"])){
  2719. switch($val["tpl_index"]){
  2720. case "12":
  2721. $paperSize = "A3";
  2722. break;
  2723. case "13":
  2724. $paperSize = "A4";
  2725. break;
  2726. case "14":
  2727. $paperSize = "8K";
  2728. break;
  2729. case "15":
  2730. $paperSize = "16K";
  2731. break;
  2732. case "2012":
  2733. $paperSize = "A3";
  2734. break;
  2735. case "2013":
  2736. $paperSize = "A4";
  2737. break;
  2738. case "2014":
  2739. $paperSize = "8K";
  2740. break;
  2741. case "2015":
  2742. $paperSize = "16K";
  2743. break;
  2744. case "2016":
  2745. $paperSize = "A3";
  2746. break;
  2747. case "2017":
  2748. $paperSize = "A4";
  2749. break;
  2750. case "2018":
  2751. $paperSize = "8K";
  2752. break;
  2753. case "2019":
  2754. $paperSize = "16K";
  2755. break;
  2756. case "1012":
  2757. $paperSize = "A3";
  2758. break;
  2759. case "1013":
  2760. $paperSize = "A4";
  2761. break;
  2762. case "1014":
  2763. $paperSize = "8K";
  2764. break;
  2765. case "1015":
  2766. $paperSize = "16K";
  2767. break;
  2768. case "1016":
  2769. $paperSize = "A3";
  2770. break;
  2771. case "1017":
  2772. $paperSize = "A4";
  2773. break;
  2774. case "1018":
  2775. $paperSize = "8K";
  2776. break;
  2777. case "1019":
  2778. $paperSize = "16K";
  2779. break;
  2780. case "3016":
  2781. $paperSize = "A3";
  2782. break;
  2783. case "3012":
  2784. $paperSize = "A3";
  2785. break;
  2786. case "3013":
  2787. $paperSize = "A4";
  2788. break;
  2789. case "3017":
  2790. $paperSize = "A4";
  2791. break;
  2792. }
  2793. }
  2794. if(in_array($val["tpl_index"], Yii::app()->params["custom_tpls_ids"])){
  2795. switch($val["tpl_index"]){
  2796. case "16":
  2797. $paperSize = "A3";
  2798. break;
  2799. case "3016":
  2800. $paperSize = "A3";
  2801. break;
  2802. case "3017":
  2803. $paperSize = "A4";
  2804. break;
  2805. case "3013":
  2806. $paperSize = "A4";
  2807. break;
  2808. case "3007":
  2809. $paperSize = "A3";
  2810. break;
  2811. case "17":
  2812. $paperSize = "A4";
  2813. break;
  2814. case "18":
  2815. $paperSize = "8K";
  2816. break;
  2817. case "19":
  2818. $paperSize = "16K";
  2819. break;
  2820. }
  2821. }
  2822. if($tplData){
  2823. if(!isset($tplData["examDate"]) || !($examDate = strtotime($tplData["examDate"])))
  2824. $examDate = $val["create_time"];
  2825. if($paperSize === null && isset($tplData["paper"]) && $tplData["paper"] == 1)
  2826. $paperSize = "A3";
  2827. }
  2828. if($examDate === null)
  2829. $examDate = $val["create_time"];
  2830. if($paperSize === null)
  2831. $paperSize = "A4";
  2832. $time = time();
  2833. $expireTime = $examDate + (3600 * 24 * 2);
  2834. if($time > $expireTime){
  2835. $rs["rs"][$key]["is_expired"] = true;
  2836. }
  2837. else{
  2838. $rs["rs"][$key]["is_expired"] = false;
  2839. }
  2840. $rs["rs"][$key]["exam_time"] = $examDate;
  2841. $rs["rs"][$key]["paper_size"] = $paperSize;
  2842. }
  2843. return $rs;
  2844. }
  2845. public function getExamList($condition = array(), $orderBy = array("add_time desc"), $pageSize = 9){
  2846. $condition = Arr::merge($condition, array("c.semester_id = '{$this->semester["id"]}'"));
  2847. $condition = $this->condition($condition);
  2848. $orderBy = $this->orderBy($orderBy);
  2849. $handle = $this->sConn->createCommand("
  2850. select c.class_name,e.exam_id,eg.exam_group_id,e.class_id, csr.subject_id, e.name as exam_name,e.is_new, e.tpl_index, e.tpl_data, e.upload_status, e.create_time, e.is_display, e.status, eg.mark_type, eg.mark_status,
  2851. p.tpl_doc_src, p.answer_card_src, p.is_labelled,p.paper_id,eg.import_score_type
  2852. from class as c
  2853. join class_subject_relation as csr on csr.class_id = c.class_id
  2854. join exam as e on e.class_id = c.class_id
  2855. JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id
  2856. join paper as p on p.exam_id = e.exam_id
  2857. {$condition}
  2858. group by e.class_id, e.exam_id, e.`type`
  2859. {$orderBy}
  2860. ")->query();
  2861. $rs = $this->paging($this->sConn, $handle, $pageSize);
  2862. $examsIds = $this->grouping($rs["rs"], "exam_id", true);
  2863. $examsIds = "'".implode("','", $examsIds)."'";
  2864. $sprs = $this->sConn->createCommand("select paper_id,exam_id, is_complete, is_feedback,is_wrongbook_pdf,is_wbisp_pdf,is_isp_pdf,student_img_paper from student_paper_relation where exam_id in({$examsIds}) and is_del=0")->queryAll();
  2865. $examsSprs = array();
  2866. $paperExamIds=array();
  2867. foreach($sprs as $key => $val){
  2868. if(!isset($examsSprs[$val["exam_id"]]))
  2869. $examsSprs[$val["exam_id"]] = array();
  2870. $examsSprs[$val["exam_id"]][] = $val;
  2871. $paperExamIds[$val["exam_id"]]=$val["paper_id"];
  2872. }
  2873. $importScoretype=$this->grouping($rs["rs"], "import_score_type", true);
  2874. //判断上传成绩方式
  2875. $student_answer_img_num=array();
  2876. //导入方式,读取实际上传数量
  2877. foreach($paperExamIds as $eid =>$paperId){
  2878. $student_answer_img_num[$eid]=$this->getUpAnswerStudent($paperId,array(),true);
  2879. }
  2880. $examsStudentsCount = array();
  2881. foreach($examsSprs as $examId => $sprs){
  2882. $examsStudentsCount[$examId] = array(
  2883. "is_complete_count" => 0,
  2884. "is_uploaded_count" => 0,
  2885. "student_img_count" => 0,
  2886. "wrongbook_pdf_count" => 0,
  2887. "wbisp_pdf_count" => 0,
  2888. "isp_pdf_count" => 0,
  2889. 'student_img_up_num'
  2890. );
  2891. $examsStudentsCount[$examId]["students_count"] = count($sprs);
  2892. foreach($sprs as $k => $v){
  2893. if($v["is_complete"] == 1)
  2894. {
  2895. $examsStudentsCount[$examId]["is_complete_count"]++;
  2896. }
  2897. if($v["is_feedback"] == 1)
  2898. {
  2899. $examsStudentsCount[$examId]["is_uploaded_count"]++;
  2900. }
  2901. if(trim($v["student_img_paper"]))
  2902. {
  2903. $examsStudentsCount[$examId]["student_img_count"]++;
  2904. }
  2905. if($v["is_wrongbook_pdf"] == 1)
  2906. {
  2907. $examsStudentsCount[$examId]["wrongbook_pdf_count"]++;
  2908. }
  2909. if($v["is_wbisp_pdf"] == 1)
  2910. {
  2911. $examsStudentsCount[$examId]["wbisp_pdf_count"]++;
  2912. }
  2913. if($v["is_isp_pdf"] == 1)
  2914. {
  2915. $examsStudentsCount[$examId]["isp_pdf_count"]++;
  2916. }
  2917. }
  2918. if(isset($student_answer_img_num[$examId])){
  2919. $examsStudentsCount[$examId]["student_img_up_num"]=$student_answer_img_num[$examId];
  2920. }else{
  2921. $examsStudentsCount[$examId]["student_img_up_num"]=0;
  2922. }
  2923. }
  2924. foreach($rs["rs"] as $key => $val){
  2925. if(isset($examsStudentsCount[$val["exam_id"]])){
  2926. $rs["rs"][$key]["students_count"] = $examsStudentsCount[$val["exam_id"]]["students_count"];
  2927. $rs["rs"][$key]["is_complete_count"] = $examsStudentsCount[$val["exam_id"]]["is_complete_count"];
  2928. $rs["rs"][$key]["is_uploaded_count"] = $examsStudentsCount[$val["exam_id"]]["is_uploaded_count"];
  2929. $rs["rs"][$key]["student_img_count"] = $examsStudentsCount[$val["exam_id"]]["student_img_count"];
  2930. $rs["rs"][$key]["wrongbook_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wrongbook_pdf_count"];
  2931. $rs["rs"][$key]["wbisp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wbisp_pdf_count"];
  2932. $rs["rs"][$key]["isp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["isp_pdf_count"];
  2933. $rs["rs"][$key]["student_img_up_num"] = $examsStudentsCount[$val["exam_id"]]["student_img_up_num"];
  2934. }
  2935. else{
  2936. $rs["rs"][$key]["students_count"] = 0;
  2937. $rs["rs"][$key]["is_complete_count"] = 0;
  2938. $rs["rs"][$key]["is_uploaded_count"] = 0;
  2939. $rs["rs"][$key]["student_img_count"] = 0;
  2940. $rs["rs"][$key]["wrongbook_pdf_count"] = 0;
  2941. $rs["rs"][$key]["wbisp_pdf_count"] = 0;
  2942. $rs["rs"][$key]["isp_pdf_count"] = 0;
  2943. $rs["rs"][$key]["student_img_up_num"] = 0;
  2944. }
  2945. $tplData = json_decode($val["tpl_data"], true);
  2946. $paperSize = null;
  2947. $examDate = null;
  2948. if($tplData){
  2949. if(!isset($tplData["examDate"]) || !($examDate = strtotime($tplData["examDate"])))
  2950. $examDate = $val["create_time"];
  2951. if($paperSize === null && isset($tplData["paper"]) && $tplData["paper"] == 1)
  2952. $paperSize = "A3";
  2953. }
  2954. if($examDate === null)
  2955. $examDate = $val["create_time"];
  2956. if($paperSize === null)
  2957. $paperSize = "A4";
  2958. $time = time();
  2959. $expireTime = $examDate + (3600 * 24 * 2);
  2960. if($time > $expireTime){
  2961. $rs["rs"][$key]["is_expired"] = true;
  2962. }
  2963. else{
  2964. $rs["rs"][$key]["is_expired"] = false;
  2965. }
  2966. $rs["rs"][$key]["exam_time"] = $examDate;
  2967. $rs["rs"][$key]["paper_size"] = $paperSize;
  2968. }
  2969. return $rs;
  2970. }
  2971. public function getThirdPrintList($condition = array(), $orderBy = array("e.create_time desc"), $pageSize = 9){
  2972. $condition = Arr::merge($condition, array("e.semester_id = '{$this->semester["id"]}'"));
  2973. $condition = $this->condition($condition);
  2974. $orderBy = $this->orderBy($orderBy);
  2975. $sql="select eg.*,e.exam_id,e.school_card_status,e.school_card_length, e.name as exam_name,e.is_new, e.tpl_index, e.tpl_data, e.upload_status, e.create_time, e.is_display, eg.mark_type, eg.mark_status,e.subject_id,e.class_id,p.tpl_doc_src, p.answer_card_src, p.is_labelled, p.labelled_type,p.paper_id
  2976. from exam_group as eg
  2977. left join exam as e on eg.exam_group_id = e.exam_group_id
  2978. left join paper as p on p.exam_id = e.exam_id
  2979. {$condition}
  2980. group by eg.exam_group_id
  2981. {$orderBy}
  2982. ";
  2983. $handle = $this->sConn->createCommand($sql)->query();
  2984. $rs = $this->paging($this->sConn, $handle, $pageSize);
  2985. return $rs;
  2986. }
  2987. //获取下载班级
  2988. public function getDownloadClassIpf($condition = array(), $orderBy = array("add_time desc")){
  2989. $condition = Arr::merge($condition, array("c.semester_id = '{$this->semester["id"]}'"));
  2990. $condition = $this->condition($condition);
  2991. $orderBy = $this->orderBy($orderBy);
  2992. $rs['rs'] = $this->sConn->createCommand("
  2993. select cep.*, c.class_name, csr.subject_id, e.name as exam_name,e.is_new, e.upload_status, e.create_time,e.complete_time, e.is_display, eg.mark_type,eg.upload_status as group_upload_status, eg.mark_status,e.exam_group_id,p.tpl_doc_src, p.answer_card_src, p.is_labelled,p.paper_id
  2994. from class as c
  2995. join class_subject_relation as csr on csr.class_id = c.class_id
  2996. join exam as e on e.class_id = c.class_id
  2997. join class_exam_printer as cep on cep.class_id = c.class_id and cep.exam_id = e.exam_id
  2998. JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id
  2999. join paper as p on p.exam_id = e.exam_id
  3000. {$condition}
  3001. group by class_id, exam_id, type
  3002. {$orderBy}
  3003. ")->queryAll();
  3004. $examsIds = $this->grouping($rs["rs"], "exam_id", true);
  3005. $examsIds = "'".implode("','", $examsIds)."'";
  3006. $sprs = $this->sConn->createCommand("select exam_id, is_complete, is_feedback,is_wrongbook_pdf,is_wbisp_pdf,is_isp_pdf from student_paper_relation where exam_id in({$examsIds})")->queryAll();
  3007. $examsSprs = array();
  3008. foreach($sprs as $key => $val){
  3009. if(!isset($examsSprs[$val["exam_id"]]))
  3010. $examsSprs[$val["exam_id"]] = array();
  3011. $examsSprs[$val["exam_id"]][] = $val;
  3012. }
  3013. $examsStudentsCount = array();
  3014. foreach($examsSprs as $examId => $sprs){
  3015. $examsStudentsCount[$examId] = array(
  3016. "is_complete_count" => 0,
  3017. "is_uploaded_count" => 0,
  3018. "wrongbook_pdf_count" => 0,
  3019. "wbisp_pdf_count" => 0,
  3020. "isp_pdf_count" => 0,
  3021. );
  3022. $examsStudentsCount[$examId]["students_count"] = count($sprs);
  3023. foreach($sprs as $k => $v){
  3024. if($v["is_complete"] == 1)
  3025. {
  3026. $examsStudentsCount[$examId]["is_complete_count"]++;
  3027. }
  3028. $examsStudentsCount[$examId]["is_uploaded_count"]++;
  3029. if($v["is_wrongbook_pdf"] == 1)
  3030. {
  3031. $examsStudentsCount[$examId]["wrongbook_pdf_count"]++;
  3032. }
  3033. if($v["is_wbisp_pdf"] == 1)
  3034. {
  3035. $examsStudentsCount[$examId]["wbisp_pdf_count"]++;
  3036. }
  3037. if($v["is_isp_pdf"] == 1)
  3038. {
  3039. $examsStudentsCount[$examId]["isp_pdf_count"]++;
  3040. }
  3041. }
  3042. }
  3043. foreach($rs["rs"] as $key => $val){
  3044. if(isset($examsStudentsCount[$val["exam_id"]])){
  3045. $rs["rs"][$key]["students_count"] = $examsStudentsCount[$val["exam_id"]]["students_count"];
  3046. $rs["rs"][$key]["is_complete_count"] = $examsStudentsCount[$val["exam_id"]]["is_complete_count"];
  3047. $rs["rs"][$key]["is_uploaded_count"] = $examsStudentsCount[$val["exam_id"]]["is_uploaded_count"];
  3048. $rs["rs"][$key]["wrongbook_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wrongbook_pdf_count"];
  3049. $rs["rs"][$key]["wbisp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wbisp_pdf_count"];
  3050. $rs["rs"][$key]["isp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["isp_pdf_count"];
  3051. }
  3052. else{
  3053. $rs["rs"][$key]["students_count"] = 0;
  3054. $rs["rs"][$key]["is_complete_count"] = 0;
  3055. $rs["rs"][$key]["is_uploaded_count"] = 0;
  3056. $rs["rs"][$key]["wrongbook_pdf_count"] = 0;
  3057. $rs["rs"][$key]["wbisp_pdf_count"] = 0;
  3058. $rs["rs"][$key]["isp_pdf_count"] = 0;
  3059. }
  3060. }
  3061. return $rs["rs"];
  3062. }
  3063. public function getPrintList_ipf($condition = array(), $orderBy = array("add_time desc"), $pageSize = 9){
  3064. $condition = Arr::merge($condition, array("c.semester_id = '{$this->semester["id"]}'"));
  3065. $condition = $this->condition($condition);
  3066. $orderBy = $this->orderBy($orderBy);
  3067. $handle = $this->sConn->createCommand("
  3068. select cep.*, c.class_name, csr.subject_id, e.name as exam_name,e.is_new, e.tpl_index, e.tpl_data, e.upload_status, e.create_time,e.complete_time, e.is_display, eg.mark_type,eg.upload_status as group_upload_status, eg.mark_status,e.exam_group_id,p.tpl_doc_src, p.answer_card_src, p.is_labelled,p.paper_id
  3069. from class as c
  3070. join class_subject_relation as csr on csr.class_id = c.class_id
  3071. join exam as e on e.class_id = c.class_id
  3072. join class_exam_printer as cep on cep.class_id = c.class_id and cep.exam_id = e.exam_id
  3073. JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id
  3074. join paper as p on p.exam_id = e.exam_id
  3075. {$condition}
  3076. group by class_id, exam_id, type
  3077. {$orderBy}
  3078. ")->query();
  3079. $rs = $this->paging($this->sConn, $handle, $pageSize);
  3080. $examsIds = $this->grouping($rs["rs"], "exam_id", true);
  3081. $examsIds = "'".implode("','", $examsIds)."'";
  3082. $sprs = $this->sConn->createCommand("select exam_id, is_complete, is_feedback,is_wrongbook_pdf,is_wbisp_pdf,is_isp_pdf,is_wrongbook_download,is_two_isp_download,is_three_isp_download from student_paper_relation where exam_id in({$examsIds})")->queryAll();
  3083. $examsSprs = array();
  3084. foreach($sprs as $key => $val){
  3085. if(!isset($examsSprs[$val["exam_id"]]))
  3086. $examsSprs[$val["exam_id"]] = array();
  3087. $examsSprs[$val["exam_id"]][] = $val;
  3088. }
  3089. $examsStudentsCount = array();
  3090. foreach($examsSprs as $examId => $sprs){
  3091. $examsStudentsCount[$examId] = array(
  3092. "is_complete_count" => 0,
  3093. "is_uploaded_count" => 0,
  3094. "wrongbook_pdf_count" => 0,
  3095. "wbisp_pdf_count" => 0,
  3096. "isp_pdf_count" => 0,
  3097. "wrongbook_download_count" => 0,
  3098. "wbisp_download_count" => 0,
  3099. "isp_download_count" => 0,
  3100. );
  3101. $examsStudentsCount[$examId]["students_count"] = count($sprs);
  3102. foreach($sprs as $k => $v){
  3103. if($v["is_complete"] == 1)
  3104. {
  3105. $examsStudentsCount[$examId]["is_complete_count"]++;
  3106. }
  3107. $examsStudentsCount[$examId]["is_uploaded_count"]++;
  3108. if($v["is_wrongbook_pdf"] == 1)
  3109. {
  3110. $examsStudentsCount[$examId]["wrongbook_pdf_count"]++;
  3111. }
  3112. if($v["is_wbisp_pdf"] == 1)
  3113. {
  3114. $examsStudentsCount[$examId]["wbisp_pdf_count"]++;
  3115. }
  3116. if($v["is_isp_pdf"] == 1)
  3117. {
  3118. $examsStudentsCount[$examId]["isp_pdf_count"]++;
  3119. }
  3120. if($v["is_wrongbook_download"] == 1)
  3121. {
  3122. $examsStudentsCount[$examId]["wrongbook_download_count"]++;
  3123. }
  3124. if($v["is_two_isp_download"] == 1)
  3125. {
  3126. $examsStudentsCount[$examId]["isp_download_count"]++;
  3127. }
  3128. if($v["is_three_isp_download"] == 1)
  3129. {
  3130. $examsStudentsCount[$examId]["wbisp_download_count"]++;
  3131. }
  3132. }
  3133. }
  3134. foreach($rs["rs"] as $key => $val){
  3135. if(isset($examsStudentsCount[$val["exam_id"]])){
  3136. $rs["rs"][$key]["students_count"] = $examsStudentsCount[$val["exam_id"]]["students_count"];
  3137. $rs["rs"][$key]["is_complete_count"] = $examsStudentsCount[$val["exam_id"]]["is_complete_count"];
  3138. $rs["rs"][$key]["is_uploaded_count"] = $examsStudentsCount[$val["exam_id"]]["is_uploaded_count"];
  3139. $rs["rs"][$key]["wrongbook_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wrongbook_pdf_count"];
  3140. $rs["rs"][$key]["wbisp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wbisp_pdf_count"];
  3141. $rs["rs"][$key]["isp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["isp_pdf_count"];
  3142. $rs["rs"][$key]["wrongbook_download_count"] = $examsStudentsCount[$val["exam_id"]]["wrongbook_download_count"];
  3143. $rs["rs"][$key]["isp_download_count"] = $examsStudentsCount[$val["exam_id"]]["isp_download_count"];
  3144. $rs["rs"][$key]["wbisp_download_count"] = $examsStudentsCount[$val["exam_id"]]["wbisp_download_count"];
  3145. }
  3146. else{
  3147. $rs["rs"][$key]["students_count"] = 0;
  3148. $rs["rs"][$key]["is_complete_count"] = 0;
  3149. $rs["rs"][$key]["is_uploaded_count"] = 0;
  3150. $rs["rs"][$key]["wrongbook_pdf_count"] = 0;
  3151. $rs["rs"][$key]["wbisp_pdf_count"] = 0;
  3152. $rs["rs"][$key]["isp_pdf_count"] = 0;
  3153. $rs["rs"][$key]["wrongbook_download_count"] = 0;
  3154. $rs["rs"][$key]["isp_download_count"] = 0;
  3155. $rs["rs"][$key]["wbisp_download_count"] = 0;
  3156. }
  3157. $tplData = json_decode($val["tpl_data"], true);
  3158. $paperSize = null;
  3159. $examDate = null;
  3160. if(in_array($val["tpl_index"], Yii::app()->params["custom_tpls_ids"])){
  3161. switch($val["tpl_index"]){
  3162. case "12":
  3163. $paperSize = "A3";
  3164. break;
  3165. case "13":
  3166. $paperSize = "A4";
  3167. break;
  3168. case "14":
  3169. $paperSize = "8K";
  3170. break;
  3171. case "15":
  3172. $paperSize = "16K";
  3173. break;
  3174. case "2012":
  3175. $paperSize = "A3";
  3176. break;
  3177. case "2013":
  3178. $paperSize = "A4";
  3179. break;
  3180. case "2014":
  3181. $paperSize = "8K";
  3182. break;
  3183. case "2015":
  3184. $paperSize = "16K";
  3185. break;
  3186. case "2016":
  3187. $paperSize = "A3";
  3188. break;
  3189. case "2017":
  3190. $paperSize = "A4";
  3191. break;
  3192. case "2018":
  3193. $paperSize = "8K";
  3194. break;
  3195. case "2019":
  3196. $paperSize = "16K";
  3197. break;
  3198. case "1012":
  3199. $paperSize = "A3";
  3200. break;
  3201. case "1013":
  3202. $paperSize = "A4";
  3203. break;
  3204. case "1014":
  3205. $paperSize = "8K";
  3206. break;
  3207. case "1015":
  3208. $paperSize = "16K";
  3209. break;
  3210. case "1016":
  3211. $paperSize = "A3";
  3212. break;
  3213. case "1017":
  3214. $paperSize = "A4";
  3215. break;
  3216. case "1018":
  3217. $paperSize = "8K";
  3218. break;
  3219. case "1019":
  3220. $paperSize = "16K";
  3221. break;
  3222. }
  3223. }
  3224. if(in_array($val["tpl_index"], Yii::app()->params["custom_tpls_ids"])){
  3225. switch($val["tpl_index"]){
  3226. case "16":
  3227. $paperSize = "A3";
  3228. break;
  3229. case "17":
  3230. $paperSize = "A4";
  3231. break;
  3232. case "18":
  3233. $paperSize = "8K";
  3234. break;
  3235. case "19":
  3236. $paperSize = "16K";
  3237. break;
  3238. }
  3239. }
  3240. if($tplData){
  3241. if(!isset($tplData["examDate"]) || !($examDate = strtotime($tplData["examDate"])))
  3242. $examDate = $val["create_time"];
  3243. if($paperSize === null && isset($tplData["paper"]) && $tplData["paper"] == 1)
  3244. $paperSize = "A3";
  3245. }
  3246. if($examDate === null)
  3247. $examDate = $val["create_time"];
  3248. if($paperSize === null)
  3249. $paperSize = "A4";
  3250. $time = time();
  3251. $expireTime = $examDate + (3600 * 24 * 2);
  3252. if($time > $expireTime){
  3253. $rs["rs"][$key]["is_expired"] = true;
  3254. }
  3255. else{
  3256. $rs["rs"][$key]["is_expired"] = false;
  3257. }
  3258. $rs["rs"][$key]["exam_time"] = $examDate;
  3259. $rs["rs"][$key]["paper_size"] = $paperSize;
  3260. }
  3261. return $rs;
  3262. }
  3263. public function getPrintListOfCoach($coachId, $condition = array(), $orderBy = array("add_time desc"), $pageSize = 9){
  3264. $rs = $this->buildEmptyPagingStruct();
  3265. if($coachId){
  3266. $condition = Arr::merge($condition, array("c.semester_id = '{$this->semester["id"]}'"));
  3267. $condition = $this->condition($condition);
  3268. $orderBy = $this->orderBy($orderBy);
  3269. $handle = $this->sConn->createCommand("
  3270. select cep.*, c.class_name, csr.subject_id, e.name as exam_name,e.is_new, e.tpl_index, e.tpl_data, e.upload_status, e.create_time, e.is_display, eg.mark_type,eg.upload_status as group_upload_status, eg.mark_status,e.exam_group_id,p.tpl_doc_src, p.answer_card_src, p.is_labelled,p.paper_id
  3271. from class as c
  3272. join class_subject_relation as csr on csr.class_id = c.class_id
  3273. join exam as e on e.class_id = c.class_id
  3274. join class_exam_printer as cep on cep.class_id = c.class_id and cep.exam_id = e.exam_id
  3275. JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id
  3276. join paper as p on p.exam_id = e.exam_id
  3277. {$condition}
  3278. group by class_id, exam_id, type
  3279. {$orderBy}
  3280. ")->query();
  3281. $rs = $this->paging($this->sConn, $handle, $pageSize);
  3282. $examsIds = $this->grouping($rs["rs"], "exam_id", true);
  3283. $examsIds = "'".implode("','", $examsIds)."'";
  3284. $sprs = $this->sConn->createCommand("select * from student_paper_relation where exam_id in({$examsIds}) ")->queryAll();
  3285. $examsSprs = array();
  3286. foreach($sprs as $key => $val){
  3287. if(!isset($examsSprs[$val["exam_id"]]))
  3288. $examsSprs[$val["exam_id"]] = array();
  3289. $examsSprs[$val["exam_id"]][] = $val;
  3290. }
  3291. $examsStudentsCount = array();
  3292. foreach($examsSprs as $examId => $sprs){
  3293. $examsStudentsCount[$examId] = array(
  3294. "is_complete_count" => 0,
  3295. "is_uploaded_count" => 0,
  3296. "wrongbook_pdf_count" => 0,
  3297. "wbisp_pdf_count" => 0,
  3298. "isp_pdf_count" => 0,
  3299. );
  3300. $examsStudentsCount[$examId]["students_count"] = count($sprs);
  3301. foreach($sprs as $k => $v){
  3302. if($v["is_complete"] == 1)
  3303. $examsStudentsCount[$examId]["is_complete_count"]++;
  3304. if($v["is_feedback"] == 1)
  3305. $examsStudentsCount[$examId]["is_uploaded_count"]++;
  3306. if($v["is_wrongbook_pdf"] == 1)
  3307. $examsStudentsCount[$examId]["wrongbook_pdf_count"]++;
  3308. if($v["is_wbisp_pdf"] == 1)
  3309. $examsStudentsCount[$examId]["wbisp_pdf_count"]++;
  3310. if($v["is_isp_pdf"] == 1)
  3311. $examsStudentsCount[$examId]["isp_pdf_count"]++;
  3312. }
  3313. }
  3314. foreach($rs["rs"] as $key => $val){
  3315. if(isset($examsStudentsCount[$val["exam_id"]])){
  3316. $rs["rs"][$key]["students_count"] = $examsStudentsCount[$val["exam_id"]]["students_count"];
  3317. $rs["rs"][$key]["is_complete_count"] = $examsStudentsCount[$val["exam_id"]]["is_complete_count"];
  3318. $rs["rs"][$key]["is_uploaded_count"] = $examsStudentsCount[$val["exam_id"]]["is_uploaded_count"];
  3319. $rs["rs"][$key]["wrongbook_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wrongbook_pdf_count"];
  3320. $rs["rs"][$key]["wbisp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wbisp_pdf_count"];
  3321. $rs["rs"][$key]["isp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["isp_pdf_count"];
  3322. }
  3323. else{
  3324. $rs["rs"][$key]["students_count"] = 0;
  3325. $rs["rs"][$key]["is_complete_count"] = 0;
  3326. $rs["rs"][$key]["is_uploaded_count"] = 0;
  3327. $rs["rs"][$key]["wrongbook_pdf_count"] = 0;
  3328. $rs["rs"][$key]["wbisp_pdf_count"] = 0;
  3329. $rs["rs"][$key]["isp_pdf_count"] = 0;
  3330. }
  3331. $tplData = json_decode($val["tpl_data"], true);
  3332. $paperSize = null;
  3333. $examDate = null;
  3334. if(in_array($val["tpl_index"], Yii::app()->params["custom_tpls_ids"])){
  3335. switch($val["tpl_index"]){
  3336. case "12":
  3337. $paperSize = "A3";
  3338. break;
  3339. case "13":
  3340. $paperSize = "A4";
  3341. break;
  3342. case "14":
  3343. $paperSize = "8K";
  3344. break;
  3345. case "15":
  3346. $paperSize = "16K";
  3347. break;
  3348. case "2012":
  3349. $paperSize = "A3";
  3350. break;
  3351. case "2013":
  3352. $paperSize = "A4";
  3353. break;
  3354. case "2014":
  3355. $paperSize = "8K";
  3356. break;
  3357. case "2015":
  3358. $paperSize = "16K";
  3359. break;
  3360. case "2016":
  3361. $paperSize = "A3";
  3362. break;
  3363. case "2017":
  3364. $paperSize = "A4";
  3365. break;
  3366. case "2018":
  3367. $paperSize = "8K";
  3368. break;
  3369. case "2019":
  3370. $paperSize = "16K";
  3371. break;
  3372. case "1012":
  3373. $paperSize = "A3";
  3374. break;
  3375. case "1013":
  3376. $paperSize = "A4";
  3377. break;
  3378. case "1014":
  3379. $paperSize = "8K";
  3380. break;
  3381. case "1015":
  3382. $paperSize = "16K";
  3383. break;
  3384. case "1016":
  3385. $paperSize = "A3";
  3386. break;
  3387. case "1017":
  3388. $paperSize = "A4";
  3389. break;
  3390. case "1018":
  3391. $paperSize = "8K";
  3392. break;
  3393. case "1019":
  3394. $paperSize = "16K";
  3395. break;
  3396. case "3013":
  3397. $paperSize = "A4";
  3398. break;
  3399. case "3017":
  3400. $paperSize = "A4";
  3401. break;
  3402. }
  3403. }
  3404. if($tplData){
  3405. if(!isset($tplData["examDate"]) || !($examDate = strtotime($tplData["examDate"])))
  3406. $examDate = $val["create_time"];
  3407. if($paperSize === null && isset($tplData["paper"]) && $tplData["paper"] == 1)
  3408. $paperSize = "A3";
  3409. }
  3410. if($examDate === null)
  3411. $examDate = $val["create_time"];
  3412. if($paperSize === null)
  3413. $paperSize = "A4";
  3414. $time = time();
  3415. $expireTime = $examDate + (3600 * 24 * 2);
  3416. if($time > $expireTime){
  3417. $rs["rs"][$key]["is_expired"] = true;
  3418. }
  3419. else{
  3420. $rs["rs"][$key]["is_expired"] = false;
  3421. }
  3422. $rs["rs"][$key]["exam_time"] = $examDate;
  3423. $rs["rs"][$key]["paper_size"] = $paperSize;
  3424. }
  3425. }
  3426. return $rs;
  3427. }
  3428. public function getClassesByCoachId($coachId,$grade=''){
  3429. $classes = array();
  3430. if($coachId){
  3431. if(in_array($grade, array("1", "2", "3"))) {
  3432. $classes = $this->sConn->createCommand("select * from `class` where coach_id = '{$coachId}' and grade='{$grade}'")->queryAll();
  3433. } else {
  3434. $classes = $this->sConn->createCommand("select * from `class` where coach_id = '{$coachId}'")->queryAll();
  3435. }
  3436. }
  3437. return $classes;
  3438. }
  3439. public function getClassesIdsByCoachId($coachId){
  3440. $rs = $this->getClassesByCoachId($coachId);
  3441. $ids = $this->grouping($rs, "class_id");
  3442. return $ids;
  3443. }
  3444. /**
  3445. * 获取学期的班级
  3446. * @param $semesterId
  3447. *
  3448. * @return array|\CDbDataReader
  3449. */
  3450. public function getSemesterClasses($semesterId){
  3451. $classes = array();
  3452. if($semesterId){
  3453. $classes = $this->sConn->createCommand("select * from class where semester_id = '{$semesterId}' and is_hide=0")->queryAll();
  3454. }
  3455. return $classes;
  3456. }
  3457. public function getSemesterClassesStudent($semesterId){
  3458. $classes = array();
  3459. if($semesterId){
  3460. $classes = $this->sConn->createCommand("
  3461. select c.*
  3462. from class as c
  3463. left join student_class_relation as scr on scr.class_id = c.class_id
  3464. where c.semester_id = ".$semesterId ." and scr.status = 0 and c.is_hide=0
  3465. group by scr.class_id ")->queryAll();
  3466. }
  3467. return $classes;
  3468. }
  3469. public function getSemesterStudents($semesterId){
  3470. $students = array();
  3471. if($semesterId){
  3472. $students = $this->sConn->createCommand("
  3473. select stu.student_id, stu.realname, scr.class_id, scr.userno, scr.serial_number
  3474. from class as c
  3475. join student_class_relation as scr on scr.class_id = c.class_id and scr.status = 1
  3476. join student_info as stu on stu.student_id = scr.student_id
  3477. where c.semester_id = '{$semesterId}'
  3478. group by stu.student_id
  3479. ")->queryAll();
  3480. }
  3481. return $students;
  3482. }
  3483. public function activateSemesterClassesStudentsRelations($semesterId){
  3484. $rs = false;
  3485. if($semesterId){
  3486. $students = $this->getSemesterStudents($semesterId);
  3487. $classes = $this->getSemesterClasses($semesterId);
  3488. if($students && $classes){
  3489. $studentsIds = $this->grouping($students, "student_id");
  3490. $studentsIds = "'".implode("','", $studentsIds)."'";
  3491. $classesIds = $this->grouping($classes, "class_id");
  3492. $classesIds = "'".implode("','", $classesIds)."'";
  3493. try{
  3494. $trans = $this->sConn->beginTransaction();
  3495. $this->sConn->createCommand("update student_class_relation set status = '1' where student_id in({$studentsIds}) and status = 0")->execute();
  3496. $this->sConn->createCommand("update student_class_relation set status = '0' where student_id in({$studentsIds}) and class_id in({$classesIds}) and status = 1")->execute();
  3497. foreach($students as $student){
  3498. $this->sConn->createCommand("update student_info set class_id = '{$student["class_id"]}' where student_id = '{$student["student_id"]}'")->execute();
  3499. }
  3500. $trans->commit();
  3501. $rs = true;
  3502. }
  3503. catch(Exception $e){
  3504. $trans->rollBack();
  3505. $rs = false;
  3506. }
  3507. }
  3508. }
  3509. return $rs;
  3510. }
  3511. public function getExamPaper($examId){
  3512. $paper = array();
  3513. if($examId){
  3514. $paper = $this->sConn->createCommand("select * from paper where exam_id = '{$examId}'")->queryRow();
  3515. }
  3516. return $paper;
  3517. }
  3518. public function setPrintTransChecked($classId, $examId){
  3519. if($classId && $examId){
  3520. $rs = $this->sConn->createCommand("select exists(select * from class_exam_printer where class_id = '{$classId}' and exam_id = '{$examId}' and type = '2' and is_checked = 1)")->queryRow();
  3521. $isChecked = current($rs) > 0 ? true : false;
  3522. if($isChecked)
  3523. $rs = true;
  3524. else{
  3525. $rs = $this->sConn->createCommand("update class_exam_printer set is_checked = '1' where class_id = '{$classId}' and exam_id = '{$examId}' and type = '2'")->execute();
  3526. }
  3527. return $rs ? true : false;
  3528. }
  3529. return false;
  3530. }
  3531. public function setStudentIspChecked($planId){
  3532. if($planId){
  3533. $rs = $this->sConn->createCommand("select exists(select * from student_improve_score_plan where plan_id = '{$planId}' and is_checked = 1)")->queryRow();
  3534. $isChecked = current($rs) > 0 ? true : false;
  3535. if($isChecked)
  3536. $rs = true;
  3537. else{
  3538. $rs = $this->sConn->createCommand("update student_improve_score_plan set is_checked = '1' where plan_id = '{$planId}'")->execute();
  3539. }
  3540. return $rs ? true : false;
  3541. }
  3542. return false;
  3543. }
  3544. public function getClassStudentsIspsList($classId, $examId, $orderBy = array("scr.serial_number asc", "stu.realname asc"), $pageSize = 9){
  3545. $isps = $this->buildEmptyPagingStruct();
  3546. /*if($examId && $classId){
  3547. $orderBy = $this->orderBy($orderBy);
  3548. $handle = $this->sConn->createCommand("
  3549. select stu.*, scr.userno, scr.serial_number, sisp.is_checked, sisp.plan_id
  3550. from student_class_relation as scr
  3551. join student_info as stu on stu.student_id = scr.student_id
  3552. join student_improve_score_plan as sisp on sisp.student_id = scr.student_id and sisp.exam_id = '{$examId}'
  3553. where scr.class_id = '{$classId}' and sisp.is_created=1 and scr.status = 0
  3554. {$orderBy}
  3555. ")->query();
  3556. $isps = $this->paging($this->sConn, $handle, $pageSize);
  3557. }*/
  3558. if($examId && $classId){
  3559. $orderBy = $this->orderBy($orderBy);
  3560. $handle = $this->sConn->createCommand("
  3561. select stu.*, scr.userno, scr.serial_number, sisp.is_checked, sisp.plan_id
  3562. from student_class_relation as scr
  3563. join student_info as stu on stu.student_id = scr.student_id
  3564. join student_improve_score_plan as sisp on sisp.student_id = scr.student_id and sisp.exam_id = '{$examId}'
  3565. where scr.class_id = '{$classId}' and sisp.is_created=1
  3566. {$orderBy}
  3567. ")->query();
  3568. $isps = $this->paging($this->sConn, $handle, $pageSize);
  3569. }
  3570. return $isps;
  3571. }
  3572. public function getIspInfo($planId){
  3573. $isp = array();
  3574. if($planId){
  3575. $isp = $this->sConn->createCommand("
  3576. select sisp.*, p.difficulty, p.score, spr.class_id
  3577. from student_improve_score_plan as sisp
  3578. join paper as p on p.paper_id = sisp.paper_id
  3579. join student_paper_relation as spr on spr.student_id = sisp.student_id and spr.paper_id = sisp.paper_id
  3580. where sisp.plan_id = '{$planId}' and spr.is_del=0
  3581. ")->queryRow();
  3582. }
  3583. return $isp;
  3584. }
  3585. //获取题目难度描述
  3586. public function getTopicDifficultyDescription($key){
  3587. $key = (string)$key;
  3588. $description = array(
  3589. "1" => "容易",
  3590. "2" => "中等",
  3591. "3" => "困难",
  3592. );
  3593. return isset($description[$key]) ? $description[$key] : "";
  3594. }
  3595. //从接口获取题目信息
  3596. public function getTopics($topicsIds = array(), $detial = false,$subject=0,$params=array()){
  3597. $topics = array();
  3598. $array = array();
  3599. $cachedTopics = array();
  3600. if($topicsIds){
  3601. foreach($topicsIds as $val){
  3602. if(!$val)
  3603. continue;
  3604. $array[$this->topicField][] = $val;
  3605. }
  3606. if($subject && $subject!=8){
  3607. $array['subjectId']=$subject;
  3608. }
  3609. if($params){
  3610. $array['params']=$params;
  3611. }
  3612. if($array){
  3613. $topics = Curl::post($this->topicUrl, $array);
  3614. $topics = json_decode($topics, true);
  3615. if(isset($topics["status"]))
  3616. {
  3617. // unset($array['subjectId']);
  3618. // unset($array['params']);
  3619. // $topics = Curl::post($this->topicUrl, $array);
  3620. // $topics = json_decode($topics, true);
  3621. // if(isset($topics["status"])) $topics = array();
  3622. $topics = array();
  3623. }
  3624. }
  3625. }
  3626. return $topics;
  3627. }
  3628. public function getTopic($topicId){
  3629. $topic = array();
  3630. if($topicId){
  3631. $rs = $this->getTopics(array($topicId));
  3632. if($rs) $topic = current($rs);
  3633. }
  3634. return $topic;
  3635. }
  3636. public function getTopicsByIspRecords($plan, $topicsRs, $paperTopicsRecords){
  3637. $topics = array();
  3638. if(Arr::isAvailable($plan) && Arr::isAvailable($topicsRs) && Arr::isAvailable($paperTopicsRecords)){
  3639. $topicsIds = array();
  3640. $schoolTopicsIds = array();
  3641. foreach($topicsRs as $topicRs){
  3642. foreach($paperTopicsRecords as $paperTopicRecord){
  3643. $topicsIds[] = $topicRs["topic_id"];
  3644. }
  3645. }
  3646. $schoolTopicsIds = array_unique($schoolTopicsIds);
  3647. $topicsIds = array_unique($topicsIds);
  3648. $schoolTopicsIds = "'".implode("','", $schoolTopicsIds)."'";
  3649. $topics = $this->getTopics($topicsIds);
  3650. }
  3651. return $topics;
  3652. }
  3653. public function getTopicsRecordsFromStudentIsp($planId, $type = "ALL"){
  3654. $rs = array();
  3655. if($planId){
  3656. $condition = array("plan_id = '{$planId}'");
  3657. if($type === "IMPROVE")
  3658. $condition = Arr::merge($condition, array("is_template = 0"));
  3659. $condition = $this->condition($condition);
  3660. $rs = $this->sConn->createCommand("select * from student_improve_score_plan_topics{$condition}")->queryAll();
  3661. }
  3662. return $rs;
  3663. }
  3664. public function getIspTopics($planId){
  3665. $topics = array();
  3666. if($isp = $this->getIspInfo($planId)){
  3667. $topicsRecords = $this->getTopicsRecordsFromStudentIsp($planId);
  3668. $paperTopicsRecords = $this->getPaperTopicsRecords($isp["paper_id"]);
  3669. $topics = $this->getTopicsByIspRecords($isp, $topicsRecords, $paperTopicsRecords);
  3670. foreach($topics as $key => $topic){
  3671. foreach($topicsRecords as $k => $v){
  3672. if($topic["id"] == $v["topic_id"]){
  3673. $topics[$key]["is_source"] = $v["is_template"];
  3674. $topics[$key]["source_id"] = $v["template_id"];
  3675. }
  3676. }
  3677. }
  3678. foreach($topics as $key => $topic){
  3679. foreach($paperTopicsRecords as $k => $topicRecord){
  3680. if($topic["id"] == $topicRecord["topic_id"])
  3681. $topics[$key]["number"] = $topicRecord["no"];
  3682. }
  3683. }
  3684. }
  3685. return $topics;
  3686. }
  3687. public function getIspTopicsIds($planId){
  3688. $ids = array();
  3689. if($rs = $this->getTopicsRecordsFromStudentIsp($planId)){
  3690. $ids = $this->grouping($rs, "topic_id");
  3691. }
  3692. return $ids;
  3693. }
  3694. public function getPaperTopicsRecords($paperId){
  3695. $records = array();
  3696. if($paperId){
  3697. $records = $this->sConn->createCommand("select * from paper_topic_relation where paper_id = '{$paperId}' order by type asc, `order` asc")->queryAll();
  3698. }
  3699. return $records;
  3700. }
  3701. public function getPaperTopics($paperId,$subject=0,$params=array(),$onlySlave=0){
  3702. if(!($ptrs = $this->getPaperTopicsRecords($paperId)))
  3703. return array();
  3704. $schoolTopicsIds = array();
  3705. $topicsIds = array();
  3706. foreach($ptrs as $ptr){
  3707. if($onlySlave==1){
  3708. $topicsIds[] = $ptr["topic_id"];
  3709. }else{
  3710. if(isset($ptr['stem_id']) && $ptr['stem_id']){
  3711. $topicsIds[] = $ptr["stem_id"];
  3712. }else{
  3713. $topicsIds[] = $ptr["topic_id"];
  3714. }
  3715. }
  3716. }
  3717. $topics = $this->getTopics($topicsIds,false,$subject,$params);
  3718. return $topics;
  3719. }
  3720. public function getPaperTopicsIds($paperId){
  3721. if(!($topicsRecords = $this->getPaperTopicsRecords($paperId)))
  3722. return array();
  3723. return $this->grouping($topicsRecords, "topic_id");
  3724. }
  3725. public function composeIspTopics($planId, $topics){
  3726. $sections = array(
  3727. "选择题" => array(
  3728. "type_id" => 1,
  3729. "type_name" => "单选题",
  3730. "wrong_topics" => array(),
  3731. "wrong_topics_count" => 0,
  3732. "correct_topics" => array(),
  3733. "correct_topics_count" => 0,
  3734. "order" => $this->topicTypesOrder["选择题"],
  3735. ),
  3736. "填空题" => array(
  3737. "type_id" => 5,
  3738. "type_name" => "填空题",
  3739. "wrong_topics" => array(),
  3740. "wrong_topics_count" => 0,
  3741. "correct_topics" => array(),
  3742. "correct_topics_count" => 0,
  3743. "order" => $this->topicTypesOrder["填空题"],
  3744. ),
  3745. "解答题" => array(
  3746. "type_id" => 7,
  3747. "type_name" => "简答题",
  3748. "wrong_topics" => array(),
  3749. "wrong_topics_count" => 0,
  3750. "correct_topics" => array(),
  3751. "correct_topics_count" => 0,
  3752. "order" => $this->topicTypesOrder["解答题"],
  3753. ),
  3754. );
  3755. if($topics){
  3756. $topicsOrder = array();
  3757. $topicNum = 1;
  3758. foreach($sections as $key => $val){
  3759. foreach($topics as $k => $topic){
  3760. if($topic["type_id"] == $val["type_id"]){
  3761. if($topic["is_source"]){
  3762. $sections[$key]["wrong_topics"][$topic["id"]] = $topic;
  3763. }
  3764. else{
  3765. $sections[$key]["correct_topics"][$topic["source_id"]][$topic["id"]] = $topic;
  3766. $sections[$key]["correct_topics_count"]++;
  3767. }
  3768. }
  3769. }
  3770. $sections[$key]["wrong_topics_count"] = count($sections[$key]["wrong_topics"]);
  3771. foreach($sections[$key]["wrong_topics"] as $wrongTopicId => $wrongTopic){
  3772. if(!isset($wrongTopic["kps"]))
  3773. $wrongTopic["kps"] = array();
  3774. $kps = $wrongTopic["kps"];
  3775. $kpsNames = $this->grouping($kps, "kp_name");
  3776. $kpsNamesStr = implode("; ", $kpsNames);
  3777. $sections[$key]["wrong_topics"][$wrongTopicId]["kps"] = $kps;
  3778. $sections[$key]["wrong_topics"][$wrongTopicId]["kps_names_str"] = $kpsNamesStr;
  3779. $sections[$key]["wrong_topics"][$wrongTopicId]["methods_ids"] = array();
  3780. $wrongTopicMethodsNames = array();
  3781. if(!empty($wrongTopic["specials"])){
  3782. foreach($wrongTopic["specials"] as $method){
  3783. $wrongTopicMethodsNames[] = $method["method_name"];
  3784. if($method["method_id"])
  3785. $sections[$key]["wrong_topics"][$wrongTopicId]["methods_ids"][] = $method["method_id"];
  3786. }
  3787. }
  3788. $sections[$key]["wrong_topics"][$wrongTopicId]["methods_names_str"] = implode("; ", $wrongTopicMethodsNames);
  3789. unset($wrongTopicMethodsNames);
  3790. if(!empty($sections[$key]["correct_topics"][$wrongTopic["id"]])){
  3791. foreach($sections[$key]["correct_topics"][$wrongTopic["id"]] as $correctTopicId => $correctTopic){
  3792. if(!isset($correctTopic["kps"]))
  3793. $correctTopic["kps"] = array();
  3794. $kps = $correctTopic["kps"];
  3795. $kpsNames = $this->grouping($kps, "kp_name");
  3796. $kpsNamesStr = implode("; ", $kpsNames);
  3797. $sections[$key]["correct_topics"][$wrongTopicId][$correctTopicId]["kps"] = $kps;
  3798. $sections[$key]["correct_topics"][$wrongTopicId][$correctTopicId]["kps_names_str"] = $kpsNamesStr;
  3799. //过滤掉图片float样式
  3800. /*$sections[$key]["correct_topics"][$wrongTopicId][$correctTopicId]["title"] = preg_replace_callback(
  3801. "/float\s*?:\s*?[a-zA-Z]*?\s*?(;|\"|\')/i",
  3802. function($matches){
  3803. return $matches[0] == "\"" || $matches[0] == "'" ? $matches[0] : "";
  3804. },
  3805. $correctTopic["title"]
  3806. );
  3807. //将题干相对路径转换为绝对路径
  3808. $sections[$key]["correct_topics"][$wrongTopicId][$correctTopicId]["title"] = preg_replace(
  3809. "/src\s*?\=\s*?\"\s*?(\/.*)\.((?:gif)|(?:jpg)|(?:png))(.*?)\"/i",
  3810. "src=\"{$this->topicHost}$1.$2$3$4\"",
  3811. $correctTopic["title"]
  3812. );*/
  3813. $topicsOrder[$correctTopicId] = $topicNum;
  3814. $sections[$key]["correct_topics"][$wrongTopicId][$correctTopicId]["methods_ids"] = array();
  3815. $correctTopicMethodsNames = array();
  3816. $sections[$key]["correct_topics"][$wrongTopicId][$correctTopicId]["methods_count"] = 0;
  3817. if(isset($correctTopic["specials"])){
  3818. $sections[$key]["correct_topics"][$wrongTopicId][$correctTopicId]["methods_count"] = count($correctTopic["specials"]);
  3819. foreach($correctTopic["specials"] as $tsm){
  3820. if($tsm["method_id"]){
  3821. $sections[$key]["correct_topics"][$wrongTopicId][$correctTopicId]["methods_ids"][] = $tsm["method_id"];
  3822. $correctTopicMethodsNames[] = $tsm["method_name"];
  3823. }
  3824. }
  3825. }
  3826. $sections[$key]["correct_topics"][$wrongTopicId][$correctTopicId]["methods_names_str"] = implode("; ", $correctTopicMethodsNames);
  3827. unset($correctTopicMethodsNames);
  3828. $topicNum++;
  3829. }
  3830. Arr::sortByField($sections[$key]["correct_topics"][$wrongTopic["id"]],'');
  3831. }
  3832. }
  3833. Arr::sortByField($sections[$key]["wrong_topics"], "number", "ASC");
  3834. if(!$this->ispTopicsOrderSeted($planId))
  3835. $this->setIspTopicsOrder($planId, $topicsOrder);
  3836. }
  3837. Arr::sortByField($sections,'', "ASC", "NATURAL", true);
  3838. }
  3839. return $sections;
  3840. }
  3841. public function ispTopicsOrderSeted($planId){
  3842. if($topics = $this->getTopicsRecordsFromStudentIsp($planId, "IMPROVE")){
  3843. return true;
  3844. }
  3845. return false;
  3846. }
  3847. public function setIspTopicsOrder($planId, $order = array()){
  3848. if($planId && $order){
  3849. try{
  3850. $trans = $this->sConn->beginTransaction();
  3851. foreach($order as $key => $val){
  3852. $this->sConn->createCommand("update student_improve_score_plan_topics set `order` = '{$val}' where plan_id = '{$planId}' and topic_id = '{$key}'")->execute();
  3853. }
  3854. $trans->commit();
  3855. return true;
  3856. }
  3857. catch(Exception $e){
  3858. $trans->rollBack();
  3859. return false;
  3860. }
  3861. }
  3862. return false;
  3863. }
  3864. public function ispTopicExists($topicId, $planId){
  3865. if($topicId && $planId){
  3866. $rs = $this->sConn->createCommand("select exists(select * from student_improve_score_plan_topics where topic_id = '{$topicId}' and plan_id = '{$planId}' and is_template = 0)")->queryRow();
  3867. $rs = current($rs);
  3868. return $rs ? true : false;
  3869. }
  3870. return false;
  3871. }
  3872. public function getIspTopic($planId, $topicId){
  3873. $topic = array();
  3874. if($planId && $topicId){
  3875. $topic = $this->sConn->createCommand("select * from student_improve_score_plan_topics where topic_id = '{$topicId}' and plan_id = '{$planId}' and is_template = 0")->queryRow();
  3876. }
  3877. return $topic;
  3878. }
  3879. public function replaceIspTopic($planId, $previousTopicId, $newTopicId){
  3880. $code = 1001;
  3881. if($previousTopicId && $newTopicId){
  3882. $code = array();
  3883. if($previousTopicId == $newTopicId)
  3884. $code[] = 2001;
  3885. if(!$this->ispTopicExists($previousTopicId, $planId))
  3886. $code[] = 2002;
  3887. if($this->ispTopicExists($newTopicId, $planId))
  3888. $code[] = 2003;
  3889. if($code)
  3890. return $this->rs($code, __FUNCTION__);
  3891. $rs = $this->sConn->createCommand("update student_improve_score_plan_topics set topic_id = '{$newTopicId}' where topic_id = '{$previousTopicId}' and plan_id = '{$planId}' and is_template = 0")->execute();
  3892. $code = $rs ? 0 : 1002;
  3893. }
  3894. return $this->rs($code, "global");
  3895. }
  3896. public function changeExamStatus($examId, $status){
  3897. if($examId){
  3898. $rs = $this->sConn->createCommand("update exam set status = '{$status}' where exam_id = '{$examId}'")->execute();
  3899. return $rs ? true : false;
  3900. }
  3901. return false;
  3902. }
  3903. public function getStudentByIspId($planId){
  3904. $student = array();
  3905. if($planId){
  3906. $student = $this->sConn->createCommand("
  3907. select stu.*
  3908. from student_improve_score_plan as sisp
  3909. join student_info as stu on stu.student_id = sisp.student_id
  3910. where sisp.plan_id = '{$planId}'
  3911. ")->queryRow();
  3912. }
  3913. return $student;
  3914. }
  3915. public function getStudentIdByIspId($planId){
  3916. $studentId = null;
  3917. if($student = $this->getStudentByIspId($planId)){
  3918. $studentId = $student["student_id"];
  3919. }
  3920. return $studentId;
  3921. }
  3922. public function getClassVacationHomeworkList($classId, $pageSize = 9){
  3923. if(!$classId)
  3924. return $this->buildEmptyPagingStruct();
  3925. $handle = $this->sConn->createCommand("
  3926. select c.class_name, seme.semester_name, cvh.generate_time, c.class_id
  3927. from class_vacation_homework as cvh
  3928. join class as c on c.class_id = cvh.class_id
  3929. join semester as seme on seme.semester_id = cvh.semester_id
  3930. where cvh.class_id = '{$classId}' and cvh.semester_id = '{$this->semester["id"]}'
  3931. order by cvh.generate_time desc
  3932. ")->query();
  3933. $rs = $this->paging($this->sConn, $handle, $pageSize);
  3934. return $rs;
  3935. }
  3936. public function getClassesVacationHomeworkList($pageSize = 9){
  3937. $handle = $this->sConn->createCommand("
  3938. select c.class_name, seme.semester_name, cvh.generate_time, c.class_id
  3939. from class_vacation_homework as cvh
  3940. join class as c on c.class_id = cvh.class_id
  3941. join semester as seme on seme.semester_id = cvh.semester_id
  3942. where cvh.semester_id = '{$this->semester["id"]}'
  3943. order by cvh.generate_time desc
  3944. ")->query();
  3945. $rs = $this->paging($this->sConn, $handle, $pageSize);
  3946. return $rs;
  3947. }
  3948. public function getClassVhStudents($classId,$realname = NULL, $pageSize = 9){
  3949. if(!$classId)
  3950. return $this->buildEmptyPagingStruct();
  3951. $where = '';
  3952. // debug($realname);
  3953. if (!empty($realname)) {
  3954. $where = "cvh.class_id = '{$classId}' and cvh.semester_id = '{$this->semester["id"]}' and stu.realname like '%{$realname}%'";
  3955. } else {
  3956. $where = "cvh.class_id = '{$classId}' and cvh.semester_id = '{$this->semester["id"]}'";
  3957. }
  3958. $handle = $this->sConn->createCommand("
  3959. select c.class_name, c.class_id, stu.realname, cvh.semester_id, vh.is_generated, stu.student_id
  3960. from class_vacation_homework as cvh
  3961. join vacation_homework as vh on vh.class_id = cvh.class_id and vh.semester_id = cvh.semester_id
  3962. join student_info as stu on stu.student_id = vh.student_id
  3963. join class as c on c.class_id = cvh.class_id
  3964. where {$where}
  3965. ")->query();
  3966. $rs = $this->paging($this->sConn, $handle, $pageSize);
  3967. return $rs;
  3968. }
  3969. public function getMaterialChapters($materialId){
  3970. $chapters = array();
  3971. if($materialId){
  3972. if(!($module = Yii::app()->cache->get("material_{$materialId}"))){
  3973. $module = Curl::post($this->moduleUrl, array($this->moduleField => $materialId));
  3974. $module = json_decode($module, true);
  3975. if($module)
  3976. Yii::app()->cache->set("material_{$materialId}", $module, $this->chapterCacheTime);
  3977. }
  3978. if(isset($module["chapters"]) && $module["chapters"]){
  3979. foreach($module["chapters"] as $chapter){
  3980. $chapters[$chapter["chapter_id"]] = $chapter;
  3981. if($chapter["chapter_id"] && !Yii::app()->cache->get("chapter_{$chapter["chapter_id"]}"))
  3982. Yii::app()->cache->set("chapter_{$chapter["chapter_id"]}", $chapter, $this->chapterCacheTime);
  3983. }
  3984. }
  3985. }
  3986. return $chapters;
  3987. }
  3988. public function getSchoolInfo(){
  3989. return $this->conn->createCommand("select * from school where school_id = '{$this->schoolId}'")->queryRow();
  3990. }
  3991. public function getArea($areaId){
  3992. if(!$areaId)
  3993. return array();
  3994. return $this->conn->createCommand("select region_id as area_id, region_code as area_code, region_name as area_name from region where region_id = '{$areaId}'")->queryRow();
  3995. }
  3996. public function getSchoolAreaFromSchoolInfo($schoolInfo){
  3997. $schoolArea = array(
  3998. "province_id" => null,
  3999. "province_name" => null,
  4000. "city_id" => null,
  4001. "city_name" => null,
  4002. "district_id" => null,
  4003. "district_name" => null,
  4004. );
  4005. $municipalitiesIds = array(2, 3, 10, 23);
  4006. if(!Arr::isAvailable($schoolInfo, array("province_id", "city_id", "area_id")))
  4007. return $schoolArea;
  4008. if($area = $this->getArea($schoolInfo["province_id"])){
  4009. $schoolArea["province_id"] = $area["area_id"];
  4010. $schoolArea["province_name"] = $area["area_name"];
  4011. }
  4012. if($area = $this->getArea($schoolInfo["city_id"])){
  4013. $schoolArea["city_id"] = $area["area_id"];
  4014. $schoolArea["city_name"] = $area["area_name"];
  4015. }
  4016. if($area = $this->getArea($schoolInfo["area_id"])){
  4017. $schoolArea["district_id"] = $area["area_id"];
  4018. $schoolArea["district_name"] = $area["area_name"];
  4019. }
  4020. if(in_array($schoolArea["province_id"], $municipalitiesIds))
  4021. $schoolArea["city_name"] = $schoolArea["province_name"];
  4022. return $schoolArea;
  4023. }
  4024. public function getCoachIdByClassId($classId){
  4025. if(!$classId)
  4026. return null;
  4027. $rs = $this->sConn->createCommand("select coach_id from `class` where class_id = '{$classId}'")->queryRow();
  4028. return $rs ? current($rs) : null;
  4029. }
  4030. public function getCoachClassRelationByClassId($classId, $type = "ARR"){
  4031. if(!$classId)
  4032. return array();
  4033. $rs = $this->sConn->createCommand("select coach_id, class_id from `class` where class_id = '{$classId}'")->queryRow();
  4034. if($type == "OBJ"){
  4035. $rs = Arr::toObj($rs);
  4036. }
  4037. return $rs;
  4038. }
  4039. public function getCoachClassesRelations($coachId, $type = "ARR"){
  4040. if(!$coachId)
  4041. return array();
  4042. $rs = $this->sConn->createCommand("select coach_id, class_id from class where coach_id = '{$coachId}'")->queryAll();
  4043. if($type == "OBJ"){
  4044. $rs = Arr::toObj($rs);
  4045. }
  4046. return $rs;
  4047. }
  4048. public function getExamClasses($examId){
  4049. if(!$examId)
  4050. return array();
  4051. return $this->sConn->createCommand("
  4052. select c.class_id, c.class_name
  4053. from exam as e
  4054. join class as c on c.class_id = e.class_id
  4055. where e.exam_id = '{$examId}'
  4056. ")->queryAll();
  4057. }
  4058. public function changeExamUploadStatus($examId, $uploadStatus){
  4059. if(!$examId || !$uploadStatus)
  4060. return false;
  4061. return $this->sConn->createCommand()->update("exam", array("upload_status" => $uploadStatus), "exam_id = '{$examId}'");
  4062. }
  4063. public function ExamStatusAndUploadStatus($examId,$status,$upload_status){
  4064. if($examId){
  4065. $rs = $this->sConn->createCommand("select * from `exam` where exam_id = '{$examId}' and status= ".$status." and upload_status = ".$upload_status)->queryRow();
  4066. if($rs)
  4067. {
  4068. return $rs;
  4069. }
  4070. }
  4071. return false;
  4072. }
  4073. public function ExamStatusAndUploadStatusArr($examId,$statusArr,$upload_status){
  4074. if($examId){
  4075. $rs = $this->sConn->createCommand("select * from `exam` where exam_id = '{$examId}' and status in(".implode(',',$statusArr).") and upload_status = ".$upload_status)->queryRow();
  4076. if($rs)
  4077. {
  4078. return $rs;
  4079. }
  4080. }
  4081. return false;
  4082. }
  4083. public function getExamClassesRelations($examId, $type = "ARR"){
  4084. if(!$examId)
  4085. return array();
  4086. $rs = $this->sConn->createCommand("select exam_id, class_id from exam where exam_id = '{$examId}'")->queryAll();
  4087. if($type == "OBJ"){
  4088. $rs = Arr::toObj($rs);
  4089. }
  4090. return $rs;
  4091. }
  4092. public function getExamClassesRelationsFilteredByUploadStatus($examId, $uploadStatus, $type = "ARR"){
  4093. if(!$examId || !$uploadStatus)
  4094. return array();
  4095. $rs = $this->sConn->createCommand("select exam_id, class_id from exam where exam_id = '{$examId}' and upload_status = '{$uploadStatus}'")->queryAll();
  4096. if($type == "OBJ"){
  4097. $rs = Arr::toObj($rs);
  4098. }
  4099. return $rs;
  4100. }
  4101. public function getExamsByExamGroupId($examGroupId, $type = "ARR"){
  4102. if(!$examGroupId)
  4103. return array();
  4104. $rs = $this->sConn->createCommand("select * from exam where exam_group_id = '{$examGroupId}'")->queryAll();
  4105. if($type == "OBJ"){
  4106. $rs = Arr::toObj($rs);
  4107. }
  4108. return $rs;
  4109. }
  4110. public function getExamsIdsByExamGroupId($examGroupId){
  4111. if(!$examGroupId)
  4112. return array();
  4113. $rs = $this->sConn->createCommand("select exam_id from exam where exam_group_id = '{$examGroupId}'")->queryAll();
  4114. return $this->grouping($rs, "exam_id");
  4115. }
  4116. public function getExamGroupIdByExamId($examId){
  4117. if(!($exam = $this->getExam($examId)))
  4118. return null;
  4119. return $exam["exam_group_id"];
  4120. }
  4121. public function getStudentsPaperRs($paperId, $studentsIds, $type = "ARR"){
  4122. if(!$paperId || !is_array($studentsIds) || !$studentsIds)
  4123. return array();
  4124. $studentsIds = "'".implode("','", $studentsIds)."'";
  4125. $orderBy = array("scoring DESC", "right_count ASC", "student_id ASC");
  4126. $orderBy = $this->orderBy($orderBy);
  4127. $rs = $this->sConn->createCommand("select * from student_paper_relation where paper_id = '{$paperId}' and student_id in({$studentsIds}) and (scoring > 0 or lost_score > 0) and is_del=0 {$orderBy}")->queryAll();
  4128. if($type == "OBJ"){
  4129. $rs = Arr::toObj($rs);
  4130. }
  4131. return $rs;
  4132. }
  4133. public function getStudentsPdfsPaths($paperId, $studentsIds, $check = "", $type = "OBJ"){
  4134. if(!$paperId || !is_array($studentsIds) || !$studentsIds)
  4135. return array();
  4136. $studentsIds = "'".implode("','", $studentsIds)."'";
  4137. $condition = array("paper_id = '{$paperId}'", "student_id in({$studentsIds})", "(scoring > 0 or lost_score > 0)");
  4138. if($check == "WB"){
  4139. $condition[] = "is_wrongbook_pdf = 1";
  4140. }
  4141. else if($check == "ISP"){
  4142. $condition[] = "is_isp_pdf = 1";
  4143. }
  4144. else if($check == "WB_ISP"){
  4145. $condition[] = "is_wbisp_pdf = 1";
  4146. }
  4147. $condition[] = "is_del = 0";
  4148. $condition = $this->condition($condition);
  4149. $rs = $this->sConn->createCommand("select wrongbook_pdf_path, isp_pdf_path, wbisp_pdf_path from student_paper_relation{$condition}")->queryAll();
  4150. if($type == "OBJ"){
  4151. $rs = Arr::toObj($rs);
  4152. }
  4153. return $rs;
  4154. }
  4155. public function getThisYearSemesterDictionary($year){
  4156. if(!$year)
  4157. return array();
  4158. return $this->conn->createCommand("select * from semester_refer where code like '{$year}%'")->queryAll();
  4159. }
  4160. public function getThisYearSemesterName($semester_name){
  4161. if(!$semester_name)
  4162. return array();
  4163. return $this->conn->createCommand("select * from semester_refer where `name` = '".$semester_name."'")->queryRow();
  4164. }
  4165. public function classSubjectExists($classId){
  4166. if(!$classId)
  4167. return false;
  4168. $rs = $this->sConn->createCommand("select exists(select * from class_subject_relation where class_id = '{$classId}')")->queryRow();
  4169. $rs = current($rs);
  4170. return $rs ? true : false;
  4171. }
  4172. public function getSemesterNameByCode($code){
  4173. if(!$code)
  4174. return null;
  4175. $rs = $this->conn->createCommand("select `name` from semester_refer where `code` = '{$code}'")->queryRow();
  4176. if(!$rs)
  4177. return null;
  4178. return current($rs);
  4179. }
  4180. public function getPaperWithTopicsDetails($paperId, $type = "JSON"){
  4181. if(!$paperId)
  4182. return array();
  4183. $rs = apiPost(Yii::app()->params['get_api_url'].'/coachio/iointerface/getpaperwithtopicsdetails', 'paperIdStr='.$paperId);
  4184. if($type == "ARR" && $rs){
  4185. $rs = json_decode($rs, true);
  4186. }
  4187. return $rs;
  4188. }
  4189. public function getPaperWithTopicsDetails_v2($paperId, $type = "JSON"){
  4190. if(!$paperId)
  4191. return array();
  4192. $rs = apiPost(Yii::app()->params['get_api_url'].'/coachio/iointerface_v2/getpaperwithtopicsdetails', 'paperIdStr='.$paperId);
  4193. if($type == "ARR" && $rs){
  4194. $rs = json_decode($rs, true);
  4195. }
  4196. return $rs;
  4197. }
  4198. public function getSubjectIdByTopic($topic){
  4199. return isset($topic["subject_id"]) ? $topic["subject_id"] : 0;
  4200. }
  4201. public function getSubjectIdByTplData($tplData){
  4202. return isset($tplData["subjectId"]) ? $tplData["subjectId"] : 0;
  4203. }
  4204. public function checkExamAnswers($examId){
  4205. if(!$examId)
  4206. return false;
  4207. $rs = $this->sConn->createCommand("
  4208. select stu.realname
  4209. from paper as p
  4210. join student_paper_relation as spr on spr.paper_id = p.paper_id
  4211. join student_paper_topic_rs as sptr on sptr.student_id = spr.student_id and sptr.paper_id = spr.paper_id
  4212. join student_info as stu on stu.student_id = spr.student_id
  4213. where p.exam_id = '{$examId}' and spr.is_feedback = 1 and spr.is_del=0 and (sptr.answer = '' and sptr.answer_url = '')
  4214. group by spr.student_id
  4215. ")->queryAll();
  4216. if(!$rs)
  4217. return array();
  4218. $studentsNames = array();
  4219. foreach($rs as $student){
  4220. $studentsNames[] = $student["realname"];
  4221. }
  4222. return $studentsNames;
  4223. }
  4224. // 操作周周练显示状态
  4225. public function oprateExamDisplay($exam_groupId, $flag=0){
  4226. if($exam_groupId){
  4227. $rs = $this->sConn->createCommand("UPDATE `exam` SET `is_display` = '{$flag}' where `exam_group_id` = '{$exam_groupId}'")->execute();
  4228. return $rs ? true : false;
  4229. }
  4230. return false;
  4231. }
  4232. // 操作周周练显示状态
  4233. public function oprateExamExportDisplay($exam_Id, $flag=0){
  4234. if($exam_Id){
  4235. if($this->sConn->createCommand("UPDATE `exam` SET `export_dispaly` = '{$flag}' where `exam_id` = '{$exam_Id}'")->execute())
  4236. {
  4237. return true;
  4238. }
  4239. }
  4240. return false;
  4241. }
  4242. public function ThirdOprateExamDisplay($exam_group_id, $flag=0){
  4243. if($exam_group_id){
  4244. $rs = $this->sConn->createCommand("UPDATE `exam` SET `is_display` = '{$flag}' where `exam_group_id` = '{$exam_group_id}'")->execute();
  4245. return $rs ? true : false;
  4246. }
  4247. return false;
  4248. }
  4249. // 根据年级获取当前学期班级
  4250. public function getSchoolByGrade($grade,$semesterId) {
  4251. return $this->sConn->createCommand("select class_id,class_name from class where grade = '{$grade}' and semester_id='{$semesterId}'")->queryAll();
  4252. }
  4253. /**
  4254. * 刘红伟
  4255. */
  4256. public function getPaperByExamId($exam_id){
  4257. if(!$exam_id)
  4258. return false;
  4259. $rs = $this->sConn->createCommand("select * from paper where `exam_id` = '{$exam_id}'")->queryRow();
  4260. if(!$rs)
  4261. return false;
  4262. return $rs;
  4263. }
  4264. public function getxuekeStatus($semester_id,$is_third = 0)
  4265. {
  4266. $subject_exam_data = array();
  4267. $class_data = ClassModel::model()->findAll('semester_id=:semester_id',array(':semester_id'=>$semester_id));
  4268. $class_array = array();
  4269. if($class_data)
  4270. {
  4271. foreach($class_data as $v)
  4272. {
  4273. $class_array[$v->class_id] = $v->class_id;
  4274. }
  4275. }
  4276. $criteria = new CDbCriteria();
  4277. $criteria->addInCondition('class_id',$class_array);
  4278. $criteria->addCondition('is_new=:is_new');
  4279. $criteria->params[':is_new'] = 0;
  4280. $exam_data = Exam::model()->findAll($criteria);
  4281. unset($criteria);
  4282. $exam_group_id = array();
  4283. if($exam_data)
  4284. {
  4285. foreach($exam_data as $v)
  4286. {
  4287. $exam_group_id[$v->exam_group_id] = $v->exam_group_id;
  4288. $subject_exam_data[$v->exam_group_id][$v->subject_id][$v->exam_id] = $v->exam_id;
  4289. }
  4290. }
  4291. $subject = array();
  4292. $criteria = new CDbCriteria();
  4293. $criteria->addInCondition('exam_group_id',$exam_group_id);
  4294. $criteria->addCondition('is_third=:is_third');
  4295. $criteria->params[':is_third'] = $is_third;
  4296. $exam_group_data = ExamGroup::model()->findAll($criteria);
  4297. if($exam_group_data)
  4298. {
  4299. foreach($exam_group_data as $v)
  4300. {
  4301. if(isset($subject_exam_data[$v->exam_group_id]))
  4302. {
  4303. foreach($subject_exam_data[$v->exam_group_id] as $k=>$s)
  4304. {
  4305. $subject[$k] = $s;
  4306. }
  4307. }
  4308. }
  4309. }
  4310. return $subject;
  4311. }
  4312. public function getStudentProduct($class_ids,$subject_id=3){
  4313. if(!$class_ids) return false;
  4314. $sql = "select student_id,class_id from student_class_relation where class_id in (".implode(',',$class_ids).") and `status` = 0";
  4315. $res = $this->sConn->createCommand($sql)->queryAll();
  4316. $student_rel_class = array();
  4317. if($res){
  4318. foreach ($res as $v){
  4319. if(!isset($student_rel_class[$v['class_id']])){
  4320. $student_rel_class[$v['class_id']] = array();
  4321. }
  4322. $student_rel_class[$v['class_id']][] = $v['student_id'];
  4323. }
  4324. }
  4325. unset($res);
  4326. $rs_is_pdf = array();
  4327. $rs_is_download = array();
  4328. $class_buti=array();
  4329. //查询补题状态
  4330. $sql="select rpc.status,category,rpc.class_id from review_product_class rpc ";
  4331. $sql.=" left join review_paper_product_set rpps on rpps.rprs_id=rpc.rprs_id ";
  4332. $sql.=" where rpps.semester_id = {$this->semester['id']} and rpps.subject_id='{$subject_id}' and rpc.status=5";
  4333. $res = $this->sConn->createCommand($sql)->queryAll();
  4334. if($res){
  4335. foreach ($res as $v){
  4336. $class_buti[(string)$v['class_id']][$v['category']]=1;
  4337. }
  4338. }
  4339. if($student_rel_class){
  4340. $create_num = array();
  4341. foreach ($student_rel_class as $class_id => $student_ids){
  4342. if(!$student_ids){
  4343. continue;
  4344. }
  4345. $__sql = "select student_id,is_download,type,product_type,rpc.status as rpc_status from student_product sp";
  4346. $__sql.=" left join review_product_class rpc on rpc.rpc_id=sp.plan_id";
  4347. $__sql.=" left join review_paper_product_set rpps on rpps.rprs_id=rpc.rprs_id";
  4348. $__sql.= " where sp.semester_id = {$this->semester['id']} and student_id in(".implode(',',$student_ids).") and `type` >0 and rpps.subject_id='{$subject_id}'";
  4349. $sql = $__sql.' and is_pdf_created = 1 ';
  4350. $res = $this->sConn->createCommand($sql)->queryAll();
  4351. if($res){
  4352. foreach ($res as $v){
  4353. if(!isset($create_num[$class_id])){
  4354. $create_num[$class_id] = array();
  4355. }
  4356. if(!isset($create_num[$class_id][$v['product_type']])){
  4357. $create_num[$class_id][$v['product_type']] = 0;
  4358. }
  4359. $create_num[$class_id][$v['product_type']]++;
  4360. $rs_is_pdf[] = array(
  4361. 'class_id' => $class_id,
  4362. 'class_name' => '',
  4363. 'is_download' => $v['is_download'],
  4364. 'type' => $v['type'],
  4365. 'student_id' => $v['student_id'],
  4366. 'student_sum' => $create_num[$class_id][$v['product_type']],
  4367. 'product_type'=>$v['product_type'],
  4368. 'rpc_status'=>$v['rpc_status']
  4369. );
  4370. }
  4371. }
  4372. unset($res);
  4373. $sql = $__sql.' and is_download = 1 ';
  4374. $res = $this->sConn->createCommand($sql)->queryAll();
  4375. if($res){
  4376. $student_sum = count($student_ids);
  4377. foreach ($res as $v){
  4378. $rs_is_download[] = array(
  4379. 'class_id' => $class_id,
  4380. 'class_name' => '',
  4381. 'is_download' => $v['is_download'],
  4382. 'type' => $v['type'],
  4383. 'student_id' => $v['student_id'],
  4384. 'student_sum' => $student_sum,
  4385. 'product_type'=>$v['product_type'],
  4386. );
  4387. }
  4388. }
  4389. unset($res);
  4390. }
  4391. }
  4392. return array($rs_is_pdf,$rs_is_download,$class_buti);
  4393. }
  4394. // public function getStudentProduct($condition = array()){
  4395. // $condition = Arr::merge($condition, array("c.semester_id = '{$this->semester["id"]}'"));
  4396. // $condition = $this->condition($condition);
  4397. // //后面需要优化
  4398. //
  4399. // $rs = $this->sConn->createCommand("
  4400. // select * from (SELECT
  4401. // c.class_name,
  4402. // c.class_id,
  4403. // p.is_download,
  4404. // p.`type`,
  4405. // p.student_id,
  4406. // COUNT(p.student_id) as student_sum
  4407. // FROM
  4408. // class AS c
  4409. // LEFT JOIN student_class_relation cr ON
  4410. // c.class_id = cr.class_id
  4411. // AND cr.`status` = 0
  4412. //
  4413. // LEFT JOIN student_product AS p ON p.student_id = cr.student_id
  4414. // {$condition} and p.semester_id = {$this->semester['id']}
  4415. // GROUP BY c.class_id,p.type ORDER BY c.grade asc,c.class_id asc)as gc WHERE `type` >0")->queryAll();
  4416. //
  4417. //
  4418. // if($rs)
  4419. // {
  4420. // return $rs;
  4421. // }
  4422. // return false;
  4423. // }
  4424. public function getPadSchool($school_ids)
  4425. {
  4426. $school_data = array();
  4427. if($school_ids){
  4428. $school_data = $this->conn->createCommand("
  4429. select s.*,sp.*
  4430. from school_project as sp
  4431. left join school as s on sp.school_id = s.school_id
  4432. WHERE s.school_id in (".implode(',',$school_ids).")
  4433. ")->queryAll();
  4434. }
  4435. return $school_data;
  4436. }
  4437. //根据学校Id读取学生数据
  4438. public function getStudentBySchool($school_id){
  4439. $sql=" select student_id from student where school_id='".$school_id."' and status=1 ";
  4440. $Arr = $this->conn->createCommand($sql)->queryAll();
  4441. return $Arr;
  4442. }
  4443. //读取学生信息扩展字段设置
  4444. public function getStudentExtend(){
  4445. $sql="select * from student_info_extend ";
  4446. $Arr = $this->sConn->createCommand($sql)->queryAll();
  4447. $result=array();
  4448. if($Arr){
  4449. foreach ($Arr as $val){
  4450. $result[$val['field_name']]=array(
  4451. 'field_mean'=>$val['field_mean'],
  4452. 'is_enable'=>$val['is_enable']
  4453. );
  4454. }
  4455. }
  4456. return $result;
  4457. }
  4458. //默认设置扩展
  4459. public function setDefaultStudentExtend(){
  4460. $result=array();
  4461. $insert="insert into student_info_extend(`field_name`,`field_mean`,`is_enable`) values ('field_1','智学网考号',1)";
  4462. $this->sConn->createCommand($insert)->execute();
  4463. $result['field_1']=array(
  4464. 'field_mean'=>'智学网考号',
  4465. 'is_enable'=>1
  4466. );
  4467. return $result;
  4468. }
  4469. //切换学期,保留班级,保留学生
  4470. public function changeSemesterByStudentAndClass($semesterId,$oldSemesterId,$IsRetainClass=false,$IsGraduation=false,$classNewNameArr=array(),$gradeDirector=1){
  4471. if($semesterId && $oldSemesterId){
  4472. $code = array();
  4473. if($this->role !== ROLE_SU){
  4474. if($this->isPreviousSemester($semesterId))
  4475. $code[] = 2001;
  4476. if(!$this->semesterAllowToChange($semesterId)){
  4477. $code[] = 2002;
  4478. }
  4479. }
  4480. if($code)
  4481. return $this->rs($code, __FUNCTION__);
  4482. $class_r_class=array(); //新旧班级对应关系
  4483. $classSql="";
  4484. $classTeacherSql="";
  4485. $classSubjectSql='';
  4486. $classStudentSql='';
  4487. $updateStudentInfoSql=array();
  4488. $updateClassStudentSql='';
  4489. $updateClassProgressSql=array();
  4490. $classTypeArr=array();
  4491. $classifiedValues=array();
  4492. $classifiedSql='';
  4493. $updateTeacherSql=array(); //年级主任同步升班
  4494. $cancelClassSubjectId=array(); //不同步升级年级主任,则删除对应科目
  4495. $classesModel = new ClassModel();
  4496. $classes_old = $this->getSemesterClassesGraduation($oldSemesterId,$IsGraduation); //读取所有原班级
  4497. //判断是否保留班级
  4498. if($IsRetainClass){
  4499. if($classes_old){
  4500. $classValues=array();
  4501. $classTeacherValues=array();
  4502. $classSubjectValues=array();
  4503. foreach($classes_old as $val){
  4504. $classTypeArr[$val['class_id']]=$val['class_type'];
  4505. $checkCreatedClass=$classesModel->find('semester_id=:seid and class_name=:cname',array(':seid'=>$semesterId,':cname'=>$val['class_name']));
  4506. if ($checkCreatedClass)
  4507. {
  4508. $class_r_class[$val['class_id']]=$checkCreatedClass['class_id'];
  4509. continue;
  4510. }else{
  4511. //$classId = getUUID();
  4512. $classId = getUniqueId($this->schoolId);
  4513. if (empty($classId)) {
  4514. $code[]=2003;
  4515. return $this->rs($code, __FUNCTION__);
  4516. }
  4517. $class_r_class[$val['class_id']]=$classId;
  4518. $teacherIds=$this->getTeachersByClassesIds(array($val['class_id']));
  4519. $grade=$val['grade'];
  4520. $className=$val['class_name'];
  4521. if(isset($classNewNameArr[(string)$val['class_id']])){
  4522. $grade=$grade+1;
  4523. $className=$classNewNameArr[(string)$val['class_id']];
  4524. }
  4525. $classValues[]="('".$classId."','".$className."','".$val['level']."','".$grade."','".$semesterId."','".$val['period']."','".time()."','".$this->coachId."','".$val['wrong_book_type']."','".$val['improve_book_type']."','".$val['wb_isp_version']."','".$val['sort']."','".$val['arts_science']."','".$val['teacher_id']."','".$val['class_type']."')";
  4526. // $sql_teacher="select * from teacher_class_relation where class_id = '{$val['class_id']}';";
  4527. // $classTeacher=$this->sConn->createCommand($sql_teacher)->queryAll();
  4528. if($teacherIds){
  4529. foreach($teacherIds as $tid){
  4530. //读取教师岗位
  4531. if($classNewNameArr && $tid['posts']==3){
  4532. if($gradeDirector==1){
  4533. //同步升级
  4534. $updateTeacherSql[]="update teacher set grade='".$grade."' where teacher_id='".$tid['teacher_id']."'";
  4535. $classTeacherValues[]="('".$classId."','".$tid['teacher_id']."','".$semesterId."','".$tid['hxb_ing']."','".$tid['is_bzr']."')";
  4536. }elseif($gradeDirector==2){
  4537. //不同步,取消班级教师关联
  4538. $cancelClassSubjectId[$tid['subjects']]=$tid['subjects'];
  4539. }
  4540. }else{
  4541. $classTeacherValues[]="('".$classId."','".$tid['teacher_id']."','".$semesterId."','".$tid['hxb_ing']."','".$tid['is_bzr']."')";
  4542. }
  4543. }
  4544. }
  4545. //班级科目
  4546. $sql_subject="select * from class_subject_relation where class_id = '{$val['class_id']}';";
  4547. $classSubject=$this->sConn->createCommand($sql_subject)->queryAll();
  4548. if($classSubject){
  4549. foreach ($classSubject as $v){
  4550. if(!$cancelClassSubjectId || !isset($cancelClassSubjectId[$v['subject_id']])){
  4551. $classSubjectValues[]="('".$classId."','".$v['subject_id']."','".$v['material_id']."','".$v['module_ids']."')";
  4552. }
  4553. }
  4554. }
  4555. //更新教学进度
  4556. $updateClassProgressSql[]="update teach_progress_class set class_id = {$classId} where class_id = '{$val['class_id']}'";
  4557. }
  4558. }
  4559. //走班设置
  4560. $classified="select * from classified where semester_id='{$oldSemesterId}'";
  4561. $classifiedData=$this->sConn->createCommand($classified)->queryAll();
  4562. if($classifiedData){
  4563. foreach ($classifiedData as $value){
  4564. $classifiedValues[]="('".$value['grade']."','".$value['subject_id']."','".$value['status']."','".$semesterId."')";
  4565. }
  4566. }
  4567. //组装sql
  4568. if($classValues){
  4569. $classSql="insert into class(`class_id`,`class_name`,`level`,`grade`,`semester_id`,`period`,`add_time`,`coach_id`,`wrong_book_type`,`improve_book_type`,`wb_isp_version`,`sort`,`arts_science`,`teacher_id`,`class_type`) values";
  4570. $classSql.=implode(',',$classValues);
  4571. if($classTeacherValues){
  4572. $classTeacherSql="insert into teacher_class_relation(`class_id`,`teacher_id`,`semester_id`,`hxb_ing`,`is_bzr`) values";
  4573. $classTeacherSql.=implode(',',$classTeacherValues);
  4574. }
  4575. if($classSubjectValues){
  4576. $classSubjectSql="insert into class_subject_relation(`class_id`,`subject_id`,`material_id`,`module_ids`) values";
  4577. $classSubjectSql.=implode(',',$classSubjectValues);
  4578. }
  4579. }
  4580. if($classifiedValues){
  4581. $classifiedDel="delete from classified where semester_id='{$semesterId}'";
  4582. $classifiedSql='insert into classified(`grade`,`subject_id`,`status`,`semester_id`) values ';
  4583. $classifiedSql.=implode(',',$classifiedValues);
  4584. }
  4585. //学生处理
  4586. $classStudentSql="";
  4587. $classStudentValues=array();
  4588. $classIds=array();
  4589. if($class_r_class){
  4590. foreach ($class_r_class as $key=>$val){
  4591. //查询原班学生
  4592. $classStudent=$this->sConn->createCommand("select student_id,serial_number,userno,class_type from student_class_relation where class_id='".$key."' and status=0 ")->queryAll();
  4593. $studentIds=array();
  4594. if($classStudent){
  4595. $classIds[]=$key;
  4596. $classType=isset($classTypeArr[$key])?$classTypeArr[$key]:$v['class_type'];
  4597. foreach ($classStudent as $v){
  4598. $studentIds[]=$v['student_id'];
  4599. $classStudentValues[]="('".$val."','".$v['student_id']."',0,'".$v['serial_number']."','".$v['userno']."','".time()."',0,'".$classType."')";
  4600. }
  4601. $updateStudentInfoSql[]="update student_info set class_id='".$val."' where student_id in(".implode(',',$studentIds).") ;";
  4602. }
  4603. }
  4604. if($classStudentValues){
  4605. $classStudentSql="insert into student_class_relation(`class_id`,`student_id`,`status`,`serial_number`,`userno`,`update_time`,`operation`,`class_type`) values ";
  4606. $classStudentSql.=implode(',',$classStudentValues);
  4607. }
  4608. }
  4609. if($classIds){
  4610. $updateClassStudentSql="update student_class_relation set status=1,operation=3 where class_id in(".implode(',',$classIds).") and status=0; ";
  4611. }
  4612. }
  4613. }
  4614. //执行
  4615. $trans = $this->sConn->beginTransaction();
  4616. try{
  4617. if($this->semesterExists($semesterId)){
  4618. //切表
  4619. $inciseTables = $this->inciseTables;
  4620. $oldSemester = $this->sConn->createCommand("SELECT semester_id,refer_code FROM `semester` WHERE `semester_id` = '".$oldSemesterId."'")->queryRow();
  4621. $newSemester = $this->sConn->createCommand("SELECT semester_id,refer_code FROM `semester` WHERE `semester_id` = '".$semesterId."'")->queryRow();
  4622. foreach ($inciseTables as $inciseTable) {
  4623. $newTableName = $inciseTable . '_' . $newSemester['refer_code']; //新学期表名
  4624. $oldTableName= $inciseTable . '_' . $oldSemester['refer_code']; //旧学期(当前学期)需要改的名字
  4625. $existTable = $this->sConn->createCommand("SHOW TABLES LIKE '$newTableName';")->queryRow(); //查询新学期表是否存在
  4626. if($existTable){
  4627. //修改当前的表名
  4628. $existOldTable=$this->sConn->createCommand("SHOW TABLES LIKE '$oldTableName';")->queryRow(); //查询当前学期表是否存在
  4629. if($existOldTable){
  4630. //throw new Exception('3001');
  4631. //重复表进行重命名
  4632. $bakTableName=$oldTableName.'_'.date('YmdHis');
  4633. $this->sConn->createCommand("ALTER TABLE ".$oldTableName." RENAME TO ".$bakTableName)->execute();
  4634. }
  4635. $this->sConn->createCommand("ALTER TABLE ".$inciseTable." RENAME TO ".$oldTableName)->execute();
  4636. //修改新学期表名
  4637. $this->sConn->createCommand("ALTER TABLE ".$newTableName." RENAME TO ".$inciseTable)->execute();
  4638. }else{
  4639. //修改当前的表名
  4640. $existOldTable=$this->sConn->createCommand("SHOW TABLES LIKE '$oldTableName';")->queryRow(); //查询当前学期表是否存在
  4641. if($existOldTable){
  4642. //throw new Exception('3001');
  4643. //重复表进行重命名
  4644. $bakTableName=$oldTableName.'_'.date('YmdHis');
  4645. $this->sConn->createCommand("ALTER TABLE ".$oldTableName." RENAME TO ".$bakTableName)->execute();
  4646. }
  4647. $this->sConn->createCommand("ALTER TABLE ".$inciseTable." RENAME TO ".$oldTableName)->execute();
  4648. //创建新学期表
  4649. $this->sConn->createCommand('CREATE TABLE '.$inciseTable.' LIKE '.$oldTableName)->execute();
  4650. }
  4651. }
  4652. if($classSql){
  4653. $this->sConn->createCommand($classSql)->execute();
  4654. if($classTeacherSql){
  4655. $this->sConn->createCommand($classTeacherSql)->execute();
  4656. }
  4657. if($classSubjectSql){
  4658. $this->sConn->createCommand($classSubjectSql)->execute();
  4659. }
  4660. if($updateTeacherSql){
  4661. foreach ($updateTeacherSql as $sql){
  4662. $this->sConn->createCommand($sql)->execute();
  4663. }
  4664. }
  4665. }
  4666. if($classStudentSql){
  4667. $this->sConn->createCommand($classStudentSql)->execute();
  4668. if($updateClassStudentSql){
  4669. $this->sConn->createCommand($updateClassStudentSql)->execute();
  4670. }
  4671. if($updateStudentInfoSql){
  4672. foreach($updateStudentInfoSql as $query){
  4673. $this->sConn->createCommand($query)->execute();
  4674. }
  4675. }
  4676. }
  4677. if(isset($classifiedSql) && $classifiedSql ){
  4678. $this->sConn->createCommand($classifiedDel)->execute();
  4679. $this->sConn->createCommand($classifiedSql)->execute();
  4680. }
  4681. if($updateClassProgressSql){
  4682. foreach($updateClassProgressSql as $query){
  4683. $this->sConn->createCommand($query)->execute();
  4684. }
  4685. }
  4686. //处理毕业班学生
  4687. if($IsGraduation){
  4688. $classGraduation= $this->sConn->createCommand("select class_id from class where semester_id = '{$oldSemesterId}' and (grade=3 or grade=9)")->queryAll();
  4689. if($classGraduation){
  4690. $gClassId=array();
  4691. foreach ($classGraduation as $item){
  4692. $gClassId[]=$item['class_id'];
  4693. }
  4694. $this->sConn->createCommand("update student_class_relation set status=1,operation=3 where class_id in(".implode(',',$gClassId).") and status=0; ")->execute();
  4695. }
  4696. }
  4697. $this->sConn->createCommand("update semester set status = 0 where status = 1")->execute();
  4698. $this->sConn->createCommand("update semester set status = 1 where semester_id = '{$semesterId}'")->execute();
  4699. $trans->commit();
  4700. $rs = true;
  4701. }
  4702. else
  4703. $rs = false;
  4704. }
  4705. catch(Exception $e){
  4706. $trans->rollBack();
  4707. if($e->getMessage()=='3001'){
  4708. $code[] = 3001;
  4709. return $this->rs($code, __FUNCTION__);
  4710. }else{
  4711. debug($e->getMessage());
  4712. $rs = false;
  4713. }
  4714. }
  4715. $code = $rs ? 0 : 1002;
  4716. }
  4717. return $this->rs($code, "global");
  4718. }
  4719. //前一学期待分班学生数量
  4720. public function getWaitStudent(){
  4721. $nowSemester=$this->getCurrSemester();
  4722. $count=0;
  4723. //前一学期
  4724. $sql="select semester_id from semester where end_time< '".$nowSemester['end_time']."' order by end_time desc limit 1";
  4725. $prevSemester=$this->sConn->createCommand($sql)->queryRow();
  4726. $sql_student="select count(*) as count from student_class_relation scr ";
  4727. $sql_student.=" join class c on c.class_id=scr.class_id ";
  4728. $sql_student.=" where c.semester_id='".$prevSemester['semester_id']."' and scr.status=2 ";
  4729. $studentCount=$this->sConn->createCommand($sql_student)->queryRow();
  4730. if($studentCount){
  4731. $count=$studentCount['count'];
  4732. }
  4733. return $count;
  4734. }
  4735. //获取上一学期id
  4736. public function getPrevSemesterId(){
  4737. $nowSemester=$this->getCurrSemester();
  4738. $count=0;
  4739. //前一学期
  4740. $sql="select semester_id from semester where end_time< '".$nowSemester['end_time']."' order by end_time desc limit 1";
  4741. $prevSemester=$this->sConn->createCommand($sql)->queryRow();
  4742. if($prevSemester){
  4743. return $prevSemester['semester_id'];
  4744. }
  4745. return 0;
  4746. }
  4747. //读取上学期班级
  4748. public function getClassesBySemesterId($semesterId){
  4749. $classes = array();
  4750. $condition = array();
  4751. $condition= array("semester_id = '{$semesterId}'");
  4752. $condition = $this->condition($condition);
  4753. $orderBy = $this->orderBy(array("class_id asc", "class_name asc"));
  4754. $classes = $this->sConn->createCommand("select * from class{$condition} group by class_id{$orderBy}")->queryAll();
  4755. return $classes;
  4756. }
  4757. public function getPrevSemesterClassStudentsList($classId, $condition = array(), $pageSize = 9,$where=''){
  4758. $student_ids = array();
  4759. if(empty($where))
  4760. {
  4761. $rs = $this->getPrevSemesterClassRelation($classId, $condition, $pageSize, "ARR");
  4762. }else
  4763. {
  4764. $accounts = $this->conn->createCommand("select * from student where ".$where)->queryAll();
  4765. if($accounts)
  4766. {
  4767. $studentIdOr=array();
  4768. foreach ($accounts as $v){
  4769. $studentIdOr[]=" stu.student_id=" . $v['student_id']." ";
  4770. }
  4771. $condition= array(" (".implode(' OR ',$studentIdOr).") ");
  4772. $rs = $this->getPrevSemesterClassRelation($classId, $condition, $pageSize, "ARR");
  4773. }else
  4774. {
  4775. $rs["rs"] =array();
  4776. $rs['pager'] = (object)array();
  4777. $rs['pager']->rowsCount = 0;
  4778. }
  4779. }
  4780. if($rs["rs"]){
  4781. foreach($rs["rs"] as $key => $val){
  4782. $rs["rs"][$key]["username"] = "";
  4783. $rs["rs"][$key]["status"] = null;
  4784. }
  4785. $studentsIds = $this->grouping($rs["rs"], "student_id");
  4786. $studentsIds = implode("','", $studentsIds);
  4787. $studentsIds = "'{$studentsIds}'";
  4788. if($where)
  4789. {
  4790. $accounts = $this->conn->createCommand("select * from student where ".$where)->queryAll();
  4791. if($accounts){
  4792. $b_student_status = array();
  4793. $b_student_card = array();
  4794. $b_student_username = array();
  4795. $b_school_student_card = array();
  4796. $b_zhixue_student_card = array();
  4797. foreach($accounts as $v)
  4798. {
  4799. $b_student_card[$v['student_id']] = $v['student_card'];
  4800. $b_student_status[$v['student_id']] = $v['status'];
  4801. $b_student_username[$v['student_id']] = $v['username'];
  4802. $b_school_student_card[$v['student_id']] = $v['school_student_card'];
  4803. $b_zhixue_student_card[$v['student_id']] = $v['zhixue_student_card'];
  4804. }
  4805. foreach($rs["rs"] as $key => $val){
  4806. if( isset($b_student_card[$val["student_id"]]) && !empty($b_student_card[$val["student_id"]])){
  4807. $rs["rs"][$key]["username"] = $b_student_username[$val["student_id"]];
  4808. $rs["rs"][$key]["student_card"] = $b_student_card[$val["student_id"]];
  4809. $rs["rs"][$key]["school_student_card"] = $b_school_student_card[$val["student_id"]];
  4810. if(isset($b_zhixue_student_card[$val["student_id"]]))
  4811. {
  4812. $rs["rs"][$key]["zhixue_student_card"] = $b_zhixue_student_card[$val["student_id"]];
  4813. }
  4814. $rs["rs"][$key]["status"] = $b_student_status[$val["student_id"]];
  4815. }else
  4816. {
  4817. unset($rs["rs"][$key]);
  4818. $rs['pager']->rowsCount = 0;
  4819. }
  4820. }
  4821. }else
  4822. {
  4823. foreach($rs["rs"] as $key => $val){
  4824. unset($rs["rs"][$key]);
  4825. }
  4826. $rs['pager']->rowsCount = 0;
  4827. }
  4828. }else
  4829. {
  4830. $accounts = $this->conn->createCommand("select * from student where student_id in ({$studentsIds})")->queryAll();
  4831. if($accounts){
  4832. $b_student_status = array();
  4833. $b_student_card = array();
  4834. $b_student_username = array();
  4835. $b_school_student_card = array();
  4836. $b_zhixue_student_card = array();
  4837. foreach($accounts as $v)
  4838. {
  4839. $b_student_card[$v['student_id']] = $v['student_card'];
  4840. $b_student_status[$v['student_id']] = $v['status'];
  4841. $b_student_username[$v['student_id']] = $v['username'];
  4842. $b_school_student_card[$v['student_id']] = $v['school_student_card'];
  4843. $b_zhixue_student_card[$v['student_id']] = $v['zhixue_student_card'];
  4844. }
  4845. foreach($rs["rs"] as $key => $val){
  4846. if( isset($b_student_card[$val["student_id"]]) && !empty($b_student_card[$val["student_id"]])){
  4847. $rs["rs"][$key]["username"] = $b_student_username[$val["student_id"]];
  4848. $rs["rs"][$key]["student_card"] = $b_student_card[$val["student_id"]];
  4849. $rs["rs"][$key]["school_student_card"] = $b_school_student_card[$val["student_id"]];
  4850. if(isset($b_zhixue_student_card[$val["student_id"]]))
  4851. {
  4852. $rs["rs"][$key]["zhixue_student_card"] = $b_zhixue_student_card[$val["student_id"]];
  4853. }
  4854. $rs["rs"][$key]["status"] = $b_student_status[$val["student_id"]];
  4855. }
  4856. }
  4857. }
  4858. }
  4859. }
  4860. return $rs;
  4861. }
  4862. public function getPrevSemesterClassRelation($classId, $condition = array(), $pageSize = 9, $type = "OBJ"){
  4863. $rs = $this->buildEmptyPagingStruct();
  4864. if($classId){
  4865. if(is_array($classId)){
  4866. $condition = Arr::merge(array("scr.class_id in( ".implode(',',$classId).")", "scr.status = 2"), $condition);
  4867. }else{
  4868. $condition = Arr::merge(array("scr.class_id =".$classId, "scr.status = 2"), $condition);
  4869. }
  4870. $condition = $this->condition($condition);
  4871. $handle = $this->sConn->createCommand("
  4872. select stu.*, scr.userno, scr.serial_number, c.class_name
  4873. from student_class_relation as scr
  4874. join student_info as stu on stu.student_id = scr.student_id
  4875. join class as c on c.class_id = scr.class_id
  4876. {$condition}
  4877. order by serial_number asc
  4878. ")->query();
  4879. $rs = $this->paging($this->sConn, $handle, $pageSize);
  4880. }
  4881. return $rs;
  4882. }
  4883. //读取导入学生模板
  4884. public function getImportStudentTemplate(){
  4885. $sql="select * from import_student_template ";
  4886. $Arr = $this->sConn->createCommand($sql)->queryRow();
  4887. $result=array();
  4888. if($Arr){
  4889. $result=$Arr['tpl_data'];
  4890. }
  4891. return $result;
  4892. }
  4893. //判断班级是否存在
  4894. public function classNameExists($className,$semesterIds,$class_type=1){
  4895. if(!$semesterIds || !$className)
  4896. return false;
  4897. if(is_array($semesterIds)){
  4898. $rs = $this->sConn->createCommand("select class_id from class where class_name = '{$className}' and semester_id in(".implode(',',$semesterIds).") and class_type='".$class_type."' and is_hide=0")->queryRow();
  4899. }else{
  4900. $rs = $this->sConn->createCommand("select class_id from class where class_name = '{$className}' and semester_id='".$semesterIds."' and class_type='".$class_type."' and is_hide=0 ")->queryRow();
  4901. }
  4902. if($rs){
  4903. return $rs['class_id'];
  4904. }
  4905. return false;
  4906. }
  4907. //根据班级,姓名 读取行政班学生数据
  4908. public function getStudentByNameClass($studentName,$semesterIds,$idNumber=false){
  4909. if(!$studentName || !$semesterIds){
  4910. return null;
  4911. }
  4912. $sql="SELECT si.student_id,si.realname,si.class_id,c.semester_id,c.class_name FROM `student_info` si ";
  4913. $sql.="join student_class_relation scr on scr.student_id=si.student_id ";
  4914. $sql.="join class c on c.class_id = scr.class_id ";
  4915. $sql.="where si.realname='{$studentName}' and scr.status=0 and scr.class_type=1";
  4916. if(is_array($semesterIds)){
  4917. $sql.=" and semester_id in(".implode(',',$semesterIds).")";
  4918. }else{
  4919. $sql.=" and semester_id ='{$semesterIds}'";
  4920. }
  4921. if($idNumber){
  4922. $sql.=" and si.id_number='".$idNumber."'";
  4923. }
  4924. $student=$this->sConn->createCommand($sql)->queryAll();
  4925. return $student;
  4926. }
  4927. //核验身份证号是否存在
  4928. public function checkStudentIdNumber($id){
  4929. if(!$id) return false;
  4930. $rs = $this->sConn->createCommand("select exists(select student_id from student_info where id_number = '{$id}')")->queryRow();
  4931. $rs = current($rs);
  4932. return $rs ? true : false;
  4933. }
  4934. //读取匹配成功数据
  4935. public function getNormalStudent($condition,$pageSize){
  4936. $where='';
  4937. if($condition){
  4938. $where=" where ".implode(' and ',$condition);
  4939. }
  4940. $handle = $this->sConn->createCommand("select student_name,class_name,sex,modify_name,extend,id_number,student_card from import_student_temp {$where} order by id asc ")->query();
  4941. $rs = $this->paging($this->sConn, $handle, $pageSize);
  4942. return $rs;
  4943. }
  4944. public function getSemesterClassesGraduation($semesterId,$Graduation=false)
  4945. {
  4946. $classes = array();
  4947. if ($semesterId) {
  4948. if ($Graduation) {
  4949. $classes = $this->sConn->createCommand("select * from class where semester_id = '{$semesterId}' and grade<>3 and grade<>9 and is_hide=0")->queryAll();
  4950. } else {
  4951. $classes = $this->sConn->createCommand("select * from class where semester_id = '{$semesterId}' and is_hide=0")->queryAll();
  4952. }
  4953. }
  4954. return $classes;
  4955. }
  4956. //根据班级读取分组
  4957. public function getTeamByClass($class_id,$get="team"){
  4958. if(!$class_id){
  4959. return null;
  4960. }
  4961. $sql="select * from class_team where class_id='".$class_id."'";
  4962. $teamData=$this->sConn->createCommand($sql)->queryAll();
  4963. $student_ids=array();
  4964. if($teamData){
  4965. foreach($teamData as $key=>$val){
  4966. $studentSql="select cst.student_id,cst.student_card,cst.real_name from class_student_team cst ";
  4967. $studentSql.="join student_class_relation scr on scr.student_id=cst.student_id and scr.class_id=cst.class_id ";
  4968. $studentSql.="where cst.team_id='".$val['team_id']."' and scr.status=0";
  4969. $student=$this->sConn->createCommand($studentSql)->queryAll();
  4970. if($student){
  4971. foreach($student as $v){
  4972. $student_ids[$v['student_id']]=$val['team_name'];
  4973. }
  4974. $teamData[$key]['student']=$student;
  4975. }else{
  4976. $teamData[$key]['student']=null;
  4977. }
  4978. }
  4979. }
  4980. if($get=='team'){
  4981. return $teamData;
  4982. }elseif($get=='student'){
  4983. return $student_ids;
  4984. }else{
  4985. return null;
  4986. }
  4987. }
  4988. //根据班级读取学生列表
  4989. public function getStudentByClassId($get_id){
  4990. if(!$get_id) return null;
  4991. $condition = array("scr.class_id = '{$get_id}'", "scr.status = 0");
  4992. $condition = $this->condition($condition);
  4993. $get_list = $this->sConn->createCommand("
  4994. select stu.*, scr.userno, scr.serial_number, c.class_name
  4995. from student_class_relation as scr
  4996. join student_info as stu on stu.student_id = scr.student_id
  4997. join class as c on c.class_id = scr.class_id
  4998. {$condition}
  4999. order by serial_number asc
  5000. ")->queryAll();
  5001. $student_ids = array();
  5002. $result=array();
  5003. if($get_list)
  5004. {
  5005. foreach($get_list as $k=> $v)
  5006. {
  5007. $student_ids[$v['student_id']] = $v['student_id'];
  5008. $result[$v['student_id']]=$v;
  5009. }
  5010. if($student_ids){
  5011. $criteria = new CDbCriteria();
  5012. $criteria->addInCondition('student_id',$student_ids);
  5013. $b_student_data = BusinessStudent::model()->findAll($criteria);
  5014. if($b_student_data)
  5015. {
  5016. foreach($b_student_data as $v)
  5017. {
  5018. $result[$v->student_id]['student_card'] = $v->student_card;
  5019. $result[$v->student_id]['school_student_card'] = (string)$v->school_student_card;
  5020. }
  5021. }
  5022. }
  5023. }
  5024. return $result;
  5025. }
  5026. //读取督学卡上传数量
  5027. public function getSuperviseStudentByExamId($examIds){
  5028. if(!$examIds) return 0;
  5029. $data=$this->sConn->createCommand("select count(*) as count from supervise_card where exam_id in(".implode(',',$examIds).")")->queryRow();
  5030. if($data){
  5031. return $data['count'];
  5032. }
  5033. return 0;
  5034. }
  5035. //判断智学网号是否存在
  5036. public function checkZhiXueNumber($id){
  5037. if(!$id) return false;
  5038. $rs = $this->conn->createCommand("select exists(select student_id from student where zhixue_student_card = '{$id}')")->queryRow();
  5039. $rs = current($rs);
  5040. return $rs ? true : false;
  5041. }
  5042. //读取全部学生id
  5043. public function delStudentPaperByExamIds($examIds){
  5044. if(!$examIds || !is_array($examIds)) return false;
  5045. $rs = $this->sConn->createCommand("update student_paper_relation set `is_del`=1 where exam_id in(".implode(',',$examIds).") and is_feedback=0 ")->execute();
  5046. return $rs;
  5047. }
  5048. //删除student_paper_relation 同步删除student_paper_relation_property
  5049. public function delStudentPaperPropertyByExamIds($examIds,$studentIds){
  5050. if(!$examIds || !is_array($examIds)) return false;
  5051. if(!$studentIds || !is_array($studentIds)) return false;
  5052. $trans = $this->sConn->beginTransaction();
  5053. try{
  5054. $this->sConn->createCommand("update student_paper_relation set `is_del`=1 where exam_id in(".implode(',',$examIds).") and is_feedback=0 ")->execute();
  5055. //$this->sConn->createCommand("delete from student_paper_relation_property where exam_id in(".implode(',',$examIds).") and student_id in(".implode(',',$studentIds).") ")->execute();
  5056. $trans->commit();
  5057. $rs = true;
  5058. }
  5059. catch(Exception $e){
  5060. $trans->rollBack();
  5061. $rs = false;
  5062. }
  5063. return $rs;
  5064. }
  5065. //读取全部学生id
  5066. public function getStudentPaperByExamIds($examIds){
  5067. if(!$examIds || !is_array($examIds)) return false;
  5068. $rs = $this->sConn->createCommand("select student_id from student_paper_relation where exam_id in(".implode(',',$examIds).") and is_feedback=0 and is_del=0 ")->queryAll();
  5069. return $rs;
  5070. }
  5071. //读取一条学期数据,判断是否新学校
  5072. public function getOneSemester(){
  5073. $semester= $this->sConn->createCommand("select semester_id from semester limit 1")->queryRow();
  5074. return $semester;
  5075. }
  5076. //根据学校准考证号读取学生数据
  5077. public function getStudentInfoBySchoolCard($schoolStudentCard,$schoolId,$semesterId){
  5078. $students=$this->conn->createCommand("select student_id from `student` where school_student_card='".$schoolStudentCard."' and school_id='".$schoolId."'")->queryAll();
  5079. $result=array();
  5080. if($students){
  5081. foreach ($students as $key => $val){
  5082. $sql="SELECT si.student_id,si.realname,scr.class_id FROM `student_info` si ";
  5083. $sql.="join student_class_relation scr on scr.student_id=si.student_id ";
  5084. $sql.="join class c on c.class_id = scr.class_id ";
  5085. $sql.="where scr.status=0 and si.student_id='".$val['student_id']."' and c.semester_id='".$semesterId."' ";
  5086. $data=$this->sConn->createCommand($sql)->queryRow();
  5087. if($data){
  5088. $result[]=$data;
  5089. }
  5090. }
  5091. }
  5092. return $result;
  5093. }
  5094. //根据学校准考证号读取学生数据
  5095. public function getStudentIdBySchoolCard($schoolStudentCard,$schoolId){
  5096. $students=$this->conn->createCommand("select student_id from `student` where school_student_card='".$schoolStudentCard."' and school_id='".$schoolId."'")->queryAll();
  5097. return $students;
  5098. }
  5099. //获取教学进度
  5100. public function getTeachProgress($sql = '', $pageSize = 10){
  5101. $handle = $this->sConn->createCommand($sql)->query();
  5102. $rs = $this->paging($this->sConn, $handle, $pageSize);
  5103. if($rs["rs"]){
  5104. }
  5105. return $rs;
  5106. }
  5107. //根据班级id,统计学生数量
  5108. public function getStudentIdByClassId($classId){
  5109. if(!$classId) return 0;
  5110. $result=array();
  5111. $data=$this->sConn->createCommand("select `student_id` from student_class_relation where class_id='".$classId."' and `status`=0 ")->queryAll();
  5112. if($data){
  5113. foreach ($data as $val){
  5114. $result[]=$val['student_id'];
  5115. }
  5116. }
  5117. return $result;
  5118. }
  5119. //统计家长绑定数量
  5120. public function countBindStudentIds($studentIds,$schoolId){
  5121. if(!$studentIds || !is_array($studentIds)) return false;
  5122. if(!$schoolId) return false;
  5123. $sql="select count(parent_id) as count from wx_parent_student where student_id in(".implode(',',$studentIds).") and school_id ='".$schoolId."' ";
  5124. $sql="SELECT * from (SELECT parent_id,student_id,school_id from wx_parent_student where school_id='".$schoolId."' and student_id in(".implode(',',$studentIds).") ) t group by student_id;";
  5125. $data=Yii::app()->db251->createCommand($sql)->queryAll();
  5126. return count($data);
  5127. }
  5128. //根据学生id,读取家长信息
  5129. public function getParentByStudentIds($studentIds,$schoolId){
  5130. if(!$studentIds || !is_array($studentIds)) return false;
  5131. if(!$schoolId) return false;
  5132. $result=array();
  5133. $sql="select pt.student_id,pu.mobile,pt.create_time,pt.type,pt.parent_id,pt.bind_type from `wx_parent_student` pt join wx_parent_user pu on pt.parent_id=pu.user_id ";
  5134. $sql.=" where pt.school_id='".$schoolId."' and pt.student_id in (".implode(',',$studentIds).") order by `type` asc";
  5135. $data=Yii::app()->db251->createCommand($sql)->queryAll();
  5136. if($data){
  5137. foreach ($data as $val){
  5138. $val['mobile']=substr_replace($val['mobile'],'****',3,4);
  5139. $result[$val['student_id']][]=$val;
  5140. }
  5141. }
  5142. return $result;
  5143. }
  5144. //家长端解除绑定
  5145. public function UnbindZl($parentId,$studentId,$schoolId){
  5146. if(!$parentId || !$schoolId || !$studentId) return false;
  5147. $sql="delete from `wx_parent_student` where school_id='".$schoolId."' and parent_id='".$parentId."' and student_id='".$studentId."'";
  5148. if(Yii::app()->db251->createCommand($sql)->execute()){
  5149. return true;
  5150. }
  5151. return false;
  5152. }
  5153. //加载教师
  5154. public function loadTeacher($keyword,$subject){
  5155. $where=array();
  5156. $where[]="status=0 ";
  5157. if($subject){
  5158. $where[]=" subjects='{$subject}'";
  5159. }
  5160. if($keyword){
  5161. $where[]=" teacher_name like '".$keyword."%' ";
  5162. }
  5163. $sql="select teacher_id,teacher_name,subjects,posts from `teacher` where ".implode(' and ',$where);
  5164. $data=$this->sConn->createCommand($sql)->queryAll();
  5165. return $data;
  5166. }
  5167. //获取教师信息
  5168. public function getTeachersByTeacherIds($teachersIds){
  5169. if(!is_array($teachersIds) || !$teachersIds)
  5170. return array();
  5171. $teachersIds = "'".implode("','", $teachersIds)."'";
  5172. return $this->sConn->createCommand("select teacher_name,subjects,status from teacher where teacher_id in({$teachersIds})")->queryAll();
  5173. }
  5174. //读取学校报名数据
  5175. public function getSignUpBySchoolIdTaskId($schoolId,$taskId){
  5176. if(!$schoolId || !$taskId) return null;
  5177. return $this->conn->createCommand("select uesn_id,teacher_id,school_id,user_name,mobile from united_exam_signup where school_id='".$schoolId."' and tk_exam_id='".$taskId."'")->queryRow();
  5178. }
  5179. //报名
  5180. public function SignUp($data){
  5181. if(!$data || !is_array($data)) return false;
  5182. $sql="insert into united_exam_signup set ";
  5183. $setValue=array();
  5184. foreach ($data as $field => $value){
  5185. $setValue[]="`{$field}` = '".$value."'";
  5186. }
  5187. $sql.=implode(',',$setValue);
  5188. return $this->conn->createCommand($sql)->execute();
  5189. }
  5190. //退出 报名
  5191. public function SignOutBySchoolIdTaskId($schoolId,$taskId){
  5192. if(!$schoolId || !$taskId) return null;
  5193. return $this->conn->createCommand("delete from united_exam_signup where school_id='".$schoolId."' and tk_exam_id='".$taskId."'")->execute();
  5194. }
  5195. //根据考试id,读取联考数据
  5196. public function getUnitedByExamGroupId($exam_group_id){
  5197. if(!$exam_group_id) return false;
  5198. $sql="SELECT uea.paper_template_url,uea.answer_template_url,uea.apply_deadline,uea.branch FROM `united_exam` ue ";
  5199. $sql.=" join united_exam_apply uea on uea.task_exam_id=ue.tk_exam_id";
  5200. $sql.=" where ue.exam_group_id='".$exam_group_id."'";
  5201. return $this->conn->createCommand($sql)->queryRow();
  5202. }
  5203. //查询是否有联考数据
  5204. public function getUnitedList($apply_setting_type){
  5205. $time=time();
  5206. if($apply_setting_type==1){
  5207. $sql="select task_exam_id,exam_name,grade,branch,create_time,apply_deadline,exam_time from united_exam_apply where apply_deadline>'".$time."' and apply_setting_type=1";
  5208. }else{
  5209. $sql="select task_exam_id,exam_name,grade,branch,create_time,apply_deadline,exam_time from united_exam_apply where apply_deadline>'".$time."' ";
  5210. }
  5211. return $this->conn->createCommand($sql)->queryAll();
  5212. }
  5213. //查询联考
  5214. public function getUnitedByTaskExamId($task_exam_id){
  5215. if(!$task_exam_id) return false;
  5216. $sql="select task_exam_id,exam_name,grade,branch,create_time,apply_deadline,exam_time from united_exam_apply where task_exam_id='".$task_exam_id."'";
  5217. return $this->conn->createCommand($sql)->queryRow();
  5218. }
  5219. //根据联考id,查询是否创建考试
  5220. public function getExamByTaskId($task_exam_id){
  5221. if(!$task_exam_id) return false;
  5222. $sql="select exam_group_id from united_exam where tk_exam_id='".$task_exam_id."' limit 1";
  5223. return $this->conn->createCommand($sql)->queryRow();
  5224. }
  5225. //查询是否有联考数据
  5226. public function getAllUnitedList($apply_setting_type){
  5227. $time=time();
  5228. if($apply_setting_type==1){
  5229. $sql="select task_exam_id,exam_name,grade,branch,create_time,apply_deadline,exam_time from united_exam_apply where apply_setting_type=1";
  5230. }else{
  5231. $sql="select task_exam_id,exam_name,grade,branch,create_time,apply_deadline,exam_time from united_exam_apply ";
  5232. }
  5233. return $this->conn->createCommand($sql)->queryAll();
  5234. }
  5235. //按学生准考证长度判断
  5236. public function getStudentByCardLength($studentIds,$cardLength){
  5237. if(!$studentIds || !is_array($studentIds)) return false;
  5238. if(!is_numeric($cardLength)) return false;
  5239. $sql="select student_id from student where student_id in(".implode(',',$studentIds).") and char_length(school_student_card)<>".$cardLength." limit 1";
  5240. return $this->conn->createCommand($sql)->queryRow();
  5241. }
  5242. public function UUID_SHORT($length = 20)
  5243. {
  5244. $query = $this->sConn->createCommand("SELECT UUID_SHORT() AS UUID_SHORT")->query()->read();
  5245. $result = $query['UUID_SHORT'];
  5246. if ($length AND is_int($length))
  5247. {
  5248. $result = substr($result, ($length * -1));
  5249. }
  5250. return $result;
  5251. }
  5252. public function getZlExamList($condition = array(), $orderBy = array("zl_create_time desc"), $pageSize = 9){
  5253. $condition = Arr::merge($condition, array("c.semester_id = '{$this->semester["id"]}'"));
  5254. $condition = $this->condition($condition);
  5255. $orderBy = $this->orderBy($orderBy);
  5256. $handle = $this->sConn->createCommand("
  5257. select c.class_name,e.zl_exam_id,eg.zl_exam_group_id,e.zl_class_id, eg.zl_exam_name as exam_name, e.zl_tpl_data, eg.zl_create_time, eg.zl_is_display
  5258. from class as c
  5259. join zl_exam as e on e.zl_class_id = c.class_id
  5260. JOIN zl_exam_group eg ON eg.zl_exam_group_id = e.zl_exam_group_id
  5261. {$condition}
  5262. group by e.zl_class_id, e.zl_exam_id
  5263. {$orderBy}
  5264. ")->query();
  5265. $rs = $this->paging($this->sConn, $handle, $pageSize);
  5266. $ZlStudentExamRelation=new ZlStudentExamRelation();
  5267. $ZlStudentExamRs=new ZlStudentExamRs();
  5268. if($rs['rs']){
  5269. foreach($rs['rs'] as $key => $val){
  5270. $allStudent=$ZlStudentExamRelation->getCountStudentByExamGroupId($val['zl_exam_group_id'],$val['zl_exam_id']);
  5271. $allStudentRs=$ZlStudentExamRs->getCountStudentRsByExamGroupId($val['zl_exam_group_id'],$val['zl_exam_id']);
  5272. $rs['rs'][$key]['is_uploaded_count']=$allStudentRs;
  5273. $rs['rs'][$key]['students_count']=$allStudent;
  5274. }
  5275. }
  5276. return $rs;
  5277. }
  5278. public function getEnglishWeek($condition = array(), $orderBy = array("ew.create_time desc"), $pageSize = 10){
  5279. $condition = Arr::merge($condition, array("ew.semester_id = '{$this->semester["id"]}'"));
  5280. $condition = $this->condition($condition);
  5281. $orderBy = $this->orderBy($orderBy);
  5282. $handle = $this->sConn->createCommand("
  5283. select ew.week_id,ew.set_id,ew.`name`,c.class_name,ew.week_group_id,ews.is_new_version from english_week ew join english_week_setting ews on ews.id=ew.set_id join class c on ew.class_id = c.class_id
  5284. {$condition}
  5285. group by ew.week_id
  5286. {$orderBy}
  5287. ")->query();
  5288. $rs = $this->paging($this->sConn, $handle, $pageSize);
  5289. if($rs['rs']){
  5290. foreach($rs['rs'] as $k=>$v){
  5291. $rs['rs'][$k]['totalCount'] = 0;
  5292. $rs['rs'][$k]['pdfCount'] = 0;
  5293. $rs['rs'][$k]['isDown'] = 0;
  5294. $rs['rs'][$k]['downTime'] = '';
  5295. $week_id = $v['week_id'];
  5296. $sql = "select COUNT(student_id) AS totalCount,SUM(CASE WHEN is_week_pdf = 1 THEN 1 ELSE 0 END) AS pdfCount from english_week_student where student_id > 0 and week_id = '{$week_id}'";
  5297. $countArr = $this->sConn->createCommand($sql)->queryRow();
  5298. if($countArr){
  5299. $rs['rs'][$k]['totalCount'] = isset($countArr['totalCount'])?$countArr['totalCount']:0;
  5300. $rs['rs'][$k]['pdfCount'] = isset($countArr['pdfCount'])?$countArr['pdfCount']:0;
  5301. }
  5302. $sql = "select week_download_time from english_week_student where student_id > 0 and week_id = '{$week_id}' and is_week_download = 1 order by week_download_time desc limit 1";
  5303. $isDownArr = $this->sConn->createCommand($sql)->queryRow();
  5304. if($isDownArr){
  5305. $rs['rs'][$k]['isDown'] = 1;
  5306. $rs['rs'][$k]['downTime'] = isset($isDownArr['week_download_time'])?date("Y-m-d H:i",$isDownArr['week_download_time']):'';
  5307. }
  5308. }
  5309. }
  5310. return $rs;
  5311. }
  5312. public function getEnglishMonth($condition = array(), $orderBy = array("em.create_time desc"), $pageSize = 10){
  5313. $condition = Arr::merge($condition, array("em.semester_id = '{$this->semester["id"]}'"));
  5314. $condition = $this->condition($condition);
  5315. $orderBy = $this->orderBy($orderBy);
  5316. $handle = $this->sConn->createCommand("
  5317. select em.month_id,em.`name`,c.class_name from english_month em join class c on em.class_id = c.class_id
  5318. {$condition}
  5319. group by em.month_id
  5320. {$orderBy}
  5321. ")->query();
  5322. $rs = $this->paging($this->sConn, $handle, $pageSize);
  5323. if($rs['rs']){
  5324. foreach($rs['rs'] as $k=>$v){
  5325. $rs['rs'][$k]['totalCount'] = 0;
  5326. $rs['rs'][$k]['pdfCount'] = 0;
  5327. $rs['rs'][$k]['isDown'] = 0;
  5328. $rs['rs'][$k]['downTime'] = '';
  5329. $month_id = $v['month_id'];
  5330. $sql = "select COUNT(student_id) AS totalCount,SUM(CASE WHEN is_month_pdf = 1 THEN 1 ELSE 0 END) AS pdfCount from english_month_student where month_id = '{$month_id}'";
  5331. $countArr = $this->sConn->createCommand($sql)->queryRow();
  5332. if($countArr){
  5333. $rs['rs'][$k]['totalCount'] = isset($countArr['totalCount'])?$countArr['totalCount']:0;
  5334. $rs['rs'][$k]['pdfCount'] = isset($countArr['pdfCount'])?$countArr['pdfCount']:0;
  5335. }
  5336. $sql = "select download_time from english_month_student where month_id = '{$month_id}' and is_download = 1 order by download_time desc limit 1";
  5337. $isDownArr = $this->sConn->createCommand($sql)->queryRow();
  5338. if($isDownArr){
  5339. $rs['rs'][$k]['isDown'] = 1;
  5340. $rs['rs'][$k]['downTime'] = isset($isDownArr['download_time'])?date("Y-m-d H:i",$isDownArr['download_time']):'';
  5341. }
  5342. }
  5343. }
  5344. return $rs;
  5345. }
  5346. //导出报告列表
  5347. public function getExportList($condition = array(), $orderBy = array("add_time desc"), $pageSize = 9){
  5348. $condition = Arr::merge($condition, array("e.semester_id = '{$this->semester["id"]}'"));
  5349. $condition = $this->condition($condition);
  5350. $orderBy = $this->orderBy($orderBy);
  5351. $handle = $this->sConn->createCommand("
  5352. select e.is_academicr_pdf,e.academicr_pdf_path,e.is_topwb_pdf,e.is_new,e.is_topwb_html, e.name as exam_name, e.tpl_index, e.tpl_data, e.upload_status, e.create_time,e.exam_group_id, e.is_display,e.complete_time,e.is_topwb_pdf,e.topwb_pdf_path,e.topwb_pdf_time,e.is_academicr_pdf, eg.mark_type, eg.mark_status,eg.upload_status as group_upload_status,e.subject_id,
  5353. eg.is_third,c.grade,e.status
  5354. from exam as e
  5355. join class as c on e.class_id=c.class_id
  5356. JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id
  5357. {$condition}
  5358. group by exam_group_id
  5359. {$orderBy}
  5360. ")->query();
  5361. $rs = $this->paging($this->sConn, $handle, $pageSize);
  5362. return $rs;
  5363. }
  5364. //读取班级列表
  5365. public function getExportClassByExamGroupId($examGroupId){
  5366. if(!$examGroupId) return false;
  5367. $sql="SELECT e.is_topwb_pdf,e.class_id,class_name,e.exam_id,e.name,e.status,e.upload_status FROM `exam` e join class c on c.class_id=e.class_id where e.exam_group_id='{$examGroupId}'";
  5368. return $this->sConn->createCommand($sql)->queryAll();
  5369. }
  5370. //获取试卷大题关联表数据
  5371. public function getPaperLargeTopicsRecords($paperId){
  5372. $records = array();
  5373. if($paperId){
  5374. $records = $this->sConn->createCommand("select * from paper_topic_large where paper_id = '{$paperId}'")->queryAll();
  5375. }
  5376. return $records;
  5377. }
  5378. //读取走班设置
  5379. public function getClassShift($semester,$subjectId=0){
  5380. if(!$semester) return null;
  5381. if($subjectId){
  5382. $sql="select grade,subject_id,status from classified where semester_id='{$semester}' and subject_id='{$subjectId}'";
  5383. }else{
  5384. $sql="select grade,subject_id,status from classified where semester_id='{$semester}'";
  5385. }
  5386. return $this->sConn->createCommand($sql)->queryAll();
  5387. }
  5388. //查询走班设置
  5389. public function getClassifiedBySubject($grade,$subject,$semester){
  5390. if(!$semester || !$grade || !$subject) return null;
  5391. $sql="select grade,subject_id,status from classified where semester_id='{$semester}' and grade='{$grade}' and subject_id='{$subject}'";
  5392. return $this->sConn->createCommand($sql)->queryRow();
  5393. }
  5394. //添加走班记录
  5395. public function insertClassified($data){
  5396. if(!$data || !is_array($data)) return false;
  5397. $sql="insert into classified(`grade`,`subject_id`,`status`,`semester_id`) values ";
  5398. $values=array();
  5399. foreach ($data as $val){
  5400. $values[]="('".$val['grade']."','".$val['subject_id']."','".$val['status']."','".$val['semester_id']."')";
  5401. }
  5402. $sql.=implode(',',$values);
  5403. return $this->sConn->createCommand($sql)->execute();
  5404. }
  5405. //更新记录状态
  5406. public function updateClassifiedBySubject($grade,$subject,$semester,$type){
  5407. if(!$semester || !$grade || !$subject || !$type) return false;
  5408. if($type=='enable'){
  5409. $sql="update classified set status=1 where semester_id='{$semester}' and grade='{$grade}' and subject_id='{$subject}'";
  5410. }elseif($type=='disable'){
  5411. $sql="update classified set status=0 where semester_id='{$semester}' and grade='{$grade}' and subject_id='{$subject}'";
  5412. }else{
  5413. return false;
  5414. }
  5415. return $this->sConn->createCommand($sql)->execute();
  5416. }
  5417. //根据年级查询学科
  5418. public function getSubjectByGrade($grade=0,$subjectId=0,$semester){
  5419. if(!$semester) return null;
  5420. if($grade){
  5421. if($subjectId){
  5422. $sql="select subject_id from classified where grade='{$grade}' and semester_id='{$semester}' and status=1 and subject_id='".$subjectId."'";
  5423. }else{
  5424. $sql="select subject_id from classified where grade='{$grade}' and semester_id='{$semester}' and status=1";
  5425. }
  5426. }else{
  5427. if($subjectId){
  5428. $sql="select subject_id from classified where semester_id='{$semester}' and status=1 and subject_id='".$subjectId."'";
  5429. }else{
  5430. $sql="select subject_id from classified where semester_id='{$semester}' and status=1 ";
  5431. }
  5432. }
  5433. return $this->sConn->createCommand($sql)->queryAll();
  5434. }
  5435. public function DelClassSubject($classId){
  5436. if(!$classId)
  5437. return false;
  5438. return $this->sConn->createCommand("delete from class_subject_relation where class_id = '{$classId}'")->execute();
  5439. }
  5440. //读取班级科目
  5441. public function getSubjectByClass($classId,$type='Name'){
  5442. if(!$classId) return null;
  5443. $sql="select subject_id from class_subject_relation where class_id='{$classId}' ";
  5444. $data = $this->sConn->createCommand($sql)->queryAll();
  5445. $result=array();
  5446. if($data){
  5447. foreach ($data as $val){
  5448. if($val['subject_id']){
  5449. if($type=='Name'){
  5450. $result[$val['subject_id']]=Yii::app()->params['subjectId'][$val['subject_id']];
  5451. }else{
  5452. $result[]=$val['subject_id'];
  5453. }
  5454. }
  5455. }
  5456. }
  5457. return $result;
  5458. }
  5459. //获取已走班学生
  5460. public function getStudentBySubjects($subjects,$grade,$semester){
  5461. if(!$subjects || !$semester || !$grade) return null;
  5462. $studentIds=array();
  5463. $classSql="SELECT c.class_id,c.class_name FROM `class` c ";
  5464. $classSql.=" left join class_subject_relation csr on csr.class_id= c.class_id ";
  5465. $classSql.=" where c.class_type=2 and csr.subject_id in(".implode(',',$subjects).") and semester_id='".$semester."' and grade='{$grade}'";
  5466. $classData=$this->sConn->createCommand($classSql)->queryAll();
  5467. $classIds=array();
  5468. if($classData){
  5469. foreach ($classData as $v){
  5470. $classIds[$v['class_id']]=$v['class_id'];
  5471. }
  5472. $sql="select student_id from student_class_relation where class_id in(".implode(',',$classIds).") and status=0";
  5473. $studentData=$this->sConn->createCommand($sql)->queryAll();
  5474. if($studentData){
  5475. foreach ($studentData as $val){
  5476. $studentIds[]=(string)$val['student_id'];
  5477. }
  5478. }
  5479. }
  5480. return $studentIds;
  5481. }
  5482. //根据姓名,查询未走班学生
  5483. public function getClassifiedStudentByName($realName,$subjects,$grade,$semester){
  5484. if(!$subjects || !$semester || !$grade || !$realName) return null;
  5485. $result=array();
  5486. $studentData=$this->sConn->createCommand("select student_id,realname from student_info where realname like '%".$realName."%'")->queryAll();
  5487. if($studentData){
  5488. foreach ($studentData as $val){
  5489. //查询班级
  5490. $classData=$this->sConn->createCommand("select class_id,class_type from student_class_relation where student_id ='".$val['student_id']."' and status=0 ")->queryAll();
  5491. if($classData){
  5492. $flag=true;
  5493. foreach ($classData as $v){
  5494. $classInfo= $this->getClassInfo($v['class_id']);
  5495. if(strcmp($semester,$classInfo['semester_id'])!=0){
  5496. $flag=false;
  5497. break;
  5498. }
  5499. if($grade!=$classInfo['grade']){
  5500. $flag=false;
  5501. break;
  5502. }
  5503. if($v['class_type']==2){
  5504. $classSubjects=$this->getSubjectByClass($v['class_id']);
  5505. foreach ($classSubjects as $subjectId =>$subjectName){
  5506. if(in_array($subjectId,$subjects)){
  5507. $flag=false;
  5508. break;
  5509. }
  5510. }
  5511. }
  5512. }
  5513. if($flag){
  5514. //查询系统准考证
  5515. $studentInfo=$this->conn->createCommand("select student_card from student where student_id='{$val['student_id']}'")->queryRow();
  5516. if($studentInfo){
  5517. $val['realname']=$val['realname'].'('.$studentInfo['student_card'].')';
  5518. }
  5519. $result[]=$val;
  5520. }
  5521. }
  5522. }
  5523. }
  5524. return $result;
  5525. }
  5526. //查询指定班级内相似姓名学生
  5527. public function searchStudentByClassIdsStudentName($classIds,$studentName,$excludeStudentIds=array()){
  5528. if(!$classIds || !is_array($classIds) || !$studentName) return null;
  5529. $sql="select si.student_id,si.realname,scr.class_id from student_info si ";
  5530. $sql.=" join student_class_relation scr on scr.student_id=si.student_id ";
  5531. $sql.=" where scr.class_id in(".implode(',',$classIds).") and si.realname like '%".$studentName."%'";
  5532. $result=array();
  5533. $data=$this->sConn->createCommand($sql)->queryAll();
  5534. if($data){
  5535. foreach ($data as $val){
  5536. if($excludeStudentIds && in_array((string)$val['student_id'],$excludeStudentIds,true)){
  5537. continue;
  5538. }
  5539. $studentCard=$this->conn->createCommand("select student_card from student where student_id='".$val['student_id']."'")->queryRow();
  5540. if($studentCard){
  5541. $result[$val['student_id']]=array(
  5542. 'realname'=>$val['realname'].'('.$studentCard['student_card'].')',
  5543. 'class_id'=>$val['class_id'],
  5544. 'student_id'=>$val['student_id']
  5545. );
  5546. }
  5547. }
  5548. }
  5549. return $result;
  5550. }
  5551. //添加走班学生
  5552. public function addClassifiedStudent($studentIds,$classId){
  5553. $subjects=$this->getSubjectByClass($classId); //本班级科目
  5554. $sql="replace into student_class_relation(`class_id`,`serial_number`,`student_id`,`status`,`update_time`,`operation`,`class_type`) values ";
  5555. $values=array();
  5556. $serialNumber=array();
  5557. foreach ($studentIds as $student_id){
  5558. //查询已有走班记录
  5559. $classRelation=$this->sConn->createCommand("select class_id from student_class_relation where student_id='{$student_id}' and status=0 and class_type=2")->queryAll();
  5560. if($classRelation){
  5561. foreach ($classRelation as $class_id){
  5562. $classSubject=$this->getSubjectByClass($class_id['class_id'],'ID');
  5563. if(array_intersect($classSubject,$subjects)){
  5564. //已经有相关科目的走班记录
  5565. return -1;
  5566. }
  5567. }
  5568. }
  5569. //查询新班级最大序号
  5570. if(!isset($serialNumber[$classId])){
  5571. $newClass=$this->sConn->createCommand("select serial_number from student_class_relation where class_id='{$classId}' order by serial_number desc limit 1")->queryRow();
  5572. if($newClass ){
  5573. $serialNumber[$classId]=intval($newClass['serial_number'])+1;
  5574. }else{
  5575. $serialNumber[$classId]=1;
  5576. }
  5577. }else{
  5578. $serialNumber[$classId]++;
  5579. }
  5580. $values[]="('".$classId."','".$serialNumber[$classId]."','".$student_id."',0,'".time()."',2,2)";
  5581. }
  5582. if($values){
  5583. $sql.=implode(',',$values);
  5584. $rs=$this->sConn->createCommand($sql)->execute();
  5585. }
  5586. return $rs;
  5587. }
  5588. //教学班转班
  5589. public function copyClassified($toClassId,$studentData){
  5590. if(!$toClassId || !$studentData) return false;
  5591. //查询目标班级
  5592. $classSubjects=$this->getSubjectByClass($toClassId,'ARR');
  5593. //取消原所在班级关系
  5594. $updateOldClass=array();
  5595. $insertNewClass=array();
  5596. //查询新班级最大序号
  5597. $serialNumber=1;
  5598. $newClass=$this->sConn->createCommand("select serial_number from student_class_relation where class_id='{$toClassId}' order by serial_number desc limit 1")->queryRow();
  5599. if($newClass){
  5600. $serialNumber=intval($newClass['serial_number'])+1;
  5601. }
  5602. foreach ($studentData as $studentId => $classId){
  5603. $updateOldClass[]="update student_class_relation set status=1,operation=2 where class_id='{$classId}' and student_id='{$studentId}'";
  5604. //查询学生原科目
  5605. $sql="select c.class_id,csr.subject_id,scr.student_id,scr.`status` from class c";
  5606. $sql.=" join class_subject_relation csr on csr.class_id=c.class_id ";
  5607. $sql.="join student_class_relation scr on scr.class_id=c.class_id";
  5608. $sql.=" where scr.`status`=0 and scr.student_id='{$studentId}' and csr.subject_id in(".implode(',',$classSubjects).") and c.class_type=2 ";
  5609. $repeatSubjectData=$this->sConn->createCommand($sql)->queryAll();
  5610. //取消学生原科目与目标班科目冲突关系
  5611. if($repeatSubjectData){
  5612. foreach ($repeatSubjectData as $v){
  5613. $updateOldClass[]="update student_class_relation set status=1,operation=2 where class_id='".$v['class_id']."' and student_id='{$studentId}'";
  5614. }
  5615. }
  5616. //加入新班级
  5617. $insertNewClass[]="('".$toClassId."','".$studentId."',0,'".$serialNumber."',0,'".time()."',2,2)";
  5618. $serialNumber++;
  5619. }
  5620. $trans = $this->sConn->beginTransaction();
  5621. try{
  5622. if($updateOldClass){
  5623. foreach ($updateOldClass as $v){
  5624. $this->sConn->createCommand($v)->execute();
  5625. }
  5626. }
  5627. if($insertNewClass){
  5628. $insertSql="insert into student_class_relation(`class_id`,`student_id`,`status`,`serial_number`,`userno`,`update_time`,`operation`,`class_type`) values ";
  5629. $insertSql.=implode(',',$insertNewClass);
  5630. $this->sConn->createCommand($insertSql)->execute();
  5631. }
  5632. $trans->commit();
  5633. $rs = true;
  5634. }
  5635. catch(Exception $e){
  5636. $trans->rollBack();
  5637. $rs = false;
  5638. }
  5639. return $rs;
  5640. }
  5641. //根据班级,姓名 读取教学班学生数据
  5642. public function getStudentByNameClassified($studentName,$semesterIds){
  5643. if(!$studentName || !$semesterIds){
  5644. return null;
  5645. }
  5646. $sql="SELECT si.student_id,si.realname,si.class_id,c.semester_id,c.class_name,c.grade FROM `student_info` si ";
  5647. $sql.="join student_class_relation scr on scr.student_id=si.student_id ";
  5648. $sql.="join class c on c.class_id = scr.class_id ";
  5649. $sql.="where si.realname='{$studentName}' and scr.status=0 and scr.class_type=2";
  5650. if(is_array($semesterIds)){
  5651. $sql.=" and semester_id in(".implode(',',$semesterIds).")";
  5652. }else{
  5653. $sql.=" and semester_id ='{$semesterIds}'";
  5654. }
  5655. $student=$this->sConn->createCommand($sql)->queryAll();
  5656. return $student;
  5657. }
  5658. //根据科目读取教学班
  5659. public function getClassifiedBySubjectId($grade,$subjectId,$semesterId){
  5660. $sql="select c.class_id,c.class_name from class c ";
  5661. $sql.="join class_subject_relation csr on csr.class_id=c.class_id ";
  5662. $sql.=" where c.grade='".$grade."' and csr.subject_id='".$subjectId."' and c.semester_id='".$semesterId."'";
  5663. return $this->sConn->createCommand($sql)->queryAll();
  5664. }
  5665. public function getClassIdBySubjectId($subjectId,$semesterId=0){
  5666. $sql="select c.class_id,c.class_name from class c ";
  5667. $sql.="join class_subject_relation csr on csr.class_id=c.class_id ";
  5668. $sql.=" where csr.subject_id='".$subjectId."'";
  5669. if($semesterId){
  5670. $sql.=" and c.semester_id='".$semesterId."'";
  5671. }
  5672. $classIds=array();
  5673. $data=$this->sConn->createCommand($sql)->queryAll();
  5674. if($data){
  5675. foreach ($data as $val){
  5676. $classIds[]=$val['class_id'];
  5677. }
  5678. }
  5679. return $classIds;
  5680. }
  5681. //
  5682. public function checkClassifiedSubject($subjectId,$classId){
  5683. if(!$subjectId || !$classId) return false;
  5684. $sql="select exists(select subject_id from class_subject_relation where class_id='{$classId}' and subject_id='{$subjectId}')";
  5685. $rs = $this->sConn->createCommand($sql)->queryRow();
  5686. $rs = current($rs);
  5687. return $rs ? true : false;
  5688. }
  5689. public function getMathWeek($condition = array(), $orderBy = array("mrs.create_time desc"), $pageSize = 10){
  5690. $condition = Arr::merge($condition, array("mrs.semester_id = '{$this->semester["id"]}'"));
  5691. $condition = $this->condition($condition);
  5692. $orderBy = $this->orderBy($orderBy);
  5693. $handle = $this->sConn->createCommand("
  5694. select mrs.mr_id,special_id,name,c.grade,c.class_id,c.class_name from math_review_setting mrs join class c on mrs.class_id= c.class_id
  5695. {$condition}
  5696. group by mrs.mr_id
  5697. {$orderBy}
  5698. ")->query();
  5699. $rs = $this->paging($this->sConn, $handle, $pageSize);
  5700. if($rs['rs']){
  5701. foreach($rs['rs'] as $k=>$v){
  5702. $rs['rs'][$k]['totalCount'] = 0;
  5703. $rs['rs'][$k]['pdfCount'] = 0;
  5704. $rs['rs'][$k]['isDown'] = 0;
  5705. $rs['rs'][$k]['downTime'] = '';
  5706. $mr_id=$v['mr_id'];
  5707. $sql = "select COUNT(student_id) AS totalCount,SUM(CASE WHEN is_review_pdf = 1 THEN 1 ELSE 0 END) AS pdfCount from math_review_student where mr_id = '{$mr_id}'";
  5708. $countArr = $this->sConn->createCommand($sql)->queryRow();
  5709. if($countArr){
  5710. $rs['rs'][$k]['totalCount'] = isset($countArr['totalCount'])?$countArr['totalCount']:0;
  5711. $rs['rs'][$k]['pdfCount'] = isset($countArr['pdfCount'])?$countArr['pdfCount']:0;
  5712. }
  5713. $sql = "select review_download_time from math_review_student where mr_id = '{$mr_id}' and is_review_download = 1 order by review_download_time desc limit 1";
  5714. $isDownArr = $this->sConn->createCommand($sql)->queryRow();
  5715. if($isDownArr){
  5716. $rs['rs'][$k]['isDown'] = 1;
  5717. $rs['rs'][$k]['downTime'] = isset($isDownArr['review_download_time'])?date("Y-m-d H:i",$isDownArr['review_download_time']):'';
  5718. }
  5719. }
  5720. }
  5721. return $rs;
  5722. }
  5723. public function getStudentByExamIds($examsIds,$page,$pageSize){
  5724. if(!$examsIds) return null;
  5725. $offset=($page-1)*$pageSize;
  5726. $query=$this->sConn->createCommand("select count(*) as count from student_paper_relation where exam_id in(".implode(',',$examsIds).") and is_feedback=0 ")->queryRow();
  5727. $total=$query['count'];
  5728. $pages=ceil($total/$pageSize);
  5729. $sprs = $this->sConn->createCommand("select student_id,student_card from student_paper_relation where exam_id in(".implode(',',$examsIds).") and is_feedback=0 limit {$offset},{$pageSize} ")->queryAll();
  5730. $data['pageTotal']=$pages;
  5731. $data['page']=$page;
  5732. $data['list']=$sprs;
  5733. $data['pageSize']=$pageSize;
  5734. return $data;
  5735. }
  5736. public function getAllStudentByExamIds($examsIds){
  5737. if(!$examsIds) return null;
  5738. $sprs = $this->sConn->createCommand("select student_id,student_card from student_paper_relation where exam_id in(".implode(',',$examsIds).") and is_feedback=0 ")->queryAll();
  5739. if($sprs){
  5740. foreach($sprs as $key =>$val){
  5741. $StudentInfo=$this->sConn->createCommand("select realname from `student_info` where student_id='".$val['student_id']."' ")->queryRow();
  5742. if($StudentInfo){
  5743. $sprs[$key]['realname']=$StudentInfo['realname'];
  5744. }
  5745. }
  5746. }
  5747. return $sprs;
  5748. }
  5749. //读取在线答题卡
  5750. public function getAnswerSheetOnline($examGroupId){
  5751. if(!$examGroupId || !is_numeric($examGroupId)){
  5752. return null;
  5753. }
  5754. $rs=$this->sConn->createCommand("select online_card,is_qrcode_online,file_path,multiplex_id from `third_answer_sheet` where exam_group_id='{$examGroupId}' and online_card=1")->queryRow();
  5755. return $rs;
  5756. }
  5757. /**
  5758. * 英语外刊美文产品列表
  5759. */
  5760. public function getEnglishReading($condition = array(), $orderBy = array("er.create_time desc"), $pageSize = 10){
  5761. $condition = Arr::merge($condition, array("er.semester_id = '{$this->semester["id"]}'"));
  5762. $condition = $this->condition($condition);
  5763. $orderBy = $this->orderBy($orderBy);
  5764. $handle = $this->sConn->createCommand("
  5765. select er.week_id,er.reading_id,er.`name`,c.class_name,ers.type,ers.level,ers.recommend_mode,ers.product_type from english_reading er join class c on er.class_id = c.class_id join english_reading_setting ers on er.reading_id = ers.reading_id
  5766. {$condition}
  5767. group by er.week_id
  5768. {$orderBy}
  5769. ")->query();
  5770. $rs = $this->paging($this->sConn, $handle, $pageSize);
  5771. if($rs['rs']){
  5772. foreach($rs['rs'] as $k=>$v){
  5773. $rs['rs'][$k]['totalCount'] = 0;
  5774. $rs['rs'][$k]['pdfCount'] = 0;
  5775. $rs['rs'][$k]['isDown'] = 0;
  5776. $rs['rs'][$k]['downTime'] = '';
  5777. $rs['rs'][$k]['type_name'] = '';
  5778. $rs['rs'][$k]['recommend_mode_name'] = '';
  5779. $rs['rs'][$k]['product_type_name'] = '';
  5780. if($v['recommend_mode']==1){
  5781. $rs['rs'][$k]['recommend_mode_name']='经典模式';
  5782. }elseif($v['recommend_mode']==2){
  5783. $rs['rs'][$k]['recommend_mode_name']='智能推荐模式';
  5784. }
  5785. if($v['product_type']==1){
  5786. $rs['rs'][$k]['product_type_name']='基础宝';
  5787. }elseif($v['product_type']==2){
  5788. $rs['rs'][$k]['product_type_name']='外刊宝';
  5789. }elseif($v['product_type']==3){
  5790. $rs['rs'][$k]['product_type_name']='热点宝';
  5791. }
  5792. if($v['type'] == 1){
  5793. $rs['rs'][$k]['type_name'] = '(个性外刊)';
  5794. }else if($v['type'] == 2){
  5795. if($v['level'] == 1){
  5796. $rs['rs'][$k]['type_name'] = '(共性外刊-尖子班)';
  5797. }else if($v['level'] == 2){
  5798. $rs['rs'][$k]['type_name'] = '(共性外刊-培优班)';
  5799. }else if($v['level'] == 3){
  5800. $rs['rs'][$k]['type_name'] = '(共性外刊-提高班)';
  5801. }
  5802. }
  5803. $week_id = $v['week_id'];
  5804. $sql = "select COUNT(student_id) AS totalCount,SUM(CASE WHEN is_week_pdf = 1 THEN 1 ELSE 0 END) AS pdfCount from english_reading_student where week_id = '{$week_id}'";
  5805. $countArr = $this->sConn->createCommand($sql)->queryRow();
  5806. if($countArr){
  5807. $rs['rs'][$k]['totalCount'] = isset($countArr['totalCount'])?$countArr['totalCount']:0;
  5808. $rs['rs'][$k]['pdfCount'] = isset($countArr['pdfCount'])?$countArr['pdfCount']:0;
  5809. }
  5810. $sql = "select week_download_time from english_reading_student where week_id = '{$week_id}' and is_week_download = 1 order by week_download_time desc limit 1";
  5811. $isDownArr = $this->sConn->createCommand($sql)->queryRow();
  5812. if($isDownArr){
  5813. $rs['rs'][$k]['isDown'] = 1;
  5814. $rs['rs'][$k]['downTime'] = isset($isDownArr['week_download_time'])?date("Y-m-d H:i",$isDownArr['week_download_time']):'';
  5815. }
  5816. }
  5817. }
  5818. return $rs;
  5819. }
  5820. /**
  5821. * 假期报告列表
  5822. */
  5823. public function getHolidayReport($condition = array(), $orderBy = array("hrs.create_time desc"), $pageSize = 10){
  5824. $condition = $this->condition($condition);
  5825. $orderBy = $this->orderBy($orderBy);
  5826. $handle = $this->sConn->createCommand("
  5827. select hrs.report_id,hrs.report_group_id,c.class_name,hrs.semester_id,s.semester_name,hrs.create_time,hrs.reset_times,hrs.class_id,hrs.reset_time from holiday_report_setting hrs join class c on hrs.class_id = c.class_id join semester s on s.semester_id= hrs.semester_id
  5828. {$condition}
  5829. group by hrs.report_id
  5830. {$orderBy}
  5831. ")->query();
  5832. $rs = $this->paging($this->sConn, $handle, $pageSize);
  5833. if($rs['rs']){
  5834. $rs['is_all_pdf'] = 1;//是否全部生成pdf
  5835. $rs['create_time'] = 0;//创建时间
  5836. $create_time_arr = array();
  5837. $reset_time_arr = array();
  5838. foreach($rs['rs'] as $k=>$v){
  5839. $rs['create_time'] = $v['create_time']?$v['create_time']:0;
  5840. if($v['create_time']){
  5841. $create_time_arr[] = $v['create_time'];
  5842. }
  5843. if($v['reset_time']){
  5844. $reset_time_arr[] = $v['reset_time'];
  5845. }
  5846. $rs['rs'][$k]['totalCount'] = 0;
  5847. $rs['rs'][$k]['pdfCount'] = 0;
  5848. $rs['rs'][$k]['isDown'] = 0;
  5849. $rs['rs'][$k]['downTime'] = '';
  5850. $rs['rs'][$k]['report_name'] = $v['class_name'].$v['semester_name'].'假期总结报告';
  5851. $rs['rs'][$k]['create_time'] = $v['reset_time']?date('Y-m-d',$v['reset_time']):date('Y-m-d',$v['create_time']);
  5852. $report_id = $v['report_id'];
  5853. $sql = "select COUNT(student_id) AS totalCount,SUM(CASE WHEN is_report_pdf = 1 THEN 1 ELSE 0 END) AS pdfCount from holiday_report_student where report_id = '{$report_id}'";
  5854. $countArr = $this->sConn->createCommand($sql)->queryRow();
  5855. if($countArr){
  5856. $rs['rs'][$k]['totalCount'] = isset($countArr['totalCount'])?$countArr['totalCount']:0;
  5857. $rs['rs'][$k]['pdfCount'] = isset($countArr['pdfCount'])?$countArr['pdfCount']:0;
  5858. }
  5859. if($rs['is_all_pdf']){
  5860. if($rs['rs'][$k]['totalCount'] && $rs['rs'][$k]['pdfCount'] != $rs['rs'][$k]['totalCount']){
  5861. $rs['is_all_pdf'] = 0;
  5862. }else{
  5863. $rs['is_all_pdf'] = 1;
  5864. }
  5865. }
  5866. $sql = "select report_download_time from holiday_report_student where `report_id` = '{$report_id}' and is_report_download = 1 order by report_download_time desc limit 1";
  5867. $isDownArr = $this->sConn->createCommand($sql)->queryRow();
  5868. if($isDownArr){
  5869. $rs['rs'][$k]['isDown'] = 1;
  5870. $rs['rs'][$k]['downTime'] = isset($isDownArr['report_download_time'])?date("Y-m-d H:i",$isDownArr['report_download_time']):'';
  5871. }
  5872. }
  5873. if($reset_time_arr){
  5874. $rs['create_time'] = max($reset_time_arr);
  5875. }else{
  5876. if($create_time_arr){
  5877. $rs['create_time'] = max($create_time_arr);
  5878. }
  5879. }
  5880. }
  5881. return $rs;
  5882. }
  5883. /**
  5884. * 根据条件获取班级
  5885. */
  5886. public function getClassesByCondition($condition = array(),$orderBy = array()){
  5887. $classes = array();
  5888. $condition = $this->condition($condition);
  5889. $orderBy = $this->orderBy($orderBy);
  5890. $classes = $this->sConn->createCommand("select * from class{$condition} group by class_id{$orderBy}")->queryAll();
  5891. return $classes;
  5892. }
  5893. /**
  5894. * 批量插入假期报告学生
  5895. */
  5896. public function batchInsetHolidayReport($schoolId,$semesterId,$is_current_semester,$is_qxk_school=0){
  5897. $data = array();
  5898. $data['status'] = 0;
  5899. $data['error'] = '创建失败';
  5900. $new_report_ids = array();
  5901. $time = time();
  5902. // $classIds = $this->getClassesByCondition(array('semester_id='.$semesterId,'class_type=1','is_hide=0'),array());
  5903. $classIds = $this->getClassesByCondition(array('semester_id='.$semesterId,'class_type=1'),array());
  5904. $is_qxk_school = $is_qxk_school?1:0;
  5905. if(!$classIds){
  5906. $data['error'] = '暂无班级';
  5907. return $data;
  5908. }else{
  5909. $class_count = count($classIds);
  5910. $report_ids = getBatchUuid($schoolId,$class_count);
  5911. if($report_ids){
  5912. $report_ids_values = array_values($report_ids);
  5913. if(count($classIds) != count($report_ids)){
  5914. $data['error'] = '班级数量不符合';
  5915. return $data;
  5916. }
  5917. $i = 0;
  5918. $classIds = array_values($classIds);
  5919. foreach($classIds as $k=>$v){
  5920. if(isset($report_ids_values[$i]) && $report_ids_values[$i]){
  5921. $new_report_ids[$v["class_id"]] = $report_ids_values[$i];
  5922. }
  5923. $i++;
  5924. }
  5925. }else{
  5926. $data['error'] = 'Id错误';
  5927. return $data;
  5928. }
  5929. }
  5930. if($is_current_semester){
  5931. $sql = "select c.class_name,c.class_id,scr.student_id from class c join student_class_relation scr on c.class_id = scr.class_id where c.semester_id = '{$semesterId}' and c.class_type = 1 and scr.`status`=0 group by scr.student_id";
  5932. }else{
  5933. $sql = "select class_name,class_id,student_id from (select c.class_name,c.class_id,scr.student_id,scr.update_time from class c join student_class_relation scr on c.class_id = scr.class_id where c.semester_id = '{$semesterId}' and c.class_type = 1 order BY scr.update_time desc) a GROUP BY student_id order by update_time desc";
  5934. }
  5935. $student_data = $this->sConn->createCommand($sql)->queryAll();
  5936. if(!$student_data){
  5937. $data['error'] = '暂无学生';
  5938. return $data;
  5939. }
  5940. $trans = $this->sConn->beginTransaction();
  5941. try{
  5942. $report_group_id = getUniqueId($schoolId);
  5943. $insert_values = "";
  5944. foreach($classIds as $class){
  5945. if(isset($new_report_ids[$class["class_id"]]) && $new_report_ids[$class["class_id"]]){
  5946. $report_id = $new_report_ids[$class["class_id"]];
  5947. $insert_values .= "(".$report_group_id.",".$report_id.",".$class["grade"].",".$class["semester_id"].",".$class["class_id"].",".$time.",".$is_qxk_school."),";
  5948. }
  5949. }
  5950. if($insert_values){
  5951. $insert_sql = "insert into holiday_report_setting (report_group_id,report_id,grade,semester_id,class_id,create_time,is_qxk_school) values".substr($insert_values,0,-1).';';
  5952. $this->sConn->createCommand($insert_sql)->execute();
  5953. }
  5954. if($student_data){
  5955. $count = count($student_data);//需要插入的学生总数
  5956. $limit = 3000;
  5957. $page = ceil($count/$limit);
  5958. for ($i=0; $i < $page; $i++) {
  5959. $values = '';
  5960. for ($j=$i*$limit; $j < ($i+1)*$limit; $j++) {
  5961. if($j > $count - 1){
  5962. continue;
  5963. }
  5964. if(isset($new_report_ids[$student_data[$j]['class_id']]) && $new_report_ids[$student_data[$j]['class_id']]){
  5965. //拼接values的值
  5966. $report_id_2 = $new_report_ids[$student_data[$j]['class_id']];
  5967. $values .= '('.$report_id_2.','.$student_data[$j]['class_id'].','.$student_data[$j]['student_id'].'),';
  5968. }
  5969. }
  5970. $values = "insert into holiday_report_student (report_id,class_id,student_id) values".substr($values,0,-1).';';
  5971. $this->sConn->createCommand($values)->execute();
  5972. }
  5973. }
  5974. $trans->commit();
  5975. $data['status'] = 1;
  5976. $data['error'] = '创建成功';
  5977. }
  5978. catch(Exception $e){
  5979. $trans->rollBack();
  5980. $data['status'] = 0;
  5981. $data['error'] = '创建失败';
  5982. }
  5983. return $data;
  5984. }
  5985. /**
  5986. * 重置假期报告
  5987. */
  5988. public function resetReport($reportId,$classId,$is_current_semester,$is_qxk_school=0){
  5989. $time = time();
  5990. $status = false;
  5991. $is_qxk_school = $is_qxk_school?1:0;
  5992. $trans = $this->sConn->beginTransaction();
  5993. try{
  5994. //删除学生数据
  5995. $sql = "delete from holiday_report_student where report_id = '{$reportId}'";
  5996. $this->sConn->createCommand($sql)->execute();
  5997. //学生数据
  5998. if($is_current_semester){
  5999. $sql = "select c.class_name,c.class_id,scr.student_id from class c join student_class_relation scr on c.class_id = scr.class_id where c.class_id = '{$classId}' and scr.`status`=0 group by scr.student_id" ;
  6000. }else{
  6001. $sql = "select student_id,update_time,class_id from (select student_id,update_time,class_id from student_class_relation where class_id = '{$classId}' order by student_id desc) a GROUP BY student_id order by update_time desc" ;
  6002. }
  6003. $student_data = $this->sConn->createCommand($sql)->queryAll();
  6004. if($student_data){
  6005. $count = count($student_data);//需要插入的学生总数
  6006. $limit = 3000;
  6007. $page = ceil($count/$limit);
  6008. for ($i=0; $i < $page; $i++) {
  6009. $values = '';
  6010. for ($j=$i*$limit; $j < ($i+1)*$limit; $j++) {
  6011. if($j > $count - 1){
  6012. continue;
  6013. }
  6014. $values .= '('.$reportId.','.$student_data[$j]['class_id'].','.$student_data[$j]['student_id'].'),';
  6015. }
  6016. $values = "insert into holiday_report_student (report_id,class_id,student_id) values".substr($values,0,-1).';';
  6017. $this->sConn->createCommand($values)->execute();
  6018. }
  6019. }
  6020. //更新设置表
  6021. $sql = "update holiday_report_setting set is_all_html=90,school_group_id=0,reset_time={$time},reset_times= reset_times + 1,is_qxk_school={$is_qxk_school} where report_id = '{$reportId}'";
  6022. $this->sConn->createCommand($sql)->execute();
  6023. //重置后清除已存在的下载任务
  6024. $this->conn->createCommand("delete from pack_product_task where school_id ={$this->schoolId} and unique_key= {$reportId} and product_type=8 and class_id={$classId} ")->execute();
  6025. $trans->commit();
  6026. $status = true;
  6027. }
  6028. catch(Exception $e){
  6029. $trans->rollBack();
  6030. }
  6031. return $status;
  6032. }
  6033. /**
  6034. * 批量重置
  6035. */
  6036. public function batchResetReport($semesterId,$is_qxk_school=0){
  6037. $time = time();
  6038. $status = false;
  6039. $report_ids = array();
  6040. $is_qxk_school = $is_qxk_school?1:0;
  6041. $sql = "select report_id from holiday_report_setting where semester_id='$semesterId'";
  6042. $report_data = $this->sConn->createCommand($sql)->queryAll();
  6043. if($report_data){
  6044. foreach($report_data as $k=>$v){
  6045. $report_ids[] = $v['report_id'];
  6046. }
  6047. }
  6048. $trans = $this->sConn->beginTransaction();
  6049. try{
  6050. if($report_ids){
  6051. $sql = "update holiday_report_setting set is_all_html=90,reset_time={$time},school_group_id=0,is_qxk_school={$is_qxk_school} where semester_id = '{$semesterId}'";
  6052. $this->sConn->createCommand($sql)->execute();
  6053. $sql = "update holiday_report_student set is_report_html=90 where report_id in (".implode(",",$report_ids).")";
  6054. $this->sConn->createCommand($sql)->execute();
  6055. //重置后清除已存在的下载任务
  6056. $task_sql = "delete from pack_product_task where school_id ={$this->schoolId} and unique_key in (". implode(",", $report_ids).") and product_type=8";
  6057. $this->conn->createCommand($task_sql)->execute();
  6058. }
  6059. $trans->commit();
  6060. $status = true;
  6061. }catch(Exception $e){
  6062. $trans->rollBack();
  6063. }
  6064. return $status;
  6065. }
  6066. /**
  6067. * 假期报告获取班级
  6068. */
  6069. public function getClassesByHolidayReport($condition = array(),$orderBy = array())
  6070. {
  6071. $classes = array();
  6072. $condition = $this->condition($condition);
  6073. $orderBy = $this->orderBy($orderBy);
  6074. $classes = $this->sConn->createCommand("select c.* from class c right join holiday_report_setting hrs on c.class_id=hrs.class_id{$condition} group by class_id{$orderBy}")->queryAll();
  6075. return $classes;
  6076. }
  6077. //查询考试上传学生数量
  6078. public function getStudentCountByExamGroupId($examGroupId,$hasFeedback=0){
  6079. if(!$examGroupId){
  6080. return null;
  6081. }
  6082. $result=array();
  6083. $result['total']=0; //总数
  6084. $result['is_feedback']=0; // 已扫描
  6085. $result['is_del']=0; //缺考
  6086. $result['abnormal']=0; //异常总量
  6087. $result['complete']=0; //完成数量
  6088. $result['surplus']=0; //剩余量
  6089. $sql="select exam_id from exam where exam_group_id='{$examGroupId}'";
  6090. $data=$this->sConn->createCommand($sql)->queryAll();
  6091. $examIds=array();
  6092. if($data){
  6093. if($hasFeedback){
  6094. foreach ($data as $val){
  6095. $examIds[]=$val['exam_id'];
  6096. }
  6097. $studentSql="select student_id,is_feedback,is_del from student_paper_relation where exam_id in(".implode(',',$examIds).")";
  6098. $studentData=$this->sConn->createCommand($studentSql)->queryAll();
  6099. if($studentData){
  6100. foreach ($studentData as $val){
  6101. if($val['is_feedback']==1){
  6102. $result['is_feedback']++;
  6103. }
  6104. if($val['is_del']==1){
  6105. $result['is_del']++;
  6106. }else{
  6107. $result['total']++;
  6108. }
  6109. }
  6110. }
  6111. }
  6112. $abnormalSql="select status from assist_student_scan_task where exam_group_id = '{$examGroupId}'";
  6113. $abnormalData=$this->conn->createCommand($abnormalSql)->queryAll();
  6114. if($abnormalData){
  6115. $result['abnormal']=count($abnormalData);
  6116. foreach ($abnormalData as $val){
  6117. if($val['status']==0){
  6118. $result['surplus']++;
  6119. }
  6120. if($val['status']==1){
  6121. $result['complete']++;
  6122. }
  6123. }
  6124. }
  6125. }
  6126. return $result;
  6127. }
  6128. //查询待处理数据
  6129. public function getSurplusDataByExamGroupId($examGroupId){
  6130. $abnormalSql="select status from assist_student_scan_task where exam_group_id = '{$examGroupId}' and status=0";
  6131. $abnormalData=$this->conn->createCommand($abnormalSql)->queryAll();
  6132. $result=array();
  6133. if($abnormalData){
  6134. foreach ($abnormalData as $val){
  6135. $result[]=array(
  6136. 'task_id'=>$val['task_id'],
  6137. 'student'=>$val['data']
  6138. );
  6139. }
  6140. }
  6141. return $result;
  6142. }
  6143. /**
  6144. * 好题本
  6145. */
  6146. public function getHtb($condition = array(), $orderBy = array("htb.create_time desc"), $pageSize = 10)
  6147. {
  6148. $condition = Arr::merge($condition, array("htb.semester_id = '{$this->semester["id"]}'"));
  6149. $condition = $this->condition($condition);
  6150. $orderBy = $this->orderBy($orderBy);
  6151. $handle = $this->sConn->createCommand("
  6152. select htb.htb_id,htb.name,c.grade,c.class_id,c.class_name,htb.is_new_version,htb.htb_group_id from math_htb_setting htb join class c on htb.class_id= c.class_id
  6153. {$condition}
  6154. group by htb.htb_id
  6155. {$orderBy}
  6156. ")->query();
  6157. $rs = $this->paging($this->sConn, $handle, $pageSize);
  6158. if ($rs['rs']) {
  6159. foreach ($rs['rs'] as $k => $v) {
  6160. $rs['rs'][$k]['totalCount'] = 0;
  6161. $rs['rs'][$k]['pdfCount'] = 0;
  6162. $rs['rs'][$k]['isDown'] = 0;
  6163. $rs['rs'][$k]['downTime'] = '';
  6164. $htb_id = $v['htb_id'];
  6165. $sql = "select COUNT(student_id) AS totalCount,SUM(CASE WHEN is_htb_pdf = 1 THEN 1 ELSE 0 END) AS pdfCount from math_htb_student where htb_id = '{$htb_id}'";
  6166. $countArr = $this->sConn->createCommand($sql)->queryRow();
  6167. if ($countArr) {
  6168. $rs['rs'][$k]['totalCount'] = isset($countArr['totalCount']) ? $countArr['totalCount'] : 0;
  6169. $rs['rs'][$k]['pdfCount'] = isset($countArr['pdfCount']) ? $countArr['pdfCount'] : 0;
  6170. }
  6171. $sql = "select htb_download_time from math_htb_student where htb_id = '{$htb_id}' and is_htb_download = 1 order by htb_download_time desc limit 1";
  6172. $isDownArr = $this->sConn->createCommand($sql)->queryRow();
  6173. if ($isDownArr) {
  6174. $rs['rs'][$k]['isDown'] = 1;
  6175. $rs['rs'][$k]['downTime'] = isset($isDownArr['htb_download_time']) ? date("Y-m-d H:i", $isDownArr['htb_download_time']) : '';
  6176. }
  6177. }
  6178. }
  6179. return $rs;
  6180. }
  6181. /**
  6182. * 全学科获取题型(topic表中题型)
  6183. */
  6184. public function getPaperTopicsRecordsByTopic($paperId)
  6185. {
  6186. $records = array();
  6187. if ($paperId) {
  6188. $sql = "select ptr.*,t.bank_type from paper_topic_relation ptr join topic t on ptr.topic_id = t.topic_id where ptr.paper_id = '{$paperId}' order by ptr.`order` asc";
  6189. $records = $this->sConn->createCommand($sql)->queryAll();
  6190. }
  6191. return $records;
  6192. }
  6193. //读取最新版本软件
  6194. public function getNewVersionBySoftwareId($id){
  6195. $sql="select file_url from client_software_version where software_id = '{$id}' order by id desc";
  6196. $data=$this->conn->createCommand($sql)->queryRow();
  6197. if($data){
  6198. return $data['file_url'];
  6199. }else{
  6200. return '';
  6201. }
  6202. }
  6203. //统计考试班级和人数
  6204. public function countExamsAndStudents($examGroupId){
  6205. if(!$examGroupId) return false;
  6206. $result=array();
  6207. $sql="select exam_id from exam where exam_group_id='".$examGroupId."'";
  6208. $exam=$this->sConn->createCommand($sql)->queryAll();
  6209. if($exam){
  6210. $examIds=array();
  6211. foreach ($exam as $val){
  6212. $examIds[]=$val['exam_id'];
  6213. }
  6214. $result['classes']=count($examIds);
  6215. $student=$this->sConn->createCommand("select count(*) as count from student_paper_relation where exam_id in(".implode(',',$examIds).") and is_del=0")->queryRow();
  6216. if($student){
  6217. $result['students']=$student['count'];
  6218. }
  6219. }
  6220. return $result;
  6221. }
  6222. //根据班级名称读取班级
  6223. public function getClassInfoByClassName($className,$semesterIds){
  6224. if(!$semesterIds || !$className)
  6225. return false;
  6226. $rs = $this->sConn->createCommand("select class_id from class where class_name = '{$className}' and semester_id='".$semesterIds."' and is_hide=0 ")->queryRow();
  6227. if($rs){
  6228. return $rs['class_id'];
  6229. }
  6230. return false;
  6231. }
  6232. //查询指定科目班级执教教师
  6233. public function getTeacherByClassSubject($classId,$subjectId){
  6234. if(!$classId || !$subjectId) return false;
  6235. if(in_array($subjectId,array(3,6,51))) $subjectId=3;
  6236. $rs = $this->sConn->createCommand("SELECT t.teacher_id,class_id FROM `teacher_class_relation` tcr join teacher t on t.teacher_id=tcr.teacher_id where t.subjects='{$subjectId}' and tcr.class_id='{$classId}';")->queryRow();
  6237. return $rs;
  6238. }
  6239. public function getExamName($examId)
  6240. {
  6241. if (!$examId) return null;
  6242. $sql = "select name from exam where exam_id ='{$examId}'";
  6243. $exam = $this->sConn->createCommand($sql)->queryRow();
  6244. if ($exam) {
  6245. return $exam['name'];
  6246. }
  6247. return null;
  6248. }
  6249. //读取未上传考生
  6250. public function getNoUploadStudentByGroupId($examGroupId,$page,$del=-1,$classId=0){
  6251. if(!$examGroupId) return false;
  6252. if(!$page) $page=1;
  6253. $result=array();
  6254. $pageLimit=10;
  6255. if($classId){
  6256. $sql="select exam_id,class_id from exam where exam_group_id='".$examGroupId."' and class_id='{$classId}'";
  6257. }else{
  6258. $sql="select exam_id,class_id from exam where exam_group_id='".$examGroupId."'";
  6259. }
  6260. $exam=$this->sConn->createCommand($sql)->queryAll();
  6261. if($exam) {
  6262. $examIds = array();
  6263. $classIds=array();
  6264. $className=array();
  6265. foreach ($exam as $val) {
  6266. $examIds[] = $val['exam_id'];
  6267. $classIds[]=$val['class_id'];
  6268. }
  6269. $classSql="select class_name,class_id from class where class_id in(".implode(',',$classIds).")";
  6270. $classes=$this->sConn->createCommand($classSql)->queryAll();
  6271. foreach ($classes as $val){
  6272. $className[(string)$val['class_id']]=$val['class_name'];
  6273. }
  6274. $condition=array();
  6275. $condition[]=" is_feedback=0 ";
  6276. $condition[]=" exam_id in(".implode(',',$examIds).") ";
  6277. $offset=($page-1)*$pageLimit;
  6278. if($del==-1) {
  6279. //全部
  6280. }elseif($del==0){
  6281. $condition[]=" is_del=0 ";
  6282. }elseif($del==1){
  6283. $condition[]=" is_del=1 ";
  6284. }
  6285. $countData=$this->sConn->createCommand("select count(*) as count from student_paper_relation where ".implode(' AND ',$condition))->queryRow();
  6286. $result['total']=$countData['count'];
  6287. $result['totalPage']=ceil($result['total']/$pageLimit);
  6288. $result['page']=$page;
  6289. $result['pageLimit']=$pageLimit;
  6290. $sql="select student_id,class_id,student_card,school_student_card,is_del,exam_id from student_paper_relation where ".implode(' AND ',$condition)." order by student_id limit {$offset},{$pageLimit} ";
  6291. $studentData=$this->sConn->createCommand($sql)->queryAll();
  6292. if($studentData){
  6293. foreach ($studentData as $key =>$val){
  6294. if(isset($className[(string)$val['class_id']])){
  6295. $studentData[$key]['class_name']= $className[(string)$val['class_id']];
  6296. }
  6297. $studentInfo=$this->sConn->createCommand("select realname from student_info where student_id ='{$val['student_id']}'")->queryRow();
  6298. if($studentInfo){
  6299. $studentData[$key]['student_name']= $studentInfo['realname'];
  6300. }
  6301. if($val['is_del']==1){
  6302. $studentData[$key]['status']= '缺考';
  6303. }else{
  6304. $studentData[$key]['status']= '未上传';
  6305. }
  6306. }
  6307. }
  6308. $result['list']=$studentData;
  6309. $result['classes']=$className;
  6310. }
  6311. return $result;
  6312. }
  6313. //删除学生
  6314. public function delStudentPaperByStudentAndExamIds($studentsIds,$examId)
  6315. {
  6316. $trans = $this->sConn->beginTransaction();
  6317. try {
  6318. if(is_array($examId)){
  6319. $this->sConn->createCommand("update student_paper_relation set is_del=1 where student_id in(".implode(',',$studentsIds).") and exam_id in(".implode(',',$examId).") and is_feedback=0")->execute();
  6320. $this->sConn->createCommand("DELETE FROM student_answer_card_online where student_id in(".implode(',',$studentsIds).") and exam_id in(".implode(',',$examId).") ")->execute();
  6321. }else{
  6322. $this->sConn->createCommand("update student_paper_relation set is_del=1 where student_id in(".implode(',',$studentsIds).") and exam_id ='{$examId}' and is_feedback=0")->execute();
  6323. $this->sConn->createCommand("DELETE FROM student_answer_card_online where student_id in(".implode(',',$studentsIds).") and exam_id ='{$examId}' ")->execute();
  6324. }
  6325. $trans->commit();
  6326. return true;
  6327. } catch (Exception $e) {
  6328. $trans->rollBack();
  6329. return false;
  6330. }
  6331. }
  6332. //下载学生
  6333. public function getExcelStudent($studentIds,$examGroupId)
  6334. {
  6335. $array=array();
  6336. $sql = "select exam_id,class_id from exam where exam_group_id='" . $examGroupId . "'";
  6337. $exam = $this->sConn->createCommand($sql)->queryAll();
  6338. if ($exam) {
  6339. $examIds = array();
  6340. $classIds = array();
  6341. $className = array();
  6342. foreach ($exam as $val) {
  6343. $examIds[] = $val['exam_id'];
  6344. $classIds[] = $val['class_id'];
  6345. }
  6346. $classSql = "select class_name,class_id from class where class_id in(" . implode(',', $classIds) . ")";
  6347. $classes = $this->sConn->createCommand($classSql)->queryAll();
  6348. foreach ($classes as $val) {
  6349. $className[(string)$val['class_id']] = $val['class_name'];
  6350. }
  6351. $condition = array();
  6352. // $condition[] = " student_id in(" . implode(',', $studentIds) . ") ";
  6353. $condition[] = " exam_id in(" . implode(',', $examIds) . ") ";
  6354. $condition[] = " is_feedback=0 ";
  6355. $sql = "select student_id,class_id,student_card,school_student_card,is_del,exam_id from student_paper_relation where " . implode(' AND ', $condition) . " ";
  6356. $studentData = $this->sConn->createCommand($sql)->queryAll();
  6357. if ($studentData) {
  6358. foreach ($studentData as $key => $val) {
  6359. $studentInfo = $this->sConn->createCommand("select realname from student_info where student_id ='{$val['student_id']}'")->queryRow();
  6360. $status='未上传';
  6361. if ($val['is_del'] == 1) {
  6362. $status = '缺考';
  6363. }
  6364. $array[]=array(
  6365. $studentInfo['realname'],
  6366. $val['student_card'],
  6367. $val['school_student_card'],
  6368. $className[(string)$val['class_id']],
  6369. $status
  6370. );
  6371. }
  6372. }
  6373. $title = array("姓名", "系统准考证号", "学校准考证号", "班级", "状态");
  6374. array_unshift($array, $title);
  6375. }
  6376. return $array;
  6377. }
  6378. public function getCyletStudentByExamIds($examIds,$classIds){
  6379. if(!$examIds || !is_array($examIds)) return null;
  6380. $studentIds=array();
  6381. $sql="select exam_group_id from exam where exam_id in(".implode(',',$examIds).")";
  6382. $data = $this->sConn->createCommand($sql)->queryAll();
  6383. foreach ($data as $datum){
  6384. $examGroupId[]=$datum['exam_group_id'];
  6385. $sql="select exam_id from exam where exam_group_id in(".implode(',',$examGroupId).") and class_id in(".implode(',',$classIds).")";
  6386. $studentExam=$this->sConn->createCommand($sql)->queryAll();
  6387. $studentExamIds=array();
  6388. foreach ($studentExam as $val){
  6389. $studentExamIds[]=$val['exam_id'];
  6390. }
  6391. if($studentExamIds){
  6392. $sql="select student_id from student_paper_relation where exam_id in(".implode(',',$studentExamIds).") and is_del=0";
  6393. $studentRs=$this->sConn->createCommand($sql)->queryAll();
  6394. if($studentRs){
  6395. foreach ($studentRs as $val){
  6396. $studentIds[(string)$val['student_id']]=$val['student_id'];
  6397. }
  6398. }
  6399. }
  6400. }
  6401. return array_values($studentIds);
  6402. }
  6403. //删除学生
  6404. public function delStudentPaperByExamGroupId($examId)
  6405. {
  6406. $trans = $this->sConn->beginTransaction();
  6407. try {
  6408. if(is_array($examId)){
  6409. $this->sConn->createCommand("update student_paper_relation set is_del=1 where exam_id in(".implode(',',$examId).") and is_feedback=0")->execute();
  6410. $this->sConn->createCommand("DELETE FROM student_answer_card_online where exam_id in(".implode(',',$examId).") ")->execute();
  6411. }else{
  6412. $this->sConn->createCommand("update student_paper_relation set is_del=1 where exam_id ='{$examId}' and is_feedback=0")->execute();
  6413. $this->sConn->createCommand("DELETE FROM student_answer_card_online where exam_id ='{$examId}' ")->execute();
  6414. }
  6415. $trans->commit();
  6416. return true;
  6417. } catch (Exception $e) {
  6418. $trans->rollBack();
  6419. return false;
  6420. }
  6421. }
  6422. //读取未上传考生
  6423. public function getStudentPaperByExamGroupId($examId)
  6424. {
  6425. if (is_array($examId)) {
  6426. $rs = $this->sConn->createCommand("select student_id from student_paper_relation where exam_id in(" . implode(',', $examId) . ") and is_feedback=0")->queryAll();
  6427. } else {
  6428. $rs = $this->sConn->createCommand("select student_id from student_paper_relation where exam_id ='{$examId}' and is_feedback=0")->queryAll();
  6429. }
  6430. $result = array();
  6431. if ($rs) {
  6432. foreach ($rs as $val) {
  6433. $result[(string)$val['student_id']] = $val['student_id'];
  6434. }
  6435. }
  6436. return $result;
  6437. }
  6438. //发送标注到教师端
  6439. public function sendLabelToTeacher($examGroupId,$type){
  6440. if(!$examGroupId || !in_array($type,array('send','cancel','resend')) ){
  6441. return false;
  6442. }
  6443. $examData=$this->getExamsIdsByExamGroupId($examGroupId);
  6444. if(!$examData){
  6445. return false;
  6446. }
  6447. $examIds=array();
  6448. foreach ($examData as $val){
  6449. $examIds[]=$val;
  6450. }
  6451. if($type=='send' || $type=='resend'){
  6452. $rs=$this->sConn->createCommand("update paper set is_labelled=2,labelled_type=2,send_labelled_time='".time()."' where exam_id in(".implode(',',$examIds).")")->execute();
  6453. }else{
  6454. $rs=$this->sConn->createCommand("update paper set is_labelled=4,send_labelled_time='".time()."' where exam_id in(".implode(',',$examIds).")")->execute();
  6455. }
  6456. return $rs;
  6457. }
  6458. //更新发送类型
  6459. public function updatePaperLabelledType($examGroupId,$type){
  6460. if(!$examGroupId ){
  6461. return false;
  6462. }
  6463. $examData=$this->getExamsIdsByExamGroupId($examGroupId);
  6464. if(!$examData){
  6465. return false;
  6466. }
  6467. $examIds=array();
  6468. foreach ($examData as $val){
  6469. $examIds[]=$val;
  6470. }
  6471. $rs=$this->sConn->createCommand("update paper set labelled_type='{$type}',send_labelled_time='".time()."',is_labelled=0 where exam_id in(".implode(',',$examIds).")")->execute();
  6472. return $rs;
  6473. }
  6474. /**
  6475. * 教师假期报告列表
  6476. */
  6477. public function getTeacherHolidayReport($condition = array(), $orderBy = array("htrs.create_time desc"), $pageSize = 10){
  6478. $condition = $this->condition($condition);
  6479. $orderBy = $this->orderBy($orderBy);
  6480. $handle = $this->sConn->createCommand("
  6481. select htrs.report_id,htrs.report_group_id,htrs.semester_id,htrs.teacher_id,htrs.create_time,t.teacher_name from holiday_teacher_report_setting htrs join teacher t on t.teacher_id = htrs.teacher_id
  6482. {$condition}
  6483. group by htrs.report_id
  6484. {$orderBy}
  6485. ")->query();
  6486. $rs = $this->paging($this->sConn, $handle, $pageSize);
  6487. if($rs['rs']){
  6488. $rs['is_all_pdf'] = 1;//是否全部生成pdf
  6489. $rs['create_time'] = 0;//创建时间
  6490. $create_time_arr = array();
  6491. $reset_time_arr = array();
  6492. foreach($rs['rs'] as $k=>$v){
  6493. $teacher_id = $v['teacher_id'];
  6494. $report_id = $v['report_id'];
  6495. $semester_id = $v['semester_id'];
  6496. //获取教师登陆账号
  6497. $sql = "select phone_number from xb_teacher where teacher_id = '{$teacher_id}'";
  6498. $teacher_data = $this->conn->createCommand($sql)->queryRow();
  6499. if($teacher_data){
  6500. $rs['rs'][$k]['phone_number'] = $teacher_data['phone_number'];
  6501. }else{
  6502. $rs['rs'][$k]['phone_number'] = "";
  6503. }
  6504. //获取生成数量
  6505. $sql = "select count(1) count,report_pdf_time from holiday_report_teacher where report_id = '{$report_id}' and is_report_pdf = 1";
  6506. $pdf_data = $this->sConn->createCommand($sql)->queryRow();
  6507. if($pdf_data){
  6508. $rs['rs'][$k]['pdf_count'] = $pdf_data['count'];
  6509. $rs['rs'][$k]['build_time'] = $pdf_data['report_pdf_time']?date("Y-m-d",$pdf_data['report_pdf_time']):'';
  6510. }else{
  6511. $rs['rs'][$k]['pdf_count'] = 0;
  6512. $rs['rs'][$k]['build_time'] = '';
  6513. }
  6514. //获取执教班级
  6515. $sql = "select c.class_id,c.class_name from teacher_class_relation tcr join class c on tcr.class_id = c.class_id where tcr.semester_id ='{$semester_id}' and tcr.teacher_id = '{$teacher_id}'";
  6516. $class_data = $this->sConn->createCommand($sql)->queryAll();
  6517. if($class_data){
  6518. $class_name = "";
  6519. foreach($class_data as $v){
  6520. $class_name .= $v['class_name'].'、';
  6521. }
  6522. // $rs['rs'][$k]['class_name'] = mb_substr($class_name, 0, -1);
  6523. $rs['rs'][$k]['class_name'] = rtrim($class_name, "、");
  6524. }else{
  6525. $rs['rs'][$k]['class_name'] = '';
  6526. }
  6527. }
  6528. }
  6529. return $rs;
  6530. }
  6531. /**
  6532. * 批量插入教师假期报告
  6533. * @type 1-没数据全部插入 2-有教师补数据
  6534. */
  6535. public function batchInsetHolidayTeacherReport($schoolId,$semesterId,$type){
  6536. $data = array();
  6537. $data['status'] = 0;
  6538. $data['error'] = '创建失败';
  6539. $teacher_ids = array();
  6540. $new_report_ids = array();
  6541. $insert_values_1 = "";//sql1
  6542. $insert_values_2 = "";//sql2
  6543. $time = time();
  6544. //获取教师执教班级信息
  6545. if($type == 1){
  6546. $sql = "select t.teacher_id,t.teacher_name,tcr.class_id,c.grade from teacher t "
  6547. . "join teacher_class_relation tcr on t.teacher_id = tcr.teacher_id "
  6548. . "join class c on tcr.class_id = c.class_id "
  6549. . "where tcr.semester_id = '{$semesterId}' and t.subjects in (".implode(',',Yii::app()->params['mathSubjectId']).") GROUP BY t.teacher_id,c.grade";
  6550. }else if($type == 2){
  6551. $sql = "select t.teacher_id,t.teacher_name,tcr.class_id,c.grade from teacher t "
  6552. . "join teacher_class_relation tcr on t.teacher_id = tcr.teacher_id "
  6553. . "join class c on tcr.class_id = c.class_id "
  6554. . "where tcr.semester_id = '{$semesterId}' and t.subjects in (".implode(',',Yii::app()->params['mathSubjectId']).") and t.teacher_id not in "
  6555. . "(select teacher_id from holiday_teacher_report_setting where semester_id = '{$semesterId}') "
  6556. . "GROUP BY t.teacher_id,c.grade";
  6557. }
  6558. $teacher_class_data = $this->sConn->createCommand($sql)->queryAll();
  6559. if(!$teacher_class_data){
  6560. $data['error'] = '暂无教师班级信息';
  6561. return $data;
  6562. }else{
  6563. $report_group_id = getUniqueId($schoolId);
  6564. foreach($teacher_class_data as $k=>$v){
  6565. $teacher_ids[] = $v['teacher_id'];
  6566. }
  6567. $teacher_ids = array_unique($teacher_ids);
  6568. $teacher_count = count($teacher_ids);
  6569. $report_ids = getBatchUuid($schoolId,$teacher_count);
  6570. if($report_ids){
  6571. $report_ids_values = array_values($report_ids);
  6572. if(count($teacher_ids) != count($report_ids)){
  6573. $data['error'] = '教师数量不符合';
  6574. return $data;
  6575. }
  6576. $i = 0;
  6577. $teacher_ids = array_values($teacher_ids);
  6578. foreach($teacher_ids as $k=>$v){
  6579. if(isset($report_ids_values[$i]) && $report_ids_values[$i]){
  6580. $new_report_ids[$v] = $report_ids_values[$i];
  6581. $report_id = $new_report_ids[$v];
  6582. $insert_values_1 .= "(".$report_group_id.",".$report_id.",".$v.",".$semesterId.",".$time."),";
  6583. $i++;
  6584. }
  6585. }
  6586. //组装插入sql语句
  6587. foreach($teacher_class_data as $v){
  6588. if(isset($new_report_ids[$v['teacher_id']]) && $new_report_ids[$v['teacher_id']]){
  6589. $report_id = $new_report_ids[$v['teacher_id']];
  6590. $insert_values_2 .= "(".$report_id.",".$v['teacher_id'].",".$v['grade']."),";
  6591. }
  6592. }
  6593. }
  6594. }
  6595. $trans = $this->sConn->beginTransaction();
  6596. try{
  6597. if($insert_values_1){
  6598. $insert_sql = "insert into holiday_teacher_report_setting (report_group_id,report_id,teacher_id,semester_id,create_time) values".substr($insert_values_1,0,-1).';';
  6599. $this->sConn->createCommand($insert_sql)->execute();
  6600. }
  6601. if($insert_values_2){
  6602. $insert_sql = "insert into holiday_report_teacher (report_id,teacher_id,grade) values".substr($insert_values_2,0,-1).';';
  6603. $this->sConn->createCommand($insert_sql)->execute();
  6604. }
  6605. $trans->commit();
  6606. $data['status'] = 1;
  6607. $data['error'] = '创建成功';
  6608. }
  6609. catch(Exception $e){
  6610. $trans->rollBack();
  6611. $data['status'] = 0;
  6612. $data['error'] = '创建失败';
  6613. }
  6614. return $data;
  6615. }
  6616. /**
  6617. * 重置教师假期报告(单个)
  6618. */
  6619. public function resetTeacherReport($reportId,$teacherId,$semesterId){
  6620. $time = time();
  6621. $status = false;
  6622. $insert_values = '';
  6623. $trans = $this->sConn->beginTransaction();
  6624. try{
  6625. //删除学生数据
  6626. $sql = "delete from holiday_report_teacher where report_id = '{$reportId}'";
  6627. $this->sConn->createCommand($sql)->execute();
  6628. //执教班级数据
  6629. $sql = "select t.teacher_id,t.teacher_name,tcr.class_id,c.grade from teacher t "
  6630. . "join teacher_class_relation tcr on t.teacher_id = tcr.teacher_id "
  6631. . "join class c on tcr.class_id = c.class_id "
  6632. . "where t.teacher_id = '{$teacherId}' and tcr.semester_id = '{$semesterId}' and t.subjects in (".implode(',',Yii::app()->params['mathSubjectId']).") GROUP BY t.teacher_id,c.grade";
  6633. $teacher_class_data = $this->sConn->createCommand($sql)->queryAll();
  6634. if($teacher_class_data){
  6635. foreach($teacher_class_data as $k=>$v){
  6636. $insert_values .= "(".$reportId.",".$v['teacher_id'].",".$v['grade']."),";
  6637. }
  6638. if($insert_values){
  6639. $insert_sql = "insert into holiday_report_teacher (report_id,teacher_id,grade) values".substr($insert_values,0,-1).';';
  6640. $this->sConn->createCommand($insert_sql)->execute();
  6641. }
  6642. }
  6643. //更新设置表
  6644. $sql = "update holiday_teacher_report_setting set is_all_html=90,school_group_id=0,reset_time={$time},reset_times= reset_times + 1 where report_id = '{$reportId}'";
  6645. $this->sConn->createCommand($sql)->execute();
  6646. //重置后清除已存在的下载任务
  6647. // $this->conn->createCommand("delete from pack_product_task where school_id ={$this->schoolId} and unique_key= {$reportId} and product_type=8 and class_id={$classId} ")->execute();
  6648. $trans->commit();
  6649. $status = true;
  6650. }
  6651. catch(Exception $e){
  6652. $trans->rollBack();
  6653. }
  6654. return $status;
  6655. }
  6656. /**
  6657. * 批量重置教师假期报告
  6658. */
  6659. public function batchResetTeacherReport($semesterId)
  6660. {
  6661. $time = time();
  6662. $status = false;
  6663. $report_ids = array();
  6664. $sql = "select report_id from holiday_teacher_report_setting where semester_id='$semesterId'";
  6665. $report_data = $this->sConn->createCommand($sql)->queryAll();
  6666. if ($report_data) {
  6667. foreach ($report_data as $k => $v) {
  6668. $report_ids[] = $v['report_id'];
  6669. }
  6670. }
  6671. $trans = $this->sConn->beginTransaction();
  6672. try {
  6673. if ($report_ids) {
  6674. $sql = "update holiday_teacher_report_setting set is_all_html=90,reset_time={$time},school_group_id=0 where semester_id = '{$semesterId}'";
  6675. $this->sConn->createCommand($sql)->execute();
  6676. $sql = "update holiday_report_teacher set is_report_html=90,is_report_pdf=0 where report_id in (" . implode(",", $report_ids) . ")";
  6677. $this->sConn->createCommand($sql)->execute();
  6678. //重置后清除已存在的下载任务
  6679. // $task_sql = "delete from pack_product_task where school_id ={$this->schoolId} and unique_key in (". implode(",", $report_ids).") and product_type=8";
  6680. // $this->conn->createCommand()->execute($task_sql);
  6681. }
  6682. $trans->commit();
  6683. $status = true;
  6684. } catch (Exception $e) {
  6685. $trans->rollBack();
  6686. }
  6687. return $status;
  6688. }
  6689. //读取全部考生
  6690. public function getAllStudentPaperByExamIds($examIds,$studentIds=array())
  6691. {
  6692. if($studentIds){
  6693. $rs = $this->sConn->createCommand("select spr.class_id,si.student_id,si.realname,student_card,school_student_card,is_feedback,exam_id,paper_id,student_img_paper from student_paper_relation spr left join student_info si on spr.student_id=si.student_id where exam_id in(" . implode(',', $examIds) . ") and spr.student_id in(".implode(',',$studentIds).") and is_del=0")->queryAll();
  6694. }else{
  6695. $rs = $this->sConn->createCommand("select spr.class_id,si.student_id,si.realname,student_card,school_student_card,is_feedback,exam_id,paper_id,student_img_paper from student_paper_relation spr left join student_info si on spr.student_id=si.student_id where exam_id in(" . implode(',', $examIds) . ") and is_del=0")->queryAll();
  6696. }
  6697. return $rs;
  6698. }
  6699. //读取走班,根据学生id
  6700. public function getAllClassByStudentId($studentIds){
  6701. $sql="select c.class_id,c.class_name,student_id from student_class_relation scr
  6702. join class c on c.class_id=scr.class_id
  6703. where status=0 and c.class_type=2 and student_id in(".implode(',',$studentIds).")";
  6704. $rs = $this->sConn->createCommand($sql)->queryAll();
  6705. $result=array();
  6706. if($rs){
  6707. foreach ($rs as $v){
  6708. $subject=$this->sConn->createCommand("select subject_id from class_subject_relation where class_id='{$v['class_id']}'")->queryAll();
  6709. $subjectList=array();
  6710. if($subject){
  6711. foreach ($subject as $item){
  6712. $subjectList[]=Yii::app()->params['subjectId'][$item['subject_id']];
  6713. }
  6714. }
  6715. $result[$v['student_id']][]=array(
  6716. 'class_name'=>$v['class_name'],
  6717. 'subject'=>$subjectList
  6718. );
  6719. }
  6720. }
  6721. return $result;
  6722. }
  6723. //全学科题库获取题型
  6724. public function getAllSubjectTopicType($subject){
  6725. $topics = array();
  6726. $array = array();
  6727. $array['subjectId']=$subject;
  6728. $url= $this->apiUrl.'/all_subject/topic_type';
  6729. $topics = Curl::post($url, $array);
  6730. $topics=json_decode($topics,true);
  6731. if(isset($topics['status']) && $topics['status']==1 ){
  6732. return $topics['data'];
  6733. }
  6734. return null;
  6735. }
  6736. //全学科题库获取题型
  6737. public function getAllSubjectBasicType(){
  6738. $topics = array();
  6739. $array = array();
  6740. $url= $this->apiUrl.'/all_subject/basic_topic_type';
  6741. $topics = Curl::post($url, $array);
  6742. $topics=json_decode($topics,true);
  6743. if(isset($topics['status']) && $topics['status']==1 ){
  6744. return $topics['data'];
  6745. }
  6746. return null;
  6747. }
  6748. //查询上传答案图片学生
  6749. public function getUpAnswerStudent($paperId,$studentIds=array(),$count=true){
  6750. if(!$paperId ){
  6751. return null;
  6752. }
  6753. if($count){
  6754. if($studentIds){
  6755. $sql="select count(DISTINCT student_id) as count from student_paper_topic_rs where paper_id='{$paperId}' and student_id in(".implode(',',$studentIds).") and answer_url<>'' ";
  6756. }else{
  6757. $sql="select count(DISTINCT student_id) as count from student_paper_topic_rs where paper_id='{$paperId}' and answer_url<>'' ";
  6758. }
  6759. $rs=$this->sConn->createCommand($sql)->queryRow();
  6760. return $rs['count'];
  6761. }else{
  6762. if($studentIds){
  6763. $sql="select DISTINCT student_id from student_paper_topic_rs where paper_id='{$paperId}' and student_id in(".implode(',',$studentIds).") and answer_url<>'' ";
  6764. }else{
  6765. $sql="select DISTINCT student_id from student_paper_topic_rs where paper_id='{$paperId}' and answer_url<>'' ";
  6766. }
  6767. $rs=$this->sConn->createCommand($sql)->queryALl();
  6768. return $rs;
  6769. }
  6770. }
  6771. //读取在线答题卡
  6772. public function getAnswerSheet($examGroupId){
  6773. if(!$examGroupId || !is_numeric($examGroupId)){
  6774. return null;
  6775. }
  6776. $sql="select online_card,tas.is_qrcode_online,tas.file_path,tas.multiplex_id,ocm.marking_papers,ocm.paper_size from `third_answer_sheet` tas ";
  6777. $sql.=" left join online_card_multiplex ocm on ocm.multiplex_id=tas.multiplex_id ";
  6778. $sql.=" where tas.exam_group_id='{$examGroupId}' ";
  6779. $rs=$this->sConn->createCommand($sql)->queryRow();
  6780. return $rs;
  6781. }
  6782. //更新标注期望完成时间
  6783. public function updateEstimateTime($examGroupId,$tplData)
  6784. {
  6785. if (!$examGroupId || !is_numeric($examGroupId) || !$tplData) {
  6786. return null;
  6787. }
  6788. $rs = $this->sConn->createCommand("update exam set tpl_data='" . $tplData . "' where exam_group_id='{$examGroupId}'")->execute();
  6789. return $rs;
  6790. }
  6791. //保存考试全流程节点时间
  6792. public function saveExamProcess($examGroupId,$actionType,$actionTime,$examId=0,$classId=0){
  6793. if(!$examGroupId || !is_numeric($examGroupId)) return false;
  6794. $model=new SExamProcess();
  6795. $model->exam_group_id=$examGroupId;
  6796. $model->exam_id=$examId;
  6797. $model->class_id=$classId;
  6798. $model->action_type=$actionType;
  6799. $model->action_time=$actionTime;
  6800. if($model->save()){
  6801. return true;
  6802. }
  6803. return false;
  6804. }
  6805. // 批量保存考试全流程节点时间
  6806. public function saveExamProcessBatch($examGroupId,$batchData){
  6807. if(!$examGroupId || !is_numeric($examGroupId)) return false;
  6808. $sql="insert into exam_process(`exam_group_id`,`exam_id`,`class_id`,`action_type`,`action_time`) values ";
  6809. $valueData=array();
  6810. foreach ($batchData as $val){
  6811. if(!in_array($val['action_type'],array(1,2,3,4,5,6,7,8,9,10,11,12))){
  6812. return false;
  6813. }
  6814. if(!isset($val['exam_id']) || !isset($val['class_id']) || !isset($val['action_type']) || !isset($val['action_time'])){
  6815. return false;
  6816. }
  6817. $valueData[]="('{$examGroupId}','{$val['exam_id']}','{$val['class_id']}','{$val['action_type']}','{$val['action_time']}')";
  6818. }
  6819. if($this->sConn->createCommand($sql.implode(',',$valueData))->execute()){
  6820. return true;
  6821. }
  6822. return false;
  6823. }
  6824. //删除指定班级未上传考生
  6825. public function delStudentPaperByExamId($examIds){
  6826. if(!$examIds || !is_array($examIds)) return false;
  6827. $sql="update student_paper_relation set is_del=1 where exam_id in(".implode(',',$examIds).") and is_feedback=0";
  6828. if($this->sConn->createCommand($sql)->execute()){
  6829. return true;
  6830. }
  6831. return false;
  6832. }
  6833. //查询导出考试数据白名单
  6834. public function getExportExamWhiteList($schoolId){
  6835. if(!$schoolId || !is_numeric($schoolId)) return false;
  6836. $sql="select id from school_download_exam_whitelist where school_id='".$schoolId."'";
  6837. $rs= $this->conn->createCommand($sql)->queryRow();
  6838. if($rs){
  6839. return 1;
  6840. }else{
  6841. return 0;
  6842. }
  6843. }
  6844. //读取在线答题卡
  6845. public function getOnlineCardMultiplex($multiplexId){
  6846. if(!$multiplexId){
  6847. return null;
  6848. }
  6849. $sql="select marking_papers from `online_card_multiplex` ";
  6850. $sql.=" where multiplex_id='{$multiplexId}' ";
  6851. $rs=$this->sConn->createCommand($sql)->queryRow();
  6852. return $rs;
  6853. }
  6854. //获取全学科试卷结构
  6855. public function getQxkPaperTopics($topicIds){
  6856. $rs = http('/qxk/topic/list','POST',$this->schoolId,array('topicList'=>array_values($topicIds)),'cgi');
  6857. $rs=json_decode($rs,true);
  6858. if(isset($rs['errCode']) && $rs['errCode']=='00'){
  6859. return $rs['data'];
  6860. }
  6861. return null;
  6862. }
  6863. //读取学校省份
  6864. public function getProvince($pid){
  6865. if(!$pid) return null;
  6866. $sql="select region_name from region where region_id='{$pid}'";
  6867. $data=$this->conn->createCommand($sql)->queryRow();
  6868. if($data){
  6869. return $data['region_name'];
  6870. }
  6871. return null;
  6872. }
  6873. //读取在线答题卡
  6874. public function getOnlineCardMultiplexByGroupId($groupId){
  6875. if(!$groupId){
  6876. return null;
  6877. }
  6878. $sql="select marking_papers,is_download,exam_group_id from `online_card_multiplex` ";
  6879. $sql.=" where exam_group_id='{$groupId}' ";
  6880. $rs=$this->sConn->createCommand($sql)->queryRow();
  6881. return $rs;
  6882. }
  6883. /**
  6884. * 校本纠错本
  6885. */
  6886. public function getCorrect($condition = array(), $orderBy = array("create_time desc"), $pageSize = 10)
  6887. {
  6888. $condition = Arr::merge($condition, array("gps.semester_id = '{$this->semester["id"]}'"));
  6889. $condition = $this->condition($condition);
  6890. $orderBy = $this->orderBy($orderBy);
  6891. $handle = $this->sConn->createCommand("
  6892. select gps.gp_group_id,`name`,gps.grade,gps.create_time,status,setting,gp.reset_times from general_product_setting gps LEFT JOIN general_product gp on gp.gp_group_id=gps.gp_group_id
  6893. {$condition}
  6894. group by gps.gp_group_id
  6895. {$orderBy}
  6896. ")->query();
  6897. $rs = $this->paging($this->sConn, $handle, $pageSize);
  6898. if ($rs['rs']) {
  6899. foreach ($rs['rs'] as $k => $v) {
  6900. $rs['rs'][$k]['totalClass'] = 0;
  6901. $rs['rs'][$k]['isDown'] = 0;
  6902. $rs['rs'][$k]['isCreate'] = 0;
  6903. $rs['rs'][$k]['isAllCreate'] = 1;
  6904. $rs['rs'][$k]['abnormal']='';
  6905. $rs['rs'][$k]['examGroupIdCount']=0;
  6906. $sql="select gp_id from general_product where gp_group_id='{$v['gp_group_id']}'";
  6907. $classCount=$this->sConn->createCommand($sql)->queryAll();
  6908. $rs['rs'][$k]['totalClass'] = count($classCount);
  6909. $gpIds=array();
  6910. foreach ($classCount as $item){
  6911. $gpIds[]=$item['gp_id'];
  6912. }
  6913. $sql="select student_id from general_product_student where gp_id in(".implode(',',$gpIds).") and is_create_pdf=1 ";
  6914. $isCreate=$this->sConn->createCommand($sql)->queryRow();
  6915. if($isCreate){
  6916. $rs['rs'][$k]['isCreate'] = 1;
  6917. }
  6918. $sql="select student_id from general_product_student where gp_id in(".implode(',',$gpIds).") and is_create_pdf=0";
  6919. $noCreate=$this->sConn->createCommand($sql)->queryRow();
  6920. if($noCreate){
  6921. $rs['rs'][$k]['isAllCreate'] = 0;
  6922. }
  6923. $sql="select distinct gp_id from general_product_student where gp_id in(".implode(',',$gpIds).") and is_download=1";
  6924. $isDownArr = $this->sConn->createCommand($sql)->queryAll();
  6925. $rs['rs'][$k]['isDown'] = count($isDownArr);
  6926. //查询异常
  6927. $setting=json_decode($v['setting'],1);
  6928. if(isset($setting['no_exam_class']) && $setting['no_exam_class']){
  6929. $names=array();
  6930. $classNames=$this->sConn->createCommand("select class_name from class where class_id in(".implode(',',$setting['no_exam_class']).")")->queryAll();
  6931. foreach ($classNames as $cname){
  6932. $names[]=$cname['class_name'];
  6933. }
  6934. $rs['rs'][$k]['abnormal'] = implode(',',$names);
  6935. }
  6936. if(isset($setting['exam_group_ids'])){
  6937. $rs['rs'][$k]['examGroupIdCount']=count($setting['exam_group_ids']);
  6938. }
  6939. }
  6940. }
  6941. return $rs;
  6942. }
  6943. }