123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394 |
- <?php
- /**
- * @author: Rick Guo
- * @brief: 学校管理器
- */
- defined("ROLE_USER") or define("ROLE_USER", 1);
- defined("ROLE_SU") or define("ROLE_SU", 2);
- class SchoolManager extends Model{
- public $coachId;
- public $coach;
- public $coachRole;
- public $role;
- public $parentNotificationHost;
- public $semesterAllowToChangeDays;
- public $semesterAllowToChangeTime;
- public $apiUrl;
- public $topicUrl;
- public $topicField;
- public $topicCacheTime;
- public $chapterCacheTime;
- public $sTopic;
- //试题sections顺序 升序
- public $topicTypesOrder = array(
- "选择题" => 1,
- "填空题" => 2,
- "解答题" => 3,
- );
- public $msgs = array(
- "global" => array(
- "0" => "操作成功",
- "1001" => "缺少参数",
- "1002" => "系统错误",
- ),
- "changeSemester" => array(
- "2001" => "不能切换到已完成的学期",
- "2002" => "",
- "2003"=>"创建班级失败",
- ),
- "delSemester" => array(
- "2001" => "不能删除当前学期",
- "2002" => "学期已关联班级",
- ),
- "delClass" => array(
- "2001" => "该班级已关联学生",
- "2002" => "该班级已创建过考试",
- ),
- "delTeacher" => array(
- "2001" => "该老师已绑定班级",
- "2002" => "该老师已创建过周周练",
- ),
- "purgeTeacher" => array(
- "2001" => "该老师已绑定班级",
- "2002" => "该老师已创建过考试",
- "2003" => "该老师还有未完成的阅卷任务",
- "2004" => "该老师还有未处理的问题卷",
- ),
- "purgeStudent" => array(
- "2001" => "无法操作,该学生已存在考试数据",
- ),
- "removeStudentClassRelation" => array(
- "2001" => "该学生存在周周练数据",
- ),
- "replaceIspTopic" => array(
- "2001" => "新题目和被替换的题目相同,未替换",
- "2002" => "被替换的题目在该提分册不存在",
- "2003" => "新题目已经存在于该提分册,请选择别的题目",
- ),
- );
- public $inciseTables=array(
- 'student_paper_topic_rs',
- 'student_paper_relation',
- 'student_improve_score_plan_topics',
- 'student_wrong_plan_topics',
- 'student_upload_result'
- );
- function __construct($coachId, $role = ROLE_USER,$pad=''){
- parent::__construct();
- if($pad)
- {
- $this->role = $role;
- $this->parentNotificationHost = Yii::app()->params["notification_host"];
- $this->semesterAllowToChangeDays = !empty(Yii::app()->params["semester_allow_to_change_days"]) ? Yii::app()->params["semester_allow_to_change_days"] : 15;
- $this->semesterAllowToChangeTime = $this->semesterAllowToChangeDays * 24 * 3600;
- $this->msgs["changeSemester"]["2002"] = "只有在学期开始前{$this->semesterAllowToChangeDays}天内允许切换";
- $this->apiUrl = Yii::app()->params["api"][0]["prefix"];
- $this->topicUrl = $this->apiUrl.Yii::app()->params["topic_store"]["topic_append"];
- $this->topicField = Yii::app()->params["topic_store"]["topic_field"];
- $this->topicCacheTime = !empty(Yii::app()->params["topic_cache_time"]) ? Yii::app()->params["topic_cache_time"] : 43200;
- $this->topicHost = $this->apiUrl.Yii::app()->params["topic_store"]["topic_host"];
- $this->chapterCacheTime = !empty(Yii::app()->params["chapter_cache_time"]) ? Yii::app()->params["chapter_cache_time"] : 43200;
- $this->sTopic = new STopic();
- }else
- {
- if(!$coachId)
- throw new CException("助教ID不能为空");
- $this->coachId = $coachId;
- $this->role = $role;
- $this->coach = $this->getMyInfo();
- $this->coachRole = $this->coach["leader"];
- $this->parentNotificationHost = Yii::app()->params["notification_host"];
- $this->semesterAllowToChangeDays = !empty(Yii::app()->params["semester_allow_to_change_days"]) ? Yii::app()->params["semester_allow_to_change_days"] : 15;
- $this->semesterAllowToChangeTime = $this->semesterAllowToChangeDays * 24 * 3600;
- $this->msgs["changeSemester"]["2002"] = "只有在学期开始前{$this->semesterAllowToChangeDays}天内允许切换";
- $this->apiUrl = Yii::app()->params["api"][0]["prefix"];
- $this->topicUrl = $this->apiUrl.Yii::app()->params["topic_store"]["topic_append"];
- $this->topicField = Yii::app()->params["topic_store"]["topic_field"];
- $this->topicCacheTime = !empty(Yii::app()->params["topic_cache_time"]) ? Yii::app()->params["topic_cache_time"] : 43200;
- $this->topicHost = $this->apiUrl.Yii::app()->params["topic_store"]["topic_host"];
- $this->chapterCacheTime = !empty(Yii::app()->params["chapter_cache_time"]) ? Yii::app()->params["chapter_cache_time"] : 43200;
- $this->sTopic = new STopic();
- }
- }
- protected function rs($code, $action = __FUNCTION__){
- $rs = array();
- if($code !== null){
- if(is_array($code))
- $codeStr = implode(", ", $code);
- else
- $codeStr = $code;
- $rs = array(
- "code" => $codeStr,
- "msg" => $this->translateCode($code, $action),
- );
- }
- return $rs;
- }
- protected function translateCode($code, $action = __FUNCTION__, $symbol = "<br/>"){
- $msg = array();
- if($code !== null && isset($this->msgs[$action])){
- if(!is_array($code))
- $code = array($code);
- $i = 1;
- foreach($code as $val){
- if(isset($this->msgs[$action][(string)$val])){
- if($val != 0)
- $msg[] = "<span style='color:red'>{$this->msgs[$action][(string)$val]}</span>";
- else
- $msg[] = "<span style='color:green'>{$this->msgs[$action][(string)$val]}</span>";
- $i++;
- }
- }
- }
- if($msg){
- $msg = implode($symbol, $msg);
- }
- else
- $msg = "";
- return $msg;
- }
- public function getTeachers($orderBy = array("teacher_id asc", "teacher_name asc")){
- $teachers = array();
- $orderBy = $this->orderBy($orderBy);
- $rs = $this->sConn->createCommand("select * from teacher where status != 2 group by teacher_id{$orderBy}")->queryAll();
- if($rs)
- $teachers = $rs;
- return $teachers;
- }
- public function getTeacherAccount($teacherId){
- $account = array();
- if($teacherId){
- $account = $this->conn->createCommand("select * from xb_teacher where teacher_id = '{$teacherId}'")->queryRow();
- }
- return $account;
- }
- public function getTeachersAccounts($teachersIds){
- if(!is_array($teachersIds) || !$teachersIds)
- return array();
- $teachersIds = "'".implode("','", $teachersIds)."'";
- return $this->conn->createCommand("select * from xb_teacher where teacher_id in({$teachersIds})")->queryAll();
- }
- public function countTeachersAccountsPages($pageSize){
- if(!$pageSize)
- return 0;
- $rs = $this->conn->createCommand("select count(*) from xb_teacher")->queryRow();
- $rs = current($rs);
- return ceil($rs / $pageSize);
- }
- public function getTeachersByClassesIds($classesIds){
- $teachers = array();
- if($classesIds){
- $classesIds = "'".implode("','", $classesIds)."'";
- return $this->sConn->createCommand("
- select t.*, tcr.class_id,tcr.is_bzr,t.subjects,tcr.hxb_ing
- from teacher_class_relation as tcr
- join teacher as t on t.teacher_id = tcr.teacher_id
- where tcr.class_id in($classesIds)
- ")->queryAll();
- }
- return $teachers;
- }
- public function getTeachersByClassesIdsAndteacherName($classesIds,$teacher_name){
- $teachers = array();
- if($classesIds){
- $classesIds = "'".implode("','", $classesIds)."'";
- return $this->sConn->createCommand("
- select t.*, tcr.class_id
- from teacher_class_relation as tcr
- join teacher as t on t.teacher_id = tcr.teacher_id
- where tcr.class_id in($classesIds) and t.teacher_name LIKE '%{$teacher_name}%'
- ")->queryAll();
- }
- return $teachers;
- }
- public function getTeachersIdsByClassesIds($classesIds){
- $classes = $this->getTeachersByClassesIds($classesIds);
- return $this->grouping($classes, "teacher_id");
- }
- public function getMyInfo(){
- return $this->conn->createCommand("select * from coach where coach_id = '{$this->coachId}'")->queryRow();
- }
- public function getNowClassesByTeacherId($teacherId,$class_id = 0){
- $classes = array();
- if($teacherId){
- if($class_id >0){
- $classes = $this->sConn->createCommand("
- select c.*
- from teacher_class_relation as tcr
- join class as c on c.class_id = tcr.class_id and c.semester_id = '{$this->semester["id"]}'
- where tcr.teacher_id = '{$teacherId}' and c.class_id = '{$class_id}'
- ")->queryAll();
- }else{
- $classes = $this->sConn->createCommand("
- select c.*
- from teacher_class_relation as tcr
- join class as c on c.class_id = tcr.class_id and c.semester_id = '{$this->semester["id"]}'
- where tcr.teacher_id = '{$teacherId}' and c.is_hide=0
- ")->queryAll();
- }
- }
- return $classes;
- }
- public function getClassesByTeacherId($teacherId){
- $classes = array();
- if($teacherId){
- $classes = $this->sConn->createCommand("
- select c.*
- from teacher_class_relation as tcr
- join class as c on c.class_id = tcr.class_id
- where tcr.teacher_id = '{$teacherId}'
- ")->queryAll();
- }
- return $classes;
- }
- /**
- * 获取 上传试卷列表
- *
- * @author CeeFee
- */
- public function getUploadPaperList($orderBy = array("add_time DESC", "id DESC"),$subject_id=3, $pageSize = 10)
- {
- $str = '';
- $orderBy = $this->orderBy($orderBy);
- if($subject_id==3)
- {
- $str = ' subject_id in ('.implode(',',Yii::app()->params['mathSubjectId']).')';
- }else
- {
- $str = ' subject_id = '.$subject_id;
- }
- $handle = $this->sConn->createCommand("
- SELECT * FROM upload_paper WHERE {$str}
- {$orderBy}
- ")->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- return $rs;
- }
- public function getTeachersList($orderBy = array("teacher_name asc", "teacher_id asc"), $pageSize = 10){
- /*$orderBy = $this->orderBy($orderBy);
- $classesIds = $this->getClassesIdsByCoachId($this->coachId);
- $teachersIds = $this->getTeachersIdsByClassesIds($classesIds);
- $teachersIds = "'".implode("','", $teachersIds)."'";
- $handle = $this->sConn->createCommand("
- select * from teacher where coach_id = '{$this->coachId}' and status != 2
- union
- select * from teacher where teacher_id in({$teachersIds})
- {$orderBy}
- ")->query();*/
- /**
- * 刘红伟修改
- * 时间:2016-11-7
- */
- $orderBy = $this->orderBy($orderBy);
- /*$classesIds = $this->getClassesIdsByCoachId($this->coachId);
- $teachersIds = $this->getTeachersIdsByClassesIds($classesIds);
- $teachersIds = "'".implode("','", $teachersIds)."'";*/
- $handle = $this->sConn->createCommand("
- select * from teacher where status != 2 {$orderBy}
- ")->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- $teachersIds = $this->grouping($rs["rs"], "teacher_id");
- $teachersAccounts = $this->getTeachersAccounts($teachersIds);
- foreach($rs["rs"] as $key => $val){
- $rs["rs"][$key]["businessphone"] = null;
- $rs["rs"][$key]["class_name"] = null;
- foreach($teachersAccounts as $account){
- if($val["teacher_id"] == $account["teacher_id"]){
- $rs["rs"][$key]["businessphone"] = $account["phone_number"];
- $classes = $this->getNowClassesByTeacherId($val["teacher_id"]);
- $classes = $this->grouping($classes, "class_name");
- $classes = implode(",", $classes);
- $rs["rs"][$key]["class_name"] = $classes;
- }
- }
- }
- return $rs;
- }
- public function getTeachersListre($teacher_name='',$subject_id = 0,$class_id = 0,$orderBy = array("teacher_name asc", "teacher_id asc"), $pageSize = 10){
- /*$orderBy = $this->orderBy($orderBy);
- $classesIds = $this->getClassesIdsByCoachId($this->coachId);
- $teachersIds = $this->getTeachersIdsByClassesIds($classesIds);
- $teachersIds = "'".implode("','", $teachersIds)."'";
- $handle = $this->sConn->createCommand("
- select * from teacher where coach_id = '{$this->coachId}' and status != 2
- union
- select * from teacher where teacher_id in({$teachersIds})
- {$orderBy}
- ")->query();*/
- /**
- * 刘红伟修改
- * 时间:2016-11-7
- */
- $orderBy = $this->orderBy($orderBy);
- /*$classesIds = $this->getClassesIdsByCoachId($this->coachId);
- $teachersIds = $this->getTeachersIdsByClassesIds($classesIds);
- $teachersIds = "'".implode("','", $teachersIds)."'";*/
- $condition=array();
- if($teacher_name){
- if(is_array($teacher_name)){
- $condition[]="t.teacher_id in(".implode(',',$teacher_name).")";
- }else{
- $condition[]="t.teacher_name LIKE '%{$teacher_name}%'";
- }
- }
- if($subject_id){
- if(in_array($subject_id,Yii::app()->params['mathSubjectId'])){
- $condition[]="t.subjects in(".implode(',',Yii::app()->params['mathSubjectId']).")";
- }else{
- $condition[]="t.subjects ='{$subject_id}'";
- }
- }
- if($class_id){
- $condition[]="tr.class_id = ".$class_id." and tr. semester_id = '".$this->semester["id"]."'";
- $handle = $this->sConn->createCommand("
- 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
- ")->query();
- }else{
- if($condition){
- $handle = $this->sConn->createCommand("select * from teacher t where ".implode(' and ',$condition)." {$orderBy}")->query();
- }else{
- $handle = $this->sConn->createCommand("select * from teacher {$orderBy}")->query();
- }
- }
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- $teachersIds = $this->grouping($rs["rs"], "teacher_id");
- $teachersAccounts = $this->getTeachersAccounts($teachersIds);
- $teachers = array();
- if($teachersAccounts)
- {
- foreach($teachersAccounts as $v)
- {
- $teachers[$v['teacher_id']] = $v;
- }
- }
- foreach($rs["rs"] as $key => $val){
- $rs["rs"][$key]["businessphone"] = null;
- $rs["rs"][$key]["class_name"] = null;
- if(isset($teachers[$val["teacher_id"]]) && !empty($teachers[$val["teacher_id"]])){
- $rs["rs"][$key]["businessphone"] = $teachers[$val["teacher_id"]]["phone_number"];
- }
- $classes = $this->getNowClassesByTeacherId($val["teacher_id"],$class_id);
- if(!$classes&&$class_id){
- unset($rs["rs"][$key]);
- continue;
- }
- $classes = $this->grouping($classes, "class_name");
- $classes = implode(",", $classes);
- $rs["rs"][$key]["class_name"] = $classes;
- }
- return $rs;
- }
- public function getClasses($grade = "ALL", $orderBy = array("class_id asc", "class_name asc"), $offset = 0, $limit = -1){
- $classes = array();
- $condition = array();
- if(in_array($grade, array("1", "2", "3")))
- $condition = array("grade = '{$grade}'");
- else if($grade !== "ALL")
- return $classes;
- $condition = Arr::merge($condition, array("semester_id = '{$this->semester["id"]}'"));
- $condition = $this->condition($condition);
- $orderBy = $this->orderBy($orderBy);
- $limit = $this->limit($offset, $limit);
- $classes = $this->sConn->createCommand("select * from class{$condition} group by class_id{$orderBy}{$limit}")->queryAll();
- return $classes;
- }
- public function getClassesWithoutTheClass($classId, $orderBy = array("class_id asc", "class_name asc"), $offset = 0, $limit = -1){
- $classes = array();
- if($classId){
- $condition = array("semester_id = '{$this->semester["id"]}'", "class_id != '{$classId}'");
- $condition = $this->condition($condition);
- $orderBy = $this->orderBy($orderBy);
- $limit = $this->limit($offset, $limit);
- $classes = $this->sConn->createCommand("select * from class{$condition} group by class_id{$orderBy}{$limit}")->queryAll();
- $classes = Arr::toObj($classes);
- }
- return $classes;
- }
- public function getClassesList($condition = array(), $pageSize = 9){
- $condition = $this->condition($condition);
- $handle = $this->sConn->createCommand("
- select c.*
- from class as c
- {$condition}
- order by c.class_id desc
- ")->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- return $rs;
- }
- public function getMyClassesList($condition = array(), $pageSize = 9){
- $condition = Arr::merge(array("ccr.coach_id = '{$this->coachId}'"), $condition);
- return $this->getClassesList($condition, $pageSize);
- }
- public function getClassesDetailListre($condition = array(), $pageSize = 9){
- $condition = $this->condition($condition);
- /*$handle = $this->sConn->createCommand("
- select c.*, seme.semester_name as name, seme.school_year
- from class as c
- join semester as seme on seme.semester_id = c.semester_id
- JOIN teacher_class_relation as tc on c.class_id = tc.class_id and seme.semester_id = tc.semester_id
- JOIN teacher as t on tc.teacher_id = t.teacher_id
- {$condition}
- order by c.class_id desc
- ")->query();*/
- $handle = $this->sConn->createCommand("
- select c.*, seme.semester_name as name, seme.school_year,c.teacher_id
- from class as c
- join semester as seme on seme.semester_id = c.semester_id
- {$condition}
- order by c.sort!=0 desc,c.sort,c.class_id desc
- ")->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- if($rs["rs"]){
- $coachesIds = $this->grouping($rs["rs"], "coach_id");
- $coachesIds = array_unique($coachesIds);
- $coaches = $this->getCoachesByIds($coachesIds);
- $classesIds = $this->grouping($rs["rs"], "class_id");
- $classesIds = array_unique($classesIds);
- $teachers = $this->getTeachersByClassesIds($classesIds);
- foreach($rs["rs"] as $key => $val){
- $rs["rs"][$key]["coach_name"] = "";
- foreach($coaches as $coach){
- if($val["coach_id"] == $coach["coach_id"]){
- $rs["rs"][$key]["coach_name"] = $coach["coach_name"];
- }
- }
- }
- foreach($rs["rs"] as $key => $val){
- $rs["rs"][$key]["teachers"] = "";
- $rs["rs"][$key]["teachers_count"]=0;
- $rs["rs"][$key]["teachers_bzr"]='';
- foreach($teachers as $teacher){
- if(strcmp($val["class_id"],$teacher["class_id"])==0){
- $rs["rs"][$key]["teachers"] .= $teacher["teacher_name"];
- $rs["rs"][$key]["teachers_count"] ++;
- }
- }
- //读取班主任
- if($val['teacher_id']){
- $rs['rs'][$key]['teachers_bzr']=Teacher::model()->getTeacherName($val['teacher_id']);
- }
- }
- }
- return $rs;
- }
- public function getClassesDetailList($condition = array(), $pageSize = 9,$teacher_name=''){
- $condition = $this->condition($condition);
- $handle = $this->sConn->createCommand("
- select c.*, seme.semester_name as name, seme.school_year,c.teacher_id
- from class as c
- join semester as seme on seme.semester_id = c.semester_id
- {$condition}
- order by c.sort!=0 desc,c.sort,c.class_id desc
- ")->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- if($rs["rs"]){
- $coachesIds = $this->grouping($rs["rs"], "coach_id");
- $coachesIds = array_unique($coachesIds);
- $coaches = $this->getCoachesByIds($coachesIds);
- $classesIds = $this->grouping($rs["rs"], "class_id");
- $classesIds = array_unique($classesIds);
- if($teacher_name){
- $teachers = $this->getTeachersByClassesIdsAndteacherName($classesIds,$teacher_name);
- }else{
- $teachers = $this->getTeachersByClassesIds($classesIds);
- }
- foreach($rs["rs"] as $key => $val){
- $rs["rs"][$key]["coach_name"] = "";
- foreach($coaches as $coach){
- if($val["coach_id"] == $coach["coach_id"]){
- $rs["rs"][$key]["coach_name"] = $coach["coach_name"];
- }
- }
- $rs["rs"][$key]["teachers"] = "";
- foreach($teachers as $teacher){
- if($val["class_id"] == $teacher["class_id"]){
- $rs["rs"][$key]["teachers"] .= $teacher["teacher_name"];
- }
- }
- //读取班主任
- if($val['teacher_id']){
- $rs['rs'][$key]['teachers_bzr']=Teacher::model()->getTeacherName($val['teacher_id']);
- }
- }
- }
- return $rs;
- }
- public function getMyclassesDetailList($condition = array(), $pageSize = 9){
- $condition = Arr::merge(array("c.coach_id = '{$this->coachId}'"), $condition);
- return $this->getClassesDetailList($condition, $pageSize);
- }
- public function getCoachesByIds($coachesIds){
- $coaches = array();
- if($coachesIds && is_array($coachesIds)){
- $coachesIds = implode("','", $coachesIds);
- $coachesIds = "'{$coachesIds}'";
- $coaches = $this->conn->createCommand("select * from coach where coach_id in($coachesIds)")->queryAll();
- }
- return $coaches;
- }
- public function changeClassTeachersRelation($classId, $teachersIds,$semesterId=0){
- if($classId && $teachersIds){
- if(!is_array($teachersIds))
- $teachersIds = array($teachersIds);
- $values = "";
- foreach($teachersIds as $key => $teacherId){
- if(trim((string)$teacherId) == null){
- unset($teachersIds[$key]);
- continue;
- }
- $values .= ",('{$classId}', '{$teacherId}', '{$semesterId}')";
- }
- if($values){
- $values = "values".substr($values, 1);
- try{
- $trans = $this->sConn->beginTransaction();
- $this->sConn->createCommand("delete from teacher_class_relation where class_id = '{$classId}'")->execute();
- $this->sConn->createCommand("insert into teacher_class_relation(`class_id`, `teacher_id`, `semester_id`) {$values}")->execute();
- $trans->commit();
- $rs = true;
- }
- catch(Exception $e){
- $trans->rollBack();
- $rs = false;
- }
- return $rs;
- }
- }
- return false;
- }
- public function _changeClassTeachersRelation($classId, $teachersIds,$class_data = array()){
- if($classId && $teachersIds){
- if(!is_array($teachersIds))
- $teachersIds = array($teachersIds);
- $values = "";
- foreach($teachersIds as $key => $teacherId){
- if(trim((string)$teacherId) == null){
- unset($teachersIds[$key]);
- continue;
- }
- $values .= ",('{$classId}', '{$teacherId}', '{$class_data['semester_id']}')";
- }
- if(!isset($class_data['class_type'])){
- $class_data['class_type']=1;
- }
- if($values){
- $values = "values".substr($values, 1);
- try{
- $trans = $this->sConn->beginTransaction();
- if(isset($class_data['teacher_id'])){
- $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();
- }else{
- $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();
- }
- $this->sConn->createCommand("delete from teacher_class_relation where class_id = '{$classId}'")->execute();
- $this->sConn->createCommand("insert into teacher_class_relation(`class_id`, `teacher_id`, `semester_id`) {$values}")->execute();
- $trans->commit();
- $rs = true;
- }
- catch(Exception $e){
- $trans->rollBack();
- $rs = false;
- }
- return $rs;
- }
- }
- return false;
- }
- /**
- * @param $semesterId
- *
- * @return bool
- * 刘红伟
- * 开发时间 2016-09-29
- *
- */
- public function insertStudentInfoAndStudentClass($userNames,$studnetIds,$realname_array,$userno,$_IDX_array,$sex_array,$school_id,$class_id,$is_insert = 1)
- {
- $trans = $this->sConn->beginTransaction();
- $student_id_array = array();
- $sql1 = '';
- try {
- if($is_insert)
- {
- $sql1='';
- $sql='INSERT INTO `student_info`
- (`student_id`,`realname`,`sex`,`school_id`,`class_id`,`add_time`)VALUES';
- foreach($userNames as $username)
- {
- if(isset($studnetIds[$username]) && !empty($studnetIds[$username]))
- {
- $student_id_array[] = $studnetIds[$username];
- $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().'),';
- }
- }
- $sql .= substr($sql1,0,-1).';';
- $this->sConn->createCommand($sql)->execute();
- }else
- {
- foreach($userNames as $username)
- {
- if(isset($studnetIds[$username]) && !empty($studnetIds[$username]))
- { $student_id_array[] = $studnetIds[$username];
- $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].';';
- $this->sConn->createCommand($sql)->execute();
- }
- }
- }
- $sql1 = '';
- $sql = '';
- $this->sConn->createCommand("delete from student_class_relation where class_id =".$class_id." and student_id in (".implode(',',$student_id_array).")")->execute();
- $sql = 'INSERT INTO `student_class_relation`
- (`class_id`,`student_id`,`status`,`serial_number`,`userno`,`update_time`)VALUES';
- foreach($userNames as $username)
- {
- if(isset($studnetIds[$username]) && !empty($studnetIds[$username]))
- {
- $sql1 .= '(' . $class_id . ',' . $studnetIds[$username] . ',0,' . $_IDX_array[$username] . ',"' . $userno[$username] . '",' . time() . '),';
- }
- }
- $sql .= substr($sql1,0,-1).';';
- $this->sConn->createCommand($sql)->execute();
- $trans->commit();
- } catch (Exception $e) {
- $trans->rollBack();
- return false;
- }
- return true;
- }
- public function getClassByClassIds($classIds)
- {
- if(!$classIds)
- {
- return false;
- }
- $rs = $this->sConn->createCommand("
- select *
- from class
- where class_id in(".implode(',',$classIds).") ")->queryAll();
- if($rs)
- {
- return $rs;
- }
- return false;
- }
- public function updateStudentClassByClassIdAndStudentID($class_id,$student_ids)
- {
- $trans = $this->sConn->beginTransaction();
- try {
- $sql='update `student_class_relation` set status = 1 where class_id= '.$class_id;
- $this->sConn->createCommand($sql)->execute();
- $sql='update `student_info` set class_id = 0 where class_id= '.$class_id;
- $this->sConn->createCommand($sql)->execute();
- $sql='update `student_class_relation` set status = 1 where student_id in ('.implode(',',$student_ids).')';
- $this->sConn->createCommand($sql)->execute();
- $trans->commit();
- } catch (Exception $e) {
- $trans->rollBack();
- return false;
- }
- return true;
- }
- public function getStudentByStudentIds($studentIds){
- if($studentIds && is_array($studentIds))
- {
- $rs = $this->sConn->createCommand("select * from student_info where student_id in(".implode(',',$studentIds).")")->queryAll();
- if($rs)
- {
- return $rs;
- }
- }
- return false;
- }
- /**
- * @param $studentsIds
- * @param $paper_id
- * @param $exam_id
- *
- */
- public function getStudentByStudentIdsAndParperIdAndExamId($studentsIds,$paper_id,$exam_id)
- {
- $data = array();
- $criteria = new CDbCriteria();
- $criteria->addCondition('paper_id=:paper_id');
- $criteria->addCondition('exam_id=:exam_id');
- $criteria->addInCondition('student_id',$studentsIds);
- $criteria->addCondition('is_feedback=:is_feedback');
- $criteria->addCondition('is_del=:is_del');
- $criteria->params[':paper_id'] = $paper_id;
- $criteria->params[':exam_id'] = $exam_id;
- $criteria->params[':is_feedback'] = 1;
- $criteria->params[':is_del'] = 0;
- $rs = SStudentPaperRelation::model()->findAll($criteria);
- if($rs){
- foreach($rs as $v)
- {
- $data[] = $v->attributes;
- }
- return $rs;
- }
- return false;
- }
- public function delStudentPaperByStudentAndPaperAndExamId($studentsIds,$paper_id)
- {
- $rs=false;
- $trans = $this->sConn->beginTransaction();
- try {
- $this->sConn->createCommand("update student_paper_relation set is_del=1 where student_id in(".implode(',',$studentsIds).") and paper_id='".$paper_id."' ")->execute();
- $this->sConn->createCommand("DELETE FROM student_answer_card_online where student_id in(".implode(',',$studentsIds).") and paper_id='".$paper_id."'")->execute();
- // $this->sConn->createCommand("DELETE FROM student_paper_relation_property where student_id in(".implode(',',$studentsIds).") and paper_id=".$paper_id." ")->execute();
- $trans->commit();
- return true;
- } catch (Exception $e) {
- $trans->rollBack();
- return false;
- }
- return false;
- }
- /**
- * 获取班级学生
- * @param $class_id
- *
- * @return array|bool|\CDbDataReader
- */
- public function getClassStudentByClassId($class_id)
- {
- $rs = $this->sConn->createCommand("select * from student_class_relation where class_id=".$class_id." and status=0")->queryAll();
- if($rs){
- return $rs;
- }
- return false;
- }
- public function getClassPaperByClassAndPaper($class_id,$paper_id,$status=0)
- {
- $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();
- if($rs){
- return $rs;
- }
- return false;
- }
- public function getClassStudentInfoByClassId($class_id){
- $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";
- //$rs = $this->sConn->createCommand("select student_id,realname,class_id from student_info where class_id=".$class_id)->queryAll();
- $rs = $this->sConn->createCommand($sql)->queryAll();
- if($rs){
- return $rs;
- }
- return false;
- }
- public function getStudentByStudentIdsAndParperId($studentsIds,$paper_id,$is_del=0)
- {
- $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();
- if($rs){
- return $rs;
- }
- return false;
- }
- public function getStudentsByStudentIdsAndExam_ids($exam_ids,$studentsIds)
- {
- if($exam_ids && $studentsIds)
- {
- $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();
- if($rs){
- return $rs;
- }
- }
- return false;
- }
- 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() )
- {
- $trans = $this->sConn->beginTransaction();
- $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';
- $sql1 = '';
- $sqlProperty = 'insert into `student_paper_relation_property` (`student_id`,`paper_id`,`class_id`,`exam_id`,`semester_id`,`create_time`) VALUES';
- $sqlPV = '';
- try {
- if($add_student)
- {
- $criteria = new CDbCriteria();
- $criteria->addCondition('exam_id=:exam_id');
- $criteria->addCondition('paper_id = :paper_id');
- $criteria->addInCondition('student_id',$add_student);
- $criteria->params[':exam_id'] = $exam_id;
- $criteria->params[':paper_id'] = $paper_id;
- SStudentPaperRelation::model()->deleteAll($criteria);
- SStudentPaperRelationProperty::model()->deleteAll($criteria);
- foreach($add_student as $student_id)
- {
- $school_student_card = 0;
- $student_card = 0;
- if(isset($school_student_cards[$student_id]) && !empty($school_student_cards[$student_id]))
- {
- $school_student_card = $school_student_cards[$student_id];
- }
- if(isset($student_cards[$student_id]) && !empty($student_cards[$student_id]))
- {
- $student_card = $student_cards[$student_id];
- $sql1 .= '(' . $student_id . ',' . $paper_id . ','.$class_id.',' .$exam_id. ',' . $semester_id .','.$student_card.',"'.$school_student_card.'",""),';
- $sqlPV.= '(' . $student_id . ',' . $paper_id . ','.$class_id.',' .$exam_id. ',' . $semester_id .','.time().'),';
- }
- }
- $sql .= substr($sql1,0,-1).';';
- $sqlProperty .= substr($sqlPV,0,-1).';';
- $this->sConn->createCommand($sql)->execute();
- $this->sConn->createCommand($sqlProperty)->execute();
- }
- $trans->commit();
- } catch (Exception $e) {
- $trans->rollBack();
- return false;
- }
- return true;
- }
- /**
- * 刘红伟 end
- */
- public function semesterAllowToChange($semesterId){
- if($semester = $this->getSemester($semesterId)){
- if(is_numeric($semester["start_time"]) && ($semester["start_time"] - time()) <= $this->semesterAllowToChangeTime)
- return true;
- }
- return false;
- }
- public function semesterExists($semesterId){
- if(!$semesterId)
- return false;
- $rs = $this->sConn->createCommand("select exists(select * from semester where semester_id = '{$semesterId}')")->queryRow();
- $rs = current($rs);
- return $rs ? true : false;
- }
- public function changeSemester($semesterId){
- $code = 1001;
- if($semesterId){
- $code = array();
- if($this->role !== ROLE_SU){
- if($this->isPreviousSemester($semesterId))
- $code[] = 2001;
- if(!$this->semesterAllowToChange($semesterId)){
- $code[] = 2002;
- }
- }
- if($code)
- return $this->rs($code, __FUNCTION__);
- try{
- if($this->semesterExists($semesterId)){
- $trans = $this->sConn->beginTransaction();
- $this->sConn->createCommand("update semester set status = 0 where status = 1")->execute();
- $this->sConn->createCommand("update semester set status = 1 where semester_id = '{$semesterId}'")->execute();
- $trans->commit();
- $rs = true;
- }
- else
- $rs = false;
- }
- catch(Exception $e){
- $trans->rollBack();
- $rs = false;
- }
- if($rs){
- if($this->isFutureSemester($semesterId))
- $this->activateSemesterClassesStudentsRelations($semesterId);
- }
- $code = $rs ? 0 : 1002;
- }
- return $this->rs($code, "global");
- }
- public function getClassesTeachers($classesIds){
- $teachers = array();
- if($classesIds){
- $classesIds = implode(",", $classesIds);
- $rs = $this->sConn->createCommand("
- select t.teacher_name , tcr.class_id, c.level,t.subjects
- from teacher_class_relation as tcr
- join teacher as t on t.teacher_id = tcr.teacher_id
- join class as c on c.class_id = tcr.class_id
- where tcr.class_id in({$classesIds})
- ")->queryAll();
- if($rs)
- foreach ($rs as $val){
- if(isset(Yii::app()->params['subjectId'][$val['subjects']])){
- $teachers[(string)$val['class_id']][]=$val['teacher_name'].'('.Yii::app()->params['subjectId'][$val['subjects']].')';
- }else{
- $teachers[(string)$val['class_id']][]=$val['teacher_name'];
- }
- }
- }
- return $teachers;
- }
- public function getTeachersByclassIdsAndteacherName($classesIds,$teacher_name){
- $teachers = array();
- if($classesIds){
- $classesIds = implode(",", $classesIds);
- $rs = $this->sConn->createCommand("
- select group_concat(t.teacher_name) as teachers_names, tcr.class_id, c.level
- from teacher_class_relation as tcr
- join teacher as t on t.teacher_id = tcr.teacher_id
- join class as c on c.class_id = tcr.class_id
- where tcr.class_id in({$classesIds}) AND t.teacher_name LIKE '%{$teacher_name}%'
- group by tcr.class_id
- ")->queryAll();
- if($rs)
- $teachers = $rs;
- }
- return $teachers;
- }
- public function getClassPreviousStudentsList($classId, $condition = array(), $pageSize = 9, $type = "OBJ"){
- $rs = $this->buildEmptyPagingStruct();
- if($classId){
- $condition = Arr::merge(array("scr.class_id = '{$classId}'"), $condition);
- $condition = $this->condition($condition);
- $handle = $this->sConn->createCommand("
- select stu.*, scr.userno, scr.serial_number, c.class_name
- from student_class_relation as scr
- join student_info as stu on stu.student_id = scr.student_id
- join class as c on c.class_id = scr.class_id
- {$condition}
- group by student_id
- order by scr.serial_number ASC ,stu.student_id desc
- ")->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- }
- return $rs;
- }
- public function getClassPreviousStudentsListre($classId, $condition = array(), $pageSize = 9, $type = "OBJ"){
- $rs = $this->buildEmptyPagingStruct();
- if($classId){
- $condition = Arr::merge(array("scr.class_id = '{$classId}'"), $condition);
- $condition = $this->condition($condition);
- $handle = $this->sConn->createCommand("
- select stu.*, scr.userno, scr.serial_number, c.class_name
- from student_class_relation as scr
- join student_info as stu on stu.student_id = scr.student_id and scr.status = 0
- join class as c on c.class_id = scr.class_id
- {$condition}
- group by student_id
- order by scr.serial_number ASC ,stu.student_id desc
- ")->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- }
- return $rs;
- }
- public function getClassPreviousStudentsListWithAccounts($classId, $condition = array(), $pageSize = 9){
- $rs = $this->getClassPreviousStudentsList($classId, $condition, $pageSize, "ARR");
- if($rs["rs"]){
- foreach($rs["rs"] as $key => $val){
- $rs["rs"][$key]["username"] = "";
- $rs["rs"][$key]["status"] = null;
- }
- $studentsIds = $this->grouping($rs["rs"], "student_id");
- $studentsIds = implode("','", $studentsIds);
- $studentsIds = "'{$studentsIds}'";
- $accounts = $this->conn->createCommand("select * from student where student_id in({$studentsIds})")->queryAll();
- if($accounts){
- foreach($accounts as $account){
- foreach($rs["rs"] as $key => $val){
- if($val["student_id"] && $val["student_id"] == $account["student_id"]){
- $rs["rs"][$key]["username"] = $account["username"];
- $rs["rs"][$key]["status"] = $account["status"];
- }
- }
- }
- }
- }
- return $rs;
- }
- public function getClass($classId){
- $class = array();
- if($classId){
- $class = $this->sConn->createCommand("select * from class where class_id = '{$classId}'")->queryRow();
- }
- return $class;
- }
- public function getClassInfo($classId, $type = "ARR"){
- $classInfo = null;
- if($classId){
- $classInfo = $this->sConn->createCommand("
- select c.*, csr.subject_id, csr.material_id, csr.module_ids as modules_ids
- from class as c
- left join class_subject_relation as csr on csr.class_id = c.class_id
- where c.class_id = '{$classId}'
- ")->queryRow();
- if($type == "OBJ"){
- $classInfo = Arr::toObj($classInfo);
- }
- }
- return $classInfo;
- }
- public function getClassTeachersIds($classId){
- $teachersIds = array();
- if($classId){
- $rs = $this->sConn->createCommand("
- select * from teacher_class_relation where class_id = '{$classId}' group by teacher_id
- ")->queryAll();
- if($rs)
- $teachersIds = $this->grouping($rs, "teacher_id");
- }
- return $teachersIds;
- }
- public function semesterHasClass($semesterId){
- if($semesterId){
- $rs = $this->sConn->createCommand("select exists(select * from class where semester_id = '{$semesterId}')")->queryRow();
- return current($rs) ? true : false;
- }
- return false;
- }
- public function classHasStudent($classId){
- if(!($class = $this->getClass($classId)))
- return false;
- $condition = array("class_id = '{$classId}'");
- if($this->isCurrentSemester($class["semester_id"]))
- $condition = Arr::merge($condition, array("status = 0"));
- $condition = $this->condition($condition);
- $rs = $this->sConn->createCommand("select exists(select * from student_class_relation{$condition})")->queryRow();
- $rs = current($rs);
- return $rs ? true : false;
- }
- public function classHasExam($classId){
- if($classId){
- $rs = $this->sConn->createCommand("select exam_id,exam_group_id from exam where class_id = '{$classId}'")->queryAll();
- if($rs){
- return $rs;
- }
- }
- return false;
- }
- public function studentHasPaper($studentId){
- if($studentId){
- $rs = $this->sConn->createCommand("
- select exists(select * from student_paper_relation where semester_id = '{$this->semester["id"]}' and student_id = '{$studentId}' and is_del=0)
- ")->queryRow();
- $rs = current($rs);
- return $rs ? true : false;
- }
- return false;
- }
- public function studentHasPaperInOtherSemesters($studentId){
- if(!$studentId)
- return false;
- $rs = $this->sConn->createCommand("
- select exists(select * from student_paper_relation where semester_id != '{$this->semester["id"]}' and student_id = '{$studentId}') and is_del=0
- ")->queryRow();
- $rs = current($rs);
- return $rs ? true : false;
- }
- public function teacherHasBindedClass($teacherId){
- if($teacherId){
- $rs = $this->sConn->createCommand("select count(*) from teacher_class_relation where teacher_id = '{$teacherId}'")->queryAll();
- return current(current($rs)) > 0 ? true : false;
- }
- return false;
- }
- public function teacherHasCreatedExam($teacherId){
- if($teacherId){
- $rs = $this->sConn->createCommand("select count(*) from exam where teacher_id = '{$teacherId}'")->queryAll();
- return current(current($rs)) > 0 ? true : false;
- }
- return false;
- }
- public function teacherHasMarkingTask($teacherId){
- if($teacherId){
- $rs = $this->sConn->createCommand("select count(*) from marking_task where teacher_id = '{$teacherId}' AND status=0" )->queryAll();
- return current(current($rs)) > 0 ? true : false;
- }
- return false;
- }
- public function teacherHasProblemMark($teacherId){
- if($teacherId){
- $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();
- return current(current($rs)) > 0 ? true : false;
- }
- return false;
- }
- public function delSemester($semesterId){
- $code = 1001;
- if($semesterId){
- $code = array();
- if($this->role !== ROLE_SU){
- if($this->isCurrentSemester($semesterId))
- $code[] = 2001;
- if($this->semesterHasClass($semesterId))
- $code[] = 2002;
- }
- if($code)
- return $this->rs($code, __FUNCTION__);
- $rs = $this->sConn->createCommand("delete from semester where semester_id = '{$semesterId}'")->execute();
- $code = $rs ? 0 : 1002;
- }
- return $this->rs($code, "global");
- }
- public function CoachdelClass($classId){
- $code = 1001;
- $hasStudent=false;
- $hasExam=false;
- if($classId){
- $code = array();
- if($this->role !== ROLE_SU){
- if($this->classHasStudent($classId)){
- $hasStudent=true;
- $code[] = 2001;
- }
- if($this->classHasExam($classId)){
- $code[] = 2002;
- $hasExam=true;
- }
- }
- if($hasStudent){
- return $this->rs($code, 'delClass');
- }else{
- try{
- $trans = $this->sConn->beginTransaction();
- //查询班级属性
- $classInfo=$this->sConn->createCommand("select class_type from class where class_id = '{$classId}' " )->queryRow();
- if($hasExam){
- //隐藏班级
- $this->sConn->createCommand("UPDATE class SET is_hide = 1 WHERE class_id = '{$classId}'")->execute();
- }else{
- $this->sConn->createCommand("delete from class where class_id = '{$classId}'")->execute();
- $this->sConn->createCommand("delete from class_subject_relation where class_id = '{$classId}'")->execute();
- $this->sConn->createCommand("delete from teacher_class_relation where class_id = '{$classId}'")->execute();
- if($classInfo['class_type']==1){
- //查询行政班学生
- $classStudent=$this->sConn->createCommand("select student_id from student_class_relation WHERE class_id = '{$classId}' and status=0")->queryAll();
- if($classStudent){
- $studentIds=array();
- foreach ($classStudent as $item){
- $studentIds[]=$item['student_id'];
- }
- $this->sConn->createCommand("update student_class_relation set status=1,operation=1 where student_id in(".implode(',',$studentIds).") and status=0")->execute();
- }
- }else{
- $this->sConn->createCommand("UPDATE student_class_relation SET status = 1 WHERE class_id = '{$classId}'")->execute();
- }
- $this->sConn->createCommand("delete from product_class_relation where class_id = '{$classId}'")->execute();
- }
- $trans->commit();
- $rs = true;
- }
- catch(Exception $e){
- $trans->rollBack();
- $rs = false;
- }
- $code = $rs ? 0 : 1002;
- }
- }
- return $this->rs($code, "global");
- }
- public function delClass($classId){
- $code = 1001;
- if($classId){
- $code = array();
- $exam_ids = array();
- $exam_group_ids = array();
- $paper_ids = array();
- $_exam_group_ids = array();
- $exam_group = array();
- //查询班级属性
- $classInfo=$this->sConn->createCommand("select class_type from class where class_id = '{$classId}' " )->queryRow();
- if($this->role !== ROLE_SU){
- $class_exam = $this->classHasExam($classId);
- if($class_exam)
- {
- if(count($class_exam)>2){
- $code[] = 2002;
- }else
- {
- foreach($class_exam as $v)
- {
- $exam_ids[$v['exam_id']] = $v['exam_id'];
- $exam_group_ids[$v['exam_group_id']] = $v['exam_group_id'];
- }
- $papers = $this->sConn->createCommand("select paper_id from paper where exam_id IN (".implode(',',$exam_ids).")")->queryAll();
- if($papers)
- {
- foreach($papers as $v)
- {
- $paper_ids[$v['paper_id']] = $v['paper_id'];
- }
- }
- $exams = $this->sConn->createCommand("select exam_id,exam_group_id from exam where exam_group_id IN (".implode(',',$exam_group_ids).")")->queryAll();
- if($exams)
- {
- foreach ($exams as $v)
- {
- $exam_group[$v['exam_group_id']][] = $v;
- }
- foreach($exam_group_ids as $v)
- {
- if(isset($exam_group[$v]) && !empty($exam_group[$v]) && count($exam_group[$v])==1){
- $_exam_group_ids[] = $v['exam_group_id'];
- }
- }
- }
- }
- }
- }
- if($code)
- return $this->rs($code, __FUNCTION__);
- try{
- $trans = $this->sConn->beginTransaction();
- $this->sConn->createCommand("delete from class where class_id = '{$classId}'")->execute();
- //$this->sConn->createCommand("UPDATE student_info SET class_id = 0 WHERE class_id = '{$classId}'")->execute();
- if($classInfo['class_type']==1){
- //查询行政班学生
- $classStudent=$this->sConn->createCommand("select student_id from student_class_relation WHERE class_id = '{$classId}' and status=0")->queryAll();
- if($classStudent){
- $studentIds=array();
- foreach ($classStudent as $item){
- $studentIds[]=$item['student_id'];
- }
- $this->sConn->createCommand("update student_class_relation set status=1,operation=1 where student_id in(".implode(',',$studentIds).") and status=0")->execute();
- }
- }else{
- $this->sConn->createCommand("UPDATE student_class_relation SET status = 1,operation=1 WHERE class_id = '{$classId}'")->execute();
- }
- $this->sConn->createCommand("delete from class_subject_relation where class_id = '{$classId}'")->execute();
- $this->sConn->createCommand("delete from teacher_class_relation where class_id = '{$classId}'")->execute();
- $this->sConn->createCommand("delete from exam where class_id = '{$classId}'")->execute();
- $this->sConn->createCommand("delete from student_paper_relation where class_id = '{$classId}'")->execute();
- if($paper_ids)
- {
- $this->sConn->createCommand("delete from student_paper_topic_rs where paper_id in (".implode(',',$paper_ids).")")->execute();
- }
- $trans->commit();
- $rs = true;
- }
- catch(Exception $e){
- $trans->rollBack();
- $rs = false;
- }
- $code = $rs ? 0 : 1002;
- }
- return $this->rs($code, "global");
- }
- public function delExam($examId, $type){
- if($examId && $type){
- return $this->sConn->createCommand("delete from exam where exam_id = '{$examId}' and type = '{$type}'")->execute();
- }
- return false;
- }
- public function studentHasBindedClass($studentId){
- if(!$studentId)
- return false;
- $rs = $this->sConn->createCommand("select exists(select * from student_class_relation where student_id = '{$studentId}' and status = 0)")->queryRow();
- $rs = current($rs);
- return $rs ? true : false;
- }
- public function studentAccountExists($studentId){
- if(!$studentId)
- return false;
- $rs = $this->conn->createCommand("select exists(select * from student where student_id = '{$studentId}')")->queryRow();
- $rs = current($rs);
- return $rs ? true : false;
- }
- public function purgeStudent($studentId,$auth=0,$classId=0){
- $code = 1001;
- $msg = '删除成功';
- if($auth==0)
- {
- $rs = true;
- $authUsername = Yii::app()->session['coachInfo']["school_id"] . '_' . Yii::app()->session['coachInfo']["coach_name"];
- $http = http('service/student-delete-perm','post', $authUsername, array($studentId));
- $response = formatResponse($http);
- if(isset($response['data']) && $response['data']){
- if($response['data'][0]['hasOrder']==1){
- $rs=false;
- $code = 2001;
- $msg = '无法操作,该学生已存在订单数据';
- }
- }
- if($studentId && $rs){
- if($classId){
- $student_paper_relation = $this->sConn->createCommand("select * from student_paper_relation where student_id = ".$studentId." and class_id='".$classId."'")->queryRow();
- }else{
- $student_paper_relation = $this->sConn->createCommand("select * from student_paper_relation where student_id = ".$studentId)->queryRow();
- }
- if(!$student_paper_relation)
- {
- $trans1 = $this->sConn->beginTransaction();
- try{
- if($classId){
- $this->sConn->createCommand("update student_class_relation set status = 1,`operation`=1 where student_id = '{$studentId}' and class_id='".$classId."' and status = 0")->execute();
- }else{
- $this->sConn->createCommand("update student_class_relation set status = 1,`operation`=1 where student_id = '{$studentId}' and status = 0")->execute();
- }
- $trans1->commit();
- }
- catch(Exception $e){
- $trans1->rollBack();
- $rs = false;
- $msg = '删除失败';
- }
- $code = $rs ? 0 : 1002;
- }else
- {
- $code = 2001;
- $msg = '无法操作,该学生已存在考试数据';
- }
- }else
- {
- $rs = false;
- if(!$msg){
- $msg = '删除失败';
- }
- $code = $rs ? 0 : 1002;
- }
- }else
- {
- $rs = true;
- if($studentId){
- $trans1 = $this->sConn->beginTransaction();
- try{
- if($classId){
- $this->sConn->createCommand("update student_class_relation set status = 1,`operation`=1 where student_id = '{$studentId}' and class_id='".$classId."' and status = 0")->execute();
- }else{
- $this->sConn->createCommand("update student_class_relation set status = 1,`operation`=1 where student_id = '{$studentId}' and status = 0")->execute();
- }
- $trans1->commit();
- }
- catch(Exception $e){
- $trans1->rollBack();
- $rs = false;
- $msg = '删除失败';
- }
- }else
- {
- $rs = false;
- $msg = '删除失败';
- }
- $code = $rs ? 0 : 1002;
- }
- return array('code'=>$code,'msg'=>$msg);
- }
- public function removeStudentClassRelation($studentId, $classId){
- $code = 1001;
- if($studentId && $classId){
- if($this->role !== ROLE_SU){
- if($this->studentHasPaper($studentId))
- return $this->rs(2001, __FUNCTION__);
- }
- $rs = $this->sConn->createCommand("delete from student_class_relation where student_id = '{$studentId}' and class_id = '{$classId}'")->execute();
- $code = $rs ? 0 : 1002;
- }
- return $this->rs($code, "global");
- }
- public function teacherAccountExists($teacherId){
- if(!$teacherId)
- return false;
- $rs = $this->conn->createCommand("select exists(select * from xb_teacher where teacher_id = '{$teacherId}')")->queryRow();
- $rs = current($rs);
- return $rs ? true : false;
- }
- public function delTeacher($teacherId){
- $code = 1001;
- if($teacherId){
- $code = array();
- if($this->role !== ROLE_SU){
- if($this->teacherHasBindedClass($teacherId))
- $code[] = 2001;
- if($this->teacherHasCreatedExam($teacherId))
- $code[] = 2002;
- }
- if($code)
- return $this->rs($code, __FUNCTION__);
- try{
- $trans1 = $this->sConn->beginTransaction();
- $trans2 = $this->conn->beginTransaction();
- $this->conn->createCommand("update xb_teacher set status = '2' where teacher_id = '{$teacherId}'")->execute();
- $this->sConn->createCommand("update teacher set status = '2' where teacher_id = '{$teacherId}'")->execute();
- $this->kickTeacher($teacherId);
- $trans1->commit();
- $trans2->commit();
- $rs = true;
- }
- catch(Exception $e){
- $trans1->rollBack();
- $trans2->rollBack();
- $rs = false;
- }
- $code = $rs ? 0 : 1002;
- }
- return $this->rs($code, "global");
- }
- public function purgeTeacher($teacherId){
- $code = 1001;
- if($teacherId){
- $code = array();
- $teacherAccountExists = $this->teacherAccountExists($teacherId);
- if($this->role !== ROLE_SU && $teacherAccountExists){
- if($this->teacherHasBindedClass($teacherId))
- $code[] = 2001;
- if($this->teacherHasCreatedExam($teacherId))
- $code[] = 2002;
- if ($this->teacherHasMarkingTask($teacherId))
- $code[] = 2003;
- if ($this->teacherHasProblemMark($teacherId))
- $code[] = 2004;
- }
- if($code)
- return $this->rs($code, __FUNCTION__);
- try{
- $trans1 = $this->sConn->beginTransaction();
- $trans2 = $this->conn->beginTransaction();
- if($teacherAccountExists){
- $this->conn->createCommand("delete from xb_teacher where teacher_id = '{$teacherId}'")->execute();
- }
- $this->sConn->createCommand("delete from teacher where teacher_id = '{$teacherId}'")->execute();
- $this->sConn->createCommand("delete from teacher_class_relation where teacher_id = '{$teacherId}'")->execute();
- $this->kickTeacher($teacherId);
- $trans1->commit();
- $trans2->commit();
- $rs = true;
- }
- catch(Exception $e){
- $trans1->rollBack();
- $trans2->rollBack();
- $rs = false;
- }
- $code = $rs ? 0 : 1002;
- }
- return $this->rs($code, "global");
- }
- public function getSemesters($condition = array(), $orderBy = array("start_time desc"), $offset = 0, $limit = -1){
- $condition = $this->condition($condition);
- $orderBy = $this->orderBy($orderBy);
- $limit = $this->limit($offset, $limit);
- $rs = $this->sConn->createCommand("select * from semester{$condition}{$orderBy}{$limit}")->queryAll();
- return $rs;
- }
- public function getSemestersList($condition = array(), $orderBy = array(), $pageSize = 20){
- $condition = $this->condition($condition);
- $orderBy = $this->orderBy($orderBy);
- $handle = $this->sConn->createCommand("select * from semester{$condition}{$orderBy}")->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- return $rs;
- }
- public function getSemesterIdByClassId($classId){
- $semesterId = null;
- $class = $this->getClass($classId);
- if(!empty($class["semester_id"]))
- $semesterId = $class["semester_id"];
- return $semesterId;
- }
- public function getSemester($semesterId){
- $semester = array();
- if($semesterId){
- $semester = $this->sConn->createCommand("select * from semester where semester_id = '{$semesterId}'")->queryRow();
- }
- return $semester;
- }
- public function getTheYearLastSemester($year){
- if(!$year)
- return array();
- return $this->sConn->createCommand("select * from semester where school_year = '{$year}' order by start_time desc limit 1")->queryRow();
- }
- public function getCurrSemester(){
- return $this->sConn->createCommand("select * from semester where status = '1'")->queryRow();
- }
- public function isCurrentSemester($semesterId){
- $semester = $this->getCurrSemester();
- if($semester && $semester['semester_id']==$semesterId){
- return true;
- }
- return false;
- }
- public function getClassExamsList($classId, $orderBy = array("exam_id desc"), $pageSize = 9){
- $rs = $this->buildEmptyPagingStruct();
- if($classId){
- $orderBy = $this->orderBy($orderBy);
- $handle = $this->sConn->createCommand("
- select e.* from exam as e where e.class_id = '{$classId}' and e.semester_id = '{$this->semester["id"]}' and e.type = 2{$orderBy}
- ")->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- }
- return $rs;
- }
- public function getExamRecordsList($examId, $orderBy = array("record_id asc"), $pageSize = 9){
- $rs = array();
- if($examId){
- $orderBy = $this->orderBy($orderBy);
- $handle = $this->sConn->createCommand("
- select er.*, stu.realname
- from exam_record as er
- join student_info as stu on stu.student_id = er.student_id
- where er.exam_id = '{$examId}'
- {$orderBy}
- ")->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- }
- return $rs;
- }
- public function getExam($examId, $type = "ARR"){
- $exam = array();
- if($examId){
- $exam = $this->sConn->createCommand("select * from exam where exam_id = '{$examId}'")->queryRow();
- if($type == "OBJ"){
- $exam = Arr::toObj($exam);
- }
- }
- return $exam;
- }
- public function getExamClassId($examId){
- if($exam = $this->getExam($examId))
- return $exam["class_id"];
- return null;
- }
- public function isClassExam($classId, $examId){
- $rs = false;
- if($classId && $examId){
- $rs = $this->sConn->createCommand("select exists(select * from exam where exam_id = '{$examId}' and class_id = '{$classId}')")->queryRow();
- $rs = current($rs) ? true : false;
- }
- return $rs;
- }
- public function studentBelongsToClass($studentId, $classId){
- if($studentId && $classId){
- $rs = $this->sConn->createCommand("select exists(select * from student_info where student_id = '{$studentId}' and class_id = '{$classId}')")->queryRow();
- $rs = current($rs);
- if($rs) return true;
- }
- return false;
- }
- public function getMyClassesIds(){
- $ids = array();
- $rs = $this->sConn->createCommand("select * from class where coach_id = '{$this->coachId}'")->queryAll();
- if($rs){
- $ids = $this->grouping($rs, "class_id");
- }
- return $ids;
- }
- public function isMyClass($classId){
- if($classId){
- $myClassesIds = $this->getMyClassesIds();
- if(in_array($classId, $myClassesIds))
- return true;
- }
- return false;
- }
- public function getExamClassesIds($examId){
- $ids = array();
- if($examId){
- $rs = $this->sConn->createCommand("select * from exam where exam_id = '{$examId}'")->queryAll();
- $ids = $this->grouping($rs, "class_id");
- }
- return $ids;
- }
- public function getParentsList($orderBy = array(), $pageSize = 9){
- $handle = $this->conn->createCommand("
- select pa.*
- from student as stu
- join parent_student_relation as psr on psr.student_id = stu.student_id
- join `parent` as pa on pa.parent_id = psr.parent_id and pa.status != 2
- where stu.school_id = '{$this->schoolId}'
- group by pa.parent_id
- ")->query();
- $rs = $this->paging($this->conn, $handle, $pageSize);
- return $rs;
- }
- public function delParentsStudentsRelations($parentsIds){
- if($parentsIds){
- if(!is_array($parentsIds)){
- $parentsIds = array($parentsIds);
- }
- $ids = "";
- foreach($parentsIds as $key => $val){
- $ids .= ",'{$val}'";
- }
- $ids = substr($ids, 1);
- try{
- $trans = $this->sConn->beginTransaction();
- $this->sConn->createCommand("delete from parent_student_relation where parent_id in({$ids})")->execute();
- $trans->commit();
- return true;
- }
- catch(Exception $e){
- $trans->rollBack();
- return false;
- }
- }
- return false;
- }
- public function updateParent($parentId, $parentData){
- $updateKeys = array("phone_number", "password", "realname", "sex", "age", "status", "last_login_time");
- $insertKeys = array("phone_number");
- foreach($parentData as $key => $val){
- switch($key){
- case "phone_number":
- if(!Filter::testPhoneNumber($val))
- return false;
- break;
- case "password":
- if(strlen($val) > 18)
- return false;
- $parentData[$key] = md5(sha1($val));
- break;
- case "realname":
- if(strlen($val) > 10)
- return false;
- break;
- case "sex":
- if(!in_array($val, array("0", "1", "2")))
- return false;
- break;
- case "age":
- if(!is_numeric($val) || $val < 1 || $val > 100)
- return false;
- break;
- case "status":
- if(!in_array($val, array("0", "1", "2")))
- return false;
- break;
- case "last_login_time":
- if(!is_numeric($val) || strlen($val) > 10)
- return false;
- break;
- default:
- break;
- }
- }
- if($parentId){
- $pattern = "";
- foreach($parentData as $key => $val){
- if(!in_array($key, $updateKeys))
- continue;
- $pattern .= ",`{$key}` = '{$val}'";
- }
- $pattern = substr($str, 1);
- if($pattern)
- return $this->conn->createCommand("update parent set {$pattern} where parent_id = '{$parentId}'")->execute();
- }
- else{
- $fields = "";
- $values = "";
- $keys = array();
- foreach($parentData as $key => $val){
- if(!in_array($key, $allowKeys))
- continue;
- $keys[] = $key;
- $fields .= ",`{$key}`";
- $values .= ",'{$val}'";
- }
- if(array_diff($requiredKeys, $keys))
- return false;
- $fields .= ",`signup_time`";
- $values .= ",'".time()."'";
- $fields = substr($fields, 1);
- $values = substr($values, 1);
- return $this->conn->createCommand("insert into parent({$fields}) values({$values})")->execute();
- }
- return false;
- }
- public function addParent($parentData){
- return $this->updateParent(null, $parentData);
- }
- public function getStudentInfo($studentId, $type = "ARRAY"){
- $studentInfo = array();
- if($studentId){
- $studentInfo = $this->sConn->createCommand("
- select stu.student_id, stu.realname, stu.sex, stu.family_tel, stu.telephone, stu.student_phone, stu.picture, stu.signature, stu.add_time,
- 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
- from student_info as stu
- join student_class_relation as scr on scr.student_id = stu.student_id and scr.status = 0
- join class as c on c.class_id = scr.class_id
- where stu.student_id = '{$studentId}'
- ")->queryRow();
- if($type == "OBJ")
- $studentInfo = Arr::toObj($studentInfo);
- }
- return $studentInfo;
- }
- public function getStudentInfoByUsername($username){
- $studentInfo = array();
- if($username){
- $rs = $this->conn->createCommand("select * from student where username = '{$username}'")->queryAll();
- if($rs){
- $rs = current($rs);
- $studentInfo = $this->getStudentInfo($rs["student_id"]);
- }
- }
- return $studentInfo;
- }
- public function getStudentParents($studentId){
- $parents = array();
- if($studentId){
- $parents = $this->conn->createCommand("
- select pa.*, pwor.openid
- from parent_student_relation as psr
- join parent as pa on pa.parent_id = psr.parent_id
- join parent_wechat_openid_relation as pwor on pwor.parent_id = psr.parent_id
- where psr.student_id = '{$studentId}'
- group by pa.parent_id
- limit 0, 10
- ")->queryAll();
- }
- return $parents;
- }
- public function insertExamRecord($recordData, $xls){
- if((empty($recordData["exam_id"]) && !isset($_FILES)) || empty($recordData["name"]) || empty($recordData["class_id"]))
- return false;
- $time = time();
- if(isset($xls["error"]) && $xls["error"] == 0){
- $xls = $xls["file"];
- $excel = new Excel();
- $sheetData = $excel->read($xls);
- $studentsCount = 0;
- $students = array();
- $studentsIds = array();
- $notExistStudents = array();
- $notExistStudentsCount = 0;
- $incomplete = array();
- $incompleteCount = 0;
- $notBelongsToClass = array();
- $notBelongsToClassCount = 0;
- $studentsExist = array();
- $studentsExistCount = 0;
- foreach($sheetData as $key => $val){
- $chinese = $val["B"];
- $math = $val["C"];
- $english = $val["D"];
- $physics = $val["E"];
- $chemistry = $val["F"];
- $biology = $val["G"];
- $politics = $val["H"];
- $history = $val["I"];
- $geography = $val["J"];
- $classRank = $val["K"];
- $gradeRank = $val["L"];
- 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)){
- continue;
- }
- 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)){
- $studentsCount++;
- $incompleteCount++;
- continue;
- }
- $studentsCount++;
- $username = (string)$val["A"];
- $studentInfo = $this->getStudentInfoByUsername($username);
- $studentId = $studentInfo ? $studentInfo["student_id"] : null;
- if(!$studentId){
- $notExistStudents[] = $username;
- $notExistStudentsCount++;
- continue;
- }
- if(!$this->studentBelongsToClass($studentId, $recordData["class_id"])){
- $notBelongsToClass[] = $username;
- $notBelongsToClassCount++;
- continue;
- }
- if(in_array($studentId, $studentsIds)){
- $studentsExist[] = $username;
- $studentsExistCount++;
- continue;
- }
- $studentsIds[] = $studentId;
- $chinese = is_numeric($val["B"]) && $val["B"] ? $val["B"] : 0;
- $math = is_numeric($val["C"]) && $val["C"] ? $val["C"] : 0;
- $english = is_numeric($val["D"]) && $val["D"] ? $val["D"] : 0;
- $physics = is_numeric($val["E"]) && $val["E"] ? $val["E"] : 0;
- $chemistry = is_numeric($val["F"]) && $val["F"] ? $val["F"] : 0;
- $biology = is_numeric($val["G"]) && $val["G"] ? $val["G"] : 0;
- $politics = is_numeric($val["H"]) && $val["H"] ? $val["H"] : 0;
- $history = is_numeric($val["I"]) && $val["I"] ? $val["I"] : 0;
- $geography = is_numeric($val["J"]) && $val["J"] ? $val["J"] : 0;
- $classRank = is_numeric($val["K"]) && $val["K"] ? $val["K"] : 0;
- $gradeRank = is_numeric($val["L"]) && $val["L"] ? $val["L"] : 0;
- $totalScore = $chinese + $math + $english + $physics + $chemistry + $biology + $politics + $history + $geography;
- $students[$studentId]["student_id"] = $studentId;
- $students[$studentId]["subject_chinese"] = $chinese;
- $students[$studentId]["subject_math"] = $math;
- $students[$studentId]["subject_english"] = $english;
- $students[$studentId]["subject_physics"] = $physics;
- $students[$studentId]["subject_chemistry"] = $chemistry;
- $students[$studentId]["subject_biology"] = $biology;
- $students[$studentId]["subject_history"] = $history;
- $students[$studentId]["subject_politics"] = $politics;
- $students[$studentId]["subject_geography"] = $geography;
- $students[$studentId]["total_score"] = $totalScore;
- $students[$studentId]["class_rank"] = $classRank;
- $students[$studentId]["grade_rank"] = $gradeRank;
- }
- $failedCount = $notExistStudentsCount + $incompleteCount + $notBelongsToClassCount + $studentsExistCount;
- $successCount = $studentsCount - $failedCount;
- $result["global"]["msg"] = "从Excel读取了{$studentsCount}条记录,其中{$successCount}导入成功,{$failedCount}条导入失败";
- $result["errors"][0]["type"] = "数据信息不完整";
- $result["errors"][0]["count"] = $incompleteCount;
- $result["errors"][0]["msg"] = "共有{$incompleteCount}行数据不完整,请检查";
- $result["errors"][1]["type"] = "不存在该用户名的学生";
- $result["errors"][1]["count"] = $notExistStudentsCount;
- $notExistStudents = implode(",", $notExistStudents);
- $result["errors"][1]["msg"] = "用户名为{$notExistStudents}的学生无法导入";
- $result["errors"][2]["type"] = "该学生不属于本班级";
- $result["errors"][2]["count"] = $notBelongsToClassCount;
- $notBelongsToClass = implode(",", $notBelongsToClass);
- $result["errors"][2]["msg"] = "用户名为{$notBelongsToClass}的学生无法导入";
- $result["errors"][3]["type"] = "表格中有重复的学生";
- $result["errors"][3]["count"] = $studentsExistCount;
- $studentsExist = implode(",", $studentsExist);
- $result["errors"][3]["msg"] = "用户名为{$studentsExist}的学生无法导入";
- if($failedCount == $studentsCount){
- $result["global"]["result"] = "失败";
- return $result;
- }
- else if($successCount == $studentsCount){
- $result["global"]["result"] = "全部成功";
- unset($result["errors"][0]);
- }
- else{
- $result["global"]["result"] = "部分成功";
- }
- $fields = "";
- $values = array();
- if($students){
- if(!empty($recordData["exam_id"]))
- $examId = $recordData["exam_id"];
- else{
- // $uuid = $this->sConn->createCommand("select RIGHT(UUID_SHORT(), 20)")->queryAll();
- // $examId = current(current($uuid));
- $examId=getUniqueId($this->schoolId);
- }
- $student = current($students);
- foreach($student as $key => $val){
- $fields .= ",`{$key}`";
- }
- $fields .= ",`record_id`";
- $fields .= ",`exam_id`";
- $fields .= ",`coach_id`";
- $fields .= ",`add_time`";
- $fields = "(".substr($fields, 1).")";
- foreach($students as $studentId => $student){
- $values[$studentId] = "";
- foreach($student as $key => $val){
- $values[$studentId] .= ",'{$val}'";
- }
- $uuid=getUniqueId($this->schoolId);
- $values[$studentId] .= ",'{$uuid}'";
- $values[$studentId] .= ",'{$examId}'";
- $values[$studentId] .= ",'{$this->coachId}'";
- $values[$studentId] .= ",'{$time}'";
- $values[$studentId] = "(".substr($values[$studentId], 1).")";
- }
- if($values){
- $values = implode(",", $values);
- $sql = "insert into exam_record{$fields} values{$values}";
- }
- else{
- $sql = "";
- }
- try{
- $trans = $this->sConn->beginTransaction();
- if(isset($recordData["exam_id"]) && $recordData["exam_id"]){
- if(isset($recordData["name"]) && $recordData["name"])
- $this->sConn->createCommand("update exam set name = '{$recordData["name"]}' where exam_id = '{$recordData["exam_id"]}'")->execute();
- if($sql){
- $this->sConn->createCommand("delete from exam_record where exam_id = '{$examId}'")->execute();
- $this->sConn->createCommand($sql)->execute();
- }
- }
- else if($sql){
- $this->sConn->createCommand("
- insert into exam(`exam_id`, `class_id`, `name`, semester_id, `type`, `status`, `create_time`)
- values('{$examId}', '{$recordData["class_id"]}', '{$recordData["name"]}', '{$this->semester["id"]}', 2, 2, '{$time}')
- ")->execute();
- $this->sConn->createCommand($sql)->execute();
- }
- $trans->commit();
- if($students){
- foreach($students as $student){
- if($parents = $this->getStudentParents($student["student_id"])){
- $student = $this->getStudentInfo($student["student_id"]);
- $studentName = $student ? $student["realname"] : "";
- $msg = "您的孩子{$studentName}综合排名有了新的数据, 点击查看";
- $redirectionPath = "home/examrecord?studentId={$student["student_id"]}";
- foreach($parents as $parent){
- $this->writeParentNotification($parent["parent_id"], $msg, 1, $redirectionPath);
- if($parent["openid"])
- send_weixin($parent["openid"], $msg, $this->parentNotificationHost."/home/examrecord?studentId={$student["student_id"]}");
- }
- }
- }
- }
- return $result;
- }
- catch(Exception $e){
- $trans->rollBack();
- return false;
- }
- }
- else if(isset($recordData["name"]) && $recordData["name"] && isset($recordData["exam_id"]) && $recordData["exam_id"])
- return $this->sConn->createCommand("update exam set name = '{$recordData["name"]}' where exam_id = '{$recordData["exam_id"]}'")->execute();
- return false;
- }
- else if(isset($recordData["name"]) && $recordData["name"] && isset($recordData["exam_id"]) && $recordData["exam_id"]){
- return $this->sConn->createCommand("update exam set name = '{$recordData["name"]}' where exam_id = '{$recordData["exam_id"]}'")->execute();
- }
- return false;
- }
- public function getOrdersList($orderBy = array(), $pageSize = 9){
- $orderBy = $this->orderBy($orderBy);
- $handle = $this->conn->createCommand("
- select ord.*
- from order_school_relation as osr
- join `order` as ord on ord.order_id = osr.order_id
- where osr.school_id = '{$this->schoolId}'
- {$orderBy}
- ")->query();
- $rs = $this->paging($this->conn, $handle, $pageSize);
- return $rs;
- }
- public function writeParentNotification($parentId, $content, $type = null, $redirectionPath = ""){
- if($parentId && $content){
- $time = time();
- $fields = "`parent_id`, `content`, `time`";
- $values = "'{$parentId}', '{$content}', '{$time}'";
- if($type){
- $fields .= ", `type`";
- $values .= ", '{$type}'";
- if($type == 1 && $redirectionPath){
- $fields .= ",`redirection_path`";
- $values .= ",'{$redirectionPath}'";
- }
- }
- $sql = "insert into parent_notification({$fields}) values({$values})";
- return $this->conn->createCommand($sql)->execute();
- }
- return false;
- }
- public function getClassStudentsList($classId, $condition = array(), $pageSize = 9, $type = "OBJ"){
- $rs = $this->buildEmptyPagingStruct();
- if($classId){
- $condition = Arr::merge(array("scr.class_id = '{$classId}'", "scr.status = 0"), $condition);
- $condition = $this->condition($condition);
- $handle = $this->sConn->createCommand("
- select stu.*, scr.userno, scr.serial_number, c.grade,c.class_name
- from student_class_relation as scr
- join student_info as stu on stu.student_id = scr.student_id
- join class as c on c.class_id = scr.class_id
- {$condition}
- order by serial_number asc
- ")->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- }
- return $rs;
- }
- public function getInClassStudentsList($classId, $condition = array(), $pageSize = 9, $type = "OBJ"){
- $rs = $this->buildEmptyPagingStruct();
- if($classId){
- $condition = Arr::merge(array("scr.class_id in( ".implode(',',$classId).")", "scr.status = 0"), $condition);
- $condition = $this->condition($condition);
- $handle = $this->sConn->createCommand("
- select stu.*, scr.userno, scr.serial_number, c.grade,c.class_name
- from student_class_relation as scr
- join student_info as stu on stu.student_id = scr.student_id
- join class as c on c.class_id = scr.class_id
- {$condition}
- order by serial_number asc
- ")->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- }
- return $rs;
- }
- public function getStudents($studentsIds = array()){
- $students = array();
- if($studentsIds){
- $studentsIds = "'".implode("','", $studentsIds)."'";
- $students = $this->sConn->createCommand("
- select stu.*, scr.serial_number, scr.userno
- from student_info as stu
- left join student_class_relation as scr on scr.student_id = stu.student_id and scr.status = 0
- where stu.student_id in({$studentsIds})
- order by serial_number asc
- ")->queryAll();
- }
- return $students;
- }
- public function getClassStudents($classId, $condition = array(), $type = "OBJ"){
- $students = array();
- if($classId){
- $condition = Arr::merge(array("scr.class_id = '{$classId}'", "scr.status = 0"), $condition);
- $condition = $this->condition($condition);
- $students = $this->sConn->createCommand("
- select stu.*, scr.userno, scr.serial_number, c.class_name
- from student_class_relation as scr
- join student_info as stu on stu.student_id = scr.student_id
- join class as c on c.class_id = scr.class_id
- {$condition}
- order by serial_number asc
- ")->queryAll();
- }
- if($type == "OBJ")
- $students = Arr::toObj($students);
- return $students;
- }
- public function getClassStudentsListWithAccounts1($classId, $condition = array(), $pageSize = 9,$where=''){
- $student_ids = array();
- if(empty($where))
- {
- if(is_array($classId)){
- $rs = $this->getInClassStudentsList($classId, $condition, $pageSize, "ARR");
- }else{
- $rs = $this->getClassStudentsList($classId, $condition, $pageSize, "ARR");
- }
- }else
- {
- $accounts = $this->conn->createCommand("select * from student where ".$where)->queryRow();
- if($accounts)
- {
- $condition= array("stu.student_id=" . $accounts['student_id']);
- if(is_array($classId)){
- $rs = $this->getInClassStudentsList($classId, $condition, $pageSize, "ARR");
- }else{
- $rs = $this->getClassStudentsList($classId, $condition, $pageSize, "ARR");
- }
- }else
- {
- $rs["rs"] =array();
- $rs['pager'] = (object)array();
- $rs['pager']->rowsCount = 0;
- }
- }
- if($rs["rs"]){
- foreach($rs["rs"] as $key => $val){
- $rs["rs"][$key]["username"] = "";
- $rs["rs"][$key]["status"] = null;
- }
- $studentsIds = $this->grouping($rs["rs"], "student_id");
- $studentsIds = implode("','", $studentsIds);
- $studentsIds = "'{$studentsIds}'";
- if($where)
- {
- $accounts = $this->conn->createCommand("select * from student where ".$where)->queryAll();
- if($accounts){
- foreach($accounts as $account){
- foreach($rs["rs"] as $key => $val){
- if($val["student_id"] && $val["student_id"] == $account["student_id"]){
- $rs["rs"][$key]["username"] = $account["username"];
- $rs["rs"][$key]["student_card"] = $account["student_card"];
- $rs["rs"][$key]["school_student_card"] = $account["school_student_card"];
- if(isset($account["zhixue_student_card"]))
- {
- $rs["rs"][$key]["zhixue_student_card"] = $account["zhixue_student_card"];
- }
- $rs["rs"][$key]["status"] = $account["status"];
- }else
- {
- unset($rs["rs"][$key]);
- $rs['pager']->rowsCount = 0;
- }
- }
- }
- }else
- {
- foreach($rs["rs"] as $key => $val){
- unset($rs["rs"][$key]);
- }
- $rs['pager']->rowsCount = 0;
- }
- }else
- {
- $accounts = $this->conn->createCommand("select * from student where student_id in({$studentsIds})")->queryAll();
- if($accounts){
- foreach($accounts as $account){
- foreach($rs["rs"] as $key => $val){
- if($val["student_id"] && $val["student_id"] == $account["student_id"]){
- $rs["rs"][$key]["username"] = $account["username"];
- $rs["rs"][$key]["student_card"] = $account["student_card"];
- $rs["rs"][$key]["school_student_card"] = $account["school_student_card"];
- if(isset($account["zhixue_student_card"]))
- {
- $rs["rs"][$key]["zhixue_student_card"] = $account["zhixue_student_card"];
- }
- $rs["rs"][$key]["status"] = $account["status"];
- }
- }
- }
- }
- }
- }
- return $rs;
- }
- public function getClassStudentsListWithAccounts($classId, $condition = array(), $pageSize = 9,$where=''){
- $student_ids = array();
- if(empty($where))
- {
- if(is_array($classId)){
- $rs = $this->getInClassStudentsList($classId, $condition, $pageSize, "ARR");
- }else{
- $rs = $this->getClassStudentsList($classId, $condition, $pageSize, "ARR");
- }
- }else
- {
- $accounts = $this->conn->createCommand("select * from student where ".$where)->queryAll();
- if($accounts)
- {
- $studentIdOr=array();
- foreach ($accounts as $v){
- $studentIdOr[]=" stu.student_id=" . $v['student_id']." ";
- }
- $condition= array(" (".implode(' OR ',$studentIdOr).") ","c.class_type=1");
- if(is_array($classId)){
- $rs = $this->getInClassStudentsList($classId, $condition, $pageSize, "ARR");
- }else{
- $rs = $this->getClassStudentsList($classId, $condition, $pageSize, "ARR");
- }
- }else
- {
- $rs["rs"] =array();
- $rs['pager'] = (object)array();
- $rs['pager']->rowsCount = 0;
- }
- }
- //debug($rs["rs"]);
- if($rs["rs"]){
- foreach($rs["rs"] as $key => $val){
- $rs["rs"][$key]["username"] = "";
- $rs["rs"][$key]["status"] = null;
- }
- $studentsIds = $this->grouping($rs["rs"], "student_id");
- $studentsIds = implode("','", $studentsIds);
- $studentsIds = "'{$studentsIds}'";
- if($where)
- {
- $accounts = $this->conn->createCommand("select * from student where ".$where)->queryAll();
- if($accounts){
- $b_student_status = array();
- $b_student_card = array();
- $b_student_username = array();
- $b_school_student_card = array();
- $b_zhixue_student_card = array();
- foreach($accounts as $v)
- {
- $b_student_card[$v['student_id']] = $v['student_card'];
- $b_student_status[$v['student_id']] = $v['status'];
- $b_student_username[$v['student_id']] = $v['username'];
- $b_school_student_card[$v['student_id']] = $v['school_student_card'];
- $b_zhixue_student_card[$v['student_id']] = $v['zhixue_student_card'];
- }
- foreach($rs["rs"] as $key => $val){
- if( isset($b_student_card[$val["student_id"]]) && !empty($b_student_card[$val["student_id"]])){
- $rs["rs"][$key]["username"] = $b_student_username[$val["student_id"]];
- $rs["rs"][$key]["student_card"] = $b_student_card[$val["student_id"]];
- $rs["rs"][$key]["school_student_card"] = $b_school_student_card[$val["student_id"]];
- if(isset($b_zhixue_student_card[$val["student_id"]]))
- {
- $rs["rs"][$key]["zhixue_student_card"] = $b_zhixue_student_card[$val["student_id"]];
- }
- $rs["rs"][$key]["status"] = $b_student_status[$val["student_id"]];
- }else
- {
- unset($rs["rs"][$key]);
- $rs['pager']->rowsCount = 0;
- }
- }
- }else
- {
- foreach($rs["rs"] as $key => $val){
- unset($rs["rs"][$key]);
- }
- $rs['pager']->rowsCount = 0;
- }
- }else
- {
- $accounts = $this->conn->createCommand("select * from student where student_id in ({$studentsIds})")->queryAll();
- if($accounts){
- $b_student_status = array();
- $b_student_card = array();
- $b_student_username = array();
- $b_school_student_card = array();
- $b_zhixue_student_card = array();
- foreach($accounts as $v)
- {
- $b_student_card[$v['student_id']] = $v['student_card'];
- $b_student_status[$v['student_id']] = $v['status'];
- $b_student_username[$v['student_id']] = $v['username'];
- $b_school_student_card[$v['student_id']] = $v['school_student_card'];
- $b_zhixue_student_card[$v['student_id']] = $v['zhixue_student_card'];
- }
- foreach($rs["rs"] as $key => $val){
- if( isset($b_student_card[$val["student_id"]]) && !empty($b_student_card[$val["student_id"]])){
- $rs["rs"][$key]["username"] = $b_student_username[$val["student_id"]];
- $rs["rs"][$key]["student_card"] = $b_student_card[$val["student_id"]];
- $rs["rs"][$key]["school_student_card"] = $b_school_student_card[$val["student_id"]];
- if(isset($b_zhixue_student_card[$val["student_id"]]))
- {
- $rs["rs"][$key]["zhixue_student_card"] = $b_zhixue_student_card[$val["student_id"]];
- }
- $rs["rs"][$key]["status"] = $b_student_status[$val["student_id"]];
- }
- }
- }
- }
- }
- return $rs;
- }
- public function classExamHasPaperRs($examId, $classId){
- if($examId){
- $rs = $this->sConn->createCommand("
- select exists(
- select *
- from exam as e
- join paper as p on p.exam_id = e.exam_id and p.paper_type = 1
- join student_paper_relation as spr on spr.paper_id = p.paper_id and spr.class_id = '{$classId}'
- join student_info as stu on stu.student_id = spr.student_id
- join student_class_relation as scr on scr.student_id = stu.student_id and scr.class_id = '{$classId}'
- where e.exam_id = '{$examId}' and (spr.scoring > 0 or spr.lost_score > 0) and spr.is_del=0
- )
- ")->queryRow();
- $rs = current($rs);
- if($rs) return true;
- }
- return false;
- }
- public function isPreviousSemester($semesterId){
- if(($semester = $this->getSemester($semesterId)) && ($currSemester = $this->getCurrSemester())){
- if($semester["start_time"] < $currSemester["start_time"])
- return true;
- }
- return false;
- }
- public function isFutureSemester($semesterId){
- return !$this->isCurrentSemester($semesterId) && !$this->isPreviousSemester($semesterId) ? true : false;
- }
- public function kickTeacher($teacherId){
- if($teacherId){
- return Redist::del(Yii::app()->session->sessionID);
- }
- return false;
- }
- public function teacherPhoneNumberExists($phoneNumber){
- if($phoneNumber){
- $count = $this->conn->createCommand("select exists(select * from xb_teacher where phone_number = '{$phoneNumber}')")->queryRow();
- $count = current($count);
- return $count ? true : false;
- }
- return false;
- }
- public function getExamRsByClass($examId, $classId, $orderBy = array(), $type = ""){
- if(!$orderBy)
- $orderBy = array("--scr.serial_number asc", "stu.realname asc");
- $orderBy = $this->orderBy($orderBy);
- $rs = $this->sConn->createCommand("
- 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,
- spr.scoring, p.score, p.paper_id, spr.wrong_count, spr.partial_right_count
- from exam as e
- join paper as p on p.exam_id = e.exam_id and p.paper_type = 1
- join student_paper_relation as spr on spr.paper_id = p.paper_id and spr.class_id = '{$classId}'
- join student_info as stu on stu.student_id = spr.student_id
- join student_class_relation as scr on scr.student_id = stu.student_id and scr.class_id = '{$classId}'
- where e.exam_id = '{$examId}' and spr.is_del=0
- {$orderBy}
- ")->queryAll();
- if($rs){
- Arr::sortByField($rs, "scoring", "DESC");
- $previousRecord = 0;
- $previousRank = 1;
- foreach($rs as $key => $val){
- if($val["scoring"] && $val["score"]){
- $rs[$key]["right_rate"] = $val["scoring"] / $val["score"];
- $rs[$key]["right_rate"] = sprintf("%.2f", $rs[$key]["right_rate"]);
- }
- else
- $rs[$key]["right_rate"] = 0;
- if($val["scoring"] && $val["score"]){
- $rs[$key]["scoring_rate"] = $val["scoring"] / $val["score"];
- $rs[$key]["scoring_rate"] = sprintf("%.2f", $rs[$key]["scoring_rate"]);
- }
- else
- $rs[$key]["scoring_rate"] = 0;
- $rs[$key]["wrong_count"] = $val["wrong_count"] + $val["partial_right_count"];
- if($val["scoring"] == $previousRecord){
- $rs[$key]["rank"] = $previousRank;
- }
- else{
- $rs[$key]["rank"] = $key + 1;
- }
- $previousRecord = $val["scoring"];
- $previousRank = $rs[$key]["rank"];
- }
- Arr::sortByField($rs, "serial_number");
- }
- if($type === "EXCEL"){
- $array = array();
- foreach($rs as $key => $val){
- $array[$key] = array(
- $val["serial_number"],
- $val["realname"],
- $val['exam_name'] . ($val["paper_name"] ? ' '.$val['paper_name'] : ''),
- $val["scoring"],
- $val["score"],
- ($val["scoring_rate"] * 100)."%",
- $val["rank"],
- $val["wrong_count"],
- );
- }
- $title = array("编号", "姓名", "试卷", "得分", "总分", "得分率", "班级名次", "错题");
- array_unshift($array, $title);
- $rs = $array;
- }
- return $rs;
- }
- public function serialNumberExistsInClass($serialNumber, $classId, $studentId = null){
- if($serialNumber && $classId){
- $condition = array("class_id = '{$classId}'", "serial_number = '{$serialNumber}'", "status = 0");
- if($studentId)
- $condition = Arr::merge($condition, array("student_id != '{$studentId}'"));
- $condition = $this->condition($condition);
- $rs = $this->sConn->createCommand("select exists(select * from student_class_relation{$condition})")->queryRow();
- $rs = current($rs);
- return $rs ? true : false;
- }
- return false;
- }
- public function getPrintTask($examId, $classId, $type){
- if(!$examId || !$classId || !is_numeric($type))
- return array();
- return $this->sConn->createCommand("select * from class_exam_printer where exam_id = '{$examId}' and class_id = '{$classId}' and `type` = '{$type}'")->queryRow();
- }
- //获取班级多个考试
- public function getClassExamAc($condition = array(), $orderBy = array("add_time desc")){
- $condition = Arr::merge($condition, array("c.semester_id = '{$this->semester["id"]}'"));
- $condition = $this->condition($condition);
- $orderBy = $this->orderBy($orderBy);
- $handle = $this->sConn->createCommand("
- select 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,
- p.tpl_doc_src, p.answer_card_src, p.is_labelled,p.paper_id
- from class as c
- join class_subject_relation as csr on csr.class_id = c.class_id
- join exam as e on e.class_id = c.class_id
- join class_exam_printer as cep on cep.class_id = c.class_id and cep.exam_id = e.exam_id
- JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id
- join paper as p on p.exam_id = e.exam_id
- {$condition}
- group by class_id, exam_id, type
- {$orderBy}
- ")->queryAll();
- return $handle;
- }
- public function getPrintListre($condition = array(), $orderBy = array("add_time desc"), $pageSize = 9){
- $condition = Arr::merge($condition, array("c.semester_id = '{$this->semester["id"]}'"));
- $condition = $this->condition($condition);
- $orderBy = $this->orderBy($orderBy);
- $handle = $this->sConn->createCommand("
- 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,
- 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
- from class as c
- join class_subject_relation as csr on csr.class_id = c.class_id
- join exam as e on e.class_id = c.class_id
- join class_exam_printer as cep on cep.class_id = c.class_id and cep.exam_id = e.exam_id
- JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id
- join paper as p on p.exam_id = e.exam_id
- {$condition}
- group by class_id, exam_id, type
- {$orderBy}
- ")->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- $examsIds = $this->grouping($rs["rs"], "exam_id", true);
- $examsIds = "'".implode("','", $examsIds)."'";
- $sprs = $this->sConn->createCommand("select exam_id, is_complete, is_feedback,is_wrongbook_pdf,is_wbisp_pdf,is_isp_pdf from student_paper_relation where exam_id in({$examsIds}) ")->queryAll();
- $examsSprs = array();
- foreach($sprs as $key => $val){
- if(!isset($examsSprs[$val["exam_id"]]))
- $examsSprs[$val["exam_id"]] = array();
- $examsSprs[$val["exam_id"]][] = $val;
- }
- $examsStudentsCount = array();
- foreach($examsSprs as $examId => $sprs){
- $examsStudentsCount[$examId] = array(
- "is_complete_count" => 0,
- "is_uploaded_count" => 0,
- "wrongbook_pdf_count" => 0,
- "wbisp_pdf_count" => 0,
- "isp_pdf_count" => 0,
- );
- $examsStudentsCount[$examId]["students_count"] = count($sprs);
- foreach($sprs as $k => $v){
- if($v["is_complete"] == 1){
- $examsStudentsCount[$examId]["is_complete_count"]++;
- }
- $examsStudentsCount[$examId]["is_uploaded_count"]++;
- if($v["is_wrongbook_pdf"] == 1)
- {
- $examsStudentsCount[$examId]["wrongbook_pdf_count"]++;
- }
- if($v["is_wbisp_pdf"] == 1)
- {
- $examsStudentsCount[$examId]["wbisp_pdf_count"]++;
- }
- if($v["is_isp_pdf"] == 1)
- {
- $examsStudentsCount[$examId]["isp_pdf_count"]++;
- }
- }
- }
- foreach($rs["rs"] as $key => $val){
- if(isset($examsStudentsCount[$val["exam_id"]])){
- $rs["rs"][$key]["students_count"] = $examsStudentsCount[$val["exam_id"]]["students_count"];
- $rs["rs"][$key]["is_complete_count"] = $examsStudentsCount[$val["exam_id"]]["is_complete_count"];
- $rs["rs"][$key]["is_uploaded_count"] = $examsStudentsCount[$val["exam_id"]]["is_uploaded_count"];
- $rs["rs"][$key]["wrongbook_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wrongbook_pdf_count"];
- $rs["rs"][$key]["wbisp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wbisp_pdf_count"];
- $rs["rs"][$key]["isp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["isp_pdf_count"];
- }
- else{
- $rs["rs"][$key]["students_count"] = 0;
- $rs["rs"][$key]["is_complete_count"] = 0;
- $rs["rs"][$key]["is_uploaded_count"] = 0;
- $rs["rs"][$key]["wrongbook_pdf_count"] = 0;
- $rs["rs"][$key]["wbisp_pdf_count"] = 0;
- $rs["rs"][$key]["isp_pdf_count"] = 0;
- }
- $tplData = json_decode($val["tpl_data"], true);
- $paperSize = null;
- $examDate = null;
- if(in_array($val["tpl_index"], Yii::app()->params["custom_tpls_ids"])){
- switch($val["tpl_index"]){
- case "12":
- $paperSize = "A3";
- break;
- case "13":
- $paperSize = "A4";
- break;
- case "14":
- $paperSize = "8K";
- break;
- case "15":
- $paperSize = "16K";
- break;
- case "2012":
- $paperSize = "A3";
- break;
- case "2013":
- $paperSize = "A4";
- break;
- case "2014":
- $paperSize = "8K";
- break;
- case "2015":
- $paperSize = "16K";
- break;
- case "2016":
- $paperSize = "A3";
- break;
- case "2017":
- $paperSize = "A4";
- break;
- case "2018":
- $paperSize = "8K";
- break;
- case "2019":
- $paperSize = "16K";
- break;
- case "1012":
- $paperSize = "A3";
- break;
- case "1013":
- $paperSize = "A4";
- break;
- case "1014":
- $paperSize = "8K";
- break;
- case "1015":
- $paperSize = "16K";
- break;
- case "1016":
- $paperSize = "A3";
- break;
- case "1017":
- $paperSize = "A4";
- break;
- case "1018":
- $paperSize = "8K";
- break;
- case "1019":
- $paperSize = "16K";
- break;
- case "3012":
- $paperSize = "A3";
- break;
- case "3016":
- $paperSize = "A3";
- break;
- }
- }
- if(in_array($val["tpl_index"], Yii::app()->params["custom_tpls_ids"])){
- switch($val["tpl_index"]){
- case "16":
- $paperSize = "A3";
- break;
- case "3016":
- $paperSize = "A3";
- break;
- case "3007":
- $paperSize = "A3";
- break;
- case "3012":
- $paperSize = "A3";
- break;
- case "17":
- $paperSize = "A4";
- break;
- case "18":
- $paperSize = "8K";
- break;
- case "19":
- $paperSize = "16K";
- break;
- }
- }
- if($tplData){
- if(!isset($tplData["examDate"]) || !($examDate = strtotime($tplData["examDate"])))
- $examDate = $val["create_time"];
- if($paperSize === null && isset($tplData["paper"]) && $tplData["paper"] == 1)
- $paperSize = "A3";
-
- $rs["rs"][$key]["topic_count"] = isset($tplData['totals'])?$tplData['totals']:0;
- }
- if($examDate === null)
- $examDate = $val["create_time"];
- if($paperSize === null)
- $paperSize = "A4";
- $time = time();
- $expireTime = $examDate + (3600 * 24 * 2);
- if($time > $expireTime){
- $rs["rs"][$key]["is_expired"] = true;
- }
- else{
- $rs["rs"][$key]["is_expired"] = false;
- }
- $rs["rs"][$key]["exam_time"] = $examDate;
- $rs["rs"][$key]["paper_size"] = $paperSize;
- }
- return $rs;
- }
- //获取下载班级
- public function getDownloadClassWb($condition = array(), $orderBy = array("add_time desc")){
- $condition = Arr::merge($condition, array("c.semester_id = '{$this->semester["id"]}'"));
- $condition = $this->condition($condition);
- $orderBy = $this->orderBy($orderBy);
- $rs['rs'] = $this->sConn->createCommand("
- 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
- from class as c
- join class_subject_relation as csr on csr.class_id = c.class_id
- join exam as e on e.class_id = c.class_id
- join class_exam_printer as cep on cep.class_id = c.class_id and cep.exam_id = e.exam_id
- JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id
- join paper as p on p.exam_id = e.exam_id
- {$condition}
- group by class_id, exam_id, type
- {$orderBy}
- ")->queryAll();
- $examsIds = $this->grouping($rs["rs"], "exam_id", true);
- $examsIds = "'".implode("','", $examsIds)."'";
- $sprs = $this->sConn->createCommand("select exam_id, is_complete, is_feedback,is_wrongbook_pdf,is_wbisp_pdf,is_isp_pdf from student_paper_relation where exam_id in({$examsIds}) and is_del=0")->queryAll();
- $examsSprs = array();
- foreach($sprs as $key => $val){
- if(!isset($examsSprs[$val["exam_id"]]))
- $examsSprs[$val["exam_id"]] = array();
- $examsSprs[$val["exam_id"]][] = $val;
- }
- $examsStudentsCount = array();
- foreach($examsSprs as $examId => $sprs){
- $examsStudentsCount[$examId] = array(
- "is_complete_count" => 0,
- "is_uploaded_count" => 0,
- "wrongbook_pdf_count" => 0,
- "wbisp_pdf_count" => 0,
- "isp_pdf_count" => 0,
- );
- $examsStudentsCount[$examId]["students_count"] = count($sprs);
- foreach($sprs as $k => $v){
- if($v["is_complete"] == 1)
- {
- $examsStudentsCount[$examId]["is_complete_count"]++;
- }
- if($v["is_feedback"] == 1)
- {
- $examsStudentsCount[$examId]["is_uploaded_count"]++;
- }
- if($v["is_wrongbook_pdf"] == 1)
- {
- $examsStudentsCount[$examId]["wrongbook_pdf_count"]++;
- }
- if($v["is_wbisp_pdf"] == 1)
- {
- $examsStudentsCount[$examId]["wbisp_pdf_count"]++;
- }
- if($v["is_isp_pdf"] == 1)
- {
- $examsStudentsCount[$examId]["isp_pdf_count"]++;
- }
- }
- }
- foreach($rs["rs"] as $key => $val){
- if(isset($examsStudentsCount[$val["exam_id"]])){
- $rs["rs"][$key]["students_count"] = $examsStudentsCount[$val["exam_id"]]["students_count"];
- $rs["rs"][$key]["is_complete_count"] = $examsStudentsCount[$val["exam_id"]]["is_complete_count"];
- $rs["rs"][$key]["is_uploaded_count"] = $examsStudentsCount[$val["exam_id"]]["is_uploaded_count"];
- $rs["rs"][$key]["wrongbook_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wrongbook_pdf_count"];
- $rs["rs"][$key]["wbisp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wbisp_pdf_count"];
- $rs["rs"][$key]["isp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["isp_pdf_count"];
- }
- else{
- $rs["rs"][$key]["students_count"] = 0;
- $rs["rs"][$key]["is_complete_count"] = 0;
- $rs["rs"][$key]["is_uploaded_count"] = 0;
- $rs["rs"][$key]["wrongbook_pdf_count"] = 0;
- $rs["rs"][$key]["wbisp_pdf_count"] = 0;
- $rs["rs"][$key]["isp_pdf_count"] = 0;
- }
- }
- return $rs["rs"];
- }
- public function getPrintList($condition = array(), $orderBy = array("add_time desc"), $pageSize = 9){
- $condition = Arr::merge($condition, array("c.semester_id = '{$this->semester["id"]}'"));
- $condition = $this->condition($condition);
- $orderBy = $this->orderBy($orderBy);
- $handle = $this->sConn->createCommand("
- 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
- from class as c
- join class_subject_relation as csr on csr.class_id = c.class_id
- join exam as e on e.class_id = c.class_id
- join class_exam_printer as cep on cep.class_id = c.class_id and cep.exam_id = e.exam_id
- JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id
- join paper as p on p.exam_id = e.exam_id
- {$condition}
- group by class_id, exam_id, type
- {$orderBy}
- ")->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- $examsIds = $this->grouping($rs["rs"], "exam_id", true);
- $examsIds = "'".implode("','", $examsIds)."'";
- $sprs = $this->sConn->createCommand("select exam_id, is_complete, is_feedback,is_wrongbook_pdf,is_wbisp_pdf,is_isp_pdf from student_paper_relation where exam_id in({$examsIds}) and is_del=0")->queryAll();
- $examsSprs = array();
- foreach($sprs as $key => $val){
- if(!isset($examsSprs[$val["exam_id"]]))
- $examsSprs[$val["exam_id"]] = array();
- $examsSprs[$val["exam_id"]][] = $val;
- }
- $examsStudentsCount = array();
- foreach($examsSprs as $examId => $sprs){
- $examsStudentsCount[$examId] = array(
- "is_complete_count" => 0,
- "is_uploaded_count" => 0,
- "wrongbook_pdf_count" => 0,
- "wbisp_pdf_count" => 0,
- "isp_pdf_count" => 0,
- );
- $examsStudentsCount[$examId]["students_count"] = count($sprs);
- foreach($sprs as $k => $v){
- if($v["is_complete"] == 1)
- {
- $examsStudentsCount[$examId]["is_complete_count"]++;
- }
- if($v["is_feedback"] == 1)
- {
- $examsStudentsCount[$examId]["is_uploaded_count"]++;
- }
- if($v["is_wrongbook_pdf"] == 1)
- {
- $examsStudentsCount[$examId]["wrongbook_pdf_count"]++;
- }
- if($v["is_wbisp_pdf"] == 1)
- {
- $examsStudentsCount[$examId]["wbisp_pdf_count"]++;
- }
- if($v["is_isp_pdf"] == 1)
- {
- $examsStudentsCount[$examId]["isp_pdf_count"]++;
- }
- }
- }
- foreach($rs["rs"] as $key => $val){
- if(isset($examsStudentsCount[$val["exam_id"]])){
- $rs["rs"][$key]["students_count"] = $examsStudentsCount[$val["exam_id"]]["students_count"];
- $rs["rs"][$key]["is_complete_count"] = $examsStudentsCount[$val["exam_id"]]["is_complete_count"];
- $rs["rs"][$key]["is_uploaded_count"] = $examsStudentsCount[$val["exam_id"]]["is_uploaded_count"];
- $rs["rs"][$key]["wrongbook_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wrongbook_pdf_count"];
- $rs["rs"][$key]["wbisp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wbisp_pdf_count"];
- $rs["rs"][$key]["isp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["isp_pdf_count"];
- }
- else{
- $rs["rs"][$key]["students_count"] = 0;
- $rs["rs"][$key]["is_complete_count"] = 0;
- $rs["rs"][$key]["is_uploaded_count"] = 0;
- $rs["rs"][$key]["wrongbook_pdf_count"] = 0;
- $rs["rs"][$key]["wbisp_pdf_count"] = 0;
- $rs["rs"][$key]["isp_pdf_count"] = 0;
- }
- $tplData = json_decode($val["tpl_data"], true);
- $paperSize = null;
- $examDate = null;
- if(in_array($val["tpl_index"], Yii::app()->params["custom_tpls_ids"])){
- switch($val["tpl_index"]){
- case "12":
- $paperSize = "A3";
- break;
- case "13":
- $paperSize = "A4";
- break;
- case "14":
- $paperSize = "8K";
- break;
- case "15":
- $paperSize = "16K";
- break;
- case "2012":
- $paperSize = "A3";
- break;
- case "2013":
- $paperSize = "A4";
- break;
- case "2014":
- $paperSize = "8K";
- break;
- case "2015":
- $paperSize = "16K";
- break;
- case "2016":
- $paperSize = "A3";
- break;
- case "2017":
- $paperSize = "A4";
- break;
- case "2018":
- $paperSize = "8K";
- break;
- case "2019":
- $paperSize = "16K";
- break;
- case "1012":
- $paperSize = "A3";
- break;
- case "1013":
- $paperSize = "A4";
- break;
- case "1014":
- $paperSize = "8K";
- break;
- case "1015":
- $paperSize = "16K";
- break;
- case "1016":
- $paperSize = "A3";
- break;
- case "1017":
- $paperSize = "A4";
- break;
- case "1018":
- $paperSize = "8K";
- break;
- case "1019":
- $paperSize = "16K";
- break;
- case "3016":
- $paperSize = "A3";
- break;
- case "3012":
- $paperSize = "A3";
- break;
- case "3013":
- $paperSize = "A4";
- break;
- case "3017":
- $paperSize = "A4";
- break;
- }
- }
- if(in_array($val["tpl_index"], Yii::app()->params["custom_tpls_ids"])){
- switch($val["tpl_index"]){
- case "16":
- $paperSize = "A3";
- break;
- case "3016":
- $paperSize = "A3";
- break;
- case "3017":
- $paperSize = "A4";
- break;
- case "3013":
- $paperSize = "A4";
- break;
- case "3007":
- $paperSize = "A3";
- break;
- case "17":
- $paperSize = "A4";
- break;
- case "18":
- $paperSize = "8K";
- break;
- case "19":
- $paperSize = "16K";
- break;
- }
- }
- if($tplData){
- if(!isset($tplData["examDate"]) || !($examDate = strtotime($tplData["examDate"])))
- $examDate = $val["create_time"];
- if($paperSize === null && isset($tplData["paper"]) && $tplData["paper"] == 1)
- $paperSize = "A3";
- }
- if($examDate === null)
- $examDate = $val["create_time"];
- if($paperSize === null)
- $paperSize = "A4";
- $time = time();
- $expireTime = $examDate + (3600 * 24 * 2);
- if($time > $expireTime){
- $rs["rs"][$key]["is_expired"] = true;
- }
- else{
- $rs["rs"][$key]["is_expired"] = false;
- }
- $rs["rs"][$key]["exam_time"] = $examDate;
- $rs["rs"][$key]["paper_size"] = $paperSize;
- }
- return $rs;
- }
- public function getExamList($condition = array(), $orderBy = array("add_time desc"), $pageSize = 9){
- $condition = Arr::merge($condition, array("c.semester_id = '{$this->semester["id"]}'"));
- $condition = $this->condition($condition);
- $orderBy = $this->orderBy($orderBy);
- $handle = $this->sConn->createCommand("
- select c.class_name,e.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,
- p.tpl_doc_src, p.answer_card_src, p.is_labelled,p.paper_id,eg.import_score_type
- from class as c
- join class_subject_relation as csr on csr.class_id = c.class_id
- join exam as e on e.class_id = c.class_id
- JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id
- join paper as p on p.exam_id = e.exam_id
- {$condition}
- group by e.class_id, e.exam_id, e.`type`
- {$orderBy}
- ")->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- $examsIds = $this->grouping($rs["rs"], "exam_id", true);
- $examsIds = "'".implode("','", $examsIds)."'";
- $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();
- $examsSprs = array();
- $paperExamIds=array();
- foreach($sprs as $key => $val){
- if(!isset($examsSprs[$val["exam_id"]]))
- $examsSprs[$val["exam_id"]] = array();
- $examsSprs[$val["exam_id"]][] = $val;
- $paperExamIds[$val["exam_id"]]=$val["paper_id"];
- }
- $importScoretype=$this->grouping($rs["rs"], "import_score_type", true);
- //判断上传成绩方式
- $student_answer_img_num=array();
- //导入方式,读取实际上传数量
- foreach($paperExamIds as $eid =>$paperId){
- $student_answer_img_num[$eid]=$this->getUpAnswerStudent($paperId,array(),true);
- }
- $examsStudentsCount = array();
- foreach($examsSprs as $examId => $sprs){
- $examsStudentsCount[$examId] = array(
- "is_complete_count" => 0,
- "is_uploaded_count" => 0,
- "student_img_count" => 0,
- "wrongbook_pdf_count" => 0,
- "wbisp_pdf_count" => 0,
- "isp_pdf_count" => 0,
- 'student_img_up_num'
- );
- $examsStudentsCount[$examId]["students_count"] = count($sprs);
- foreach($sprs as $k => $v){
- if($v["is_complete"] == 1)
- {
- $examsStudentsCount[$examId]["is_complete_count"]++;
- }
- if($v["is_feedback"] == 1)
- {
- $examsStudentsCount[$examId]["is_uploaded_count"]++;
- }
- if(trim($v["student_img_paper"]))
- {
- $examsStudentsCount[$examId]["student_img_count"]++;
- }
- if($v["is_wrongbook_pdf"] == 1)
- {
- $examsStudentsCount[$examId]["wrongbook_pdf_count"]++;
- }
- if($v["is_wbisp_pdf"] == 1)
- {
- $examsStudentsCount[$examId]["wbisp_pdf_count"]++;
- }
- if($v["is_isp_pdf"] == 1)
- {
- $examsStudentsCount[$examId]["isp_pdf_count"]++;
- }
- }
- if(isset($student_answer_img_num[$examId])){
- $examsStudentsCount[$examId]["student_img_up_num"]=$student_answer_img_num[$examId];
- }else{
- $examsStudentsCount[$examId]["student_img_up_num"]=0;
- }
- }
- foreach($rs["rs"] as $key => $val){
- if(isset($examsStudentsCount[$val["exam_id"]])){
- $rs["rs"][$key]["students_count"] = $examsStudentsCount[$val["exam_id"]]["students_count"];
- $rs["rs"][$key]["is_complete_count"] = $examsStudentsCount[$val["exam_id"]]["is_complete_count"];
- $rs["rs"][$key]["is_uploaded_count"] = $examsStudentsCount[$val["exam_id"]]["is_uploaded_count"];
- $rs["rs"][$key]["student_img_count"] = $examsStudentsCount[$val["exam_id"]]["student_img_count"];
- $rs["rs"][$key]["wrongbook_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wrongbook_pdf_count"];
- $rs["rs"][$key]["wbisp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wbisp_pdf_count"];
- $rs["rs"][$key]["isp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["isp_pdf_count"];
- $rs["rs"][$key]["student_img_up_num"] = $examsStudentsCount[$val["exam_id"]]["student_img_up_num"];
- }
- else{
- $rs["rs"][$key]["students_count"] = 0;
- $rs["rs"][$key]["is_complete_count"] = 0;
- $rs["rs"][$key]["is_uploaded_count"] = 0;
- $rs["rs"][$key]["student_img_count"] = 0;
- $rs["rs"][$key]["wrongbook_pdf_count"] = 0;
- $rs["rs"][$key]["wbisp_pdf_count"] = 0;
- $rs["rs"][$key]["isp_pdf_count"] = 0;
- $rs["rs"][$key]["student_img_up_num"] = 0;
- }
- $tplData = json_decode($val["tpl_data"], true);
- $paperSize = null;
- $examDate = null;
- if($tplData){
- if(!isset($tplData["examDate"]) || !($examDate = strtotime($tplData["examDate"])))
- $examDate = $val["create_time"];
- if($paperSize === null && isset($tplData["paper"]) && $tplData["paper"] == 1)
- $paperSize = "A3";
- }
- if($examDate === null)
- $examDate = $val["create_time"];
- if($paperSize === null)
- $paperSize = "A4";
- $time = time();
- $expireTime = $examDate + (3600 * 24 * 2);
- if($time > $expireTime){
- $rs["rs"][$key]["is_expired"] = true;
- }
- else{
- $rs["rs"][$key]["is_expired"] = false;
- }
- $rs["rs"][$key]["exam_time"] = $examDate;
- $rs["rs"][$key]["paper_size"] = $paperSize;
- }
- return $rs;
- }
- public function getThirdPrintList($condition = array(), $orderBy = array("e.create_time desc"), $pageSize = 9){
- $condition = Arr::merge($condition, array("e.semester_id = '{$this->semester["id"]}'"));
- $condition = $this->condition($condition);
- $orderBy = $this->orderBy($orderBy);
- $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
- from exam_group as eg
- left join exam as e on eg.exam_group_id = e.exam_group_id
- left join paper as p on p.exam_id = e.exam_id
- {$condition}
- group by eg.exam_group_id
- {$orderBy}
- ";
- $handle = $this->sConn->createCommand($sql)->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- return $rs;
- }
- //获取下载班级
- public function getDownloadClassIpf($condition = array(), $orderBy = array("add_time desc")){
- $condition = Arr::merge($condition, array("c.semester_id = '{$this->semester["id"]}'"));
- $condition = $this->condition($condition);
- $orderBy = $this->orderBy($orderBy);
- $rs['rs'] = $this->sConn->createCommand("
- 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
- from class as c
- join class_subject_relation as csr on csr.class_id = c.class_id
- join exam as e on e.class_id = c.class_id
- join class_exam_printer as cep on cep.class_id = c.class_id and cep.exam_id = e.exam_id
- JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id
- join paper as p on p.exam_id = e.exam_id
- {$condition}
- group by class_id, exam_id, type
- {$orderBy}
- ")->queryAll();
- $examsIds = $this->grouping($rs["rs"], "exam_id", true);
- $examsIds = "'".implode("','", $examsIds)."'";
- $sprs = $this->sConn->createCommand("select exam_id, is_complete, is_feedback,is_wrongbook_pdf,is_wbisp_pdf,is_isp_pdf from student_paper_relation where exam_id in({$examsIds})")->queryAll();
- $examsSprs = array();
- foreach($sprs as $key => $val){
- if(!isset($examsSprs[$val["exam_id"]]))
- $examsSprs[$val["exam_id"]] = array();
- $examsSprs[$val["exam_id"]][] = $val;
- }
- $examsStudentsCount = array();
- foreach($examsSprs as $examId => $sprs){
- $examsStudentsCount[$examId] = array(
- "is_complete_count" => 0,
- "is_uploaded_count" => 0,
- "wrongbook_pdf_count" => 0,
- "wbisp_pdf_count" => 0,
- "isp_pdf_count" => 0,
- );
- $examsStudentsCount[$examId]["students_count"] = count($sprs);
- foreach($sprs as $k => $v){
- if($v["is_complete"] == 1)
- {
- $examsStudentsCount[$examId]["is_complete_count"]++;
- }
- $examsStudentsCount[$examId]["is_uploaded_count"]++;
- if($v["is_wrongbook_pdf"] == 1)
- {
- $examsStudentsCount[$examId]["wrongbook_pdf_count"]++;
- }
- if($v["is_wbisp_pdf"] == 1)
- {
- $examsStudentsCount[$examId]["wbisp_pdf_count"]++;
- }
- if($v["is_isp_pdf"] == 1)
- {
- $examsStudentsCount[$examId]["isp_pdf_count"]++;
- }
- }
- }
- foreach($rs["rs"] as $key => $val){
- if(isset($examsStudentsCount[$val["exam_id"]])){
- $rs["rs"][$key]["students_count"] = $examsStudentsCount[$val["exam_id"]]["students_count"];
- $rs["rs"][$key]["is_complete_count"] = $examsStudentsCount[$val["exam_id"]]["is_complete_count"];
- $rs["rs"][$key]["is_uploaded_count"] = $examsStudentsCount[$val["exam_id"]]["is_uploaded_count"];
- $rs["rs"][$key]["wrongbook_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wrongbook_pdf_count"];
- $rs["rs"][$key]["wbisp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wbisp_pdf_count"];
- $rs["rs"][$key]["isp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["isp_pdf_count"];
- }
- else{
- $rs["rs"][$key]["students_count"] = 0;
- $rs["rs"][$key]["is_complete_count"] = 0;
- $rs["rs"][$key]["is_uploaded_count"] = 0;
- $rs["rs"][$key]["wrongbook_pdf_count"] = 0;
- $rs["rs"][$key]["wbisp_pdf_count"] = 0;
- $rs["rs"][$key]["isp_pdf_count"] = 0;
- }
- }
- return $rs["rs"];
- }
- public function getPrintList_ipf($condition = array(), $orderBy = array("add_time desc"), $pageSize = 9){
- $condition = Arr::merge($condition, array("c.semester_id = '{$this->semester["id"]}'"));
- $condition = $this->condition($condition);
- $orderBy = $this->orderBy($orderBy);
- $handle = $this->sConn->createCommand("
- 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
- from class as c
- join class_subject_relation as csr on csr.class_id = c.class_id
- join exam as e on e.class_id = c.class_id
- join class_exam_printer as cep on cep.class_id = c.class_id and cep.exam_id = e.exam_id
- JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id
- join paper as p on p.exam_id = e.exam_id
- {$condition}
- group by class_id, exam_id, type
- {$orderBy}
- ")->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- $examsIds = $this->grouping($rs["rs"], "exam_id", true);
- $examsIds = "'".implode("','", $examsIds)."'";
- $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();
- $examsSprs = array();
- foreach($sprs as $key => $val){
- if(!isset($examsSprs[$val["exam_id"]]))
- $examsSprs[$val["exam_id"]] = array();
- $examsSprs[$val["exam_id"]][] = $val;
- }
- $examsStudentsCount = array();
- foreach($examsSprs as $examId => $sprs){
- $examsStudentsCount[$examId] = array(
- "is_complete_count" => 0,
- "is_uploaded_count" => 0,
- "wrongbook_pdf_count" => 0,
- "wbisp_pdf_count" => 0,
- "isp_pdf_count" => 0,
- "wrongbook_download_count" => 0,
- "wbisp_download_count" => 0,
- "isp_download_count" => 0,
- );
- $examsStudentsCount[$examId]["students_count"] = count($sprs);
- foreach($sprs as $k => $v){
- if($v["is_complete"] == 1)
- {
- $examsStudentsCount[$examId]["is_complete_count"]++;
- }
- $examsStudentsCount[$examId]["is_uploaded_count"]++;
- if($v["is_wrongbook_pdf"] == 1)
- {
- $examsStudentsCount[$examId]["wrongbook_pdf_count"]++;
- }
- if($v["is_wbisp_pdf"] == 1)
- {
- $examsStudentsCount[$examId]["wbisp_pdf_count"]++;
- }
- if($v["is_isp_pdf"] == 1)
- {
- $examsStudentsCount[$examId]["isp_pdf_count"]++;
- }
- if($v["is_wrongbook_download"] == 1)
- {
- $examsStudentsCount[$examId]["wrongbook_download_count"]++;
- }
- if($v["is_two_isp_download"] == 1)
- {
- $examsStudentsCount[$examId]["isp_download_count"]++;
- }
- if($v["is_three_isp_download"] == 1)
- {
- $examsStudentsCount[$examId]["wbisp_download_count"]++;
- }
- }
- }
- foreach($rs["rs"] as $key => $val){
- if(isset($examsStudentsCount[$val["exam_id"]])){
- $rs["rs"][$key]["students_count"] = $examsStudentsCount[$val["exam_id"]]["students_count"];
- $rs["rs"][$key]["is_complete_count"] = $examsStudentsCount[$val["exam_id"]]["is_complete_count"];
- $rs["rs"][$key]["is_uploaded_count"] = $examsStudentsCount[$val["exam_id"]]["is_uploaded_count"];
- $rs["rs"][$key]["wrongbook_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wrongbook_pdf_count"];
- $rs["rs"][$key]["wbisp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wbisp_pdf_count"];
- $rs["rs"][$key]["isp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["isp_pdf_count"];
- $rs["rs"][$key]["wrongbook_download_count"] = $examsStudentsCount[$val["exam_id"]]["wrongbook_download_count"];
- $rs["rs"][$key]["isp_download_count"] = $examsStudentsCount[$val["exam_id"]]["isp_download_count"];
- $rs["rs"][$key]["wbisp_download_count"] = $examsStudentsCount[$val["exam_id"]]["wbisp_download_count"];
- }
- else{
- $rs["rs"][$key]["students_count"] = 0;
- $rs["rs"][$key]["is_complete_count"] = 0;
- $rs["rs"][$key]["is_uploaded_count"] = 0;
- $rs["rs"][$key]["wrongbook_pdf_count"] = 0;
- $rs["rs"][$key]["wbisp_pdf_count"] = 0;
- $rs["rs"][$key]["isp_pdf_count"] = 0;
- $rs["rs"][$key]["wrongbook_download_count"] = 0;
- $rs["rs"][$key]["isp_download_count"] = 0;
- $rs["rs"][$key]["wbisp_download_count"] = 0;
- }
- $tplData = json_decode($val["tpl_data"], true);
- $paperSize = null;
- $examDate = null;
- if(in_array($val["tpl_index"], Yii::app()->params["custom_tpls_ids"])){
- switch($val["tpl_index"]){
- case "12":
- $paperSize = "A3";
- break;
- case "13":
- $paperSize = "A4";
- break;
- case "14":
- $paperSize = "8K";
- break;
- case "15":
- $paperSize = "16K";
- break;
- case "2012":
- $paperSize = "A3";
- break;
- case "2013":
- $paperSize = "A4";
- break;
- case "2014":
- $paperSize = "8K";
- break;
- case "2015":
- $paperSize = "16K";
- break;
- case "2016":
- $paperSize = "A3";
- break;
- case "2017":
- $paperSize = "A4";
- break;
- case "2018":
- $paperSize = "8K";
- break;
- case "2019":
- $paperSize = "16K";
- break;
- case "1012":
- $paperSize = "A3";
- break;
- case "1013":
- $paperSize = "A4";
- break;
- case "1014":
- $paperSize = "8K";
- break;
- case "1015":
- $paperSize = "16K";
- break;
- case "1016":
- $paperSize = "A3";
- break;
- case "1017":
- $paperSize = "A4";
- break;
- case "1018":
- $paperSize = "8K";
- break;
- case "1019":
- $paperSize = "16K";
- break;
- }
- }
- if(in_array($val["tpl_index"], Yii::app()->params["custom_tpls_ids"])){
- switch($val["tpl_index"]){
- case "16":
- $paperSize = "A3";
- break;
- case "17":
- $paperSize = "A4";
- break;
- case "18":
- $paperSize = "8K";
- break;
- case "19":
- $paperSize = "16K";
- break;
- }
- }
- if($tplData){
- if(!isset($tplData["examDate"]) || !($examDate = strtotime($tplData["examDate"])))
- $examDate = $val["create_time"];
- if($paperSize === null && isset($tplData["paper"]) && $tplData["paper"] == 1)
- $paperSize = "A3";
- }
- if($examDate === null)
- $examDate = $val["create_time"];
- if($paperSize === null)
- $paperSize = "A4";
- $time = time();
- $expireTime = $examDate + (3600 * 24 * 2);
- if($time > $expireTime){
- $rs["rs"][$key]["is_expired"] = true;
- }
- else{
- $rs["rs"][$key]["is_expired"] = false;
- }
- $rs["rs"][$key]["exam_time"] = $examDate;
- $rs["rs"][$key]["paper_size"] = $paperSize;
- }
- return $rs;
- }
- public function getPrintListOfCoach($coachId, $condition = array(), $orderBy = array("add_time desc"), $pageSize = 9){
- $rs = $this->buildEmptyPagingStruct();
- if($coachId){
- $condition = Arr::merge($condition, array("c.semester_id = '{$this->semester["id"]}'"));
- $condition = $this->condition($condition);
- $orderBy = $this->orderBy($orderBy);
- $handle = $this->sConn->createCommand("
- 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
- from class as c
- join class_subject_relation as csr on csr.class_id = c.class_id
- join exam as e on e.class_id = c.class_id
- join class_exam_printer as cep on cep.class_id = c.class_id and cep.exam_id = e.exam_id
- JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id
- join paper as p on p.exam_id = e.exam_id
- {$condition}
- group by class_id, exam_id, type
- {$orderBy}
- ")->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- $examsIds = $this->grouping($rs["rs"], "exam_id", true);
- $examsIds = "'".implode("','", $examsIds)."'";
- $sprs = $this->sConn->createCommand("select * from student_paper_relation where exam_id in({$examsIds}) ")->queryAll();
- $examsSprs = array();
- foreach($sprs as $key => $val){
- if(!isset($examsSprs[$val["exam_id"]]))
- $examsSprs[$val["exam_id"]] = array();
- $examsSprs[$val["exam_id"]][] = $val;
- }
- $examsStudentsCount = array();
- foreach($examsSprs as $examId => $sprs){
- $examsStudentsCount[$examId] = array(
- "is_complete_count" => 0,
- "is_uploaded_count" => 0,
- "wrongbook_pdf_count" => 0,
- "wbisp_pdf_count" => 0,
- "isp_pdf_count" => 0,
- );
- $examsStudentsCount[$examId]["students_count"] = count($sprs);
- foreach($sprs as $k => $v){
- if($v["is_complete"] == 1)
- $examsStudentsCount[$examId]["is_complete_count"]++;
- if($v["is_feedback"] == 1)
- $examsStudentsCount[$examId]["is_uploaded_count"]++;
- if($v["is_wrongbook_pdf"] == 1)
- $examsStudentsCount[$examId]["wrongbook_pdf_count"]++;
- if($v["is_wbisp_pdf"] == 1)
- $examsStudentsCount[$examId]["wbisp_pdf_count"]++;
- if($v["is_isp_pdf"] == 1)
- $examsStudentsCount[$examId]["isp_pdf_count"]++;
- }
- }
- foreach($rs["rs"] as $key => $val){
- if(isset($examsStudentsCount[$val["exam_id"]])){
- $rs["rs"][$key]["students_count"] = $examsStudentsCount[$val["exam_id"]]["students_count"];
- $rs["rs"][$key]["is_complete_count"] = $examsStudentsCount[$val["exam_id"]]["is_complete_count"];
- $rs["rs"][$key]["is_uploaded_count"] = $examsStudentsCount[$val["exam_id"]]["is_uploaded_count"];
- $rs["rs"][$key]["wrongbook_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wrongbook_pdf_count"];
- $rs["rs"][$key]["wbisp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["wbisp_pdf_count"];
- $rs["rs"][$key]["isp_pdf_count"] = $examsStudentsCount[$val["exam_id"]]["isp_pdf_count"];
- }
- else{
- $rs["rs"][$key]["students_count"] = 0;
- $rs["rs"][$key]["is_complete_count"] = 0;
- $rs["rs"][$key]["is_uploaded_count"] = 0;
- $rs["rs"][$key]["wrongbook_pdf_count"] = 0;
- $rs["rs"][$key]["wbisp_pdf_count"] = 0;
- $rs["rs"][$key]["isp_pdf_count"] = 0;
- }
- $tplData = json_decode($val["tpl_data"], true);
- $paperSize = null;
- $examDate = null;
- if(in_array($val["tpl_index"], Yii::app()->params["custom_tpls_ids"])){
- switch($val["tpl_index"]){
- case "12":
- $paperSize = "A3";
- break;
- case "13":
- $paperSize = "A4";
- break;
- case "14":
- $paperSize = "8K";
- break;
- case "15":
- $paperSize = "16K";
- break;
- case "2012":
- $paperSize = "A3";
- break;
- case "2013":
- $paperSize = "A4";
- break;
- case "2014":
- $paperSize = "8K";
- break;
- case "2015":
- $paperSize = "16K";
- break;
- case "2016":
- $paperSize = "A3";
- break;
- case "2017":
- $paperSize = "A4";
- break;
- case "2018":
- $paperSize = "8K";
- break;
- case "2019":
- $paperSize = "16K";
- break;
- case "1012":
- $paperSize = "A3";
- break;
- case "1013":
- $paperSize = "A4";
- break;
- case "1014":
- $paperSize = "8K";
- break;
- case "1015":
- $paperSize = "16K";
- break;
- case "1016":
- $paperSize = "A3";
- break;
- case "1017":
- $paperSize = "A4";
- break;
- case "1018":
- $paperSize = "8K";
- break;
- case "1019":
- $paperSize = "16K";
- break;
- case "3013":
- $paperSize = "A4";
- break;
- case "3017":
- $paperSize = "A4";
- break;
- }
- }
- if($tplData){
- if(!isset($tplData["examDate"]) || !($examDate = strtotime($tplData["examDate"])))
- $examDate = $val["create_time"];
- if($paperSize === null && isset($tplData["paper"]) && $tplData["paper"] == 1)
- $paperSize = "A3";
- }
- if($examDate === null)
- $examDate = $val["create_time"];
- if($paperSize === null)
- $paperSize = "A4";
- $time = time();
- $expireTime = $examDate + (3600 * 24 * 2);
- if($time > $expireTime){
- $rs["rs"][$key]["is_expired"] = true;
- }
- else{
- $rs["rs"][$key]["is_expired"] = false;
- }
- $rs["rs"][$key]["exam_time"] = $examDate;
- $rs["rs"][$key]["paper_size"] = $paperSize;
- }
- }
- return $rs;
- }
- public function getClassesByCoachId($coachId,$grade=''){
- $classes = array();
- if($coachId){
- if(in_array($grade, array("1", "2", "3"))) {
- $classes = $this->sConn->createCommand("select * from `class` where coach_id = '{$coachId}' and grade='{$grade}'")->queryAll();
- } else {
- $classes = $this->sConn->createCommand("select * from `class` where coach_id = '{$coachId}'")->queryAll();
- }
- }
- return $classes;
- }
- public function getClassesIdsByCoachId($coachId){
- $rs = $this->getClassesByCoachId($coachId);
- $ids = $this->grouping($rs, "class_id");
- return $ids;
- }
- /**
- * 获取学期的班级
- * @param $semesterId
- *
- * @return array|\CDbDataReader
- */
- public function getSemesterClasses($semesterId){
- $classes = array();
- if($semesterId){
- $classes = $this->sConn->createCommand("select * from class where semester_id = '{$semesterId}' and is_hide=0")->queryAll();
- }
- return $classes;
- }
- public function getSemesterClassesStudent($semesterId){
- $classes = array();
- if($semesterId){
- $classes = $this->sConn->createCommand("
- select c.*
- from class as c
- left join student_class_relation as scr on scr.class_id = c.class_id
- where c.semester_id = ".$semesterId ." and scr.status = 0 and c.is_hide=0
- group by scr.class_id ")->queryAll();
- }
- return $classes;
- }
- public function getSemesterStudents($semesterId){
- $students = array();
- if($semesterId){
- $students = $this->sConn->createCommand("
- select stu.student_id, stu.realname, scr.class_id, scr.userno, scr.serial_number
- from class as c
- join student_class_relation as scr on scr.class_id = c.class_id and scr.status = 1
- join student_info as stu on stu.student_id = scr.student_id
- where c.semester_id = '{$semesterId}'
- group by stu.student_id
- ")->queryAll();
- }
- return $students;
- }
- public function activateSemesterClassesStudentsRelations($semesterId){
- $rs = false;
- if($semesterId){
- $students = $this->getSemesterStudents($semesterId);
- $classes = $this->getSemesterClasses($semesterId);
- if($students && $classes){
- $studentsIds = $this->grouping($students, "student_id");
- $studentsIds = "'".implode("','", $studentsIds)."'";
- $classesIds = $this->grouping($classes, "class_id");
- $classesIds = "'".implode("','", $classesIds)."'";
- try{
- $trans = $this->sConn->beginTransaction();
- $this->sConn->createCommand("update student_class_relation set status = '1' where student_id in({$studentsIds}) and status = 0")->execute();
- $this->sConn->createCommand("update student_class_relation set status = '0' where student_id in({$studentsIds}) and class_id in({$classesIds}) and status = 1")->execute();
- foreach($students as $student){
- $this->sConn->createCommand("update student_info set class_id = '{$student["class_id"]}' where student_id = '{$student["student_id"]}'")->execute();
- }
- $trans->commit();
- $rs = true;
- }
- catch(Exception $e){
- $trans->rollBack();
- $rs = false;
- }
- }
- }
- return $rs;
- }
- public function getExamPaper($examId){
- $paper = array();
- if($examId){
- $paper = $this->sConn->createCommand("select * from paper where exam_id = '{$examId}'")->queryRow();
- }
- return $paper;
- }
- public function setPrintTransChecked($classId, $examId){
- if($classId && $examId){
- $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();
- $isChecked = current($rs) > 0 ? true : false;
- if($isChecked)
- $rs = true;
- else{
- $rs = $this->sConn->createCommand("update class_exam_printer set is_checked = '1' where class_id = '{$classId}' and exam_id = '{$examId}' and type = '2'")->execute();
- }
- return $rs ? true : false;
- }
- return false;
- }
- public function setStudentIspChecked($planId){
- if($planId){
- $rs = $this->sConn->createCommand("select exists(select * from student_improve_score_plan where plan_id = '{$planId}' and is_checked = 1)")->queryRow();
- $isChecked = current($rs) > 0 ? true : false;
- if($isChecked)
- $rs = true;
- else{
- $rs = $this->sConn->createCommand("update student_improve_score_plan set is_checked = '1' where plan_id = '{$planId}'")->execute();
- }
- return $rs ? true : false;
- }
- return false;
- }
- public function getClassStudentsIspsList($classId, $examId, $orderBy = array("scr.serial_number asc", "stu.realname asc"), $pageSize = 9){
- $isps = $this->buildEmptyPagingStruct();
- /*if($examId && $classId){
- $orderBy = $this->orderBy($orderBy);
- $handle = $this->sConn->createCommand("
- select stu.*, scr.userno, scr.serial_number, sisp.is_checked, sisp.plan_id
- from student_class_relation as scr
- join student_info as stu on stu.student_id = scr.student_id
- join student_improve_score_plan as sisp on sisp.student_id = scr.student_id and sisp.exam_id = '{$examId}'
- where scr.class_id = '{$classId}' and sisp.is_created=1 and scr.status = 0
- {$orderBy}
- ")->query();
- $isps = $this->paging($this->sConn, $handle, $pageSize);
- }*/
- if($examId && $classId){
- $orderBy = $this->orderBy($orderBy);
- $handle = $this->sConn->createCommand("
- select stu.*, scr.userno, scr.serial_number, sisp.is_checked, sisp.plan_id
- from student_class_relation as scr
- join student_info as stu on stu.student_id = scr.student_id
- join student_improve_score_plan as sisp on sisp.student_id = scr.student_id and sisp.exam_id = '{$examId}'
- where scr.class_id = '{$classId}' and sisp.is_created=1
- {$orderBy}
- ")->query();
- $isps = $this->paging($this->sConn, $handle, $pageSize);
- }
- return $isps;
- }
- public function getIspInfo($planId){
- $isp = array();
- if($planId){
- $isp = $this->sConn->createCommand("
- select sisp.*, p.difficulty, p.score, spr.class_id
- from student_improve_score_plan as sisp
- join paper as p on p.paper_id = sisp.paper_id
- join student_paper_relation as spr on spr.student_id = sisp.student_id and spr.paper_id = sisp.paper_id
- where sisp.plan_id = '{$planId}' and spr.is_del=0
- ")->queryRow();
- }
- return $isp;
- }
- //获取题目难度描述
- public function getTopicDifficultyDescription($key){
- $key = (string)$key;
- $description = array(
- "1" => "容易",
- "2" => "中等",
- "3" => "困难",
- );
- return isset($description[$key]) ? $description[$key] : "";
- }
- //从接口获取题目信息
- public function getTopics($topicsIds = array(), $detial = false,$subject=0,$params=array()){
- $topics = array();
- $array = array();
- $cachedTopics = array();
- if($topicsIds){
- foreach($topicsIds as $val){
- if(!$val)
- continue;
- $array[$this->topicField][] = $val;
- }
- if($subject && $subject!=8){
- $array['subjectId']=$subject;
- }
- if($params){
- $array['params']=$params;
- }
- if($array){
- $topics = Curl::post($this->topicUrl, $array);
- $topics = json_decode($topics, true);
- if(isset($topics["status"]))
- {
- // unset($array['subjectId']);
- // unset($array['params']);
- // $topics = Curl::post($this->topicUrl, $array);
- // $topics = json_decode($topics, true);
- // if(isset($topics["status"])) $topics = array();
- $topics = array();
- }
- }
- }
- return $topics;
- }
- public function getTopic($topicId){
- $topic = array();
- if($topicId){
- $rs = $this->getTopics(array($topicId));
- if($rs) $topic = current($rs);
- }
- return $topic;
- }
- public function getTopicsByIspRecords($plan, $topicsRs, $paperTopicsRecords){
- $topics = array();
- if(Arr::isAvailable($plan) && Arr::isAvailable($topicsRs) && Arr::isAvailable($paperTopicsRecords)){
- $topicsIds = array();
- $schoolTopicsIds = array();
- foreach($topicsRs as $topicRs){
- foreach($paperTopicsRecords as $paperTopicRecord){
- $topicsIds[] = $topicRs["topic_id"];
- }
- }
- $schoolTopicsIds = array_unique($schoolTopicsIds);
- $topicsIds = array_unique($topicsIds);
- $schoolTopicsIds = "'".implode("','", $schoolTopicsIds)."'";
- $topics = $this->getTopics($topicsIds);
- }
- return $topics;
- }
- public function getTopicsRecordsFromStudentIsp($planId, $type = "ALL"){
- $rs = array();
- if($planId){
- $condition = array("plan_id = '{$planId}'");
- if($type === "IMPROVE")
- $condition = Arr::merge($condition, array("is_template = 0"));
- $condition = $this->condition($condition);
- $rs = $this->sConn->createCommand("select * from student_improve_score_plan_topics{$condition}")->queryAll();
- }
- return $rs;
- }
- public function getIspTopics($planId){
- $topics = array();
- if($isp = $this->getIspInfo($planId)){
- $topicsRecords = $this->getTopicsRecordsFromStudentIsp($planId);
- $paperTopicsRecords = $this->getPaperTopicsRecords($isp["paper_id"]);
- $topics = $this->getTopicsByIspRecords($isp, $topicsRecords, $paperTopicsRecords);
- foreach($topics as $key => $topic){
- foreach($topicsRecords as $k => $v){
- if($topic["id"] == $v["topic_id"]){
- $topics[$key]["is_source"] = $v["is_template"];
- $topics[$key]["source_id"] = $v["template_id"];
- }
- }
- }
- foreach($topics as $key => $topic){
- foreach($paperTopicsRecords as $k => $topicRecord){
- if($topic["id"] == $topicRecord["topic_id"])
- $topics[$key]["number"] = $topicRecord["no"];
- }
- }
- }
- return $topics;
- }
- public function getIspTopicsIds($planId){
- $ids = array();
- if($rs = $this->getTopicsRecordsFromStudentIsp($planId)){
- $ids = $this->grouping($rs, "topic_id");
- }
- return $ids;
- }
- public function getPaperTopicsRecords($paperId){
- $records = array();
- if($paperId){
- $records = $this->sConn->createCommand("select * from paper_topic_relation where paper_id = '{$paperId}' order by type asc, `order` asc")->queryAll();
- }
- return $records;
- }
- public function getPaperTopics($paperId,$subject=0,$params=array(),$onlySlave=0){
- if(!($ptrs = $this->getPaperTopicsRecords($paperId)))
- return array();
- $schoolTopicsIds = array();
- $topicsIds = array();
- foreach($ptrs as $ptr){
- if($onlySlave==1){
- $topicsIds[] = $ptr["topic_id"];
- }else{
- if(isset($ptr['stem_id']) && $ptr['stem_id']){
- $topicsIds[] = $ptr["stem_id"];
- }else{
- $topicsIds[] = $ptr["topic_id"];
- }
- }
- }
- $topics = $this->getTopics($topicsIds,false,$subject,$params);
- return $topics;
- }
- public function getPaperTopicsIds($paperId){
- if(!($topicsRecords = $this->getPaperTopicsRecords($paperId)))
- return array();
- return $this->grouping($topicsRecords, "topic_id");
- }
- public function composeIspTopics($planId, $topics){
- $sections = array(
- "选择题" => array(
- "type_id" => 1,
- "type_name" => "单选题",
- "wrong_topics" => array(),
- "wrong_topics_count" => 0,
- "correct_topics" => array(),
- "correct_topics_count" => 0,
- "order" => $this->topicTypesOrder["选择题"],
- ),
- "填空题" => array(
- "type_id" => 5,
- "type_name" => "填空题",
- "wrong_topics" => array(),
- "wrong_topics_count" => 0,
- "correct_topics" => array(),
- "correct_topics_count" => 0,
- "order" => $this->topicTypesOrder["填空题"],
- ),
- "解答题" => array(
- "type_id" => 7,
- "type_name" => "简答题",
- "wrong_topics" => array(),
- "wrong_topics_count" => 0,
- "correct_topics" => array(),
- "correct_topics_count" => 0,
- "order" => $this->topicTypesOrder["解答题"],
- ),
- );
- if($topics){
- $topicsOrder = array();
- $topicNum = 1;
- foreach($sections as $key => $val){
- foreach($topics as $k => $topic){
- if($topic["type_id"] == $val["type_id"]){
- if($topic["is_source"]){
- $sections[$key]["wrong_topics"][$topic["id"]] = $topic;
- }
- else{
- $sections[$key]["correct_topics"][$topic["source_id"]][$topic["id"]] = $topic;
- $sections[$key]["correct_topics_count"]++;
- }
- }
- }
- $sections[$key]["wrong_topics_count"] = count($sections[$key]["wrong_topics"]);
- foreach($sections[$key]["wrong_topics"] as $wrongTopicId => $wrongTopic){
- if(!isset($wrongTopic["kps"]))
- $wrongTopic["kps"] = array();
- $kps = $wrongTopic["kps"];
- $kpsNames = $this->grouping($kps, "kp_name");
- $kpsNamesStr = implode("; ", $kpsNames);
- $sections[$key]["wrong_topics"][$wrongTopicId]["kps"] = $kps;
- $sections[$key]["wrong_topics"][$wrongTopicId]["kps_names_str"] = $kpsNamesStr;
- $sections[$key]["wrong_topics"][$wrongTopicId]["methods_ids"] = array();
- $wrongTopicMethodsNames = array();
- if(!empty($wrongTopic["specials"])){
- foreach($wrongTopic["specials"] as $method){
- $wrongTopicMethodsNames[] = $method["method_name"];
- if($method["method_id"])
- $sections[$key]["wrong_topics"][$wrongTopicId]["methods_ids"][] = $method["method_id"];
- }
- }
- $sections[$key]["wrong_topics"][$wrongTopicId]["methods_names_str"] = implode("; ", $wrongTopicMethodsNames);
- unset($wrongTopicMethodsNames);
- if(!empty($sections[$key]["correct_topics"][$wrongTopic["id"]])){
- foreach($sections[$key]["correct_topics"][$wrongTopic["id"]] as $correctTopicId => $correctTopic){
- if(!isset($correctTopic["kps"]))
- $correctTopic["kps"] = array();
- $kps = $correctTopic["kps"];
- $kpsNames = $this->grouping($kps, "kp_name");
- $kpsNamesStr = implode("; ", $kpsNames);
- $sections[$key]["correct_topics"][$wrongTopicId][$correctTopicId]["kps"] = $kps;
- $sections[$key]["correct_topics"][$wrongTopicId][$correctTopicId]["kps_names_str"] = $kpsNamesStr;
- //过滤掉图片float样式
- /*$sections[$key]["correct_topics"][$wrongTopicId][$correctTopicId]["title"] = preg_replace_callback(
- "/float\s*?:\s*?[a-zA-Z]*?\s*?(;|\"|\')/i",
- function($matches){
- return $matches[0] == "\"" || $matches[0] == "'" ? $matches[0] : "";
- },
- $correctTopic["title"]
- );
- //将题干相对路径转换为绝对路径
- $sections[$key]["correct_topics"][$wrongTopicId][$correctTopicId]["title"] = preg_replace(
- "/src\s*?\=\s*?\"\s*?(\/.*)\.((?:gif)|(?:jpg)|(?:png))(.*?)\"/i",
- "src=\"{$this->topicHost}$1.$2$3$4\"",
- $correctTopic["title"]
- );*/
- $topicsOrder[$correctTopicId] = $topicNum;
- $sections[$key]["correct_topics"][$wrongTopicId][$correctTopicId]["methods_ids"] = array();
- $correctTopicMethodsNames = array();
- $sections[$key]["correct_topics"][$wrongTopicId][$correctTopicId]["methods_count"] = 0;
- if(isset($correctTopic["specials"])){
- $sections[$key]["correct_topics"][$wrongTopicId][$correctTopicId]["methods_count"] = count($correctTopic["specials"]);
- foreach($correctTopic["specials"] as $tsm){
- if($tsm["method_id"]){
- $sections[$key]["correct_topics"][$wrongTopicId][$correctTopicId]["methods_ids"][] = $tsm["method_id"];
- $correctTopicMethodsNames[] = $tsm["method_name"];
- }
- }
- }
- $sections[$key]["correct_topics"][$wrongTopicId][$correctTopicId]["methods_names_str"] = implode("; ", $correctTopicMethodsNames);
- unset($correctTopicMethodsNames);
- $topicNum++;
- }
- Arr::sortByField($sections[$key]["correct_topics"][$wrongTopic["id"]],'');
- }
- }
- Arr::sortByField($sections[$key]["wrong_topics"], "number", "ASC");
- if(!$this->ispTopicsOrderSeted($planId))
- $this->setIspTopicsOrder($planId, $topicsOrder);
- }
- Arr::sortByField($sections,'', "ASC", "NATURAL", true);
- }
- return $sections;
- }
- public function ispTopicsOrderSeted($planId){
- if($topics = $this->getTopicsRecordsFromStudentIsp($planId, "IMPROVE")){
- return true;
- }
- return false;
- }
- public function setIspTopicsOrder($planId, $order = array()){
- if($planId && $order){
- try{
- $trans = $this->sConn->beginTransaction();
- foreach($order as $key => $val){
- $this->sConn->createCommand("update student_improve_score_plan_topics set `order` = '{$val}' where plan_id = '{$planId}' and topic_id = '{$key}'")->execute();
- }
- $trans->commit();
- return true;
- }
- catch(Exception $e){
- $trans->rollBack();
- return false;
- }
- }
- return false;
- }
- public function ispTopicExists($topicId, $planId){
- if($topicId && $planId){
- $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();
- $rs = current($rs);
- return $rs ? true : false;
- }
- return false;
- }
- public function getIspTopic($planId, $topicId){
- $topic = array();
- if($planId && $topicId){
- $topic = $this->sConn->createCommand("select * from student_improve_score_plan_topics where topic_id = '{$topicId}' and plan_id = '{$planId}' and is_template = 0")->queryRow();
- }
- return $topic;
- }
- public function replaceIspTopic($planId, $previousTopicId, $newTopicId){
- $code = 1001;
- if($previousTopicId && $newTopicId){
- $code = array();
- if($previousTopicId == $newTopicId)
- $code[] = 2001;
- if(!$this->ispTopicExists($previousTopicId, $planId))
- $code[] = 2002;
- if($this->ispTopicExists($newTopicId, $planId))
- $code[] = 2003;
- if($code)
- return $this->rs($code, __FUNCTION__);
- $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();
- $code = $rs ? 0 : 1002;
- }
- return $this->rs($code, "global");
- }
- public function changeExamStatus($examId, $status){
- if($examId){
- $rs = $this->sConn->createCommand("update exam set status = '{$status}' where exam_id = '{$examId}'")->execute();
- return $rs ? true : false;
- }
- return false;
- }
- public function getStudentByIspId($planId){
- $student = array();
- if($planId){
- $student = $this->sConn->createCommand("
- select stu.*
- from student_improve_score_plan as sisp
- join student_info as stu on stu.student_id = sisp.student_id
- where sisp.plan_id = '{$planId}'
- ")->queryRow();
- }
- return $student;
- }
- public function getStudentIdByIspId($planId){
- $studentId = null;
- if($student = $this->getStudentByIspId($planId)){
- $studentId = $student["student_id"];
- }
- return $studentId;
- }
- public function getClassVacationHomeworkList($classId, $pageSize = 9){
- if(!$classId)
- return $this->buildEmptyPagingStruct();
- $handle = $this->sConn->createCommand("
- select c.class_name, seme.semester_name, cvh.generate_time, c.class_id
- from class_vacation_homework as cvh
- join class as c on c.class_id = cvh.class_id
- join semester as seme on seme.semester_id = cvh.semester_id
- where cvh.class_id = '{$classId}' and cvh.semester_id = '{$this->semester["id"]}'
- order by cvh.generate_time desc
- ")->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- return $rs;
- }
- public function getClassesVacationHomeworkList($pageSize = 9){
- $handle = $this->sConn->createCommand("
- select c.class_name, seme.semester_name, cvh.generate_time, c.class_id
- from class_vacation_homework as cvh
- join class as c on c.class_id = cvh.class_id
- join semester as seme on seme.semester_id = cvh.semester_id
- where cvh.semester_id = '{$this->semester["id"]}'
- order by cvh.generate_time desc
- ")->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- return $rs;
- }
- public function getClassVhStudents($classId,$realname = NULL, $pageSize = 9){
- if(!$classId)
- return $this->buildEmptyPagingStruct();
- $where = '';
- // debug($realname);
- if (!empty($realname)) {
- $where = "cvh.class_id = '{$classId}' and cvh.semester_id = '{$this->semester["id"]}' and stu.realname like '%{$realname}%'";
- } else {
- $where = "cvh.class_id = '{$classId}' and cvh.semester_id = '{$this->semester["id"]}'";
- }
- $handle = $this->sConn->createCommand("
- select c.class_name, c.class_id, stu.realname, cvh.semester_id, vh.is_generated, stu.student_id
- from class_vacation_homework as cvh
- join vacation_homework as vh on vh.class_id = cvh.class_id and vh.semester_id = cvh.semester_id
- join student_info as stu on stu.student_id = vh.student_id
- join class as c on c.class_id = cvh.class_id
- where {$where}
- ")->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- return $rs;
- }
- public function getMaterialChapters($materialId){
- $chapters = array();
- if($materialId){
- if(!($module = Yii::app()->cache->get("material_{$materialId}"))){
- $module = Curl::post($this->moduleUrl, array($this->moduleField => $materialId));
- $module = json_decode($module, true);
- if($module)
- Yii::app()->cache->set("material_{$materialId}", $module, $this->chapterCacheTime);
- }
- if(isset($module["chapters"]) && $module["chapters"]){
- foreach($module["chapters"] as $chapter){
- $chapters[$chapter["chapter_id"]] = $chapter;
- if($chapter["chapter_id"] && !Yii::app()->cache->get("chapter_{$chapter["chapter_id"]}"))
- Yii::app()->cache->set("chapter_{$chapter["chapter_id"]}", $chapter, $this->chapterCacheTime);
- }
- }
- }
- return $chapters;
- }
- public function getSchoolInfo(){
- return $this->conn->createCommand("select * from school where school_id = '{$this->schoolId}'")->queryRow();
- }
- public function getArea($areaId){
- if(!$areaId)
- return array();
- 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();
- }
- public function getSchoolAreaFromSchoolInfo($schoolInfo){
- $schoolArea = array(
- "province_id" => null,
- "province_name" => null,
- "city_id" => null,
- "city_name" => null,
- "district_id" => null,
- "district_name" => null,
- );
- $municipalitiesIds = array(2, 3, 10, 23);
- if(!Arr::isAvailable($schoolInfo, array("province_id", "city_id", "area_id")))
- return $schoolArea;
- if($area = $this->getArea($schoolInfo["province_id"])){
- $schoolArea["province_id"] = $area["area_id"];
- $schoolArea["province_name"] = $area["area_name"];
- }
- if($area = $this->getArea($schoolInfo["city_id"])){
- $schoolArea["city_id"] = $area["area_id"];
- $schoolArea["city_name"] = $area["area_name"];
- }
- if($area = $this->getArea($schoolInfo["area_id"])){
- $schoolArea["district_id"] = $area["area_id"];
- $schoolArea["district_name"] = $area["area_name"];
- }
- if(in_array($schoolArea["province_id"], $municipalitiesIds))
- $schoolArea["city_name"] = $schoolArea["province_name"];
- return $schoolArea;
- }
- public function getCoachIdByClassId($classId){
- if(!$classId)
- return null;
- $rs = $this->sConn->createCommand("select coach_id from `class` where class_id = '{$classId}'")->queryRow();
- return $rs ? current($rs) : null;
- }
- public function getCoachClassRelationByClassId($classId, $type = "ARR"){
- if(!$classId)
- return array();
- $rs = $this->sConn->createCommand("select coach_id, class_id from `class` where class_id = '{$classId}'")->queryRow();
- if($type == "OBJ"){
- $rs = Arr::toObj($rs);
- }
- return $rs;
- }
- public function getCoachClassesRelations($coachId, $type = "ARR"){
- if(!$coachId)
- return array();
- $rs = $this->sConn->createCommand("select coach_id, class_id from class where coach_id = '{$coachId}'")->queryAll();
- if($type == "OBJ"){
- $rs = Arr::toObj($rs);
- }
- return $rs;
- }
- public function getExamClasses($examId){
- if(!$examId)
- return array();
- return $this->sConn->createCommand("
- select c.class_id, c.class_name
- from exam as e
- join class as c on c.class_id = e.class_id
- where e.exam_id = '{$examId}'
- ")->queryAll();
- }
- public function changeExamUploadStatus($examId, $uploadStatus){
- if(!$examId || !$uploadStatus)
- return false;
- return $this->sConn->createCommand()->update("exam", array("upload_status" => $uploadStatus), "exam_id = '{$examId}'");
- }
- public function ExamStatusAndUploadStatus($examId,$status,$upload_status){
- if($examId){
- $rs = $this->sConn->createCommand("select * from `exam` where exam_id = '{$examId}' and status= ".$status." and upload_status = ".$upload_status)->queryRow();
- if($rs)
- {
- return $rs;
- }
- }
- return false;
- }
- public function ExamStatusAndUploadStatusArr($examId,$statusArr,$upload_status){
- if($examId){
- $rs = $this->sConn->createCommand("select * from `exam` where exam_id = '{$examId}' and status in(".implode(',',$statusArr).") and upload_status = ".$upload_status)->queryRow();
- if($rs)
- {
- return $rs;
- }
- }
- return false;
- }
- public function getExamClassesRelations($examId, $type = "ARR"){
- if(!$examId)
- return array();
- $rs = $this->sConn->createCommand("select exam_id, class_id from exam where exam_id = '{$examId}'")->queryAll();
- if($type == "OBJ"){
- $rs = Arr::toObj($rs);
- }
- return $rs;
- }
- public function getExamClassesRelationsFilteredByUploadStatus($examId, $uploadStatus, $type = "ARR"){
- if(!$examId || !$uploadStatus)
- return array();
- $rs = $this->sConn->createCommand("select exam_id, class_id from exam where exam_id = '{$examId}' and upload_status = '{$uploadStatus}'")->queryAll();
- if($type == "OBJ"){
- $rs = Arr::toObj($rs);
- }
- return $rs;
- }
- public function getExamsByExamGroupId($examGroupId, $type = "ARR"){
- if(!$examGroupId)
- return array();
- $rs = $this->sConn->createCommand("select * from exam where exam_group_id = '{$examGroupId}'")->queryAll();
- if($type == "OBJ"){
- $rs = Arr::toObj($rs);
- }
- return $rs;
- }
- public function getExamsIdsByExamGroupId($examGroupId){
- if(!$examGroupId)
- return array();
- $rs = $this->sConn->createCommand("select exam_id from exam where exam_group_id = '{$examGroupId}'")->queryAll();
- return $this->grouping($rs, "exam_id");
- }
- public function getExamGroupIdByExamId($examId){
- if(!($exam = $this->getExam($examId)))
- return null;
- return $exam["exam_group_id"];
- }
- public function getStudentsPaperRs($paperId, $studentsIds, $type = "ARR"){
- if(!$paperId || !is_array($studentsIds) || !$studentsIds)
- return array();
- $studentsIds = "'".implode("','", $studentsIds)."'";
- $orderBy = array("scoring DESC", "right_count ASC", "student_id ASC");
- $orderBy = $this->orderBy($orderBy);
- $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();
- if($type == "OBJ"){
- $rs = Arr::toObj($rs);
- }
- return $rs;
- }
- public function getStudentsPdfsPaths($paperId, $studentsIds, $check = "", $type = "OBJ"){
- if(!$paperId || !is_array($studentsIds) || !$studentsIds)
- return array();
- $studentsIds = "'".implode("','", $studentsIds)."'";
- $condition = array("paper_id = '{$paperId}'", "student_id in({$studentsIds})", "(scoring > 0 or lost_score > 0)");
- if($check == "WB"){
- $condition[] = "is_wrongbook_pdf = 1";
- }
- else if($check == "ISP"){
- $condition[] = "is_isp_pdf = 1";
- }
- else if($check == "WB_ISP"){
- $condition[] = "is_wbisp_pdf = 1";
- }
- $condition[] = "is_del = 0";
- $condition = $this->condition($condition);
- $rs = $this->sConn->createCommand("select wrongbook_pdf_path, isp_pdf_path, wbisp_pdf_path from student_paper_relation{$condition}")->queryAll();
- if($type == "OBJ"){
- $rs = Arr::toObj($rs);
- }
- return $rs;
- }
- public function getThisYearSemesterDictionary($year){
- if(!$year)
- return array();
- return $this->conn->createCommand("select * from semester_refer where code like '{$year}%'")->queryAll();
- }
- public function getThisYearSemesterName($semester_name){
- if(!$semester_name)
- return array();
- return $this->conn->createCommand("select * from semester_refer where `name` = '".$semester_name."'")->queryRow();
- }
- public function classSubjectExists($classId){
- if(!$classId)
- return false;
- $rs = $this->sConn->createCommand("select exists(select * from class_subject_relation where class_id = '{$classId}')")->queryRow();
- $rs = current($rs);
- return $rs ? true : false;
- }
- public function getSemesterNameByCode($code){
- if(!$code)
- return null;
- $rs = $this->conn->createCommand("select `name` from semester_refer where `code` = '{$code}'")->queryRow();
- if(!$rs)
- return null;
- return current($rs);
- }
- public function getPaperWithTopicsDetails($paperId, $type = "JSON"){
- if(!$paperId)
- return array();
- $rs = apiPost(Yii::app()->params['get_api_url'].'/coachio/iointerface/getpaperwithtopicsdetails', 'paperIdStr='.$paperId);
- if($type == "ARR" && $rs){
- $rs = json_decode($rs, true);
- }
- return $rs;
- }
- public function getPaperWithTopicsDetails_v2($paperId, $type = "JSON"){
- if(!$paperId)
- return array();
- $rs = apiPost(Yii::app()->params['get_api_url'].'/coachio/iointerface_v2/getpaperwithtopicsdetails', 'paperIdStr='.$paperId);
- if($type == "ARR" && $rs){
- $rs = json_decode($rs, true);
- }
- return $rs;
- }
- public function getSubjectIdByTopic($topic){
- return isset($topic["subject_id"]) ? $topic["subject_id"] : 0;
- }
- public function getSubjectIdByTplData($tplData){
- return isset($tplData["subjectId"]) ? $tplData["subjectId"] : 0;
- }
- public function checkExamAnswers($examId){
- if(!$examId)
- return false;
- $rs = $this->sConn->createCommand("
- select stu.realname
- from paper as p
- join student_paper_relation as spr on spr.paper_id = p.paper_id
- join student_paper_topic_rs as sptr on sptr.student_id = spr.student_id and sptr.paper_id = spr.paper_id
- join student_info as stu on stu.student_id = spr.student_id
- where p.exam_id = '{$examId}' and spr.is_feedback = 1 and spr.is_del=0 and (sptr.answer = '' and sptr.answer_url = '')
- group by spr.student_id
- ")->queryAll();
- if(!$rs)
- return array();
- $studentsNames = array();
- foreach($rs as $student){
- $studentsNames[] = $student["realname"];
- }
- return $studentsNames;
- }
- // 操作周周练显示状态
- public function oprateExamDisplay($exam_groupId, $flag=0){
- if($exam_groupId){
- $rs = $this->sConn->createCommand("UPDATE `exam` SET `is_display` = '{$flag}' where `exam_group_id` = '{$exam_groupId}'")->execute();
- return $rs ? true : false;
- }
- return false;
- }
- // 操作周周练显示状态
- public function oprateExamExportDisplay($exam_Id, $flag=0){
- if($exam_Id){
- if($this->sConn->createCommand("UPDATE `exam` SET `export_dispaly` = '{$flag}' where `exam_id` = '{$exam_Id}'")->execute())
- {
- return true;
- }
- }
- return false;
- }
- public function ThirdOprateExamDisplay($exam_group_id, $flag=0){
- if($exam_group_id){
- $rs = $this->sConn->createCommand("UPDATE `exam` SET `is_display` = '{$flag}' where `exam_group_id` = '{$exam_group_id}'")->execute();
- return $rs ? true : false;
- }
- return false;
- }
- // 根据年级获取当前学期班级
- public function getSchoolByGrade($grade,$semesterId) {
- return $this->sConn->createCommand("select class_id,class_name from class where grade = '{$grade}' and semester_id='{$semesterId}'")->queryAll();
- }
- /**
- * 刘红伟
- */
- public function getPaperByExamId($exam_id){
- if(!$exam_id)
- return false;
- $rs = $this->sConn->createCommand("select * from paper where `exam_id` = '{$exam_id}'")->queryRow();
- if(!$rs)
- return false;
- return $rs;
- }
- public function getxuekeStatus($semester_id,$is_third = 0)
- {
- $subject_exam_data = array();
- $class_data = ClassModel::model()->findAll('semester_id=:semester_id',array(':semester_id'=>$semester_id));
- $class_array = array();
- if($class_data)
- {
- foreach($class_data as $v)
- {
- $class_array[$v->class_id] = $v->class_id;
- }
- }
- $criteria = new CDbCriteria();
- $criteria->addInCondition('class_id',$class_array);
- $criteria->addCondition('is_new=:is_new');
- $criteria->params[':is_new'] = 0;
- $exam_data = Exam::model()->findAll($criteria);
- unset($criteria);
- $exam_group_id = array();
- if($exam_data)
- {
- foreach($exam_data as $v)
- {
- $exam_group_id[$v->exam_group_id] = $v->exam_group_id;
- $subject_exam_data[$v->exam_group_id][$v->subject_id][$v->exam_id] = $v->exam_id;
- }
- }
- $subject = array();
- $criteria = new CDbCriteria();
- $criteria->addInCondition('exam_group_id',$exam_group_id);
- $criteria->addCondition('is_third=:is_third');
- $criteria->params[':is_third'] = $is_third;
- $exam_group_data = ExamGroup::model()->findAll($criteria);
- if($exam_group_data)
- {
- foreach($exam_group_data as $v)
- {
- if(isset($subject_exam_data[$v->exam_group_id]))
- {
- foreach($subject_exam_data[$v->exam_group_id] as $k=>$s)
- {
- $subject[$k] = $s;
- }
- }
- }
- }
- return $subject;
- }
- public function getStudentProduct($class_ids,$subject_id=3){
- if(!$class_ids) return false;
- $sql = "select student_id,class_id from student_class_relation where class_id in (".implode(',',$class_ids).") and `status` = 0";
- $res = $this->sConn->createCommand($sql)->queryAll();
- $student_rel_class = array();
- if($res){
- foreach ($res as $v){
- if(!isset($student_rel_class[$v['class_id']])){
- $student_rel_class[$v['class_id']] = array();
- }
- $student_rel_class[$v['class_id']][] = $v['student_id'];
- }
- }
- unset($res);
- $rs_is_pdf = array();
- $rs_is_download = array();
- $class_buti=array();
- //查询补题状态
- $sql="select rpc.status,category,rpc.class_id from review_product_class rpc ";
- $sql.=" left join review_paper_product_set rpps on rpps.rprs_id=rpc.rprs_id ";
- $sql.=" where rpps.semester_id = {$this->semester['id']} and rpps.subject_id='{$subject_id}' and rpc.status=5";
- $res = $this->sConn->createCommand($sql)->queryAll();
- if($res){
- foreach ($res as $v){
- $class_buti[(string)$v['class_id']][$v['category']]=1;
- }
- }
- if($student_rel_class){
- $create_num = array();
- foreach ($student_rel_class as $class_id => $student_ids){
- if(!$student_ids){
- continue;
- }
- $__sql = "select student_id,is_download,type,product_type,rpc.status as rpc_status from student_product sp";
- $__sql.=" left join review_product_class rpc on rpc.rpc_id=sp.plan_id";
- $__sql.=" left join review_paper_product_set rpps on rpps.rprs_id=rpc.rprs_id";
- $__sql.= " where sp.semester_id = {$this->semester['id']} and student_id in(".implode(',',$student_ids).") and `type` >0 and rpps.subject_id='{$subject_id}'";
- $sql = $__sql.' and is_pdf_created = 1 ';
- $res = $this->sConn->createCommand($sql)->queryAll();
- if($res){
- foreach ($res as $v){
- if(!isset($create_num[$class_id])){
- $create_num[$class_id] = array();
- }
- if(!isset($create_num[$class_id][$v['product_type']])){
- $create_num[$class_id][$v['product_type']] = 0;
- }
- $create_num[$class_id][$v['product_type']]++;
- $rs_is_pdf[] = array(
- 'class_id' => $class_id,
- 'class_name' => '',
- 'is_download' => $v['is_download'],
- 'type' => $v['type'],
- 'student_id' => $v['student_id'],
- 'student_sum' => $create_num[$class_id][$v['product_type']],
- 'product_type'=>$v['product_type'],
- 'rpc_status'=>$v['rpc_status']
- );
- }
- }
- unset($res);
- $sql = $__sql.' and is_download = 1 ';
- $res = $this->sConn->createCommand($sql)->queryAll();
- if($res){
- $student_sum = count($student_ids);
- foreach ($res as $v){
- $rs_is_download[] = array(
- 'class_id' => $class_id,
- 'class_name' => '',
- 'is_download' => $v['is_download'],
- 'type' => $v['type'],
- 'student_id' => $v['student_id'],
- 'student_sum' => $student_sum,
- 'product_type'=>$v['product_type'],
- );
- }
- }
- unset($res);
- }
- }
- return array($rs_is_pdf,$rs_is_download,$class_buti);
- }
- // public function getStudentProduct($condition = array()){
- // $condition = Arr::merge($condition, array("c.semester_id = '{$this->semester["id"]}'"));
- // $condition = $this->condition($condition);
- // //后面需要优化
- //
- // $rs = $this->sConn->createCommand("
- // select * from (SELECT
- // c.class_name,
- // c.class_id,
- // p.is_download,
- // p.`type`,
- // p.student_id,
- // COUNT(p.student_id) as student_sum
- // FROM
- // class AS c
- // LEFT JOIN student_class_relation cr ON
- // c.class_id = cr.class_id
- // AND cr.`status` = 0
- //
- // LEFT JOIN student_product AS p ON p.student_id = cr.student_id
- // {$condition} and p.semester_id = {$this->semester['id']}
- // GROUP BY c.class_id,p.type ORDER BY c.grade asc,c.class_id asc)as gc WHERE `type` >0")->queryAll();
- //
- //
- // if($rs)
- // {
- // return $rs;
- // }
- // return false;
- // }
- public function getPadSchool($school_ids)
- {
- $school_data = array();
- if($school_ids){
- $school_data = $this->conn->createCommand("
- select s.*,sp.*
- from school_project as sp
- left join school as s on sp.school_id = s.school_id
- WHERE s.school_id in (".implode(',',$school_ids).")
- ")->queryAll();
- }
- return $school_data;
- }
- //根据学校Id读取学生数据
- public function getStudentBySchool($school_id){
- $sql=" select student_id from student where school_id='".$school_id."' and status=1 ";
- $Arr = $this->conn->createCommand($sql)->queryAll();
- return $Arr;
- }
- //读取学生信息扩展字段设置
- public function getStudentExtend(){
- $sql="select * from student_info_extend ";
- $Arr = $this->sConn->createCommand($sql)->queryAll();
- $result=array();
- if($Arr){
- foreach ($Arr as $val){
- $result[$val['field_name']]=array(
- 'field_mean'=>$val['field_mean'],
- 'is_enable'=>$val['is_enable']
- );
- }
- }
- return $result;
- }
- //默认设置扩展
- public function setDefaultStudentExtend(){
- $result=array();
- $insert="insert into student_info_extend(`field_name`,`field_mean`,`is_enable`) values ('field_1','智学网考号',1)";
- $this->sConn->createCommand($insert)->execute();
- $result['field_1']=array(
- 'field_mean'=>'智学网考号',
- 'is_enable'=>1
- );
- return $result;
- }
- //切换学期,保留班级,保留学生
- public function changeSemesterByStudentAndClass($semesterId,$oldSemesterId,$IsRetainClass=false,$IsGraduation=false,$classNewNameArr=array(),$gradeDirector=1){
- if($semesterId && $oldSemesterId){
- $code = array();
- if($this->role !== ROLE_SU){
- if($this->isPreviousSemester($semesterId))
- $code[] = 2001;
- if(!$this->semesterAllowToChange($semesterId)){
- $code[] = 2002;
- }
- }
- if($code)
- return $this->rs($code, __FUNCTION__);
- $class_r_class=array(); //新旧班级对应关系
- $classSql="";
- $classTeacherSql="";
- $classSubjectSql='';
- $classStudentSql='';
- $updateStudentInfoSql=array();
- $updateClassStudentSql='';
- $updateClassProgressSql=array();
- $classTypeArr=array();
- $classifiedValues=array();
- $classifiedSql='';
- $updateTeacherSql=array(); //年级主任同步升班
- $cancelClassSubjectId=array(); //不同步升级年级主任,则删除对应科目
- $classesModel = new ClassModel();
- $classes_old = $this->getSemesterClassesGraduation($oldSemesterId,$IsGraduation); //读取所有原班级
- //判断是否保留班级
- if($IsRetainClass){
- if($classes_old){
- $classValues=array();
- $classTeacherValues=array();
- $classSubjectValues=array();
- foreach($classes_old as $val){
- $classTypeArr[$val['class_id']]=$val['class_type'];
- $checkCreatedClass=$classesModel->find('semester_id=:seid and class_name=:cname',array(':seid'=>$semesterId,':cname'=>$val['class_name']));
- if ($checkCreatedClass)
- {
- $class_r_class[$val['class_id']]=$checkCreatedClass['class_id'];
- continue;
- }else{
- //$classId = getUUID();
- $classId = getUniqueId($this->schoolId);
- if (empty($classId)) {
- $code[]=2003;
- return $this->rs($code, __FUNCTION__);
- }
- $class_r_class[$val['class_id']]=$classId;
- $teacherIds=$this->getTeachersByClassesIds(array($val['class_id']));
- $grade=$val['grade'];
- $className=$val['class_name'];
- if(isset($classNewNameArr[(string)$val['class_id']])){
- $grade=$grade+1;
- $className=$classNewNameArr[(string)$val['class_id']];
- }
- $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']."')";
- // $sql_teacher="select * from teacher_class_relation where class_id = '{$val['class_id']}';";
- // $classTeacher=$this->sConn->createCommand($sql_teacher)->queryAll();
- if($teacherIds){
- foreach($teacherIds as $tid){
- //读取教师岗位
- if($classNewNameArr && $tid['posts']==3){
- if($gradeDirector==1){
- //同步升级
- $updateTeacherSql[]="update teacher set grade='".$grade."' where teacher_id='".$tid['teacher_id']."'";
- $classTeacherValues[]="('".$classId."','".$tid['teacher_id']."','".$semesterId."','".$tid['hxb_ing']."','".$tid['is_bzr']."')";
- }elseif($gradeDirector==2){
- //不同步,取消班级教师关联
- $cancelClassSubjectId[$tid['subjects']]=$tid['subjects'];
- }
- }else{
- $classTeacherValues[]="('".$classId."','".$tid['teacher_id']."','".$semesterId."','".$tid['hxb_ing']."','".$tid['is_bzr']."')";
- }
- }
- }
- //班级科目
- $sql_subject="select * from class_subject_relation where class_id = '{$val['class_id']}';";
- $classSubject=$this->sConn->createCommand($sql_subject)->queryAll();
- if($classSubject){
- foreach ($classSubject as $v){
- if(!$cancelClassSubjectId || !isset($cancelClassSubjectId[$v['subject_id']])){
- $classSubjectValues[]="('".$classId."','".$v['subject_id']."','".$v['material_id']."','".$v['module_ids']."')";
- }
- }
- }
- //更新教学进度
- $updateClassProgressSql[]="update teach_progress_class set class_id = {$classId} where class_id = '{$val['class_id']}'";
- }
- }
- //走班设置
- $classified="select * from classified where semester_id='{$oldSemesterId}'";
- $classifiedData=$this->sConn->createCommand($classified)->queryAll();
- if($classifiedData){
- foreach ($classifiedData as $value){
- $classifiedValues[]="('".$value['grade']."','".$value['subject_id']."','".$value['status']."','".$semesterId."')";
- }
- }
- //组装sql
- if($classValues){
- $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";
- $classSql.=implode(',',$classValues);
- if($classTeacherValues){
- $classTeacherSql="insert into teacher_class_relation(`class_id`,`teacher_id`,`semester_id`,`hxb_ing`,`is_bzr`) values";
- $classTeacherSql.=implode(',',$classTeacherValues);
- }
- if($classSubjectValues){
- $classSubjectSql="insert into class_subject_relation(`class_id`,`subject_id`,`material_id`,`module_ids`) values";
- $classSubjectSql.=implode(',',$classSubjectValues);
- }
- }
- if($classifiedValues){
- $classifiedDel="delete from classified where semester_id='{$semesterId}'";
- $classifiedSql='insert into classified(`grade`,`subject_id`,`status`,`semester_id`) values ';
- $classifiedSql.=implode(',',$classifiedValues);
- }
-
- //学生处理
- $classStudentSql="";
- $classStudentValues=array();
- $classIds=array();
- if($class_r_class){
- foreach ($class_r_class as $key=>$val){
- //查询原班学生
- $classStudent=$this->sConn->createCommand("select student_id,serial_number,userno,class_type from student_class_relation where class_id='".$key."' and status=0 ")->queryAll();
- $studentIds=array();
- if($classStudent){
- $classIds[]=$key;
- $classType=isset($classTypeArr[$key])?$classTypeArr[$key]:$v['class_type'];
- foreach ($classStudent as $v){
- $studentIds[]=$v['student_id'];
- $classStudentValues[]="('".$val."','".$v['student_id']."',0,'".$v['serial_number']."','".$v['userno']."','".time()."',0,'".$classType."')";
- }
- $updateStudentInfoSql[]="update student_info set class_id='".$val."' where student_id in(".implode(',',$studentIds).") ;";
- }
- }
- if($classStudentValues){
- $classStudentSql="insert into student_class_relation(`class_id`,`student_id`,`status`,`serial_number`,`userno`,`update_time`,`operation`,`class_type`) values ";
- $classStudentSql.=implode(',',$classStudentValues);
- }
- }
- if($classIds){
- $updateClassStudentSql="update student_class_relation set status=1,operation=3 where class_id in(".implode(',',$classIds).") and status=0; ";
- }
- }
- }
- //执行
- $trans = $this->sConn->beginTransaction();
- try{
- if($this->semesterExists($semesterId)){
- //切表
- $inciseTables = $this->inciseTables;
- $oldSemester = $this->sConn->createCommand("SELECT semester_id,refer_code FROM `semester` WHERE `semester_id` = '".$oldSemesterId."'")->queryRow();
- $newSemester = $this->sConn->createCommand("SELECT semester_id,refer_code FROM `semester` WHERE `semester_id` = '".$semesterId."'")->queryRow();
- foreach ($inciseTables as $inciseTable) {
- $newTableName = $inciseTable . '_' . $newSemester['refer_code']; //新学期表名
- $oldTableName= $inciseTable . '_' . $oldSemester['refer_code']; //旧学期(当前学期)需要改的名字
- $existTable = $this->sConn->createCommand("SHOW TABLES LIKE '$newTableName';")->queryRow(); //查询新学期表是否存在
- if($existTable){
- //修改当前的表名
- $existOldTable=$this->sConn->createCommand("SHOW TABLES LIKE '$oldTableName';")->queryRow(); //查询当前学期表是否存在
- if($existOldTable){
- //throw new Exception('3001');
- //重复表进行重命名
- $bakTableName=$oldTableName.'_'.date('YmdHis');
- $this->sConn->createCommand("ALTER TABLE ".$oldTableName." RENAME TO ".$bakTableName)->execute();
- }
- $this->sConn->createCommand("ALTER TABLE ".$inciseTable." RENAME TO ".$oldTableName)->execute();
- //修改新学期表名
- $this->sConn->createCommand("ALTER TABLE ".$newTableName." RENAME TO ".$inciseTable)->execute();
- }else{
- //修改当前的表名
- $existOldTable=$this->sConn->createCommand("SHOW TABLES LIKE '$oldTableName';")->queryRow(); //查询当前学期表是否存在
- if($existOldTable){
- //throw new Exception('3001');
- //重复表进行重命名
- $bakTableName=$oldTableName.'_'.date('YmdHis');
- $this->sConn->createCommand("ALTER TABLE ".$oldTableName." RENAME TO ".$bakTableName)->execute();
- }
- $this->sConn->createCommand("ALTER TABLE ".$inciseTable." RENAME TO ".$oldTableName)->execute();
- //创建新学期表
- $this->sConn->createCommand('CREATE TABLE '.$inciseTable.' LIKE '.$oldTableName)->execute();
- }
- }
- if($classSql){
- $this->sConn->createCommand($classSql)->execute();
- if($classTeacherSql){
- $this->sConn->createCommand($classTeacherSql)->execute();
- }
- if($classSubjectSql){
- $this->sConn->createCommand($classSubjectSql)->execute();
- }
- if($updateTeacherSql){
- foreach ($updateTeacherSql as $sql){
- $this->sConn->createCommand($sql)->execute();
- }
- }
- }
- if($classStudentSql){
- $this->sConn->createCommand($classStudentSql)->execute();
- if($updateClassStudentSql){
- $this->sConn->createCommand($updateClassStudentSql)->execute();
- }
- if($updateStudentInfoSql){
- foreach($updateStudentInfoSql as $query){
- $this->sConn->createCommand($query)->execute();
- }
- }
- }
- if(isset($classifiedSql) && $classifiedSql ){
- $this->sConn->createCommand($classifiedDel)->execute();
- $this->sConn->createCommand($classifiedSql)->execute();
- }
- if($updateClassProgressSql){
- foreach($updateClassProgressSql as $query){
- $this->sConn->createCommand($query)->execute();
- }
- }
- //处理毕业班学生
- if($IsGraduation){
- $classGraduation= $this->sConn->createCommand("select class_id from class where semester_id = '{$oldSemesterId}' and (grade=3 or grade=9)")->queryAll();
- if($classGraduation){
- $gClassId=array();
- foreach ($classGraduation as $item){
- $gClassId[]=$item['class_id'];
- }
- $this->sConn->createCommand("update student_class_relation set status=1,operation=3 where class_id in(".implode(',',$gClassId).") and status=0; ")->execute();
- }
- }
- $this->sConn->createCommand("update semester set status = 0 where status = 1")->execute();
- $this->sConn->createCommand("update semester set status = 1 where semester_id = '{$semesterId}'")->execute();
- $trans->commit();
- $rs = true;
- }
- else
- $rs = false;
- }
- catch(Exception $e){
- $trans->rollBack();
- if($e->getMessage()=='3001'){
- $code[] = 3001;
- return $this->rs($code, __FUNCTION__);
- }else{
- debug($e->getMessage());
- $rs = false;
- }
- }
- $code = $rs ? 0 : 1002;
- }
- return $this->rs($code, "global");
- }
- //前一学期待分班学生数量
- public function getWaitStudent(){
- $nowSemester=$this->getCurrSemester();
- $count=0;
- //前一学期
- $sql="select semester_id from semester where end_time< '".$nowSemester['end_time']."' order by end_time desc limit 1";
- $prevSemester=$this->sConn->createCommand($sql)->queryRow();
- $sql_student="select count(*) as count from student_class_relation scr ";
- $sql_student.=" join class c on c.class_id=scr.class_id ";
- $sql_student.=" where c.semester_id='".$prevSemester['semester_id']."' and scr.status=2 ";
- $studentCount=$this->sConn->createCommand($sql_student)->queryRow();
- if($studentCount){
- $count=$studentCount['count'];
- }
- return $count;
- }
- //获取上一学期id
- public function getPrevSemesterId(){
- $nowSemester=$this->getCurrSemester();
- $count=0;
- //前一学期
- $sql="select semester_id from semester where end_time< '".$nowSemester['end_time']."' order by end_time desc limit 1";
- $prevSemester=$this->sConn->createCommand($sql)->queryRow();
- if($prevSemester){
- return $prevSemester['semester_id'];
- }
- return 0;
- }
- //读取上学期班级
- public function getClassesBySemesterId($semesterId){
- $classes = array();
- $condition = array();
- $condition= array("semester_id = '{$semesterId}'");
- $condition = $this->condition($condition);
- $orderBy = $this->orderBy(array("class_id asc", "class_name asc"));
- $classes = $this->sConn->createCommand("select * from class{$condition} group by class_id{$orderBy}")->queryAll();
- return $classes;
- }
- public function getPrevSemesterClassStudentsList($classId, $condition = array(), $pageSize = 9,$where=''){
- $student_ids = array();
- if(empty($where))
- {
- $rs = $this->getPrevSemesterClassRelation($classId, $condition, $pageSize, "ARR");
- }else
- {
- $accounts = $this->conn->createCommand("select * from student where ".$where)->queryAll();
- if($accounts)
- {
- $studentIdOr=array();
- foreach ($accounts as $v){
- $studentIdOr[]=" stu.student_id=" . $v['student_id']." ";
- }
- $condition= array(" (".implode(' OR ',$studentIdOr).") ");
- $rs = $this->getPrevSemesterClassRelation($classId, $condition, $pageSize, "ARR");
- }else
- {
- $rs["rs"] =array();
- $rs['pager'] = (object)array();
- $rs['pager']->rowsCount = 0;
- }
- }
- if($rs["rs"]){
- foreach($rs["rs"] as $key => $val){
- $rs["rs"][$key]["username"] = "";
- $rs["rs"][$key]["status"] = null;
- }
- $studentsIds = $this->grouping($rs["rs"], "student_id");
- $studentsIds = implode("','", $studentsIds);
- $studentsIds = "'{$studentsIds}'";
- if($where)
- {
- $accounts = $this->conn->createCommand("select * from student where ".$where)->queryAll();
- if($accounts){
- $b_student_status = array();
- $b_student_card = array();
- $b_student_username = array();
- $b_school_student_card = array();
- $b_zhixue_student_card = array();
- foreach($accounts as $v)
- {
- $b_student_card[$v['student_id']] = $v['student_card'];
- $b_student_status[$v['student_id']] = $v['status'];
- $b_student_username[$v['student_id']] = $v['username'];
- $b_school_student_card[$v['student_id']] = $v['school_student_card'];
- $b_zhixue_student_card[$v['student_id']] = $v['zhixue_student_card'];
- }
- foreach($rs["rs"] as $key => $val){
- if( isset($b_student_card[$val["student_id"]]) && !empty($b_student_card[$val["student_id"]])){
- $rs["rs"][$key]["username"] = $b_student_username[$val["student_id"]];
- $rs["rs"][$key]["student_card"] = $b_student_card[$val["student_id"]];
- $rs["rs"][$key]["school_student_card"] = $b_school_student_card[$val["student_id"]];
- if(isset($b_zhixue_student_card[$val["student_id"]]))
- {
- $rs["rs"][$key]["zhixue_student_card"] = $b_zhixue_student_card[$val["student_id"]];
- }
- $rs["rs"][$key]["status"] = $b_student_status[$val["student_id"]];
- }else
- {
- unset($rs["rs"][$key]);
- $rs['pager']->rowsCount = 0;
- }
- }
- }else
- {
- foreach($rs["rs"] as $key => $val){
- unset($rs["rs"][$key]);
- }
- $rs['pager']->rowsCount = 0;
- }
- }else
- {
- $accounts = $this->conn->createCommand("select * from student where student_id in ({$studentsIds})")->queryAll();
- if($accounts){
- $b_student_status = array();
- $b_student_card = array();
- $b_student_username = array();
- $b_school_student_card = array();
- $b_zhixue_student_card = array();
- foreach($accounts as $v)
- {
- $b_student_card[$v['student_id']] = $v['student_card'];
- $b_student_status[$v['student_id']] = $v['status'];
- $b_student_username[$v['student_id']] = $v['username'];
- $b_school_student_card[$v['student_id']] = $v['school_student_card'];
- $b_zhixue_student_card[$v['student_id']] = $v['zhixue_student_card'];
- }
- foreach($rs["rs"] as $key => $val){
- if( isset($b_student_card[$val["student_id"]]) && !empty($b_student_card[$val["student_id"]])){
- $rs["rs"][$key]["username"] = $b_student_username[$val["student_id"]];
- $rs["rs"][$key]["student_card"] = $b_student_card[$val["student_id"]];
- $rs["rs"][$key]["school_student_card"] = $b_school_student_card[$val["student_id"]];
- if(isset($b_zhixue_student_card[$val["student_id"]]))
- {
- $rs["rs"][$key]["zhixue_student_card"] = $b_zhixue_student_card[$val["student_id"]];
- }
- $rs["rs"][$key]["status"] = $b_student_status[$val["student_id"]];
- }
- }
- }
- }
- }
- return $rs;
- }
- public function getPrevSemesterClassRelation($classId, $condition = array(), $pageSize = 9, $type = "OBJ"){
- $rs = $this->buildEmptyPagingStruct();
- if($classId){
- if(is_array($classId)){
- $condition = Arr::merge(array("scr.class_id in( ".implode(',',$classId).")", "scr.status = 2"), $condition);
- }else{
- $condition = Arr::merge(array("scr.class_id =".$classId, "scr.status = 2"), $condition);
- }
- $condition = $this->condition($condition);
- $handle = $this->sConn->createCommand("
- select stu.*, scr.userno, scr.serial_number, c.class_name
- from student_class_relation as scr
- join student_info as stu on stu.student_id = scr.student_id
- join class as c on c.class_id = scr.class_id
- {$condition}
- order by serial_number asc
- ")->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- }
- return $rs;
- }
- //读取导入学生模板
- public function getImportStudentTemplate(){
- $sql="select * from import_student_template ";
- $Arr = $this->sConn->createCommand($sql)->queryRow();
- $result=array();
- if($Arr){
- $result=$Arr['tpl_data'];
- }
- return $result;
- }
- //判断班级是否存在
- public function classNameExists($className,$semesterIds,$class_type=1){
- if(!$semesterIds || !$className)
- return false;
- if(is_array($semesterIds)){
- $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();
- }else{
- $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();
- }
- if($rs){
- return $rs['class_id'];
- }
- return false;
- }
- //根据班级,姓名 读取行政班学生数据
- public function getStudentByNameClass($studentName,$semesterIds,$idNumber=false){
- if(!$studentName || !$semesterIds){
- return null;
- }
- $sql="SELECT si.student_id,si.realname,si.class_id,c.semester_id,c.class_name FROM `student_info` si ";
- $sql.="join student_class_relation scr on scr.student_id=si.student_id ";
- $sql.="join class c on c.class_id = scr.class_id ";
- $sql.="where si.realname='{$studentName}' and scr.status=0 and scr.class_type=1";
- if(is_array($semesterIds)){
- $sql.=" and semester_id in(".implode(',',$semesterIds).")";
- }else{
- $sql.=" and semester_id ='{$semesterIds}'";
- }
- if($idNumber){
- $sql.=" and si.id_number='".$idNumber."'";
- }
- $student=$this->sConn->createCommand($sql)->queryAll();
- return $student;
- }
- //核验身份证号是否存在
- public function checkStudentIdNumber($id){
- if(!$id) return false;
- $rs = $this->sConn->createCommand("select exists(select student_id from student_info where id_number = '{$id}')")->queryRow();
- $rs = current($rs);
- return $rs ? true : false;
- }
- //读取匹配成功数据
- public function getNormalStudent($condition,$pageSize){
- $where='';
- if($condition){
- $where=" where ".implode(' and ',$condition);
- }
- $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();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- return $rs;
- }
- public function getSemesterClassesGraduation($semesterId,$Graduation=false)
- {
- $classes = array();
- if ($semesterId) {
- if ($Graduation) {
- $classes = $this->sConn->createCommand("select * from class where semester_id = '{$semesterId}' and grade<>3 and grade<>9 and is_hide=0")->queryAll();
- } else {
- $classes = $this->sConn->createCommand("select * from class where semester_id = '{$semesterId}' and is_hide=0")->queryAll();
- }
- }
- return $classes;
- }
- //根据班级读取分组
- public function getTeamByClass($class_id,$get="team"){
- if(!$class_id){
- return null;
- }
- $sql="select * from class_team where class_id='".$class_id."'";
- $teamData=$this->sConn->createCommand($sql)->queryAll();
- $student_ids=array();
- if($teamData){
- foreach($teamData as $key=>$val){
- $studentSql="select cst.student_id,cst.student_card,cst.real_name from class_student_team cst ";
- $studentSql.="join student_class_relation scr on scr.student_id=cst.student_id and scr.class_id=cst.class_id ";
- $studentSql.="where cst.team_id='".$val['team_id']."' and scr.status=0";
- $student=$this->sConn->createCommand($studentSql)->queryAll();
- if($student){
- foreach($student as $v){
- $student_ids[$v['student_id']]=$val['team_name'];
- }
- $teamData[$key]['student']=$student;
- }else{
- $teamData[$key]['student']=null;
- }
- }
- }
- if($get=='team'){
- return $teamData;
- }elseif($get=='student'){
- return $student_ids;
- }else{
- return null;
- }
- }
- //根据班级读取学生列表
- public function getStudentByClassId($get_id){
- if(!$get_id) return null;
- $condition = array("scr.class_id = '{$get_id}'", "scr.status = 0");
- $condition = $this->condition($condition);
- $get_list = $this->sConn->createCommand("
- select stu.*, scr.userno, scr.serial_number, c.class_name
- from student_class_relation as scr
- join student_info as stu on stu.student_id = scr.student_id
- join class as c on c.class_id = scr.class_id
- {$condition}
- order by serial_number asc
- ")->queryAll();
- $student_ids = array();
- $result=array();
- if($get_list)
- {
- foreach($get_list as $k=> $v)
- {
- $student_ids[$v['student_id']] = $v['student_id'];
- $result[$v['student_id']]=$v;
- }
- if($student_ids){
- $criteria = new CDbCriteria();
- $criteria->addInCondition('student_id',$student_ids);
- $b_student_data = BusinessStudent::model()->findAll($criteria);
- if($b_student_data)
- {
- foreach($b_student_data as $v)
- {
- $result[$v->student_id]['student_card'] = $v->student_card;
- $result[$v->student_id]['school_student_card'] = (string)$v->school_student_card;
- }
- }
- }
- }
- return $result;
- }
- //读取督学卡上传数量
- public function getSuperviseStudentByExamId($examIds){
- if(!$examIds) return 0;
- $data=$this->sConn->createCommand("select count(*) as count from supervise_card where exam_id in(".implode(',',$examIds).")")->queryRow();
- if($data){
- return $data['count'];
- }
- return 0;
- }
- //判断智学网号是否存在
- public function checkZhiXueNumber($id){
- if(!$id) return false;
- $rs = $this->conn->createCommand("select exists(select student_id from student where zhixue_student_card = '{$id}')")->queryRow();
- $rs = current($rs);
- return $rs ? true : false;
- }
- //读取全部学生id
- public function delStudentPaperByExamIds($examIds){
- if(!$examIds || !is_array($examIds)) return false;
- $rs = $this->sConn->createCommand("update student_paper_relation set `is_del`=1 where exam_id in(".implode(',',$examIds).") and is_feedback=0 ")->execute();
- return $rs;
- }
- //删除student_paper_relation 同步删除student_paper_relation_property
- public function delStudentPaperPropertyByExamIds($examIds,$studentIds){
- if(!$examIds || !is_array($examIds)) return false;
- if(!$studentIds || !is_array($studentIds)) return false;
- $trans = $this->sConn->beginTransaction();
- try{
- $this->sConn->createCommand("update student_paper_relation set `is_del`=1 where exam_id in(".implode(',',$examIds).") and is_feedback=0 ")->execute();
- //$this->sConn->createCommand("delete from student_paper_relation_property where exam_id in(".implode(',',$examIds).") and student_id in(".implode(',',$studentIds).") ")->execute();
- $trans->commit();
- $rs = true;
- }
- catch(Exception $e){
- $trans->rollBack();
- $rs = false;
- }
- return $rs;
- }
- //读取全部学生id
- public function getStudentPaperByExamIds($examIds){
- if(!$examIds || !is_array($examIds)) return false;
- $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();
- return $rs;
- }
- //读取一条学期数据,判断是否新学校
- public function getOneSemester(){
- $semester= $this->sConn->createCommand("select semester_id from semester limit 1")->queryRow();
- return $semester;
- }
- //根据学校准考证号读取学生数据
- public function getStudentInfoBySchoolCard($schoolStudentCard,$schoolId,$semesterId){
- $students=$this->conn->createCommand("select student_id from `student` where school_student_card='".$schoolStudentCard."' and school_id='".$schoolId."'")->queryAll();
- $result=array();
- if($students){
- foreach ($students as $key => $val){
- $sql="SELECT si.student_id,si.realname,scr.class_id FROM `student_info` si ";
- $sql.="join student_class_relation scr on scr.student_id=si.student_id ";
- $sql.="join class c on c.class_id = scr.class_id ";
- $sql.="where scr.status=0 and si.student_id='".$val['student_id']."' and c.semester_id='".$semesterId."' ";
- $data=$this->sConn->createCommand($sql)->queryRow();
- if($data){
- $result[]=$data;
- }
- }
- }
- return $result;
- }
- //根据学校准考证号读取学生数据
- public function getStudentIdBySchoolCard($schoolStudentCard,$schoolId){
- $students=$this->conn->createCommand("select student_id from `student` where school_student_card='".$schoolStudentCard."' and school_id='".$schoolId."'")->queryAll();
- return $students;
- }
- //获取教学进度
- public function getTeachProgress($sql = '', $pageSize = 10){
- $handle = $this->sConn->createCommand($sql)->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- if($rs["rs"]){
- }
- return $rs;
- }
- //根据班级id,统计学生数量
- public function getStudentIdByClassId($classId){
- if(!$classId) return 0;
- $result=array();
- $data=$this->sConn->createCommand("select `student_id` from student_class_relation where class_id='".$classId."' and `status`=0 ")->queryAll();
- if($data){
- foreach ($data as $val){
- $result[]=$val['student_id'];
- }
- }
- return $result;
- }
- //统计家长绑定数量
- public function countBindStudentIds($studentIds,$schoolId){
- if(!$studentIds || !is_array($studentIds)) return false;
- if(!$schoolId) return false;
- $sql="select count(parent_id) as count from wx_parent_student where student_id in(".implode(',',$studentIds).") and school_id ='".$schoolId."' ";
- $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;";
- $data=Yii::app()->db251->createCommand($sql)->queryAll();
- return count($data);
- }
- //根据学生id,读取家长信息
- public function getParentByStudentIds($studentIds,$schoolId){
- if(!$studentIds || !is_array($studentIds)) return false;
- if(!$schoolId) return false;
- $result=array();
- $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 ";
- $sql.=" where pt.school_id='".$schoolId."' and pt.student_id in (".implode(',',$studentIds).") order by `type` asc";
- $data=Yii::app()->db251->createCommand($sql)->queryAll();
- if($data){
- foreach ($data as $val){
- $val['mobile']=substr_replace($val['mobile'],'****',3,4);
- $result[$val['student_id']][]=$val;
- }
- }
- return $result;
- }
- //家长端解除绑定
- public function UnbindZl($parentId,$studentId,$schoolId){
- if(!$parentId || !$schoolId || !$studentId) return false;
- $sql="delete from `wx_parent_student` where school_id='".$schoolId."' and parent_id='".$parentId."' and student_id='".$studentId."'";
- if(Yii::app()->db251->createCommand($sql)->execute()){
- return true;
- }
- return false;
- }
- //加载教师
- public function loadTeacher($keyword,$subject){
- $where=array();
- $where[]="status=0 ";
- if($subject){
- $where[]=" subjects='{$subject}'";
- }
- if($keyword){
- $where[]=" teacher_name like '".$keyword."%' ";
- }
- $sql="select teacher_id,teacher_name,subjects,posts from `teacher` where ".implode(' and ',$where);
- $data=$this->sConn->createCommand($sql)->queryAll();
- return $data;
- }
- //获取教师信息
- public function getTeachersByTeacherIds($teachersIds){
- if(!is_array($teachersIds) || !$teachersIds)
- return array();
- $teachersIds = "'".implode("','", $teachersIds)."'";
- return $this->sConn->createCommand("select teacher_name,subjects,status from teacher where teacher_id in({$teachersIds})")->queryAll();
- }
- //读取学校报名数据
- public function getSignUpBySchoolIdTaskId($schoolId,$taskId){
- if(!$schoolId || !$taskId) return null;
- 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();
- }
- //报名
- public function SignUp($data){
- if(!$data || !is_array($data)) return false;
- $sql="insert into united_exam_signup set ";
- $setValue=array();
- foreach ($data as $field => $value){
- $setValue[]="`{$field}` = '".$value."'";
- }
- $sql.=implode(',',$setValue);
- return $this->conn->createCommand($sql)->execute();
- }
- //退出 报名
- public function SignOutBySchoolIdTaskId($schoolId,$taskId){
- if(!$schoolId || !$taskId) return null;
- return $this->conn->createCommand("delete from united_exam_signup where school_id='".$schoolId."' and tk_exam_id='".$taskId."'")->execute();
- }
- //根据考试id,读取联考数据
- public function getUnitedByExamGroupId($exam_group_id){
- if(!$exam_group_id) return false;
- $sql="SELECT uea.paper_template_url,uea.answer_template_url,uea.apply_deadline,uea.branch FROM `united_exam` ue ";
- $sql.=" join united_exam_apply uea on uea.task_exam_id=ue.tk_exam_id";
- $sql.=" where ue.exam_group_id='".$exam_group_id."'";
- return $this->conn->createCommand($sql)->queryRow();
- }
- //查询是否有联考数据
- public function getUnitedList($apply_setting_type){
- $time=time();
- if($apply_setting_type==1){
- $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";
- }else{
- $sql="select task_exam_id,exam_name,grade,branch,create_time,apply_deadline,exam_time from united_exam_apply where apply_deadline>'".$time."' ";
- }
- return $this->conn->createCommand($sql)->queryAll();
- }
- //查询联考
- public function getUnitedByTaskExamId($task_exam_id){
- if(!$task_exam_id) return false;
- $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."'";
- return $this->conn->createCommand($sql)->queryRow();
- }
- //根据联考id,查询是否创建考试
- public function getExamByTaskId($task_exam_id){
- if(!$task_exam_id) return false;
- $sql="select exam_group_id from united_exam where tk_exam_id='".$task_exam_id."' limit 1";
- return $this->conn->createCommand($sql)->queryRow();
- }
- //查询是否有联考数据
- public function getAllUnitedList($apply_setting_type){
- $time=time();
- if($apply_setting_type==1){
- $sql="select task_exam_id,exam_name,grade,branch,create_time,apply_deadline,exam_time from united_exam_apply where apply_setting_type=1";
- }else{
- $sql="select task_exam_id,exam_name,grade,branch,create_time,apply_deadline,exam_time from united_exam_apply ";
- }
- return $this->conn->createCommand($sql)->queryAll();
- }
- //按学生准考证长度判断
- public function getStudentByCardLength($studentIds,$cardLength){
- if(!$studentIds || !is_array($studentIds)) return false;
- if(!is_numeric($cardLength)) return false;
- $sql="select student_id from student where student_id in(".implode(',',$studentIds).") and char_length(school_student_card)<>".$cardLength." limit 1";
- return $this->conn->createCommand($sql)->queryRow();
- }
- public function UUID_SHORT($length = 20)
- {
- $query = $this->sConn->createCommand("SELECT UUID_SHORT() AS UUID_SHORT")->query()->read();
- $result = $query['UUID_SHORT'];
- if ($length AND is_int($length))
- {
- $result = substr($result, ($length * -1));
- }
- return $result;
- }
- public function getZlExamList($condition = array(), $orderBy = array("zl_create_time desc"), $pageSize = 9){
- $condition = Arr::merge($condition, array("c.semester_id = '{$this->semester["id"]}'"));
- $condition = $this->condition($condition);
- $orderBy = $this->orderBy($orderBy);
- $handle = $this->sConn->createCommand("
- select c.class_name,e.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
- from class as c
- join zl_exam as e on e.zl_class_id = c.class_id
- JOIN zl_exam_group eg ON eg.zl_exam_group_id = e.zl_exam_group_id
- {$condition}
- group by e.zl_class_id, e.zl_exam_id
- {$orderBy}
- ")->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- $ZlStudentExamRelation=new ZlStudentExamRelation();
- $ZlStudentExamRs=new ZlStudentExamRs();
- if($rs['rs']){
- foreach($rs['rs'] as $key => $val){
- $allStudent=$ZlStudentExamRelation->getCountStudentByExamGroupId($val['zl_exam_group_id'],$val['zl_exam_id']);
- $allStudentRs=$ZlStudentExamRs->getCountStudentRsByExamGroupId($val['zl_exam_group_id'],$val['zl_exam_id']);
- $rs['rs'][$key]['is_uploaded_count']=$allStudentRs;
- $rs['rs'][$key]['students_count']=$allStudent;
- }
- }
- return $rs;
- }
- public function getEnglishWeek($condition = array(), $orderBy = array("ew.create_time desc"), $pageSize = 10){
- $condition = Arr::merge($condition, array("ew.semester_id = '{$this->semester["id"]}'"));
- $condition = $this->condition($condition);
- $orderBy = $this->orderBy($orderBy);
- $handle = $this->sConn->createCommand("
- 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
- {$condition}
- group by ew.week_id
- {$orderBy}
- ")->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- if($rs['rs']){
- foreach($rs['rs'] as $k=>$v){
- $rs['rs'][$k]['totalCount'] = 0;
- $rs['rs'][$k]['pdfCount'] = 0;
- $rs['rs'][$k]['isDown'] = 0;
- $rs['rs'][$k]['downTime'] = '';
- $week_id = $v['week_id'];
- $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}'";
- $countArr = $this->sConn->createCommand($sql)->queryRow();
- if($countArr){
- $rs['rs'][$k]['totalCount'] = isset($countArr['totalCount'])?$countArr['totalCount']:0;
- $rs['rs'][$k]['pdfCount'] = isset($countArr['pdfCount'])?$countArr['pdfCount']:0;
- }
- $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";
- $isDownArr = $this->sConn->createCommand($sql)->queryRow();
- if($isDownArr){
- $rs['rs'][$k]['isDown'] = 1;
- $rs['rs'][$k]['downTime'] = isset($isDownArr['week_download_time'])?date("Y-m-d H:i",$isDownArr['week_download_time']):'';
- }
- }
- }
- return $rs;
- }
- public function getEnglishMonth($condition = array(), $orderBy = array("em.create_time desc"), $pageSize = 10){
- $condition = Arr::merge($condition, array("em.semester_id = '{$this->semester["id"]}'"));
- $condition = $this->condition($condition);
- $orderBy = $this->orderBy($orderBy);
- $handle = $this->sConn->createCommand("
- select em.month_id,em.`name`,c.class_name from english_month em join class c on em.class_id = c.class_id
- {$condition}
- group by em.month_id
- {$orderBy}
- ")->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- if($rs['rs']){
- foreach($rs['rs'] as $k=>$v){
- $rs['rs'][$k]['totalCount'] = 0;
- $rs['rs'][$k]['pdfCount'] = 0;
- $rs['rs'][$k]['isDown'] = 0;
- $rs['rs'][$k]['downTime'] = '';
- $month_id = $v['month_id'];
- $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}'";
- $countArr = $this->sConn->createCommand($sql)->queryRow();
- if($countArr){
- $rs['rs'][$k]['totalCount'] = isset($countArr['totalCount'])?$countArr['totalCount']:0;
- $rs['rs'][$k]['pdfCount'] = isset($countArr['pdfCount'])?$countArr['pdfCount']:0;
- }
- $sql = "select download_time from english_month_student where month_id = '{$month_id}' and is_download = 1 order by download_time desc limit 1";
- $isDownArr = $this->sConn->createCommand($sql)->queryRow();
- if($isDownArr){
- $rs['rs'][$k]['isDown'] = 1;
- $rs['rs'][$k]['downTime'] = isset($isDownArr['download_time'])?date("Y-m-d H:i",$isDownArr['download_time']):'';
- }
- }
- }
- return $rs;
- }
- //导出报告列表
- public function getExportList($condition = array(), $orderBy = array("add_time desc"), $pageSize = 9){
- $condition = Arr::merge($condition, array("e.semester_id = '{$this->semester["id"]}'"));
- $condition = $this->condition($condition);
- $orderBy = $this->orderBy($orderBy);
- $handle = $this->sConn->createCommand("
- 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,
- eg.is_third,c.grade,e.status
- from exam as e
- join class as c on e.class_id=c.class_id
- JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id
- {$condition}
- group by exam_group_id
- {$orderBy}
- ")->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- return $rs;
- }
- //读取班级列表
- public function getExportClassByExamGroupId($examGroupId){
- if(!$examGroupId) return false;
- $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}'";
- return $this->sConn->createCommand($sql)->queryAll();
- }
- //获取试卷大题关联表数据
- public function getPaperLargeTopicsRecords($paperId){
- $records = array();
- if($paperId){
- $records = $this->sConn->createCommand("select * from paper_topic_large where paper_id = '{$paperId}'")->queryAll();
- }
- return $records;
- }
- //读取走班设置
- public function getClassShift($semester,$subjectId=0){
- if(!$semester) return null;
- if($subjectId){
- $sql="select grade,subject_id,status from classified where semester_id='{$semester}' and subject_id='{$subjectId}'";
- }else{
- $sql="select grade,subject_id,status from classified where semester_id='{$semester}'";
- }
- return $this->sConn->createCommand($sql)->queryAll();
- }
- //查询走班设置
- public function getClassifiedBySubject($grade,$subject,$semester){
- if(!$semester || !$grade || !$subject) return null;
- $sql="select grade,subject_id,status from classified where semester_id='{$semester}' and grade='{$grade}' and subject_id='{$subject}'";
- return $this->sConn->createCommand($sql)->queryRow();
- }
- //添加走班记录
- public function insertClassified($data){
- if(!$data || !is_array($data)) return false;
- $sql="insert into classified(`grade`,`subject_id`,`status`,`semester_id`) values ";
- $values=array();
- foreach ($data as $val){
- $values[]="('".$val['grade']."','".$val['subject_id']."','".$val['status']."','".$val['semester_id']."')";
- }
- $sql.=implode(',',$values);
- return $this->sConn->createCommand($sql)->execute();
- }
- //更新记录状态
- public function updateClassifiedBySubject($grade,$subject,$semester,$type){
- if(!$semester || !$grade || !$subject || !$type) return false;
- if($type=='enable'){
- $sql="update classified set status=1 where semester_id='{$semester}' and grade='{$grade}' and subject_id='{$subject}'";
- }elseif($type=='disable'){
- $sql="update classified set status=0 where semester_id='{$semester}' and grade='{$grade}' and subject_id='{$subject}'";
- }else{
- return false;
- }
- return $this->sConn->createCommand($sql)->execute();
- }
- //根据年级查询学科
- public function getSubjectByGrade($grade=0,$subjectId=0,$semester){
- if(!$semester) return null;
- if($grade){
- if($subjectId){
- $sql="select subject_id from classified where grade='{$grade}' and semester_id='{$semester}' and status=1 and subject_id='".$subjectId."'";
- }else{
- $sql="select subject_id from classified where grade='{$grade}' and semester_id='{$semester}' and status=1";
- }
- }else{
- if($subjectId){
- $sql="select subject_id from classified where semester_id='{$semester}' and status=1 and subject_id='".$subjectId."'";
- }else{
- $sql="select subject_id from classified where semester_id='{$semester}' and status=1 ";
- }
- }
- return $this->sConn->createCommand($sql)->queryAll();
- }
- public function DelClassSubject($classId){
- if(!$classId)
- return false;
- return $this->sConn->createCommand("delete from class_subject_relation where class_id = '{$classId}'")->execute();
- }
- //读取班级科目
- public function getSubjectByClass($classId,$type='Name'){
- if(!$classId) return null;
- $sql="select subject_id from class_subject_relation where class_id='{$classId}' ";
- $data = $this->sConn->createCommand($sql)->queryAll();
- $result=array();
- if($data){
- foreach ($data as $val){
- if($val['subject_id']){
- if($type=='Name'){
- $result[$val['subject_id']]=Yii::app()->params['subjectId'][$val['subject_id']];
- }else{
- $result[]=$val['subject_id'];
- }
- }
- }
- }
- return $result;
- }
- //获取已走班学生
- public function getStudentBySubjects($subjects,$grade,$semester){
- if(!$subjects || !$semester || !$grade) return null;
- $studentIds=array();
- $classSql="SELECT c.class_id,c.class_name FROM `class` c ";
- $classSql.=" left join class_subject_relation csr on csr.class_id= c.class_id ";
- $classSql.=" where c.class_type=2 and csr.subject_id in(".implode(',',$subjects).") and semester_id='".$semester."' and grade='{$grade}'";
- $classData=$this->sConn->createCommand($classSql)->queryAll();
- $classIds=array();
- if($classData){
- foreach ($classData as $v){
- $classIds[$v['class_id']]=$v['class_id'];
- }
- $sql="select student_id from student_class_relation where class_id in(".implode(',',$classIds).") and status=0";
- $studentData=$this->sConn->createCommand($sql)->queryAll();
- if($studentData){
- foreach ($studentData as $val){
- $studentIds[]=(string)$val['student_id'];
- }
- }
- }
- return $studentIds;
- }
- //根据姓名,查询未走班学生
- public function getClassifiedStudentByName($realName,$subjects,$grade,$semester){
- if(!$subjects || !$semester || !$grade || !$realName) return null;
- $result=array();
- $studentData=$this->sConn->createCommand("select student_id,realname from student_info where realname like '%".$realName."%'")->queryAll();
- if($studentData){
- foreach ($studentData as $val){
- //查询班级
- $classData=$this->sConn->createCommand("select class_id,class_type from student_class_relation where student_id ='".$val['student_id']."' and status=0 ")->queryAll();
- if($classData){
- $flag=true;
- foreach ($classData as $v){
- $classInfo= $this->getClassInfo($v['class_id']);
- if(strcmp($semester,$classInfo['semester_id'])!=0){
- $flag=false;
- break;
- }
- if($grade!=$classInfo['grade']){
- $flag=false;
- break;
- }
- if($v['class_type']==2){
- $classSubjects=$this->getSubjectByClass($v['class_id']);
- foreach ($classSubjects as $subjectId =>$subjectName){
- if(in_array($subjectId,$subjects)){
- $flag=false;
- break;
- }
- }
- }
- }
- if($flag){
- //查询系统准考证
- $studentInfo=$this->conn->createCommand("select student_card from student where student_id='{$val['student_id']}'")->queryRow();
- if($studentInfo){
- $val['realname']=$val['realname'].'('.$studentInfo['student_card'].')';
- }
- $result[]=$val;
- }
- }
- }
- }
- return $result;
- }
- //查询指定班级内相似姓名学生
- public function searchStudentByClassIdsStudentName($classIds,$studentName,$excludeStudentIds=array()){
- if(!$classIds || !is_array($classIds) || !$studentName) return null;
- $sql="select si.student_id,si.realname,scr.class_id from student_info si ";
- $sql.=" join student_class_relation scr on scr.student_id=si.student_id ";
- $sql.=" where scr.class_id in(".implode(',',$classIds).") and si.realname like '%".$studentName."%'";
- $result=array();
- $data=$this->sConn->createCommand($sql)->queryAll();
- if($data){
- foreach ($data as $val){
- if($excludeStudentIds && in_array((string)$val['student_id'],$excludeStudentIds,true)){
- continue;
- }
- $studentCard=$this->conn->createCommand("select student_card from student where student_id='".$val['student_id']."'")->queryRow();
- if($studentCard){
- $result[$val['student_id']]=array(
- 'realname'=>$val['realname'].'('.$studentCard['student_card'].')',
- 'class_id'=>$val['class_id'],
- 'student_id'=>$val['student_id']
- );
- }
- }
- }
- return $result;
- }
- //添加走班学生
- public function addClassifiedStudent($studentIds,$classId){
- $subjects=$this->getSubjectByClass($classId); //本班级科目
- $sql="replace into student_class_relation(`class_id`,`serial_number`,`student_id`,`status`,`update_time`,`operation`,`class_type`) values ";
- $values=array();
- $serialNumber=array();
- foreach ($studentIds as $student_id){
- //查询已有走班记录
- $classRelation=$this->sConn->createCommand("select class_id from student_class_relation where student_id='{$student_id}' and status=0 and class_type=2")->queryAll();
- if($classRelation){
- foreach ($classRelation as $class_id){
- $classSubject=$this->getSubjectByClass($class_id,'ID');
- if(array_intersect($classSubject,$subjects)){
- //已经有相关科目的走班记录
- return -1;
- }
- }
- }
- //查询新班级最大序号
- if(!isset($serialNumber[$classId])){
- $newClass=$this->sConn->createCommand("select serial_number from student_class_relation where class_id='{$classId}' order by serial_number desc limit 1")->queryRow();
- if($newClass ){
- $serialNumber[$classId]=intval($newClass['serial_number'])+1;
- }else{
- $serialNumber[$classId]=1;
- }
- }else{
- $serialNumber[$classId]++;
- }
- $values[]="('".$classId."','".$serialNumber[$classId]."','".$student_id."',0,'".time()."',2,2)";
- }
- if($values){
- $sql.=implode(',',$values);
- $rs=$this->sConn->createCommand($sql)->execute();
- }
- return $rs;
- }
- //教学班转班
- public function copyClassified($toClassId,$studentData){
- if(!$toClassId || !$studentData) return false;
- //查询目标班级
- $classSubjects=$this->getSubjectByClass($toClassId,'ARR');
- //取消原所在班级关系
- $updateOldClass=array();
- $insertNewClass=array();
- //查询新班级最大序号
- $serialNumber=1;
- $newClass=$this->sConn->createCommand("select serial_number from student_class_relation where class_id='{$toClassId}' order by serial_number desc limit 1")->queryRow();
- if($newClass){
- $serialNumber=intval($newClass['serial_number'])+1;
- }
- foreach ($studentData as $studentId => $classId){
- $updateOldClass[]="update student_class_relation set status=1,operation=2 where class_id='{$classId}' and student_id='{$studentId}'";
- //查询学生原科目
- $sql="select c.class_id,csr.subject_id,scr.student_id,scr.`status` from class c";
- $sql.=" join class_subject_relation csr on csr.class_id=c.class_id ";
- $sql.="join student_class_relation scr on scr.class_id=c.class_id";
- $sql.=" where scr.`status`=0 and scr.student_id='{$studentId}' and csr.subject_id in(".implode(',',$classSubjects).") and c.class_type=2 ";
- $repeatSubjectData=$this->sConn->createCommand($sql)->queryAll();
- //取消学生原科目与目标班科目冲突关系
- if($repeatSubjectData){
- foreach ($repeatSubjectData as $v){
- $updateOldClass[]="update student_class_relation set status=1,operation=2 where class_id='".$v['class_id']."' and student_id='{$studentId}'";
- }
- }
- //加入新班级
- $insertNewClass[]="('".$toClassId."','".$studentId."',0,'".$serialNumber."',0,'".time()."',2,2)";
- $serialNumber++;
- }
- $trans = $this->sConn->beginTransaction();
- try{
- if($updateOldClass){
- foreach ($updateOldClass as $v){
- $this->sConn->createCommand($v)->execute();
- }
- }
- if($insertNewClass){
- $insertSql="insert into student_class_relation(`class_id`,`student_id`,`status`,`serial_number`,`userno`,`update_time`,`operation`,`class_type`) values ";
- $insertSql.=implode(',',$insertNewClass);
- $this->sConn->createCommand($insertSql)->execute();
- }
- $trans->commit();
- $rs = true;
- }
- catch(Exception $e){
- $trans->rollBack();
- $rs = false;
- }
- return $rs;
- }
- //根据班级,姓名 读取教学班学生数据
- public function getStudentByNameClassified($studentName,$semesterIds){
- if(!$studentName || !$semesterIds){
- return null;
- }
- $sql="SELECT si.student_id,si.realname,si.class_id,c.semester_id,c.class_name,c.grade FROM `student_info` si ";
- $sql.="join student_class_relation scr on scr.student_id=si.student_id ";
- $sql.="join class c on c.class_id = scr.class_id ";
- $sql.="where si.realname='{$studentName}' and scr.status=0 and scr.class_type=2";
- if(is_array($semesterIds)){
- $sql.=" and semester_id in(".implode(',',$semesterIds).")";
- }else{
- $sql.=" and semester_id ='{$semesterIds}'";
- }
- $student=$this->sConn->createCommand($sql)->queryAll();
- return $student;
- }
- //根据科目读取教学班
- public function getClassifiedBySubjectId($grade,$subjectId,$semesterId){
- $sql="select c.class_id,c.class_name from class c ";
- $sql.="join class_subject_relation csr on csr.class_id=c.class_id ";
- $sql.=" where c.grade='".$grade."' and csr.subject_id='".$subjectId."' and c.semester_id='".$semesterId."'";
- return $this->sConn->createCommand($sql)->queryAll();
- }
- public function getClassIdBySubjectId($subjectId,$semesterId=0){
- $sql="select c.class_id,c.class_name from class c ";
- $sql.="join class_subject_relation csr on csr.class_id=c.class_id ";
- $sql.=" where csr.subject_id='".$subjectId."'";
- if($semesterId){
- $sql.=" and c.semester_id='".$semesterId."'";
- }
- $classIds=array();
- $data=$this->sConn->createCommand($sql)->queryAll();
- if($data){
- foreach ($data as $val){
- $classIds[]=$val['class_id'];
- }
- }
- return $classIds;
- }
- //
- public function checkClassifiedSubject($subjectId,$classId){
- if(!$subjectId || !$classId) return false;
- $sql="select exists(select subject_id from class_subject_relation where class_id='{$classId}' and subject_id='{$subjectId}')";
- $rs = $this->sConn->createCommand($sql)->queryRow();
- $rs = current($rs);
- return $rs ? true : false;
- }
- public function getMathWeek($condition = array(), $orderBy = array("mrs.create_time desc"), $pageSize = 10){
- $condition = Arr::merge($condition, array("mrs.semester_id = '{$this->semester["id"]}'"));
- $condition = $this->condition($condition);
- $orderBy = $this->orderBy($orderBy);
- $handle = $this->sConn->createCommand("
- 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
- {$condition}
- group by mrs.mr_id
- {$orderBy}
- ")->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- if($rs['rs']){
- foreach($rs['rs'] as $k=>$v){
- $rs['rs'][$k]['totalCount'] = 0;
- $rs['rs'][$k]['pdfCount'] = 0;
- $rs['rs'][$k]['isDown'] = 0;
- $rs['rs'][$k]['downTime'] = '';
- $mr_id=$v['mr_id'];
- $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}'";
- $countArr = $this->sConn->createCommand($sql)->queryRow();
- if($countArr){
- $rs['rs'][$k]['totalCount'] = isset($countArr['totalCount'])?$countArr['totalCount']:0;
- $rs['rs'][$k]['pdfCount'] = isset($countArr['pdfCount'])?$countArr['pdfCount']:0;
- }
- $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";
- $isDownArr = $this->sConn->createCommand($sql)->queryRow();
- if($isDownArr){
- $rs['rs'][$k]['isDown'] = 1;
- $rs['rs'][$k]['downTime'] = isset($isDownArr['review_download_time'])?date("Y-m-d H:i",$isDownArr['review_download_time']):'';
- }
- }
- }
- return $rs;
- }
- public function getStudentByExamIds($examsIds,$page,$pageSize){
- if(!$examsIds) return null;
- $offset=($page-1)*$pageSize;
- $query=$this->sConn->createCommand("select count(*) as count from student_paper_relation where exam_id in(".implode(',',$examsIds).") and is_feedback=0 ")->queryRow();
- $total=$query['count'];
- $pages=ceil($total/$pageSize);
- $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();
- $data['pageTotal']=$pages;
- $data['page']=$page;
- $data['list']=$sprs;
- $data['pageSize']=$pageSize;
- return $data;
- }
- public function getAllStudentByExamIds($examsIds){
- if(!$examsIds) return null;
- $sprs = $this->sConn->createCommand("select student_id,student_card from student_paper_relation where exam_id in(".implode(',',$examsIds).") and is_feedback=0 ")->queryAll();
- if($sprs){
- foreach($sprs as $key =>$val){
- $StudentInfo=$this->sConn->createCommand("select realname from `student_info` where student_id='".$val['student_id']."' ")->queryRow();
- if($StudentInfo){
- $sprs[$key]['realname']=$StudentInfo['realname'];
- }
- }
- }
- return $sprs;
- }
- //读取在线答题卡
- public function getAnswerSheetOnline($examGroupId){
- if(!$examGroupId || !is_numeric($examGroupId)){
- return null;
- }
- $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();
- return $rs;
- }
- /**
- * 英语外刊美文产品列表
- */
- public function getEnglishReading($condition = array(), $orderBy = array("er.create_time desc"), $pageSize = 10){
- $condition = Arr::merge($condition, array("er.semester_id = '{$this->semester["id"]}'"));
- $condition = $this->condition($condition);
- $orderBy = $this->orderBy($orderBy);
- $handle = $this->sConn->createCommand("
- 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
- {$condition}
- group by er.week_id
- {$orderBy}
- ")->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- if($rs['rs']){
- foreach($rs['rs'] as $k=>$v){
- $rs['rs'][$k]['totalCount'] = 0;
- $rs['rs'][$k]['pdfCount'] = 0;
- $rs['rs'][$k]['isDown'] = 0;
- $rs['rs'][$k]['downTime'] = '';
- $rs['rs'][$k]['type_name'] = '';
- $rs['rs'][$k]['recommend_mode_name'] = '';
- $rs['rs'][$k]['product_type_name'] = '';
- if($v['recommend_mode']==1){
- $rs['rs'][$k]['recommend_mode_name']='经典模式';
- }elseif($v['recommend_mode']==2){
- $rs['rs'][$k]['recommend_mode_name']='智能推荐模式';
- }
- if($v['product_type']==1){
- $rs['rs'][$k]['product_type_name']='基础宝';
- }elseif($v['product_type']==2){
- $rs['rs'][$k]['product_type_name']='外刊宝';
- }elseif($v['product_type']==3){
- $rs['rs'][$k]['product_type_name']='热点宝';
- }
- if($v['type'] == 1){
- $rs['rs'][$k]['type_name'] = '(个性外刊)';
- }else if($v['type'] == 2){
- if($v['level'] == 1){
- $rs['rs'][$k]['type_name'] = '(共性外刊-尖子班)';
- }else if($v['level'] == 2){
- $rs['rs'][$k]['type_name'] = '(共性外刊-培优班)';
- }else if($v['level'] == 3){
- $rs['rs'][$k]['type_name'] = '(共性外刊-提高班)';
- }
- }
- $week_id = $v['week_id'];
- $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}'";
- $countArr = $this->sConn->createCommand($sql)->queryRow();
- if($countArr){
- $rs['rs'][$k]['totalCount'] = isset($countArr['totalCount'])?$countArr['totalCount']:0;
- $rs['rs'][$k]['pdfCount'] = isset($countArr['pdfCount'])?$countArr['pdfCount']:0;
- }
- $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";
- $isDownArr = $this->sConn->createCommand($sql)->queryRow();
- if($isDownArr){
- $rs['rs'][$k]['isDown'] = 1;
- $rs['rs'][$k]['downTime'] = isset($isDownArr['week_download_time'])?date("Y-m-d H:i",$isDownArr['week_download_time']):'';
- }
- }
- }
- return $rs;
- }
- /**
- * 假期报告列表
- */
- public function getHolidayReport($condition = array(), $orderBy = array("hrs.create_time desc"), $pageSize = 10){
- $condition = $this->condition($condition);
- $orderBy = $this->orderBy($orderBy);
- $handle = $this->sConn->createCommand("
- 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
- {$condition}
- group by hrs.report_id
- {$orderBy}
- ")->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- if($rs['rs']){
- $rs['is_all_pdf'] = 1;//是否全部生成pdf
- $rs['create_time'] = 0;//创建时间
- $create_time_arr = array();
- $reset_time_arr = array();
- foreach($rs['rs'] as $k=>$v){
- $rs['create_time'] = $v['create_time']?$v['create_time']:0;
- if($v['create_time']){
- $create_time_arr[] = $v['create_time'];
- }
- if($v['reset_time']){
- $reset_time_arr[] = $v['reset_time'];
- }
- $rs['rs'][$k]['totalCount'] = 0;
- $rs['rs'][$k]['pdfCount'] = 0;
- $rs['rs'][$k]['isDown'] = 0;
- $rs['rs'][$k]['downTime'] = '';
- $rs['rs'][$k]['report_name'] = $v['class_name'].$v['semester_name'].'假期总结报告';
- $rs['rs'][$k]['create_time'] = $v['reset_time']?date('Y-m-d',$v['reset_time']):date('Y-m-d',$v['create_time']);
- $report_id = $v['report_id'];
- $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}'";
- $countArr = $this->sConn->createCommand($sql)->queryRow();
- if($countArr){
- $rs['rs'][$k]['totalCount'] = isset($countArr['totalCount'])?$countArr['totalCount']:0;
- $rs['rs'][$k]['pdfCount'] = isset($countArr['pdfCount'])?$countArr['pdfCount']:0;
- }
- if($rs['is_all_pdf']){
- if($rs['rs'][$k]['totalCount'] && $rs['rs'][$k]['pdfCount'] != $rs['rs'][$k]['totalCount']){
- $rs['is_all_pdf'] = 0;
- }else{
- $rs['is_all_pdf'] = 1;
- }
- }
- $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";
- $isDownArr = $this->sConn->createCommand($sql)->queryRow();
- if($isDownArr){
- $rs['rs'][$k]['isDown'] = 1;
- $rs['rs'][$k]['downTime'] = isset($isDownArr['report_download_time'])?date("Y-m-d H:i",$isDownArr['report_download_time']):'';
- }
- }
- if($reset_time_arr){
- $rs['create_time'] = max($reset_time_arr);
- }else{
- if($create_time_arr){
- $rs['create_time'] = max($create_time_arr);
- }
- }
- }
- return $rs;
- }
- /**
- * 根据条件获取班级
- */
- public function getClassesByCondition($condition = array(),$orderBy = array()){
- $classes = array();
- $condition = $this->condition($condition);
- $orderBy = $this->orderBy($orderBy);
- $classes = $this->sConn->createCommand("select * from class{$condition} group by class_id{$orderBy}")->queryAll();
- return $classes;
- }
- /**
- * 批量插入假期报告学生
- */
- public function batchInsetHolidayReport($schoolId,$semesterId,$is_current_semester,$is_qxk_school=0){
- $data = array();
- $data['status'] = 0;
- $data['error'] = '创建失败';
- $new_report_ids = array();
- $time = time();
- // $classIds = $this->getClassesByCondition(array('semester_id='.$semesterId,'class_type=1','is_hide=0'),array());
- $classIds = $this->getClassesByCondition(array('semester_id='.$semesterId,'class_type=1'),array());
- $is_qxk_school = $is_qxk_school?1:0;
- if(!$classIds){
- $data['error'] = '暂无班级';
- return $data;
- }else{
- $class_count = count($classIds);
- $report_ids = getBatchUuid($schoolId,$class_count);
- if($report_ids){
- $report_ids_values = array_values($report_ids);
- if(count($classIds) != count($report_ids)){
- $data['error'] = '班级数量不符合';
- return $data;
- }
- $i = 0;
- $classIds = array_values($classIds);
- foreach($classIds as $k=>$v){
- if(isset($report_ids_values[$i]) && $report_ids_values[$i]){
- $new_report_ids[$v["class_id"]] = $report_ids_values[$i];
- }
- $i++;
- }
- }else{
- $data['error'] = 'Id错误';
- return $data;
- }
- }
- if($is_current_semester){
- $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";
- }else{
- $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";
- }
- $student_data = $this->sConn->createCommand($sql)->queryAll();
- if(!$student_data){
- $data['error'] = '暂无学生';
- return $data;
- }
- $trans = $this->sConn->beginTransaction();
- try{
- $report_group_id = getUniqueId($schoolId);
- $insert_values = "";
- foreach($classIds as $class){
- if(isset($new_report_ids[$class["class_id"]]) && $new_report_ids[$class["class_id"]]){
- $report_id = $new_report_ids[$class["class_id"]];
- $insert_values .= "(".$report_group_id.",".$report_id.",".$class["grade"].",".$class["semester_id"].",".$class["class_id"].",".$time.",".$is_qxk_school."),";
- }
- }
- if($insert_values){
- $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).';';
- $this->sConn->createCommand($insert_sql)->execute();
- }
- if($student_data){
- $count = count($student_data);//需要插入的学生总数
- $limit = 3000;
- $page = ceil($count/$limit);
- for ($i=0; $i < $page; $i++) {
- $values = '';
- for ($j=$i*$limit; $j < ($i+1)*$limit; $j++) {
- if($j > $count - 1){
- continue;
- }
- if(isset($new_report_ids[$student_data[$j]['class_id']]) && $new_report_ids[$student_data[$j]['class_id']]){
- //拼接values的值
- $report_id_2 = $new_report_ids[$student_data[$j]['class_id']];
- $values .= '('.$report_id_2.','.$student_data[$j]['class_id'].','.$student_data[$j]['student_id'].'),';
- }
- }
- $values = "insert into holiday_report_student (report_id,class_id,student_id) values".substr($values,0,-1).';';
- $this->sConn->createCommand($values)->execute();
- }
- }
- $trans->commit();
- $data['status'] = 1;
- $data['error'] = '创建成功';
- }
- catch(Exception $e){
- $trans->rollBack();
- $data['status'] = 0;
- $data['error'] = '创建失败';
- }
- return $data;
- }
- /**
- * 重置假期报告
- */
- public function resetReport($reportId,$classId,$is_current_semester,$is_qxk_school=0){
- $time = time();
- $status = false;
- $is_qxk_school = $is_qxk_school?1:0;
- $trans = $this->sConn->beginTransaction();
- try{
- //删除学生数据
- $sql = "delete from holiday_report_student where report_id = '{$reportId}'";
- $this->sConn->createCommand($sql)->execute();
- //学生数据
- if($is_current_semester){
- $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" ;
- }else{
- $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" ;
- }
- $student_data = $this->sConn->createCommand($sql)->queryAll();
- if($student_data){
- $count = count($student_data);//需要插入的学生总数
- $limit = 3000;
- $page = ceil($count/$limit);
- for ($i=0; $i < $page; $i++) {
- $values = '';
- for ($j=$i*$limit; $j < ($i+1)*$limit; $j++) {
- if($j > $count - 1){
- continue;
- }
- $values .= '('.$reportId.','.$student_data[$j]['class_id'].','.$student_data[$j]['student_id'].'),';
- }
- $values = "insert into holiday_report_student (report_id,class_id,student_id) values".substr($values,0,-1).';';
- $this->sConn->createCommand($values)->execute();
- }
- }
- //更新设置表
- $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}'";
- $this->sConn->createCommand($sql)->execute();
- //重置后清除已存在的下载任务
- $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();
- $trans->commit();
- $status = true;
- }
- catch(Exception $e){
- $trans->rollBack();
- }
- return $status;
- }
- /**
- * 批量重置
- */
- public function batchResetReport($semesterId,$is_qxk_school=0){
- $time = time();
- $status = false;
- $report_ids = array();
- $is_qxk_school = $is_qxk_school?1:0;
- $sql = "select report_id from holiday_report_setting where semester_id='$semesterId'";
- $report_data = $this->sConn->createCommand($sql)->queryAll();
- if($report_data){
- foreach($report_data as $k=>$v){
- $report_ids[] = $v['report_id'];
- }
- }
- $trans = $this->sConn->beginTransaction();
- try{
- if($report_ids){
- $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}'";
- $this->sConn->createCommand($sql)->execute();
- $sql = "update holiday_report_student set is_report_html=90 where report_id in (".implode(",",$report_ids).")";
- $this->sConn->createCommand($sql)->execute();
- //重置后清除已存在的下载任务
- $task_sql = "delete from pack_product_task where school_id ={$this->schoolId} and unique_key in (". implode(",", $report_ids).") and product_type=8";
- $this->conn->createCommand($task_sql)->execute();
- }
- $trans->commit();
- $status = true;
- }catch(Exception $e){
- $trans->rollBack();
- }
- return $status;
- }
- /**
- * 假期报告获取班级
- */
- public function getClassesByHolidayReport($condition = array(),$orderBy = array())
- {
- $classes = array();
- $condition = $this->condition($condition);
- $orderBy = $this->orderBy($orderBy);
- $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();
- return $classes;
- }
- //查询考试上传学生数量
- public function getStudentCountByExamGroupId($examGroupId,$hasFeedback=0){
- if(!$examGroupId){
- return null;
- }
- $result=array();
- $result['total']=0; //总数
- $result['is_feedback']=0; // 已扫描
- $result['is_del']=0; //缺考
- $result['abnormal']=0; //异常总量
- $result['complete']=0; //完成数量
- $result['surplus']=0; //剩余量
- $sql="select exam_id from exam where exam_group_id='{$examGroupId}'";
- $data=$this->sConn->createCommand($sql)->queryAll();
- $examIds=array();
- if($data){
- if($hasFeedback){
- foreach ($data as $val){
- $examIds[]=$val['exam_id'];
- }
- $studentSql="select student_id,is_feedback,is_del from student_paper_relation where exam_id in(".implode(',',$examIds).")";
- $studentData=$this->sConn->createCommand($studentSql)->queryAll();
- if($studentData){
- foreach ($studentData as $val){
- if($val['is_feedback']==1){
- $result['is_feedback']++;
- }
- if($val['is_del']==1){
- $result['is_del']++;
- }else{
- $result['total']++;
- }
- }
- }
- }
- $abnormalSql="select status from assist_student_scan_task where exam_group_id = '{$examGroupId}'";
- $abnormalData=$this->conn->createCommand($abnormalSql)->queryAll();
- if($abnormalData){
- $result['abnormal']=count($abnormalData);
- foreach ($abnormalData as $val){
- if($val['status']==0){
- $result['surplus']++;
- }
- if($val['status']==1){
- $result['complete']++;
- }
- }
- }
- }
- return $result;
- }
- //查询待处理数据
- public function getSurplusDataByExamGroupId($examGroupId){
- $abnormalSql="select status from assist_student_scan_task where exam_group_id = '{$examGroupId}' and status=0";
- $abnormalData=$this->conn->createCommand($abnormalSql)->queryAll();
- $result=array();
- if($abnormalData){
- foreach ($abnormalData as $val){
- $result[]=array(
- 'task_id'=>$val['task_id'],
- 'student'=>$val['data']
- );
- }
- }
- return $result;
- }
- /**
- * 好题本
- */
- public function getHtb($condition = array(), $orderBy = array("htb.create_time desc"), $pageSize = 10)
- {
- $condition = Arr::merge($condition, array("htb.semester_id = '{$this->semester["id"]}'"));
- $condition = $this->condition($condition);
- $orderBy = $this->orderBy($orderBy);
- $handle = $this->sConn->createCommand("
- 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
- {$condition}
- group by htb.htb_id
- {$orderBy}
- ")->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- if ($rs['rs']) {
- foreach ($rs['rs'] as $k => $v) {
- $rs['rs'][$k]['totalCount'] = 0;
- $rs['rs'][$k]['pdfCount'] = 0;
- $rs['rs'][$k]['isDown'] = 0;
- $rs['rs'][$k]['downTime'] = '';
- $htb_id = $v['htb_id'];
- $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}'";
- $countArr = $this->sConn->createCommand($sql)->queryRow();
- if ($countArr) {
- $rs['rs'][$k]['totalCount'] = isset($countArr['totalCount']) ? $countArr['totalCount'] : 0;
- $rs['rs'][$k]['pdfCount'] = isset($countArr['pdfCount']) ? $countArr['pdfCount'] : 0;
- }
- $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";
- $isDownArr = $this->sConn->createCommand($sql)->queryRow();
- if ($isDownArr) {
- $rs['rs'][$k]['isDown'] = 1;
- $rs['rs'][$k]['downTime'] = isset($isDownArr['htb_download_time']) ? date("Y-m-d H:i", $isDownArr['htb_download_time']) : '';
- }
- }
- }
- return $rs;
- }
- /**
- * 全学科获取题型(topic表中题型)
- */
- public function getPaperTopicsRecordsByTopic($paperId)
- {
- $records = array();
- if ($paperId) {
- $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";
-
- $records = $this->sConn->createCommand($sql)->queryAll();
- }
- return $records;
- }
- //读取最新版本软件
- public function getNewVersionBySoftwareId($id){
- $sql="select file_url from client_software_version where software_id = '{$id}' order by id desc";
- $data=$this->conn->createCommand($sql)->queryRow();
- if($data){
- return $data['file_url'];
- }else{
- return '';
- }
- }
- //统计考试班级和人数
- public function countExamsAndStudents($examGroupId){
- if(!$examGroupId) return false;
- $result=array();
- $sql="select exam_id from exam where exam_group_id='".$examGroupId."'";
- $exam=$this->sConn->createCommand($sql)->queryAll();
- if($exam){
- $examIds=array();
- foreach ($exam as $val){
- $examIds[]=$val['exam_id'];
- }
- $result['classes']=count($examIds);
- $student=$this->sConn->createCommand("select count(*) as count from student_paper_relation where exam_id in(".implode(',',$examIds).") and is_del=0")->queryRow();
- if($student){
- $result['students']=$student['count'];
- }
- }
- return $result;
- }
- //根据班级名称读取班级
- public function getClassInfoByClassName($className,$semesterIds){
- if(!$semesterIds || !$className)
- return false;
- $rs = $this->sConn->createCommand("select class_id from class where class_name = '{$className}' and semester_id='".$semesterIds."' and is_hide=0 ")->queryRow();
- if($rs){
- return $rs['class_id'];
- }
- return false;
- }
- //查询指定科目班级执教教师
- public function getTeacherByClassSubject($classId,$subjectId){
- if(!$classId || !$subjectId) return false;
- if(in_array($subjectId,array(3,6,51))) $subjectId=3;
- $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();
- return $rs;
- }
- public function getExamName($examId)
- {
- if (!$examId) return null;
- $sql = "select name from exam where exam_id ='{$examId}'";
- $exam = $this->sConn->createCommand($sql)->queryRow();
- if ($exam) {
- return $exam['name'];
- }
- return null;
- }
- //读取未上传考生
- public function getNoUploadStudentByGroupId($examGroupId,$page,$del=-1,$classId=0){
- if(!$examGroupId) return false;
- if(!$page) $page=1;
- $result=array();
- $pageLimit=10;
- if($classId){
- $sql="select exam_id,class_id from exam where exam_group_id='".$examGroupId."' and class_id='{$classId}'";
- }else{
- $sql="select exam_id,class_id from exam where exam_group_id='".$examGroupId."'";
- }
- $exam=$this->sConn->createCommand($sql)->queryAll();
- if($exam) {
- $examIds = array();
- $classIds=array();
- $className=array();
- foreach ($exam as $val) {
- $examIds[] = $val['exam_id'];
- $classIds[]=$val['class_id'];
- }
- $classSql="select class_name,class_id from class where class_id in(".implode(',',$classIds).")";
- $classes=$this->sConn->createCommand($classSql)->queryAll();
- foreach ($classes as $val){
- $className[(string)$val['class_id']]=$val['class_name'];
- }
- $condition=array();
- $condition[]=" is_feedback=0 ";
- $condition[]=" exam_id in(".implode(',',$examIds).") ";
- $offset=($page-1)*$pageLimit;
- if($del==-1) {
- //全部
- }elseif($del==0){
- $condition[]=" is_del=0 ";
- }elseif($del==1){
- $condition[]=" is_del=1 ";
- }
- $countData=$this->sConn->createCommand("select count(*) as count from student_paper_relation where ".implode(' AND ',$condition))->queryRow();
- $result['total']=$countData['count'];
- $result['totalPage']=ceil($result['total']/$pageLimit);
- $result['page']=$page;
- $result['pageLimit']=$pageLimit;
- $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} ";
- $studentData=$this->sConn->createCommand($sql)->queryAll();
- if($studentData){
- foreach ($studentData as $key =>$val){
- if(isset($className[(string)$val['class_id']])){
- $studentData[$key]['class_name']= $className[(string)$val['class_id']];
- }
- $studentInfo=$this->sConn->createCommand("select realname from student_info where student_id ='{$val['student_id']}'")->queryRow();
- if($studentInfo){
- $studentData[$key]['student_name']= $studentInfo['realname'];
- }
- if($val['is_del']==1){
- $studentData[$key]['status']= '缺考';
- }else{
- $studentData[$key]['status']= '未上传';
- }
- }
- }
- $result['list']=$studentData;
- $result['classes']=$className;
- }
- return $result;
- }
- //删除学生
- public function delStudentPaperByStudentAndExamIds($studentsIds,$examId)
- {
- $trans = $this->sConn->beginTransaction();
- try {
- if(is_array($examId)){
- $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();
- $this->sConn->createCommand("DELETE FROM student_answer_card_online where student_id in(".implode(',',$studentsIds).") and exam_id in(".implode(',',$examId).") ")->execute();
- }else{
- $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();
- $this->sConn->createCommand("DELETE FROM student_answer_card_online where student_id in(".implode(',',$studentsIds).") and exam_id ='{$examId}' ")->execute();
- }
- $trans->commit();
- return true;
- } catch (Exception $e) {
- $trans->rollBack();
- return false;
- }
- }
- //下载学生
- public function getExcelStudent($studentIds,$examGroupId)
- {
- $array=array();
- $sql = "select exam_id,class_id from exam where exam_group_id='" . $examGroupId . "'";
- $exam = $this->sConn->createCommand($sql)->queryAll();
- if ($exam) {
- $examIds = array();
- $classIds = array();
- $className = array();
- foreach ($exam as $val) {
- $examIds[] = $val['exam_id'];
- $classIds[] = $val['class_id'];
- }
- $classSql = "select class_name,class_id from class where class_id in(" . implode(',', $classIds) . ")";
- $classes = $this->sConn->createCommand($classSql)->queryAll();
- foreach ($classes as $val) {
- $className[(string)$val['class_id']] = $val['class_name'];
- }
- $condition = array();
- // $condition[] = " student_id in(" . implode(',', $studentIds) . ") ";
- $condition[] = " exam_id in(" . implode(',', $examIds) . ") ";
- $condition[] = " is_feedback=0 ";
- $sql = "select student_id,class_id,student_card,school_student_card,is_del,exam_id from student_paper_relation where " . implode(' AND ', $condition) . " ";
- $studentData = $this->sConn->createCommand($sql)->queryAll();
- if ($studentData) {
- foreach ($studentData as $key => $val) {
- $studentInfo = $this->sConn->createCommand("select realname from student_info where student_id ='{$val['student_id']}'")->queryRow();
- $status='未上传';
- if ($val['is_del'] == 1) {
- $status = '缺考';
- }
- $array[]=array(
- $studentInfo['realname'],
- $val['student_card'],
- $val['school_student_card'],
- $className[(string)$val['class_id']],
- $status
- );
- }
- }
- $title = array("姓名", "系统准考证号", "学校准考证号", "班级", "状态");
- array_unshift($array, $title);
- }
- return $array;
- }
- public function getCyletStudentByExamIds($examIds,$classIds){
- if(!$examIds || !is_array($examIds)) return null;
- $studentIds=array();
- $sql="select exam_group_id from exam where exam_id in(".implode(',',$examIds).")";
- $data = $this->sConn->createCommand($sql)->queryAll();
- foreach ($data as $datum){
- $examGroupId[]=$datum['exam_group_id'];
- $sql="select exam_id from exam where exam_group_id in(".implode(',',$examGroupId).") and class_id in(".implode(',',$classIds).")";
- $studentExam=$this->sConn->createCommand($sql)->queryAll();
- $studentExamIds=array();
- foreach ($studentExam as $val){
- $studentExamIds[]=$val['exam_id'];
- }
- if($studentExamIds){
- $sql="select student_id from student_paper_relation where exam_id in(".implode(',',$studentExamIds).") and is_del=0";
- $studentRs=$this->sConn->createCommand($sql)->queryAll();
- if($studentRs){
- foreach ($studentRs as $val){
- $studentIds[(string)$val['student_id']]=$val['student_id'];
- }
- }
- }
- }
- return array_values($studentIds);
- }
- //删除学生
- public function delStudentPaperByExamGroupId($examId)
- {
- $trans = $this->sConn->beginTransaction();
- try {
- if(is_array($examId)){
- $this->sConn->createCommand("update student_paper_relation set is_del=1 where exam_id in(".implode(',',$examId).") and is_feedback=0")->execute();
- $this->sConn->createCommand("DELETE FROM student_answer_card_online where exam_id in(".implode(',',$examId).") ")->execute();
- }else{
- $this->sConn->createCommand("update student_paper_relation set is_del=1 where exam_id ='{$examId}' and is_feedback=0")->execute();
- $this->sConn->createCommand("DELETE FROM student_answer_card_online where exam_id ='{$examId}' ")->execute();
- }
- $trans->commit();
- return true;
- } catch (Exception $e) {
- $trans->rollBack();
- return false;
- }
- }
- //读取未上传考生
- public function getStudentPaperByExamGroupId($examId)
- {
- if (is_array($examId)) {
- $rs = $this->sConn->createCommand("select student_id from student_paper_relation where exam_id in(" . implode(',', $examId) . ") and is_feedback=0")->queryAll();
- } else {
- $rs = $this->sConn->createCommand("select student_id from student_paper_relation where exam_id ='{$examId}' and is_feedback=0")->queryAll();
- }
- $result = array();
- if ($rs) {
- foreach ($rs as $val) {
- $result[(string)$val['student_id']] = $val['student_id'];
- }
- }
- return $result;
- }
- //发送标注到教师端
- public function sendLabelToTeacher($examGroupId,$type){
- if(!$examGroupId || !in_array($type,array('send','cancel','resend')) ){
- return false;
- }
- $examData=$this->getExamsIdsByExamGroupId($examGroupId);
- if(!$examData){
- return false;
- }
- $examIds=array();
- foreach ($examData as $val){
- $examIds[]=$val;
- }
- if($type=='send' || $type=='resend'){
- $rs=$this->sConn->createCommand("update paper set is_labelled=2,labelled_type=2,send_labelled_time='".time()."' where exam_id in(".implode(',',$examIds).")")->execute();
- }else{
- $rs=$this->sConn->createCommand("update paper set is_labelled=4,send_labelled_time='".time()."' where exam_id in(".implode(',',$examIds).")")->execute();
- }
- return $rs;
- }
- //更新发送类型
- public function updatePaperLabelledType($examGroupId,$type){
- if(!$examGroupId ){
- return false;
- }
- $examData=$this->getExamsIdsByExamGroupId($examGroupId);
- if(!$examData){
- return false;
- }
- $examIds=array();
- foreach ($examData as $val){
- $examIds[]=$val;
- }
- $rs=$this->sConn->createCommand("update paper set labelled_type='{$type}',send_labelled_time='".time()."',is_labelled=0 where exam_id in(".implode(',',$examIds).")")->execute();
- return $rs;
- }
-
- /**
- * 教师假期报告列表
- */
- public function getTeacherHolidayReport($condition = array(), $orderBy = array("htrs.create_time desc"), $pageSize = 10){
- $condition = $this->condition($condition);
- $orderBy = $this->orderBy($orderBy);
- $handle = $this->sConn->createCommand("
- 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
- {$condition}
- group by htrs.report_id
- {$orderBy}
- ")->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- if($rs['rs']){
- $rs['is_all_pdf'] = 1;//是否全部生成pdf
- $rs['create_time'] = 0;//创建时间
- $create_time_arr = array();
- $reset_time_arr = array();
- foreach($rs['rs'] as $k=>$v){
- $teacher_id = $v['teacher_id'];
- $report_id = $v['report_id'];
- $semester_id = $v['semester_id'];
- //获取教师登陆账号
- $sql = "select phone_number from xb_teacher where teacher_id = '{$teacher_id}'";
- $teacher_data = $this->conn->createCommand($sql)->queryRow();
- if($teacher_data){
- $rs['rs'][$k]['phone_number'] = $teacher_data['phone_number'];
- }else{
- $rs['rs'][$k]['phone_number'] = "";
- }
- //获取生成数量
- $sql = "select count(1) count,report_pdf_time from holiday_report_teacher where report_id = '{$report_id}' and is_report_pdf = 1";
- $pdf_data = $this->sConn->createCommand($sql)->queryRow();
- if($pdf_data){
- $rs['rs'][$k]['pdf_count'] = $pdf_data['count'];
- $rs['rs'][$k]['build_time'] = $pdf_data['report_pdf_time']?date("Y-m-d",$pdf_data['report_pdf_time']):'';
- }else{
- $rs['rs'][$k]['pdf_count'] = 0;
- $rs['rs'][$k]['build_time'] = '';
- }
- //获取执教班级
- $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}'";
- $class_data = $this->sConn->createCommand($sql)->queryAll();
- if($class_data){
- $class_name = "";
- foreach($class_data as $v){
- $class_name .= $v['class_name'].'、';
- }
- // $rs['rs'][$k]['class_name'] = mb_substr($class_name, 0, -1);
- $rs['rs'][$k]['class_name'] = rtrim($class_name, "、");
- }else{
- $rs['rs'][$k]['class_name'] = '';
- }
-
-
-
- }
-
-
- }
- return $rs;
- }
-
- /**
- * 批量插入教师假期报告
- * @type 1-没数据全部插入 2-有教师补数据
- */
- public function batchInsetHolidayTeacherReport($schoolId,$semesterId,$type){
- $data = array();
- $data['status'] = 0;
- $data['error'] = '创建失败';
- $teacher_ids = array();
- $new_report_ids = array();
- $insert_values_1 = "";//sql1
- $insert_values_2 = "";//sql2
- $time = time();
-
- //获取教师执教班级信息
- if($type == 1){
- $sql = "select t.teacher_id,t.teacher_name,tcr.class_id,c.grade from teacher t "
- . "join teacher_class_relation tcr on t.teacher_id = tcr.teacher_id "
- . "join class c on tcr.class_id = c.class_id "
- . "where tcr.semester_id = '{$semesterId}' and t.subjects in (".implode(',',Yii::app()->params['mathSubjectId']).") GROUP BY t.teacher_id,c.grade";
- }else if($type == 2){
- $sql = "select t.teacher_id,t.teacher_name,tcr.class_id,c.grade from teacher t "
- . "join teacher_class_relation tcr on t.teacher_id = tcr.teacher_id "
- . "join class c on tcr.class_id = c.class_id "
- . "where tcr.semester_id = '{$semesterId}' and t.subjects in (".implode(',',Yii::app()->params['mathSubjectId']).") and t.teacher_id not in "
- . "(select teacher_id from holiday_teacher_report_setting where semester_id = '{$semesterId}') "
- . "GROUP BY t.teacher_id,c.grade";
- }
- $teacher_class_data = $this->sConn->createCommand($sql)->queryAll();
- if(!$teacher_class_data){
- $data['error'] = '暂无教师班级信息';
- return $data;
- }else{
- $report_group_id = getUniqueId($schoolId);
- foreach($teacher_class_data as $k=>$v){
- $teacher_ids[] = $v['teacher_id'];
- }
- $teacher_ids = array_unique($teacher_ids);
-
- $teacher_count = count($teacher_ids);
- $report_ids = getBatchUuid($schoolId,$teacher_count);
- if($report_ids){
- $report_ids_values = array_values($report_ids);
-
- if(count($teacher_ids) != count($report_ids)){
- $data['error'] = '教师数量不符合';
- return $data;
- }
- $i = 0;
- $teacher_ids = array_values($teacher_ids);
- foreach($teacher_ids as $k=>$v){
- if(isset($report_ids_values[$i]) && $report_ids_values[$i]){
- $new_report_ids[$v] = $report_ids_values[$i];
- $report_id = $new_report_ids[$v];
- $insert_values_1 .= "(".$report_group_id.",".$report_id.",".$v.",".$semesterId.",".$time."),";
- $i++;
- }
- }
- //组装插入sql语句
- foreach($teacher_class_data as $v){
- if(isset($new_report_ids[$v['teacher_id']]) && $new_report_ids[$v['teacher_id']]){
- $report_id = $new_report_ids[$v['teacher_id']];
- $insert_values_2 .= "(".$report_id.",".$v['teacher_id'].",".$v['grade']."),";
- }
- }
- }
- }
- $trans = $this->sConn->beginTransaction();
- try{
-
- if($insert_values_1){
- $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).';';
- $this->sConn->createCommand($insert_sql)->execute();
- }
- if($insert_values_2){
- $insert_sql = "insert into holiday_report_teacher (report_id,teacher_id,grade) values".substr($insert_values_2,0,-1).';';
- $this->sConn->createCommand($insert_sql)->execute();
- }
- $trans->commit();
- $data['status'] = 1;
- $data['error'] = '创建成功';
- }
- catch(Exception $e){
- $trans->rollBack();
- $data['status'] = 0;
- $data['error'] = '创建失败';
- }
- return $data;
- }
-
- /**
- * 重置教师假期报告(单个)
- */
- public function resetTeacherReport($reportId,$teacherId,$semesterId){
- $time = time();
- $status = false;
- $insert_values = '';
- $trans = $this->sConn->beginTransaction();
- try{
- //删除学生数据
- $sql = "delete from holiday_report_teacher where report_id = '{$reportId}'";
- $this->sConn->createCommand($sql)->execute();
-
- //执教班级数据
- $sql = "select t.teacher_id,t.teacher_name,tcr.class_id,c.grade from teacher t "
- . "join teacher_class_relation tcr on t.teacher_id = tcr.teacher_id "
- . "join class c on tcr.class_id = c.class_id "
- . "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";
- $teacher_class_data = $this->sConn->createCommand($sql)->queryAll();
-
- if($teacher_class_data){
- foreach($teacher_class_data as $k=>$v){
- $insert_values .= "(".$reportId.",".$v['teacher_id'].",".$v['grade']."),";
- }
- if($insert_values){
- $insert_sql = "insert into holiday_report_teacher (report_id,teacher_id,grade) values".substr($insert_values,0,-1).';';
- $this->sConn->createCommand($insert_sql)->execute();
- }
- }
- //更新设置表
- $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}'";
- $this->sConn->createCommand($sql)->execute();
- //重置后清除已存在的下载任务
- // $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();
- $trans->commit();
- $status = true;
- }
- catch(Exception $e){
- $trans->rollBack();
- }
- return $status;
- }
-
- /**
- * 批量重置教师假期报告
- */
- public function batchResetTeacherReport($semesterId)
- {
- $time = time();
- $status = false;
- $report_ids = array();
- $sql = "select report_id from holiday_teacher_report_setting where semester_id='$semesterId'";
- $report_data = $this->sConn->createCommand($sql)->queryAll();
- if ($report_data) {
- foreach ($report_data as $k => $v) {
- $report_ids[] = $v['report_id'];
- }
- }
- $trans = $this->sConn->beginTransaction();
- try {
- if ($report_ids) {
- $sql = "update holiday_teacher_report_setting set is_all_html=90,reset_time={$time},school_group_id=0 where semester_id = '{$semesterId}'";
- $this->sConn->createCommand($sql)->execute();
- $sql = "update holiday_report_teacher set is_report_html=90,is_report_pdf=0 where report_id in (" . implode(",", $report_ids) . ")";
- $this->sConn->createCommand($sql)->execute();
- //重置后清除已存在的下载任务
- // $task_sql = "delete from pack_product_task where school_id ={$this->schoolId} and unique_key in (". implode(",", $report_ids).") and product_type=8";
- // $this->conn->createCommand()->execute($task_sql);
- }
- $trans->commit();
- $status = true;
- } catch (Exception $e) {
- $trans->rollBack();
- }
- return $status;
- }
- //读取全部考生
- public function getAllStudentPaperByExamIds($examIds,$studentIds=array())
- {
- if($studentIds){
- $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();
- }else{
- $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();
- }
- return $rs;
- }
- //读取走班,根据学生id
- public function getAllClassByStudentId($studentIds){
- $sql="select c.class_id,c.class_name,student_id from student_class_relation scr
- join class c on c.class_id=scr.class_id
- where status=0 and c.class_type=2 and student_id in(".implode(',',$studentIds).")";
- $rs = $this->sConn->createCommand($sql)->queryAll();
- $result=array();
- if($rs){
- foreach ($rs as $v){
- $subject=$this->sConn->createCommand("select subject_id from class_subject_relation where class_id='{$v['class_id']}'")->queryAll();
- $subjectList=array();
- if($subject){
- foreach ($subject as $item){
- $subjectList[]=Yii::app()->params['subjectId'][$item['subject_id']];
- }
- }
- $result[$v['student_id']][]=array(
- 'class_name'=>$v['class_name'],
- 'subject'=>$subjectList
- );
- }
- }
- return $result;
- }
- //全学科题库获取题型
- public function getAllSubjectTopicType($subject){
- $topics = array();
- $array = array();
- $array['subjectId']=$subject;
- $url= $this->apiUrl.'/all_subject/topic_type';
- $topics = Curl::post($url, $array);
- $topics=json_decode($topics,true);
- if(isset($topics['status']) && $topics['status']==1 ){
- return $topics['data'];
- }
- return null;
- }
- //全学科题库获取题型
- public function getAllSubjectBasicType(){
- $topics = array();
- $array = array();
- $url= $this->apiUrl.'/all_subject/basic_topic_type';
- $topics = Curl::post($url, $array);
- $topics=json_decode($topics,true);
- if(isset($topics['status']) && $topics['status']==1 ){
- return $topics['data'];
- }
- return null;
- }
- //查询上传答案图片学生
- public function getUpAnswerStudent($paperId,$studentIds=array(),$count=true){
- if(!$paperId ){
- return null;
- }
- if($count){
- if($studentIds){
- $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<>'' ";
- }else{
- $sql="select count(DISTINCT student_id) as count from student_paper_topic_rs where paper_id='{$paperId}' and answer_url<>'' ";
- }
- $rs=$this->sConn->createCommand($sql)->queryRow();
- return $rs['count'];
- }else{
- if($studentIds){
- $sql="select DISTINCT student_id from student_paper_topic_rs where paper_id='{$paperId}' and student_id in(".implode(',',$studentIds).") and answer_url<>'' ";
- }else{
- $sql="select DISTINCT student_id from student_paper_topic_rs where paper_id='{$paperId}' and answer_url<>'' ";
- }
- $rs=$this->sConn->createCommand($sql)->queryALl();
- return $rs;
- }
- }
- //读取在线答题卡
- public function getAnswerSheet($examGroupId){
- if(!$examGroupId || !is_numeric($examGroupId)){
- return null;
- }
- $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 ";
- $sql.=" left join online_card_multiplex ocm on ocm.multiplex_id=tas.multiplex_id ";
- $sql.=" where tas.exam_group_id='{$examGroupId}' ";
- $rs=$this->sConn->createCommand($sql)->queryRow();
- return $rs;
- }
- //更新标注期望完成时间
- public function updateEstimateTime($examGroupId,$tplData)
- {
- if (!$examGroupId || !is_numeric($examGroupId) || !$tplData) {
- return null;
- }
- $rs = $this->sConn->createCommand("update exam set tpl_data='" . $tplData . "' where exam_group_id='{$examGroupId}'")->execute();
- return $rs;
- }
- //保存考试全流程节点时间
- public function saveExamProcess($examGroupId,$actionType,$actionTime,$examId=0,$classId=0){
- if(!$examGroupId || !is_numeric($examGroupId)) return false;
- $model=new SExamProcess();
- $model->exam_group_id=$examGroupId;
- $model->exam_id=$examId;
- $model->class_id=$classId;
- $model->action_type=$actionType;
- $model->action_time=$actionTime;
- if($model->save()){
- return true;
- }
- return false;
- }
- // 批量保存考试全流程节点时间
- public function saveExamProcessBatch($examGroupId,$batchData){
- if(!$examGroupId || !is_numeric($examGroupId)) return false;
- $sql="insert into exam_process(`exam_group_id`,`exam_id`,`class_id`,`action_type`,`action_time`) values ";
- $valueData=array();
- foreach ($batchData as $val){
- if(!in_array($val['action_type'],array(1,2,3,4,5,6,7,8,9,10,11,12))){
- return false;
- }
- if(!isset($val['exam_id']) || !isset($val['class_id']) || !isset($val['action_type']) || !isset($val['action_time'])){
- return false;
- }
- $valueData[]="('{$examGroupId}','{$val['exam_id']}','{$val['class_id']}','{$val['action_type']}','{$val['action_time']}')";
- }
- if($this->sConn->createCommand($sql.implode(',',$valueData))->execute()){
- return true;
- }
- return false;
- }
- //删除指定班级未上传考生
- public function delStudentPaperByExamId($examIds){
- if(!$examIds || !is_array($examIds)) return false;
- $sql="update student_paper_relation set is_del=1 where exam_id in(".implode(',',$examIds).") and is_feedback=0";
- if($this->sConn->createCommand($sql)->execute()){
- return true;
- }
- return false;
- }
- //查询导出考试数据白名单
- public function getExportExamWhiteList($schoolId){
- if(!$schoolId || !is_numeric($schoolId)) return false;
- $sql="select id from school_download_exam_whitelist where school_id='".$schoolId."'";
- $rs= $this->conn->createCommand($sql)->queryRow();
- if($rs){
- return 1;
- }else{
- return 0;
- }
- }
- //读取在线答题卡
- public function getOnlineCardMultiplex($multiplexId){
- if(!$multiplexId){
- return null;
- }
- $sql="select marking_papers from `online_card_multiplex` ";
- $sql.=" where multiplex_id='{$multiplexId}' ";
- $rs=$this->sConn->createCommand($sql)->queryRow();
- return $rs;
- }
- //获取全学科试卷结构
- public function getQxkPaperTopics($topicIds){
- $rs = http('/qxk/topic/list','POST',$this->schoolId,array('topicList'=>array_values($topicIds)),'cgi');
- $rs=json_decode($rs,true);
- if(isset($rs['errCode']) && $rs['errCode']=='00'){
- return $rs['data'];
- }
- return null;
- }
- //读取学校省份
- public function getProvince($pid){
- if(!$pid) return null;
- $sql="select region_name from region where region_id='{$pid}'";
- $data=$this->conn->createCommand($sql)->queryRow();
- if($data){
- return $data['region_name'];
- }
- return null;
- }
- //读取在线答题卡
- public function getOnlineCardMultiplexByGroupId($groupId){
- if(!$groupId){
- return null;
- }
- $sql="select marking_papers,is_download,exam_group_id from `online_card_multiplex` ";
- $sql.=" where exam_group_id='{$groupId}' ";
- $rs=$this->sConn->createCommand($sql)->queryRow();
- return $rs;
- }
- /**
- * 校本纠错本
- */
- public function getCorrect($condition = array(), $orderBy = array("create_time desc"), $pageSize = 10)
- {
- $condition = Arr::merge($condition, array("gps.semester_id = '{$this->semester["id"]}'"));
- $condition = $this->condition($condition);
- $orderBy = $this->orderBy($orderBy);
- $handle = $this->sConn->createCommand("
- 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
- {$condition}
- group by gps.gp_group_id
- {$orderBy}
- ")->query();
- $rs = $this->paging($this->sConn, $handle, $pageSize);
- if ($rs['rs']) {
- foreach ($rs['rs'] as $k => $v) {
- $rs['rs'][$k]['totalClass'] = 0;
- $rs['rs'][$k]['isDown'] = 0;
- $rs['rs'][$k]['isCreate'] = 0;
- $rs['rs'][$k]['isAllCreate'] = 1;
- $rs['rs'][$k]['abnormal']='';
- $rs['rs'][$k]['examGroupIdCount']=0;
- $sql="select gp_id from general_product where gp_group_id='{$v['gp_group_id']}'";
- $classCount=$this->sConn->createCommand($sql)->queryAll();
- $rs['rs'][$k]['totalClass'] = count($classCount);
- $gpIds=array();
- foreach ($classCount as $item){
- $gpIds[]=$item['gp_id'];
- }
- $sql="select student_id from general_product_student where gp_id in(".implode(',',$gpIds).") and is_create_pdf=1 ";
- $isCreate=$this->sConn->createCommand($sql)->queryRow();
- if($isCreate){
- $rs['rs'][$k]['isCreate'] = 1;
- }
- $sql="select student_id from general_product_student where gp_id in(".implode(',',$gpIds).") and is_create_pdf=0";
- $noCreate=$this->sConn->createCommand($sql)->queryRow();
- if($noCreate){
- $rs['rs'][$k]['isAllCreate'] = 0;
- }
- $sql="select distinct gp_id from general_product_student where gp_id in(".implode(',',$gpIds).") and is_download=1";
- $isDownArr = $this->sConn->createCommand($sql)->queryAll();
- $rs['rs'][$k]['isDown'] = count($isDownArr);
- //查询异常
- $setting=json_decode($v['setting'],1);
- if(isset($setting['no_exam_class']) && $setting['no_exam_class']){
- $names=array();
- $classNames=$this->sConn->createCommand("select class_name from class where class_id in(".implode(',',$setting['no_exam_class']).")")->queryAll();
- foreach ($classNames as $cname){
- $names[]=$cname['class_name'];
- }
- $rs['rs'][$k]['abnormal'] = implode(',',$names);
- }
- if(isset($setting['exam_group_ids'])){
- $rs['rs'][$k]['examGroupIdCount']=count($setting['exam_group_ids']);
- }
- }
- }
- return $rs;
- }
- }
|