You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

users_controller.rb 160 kB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
11 years ago
11 years ago
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
10 years ago
​
​
​
​
11 years ago
​
​
​
10 years ago
​
​
​
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
11 years ago
11 years ago
11 years ago
​
11 years ago
​
​
​
11 years ago
​
​
​
11 years ago
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
10 years ago
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
10 years ago
​
​
10 years ago
10 years ago
​
10 years ago
​
​
​
10 years ago
10 years ago
​
​
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
10 years ago
10 years ago
​
​
​
​
​
​
​
​
​
​
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
​
11 years ago
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
11 years ago
​
11 years ago
11 years ago
11 years ago
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
11 years ago
​
​
​
​
10 years ago
​
​
​
​
​
​
11 years ago
11 years ago
​
11 years ago
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
​
​
​
11 years ago
11 years ago
11 years ago
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
​
​
11 years ago
11 years ago
11 years ago
11 years ago
​
​
​
​
​
​
​
11 years ago
​
11 years ago
​
​
​
​
​
​
11 years ago
​
11 years ago
11 years ago
11 years ago
11 years ago
​
11 years ago
11 years ago
​
11 years ago
​
​
​
​
11 years ago
11 years ago
​
​
​
​
​
​
10 years ago
​
​
​
​
11 years ago
11 years ago
​
​
​
11 years ago
​
​
​
​
11 years ago
​
​
​
​
​
​
11 years ago
​
​
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
​
​
​
11 years ago
11 years ago
​
11 years ago
​
​
​
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
11 years ago
​
​
​
​
10 years ago
​
​
​
​
11 years ago
​
​
​
​
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
11 years ago
​
11 years ago
​
​
​
11 years ago
​
11 years ago
​
11 years ago
11 years ago
11 years ago
​
​
​
​
11 years ago
​
​
​
11 years ago
​
11 years ago
11 years ago
11 years ago
11 years ago
​
​
​
​
11 years ago
​
​
​
10 years ago
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
​
10 years ago
​
​
​
11 years ago
11 years ago
11 years ago
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
11 years ago
​
​
​
​
​
​
11 years ago
​
​
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
10 years ago
​
​
​
​
11 years ago
11 years ago
​
​
​
10 years ago
​
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
10 years ago
​
​
​
​
​
​
​
​
11 years ago
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
11 years ago
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
10 years ago
​
​
​
​
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
11 years ago
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
10 years ago
​
​
​
​
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
11 years ago
​
​
​
​
​
​
​
​
11 years ago
​
11 years ago
​
11 years ago
11 years ago
​
​
​
​
​
​
​
11 years ago
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
​
10 years ago
​
​
10 years ago
10 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
11 years ago
11 years ago
​
​
11 years ago
11 years ago
​
10 years ago
11 years ago
​
​
​
​
​
​
​
10 years ago
​
​
​
10 years ago
10 years ago
10 years ago
11 years ago
10 years ago
11 years ago
11 years ago
​
​
11 years ago
11 years ago
​
10 years ago
11 years ago
​
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
10 years ago
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
11 years ago
11 years ago
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
11 years ago
​
​
11 years ago
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
10 years ago
​
​
10 years ago
10 years ago
​
10 years ago
​
​
​
​
​
​
​
​
​
​
10 years ago
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
10 years ago
​
​
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
​
​
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490
  1. #encoding: utf-8
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2013 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. class UsersController < ApplicationController
  19. layout :setting_layout
  20. #Added by young
  21. before_filter :auth_login1, :only => [:show, :user_activities, :user_newfeedback]
  22. before_filter :logged_user_by_apptoken, :only => [:show,:user_newfeedback]
  23. menu_item :activity
  24. menu_item :user_information, :only => :info
  25. menu_item :user_course, :only => :user_courses
  26. menu_item :user_homework, :only => :user_homeworks
  27. menu_item :student_homework, :only => :student_homeworks
  28. menu_item :user_project, :only => [:user_projects, :watch_projects]
  29. menu_item :requirement_focus, :only => :watch_contests
  30. menu_item :user_newfeedback, :only => :user_newfeedback
  31. menu_item :user_messages, :only => :user_messages
  32. #
  33. before_filter :can_show_course, :only => [:user_courses,:user_homeworks]
  34. before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :user_courses,
  35. :user_homeworks,:student_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments,
  36. :watch_contests, :info, :watch_projects, :show_score, :topic_score_index, :project_score_index,
  37. :activity_score_index, :influence_score_index, :score_index,:show_new_score, :topic_new_score_index, :project_new_score_index,
  38. :activity_new_score_index, :influence_new_score_index, :score_new_index,:user_projects_index,:user_resource,
  39. :user_courses4show,:user_projects4show,:user_course_activities,:user_project_activities,:user_feedback4show,:user_visitorlist,:user_messages,:edit_brief_introduction,
  40. :user_import_homeworks,:user_search_homeworks,:user_import_resource, :user_system_messages,:choose_user_course,:user_courselist,:user_projectlist,:sort_syllabus_list]
  41. before_filter :auth_user_extension, only: :show
  42. #before_filter :rest_user_score, only: :show
  43. #before_filter :select_entry, only: :user_projects
  44. accept_api_auth :index, :show, :create, :update, :destroy,:tag_save , :tag_saveEx
  45. #william
  46. before_filter :require_login, :only => [:tag_save,:tag_saveEx]
  47. #before_filter :refresh_changests, :only =>[:user_activities,:user_courses,:user_projects,:user_newfeedback]
  48. #visitor
  49. before_filter :recorded_visitor, :only => [:show,:user_fanslist,:user_watchlist,:user_visitorlist]
  50. helper :sort
  51. helper :attachments
  52. include SortHelper
  53. include ApplicationHelper
  54. helper :custom_fields
  55. include CustomFieldsHelper
  56. include AvatarHelper
  57. include WordsHelper
  58. include GitlabHelper
  59. include UserScoreHelper
  60. include PollHelper
  61. helper :user_score
  62. helper :journals
  63. # added by liuping 关注
  64. helper :watchers
  65. helper :activities
  66. ### added by william
  67. include ActsAsTaggableOn::TagsHelper
  68. # fq
  69. helper :words
  70. helper :project_score
  71. helper :issues
  72. include UsersHelper
  73. #展开所有回复
  74. def show_all_replies
  75. case params[:type]
  76. when 'JournalsForMessage'
  77. @comment = JournalsForMessage.find params[:comment].to_i
  78. when 'Message'
  79. @comment = Message.find params[:comment].to_i
  80. when 'BlogComment'
  81. @comment = BlogComment.find params[:comment].to_i
  82. when 'OrgDocumentComment'
  83. @comment = OrgDocumentComment.find params[:comment].to_i
  84. when 'Comment'
  85. @comment = Comment.find params[:comment].to_i
  86. when 'Journal'
  87. @comment = Journal.find params[:comment].to_i
  88. end
  89. end
  90. #二级回复
  91. def reply_to
  92. case params[:type]
  93. when 'HomeworkCommon'
  94. @reply = JournalsForMessage.find params[:reply_id]
  95. @type = 'HomeworkCommon'
  96. if params[:user_activity_id]
  97. @user_activity_id = params[:user_activity_id]
  98. else
  99. @user_activity_id = -1
  100. end
  101. @is_in_course = params[:is_in_course].to_i
  102. @course_activity = params[:course_activity].to_i
  103. when 'JournalsForMessage'
  104. @reply = JournalsForMessage.find params[:reply_id]
  105. @user_activity_id = params[:user_activity_id]
  106. @activity_id = params[:activity_id]
  107. @type = 'JournalsForMessage'
  108. when 'Message'
  109. @reply = Message.find params[:reply_id]
  110. @user_activity_id = params[:user_activity_id]
  111. @activity_id = params[:activity_id]
  112. @is_course = params[:is_course]
  113. @is_board = params[:is_board]
  114. @type = 'Message'
  115. when 'BlogComment'
  116. @reply = BlogComment.find params[:reply_id]
  117. @user_activity_id = params[:user_activity_id]
  118. @activity_id = params[:activity_id]
  119. @homepage = params[:homepage]
  120. @user_id = params[:user_id]
  121. @type = 'BlogComment'
  122. when 'OrgDocumentComment'
  123. @reply = OrgDocumentComment.find params[:reply_id]
  124. @user_activity_id = params[:user_activity_id]
  125. @activity_id = params[:activity_id]
  126. @type = 'OrgDocumentComment'
  127. when 'News'
  128. @reply = Comment.find params[:reply_id]
  129. @user_activity_id = params[:user_activity_id]
  130. @activity_id = params[:activity_id]
  131. @type = 'News'
  132. when 'Issue'
  133. @reply = Journal.find params[:reply_id]
  134. @user_activity_id = params[:user_activity_id]
  135. @activity_id = params[:activity_id]
  136. @type = 'Issue'
  137. when 'Syllabus'
  138. @reply = JournalsForMessage.find params[:reply_id]
  139. @type = 'Syllabus'
  140. end
  141. respond_to do |format|
  142. format.js
  143. end
  144. end
  145. def refresh_changests
  146. if !(@user.nil?) && !(@user.memberships.nil?)
  147. @user.memberships.each do |member|
  148. unless member.project.nil?
  149. member.project.repository.fetch_changesets if Setting.autofetch_changesets?
  150. end
  151. end
  152. end
  153. end
  154. # 更新issue状态
  155. def user_act_issue_assign_to
  156. end
  157. #未读消息弹窗
  158. def user_messages_unviewed
  159. @message_alls = []
  160. messages = MessageAll.where("user_id =?", User.current.id).includes(:message).order("created_at desc")
  161. onclick_time = User.current.onclick_time.onclick_time
  162. messages.each do |message_all|
  163. # 未读的消息存放在数组
  164. mess = message_all.message
  165. if (message_all.message_type != "SystemMessage"&& !mess.nil? && (mess.viewed == 0 || !mess.viewed)) || (message_all.message_type == "SystemMessage"&& !mess.nil? && mess.created_at > onclick_time)
  166. unless (message_all.message_type == 'CourseMessage' && mess && mess.course && mess.course.is_delete == 1)
  167. @message_alls << mess
  168. end
  169. break if @message_alls.length == 10
  170. end
  171. end
  172. end
  173. # 用户消息
  174. # 说明: homework 发布作业;message:讨论区; news:新闻; poll:问卷;works_reviewers:作品评阅;works_reply:作品回复,exercise:课程测验
  175. # issue:问题;journal:缺陷状态更新; forum:公共贴吧: user_feedback: 用户留言; new_reply:新闻回复(comment)
  176. def user_messages
  177. if !User.current.logged?
  178. redirect_to signin_url
  179. return
  180. elsif @user != User.current && !User.current.admin?
  181. return render_403
  182. end
  183. # 初始化/更新 点击按钮时间, 24小时内显示系统消息
  184. update_onclick_time
  185. # 全部设为已读
  186. if params[:viewed] == "all"
  187. update_message_viewed(@user)
  188. end
  189. # @new_message_count = forge_querys.count + forum_querys.count + course_querys.count + user_querys.count
  190. courses = @user.courses.where("is_delete = 1")
  191. course_ids = courses.empty? ? "(-1)" : "(" + courses.map{|course| course.id}.join(",") + ")"
  192. case params[:type]
  193. when nil
  194. # 系统消息为管理员发送,我的消息中包含有系统消息
  195. @message_alls = []
  196. messages = MessageAll.where("(user_id =? and message_type !=?) or message_type =?" ,@user.id, "SystemMessage", "SystemMessage").includes(:message).order("created_at desc")
  197. messages.each do |message_all|
  198. mess = message_all.message
  199. unless (message_all.message_type == 'CourseMessage' && mess && mess.course && mess.course.is_delete == 1)
  200. @message_alls << mess
  201. end
  202. end
  203. when 'unviewed'
  204. @message_alls = []
  205. messages = MessageAll.where("message_alls.user_id =?", @user.id).includes(:message).order("created_at desc")
  206. messages.each do |message_all|
  207. # 在点击或者刷新消息列表后未读的消息存放在数组
  208. mess = message_all.message
  209. if message_all.message_type != "SystemMessage"&& !mess.nil? && (mess.viewed == 0 || !mess.viewed)
  210. unless (message_all.message_type == 'CourseMessage' && mess && mess.course && mess.course.is_delete == 1)
  211. @message_alls << mess
  212. end
  213. end
  214. end
  215. #课程相关消息
  216. when 'homework'
  217. @message_alls = CourseMessage.where("course_message_type in ('HomeworkCommon','StudentWorksScore','JournalsForMessage','StudentWork','Exercise') and user_id =? and course_id NOT IN #{course_ids}", @user.id).order("created_at desc")
  218. when 'course_message'
  219. @message_alls = CourseMessage.where("course_message_type =? and user_id =? and course_id NOT IN #{course_ids}", "Message", @user.id).order("created_at desc")
  220. when 'course_news'
  221. # 课程通知包含发布的通知和回复的通知
  222. @message_alls = CourseMessage.where("course_message_type in ('News', 'Comment') and user_id =? and course_id NOT IN #{course_ids}", @user.id).order("created_at desc")
  223. when 'poll'
  224. @message_alls = CourseMessage.where("course_message_type =? and user_id =? and course_id NOT IN #{course_ids}", "Poll", @user.id).order("created_at desc")
  225. #项目相关消息
  226. when 'issue'
  227. @message_alls = ForgeMessage.where("forge_message_type in ('Issue', 'Journal') and user_id =?" , @user.id).order("created_at desc")
  228. when 'forge_message'
  229. @message_alls = ForgeMessage.where("forge_message_type =? and user_id =?", "Message", @user.id).order("created_at desc")
  230. when 'forge_news'
  231. @message_alls = ForgeMessage.where("forge_message_type in (?,?) and user_id =?", "News", "Comment", @user.id).order("created_at desc")
  232. when 'apply'
  233. @message_alls = ForgeMessage.where("forge_message_type in ('ProjectInvite', 'AppliedProject', 'JoinProject', 'RemoveFromProject') and user_id =?", @user.id).order("created_at desc")
  234. #贴吧消息
  235. when 'forum'
  236. @message_alls = MemoMessage.where("memo_type =? and user_id =?", "Memo", @user.id).order("created_at desc")
  237. #用户留言
  238. when 'user_feedback'
  239. @message_alls = UserFeedbackMessage.where("journals_for_message_type =? and user_id =?", "JournalsForMessage", @user.id).order("created_at desc")
  240. else
  241. render_404
  242. return
  243. end
  244. @message_alls = paginateHelper @message_alls,25
  245. respond_to do |format|
  246. format.html{render :layout=>'new_base_user'}
  247. end
  248. end
  249. # 初始化/更新 点击按钮时间
  250. def update_onclick_time
  251. # 记录当前点击按钮的时间
  252. # 考虑到用户未退出刷新消息页面
  253. message_time = OnclickTime.where("user_id =?", User.current).first
  254. if message_time.nil?
  255. message_new_time = OnclickTime.new
  256. message_new_time.user_id = User.current.id
  257. message_new_time.onclick_time = Time.now
  258. message_new_time.save
  259. else
  260. message_time.update_attributes(:onclick_time => Time.now)
  261. end
  262. end
  263. # 消息设置为已读
  264. def update_message_viewed(user)
  265. if User.current.id == @user.id
  266. course_querys = CourseMessage.where("user_id =? and viewed =?", user, 0)
  267. forge_querys = ForgeMessage.where("user_id =? and viewed =?", user, 0)
  268. user_querys = UserFeedbackMessage.where("user_id =? and viewed =?", user, 0)
  269. forum_querys = MemoMessage.where("user_id =? and viewed =?", user, 0)
  270. org_querys = OrgMessage.where("user_id=? and viewed=0", user)
  271. at_querys = AtMessage.where("user_id=? and viewed=0", user)
  272. course_querys.update_all(:viewed => true) unless course_querys.nil?
  273. forge_querys.update_all(:viewed => true) unless forge_querys.nil?
  274. user_querys.update_all(:viewed => true) unless user_querys.nil?
  275. forum_querys.update_all(:viewed => true) unless forum_querys.nil?
  276. org_querys.update_all(:viewed => true) unless org_querys.nil?
  277. at_querys.update_all(:viewed => true) unless at_querys.nil?
  278. end
  279. end
  280. # 系统消息
  281. def user_system_messages
  282. @sytem_messages = SystemMessage.order("created_at desc").all
  283. @sytem_messages = paginateHelper @sytem_messages, 10
  284. respond_to do |format|
  285. format.html{render :layout=>'new_base_user'}
  286. end
  287. end
  288. def user_projects_index
  289. if User.current.admin?
  290. memberships = @user.memberships.all(conditions: "projects.project_type = #{Project::ProjectType_project}").first
  291. else
  292. cond = Project.visible_condition(User.current) + " AND projects.project_type <> 1"
  293. memberships = @user.memberships.all(:conditions => cond).first
  294. end
  295. watch_projects = Project.joins(:watchers).where("project_type <>? and watchable_type = ? and `watchers`.user_id = ?", '1','Project', @user.id).first
  296. if memberships.nil? && watch_projects
  297. redirect_to(:watch_projects_user) and return
  298. else
  299. redirect_to(:user_projects_user) and return
  300. end
  301. end
  302. #added by young
  303. def user_projects
  304. unless User.current.admin?
  305. if !@user.active? #|| (@user != User.current && @memberships.empty? && events.empty?)
  306. render_404
  307. return
  308. end
  309. end
  310. projects = @user.projects.visible.select("projects.*,(SELECT MAX(created_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc")
  311. if(params[:status] == '1')
  312. projects = projects.where("projects.user_id = ?",@user.id)
  313. elsif(params[:status] == '2')
  314. projects = projects.where("projects.user_id <> ?",@user.id)
  315. end
  316. @list = paginateHelper projects,10
  317. @params = params[:status]
  318. respond_to do |format|
  319. format.html{render :layout=>'base_users_new'}
  320. format.api
  321. end
  322. end
  323. #处理加入课程成为教辅教师的请求
  324. #status 1 同意 2 拒绝
  325. def dealwith_apply_request
  326. @msg = CourseMessage.find(params[:msg_id])
  327. #CourseMessage content存的是role 7教辅 9 教师
  328. case params[:agree]
  329. when 'Y'
  330. apply_user = User.find(@msg.course_message_id)
  331. ids = @msg.content.split(",") # [@msg.content] msg content保存的是申请的职位角色
  332. integer_ids = []
  333. ids.each do |role_id|
  334. integer_ids << role_id.to_i
  335. end
  336. if apply_user.member_of_course?(Course.find(@msg.course_id))
  337. #将角色改为老师或者教辅
  338. member = Course.find(@msg.course_id).members.where(:user_id=>apply_user.id).all[0]
  339. member.role_ids = integer_ids
  340. #删除为学生的记录
  341. unless member.role_ids.include?(10)
  342. joined = StudentsForCourse.where('student_id = ? and course_id = ?', member.user_id,@msg.course_id)
  343. joined.each do |join|
  344. join.delete
  345. end
  346. end
  347. member.course_group_id = 0
  348. member.save
  349. CourseMessage.create(:user_id => @msg.course_message_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>User.current.id,:content=>@msg.content,:course_message_type=>'CourseRequestDealResult',:status=>1)
  350. @msg.update_attributes(:status=>1,:viewed=>1)
  351. else
  352. members = []
  353. members << Member.new(:role_ids => integer_ids, :user_id => @msg.course_message_id)
  354. Course.find(@msg.course_id).members << members
  355. CourseMessage.create(:user_id => @msg.course_message_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>User.current.id,:content=>@msg.content,:course_message_type=>'CourseRequestDealResult',:status=>1)
  356. @msg.update_attributes(:status=>1,:viewed=>1)
  357. end
  358. when 'N'
  359. CourseMessage.create(:user_id => @msg.course_message_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>User.current.id,:content=>@msg.content,:course_message_type=>'CourseRequestDealResult',:status=>2)
  360. @msg.update_attributes(:status=>2,:viewed=>1)
  361. end
  362. respond_to do |format|
  363. format.js
  364. end
  365. end
  366. # 处理资源引用请求
  367. # status
  368. def deal_with_apply_resource
  369. @msg = CourseMessage.find(params[:msg_id])
  370. ar = ApplyResource.where("id = ?", @msg.course_message_id).first
  371. unless ar.nil?
  372. case params[:agree]
  373. when 'Y'
  374. ar.update_column('status', 2)
  375. @msg.update_attributes(:apply_result => 1, :viewed => 1)
  376. ar.course_messages << CourseMessage.new(:user_id => ar.user_id, :course_id => -1, :viewed => false, :apply_result => 2, :status => 1)
  377. when 'N'
  378. ar.update_column('status', 3)
  379. @msg.update_attributes(:apply_result => 2, :viewed => 1)
  380. ar.course_messages << CourseMessage.new(:user_id => ar.user_id, :course_id => -1, :viewed => false, :apply_result => 3, :status => 1)
  381. end
  382. end
  383. respond_to do |format|
  384. format.js
  385. end
  386. end
  387. #处理引用作业的请求
  388. #status 1 同意 2 拒绝
  389. def dealwith_apply_homework
  390. @msg = CourseMessage.find(params[:msg_id])
  391. ah = ApplyHomework.where("user_id = ? and homework_common_id = ?",@msg.apply_user_id, @msg.course_message_id)
  392. case params[:agree]
  393. when 'Y'
  394. unless ah.empty?
  395. ah.first.update_column('status', 2)
  396. CourseMessage.create(:user_id => @msg.apply_user_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>@msg.course_message_id,:content=>@msg.content,:course_message_type=>'HomeworkCommon',:status=>6,:apply_result=>1)
  397. @msg.update_attributes(:apply_result=>1,:viewed=>1)
  398. end
  399. when 'N'
  400. unless ah.empty?
  401. ah.first.update_column('status', 3)
  402. CourseMessage.create(:user_id => @msg.apply_user_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>@msg.course_message_id,:content=>@msg.content,:course_message_type=>'HomeworkCommon',:status=>6,:apply_result=>2)
  403. @msg.update_attributes(:apply_result=>2,:viewed=>1)
  404. end
  405. end
  406. respond_to do |format|
  407. format.js
  408. end
  409. end
  410. # added by bai
  411. def show_score
  412. end
  413. def show_new_score
  414. render :layout => 'users_base'
  415. end
  416. # end
  417. ##added by fq
  418. def watch_bids
  419. # cond = 'bids.reward_type <> 1'
  420. # @bids = Bid.watched_by(@user).where('reward_type = ?', 1) # added by huang
  421. # @offset, @limit = api_offset_and_limit({:limit => 10})
  422. # @bid_count = @bids.count
  423. # @bid_pages = Paginator.new @bid_count, @limit, params['page']
  424. # @offset ||= @bid_pages.reverse_offset
  425. # unless @offset == 0
  426. # @bid = @bids.offset(@offset).limit(@limit).all.reverse
  427. # else
  428. # limit = @bid_count % @limit
  429. # @bid = @bids.offset(@offset).limit(limit).all.reverse
  430. # end
  431. #
  432. # respond_to do |format|
  433. # format.html {
  434. # render :layout => 'base_users'
  435. # }
  436. # format.api
  437. # end
  438. end
  439. #new add by linchun
  440. def watch_contests
  441. @bids = Contest.watched_by(@user)
  442. @offset, @limit = api_offset_and_limit({:limit => 10})
  443. @contest_count = @contests.count
  444. @contest_pages = Paginator.new @contest_count, @limit, params['page']
  445. @offset ||= @contest_pages.reverse_offset
  446. unless @offset == 0
  447. @contest = @contests.offset(@offset).limit(@limit).all.reverse
  448. else
  449. limit = @bid_count % @limit
  450. @contest = @contests.offset(@offset).limit(limit).all.reverse
  451. end
  452. respond_to do |format|
  453. format.html {
  454. render :layout => 'base_users'
  455. }
  456. format.api
  457. end
  458. end
  459. # added by fq
  460. def user_activities
  461. redirect_to user_url(@user, type: params[:type], page: params[:page])
  462. return
  463. # useless abort.
  464. @watcher = User.watched_by_id(@user)
  465. events = []
  466. for user in @watcher
  467. events << Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 30)
  468. end
  469. @events_by_day = events.group_by(&:event_date)
  470. unless User.current.admin?
  471. if !@user.active? || (@user != User.current && @memberships.empty? && events.empty?)
  472. render_404
  473. return
  474. end
  475. end
  476. respond_to do |format|
  477. format.html
  478. format.api
  479. end
  480. end
  481. # end
  482. # 资源分享请求弹框
  483. def apply_resource
  484. @attachment = Attachment.find params[:attachment_id]
  485. respond_to do |format|
  486. format.js
  487. end
  488. end
  489. #引用作业请求弹框
  490. def apply_homework
  491. if User.current.logged?
  492. @homework = HomeworkCommon.find params[:homework_id]
  493. @state = 2
  494. else
  495. @state = 1
  496. end
  497. respond_to do |format|
  498. format.js
  499. end
  500. end
  501. # 申请引用资源
  502. def apply_for_resource
  503. if User.current.logged?
  504. @attachment = Attachment.where("id =?", params[:attachment_id].to_i).first
  505. unless @attachment.nil?
  506. ar = ApplyResource.where("user_id = ? and attachment_id = ?", User.current.id, params[:attacment_id].to_i)
  507. if ar.empty?
  508. ApplyResource.create(:user_id => params[:id].to_i, :attachment_id => params[:attachment_id].to_i, :status => true, :container_id => @attachment.container_id, :container_type => @attachment.container_type, :content => params[:content], :apply_user_id => @attachment.author_id)
  509. @state = 2
  510. else
  511. @state = 3
  512. end
  513. end
  514. else
  515. @state = 1
  516. end
  517. respond_to do |format|
  518. format.js
  519. end
  520. end
  521. #申请引用非公开作业
  522. def apply_for_homework
  523. if User.current.logged?
  524. homework = HomeworkCommon.find params[:homework_id]
  525. unless homework.nil?
  526. ah = ApplyHomework.where("user_id = ? and homework_common_id = ?", User.current.id, params[:homework_id].to_i)
  527. if ah.empty?
  528. ApplyHomework.create(:user_id => params[:id].to_i, :homework_common_id => params[:homework_id].to_i, :status => 1)
  529. Mailer.run.apply_for_homework_request(homework, User.current)
  530. CourseMessage.create(:user_id => homework.user_id, :course_id => homework.course.id, :viewed => false,:course_message_id=>params[:homework_id].to_i,:course_message_type=>'HomeworkCommon',:status=>5,:apply_user_id=>params[:id].to_i,:content=>params[:content])
  531. @state = 2
  532. @ah = ApplyHomework.where("user_id = ? and homework_common_id = ?", params[:id].to_i, params[:homework_id].to_i).first
  533. @homework = homework
  534. else
  535. @state = 3
  536. end
  537. end
  538. else
  539. @state = 1
  540. end
  541. respond_to do |format|
  542. format.js
  543. end
  544. end
  545. #用户作业列表
  546. def user_homeworks
  547. @order,@b_sort = params[:order] || "created_at",params[:sort] || "desc"
  548. @user = User.current
  549. @r_sort = @b_sort == "desc" ? "asc" : "desc"
  550. if(params[:type].blank? || params[:type] == "1") #我的题库
  551. @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}'").order("#{@order} #{@b_sort}")
  552. elsif params[:type] == "2" #题库
  553. visible_course = Course.where("is_delete = 0")
  554. visible_course_ids = visible_course.empty? ? "(-1)" : "(" + visible_course.map{|course| course.id}.join(",") + ")"
  555. @homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}'").order("#{@order} #{@b_sort}")
  556. end
  557. @type = params[:type]
  558. @limit = 25
  559. @is_remote = true
  560. @hw_count = @homeworks.count
  561. @hw_pages = Paginator.new @hw_count, @limit, params['page'] || 1
  562. @offset ||= @hw_pages.offset
  563. @homeworks = paginateHelper @homeworks,25
  564. respond_to do |format|
  565. format.js
  566. format.html {render :layout => 'static_base'}
  567. end
  568. end
  569. def student_homeworks
  570. if User.current == @user
  571. @page = params[:page] ? params[:page].to_i + 1 : 0
  572. user_course_ids = @user.courses.empty? ? "(-1)" :"(" + @user.courses.visible.map{|course| course.id}.join(",") + ")"
  573. #判断当前用户在当前课程的身份
  574. visibleCourse = @user.courses.empty? ? [] : @user.courses.where("is_delete = 0").visible
  575. homework_ids = []
  576. visibleCourse.each do |course|
  577. homeworks = HomeworkCommon.where("course_id = #{course.id} and publish_time <= '#{Date.today}'")
  578. homework_ids << homeworks.pluck(:id) unless homeworks.empty?
  579. end
  580. visible_homework_ids = homework_ids.size == 0 ? "(-1)" :"(" + homework_ids.join(",") + ")"
  581. @homework_commons = HomeworkCommon.where("id in #{visible_homework_ids}").order("created_at desc").limit(10).offset(@page * 10)
  582. @is_teacher = User.current.user_extensions && User.current.user_extensions.identity == 0 && User.current.allowed_to?(:add_course, nil, :global => true)
  583. @is_in_course = params[:is_in_course].to_i || 0
  584. respond_to do |format|
  585. format.js
  586. format.html {render :layout => 'new_base_user'}
  587. end
  588. else
  589. render_403
  590. end
  591. end
  592. def choose_user_course
  593. homework = HomeworkCommon.find params[:send_id].to_i
  594. if homework.user != User.current && homework.course.is_public == 0 && !User.current.allowed_to?(:as_teacher,homework.course)
  595. ah = ApplyHomework.where("user_id = ? and homework_common_id = ?", User.current.id, params[:send_id].to_i)
  596. if ah.empty?
  597. @status = 2
  598. elsif ah.first.status != 2
  599. @status = ah.first.status
  600. end
  601. end
  602. if !params[:search].nil?
  603. search = "%#{params[:search].to_s.strip.downcase}%"
  604. @course = @user.courses.where("is_delete = 0 and #{Course.table_name}.id != #{homework.course_id} and (#{Course.table_name}.id = #{params[:search].to_i } or #{Course.table_name}.name like :p)",:p=>search).select { |course| @user.allowed_to?(:as_teacher,course)}
  605. else
  606. @course = @user.courses.where("is_delete = 0 and #{Course.table_name}.id != #{homework.course_id}").select { |course| @user.allowed_to?(:as_teacher,course)}
  607. end
  608. @search = params[:search]
  609. #这里仅仅是传递需要发送的资源id
  610. @send_id = params[:send_id]
  611. respond_to do |format|
  612. format.js
  613. end
  614. end
  615. def send_homework_to_course
  616. homework = HomeworkCommon.find params[:send_id].to_i
  617. course_ids = params[:course_ids]
  618. course_ids.each do |course_id|
  619. course = Course.find course_id.to_i
  620. new_homework = HomeworkCommon.new
  621. new_homework.name = homework.name
  622. new_homework.user_id = User.current.id
  623. new_homework.description = homework.description
  624. new_homework.homework_type = homework.homework_type
  625. new_homework.late_penalty = homework.late_penalty
  626. new_homework.course_id = course.id
  627. new_homework.teacher_priority = homework.teacher_priority
  628. new_homework.anonymous_comment = homework.anonymous_comment
  629. new_homework.quotes = 0
  630. new_homework.is_open = homework.is_open
  631. homework.attachments.each do |attachment|
  632. att = attachment.copy
  633. att.container_id = nil
  634. att.container_type = nil
  635. att.copy_from = attachment.id
  636. att.save
  637. new_homework.attachments << att
  638. end
  639. homework_detail_manual = homework.homework_detail_manual
  640. homework_detail_programing = homework.homework_detail_programing
  641. homework_detail_group = homework.homework_detail_group
  642. if homework_detail_manual
  643. new_homework.homework_detail_manual = HomeworkDetailManual.new
  644. new_homework_detail_manual = new_homework.homework_detail_manual
  645. new_homework_detail_manual.ta_proportion = homework_detail_manual.ta_proportion
  646. new_homework_detail_manual.comment_status = 0
  647. new_homework_detail_manual.evaluation_num = homework_detail_manual.evaluation_num
  648. new_homework_detail_manual.absence_penalty = homework_detail_manual.absence_penalty
  649. end
  650. if homework_detail_programing
  651. new_homework.homework_detail_programing = HomeworkDetailPrograming.new
  652. new_homework.homework_detail_programing.ta_proportion = homework_detail_programing.ta_proportion
  653. new_homework.homework_detail_programing.language = homework_detail_programing.language
  654. homework.homework_tests.each_with_index do |homework_test|
  655. new_homework.homework_tests << HomeworkTest.new(
  656. input: homework_test.input,
  657. output: homework_test.output
  658. )
  659. end
  660. end
  661. if homework_detail_group
  662. new_homework.homework_detail_group = HomeworkDetailGroup.new
  663. new_homework.homework_detail_group.min_num = homework_detail_group.min_num
  664. new_homework.homework_detail_group.max_num = homework_detail_group.max_num
  665. new_homework.homework_detail_group.base_on_project = homework_detail_group.base_on_project
  666. end
  667. if new_homework.save
  668. new_homework_detail_manual.save if new_homework_detail_manual
  669. new_homework.homework_detail_programing.save if new_homework.homework_detail_programing
  670. new_homework.homework_detail_group.save if new_homework.homework_detail_group
  671. end
  672. homework.update_column(:quotes, homework.quotes+1)
  673. end
  674. @homework = homework
  675. respond_to do |format|
  676. format.js
  677. end
  678. end
  679. #导入作业
  680. def user_import_homeworks
  681. @user = User.current
  682. @select_course = params[:select_course] ? 1 : 0
  683. #@user_homeworks = HomeworkCommon.where(:user_id => @user.id).order("created_at desc")
  684. courses = @user.courses.where("is_delete = 1")
  685. course_ids = courses.empty? ? "(-1)" : "(" + courses.map{|course| course.id}.join(",") + ")"
  686. @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and course_id not in #{course_ids}").order("#{@order} #{@b_sort}")
  687. @type = params[:type]
  688. @limit = 15
  689. @is_remote = true
  690. @hw_count = @homeworks.count
  691. @hw_pages = Paginator.new @hw_count, @limit, params['page'] || 1
  692. @offset ||= @hw_pages.offset
  693. @homeworks = paginateHelper @homeworks,15
  694. respond_to do |format|
  695. format.js
  696. end
  697. end
  698. def user_homework_type
  699. @order,@b_sort = params[:order] || "created_at",params[:sort] || "desc"
  700. @r_sort = @b_sort == "desc" ? "asc" : "desc"
  701. @user = User.current
  702. if(params[:type].blank? || params[:type] == "1") #我的题库
  703. courses = @user.courses.where("is_delete = 1")
  704. course_ids = courses.empty? ? "(-1)" : "(" + courses.map{|course| course.id}.join(",") + ")"
  705. @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and course_id not in #{course_ids}").order("#{@order} #{@b_sort}")
  706. elsif params[:type] == "2" #题库
  707. if params[:is_import].to_i == 1
  708. visible_course = Course.where("is_public = 1 && is_delete = 0")
  709. elsif params[:is_import].to_i == 0
  710. visible_course = Course.where("is_delete = 0")
  711. end
  712. visible_course_ids = visible_course.empty? ? "(-1)" : "(" + visible_course.map{|course| course.id}.join(",") + ")"
  713. @homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}'").order("#{@order} #{@b_sort}")
  714. elsif params[:type] == "3" #申请题库
  715. none_visible_course = Course.where("is_delete = 1")
  716. none_visible_course_ids = none_visible_course.empty? ? "(-1)" : "(" + none_visible_course.map{|course| course.id}.join(",") + ")"
  717. #apply_homeworks = ApplyHomework.where("user_id = ?",@user.id).order('created_at desc')
  718. #homework_ids = apply_homeworks.empty? ? "(-1)" : "(" + apply_homeworks.map{|ah| ah.homework_common_id}.join(",") + ")"
  719. #@homeworks = HomeworkCommon.where("id in #{homework_ids} and course_id not in #{none_visible_course_ids}")
  720. sql = "SELECT homework_commons.* FROM homework_commons INNER JOIN apply_homeworks as ah ON homework_commons.id = ah.homework_common_id where ah.user_id = #{@user.id} and homework_commons.course_id not in #{none_visible_course_ids} order by ah.created_at desc"
  721. @homeworks = HomeworkCommon.find_by_sql(sql)
  722. end
  723. if params[:property]
  724. all_homework_ids = @homeworks.empty? ? "(-1)" : "(" + @homeworks.map{|h| h.id}.join(",") + ")"
  725. if params[:property] == "1"
  726. @homeworks = HomeworkCommon.find_by_sql("select * from homework_commons where id in #{all_homework_ids} and homework_type = 1")
  727. #@homeworks = @homeworks.where("homework_type = 1").reorder("#{@order} #{@b_sort}")
  728. elsif params[:property] == "2"
  729. @homeworks = HomeworkCommon.find_by_sql("select * from homework_commons where id in #{all_homework_ids} and homework_type = 2")
  730. #@homeworks = @homeworks.where("homework_type = 2").reorder("#{@order} #{@b_sort}")
  731. elsif params[:property] == "3"
  732. @homeworks = HomeworkCommon.find_by_sql("select * from homework_commons where id in #{all_homework_ids} and homework_type = 3")
  733. #@homeworks = @homeworks.where("homework_type = 3").reorder("#{@order} #{@b_sort}")
  734. end
  735. end
  736. @type = params[:type]
  737. @property = params[:property]
  738. @is_import = params[:is_import]
  739. @limit = params[:is_import].to_i == 1 ? 15 : 25
  740. @is_remote = true
  741. @hw_count = @homeworks.count
  742. @hw_pages = Paginator.new @hw_count, @limit, params['page'] || 1
  743. @offset ||= @hw_pages.offset
  744. @homeworks = paginateHelper @homeworks,@limit
  745. respond_to do |format|
  746. format.js
  747. end
  748. end
  749. def show_homework_detail
  750. @homework = HomeworkCommon.find params[:homework].to_i
  751. # if homework.course.is_public == 0 && !User.current.allowed_to?(:as_teacher,homework.course) && User.current != homework.user
  752. # ah = ApplyHomework.where("user_id = ? and homework_common_id = ?", User.current.id, params[:homework].to_i)
  753. # if ah.empty?
  754. # @status = 2
  755. # @homework = nil
  756. # elsif ah.first.status != 2
  757. # @status = ah.first.status
  758. # @homework = nil
  759. # elsif ah.first.status == 2
  760. # @homework = homework
  761. # end
  762. # else
  763. # @homework = homework
  764. # end
  765. @is_import = params[:is_import]
  766. respond_to do |format|
  767. format.js
  768. end
  769. end
  770. #用户主页过滤作业
  771. def user_search_homeworks
  772. @order,@b_sort = params[:order] || "created_at",params[:sort] || "desc"
  773. @r_sort = @b_sort == "desc" ? "asc" : "desc"
  774. @user = User.current
  775. search = params[:name].to_s.strip.downcase
  776. type_ids = params[:property]=="" || params[:property].nil? ? "(1, 2, 3)" : "(" + params[:property] + ")"
  777. if(params[:type].blank? || params[:type] == "1") #我的题库
  778. courses = @user.courses.where("is_delete = 1")
  779. course_ids = courses.empty? ? "(-1)" : "(" + courses.map{|course| course.id}.join(",") + ")"
  780. if @order == "course_name"
  781. sql = "SELECT homework_commons.* FROM homework_commons INNER JOIN courses ON homework_commons.course_id = courses.id where homework_commons.course_id not in #{course_ids} and homework_commons.user_id = #{@user.id} and homework_type in #{type_ids} and publish_time <= '#{Date.today}' and (homework_commons.name like '%#{search}%') order by CONVERT (courses.name USING gbk) COLLATE gbk_chinese_ci #{@b_sort}"
  782. @homeworks = HomeworkCommon.find_by_sql(sql)
  783. elsif @order == "user_name"
  784. @homeworks = HomeworkCommon.where("user_id = #{@user.id} and course_id not in #{course_ids} and publish_time <= '#{Date.today}' and (name like '%#{search}%') and homework_type in #{type_ids}").joins(:user).order("CONVERT (lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, CONVERT (firstname USING gbk) COLLATE gbk_chinese_ci #{@b_sort},login #{@b_sort}")
  785. else
  786. @homeworks = HomeworkCommon.where("user_id = #{@user.id} and course_id not in #{course_ids} and publish_time <= '#{Date.today}' and (name like '%#{search}%') and homework_type in #{type_ids}").order("#{@order} #{@b_sort}")
  787. end
  788. elsif params[:type] == "2" #题库
  789. if params[:is_import].to_i == 1
  790. visible_course = Course.where("is_public = 1 && is_delete = 0")
  791. elsif params[:is_import].to_i == 0
  792. visible_course = Course.where("is_delete = 0")
  793. end
  794. visible_course_ids = visible_course.empty? ? "(-1)" : "(" + visible_course.map{|course| course.id}.join(",") + ")"
  795. all_homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}'")
  796. all_user_ids = all_homeworks.map{|hw| hw.user_id}
  797. user_str_ids = search_user_by_name all_user_ids, search
  798. user_ids = user_str_ids.empty? ? "(-1)" : "(" + user_str_ids.join(",") + ")"
  799. if @order == "course_name"
  800. sql = "SELECT homework_commons.* FROM homework_commons INNER JOIN courses ON homework_commons.course_id = courses.id where homework_type in #{type_ids} and course_id in #{visible_course_ids} and publish_time <= '#{Date.today}' and (homework_commons.name like '%#{search}%' or homework_commons.user_id in #{user_ids}) order by CONVERT (courses.name USING gbk) COLLATE gbk_chinese_ci #{@b_sort}"
  801. @homeworks = HomeworkCommon.find_by_sql(sql)
  802. elsif @order == "user_name"
  803. @homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}' and homework_type in #{type_ids} and (name like '%#{search}%' or user_id in #{user_ids})").joins(:user).order("CONVERT (lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, CONVERT (firstname USING gbk) COLLATE gbk_chinese_ci #{@b_sort},login #{@b_sort}")
  804. else
  805. @homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}' and homework_type in #{type_ids} and (name like '%#{search}%' or user_id in #{user_ids})").order("#{@order} #{@b_sort}")
  806. end
  807. elsif params[:type] == "3" #申请题库
  808. apply_homeworks = ApplyHomework.where("user_id = ?",@user.id)
  809. homework_ids = apply_homeworks.empty? ? "(-1)" : "(" + apply_homeworks.map{|ah| ah.homework_common_id}.join(",") + ")"
  810. none_visible_course = Course.where("is_delete = 1")
  811. none_visible_course_ids = none_visible_course.empty? ? "(-1)" : "(" + none_visible_course.map{|course| course.id}.join(",") + ")"
  812. if @order == "course_name"
  813. sql = "SELECT homework_commons.* FROM homework_commons INNER JOIN courses ON homework_commons.course_id = courses.id where courses.is_delete = 0 and homework_commons.id in #{homework_ids} and homework_type in #{type_ids} and publish_time <= '#{Date.today}' and (homework_commons.name like '%#{search}%') order by CONVERT (courses.name USING gbk) COLLATE gbk_chinese_ci #{@b_sort}"
  814. @homeworks = HomeworkCommon.find_by_sql(sql)
  815. elsif @order == "user_name"
  816. @homeworks = HomeworkCommon.where("homework_commons.id in #{homework_ids} and course_id not in #{none_visible_course_ids} and (name like '%#{search}%') and homework_type in #{type_ids}").joins(:user).order("CONVERT (lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, CONVERT (firstname USING gbk) COLLATE gbk_chinese_ci #{@b_sort},login #{@b_sort}")
  817. else
  818. @homeworks = HomeworkCommon.where("id in #{homework_ids} and (name like '%#{search}%') and course_id not in #{none_visible_course_ids} and homework_type in #{type_ids}").order("#{@order} #{@b_sort}")
  819. end
  820. end
  821. =begin
  822. if params[:property] && params[:property] == "1"
  823. @homeworks = @homeworks.where("homework_type = 1")
  824. elsif params[:property] && params[:property] == "2"
  825. @homeworks = @homeworks.where("homework_type = 2")
  826. elsif params[:property] && params[:property] == "3"
  827. @homeworks = @homeworks.where("homework_type = 3")
  828. end
  829. =end
  830. @type = params[:type]
  831. @limit = params[:is_import].to_i == 1 ? 15 : 25
  832. @is_remote = true
  833. @hw_count = @homeworks.count
  834. @hw_pages = Paginator.new @hw_count, @limit, params['page'] || 1
  835. @offset ||= @hw_pages.offset
  836. @homeworks = paginateHelper @homeworks,@limit
  837. @is_import = params[:is_import]
  838. @property = params[:property]
  839. @search = search
  840. respond_to do |format|
  841. format.js
  842. end
  843. end
  844. #导入作业,确定按钮
  845. def user_select_homework
  846. homework = HomeworkCommon.find_by_id params[:checkMenu]
  847. homework_detail_programing = homework.homework_detail_programing
  848. homework_detail_group = homework.homework_detail_group
  849. @homework = HomeworkCommon.new
  850. @select_course = params[:select_course] || 0
  851. if homework
  852. @ref_homework = homework
  853. @homework.name = homework.name
  854. @homework.description = homework.description
  855. @homework.end_time = homework.end_time
  856. @homework.homework_type = homework.homework_type
  857. @homework.course_id = homework.course_id
  858. homework.attachments.each do |attachment|
  859. att = attachment.copy
  860. att.container_id = nil
  861. att.container_type = nil
  862. att.copy_from = attachment.id
  863. att.save
  864. @homework.attachments << att
  865. end
  866. if homework_detail_programing
  867. @homework.homework_detail_programing = HomeworkDetailPrograming.new
  868. @homework_detail_programing = @homework.homework_detail_programing
  869. @homework_detail_programing.ta_proportion = homework_detail_programing.ta_proportion
  870. @homework_detail_programing.language = homework_detail_programing.language
  871. homework.homework_tests.each_with_index do |homework_test|
  872. @homework.homework_tests << HomeworkTest.new(
  873. input: homework_test.input,
  874. output: homework_test.output
  875. )
  876. end
  877. end
  878. if homework_detail_group
  879. @homework.homework_detail_group = HomeworkDetailGroup.new
  880. @homework_detail_group = @homework.homework_detail_group
  881. @homework_detail_group.min_num = homework_detail_group.min_num
  882. @homework_detail_group.max_num = homework_detail_group.max_num
  883. @homework_detail_group.base_on_project = homework_detail_group.base_on_project
  884. end
  885. end
  886. respond_to do |format|
  887. format.js
  888. end
  889. end
  890. def new_user_commit_homework
  891. if User.current.logged?
  892. @user = User.current
  893. @homework = HomeworkCommon.find(params[:homework_id])
  894. @is_test = params[:is_test] == 'true'
  895. @student_work = StudentWork.where(homework_common_id: @homework.id, user_id: User.current.id).first
  896. if @student_work.nil?
  897. @student_work = StudentWork.new
  898. end
  899. @course = @homework.course
  900. @left_nav_type = 3
  901. respond_to do |format|
  902. format.js
  903. format.html {render :layout => 'base_courses'}
  904. end
  905. else
  906. render_403
  907. end
  908. end
  909. #修改编程作业
  910. def edit_user_commit_homework
  911. if User.current.logged?
  912. respond_to do |format|
  913. format.js
  914. format.html {render :layout => 'new_base_user'}
  915. end
  916. else
  917. render_403
  918. end
  919. end
  920. def user_commit_homework
  921. homework = HomeworkCommon.find(params[:homework])
  922. student_work = StudentWork.where(homework_common_id: homework.id, user_id: User.current.id).first
  923. if student_work
  924. #提交作品时,计算是否迟交
  925. if Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d")
  926. student_work.late_penalty = homework.late_penalty
  927. student_work.work_status = 2
  928. else
  929. student_work.late_penalty = 0
  930. student_work.work_status = 1
  931. end
  932. student_work.save
  933. send_message_to_teacher(student_work)
  934. homework.update_column(:updated_at, Time.now)
  935. update_course_activity(homework.class,homework.id)
  936. update_user_activity(homework.class,homework.id)
  937. update_org_activity(homework.class,homework.id)
  938. flash[:notice] = l(:notice_successful_create)
  939. redirect_to student_work_index_url(:homework => params[:homework])
  940. else
  941. render_403
  942. end
  943. end
  944. def user_new_homework
  945. if User.current.logged?
  946. if params[:homework_common]
  947. homework = HomeworkCommon.new
  948. homework.name = params[:homework_common][:name]
  949. homework.description = params[:homework_common][:description]
  950. homework.end_time = params[:homework_common][:end_time] || Date.today
  951. if params[:homework_common][:publish_time] == ""
  952. homework.publish_time = Date.today
  953. else
  954. homework.publish_time = params[:homework_common][:publish_time]
  955. end
  956. homework.anonymous_comment = params[:homework_common][:anonymous_comment] ? params[:homework_common][:anonymous_comment] : 0
  957. homework.homework_type = params[:homework_type].to_i || 1
  958. homework.late_penalty = 10
  959. homework.teacher_priority = 1
  960. homework.user_id = User.current.id
  961. homework.course_id = params[:course_id]
  962. homework.save_attachments(params[:attachments])
  963. render_attachment_warning_if_needed(homework)
  964. homework_detail_manual = HomeworkDetailManual.new
  965. if homework.anonymous_comment == 1
  966. homework_detail_manual.ta_proportion = homework.homework_type == 1 ? 1.0 : 0.4
  967. else
  968. homework_detail_manual.ta_proportion = homework.homework_type == 1 ? 0.6 : 0.3
  969. end
  970. if homework.publish_time > Date.today
  971. homework_detail_manual.comment_status = 0
  972. else
  973. homework_detail_manual.comment_status = 1
  974. end
  975. homework_detail_manual.evaluation_start = params[:evaluation_start].blank? ? homework.end_time + 7 : params[:evaluation_start]
  976. homework_detail_manual.evaluation_end = params[:evaluation_end].blank? ? homework_detail_manual.evaluation_start + 7 : params[:evaluation_end]
  977. homework_detail_manual.evaluation_num = params[:evaluation_num] || 3
  978. homework_detail_manual.absence_penalty = 5
  979. homework.homework_detail_manual = homework_detail_manual
  980. #编程作业相关属性
  981. if homework.homework_type == 2
  982. homework_detail_programing = HomeworkDetailPrograming.new
  983. homework.homework_detail_programing = homework_detail_programing
  984. if homework.anonymous_comment == 1
  985. homework_detail_programing.ta_proportion = 0.6
  986. else
  987. homework_detail_programing.ta_proportion = 0.5
  988. end
  989. homework_detail_programing.language = params[:language_type].to_i
  990. inputs = params[:program][:input]
  991. if Array === inputs
  992. inputs.each_with_index do |val, i|
  993. homework.homework_tests << HomeworkTest.new(
  994. input: val,
  995. output: params[:program][:output][i]
  996. )
  997. end
  998. end
  999. end
  1000. #分组作业
  1001. if homework.homework_type == 3
  1002. homework_detail_group = HomeworkDetailGroup.new
  1003. homework.homework_detail_group = homework_detail_group
  1004. homework_detail_group.min_num = params[:min_num].to_i
  1005. homework_detail_group.max_num = params[:max_num].to_i
  1006. homework_detail_group.base_on_project = params[:base_on_project].to_i
  1007. end
  1008. if homework.save
  1009. homework_detail_manual.save if homework_detail_manual
  1010. homework_detail_programing.save if homework_detail_programing
  1011. homework_detail_group.save if homework_detail_group
  1012. if homework.homework_type != 3
  1013. students = homework.course.student
  1014. if !homework.course.nil? && !students.empty?
  1015. name = homework.name
  1016. name_str = name + "的作品提交"
  1017. str = ""
  1018. students.each do |student|
  1019. if str != ""
  1020. str += ","
  1021. end
  1022. str += "('#{name_str}',#{homework.id},#{student.student_id}, '#{format_time(Time.now)}', '#{format_time(Time.now)}')"
  1023. end
  1024. #('#{name}的作品提交',#{homework.id},#{student.student_id}, '#{format_time(Time.now)}', '#{format_time(Time.now)}')
  1025. sql = "insert into student_works (name, homework_common_id,user_id, created_at, updated_at) values" + str
  1026. #StudentWork.create(:name => "#{name}的作品提交", :homework_common_id => homework.id, :user_id => student.student_id)
  1027. ActiveRecord::Base.connection.execute sql
  1028. end
  1029. end
  1030. if params[:quotes] && !params[:quotes].blank?
  1031. quotes_homework = HomeworkCommon.find params[:quotes].to_i
  1032. quotes_homework.update_column(:quotes, quotes_homework.quotes+1)
  1033. end
  1034. if params[:is_in_course] == "1"
  1035. redirect_to homework_common_index_path(:course => homework.course_id)
  1036. else
  1037. redirect_to user_homeworks_user_path(User.current.id)
  1038. end
  1039. end
  1040. end
  1041. else
  1042. render_403
  1043. end
  1044. end
  1045. #用户从资源库导入资源到作业
  1046. def user_import_resource
  1047. @user = User.current
  1048. user_course_ids = @user.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
  1049. @attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
  1050. "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").order("created_on desc")
  1051. @type = params[:type]
  1052. @homework_id = params[:homework_id]
  1053. @limit = 7
  1054. @is_remote = true
  1055. @atta_count = @attachments.count
  1056. @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
  1057. @offset ||= @atta_pages.offset
  1058. @seleted_resources = session[:seleted_resource_ids].nil? ? [] : session[:seleted_resource_ids]
  1059. #@curse_attachments_all = @all_attachments[@offset, @limit]
  1060. @attachments = paginateHelper @attachments,7
  1061. respond_to do |format|
  1062. format.js
  1063. end
  1064. end
  1065. #引入资源列表根据类型过滤
  1066. def user_resource_type
  1067. if User.current.id.to_i != params[:id].to_i
  1068. render_403
  1069. return
  1070. end
  1071. user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id}
  1072. user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id }
  1073. # user_org_ids = User.current.organizations.map {|o| o.id}
  1074. if(params[:type].blank? || params[:type] == "1") # 我的资源
  1075. # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
  1076. if params[:status] == "2"
  1077. @attachments = get_course_resources(params[:id], user_course_ids, @order, @score)
  1078. elsif params[:status] == "3"
  1079. @attachments = get_project_resources(params[:id], user_project_ids, @order, @score)
  1080. elsif params[:status] == "4"
  1081. @attachments = get_attch_resources(params[:id], @order, @score)
  1082. elsif params[:status] == "5"
  1083. @attachments = get_principal_resources(params[:id], @order, @score)
  1084. else
  1085. # 公共资源库:所有公开资源或者我上传的私有资源
  1086. @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score)
  1087. end
  1088. elsif params[:type] == "6" # 公共资源
  1089. if params[:status] == "2"
  1090. @attachments = get_course_resources_public( user_course_ids, @order, @score)
  1091. elsif params[:status] == "3"
  1092. @attachments = get_project_resources_public(user_project_ids, @order, @score)
  1093. elsif params[:status] == "4"
  1094. @attachments = get_attch_resources_public(@order, @score)
  1095. elsif params[:status] == "5"
  1096. @attachments = get_principal_resources_public(@order, @score)
  1097. else
  1098. # 公共资源库:所有公开资源或者我上传的私有资源
  1099. @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score)
  1100. end
  1101. end
  1102. @type = params[:type]
  1103. @limit = 7
  1104. @is_remote = true
  1105. @atta_count = @attachments.count
  1106. @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
  1107. @offset ||= @atta_pages.offset
  1108. @seleted_resources = session[:seleted_resource_ids].nil? ? [] : session[:seleted_resource_ids]
  1109. #@curse_attachments_all = @all_attachments[@offset, @limit]
  1110. @attachments = paginateHelper @attachments,7
  1111. respond_to do |format|
  1112. format.js
  1113. end
  1114. end
  1115. #引入资源列表根据关键词过滤
  1116. def user_ref_resource_search
  1117. if User.current.id.to_i != params[:id].to_i
  1118. render_403
  1119. return
  1120. end
  1121. @resource_id = params[:mul_id]
  1122. @resource_type = params[:mul_type]
  1123. @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc"
  1124. @score = @b_sort == "desc" ? "asc" : "desc"
  1125. @user = User.current
  1126. @switch_search = params[:search].nil? ? " " : params[:search]
  1127. search = "%#{@switch_search.strip.downcase}%"
  1128. # 别人的资源库是没有权限去看的
  1129. if(params[:type] == "1") # 我的资源
  1130. # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
  1131. user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id}
  1132. user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id }
  1133. # user_org_ids = User.current.organizations.map {|o| o.id}
  1134. @attachments = get_my_resources_search(params[:id], user_course_ids, user_project_ids, @order, @score, search)
  1135. elsif (params[:type].blank? || params[:type] == "6") # 公共资源
  1136. # 公共资源库:所有公开资源或者我上传的私有资源
  1137. @attachments = get_public_resources_search(user_course_ids, user_project_ids, @order, @score, search)
  1138. end
  1139. @type = params[:type]
  1140. @limit = 7
  1141. @is_remote = true
  1142. @atta_count = @attachments.count
  1143. @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
  1144. @offset ||= @atta_pages.offset
  1145. @seleted_resources = session[:seleted_resource_ids].nil? ? [] : session[:seleted_resource_ids]
  1146. #@curse_attachments_all = @all_attachments[@offset, @limit]
  1147. @attachments = paginateHelper @attachments,7
  1148. respond_to do |format|
  1149. format.js
  1150. end
  1151. end
  1152. #将资源批量引入
  1153. def import_resources_to_homework
  1154. @attachments = []
  1155. unless session[:seleted_resource_ids].nil? || session[:seleted_resource_ids].blank?
  1156. session[:seleted_resource_ids].each do |id|
  1157. atta = Attachment.find(id)
  1158. att_copy = atta.copy
  1159. att_copy.container_id = nil
  1160. att_copy.container_type = nil
  1161. att_copy.author_id = User.current.id
  1162. att_copy.copy_from = atta.id
  1163. att_copy.save
  1164. @attachments << att_copy
  1165. end
  1166. end
  1167. session[:seleted_resource_ids] = [] #保存后清空
  1168. respond_to do |format|
  1169. format.js
  1170. end
  1171. end
  1172. # ajax 用session保存选择的资源id
  1173. def store_selected_resource
  1174. session[:seleted_resource_ids] = [] if session[:seleted_resource_ids].nil?
  1175. if params[:save] == 'y'
  1176. session[:seleted_resource_ids] << params[:res_id]
  1177. else
  1178. session[:seleted_resource_ids].delete( params[:res_id])
  1179. end
  1180. render :nothing => true
  1181. end
  1182. include CoursesHelper
  1183. def user_courses
  1184. unless User.current.admin?
  1185. if !@user.active?
  1186. render_404
  1187. return
  1188. end
  1189. end
  1190. courses = @user.courses.visible.select("courses.*,(SELECT MAX(created_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc")
  1191. if(params[:status] == '1')
  1192. courses = courses.where("endup_time >= ? or endup_time is null or endup_time=''",Time.now)
  1193. elsif(params[:status] == '2')
  1194. courses = courses.where("endup_time < ?",Time.now)
  1195. end
  1196. @list = paginateHelper courses,10
  1197. @params = params[:status]
  1198. render :layout=>'base_users_new'
  1199. end
  1200. # modified by fq
  1201. def user_newfeedback
  1202. unless User.current.logged?
  1203. redirect_to signin_url
  1204. return
  1205. end
  1206. # 自己访问自己的页面才更新消息状态
  1207. UserFeedbackMessage.where("user_id =? and viewed =? and journals_for_message_type =? ", User.current.id, 0, "JournalsForMessage").update_all(:viewed => true)
  1208. # end
  1209. @page = params[:page] ? params[:page].to_i + 1 : 0
  1210. if params[:type].present?
  1211. case params[:type]
  1212. when "public"
  1213. jours = @user.journals_for_messages.where('m_parent_id IS NULL and private = 0').order('updated_on DESC')
  1214. when "private"
  1215. jours = @user.journals_for_messages.where('m_parent_id IS NULL and private = 1').order('updated_on DESC')
  1216. else
  1217. jours = @user.journals_for_messages.where('m_parent_id IS NULL').order('updated_on DESC')
  1218. end
  1219. else
  1220. jours = @user.journals_for_messages.where('m_parent_id IS NULL').order('updated_on DESC')
  1221. end
  1222. @jour_count = jours.count
  1223. @jour = jours.limit(10).offset(@page * 10)
  1224. @type = params[:type]
  1225. if User.current == @user
  1226. jours.update_all(:is_readed => true, :status => false)
  1227. jours.each do |journal|
  1228. fetch_user_leaveWord_reply(journal).update_all(:is_readed => true, :status => false)
  1229. end
  1230. end
  1231. @state = false
  1232. render :layout=>'new_base_user'
  1233. end
  1234. #给某人留言
  1235. def feedBackTo
  1236. end
  1237. def user_comments
  1238. end
  1239. #end
  1240. def index
  1241. @status = params[:status] || 1
  1242. sort_init 'login', 'asc'
  1243. sort_update %w(login firstname lastname mail admin created_on last_login_on)
  1244. case params[:format]
  1245. when 'xml', 'json'
  1246. @offset, @limit = api_offset_and_limit({:limit => 15})
  1247. else
  1248. @limit = 15
  1249. end
  1250. # retrieve all users
  1251. # 先内连一下statuses 保证排序之后数量一致
  1252. scope = User.visible.
  1253. joins("INNER JOIN user_statuses ON users.id = user_statuses.user_id")
  1254. # unknow
  1255. scope = scope.in_group(params[:group_id]) if params[:group_id].present?
  1256. # pagination
  1257. @user_count = scope.count
  1258. @user_pages = Paginator.new @user_count, @limit, params['page']
  1259. # users classify
  1260. case params[:user_sort_type]
  1261. when '0'
  1262. # 创建时间排序
  1263. @s_type = 0
  1264. @users = scope.reorder('users.created_on DESC')
  1265. when '1'
  1266. # 活跃度排序, 就是所谓的得分情况
  1267. @s_type = 1
  1268. @users = scope.
  1269. joins("LEFT JOIN option_numbers ON users.id = option_numbers.user_id and option_numbers.score_type = 1").
  1270. reorder('option_numbers.total_score DESC')
  1271. when '2'
  1272. # 粉丝数排序
  1273. @s_type = 2
  1274. @users = scope.
  1275. #joins("INNER JOIN user_statuses ON users.id = user_statuses.user_id").
  1276. reorder('user_statuses.watchers_count DESC')
  1277. else
  1278. # 默认活跃度排序
  1279. @s_type = 1
  1280. @users = scope.
  1281. joins("LEFT JOIN option_numbers ON users.id = option_numbers.user_id and option_numbers.score_type = 1").
  1282. reorder('option_numbers.total_score DESC')
  1283. end
  1284. # limit and offset
  1285. @users = @users.limit(@user_pages.per_page).offset(@user_pages.offset)
  1286. @user_base_tag = params[:id] ? 'base_users':'users_base'
  1287. respond_to do |format|
  1288. format.html {
  1289. @groups = Group.all.sort
  1290. User.current.admin? ? (render :layout => @user_base_tag) : (render_404)
  1291. }
  1292. format.api
  1293. end
  1294. end
  1295. def search
  1296. sort_init 'login', 'asc'
  1297. sort_update %w(login firstname lastname mail admin created_on last_login_on)
  1298. (redirect_to user_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank?
  1299. case params[:format]
  1300. when 'xml', 'json'
  1301. @offset, @limit = api_offset_and_limit({:limit => 15})
  1302. else
  1303. @limit = 15#per_page_option
  1304. end
  1305. #
  1306. #@status = params[:status] || 1
  1307. #has = {
  1308. # "show_changesets" => true
  1309. #}
  1310. # scope = User.logged.status(@status)
  1311. # @search_by = params[:search_by] ? params[:search_by][:id] : 0
  1312. # scope = scope.like(params[:name],@search_by) if params[:name].present?
  1313. @search_by = params[:search_by] ? params[:search_by] : 0
  1314. us = UsersService.new
  1315. scope = us.search_user params
  1316. @user_count = scope.count
  1317. @user_pages = Paginator.new @user_count, @limit, params['page']
  1318. @user_base_tag = params[:id] ? 'base_users':'users_base'
  1319. @offset ||= @user_pages.reverse_offset
  1320. unless @offset == 0
  1321. @users = scope.offset(@offset).limit(@limit).all.reverse
  1322. else
  1323. limit = @user_count % @limit
  1324. if limit == 0
  1325. limit = @limit
  1326. end
  1327. @users = scope.offset(@offset).limit(limit).all.reverse
  1328. end
  1329. @name = params[:name]
  1330. @type = 'users'
  1331. respond_to do |format|
  1332. format.html {
  1333. @groups = Group.all.sort
  1334. render :layout => @user_base_tag
  1335. }
  1336. format.api
  1337. end
  1338. end
  1339. #显示更多用户课程
  1340. def user_courses4show
  1341. @page = params[:page].to_i + 1
  1342. @type = params[:type]
  1343. if @type == 'User'
  1344. @courses = @user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(5).offset(@page * 5)
  1345. @all_count = @user.courses.visible.where("is_delete =?", 0).count
  1346. elsif @type == 'Syllabus'
  1347. @syllabus = Syllabus.where("id = #{params[:syllabus]}").first
  1348. if User.current == @syllabus.user || User.current.admin?
  1349. all_courses = @syllabus.courses.where("is_delete = 0").select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc")
  1350. else
  1351. all_courses = User.current.courses.visible.where("is_delete =? and syllabus_id =?", 0, @syllabus.id).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc")
  1352. end
  1353. @courses = all_courses.limit(5).offset(@page * 5)
  1354. @all_count = all_courses.count
  1355. end
  1356. end
  1357. #显示更多用户项目
  1358. def user_projects4show
  1359. @page = params[:page].to_i + 1
  1360. @projects = @user.projects.visible.select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(5).offset(@page * 5)
  1361. end
  1362. def user_course_activities
  1363. lastid = nil
  1364. if params[:lastid]!=nil && !params[:lastid].empty?
  1365. lastid = params[:lastid];
  1366. end
  1367. user_ids = []
  1368. if @user == User.current
  1369. watcher = User.watched_by(@user)
  1370. watcher.push(User.current)
  1371. user_ids = watcher.map{|x| x.id}
  1372. else
  1373. user_ids << @user.id
  1374. end
  1375. query = Activity.joins("join courses c on c.id=#{Activity.table_name}.activity_container_id and #{Activity.table_name}.activity_container_type='Course'")
  1376. query = query.where("#{Activity.table_name}.user_id in (?)", user_ids)
  1377. if User.current != @user #看别人
  1378. if @user.user_extensions!=nil && @user.user_extensions.identity == 0 #看老师
  1379. query = query.joins("join members m on c.id=m.course_id and m.user_id = #{@user.id}")
  1380. query = query.joins("join member_roles r on m.id = r.member_id")
  1381. query = query.where("r.role_id in(3,7,9)")
  1382. end
  1383. query = query.where("c.is_public=1")
  1384. end
  1385. if(lastid != nil)
  1386. query = query.where("#{Activity.table_name}.id < ?",lastid)
  1387. end
  1388. query = query.order("#{Activity.table_name}.id desc")
  1389. @list = query_activities(query)
  1390. render :layout=>nil
  1391. end
  1392. def user_project_activities
  1393. lastid = nil
  1394. if params[:lastid]!=nil && !params[:lastid].empty?
  1395. lastid = params[:lastid];
  1396. end
  1397. user_ids = []
  1398. if @user == User.current
  1399. watcher = User.watched_by(@user)
  1400. watcher.push(User.current)
  1401. user_ids = watcher.map{|x| x.id}
  1402. else
  1403. user_ids << @user.id
  1404. end
  1405. query = Activity.joins("join projects c on c.id=#{Activity.table_name}.activity_container_id and #{Activity.table_name}.activity_container_type='Project'")
  1406. query = query.where(user_id: user_ids)
  1407. if User.current != @user #看别人
  1408. query = query.where("c.is_public=1")
  1409. end
  1410. if(lastid != nil)
  1411. query = query.where("#{Activity.table_name}.id < ?",lastid)
  1412. end
  1413. query = query.order("#{Activity.table_name}.id desc")
  1414. @list = query_activities(query)
  1415. render :action=>'user_course_activities',:layout=>nil
  1416. end
  1417. def user_feedback4show
  1418. query = @user.journals_for_messages
  1419. if params[:lastid]!=nil && !params[:lastid].empty?
  1420. query = query.where("#{JournalsForMessage.table_name}.id < ?",params[:lastid])
  1421. end
  1422. logger.info('xxoo')
  1423. @list = query.order("#{JournalsForMessage.table_name}.id desc").limit(3).all
  1424. logger.info('aavv')
  1425. render :layout=>nil,:locals => {:feed_list=>@list}
  1426. end
  1427. def show
  1428. #更新用户申请成为课程老师或教辅消息的状态
  1429. if params[:course_id] != nil
  1430. join_course_messages = CourseMessage.where("course_id =? and course_message_type =? and user_id =? and course_message_id =? and viewed =?",
  1431. params[:course_id], 'JoinCourseRequest', User.current.id, @user.id, false)
  1432. join_course_messages.update_all(:viewed => true)
  1433. end
  1434. shield_project_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{@user.id} and shield_type='Project'").map(&:shield_id)
  1435. shield_course_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{@user.id} and shield_type='Course'").map(&:shield_id)
  1436. @page = params[:page] ? params[:page].to_i + 1 : 0
  1437. user_project_ids = (@user.projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (@user.projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")"
  1438. user_course_ids = (@user.courses.visible.where("is_delete = 0").map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (@user.courses.visible.where("is_delete = 0").map{|course| course.id}-shield_course_ids).join(",") + ")"
  1439. course_types = "('Message','News','HomeworkCommon','Poll','Course','JournalsForMessage')"
  1440. project_types = "('Message','Issue','Project')"
  1441. principal_types = "JournalsForMessage"
  1442. if params[:type].present?
  1443. case params[:type]
  1444. when "course_homework"
  1445. @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'HomeworkCommon'").order('updated_at desc').limit(10).offset(@page * 10)
  1446. when "course_news"
  1447. @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'News'").order('updated_at desc').limit(10).offset(@page * 10)
  1448. when "course_message"
  1449. @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'Message'").order('updated_at desc').limit(10).offset(@page * 10)
  1450. when "course_poll"
  1451. @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'Poll'").order('updated_at desc').limit(10).offset(@page * 10)
  1452. when "course_journals"
  1453. @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'JournalsForMessage'").order('updated_at desc').limit(10).offset(@page * 10)
  1454. when "project_issue"
  1455. @user_activities = UserActivity.where("container_type = 'Project' and container_id in #{user_project_ids} and act_type = 'Issue'").order('updated_at desc').limit(10).offset(@page * 10)
  1456. when "project_message"
  1457. @user_activities = UserActivity.where("container_type = 'Project' and container_id in #{user_project_ids} and act_type = 'Message'").order('updated_at desc').limit(10).offset(@page * 10)
  1458. when "user_journals"
  1459. @user_activities = UserActivity.where("container_type = 'Principal' and act_type= 'JournalsForMessage' and container_id = #{@user.id}").order('updated_at desc').limit(10).offset(@page * 10)
  1460. when "current_user"
  1461. @user_activities = UserActivity.where("user_id = #{@user.id} and ((container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}))").order('updated_at desc').limit(10).offset(@page * 10)
  1462. else
  1463. if @user == User.current
  1464. blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")"
  1465. else
  1466. blog_ids = "("+@user.blog.id.to_s+")"
  1467. end
  1468. @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" +
  1469. "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+
  1470. "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " +
  1471. "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(10).offset(@page * 10)
  1472. end
  1473. else
  1474. # @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id})").order('updated_at desc').limit(10).offset(@page * 10)
  1475. # blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")"
  1476. # 减少数据库交互
  1477. if @user == User.current
  1478. watched_user_ids = User.watched_by(@user.id).count == 0 ? " " : ("," + User.watched_by(@user.id).map{|u| u.id.to_s }.join(','))
  1479. user_ids = "(" + @user.id.to_s + watched_user_ids + ")"
  1480. else
  1481. user_ids = "(" + @user.id.to_s + ")"
  1482. end
  1483. watched_user_blog_ids = Blog.select("id").where("author_id in #{user_ids}")
  1484. blog_ids = watched_user_blog_ids.empty? ? "(-1)" : "(" + watched_user_blog_ids.map { |blog| blog.id}.join(",") + ")"
  1485. @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" +
  1486. "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+
  1487. "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " +
  1488. "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(10).offset(@page * 10)
  1489. end
  1490. # @user_activities = paginateHelper @user_activities,500
  1491. @type = params[:type]
  1492. respond_to do |format|
  1493. format.js
  1494. format.html {render :layout => 'new_base_user'}
  1495. end
  1496. end
  1497. def show_old
  1498. pre_count = 10 #limit
  1499. # Time 2015-02-04 11:46:34
  1500. # Author lizanle
  1501. # Description type 1 :所有动态包括我关注的人 type 2:我的动态 type 3:关于我的回复
  1502. case params[:type]
  1503. when "1"
  1504. if @user == User.current
  1505. activity = Activity.where('user_id = ?', User.current.id).order('id desc')
  1506. @activity_count = activity.count
  1507. @activity_pages = Paginator.new @activity_count, pre_count, params['page']
  1508. @activity = activity.offset(@activity_pages.offset).limit(@activity_pages.per_page).all
  1509. @state = 1
  1510. end
  1511. when "2"
  1512. message = []
  1513. if @user == User.current
  1514. message = JournalsForMessage.reference_message(@user.id)
  1515. message += Journal.reference_message(@user.id)
  1516. end
  1517. @activity_count = message.size
  1518. @info_pages = Paginator.new @activity_count, pre_count, params['page']
  1519. messages = message.sort {|x,y| y.created_on <=> x.created_on }
  1520. @message = messages[@info_pages.offset, @info_pages.per_page]
  1521. @state = 2
  1522. else
  1523. # Time 2015-02-04 10:50:49
  1524. # Author lizanle
  1525. # Description 所有动态
  1526. where_condition = nil;
  1527. # where_condition = "act_type <> 'JournalsForMessage'"
  1528. user_ids = []
  1529. if @user == User.current
  1530. watcher = User.watched_by(@user)
  1531. watcher.push(User.current)
  1532. user_ids = watcher.map{|x| x.id}
  1533. else
  1534. user_ids << @user.id
  1535. end
  1536. activity = Activity.where(where_condition).where(user_id: user_ids).order('id desc')
  1537. permission = !User.current.admin?
  1538. if permission
  1539. #Issue
  1540. act_ids = activity.where(act_type: 'Issue').select('act_id').map{|x| x.act_id}
  1541. project_ids = Issue.where(id: act_ids).select('distinct project_id').map{|x| x.project_id}
  1542. p_ids = []
  1543. Project.where(id: project_ids).each do |x|
  1544. p_ids << x.id unless x.visible?(User.current)
  1545. end
  1546. ids = []
  1547. ids << Issue.where(id: act_ids, project_id: p_ids).map{|x| x.id}
  1548. #HomeworkCommon
  1549. act_ids = activity.where(act_type: 'HomeworkCommon').select('act_id').map{|x| x.act_id}
  1550. course_ids = HomeworkCommon.where(id: act_ids).select('distinct course_id').map{|x| x.course_id}
  1551. c_ids = []
  1552. Course.where(id: course_ids).each do |x|
  1553. c_ids << x.id unless x.is_public !=0 && User.current.member_of_course?(x)
  1554. end
  1555. ids << HomeworkCommon.where(id: act_ids, course_id: c_ids).map{|x| x.id}
  1556. #Journal
  1557. act_ids = activity.where(act_type: 'Journal').select('act_id').map{|x| x.act_id}
  1558. project_ids = Journal.where(id:act_ids, journalized_type: 'Project').select('distinct journalized_id').map{|x| x.journalized_id}
  1559. p_ids = []
  1560. Project.where(id: project_ids).each do |x|
  1561. p_ids << x.id unless x.visible?(User.current)
  1562. end
  1563. ids << Journal.where(id: act_ids, journalized_id: p_ids, journalized_type: 'Project').map{|x| x.id}
  1564. #News
  1565. act_ids = activity.where(act_type: 'News').select('act_id').map{|x| x.act_id}
  1566. project_ids = News.where(id: act_ids).select('distinct project_id').map{|x| x.project_id}
  1567. p_ids = []
  1568. Project.where(id: project_ids).each do |x|
  1569. p_ids << x.id unless x.visible?(User.current)
  1570. end
  1571. ids << News.where(id: act_ids, project_id: p_ids).map{|x| x.id}
  1572. project_ids = News.where(id: act_ids).select('distinct course_id').map{|x| x.course_id}
  1573. c_ids = []
  1574. Course.where(id: project_ids).each do |x|
  1575. c_ids << x.id unless x.is_public !=0 && User.current.member_of_course?(x)
  1576. end
  1577. ids << News.where(id: act_ids, course_id: p_ids).map{|x| x.id}
  1578. #Message
  1579. act_ids = activity.where(act_type: 'Message').select('act_id').map{|x| x.act_id}
  1580. board_ids = Message.where(id: act_ids).select('distinct board_id').map{|x| x.board_id}
  1581. project_ids = Board.where(id: board_ids).select('distinct project_id').map{|x| x.project_id}
  1582. p_ids = []
  1583. Project.where(id: project_ids).each do |x|
  1584. p_ids << x.id unless x.visible?(User.current)
  1585. end
  1586. ids << Message.where(id: act_ids, board_id: p_ids).map{|x| x.id}
  1587. project_ids = Board.where(id: board_ids).select('distinct course_id').map{|x| x.course_id}
  1588. c_ids = []
  1589. Course.where(id: project_ids).each do |x|
  1590. c_ids << x.id unless x.is_public !=0 && User.current.member_of_course?(x)
  1591. end
  1592. ids << Message.where(id: act_ids, board_id: c_ids).map{|x| x.id}
  1593. logger.debug "filter ids #{ids}"
  1594. activity = activity.where('act_id not in (?)', ids.flatten ).order('id desc') unless ids.flatten.empty?
  1595. end
  1596. # activity = activity.reject { |e|
  1597. # e.act.nil? ||
  1598. # (!User.current.admin? && !e.act.nil?
  1599. # (((e.act_type == "Issue") && !e.act.project.visible?(User.current)) ||
  1600. # (e.act_type == "Bid" && !e.act.courses.first.nil? && e.act.courses.first.is_public == 0 && !User.current.member_of_course?(e.act.courses.first)) ||
  1601. # (e.act_type == "Journal" && e.act.respond_to?("Project") && !e.act.project.visible?(User.current)) ||
  1602. # (e.act_type == "News" && ((!e.act.project.nil? && !e.act.project.visible?(User.current)) || (!e.act.course.nil? && e.act.course.is_public == 0 && !User.current.member_of_course?(e.act.course)))) ||
  1603. # (e.act_type == "Message" && !e.act.board.nil? && ((!e.act.board.project.nil? && !e.act.board.project.visible?(User.current)) || (!e.act.board.course.nil? && e.act.board.course.is_public == 0 && !User.current.member_of_course?(e.act.board.course))))))
  1604. # }
  1605. #
  1606. @activity_count = activity.count
  1607. @activity_pages = Paginator.new @activity_count, pre_count, params['page']
  1608. @activity = activity.slice(@activity_pages.offset,@activity_pages.per_page)
  1609. @state = 0
  1610. end
  1611. if params[:user].present?
  1612. user_temp = User.find_by_sql("select id from users where concat(lastname,firstname) like '%#{params[:user]}%' or lastname like '%#{params[:user]}%'")
  1613. if user_temp.size > 1
  1614. activity = Activity.where('user_id in (?)', user_temp).where('user_id in (?)', watcher).order('id desc')
  1615. elsif user_temp.size == 1
  1616. activity = Activity.where('user_id = ?', user_temp).where('user_id in (?)', watcher).order('id desc')
  1617. else
  1618. activity = Activity.where("1 = 0")
  1619. end
  1620. @offset, @limit = api_offset_and_limit({:limit => 10})
  1621. @activity_count = activity.count
  1622. @activity_pages = Paginator.new @activity_count, @limit, params['page']
  1623. @offset ||= @activity_pages.offset
  1624. @activity = activity.offset(@offset).limit(@limit)
  1625. @state = 0
  1626. end
  1627. #Modified by nie
  1628. unless User.current.admin?
  1629. if !@user.active? #|| (@user != User.current && @memberships.empty? && events.empty?)
  1630. # redirect_to home_path
  1631. render_404
  1632. return
  1633. end
  1634. end
  1635. respond_to do |format|
  1636. format.html
  1637. format.api
  1638. end
  1639. end
  1640. ##end fq
  1641. #### added by fq
  1642. def info
  1643. message = []
  1644. if @user == User.current
  1645. message = JournalsForMessage.reference_message(@user.id)
  1646. message += Journal.reference_message(@user.id)
  1647. end
  1648. @offset, @limit = api_offset_and_limit({:limit => 10})
  1649. @info_count = message.size
  1650. @info_pages = Paginator.new @info_count, @limit, params['page']
  1651. @offset ||= @info_pages.offset
  1652. messages = message.sort {|x,y| y.created_on <=> x.created_on }
  1653. @message = messages[@offset, @limit]
  1654. unless User.current.admin?
  1655. if !@user.active?
  1656. render_404
  1657. return
  1658. end
  1659. end
  1660. respond_to do |format|
  1661. format.html
  1662. format.api
  1663. end
  1664. end
  1665. #### end
  1666. def new
  1667. @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option)
  1668. @auth_sources = AuthSource.all
  1669. render :layout => "users_base"
  1670. end
  1671. def create
  1672. @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option)
  1673. @user.safe_attributes = params[:user]
  1674. @user.admin = params[:user][:admin] || false
  1675. @user.login = params[:user][:login]
  1676. @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation] unless @user.auth_source_id
  1677. if @user.save
  1678. @user.pref.attributes = params[:pref]
  1679. @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
  1680. @user.pref.save
  1681. @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : [])
  1682. Mailer.run.account_information(@user, params[:user][:password]) if params[:send_information]
  1683. respond_to do |format|
  1684. format.html {
  1685. flash[:notice] = l(:notice_user_successful_create, :id => view_context.link_to(@user.login, user_path(@user)))
  1686. if params[:continue]
  1687. redirect_to new_user_url
  1688. else
  1689. redirect_to edit_user_url(@user)
  1690. end
  1691. }
  1692. format.api { render :action => 'show', :status => :created, :location => user_url(@user) }
  1693. end
  1694. else
  1695. @auth_sources = AuthSource.all
  1696. # Clear password input
  1697. @user.password = @user.password_confirmation = nil
  1698. respond_to do |format|
  1699. format.html { render :action => 'new',:layout => "users_base" }
  1700. format.api { render_validation_errors(@user) }
  1701. end
  1702. end
  1703. unless @user.id.nil?
  1704. #后台注册的用户默认权限为男性开发员
  1705. ue = UserExtensions.create(:identity => 3,
  1706. :gender => 0,
  1707. :user_id => @user.id)
  1708. ue.save
  1709. end
  1710. end
  1711. def edit
  1712. @auth_sources = AuthSource.all
  1713. @membership ||= Member.new
  1714. end
  1715. def watch_projects
  1716. @watch_projects = Project.joins(:watchers).where("project_type <>? and watchable_type = ? and `watchers`.user_id = ?", '1','Project', @user.id)
  1717. @state = 1
  1718. respond_to do |format|
  1719. format.html {
  1720. render :layout => 'base_users'
  1721. }
  1722. format.api
  1723. end
  1724. end
  1725. def update
  1726. @user.admin = params[:user][:admin] if params[:user][:admin]
  1727. @user.login = params[:user][:login] if params[:user][:login]
  1728. if params[:user][:password].present? && (@user.auth_source_id.nil? || params[:user][:auth_source_id].blank?)
  1729. @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation]
  1730. end
  1731. @user.safe_attributes = params[:user]
  1732. # Was the account actived ? (do it before User#save clears the change)
  1733. was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE])
  1734. # TODO: Similar to My#account
  1735. @user.pref.attributes = params[:pref]
  1736. @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
  1737. if @user.save
  1738. @user.pref.save
  1739. @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : [])
  1740. if was_activated
  1741. Mailer.run.account_activated(@user)
  1742. elsif @user.active? && params[:send_information] && !params[:user][:password].blank? && @user.auth_source_id.nil?
  1743. Mailer.run.account_information(@user, params[:user][:password])
  1744. end
  1745. respond_to do |format|
  1746. format.html {
  1747. flash[:notice] = l(:notice_successful_update)
  1748. redirect_to_referer_or edit_user_url(@user)
  1749. }
  1750. format.api { render_api_ok }
  1751. end
  1752. else
  1753. @auth_sources = AuthSource.all
  1754. @membership ||= Member.new
  1755. # Clear password input
  1756. @user.password = @user.password_confirmation = nil
  1757. respond_to do |format|
  1758. format.html { render :action => :edit }
  1759. format.api { render_validation_errors(@user) }
  1760. end
  1761. end
  1762. end
  1763. # 上传用户资源
  1764. def user_resource_create
  1765. user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id}
  1766. user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id }
  1767. # user_org_ids = User.current.organizations.map {|o| o.id}
  1768. @user = User.find(params[:id])
  1769. # 保存文件
  1770. attach = Attachment.attach_filesex_public(@user, params[:attachments], params[:attachment_type], is_public = true)
  1771. @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc"
  1772. @score = @b_sort == "desc" ? "asc" : "desc"
  1773. # user_org_ids = User.current.organizations.map {|o| o.id}
  1774. if(params[:type].blank? || params[:type] == "1") # 我的资源
  1775. # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
  1776. if params[:status] == "2"
  1777. @attachments = get_course_resources(params[:id], user_course_ids, @order, @score)
  1778. elsif params[:status] == "3"
  1779. @attachments = get_project_resources(params[:id], user_project_ids, @order, @score)
  1780. elsif params[:status] == "4"
  1781. @attachments = get_attch_resources(params[:id], @order, @score)
  1782. elsif params[:status] == "5"
  1783. @attachments = get_principal_resources(params[:id], @order, @score)
  1784. else
  1785. # 公共资源库:所有公开资源或者我上传的私有资源
  1786. @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score)
  1787. end
  1788. elsif params[:type] == "6" # 公共资源
  1789. if params[:status] == "2"
  1790. @attachments = get_course_resources_public( user_course_ids, @order, @score)
  1791. elsif params[:status] == "3"
  1792. @attachments = get_project_resources_public(user_project_ids, @order, @score)
  1793. elsif params[:status] == "4"
  1794. @attachments = get_attch_resources_public(@order, @score)
  1795. elsif params[:status] == "5"
  1796. @attachments = get_principal_resources_public(@order, @score)
  1797. else
  1798. # 公共资源库:所有公开资源或者我上传的私有资源
  1799. @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score)
  1800. end
  1801. end
  1802. @status = params[:status]
  1803. @type = params[:type]
  1804. @path = user_resource_user_path(User.current, :type => @type)
  1805. @limit = 25
  1806. @is_remote = true
  1807. @atta_count = @attachments.count
  1808. @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
  1809. @offset ||= @atta_pages.offset
  1810. #@curse_attachments_all = @all_attachments[@offset, @limit]
  1811. @attachments = paginateHelper @attachments,25
  1812. respond_to do |format|
  1813. format.js
  1814. end
  1815. end
  1816. # 删除用户资源,分为批量删除 和 单个删除,只能删除自己上传的资源
  1817. def user_resource_delete
  1818. if params[:resource_id].present?
  1819. Attachment.where("author_id =? and id =?", User.current.id, params[:resource_id]).first.destroy
  1820. elsif params[:checkbox1].present?
  1821. params[:checkbox1].each do |id|
  1822. Attachment.where("author_id =? and id =?", User.current.id, id).first.destroy
  1823. end
  1824. end
  1825. @user = User.current
  1826. @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc"
  1827. @score = @b_sort == "desc" ? "asc" : "desc"
  1828. user_course_ids = User.current.courses.map { |c| c.id}
  1829. user_project_ids = User.current.projects.map {|p| p.id}
  1830. # user_org_ids = User.current.organizations.map {|o| o.id}
  1831. if(params[:type].blank? || params[:type] == "1") # 我的资源
  1832. # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
  1833. if params[:status] == "2"
  1834. @attachments = get_course_resources(params[:id], user_course_ids, @order, @score)
  1835. elsif params[:status] == "3"
  1836. @attachments = get_project_resources(params[:id], user_project_ids, @order, @score)
  1837. elsif params[:status] == "4"
  1838. @attachments = get_attch_resources(params[:id], @order, @score)
  1839. elsif params[:status] == "5"
  1840. @attachments = get_principal_resources(params[:id], @order, @score)
  1841. else
  1842. # 公共资源库:所有公开资源或者我上传的私有资源
  1843. @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score)
  1844. end
  1845. elsif params[:type] == "6" # 公共资源
  1846. if params[:status] == "2"
  1847. @attachments = get_course_resources_public( user_course_ids, @order, @score)
  1848. elsif params[:status] == "3"
  1849. @attachments = get_project_resources_public(user_project_ids, @order, @score)
  1850. elsif params[:status] == "4"
  1851. @attachments = get_attch_resources_public(@order, @score)
  1852. elsif params[:status] == "5"
  1853. @attachments = get_principal_resources_public(@order, @score)
  1854. else
  1855. # 公共资源库:所有公开资源或者我上传的私有资源
  1856. @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score)
  1857. end
  1858. end
  1859. @status = params[:status]
  1860. @type = params[:type]
  1861. @path = user_resource_user_path(User.current, :type => @type)
  1862. @limit = 25
  1863. @is_remote = true
  1864. @atta_count = @attachments.count
  1865. @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
  1866. @offset ||= @atta_pages.offset
  1867. #@curse_attachments_all = @all_attachments[@offset, @limit]
  1868. @attachments = paginateHelper @attachments,25
  1869. respond_to do |format|
  1870. format.js
  1871. end
  1872. end
  1873. #根据id或者名称搜索教师或者助教为当前用户的课程
  1874. def search_user_course
  1875. @user = User.current
  1876. if !params[:search].nil?
  1877. search = "%#{params[:search].to_s.strip.downcase}%"
  1878. @course = @user.courses.where(" #{Course.table_name}.id = #{params[:search].to_i } or #{Course.table_name}.name like :p",:p=>search)
  1879. .select { |course| @user.allowed_to?(:as_teacher,course) and course.is_delete == 0 }
  1880. else
  1881. @course = @user.courses
  1882. .select { |course| @user.allowed_to?(:as_teacher,course) and course.is_delete == 0 }
  1883. end
  1884. @search = params[:search]
  1885. @type = params[:type]
  1886. #这里仅仅是传递需要发送的资源id
  1887. @send_id = params[:send_id]
  1888. @send_ids = params[:checkbox1] || params[:send_ids]
  1889. respond_to do |format|
  1890. format.js
  1891. end
  1892. end
  1893. # 根据id或者名称搜索当前用户所在的项目
  1894. def search_user_project
  1895. @user = User.current
  1896. if !params[:search].nil?
  1897. search = "%#{params[:search].to_s.strip.downcase}%"
  1898. @projects = @user.projects.where(" #{Project.table_name}.id = #{params[:search].to_i } or #{Project.table_name}.name like :p",:p=>search)
  1899. else
  1900. @projects = @user.projects.visible
  1901. end
  1902. @search = params[:search]
  1903. @type = params[:type]
  1904. #这里仅仅是传递需要发送的资源id
  1905. @send_id = params[:send_id]
  1906. @send_ids = params[:checkbox1] || params[:send_ids] #搜索的时候 和 直接 用表格提交的时候的send_ids
  1907. respond_to do |format|
  1908. format.js
  1909. end
  1910. end
  1911. # 将资源发送到对应的课程,分为发送单个,或者批量发送
  1912. def add_exist_file_to_course
  1913. @flag = true
  1914. if params[:send_id].present?
  1915. rs = ResourcesService.new
  1916. @ori, @flag, @save_message = rs.send_resource_to_course(User.current, params)
  1917. elsif params[:send_ids].present?
  1918. send_ids = params[:send_ids].split(",")
  1919. course_ids = params[:course_ids]
  1920. if course_ids.nil?
  1921. @flag = false
  1922. end
  1923. send_ids.each do |send_id|
  1924. quotes = 0
  1925. @ori = Attachment.find_by_id(send_id)
  1926. unless course_ids.nil?
  1927. course_ids.each do |id|
  1928. quotes = 0
  1929. next if @ori.blank?
  1930. @exist = false
  1931. Course.find(id).attachments.each do |att| #如果课程中包含该资源
  1932. if att.id == @ori.id || (!att.copy_from.nil? && !@ori.copy_from.nil? && att.copy_from == @ori.copy_from) || att.copy_from == @ori.id || att.id == @ori.copy_from
  1933. att.created_on = Time.now
  1934. att.save
  1935. @exist = true
  1936. break
  1937. end
  1938. end
  1939. next if @exist
  1940. attach_copied_obj = @ori.copy
  1941. attach_copied_obj.tag_list.add(@ori.tag_list) # tag关联
  1942. attach_copied_obj.container = Course.find(id)
  1943. attach_copied_obj.created_on = Time.now
  1944. attach_copied_obj.author_id = User.current.id
  1945. attach_copied_obj.is_public = 0
  1946. attach_copied_obj.copy_from = @ori.copy_from.nil? ? @ori.id : @ori.copy_from #发送要添加copy_from
  1947. if attach_copied_obj.attachtype == nil
  1948. attach_copied_obj.attachtype = 4
  1949. end
  1950. if attach_copied_obj.save
  1951. # 更新引用次数
  1952. quotes = @ori.quotes.to_i + 1
  1953. @ori.update_attribute(:quotes, quotes) unless @ori.nil?
  1954. @ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now)
  1955. end
  1956. @save_message = attach_copied_obj.errors.full_messages
  1957. end
  1958. end
  1959. end
  1960. else
  1961. @flag = false
  1962. end
  1963. @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc"
  1964. @score = @b_sort == "desc" ? "asc" : "desc"
  1965. user_project_ids = User.current.projects.map {|p| p.id}
  1966. user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
  1967. if(params[:type] == "1") # 我的资源
  1968. # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
  1969. if params[:status] == "2"
  1970. @attachments = get_course_resources(params[:id], user_course_ids, @order, @score)
  1971. elsif params[:status] == "3"
  1972. @attachments = get_project_resources(params[:id], user_project_ids, @order, @score)
  1973. elsif params[:status] == "4"
  1974. @attachments = get_attch_resources(params[:id], @order, @score)
  1975. elsif params[:status] == "5"
  1976. @attachments = get_principal_resources(params[:id], @order, @score)
  1977. else
  1978. # 公共资源库:所有公开资源或者我上传的私有资源
  1979. @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score)
  1980. end
  1981. elsif (params[:type].blank? || params[:type] == "6") # 公共资源
  1982. if params[:status] == "2"
  1983. @attachments = get_course_resources_public( user_course_ids, @order, @score)
  1984. elsif params[:status] == "3"
  1985. @attachments = get_project_resources_public(user_project_ids, @order, @score)
  1986. elsif params[:status] == "4"
  1987. @attachments = get_attch_resources_public(@order, @score)
  1988. elsif params[:status] == "5"
  1989. @attachments = get_principal_resources_public(@order, @score)
  1990. else
  1991. # 公共资源库:所有公开资源或者我上传的私有资源
  1992. @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score)
  1993. end
  1994. # elsif params[:type] == "2"
  1995. # apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id}
  1996. # if params[:status] == "2"
  1997. # resource_type = "'Course'"
  1998. # elsif params[:status] == "3"
  1999. # resource_type = "'Project'"
  2000. # elsif params[:status] == "5"
  2001. # resource_type = "'Principal'"
  2002. # else
  2003. # resource_type = "'Project','OrgSubfield','Principal','Course'"
  2004. # end
  2005. # @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score)
  2006. end
  2007. @type = params[:type]
  2008. @limit = 25
  2009. @path = user_resource_user_path(User.current, :type => @type)
  2010. @user = User.current
  2011. @is_remote = true
  2012. @atta_count = @attachments.count
  2013. @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
  2014. @offset ||= @atta_pages.offset
  2015. #@curse_attachments_all = @all_attachments[@offset, @limit]
  2016. @attachments = paginateHelper @attachments,25
  2017. respond_to do |format|
  2018. format.js
  2019. end
  2020. end
  2021. # 添加资源到对应的项目
  2022. def add_exist_file_to_project
  2023. @flag = true
  2024. # 发送单个资源
  2025. if params[:send_id].present?
  2026. send_id = params[:send_id]
  2027. project_ids = params[:projects_ids]
  2028. if project_ids.nil?
  2029. @flag = false
  2030. end
  2031. ori = Attachment.find_by_id(send_id)
  2032. unless project_ids.nil?
  2033. project_ids.each do |project_id|
  2034. next if ori.blank?
  2035. @exist = false
  2036. # 如果对象中包含该资源
  2037. Project.find(project_id).attachments.each do |att|
  2038. if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from
  2039. att.created_on = Time.now
  2040. att.save
  2041. @exist = true
  2042. break
  2043. end
  2044. end
  2045. next if @exist
  2046. attach_copied_obj = ori.copy
  2047. attach_copied_obj.tag_list.add(ori.tag_list) # tag关联
  2048. attach_copied_obj.container = Project.find(project_id)
  2049. attach_copied_obj.created_on = Time.now
  2050. attach_copied_obj.author_id = User.current.id
  2051. attach_copied_obj.is_public = 0
  2052. attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from
  2053. if attach_copied_obj.attachtype == nil
  2054. attach_copied_obj.attachtype = 1
  2055. end
  2056. if attach_copied_obj.save
  2057. # 更新引用次数
  2058. quotes = ori.quotes.to_i + 1
  2059. ori.update_attribute(:quotes, quotes) unless ori.nil?
  2060. ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now)
  2061. # 项目中添加动态
  2062. ForgeActivity.create(:user_id => User.current.id, :project_id => project_id, :forge_act_id => attach_copied_obj.id, :forge_act_type => "Attachment" )
  2063. end
  2064. unless Project.find(project_id).project_score.nil?
  2065. Project.find(project_id).project_score.update_attribute(:attach_num,
  2066. Project.find(project_id).project_score.attach_num + 1)
  2067. end
  2068. end
  2069. @ori = ori
  2070. end
  2071. # 发送多个资源
  2072. elsif params[:send_ids].present?
  2073. send_ids = params[:send_ids].split(",")
  2074. project_ids = params[:projects_ids]
  2075. if project_ids.nil?
  2076. @flag = false
  2077. end
  2078. send_ids.each do |send_id|
  2079. quotes = 0
  2080. ori = Attachment.find_by_id(send_id)
  2081. unless project_ids.nil?
  2082. project_ids.each do |project_id|
  2083. quotes = 0
  2084. next if ori.blank?
  2085. @exist = false
  2086. Project.find(project_id).attachments.each do |att| #如果课程中包含该资源
  2087. if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from
  2088. att.created_on = Time.now
  2089. att.save
  2090. @exist = true
  2091. break
  2092. end
  2093. end
  2094. next if @exist
  2095. attach_copied_obj = ori.copy
  2096. attach_copied_obj.tag_list.add(ori.tag_list) # tag关联
  2097. attach_copied_obj.container = Project.find(project_id)
  2098. attach_copied_obj.created_on = Time.now
  2099. attach_copied_obj.author_id = User.current.id
  2100. attach_copied_obj.is_public = 0
  2101. attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from
  2102. if attach_copied_obj.attachtype == nil
  2103. attach_copied_obj.attachtype = 1
  2104. end
  2105. if attach_copied_obj.save
  2106. # 更新引用次数
  2107. quotes = ori.quotes.to_i + 1
  2108. ori.update_attribute(:quotes, quotes) unless ori.nil?
  2109. ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now)
  2110. # 项目中添加动态
  2111. ForgeActivity.create(:user_id => User.current.id, :project_id => project_id, :forge_act_id => attach_copied_obj.id, :forge_act_type => "Attachment" )
  2112. end
  2113. unless Project.find(project_id).project_score.nil?
  2114. Project.find(project_id).project_score.update_attribute(:attach_num, Project.find(project_id).project_score.attach_num + 1)
  2115. end
  2116. end
  2117. end
  2118. end
  2119. else
  2120. @flag=true
  2121. end
  2122. @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc"
  2123. @score = @b_sort == "desc" ? "asc" : "desc"
  2124. user_project_ids = User.current.projects.map {|p| p.id}
  2125. user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
  2126. if(params[:type] == "1") # 我的资源
  2127. # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
  2128. if params[:status] == "2"
  2129. @attachments = get_course_resources(params[:id], user_course_ids, @order, @score)
  2130. elsif params[:status] == "3"
  2131. @attachments = get_project_resources(params[:id], user_project_ids, @order, @score)
  2132. elsif params[:status] == "4"
  2133. @attachments = get_attch_resources(params[:id], @order, @score)
  2134. elsif params[:status] == "5"
  2135. @attachments = get_principal_resources(params[:id], @order, @score)
  2136. else
  2137. # 公共资源库:所有公开资源或者我上传的私有资源
  2138. @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score)
  2139. end
  2140. elsif (params[:type].blank? || params[:type] == "6") # 公共资源
  2141. if params[:status] == "2"
  2142. @attachments = get_course_resources_public( user_course_ids, @order, @score)
  2143. elsif params[:status] == "3"
  2144. @attachments = get_project_resources_public(user_project_ids, @order, @score)
  2145. elsif params[:status] == "4"
  2146. @attachments = get_attch_resources_public(@order, @score)
  2147. elsif params[:status] == "5"
  2148. @attachments = get_principal_resources_public(@order, @score)
  2149. else
  2150. # 公共资源库:所有公开资源或者我上传的私有资源
  2151. @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score)
  2152. end
  2153. # elsif params[:type] == "2"
  2154. # apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id}
  2155. # if params[:status] == "2"
  2156. # resource_type = "'Course'"
  2157. # elsif params[:status] == "3"
  2158. # resource_type = "'Project'"
  2159. # elsif params[:status] == "5"
  2160. # resource_type = "'Principal'"
  2161. # else
  2162. # resource_type = "'Project','OrgSubfield','Principal','Course'"
  2163. # end
  2164. # @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score)
  2165. end
  2166. @status = params[:status]
  2167. @type = params[:type]
  2168. @limit = 25
  2169. @path = user_resource_user_path(User.current, :type => @type)
  2170. @user = User.current
  2171. @is_remote = true
  2172. @atta_count = @attachments.count
  2173. @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
  2174. @offset ||= @atta_pages.offset
  2175. #@curse_attachments_all = @all_attachments[@offset, @limit]
  2176. @attachments = paginateHelper @attachments,25
  2177. respond_to do |format|
  2178. format.js
  2179. end
  2180. end
  2181. def add_exist_file_to_org
  2182. @flag = true
  2183. if params[:send_id].present?
  2184. send_id = params[:send_id]
  2185. subfield_id = params[:subfield]
  2186. if subfield_id.nil?
  2187. @flag = false
  2188. end
  2189. ori = Attachment.find_by_id(send_id)
  2190. unless subfield_id.nil?
  2191. attach_copied_obj = ori.copy
  2192. @exist = false
  2193. OrgSubfield.find(subfield_id).attachments.each do |att| #如果课程中包含该资源
  2194. if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from
  2195. att.created_on = Time.now
  2196. att.save
  2197. @exist = true
  2198. break
  2199. end
  2200. end
  2201. if @exist == false #如果不存在该资源
  2202. attach_copied_obj.tag_list.add(ori.tag_list) # tag关联
  2203. attach_copied_obj.container = OrgSubfield.find(subfield_id)
  2204. attach_copied_obj.created_on = Time.now
  2205. attach_copied_obj.author_id = User.current.id
  2206. attach_copied_obj.is_public = 0
  2207. attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from
  2208. if attach_copied_obj.attachtype == nil
  2209. attach_copied_obj.attachtype = 1
  2210. end
  2211. if attach_copied_obj.save
  2212. # 更新引用次数
  2213. quotes = ori.quotes.to_i + 1
  2214. ori.update_attribute(:quotes, quotes) unless ori.nil?
  2215. ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now)
  2216. end
  2217. end
  2218. end
  2219. @ori = ori
  2220. elsif params[:send_ids].present?
  2221. send_ids = params[:send_ids].split(",")
  2222. subfield_id = params[:subfield]
  2223. if subfield_id.nil?
  2224. @flag = false
  2225. end
  2226. send_ids.each do |send_id|
  2227. quotes = 0
  2228. ori = Attachment.find_by_id(send_id)
  2229. unless subfield_id.nil?
  2230. next if ori.blank?
  2231. @exist = false
  2232. OrgSubfield.find(subfield_id).attachments.each do |att| #如果课程中包含该资源
  2233. if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from
  2234. att.created_on = Time.now
  2235. att.save
  2236. @exist = true
  2237. break
  2238. end
  2239. end
  2240. next if @exist
  2241. attach_copied_obj = ori.copy
  2242. attach_copied_obj.tag_list.add(ori.tag_list) # tag关联
  2243. attach_copied_obj.container = OrgSubfield.find(subfield_id)
  2244. attach_copied_obj.created_on = Time.now
  2245. attach_copied_obj.author_id = User.current.id
  2246. attach_copied_obj.is_public = 0
  2247. attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from
  2248. if attach_copied_obj.attachtype == nil
  2249. attach_copied_obj.attachtype = 1
  2250. end
  2251. if attach_copied_obj.save
  2252. # 更新引用次数
  2253. quotes = ori.quotes.to_i + 1
  2254. ori.update_attribute(:quotes, quotes) unless ori.nil?
  2255. ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now)
  2256. end
  2257. end
  2258. end
  2259. else
  2260. @flag=true
  2261. end
  2262. @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc"
  2263. @score = @b_sort == "desc" ? "asc" : "desc"
  2264. user_project_ids = User.current.projects.map {|p| p.id}
  2265. user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
  2266. if(params[:type] == "1") # 我的资源
  2267. # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
  2268. if params[:status] == "2"
  2269. @attachments = get_course_resources(params[:id], user_course_ids, @order, @score)
  2270. elsif params[:status] == "3"
  2271. @attachments = get_project_resources(params[:id], user_project_ids, @order, @score)
  2272. elsif params[:status] == "4"
  2273. @attachments = get_attch_resources(params[:id], @order, @score)
  2274. elsif params[:status] == "5"
  2275. @attachments = get_principal_resources(params[:id], @order, @score)
  2276. else
  2277. # 公共资源库:所有公开资源或者我上传的私有资源
  2278. @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score)
  2279. end
  2280. elsif (params[:type].blank? || params[:type] == "6") # 公共资源
  2281. if params[:status] == "2"
  2282. @attachments = get_course_resources_public( user_course_ids, @order, @score)
  2283. elsif params[:status] == "3"
  2284. @attachments = get_project_resources_public(user_project_ids, @order, @score)
  2285. elsif params[:status] == "4"
  2286. @attachments = get_attch_resources_public(@order, @score)
  2287. elsif params[:status] == "5"
  2288. @attachments = get_principal_resources_public(@order, @score)
  2289. else
  2290. # 公共资源库:所有公开资源或者我上传的私有资源
  2291. @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score)
  2292. end
  2293. # elsif params[:type] == "2"
  2294. # apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id}
  2295. # if params[:status] == "2"
  2296. # resource_type = "'Course'"
  2297. # elsif params[:status] == "3"
  2298. # resource_type = "'Project'"
  2299. # elsif params[:status] == "5"
  2300. # resource_type = "'Principal'"
  2301. # else
  2302. # resource_type = "'Project','OrgSubfield','Principal','Course'"
  2303. # end
  2304. # @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score)
  2305. end
  2306. @type = params[:type]
  2307. @limit = 25
  2308. @path = user_resource_user_path(User.current, :type => @type)
  2309. @user = User.current
  2310. @is_remote = true
  2311. @atta_count = @attachments.count
  2312. @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
  2313. @offset ||= @atta_pages.offset
  2314. #@curse_attachments_all = @all_attachments[@offset, @limit]
  2315. @attachments = paginateHelper @attachments,25
  2316. respond_to do |format|
  2317. format.js
  2318. end
  2319. end
  2320. def share_news_to_course
  2321. news = News.find(params[:send_id])
  2322. course_ids = params[:course_ids]
  2323. course_ids.each do |course_id|
  2324. if Course.find(course_id).news.map(&:id).exclude?(news.id)
  2325. course_news = News.create(:course_id => course_id.to_i, :title => news.title, :summary => news.summary, :description => news.description,:author_id => User.current.id, :created_on => Time.now,:project_id => -1)
  2326. #record forward to table forwards if new record is valid
  2327. if course_news.valid?
  2328. news.forwards << Forward.new(:to_type => course_news.class.name, :to_id => course_news.id)
  2329. end
  2330. news.attachments.each do |attach|
  2331. course_news.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest,
  2332. :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype,
  2333. :is_public => attach.is_public, :quotes => 0)
  2334. end
  2335. end
  2336. end
  2337. end
  2338. def share_news_to_project
  2339. news = News.find(params[:send_id])
  2340. project_ids = params[:project_ids]
  2341. project_ids.each do |project_id|
  2342. project = Project.find(project_id)
  2343. if project.news.map(&:id).exclude?(news.id)
  2344. message = Message.create(:board_id => project.boards.first.id, :subject => news.title, :content => news.description, :author_id => User.current.id)
  2345. # record forward to table forwards if new record is valid
  2346. if message.valid?
  2347. news.forwards << Forward.new(:to_type => message.class.name, :to_id => message.id)
  2348. end
  2349. news.attachments.each do |attach|
  2350. message.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest,
  2351. :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype,
  2352. :is_public => attach.is_public, :quotes => 0)
  2353. end
  2354. end
  2355. end
  2356. end
  2357. def share_news_to_org
  2358. news = News.find(params[:send_id])
  2359. field_id = params[:subfield]
  2360. org_news = News.create(:org_subfield_id => field_id.to_i, :title => news.title, :summary => news.summary, :description => news.description,:author_id => User.current.id, :created_on => Time.now,:project_id => -1)
  2361. # record forward to table forwards if new record is valid
  2362. if org_news.valid?
  2363. news.forwards << Forward.new(:to_type => org_news.class.name, :to_id => org_news.id)
  2364. end
  2365. news.attachments.each do |attach|
  2366. org_news.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest,
  2367. :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype,
  2368. :is_public => attach.is_public, :quotes => 0)
  2369. end
  2370. OrgActivity.create(:container_type => 'OrgSubfield', :container_id => field_id.to_i, :org_act_type=>'News', :org_act_id => org_news.id, :user_id => User.current.id)
  2371. end
  2372. def share_message_to_course
  2373. @message = Message.find(params[:send_id])
  2374. course_ids = params[:course_ids]
  2375. course_ids.each do |course_id|
  2376. course = Course.find(course_id)
  2377. if course.news.map(&:id).exclude?(@message.id)
  2378. message = Message.create(:board_id => course.boards.first.id, :subject => @message.subject, :content => @message.content, :author_id => User.current.id)
  2379. # record forward to table forwards if new record is valid
  2380. if message.valid?
  2381. @message.forwards << Forward.new(:to_type => message.class.name, :to_id => message.id)
  2382. end
  2383. @message.attachments.each do |attach|
  2384. message.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest,
  2385. :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype,
  2386. :is_public => attach.is_public, :quotes => 0)
  2387. end
  2388. end
  2389. end
  2390. end
  2391. def share_message_to_project
  2392. @message = Message.find(params[:send_id])
  2393. project_ids = params[:project_ids]
  2394. project_ids.each do |project_id|
  2395. project = Project.find(project_id)
  2396. if project.news.map(&:id).exclude?(@message.id)
  2397. message = Message.create(:board_id => project.boards.first.id, :subject => @message.subject, :content => @message.content, :author_id => User.current.id)
  2398. # record forward to table forwards if new record is valid
  2399. if message.valid?
  2400. @message.forwards << Forward.new(:to_type => message.class.name, :to_id => message.id)
  2401. end
  2402. @message.attachments.each do |attach|
  2403. message.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest,
  2404. :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype,
  2405. :is_public => attach.is_public, :quotes => 0)
  2406. end
  2407. end
  2408. end
  2409. end
  2410. def share_message_to_org
  2411. field_id = params[:subfield]
  2412. @message = Message.find(params[:send_id])
  2413. @message.quotes = @message.quotes.nil? ? 1 : (@message.quotes + 1)
  2414. @message.save
  2415. board = OrgSubfield.find(field_id).boards.first
  2416. mes = Message.create(:board_id => board.id, :subject => @message.subject, :content => @message.content, :author_id => User.current.id)
  2417. # record forward to table forwards if new record is valid
  2418. if mes.valid?
  2419. @message.forwards << Forward.new(:to_type => mes.class.name, :to_id => mes.id)
  2420. end
  2421. @message.attachments.each do |attach|
  2422. mes.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest,
  2423. :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype,
  2424. :is_public => attach.is_public, :quotes => 0)
  2425. end
  2426. OrgActivity.create(:container_type => 'OrgSubfield', :container_id => field_id.to_i, :org_act_type=>'Message', :org_act_id => mes.id, :user_id => User.current.id)
  2427. end
  2428. def change_org_subfield
  2429. end
  2430. # 资源预览
  2431. def resource_preview
  2432. preview_id = params[:resource_id]
  2433. @file = Attachment.find(preview_id)
  2434. @preview_able = false;
  2435. if %w(pdf pptx doc docx xls xlsx).any?{|x| @file.filename.downcase.end_with?(x)}
  2436. @preview_able = true;
  2437. end
  2438. respond_to do |format|
  2439. format.js
  2440. end
  2441. end
  2442. # 重命名资源
  2443. def rename_resource
  2444. @attachment = Attachment.find(params[:res_id]) if params[:res_id].present?
  2445. if @attachment != nil
  2446. @attachment.filename = params[:res_name]
  2447. @flag = @attachment.save
  2448. end
  2449. # respond_to do |format|
  2450. # format.js
  2451. # end
  2452. if @flag
  2453. render :text=> download_named_attachment_path(@attachment.id, @attachment.filename)
  2454. else
  2455. render :text=>'fail'
  2456. end
  2457. end
  2458. def destroy
  2459. @user.destroy
  2460. respond_to do |format|
  2461. format.html { redirect_back_or_default(admin_users_path) }
  2462. format.api { render_api_ok }
  2463. end
  2464. end
  2465. def edit_membership
  2466. @membership = Member.edit_membership(params[:membership_id], params[:membership], @user)
  2467. @membership.save
  2468. respond_to do |format|
  2469. format.html { redirect_to edit_user_url(@user, :tab => 'memberships') }
  2470. format.js
  2471. end
  2472. end
  2473. def destroy_membership
  2474. @membership = Member.find(params[:membership_id])
  2475. if @membership.deletable?
  2476. @membership.destroy
  2477. end
  2478. respond_to do |format|
  2479. format.html { redirect_to edit_user_url(@user, :tab => 'memberships') }
  2480. format.js
  2481. end
  2482. end
  2483. ################# added by william
  2484. def tag_save
  2485. @tags = params[:tag_for_save][:name]
  2486. @obj_id = params[:tag_for_save][:object_id]
  2487. @obj_flag = params[:tag_for_save][:object_flag]
  2488. case @obj_flag
  2489. when '1' then
  2490. @obj = User.find_by_id(@obj_id)
  2491. when '2' then
  2492. @obj = Project.find_by_id(@obj_id)
  2493. when '3' then
  2494. @obj = Issue.find_by_id(@obj_id)
  2495. when '4' then
  2496. # @obj = Bid.find_by_id(@obj_id)
  2497. when '5' then
  2498. @obj = Forum.find_by_id(@obj_id)
  2499. when '6'
  2500. @obj = Attachment.find_by_id(@obj_id)
  2501. when '7' then
  2502. @obj = Contest.find_by_id(@obj_id)
  2503. when '8'
  2504. @obj = OpenSourceProject.find_by_id(@obj_id)
  2505. when '9'
  2506. @obj = Course.find_by_id(@obj_id)
  2507. else
  2508. @obj = nil
  2509. end
  2510. unless @obj.nil?
  2511. @obj.tag_list.add(@tags.split(","))
  2512. else
  2513. return
  2514. end
  2515. if @obj.save
  2516. logger.debug "#{__FILE__}:#{__LINE__} ===> #{@obj.to_json}"
  2517. else
  2518. logger.error "#{__FILE__}:#{__LINE__} ===> #{@obj.errors.try(:full_messages)}"
  2519. end
  2520. respond_to do |format|
  2521. format.js
  2522. format.html
  2523. end
  2524. end
  2525. def tag_saveEx
  2526. @tags = params[:tag_name]
  2527. @obj_id = params[:obj_id]
  2528. @obj_flag = params[:obj_flag]
  2529. case @obj_flag
  2530. when '1' then
  2531. @obj = User.find_by_id(@obj_id)
  2532. when '2' then
  2533. @obj = Project.find_by_id(@obj_id)
  2534. when '3' then
  2535. @obj = Issue.find_by_id(@obj_id)
  2536. when '4' then
  2537. # @obj = Bid.find_by_id(@obj_id)
  2538. when '5' then
  2539. @obj = Forum.find_by_id(@obj_id)
  2540. when '6'
  2541. @obj = Attachment.find_by_id(@obj_id)
  2542. when '7' then
  2543. @obj = Contest.find_by_id(@obj_id)
  2544. when '8'
  2545. @obj = OpenSourceProject.find_by_id(@obj_id)
  2546. when '9'
  2547. @obj = Course.find_by_id(@obj_id)
  2548. else
  2549. @obj = nil
  2550. end
  2551. unless @obj.nil?
  2552. @obj.tag_list.add(@tags.split(","))
  2553. else
  2554. return
  2555. end
  2556. if @obj.save
  2557. ## 执行成功的操作。
  2558. else
  2559. #捕获异常
  2560. end
  2561. respond_to do |format|
  2562. format.js
  2563. format.html
  2564. end
  2565. end
  2566. ###add by huang
  2567. def user_watchlist
  2568. limit = 10;
  2569. query = User.watched_by(@user.id);
  2570. @obj_count = query.count();
  2571. @obj_pages = Paginator.new @obj_count,limit,params['page']
  2572. @list = query.order("#{Watcher.table_name}.id desc").limit(limit).offset(@obj_pages.offset).all();
  2573. @action = 'watch'
  2574. render :template=>'users/user_fanslist',:layout=>'new_base_user'
  2575. end
  2576. ###add by huang
  2577. def user_fanslist
  2578. limit = 10;
  2579. query = @user.watcher_users;
  2580. @obj_count = query.count();
  2581. @obj_pages = Paginator.new @obj_count,limit,params['page']
  2582. @list = query.order("#{Watcher.table_name}.id desc").limit(limit).offset(@obj_pages.offset).all();
  2583. @action = 'fans'
  2584. render :layout=>'new_base_user'
  2585. end
  2586. def user_visitorlist
  2587. limit = 10;
  2588. #query = @user.watcher_users;
  2589. query = User.joins("join visitors v on #{User.table_name}.id=v.user_id")
  2590. query = query.where("v.master_id=?",@user.id)
  2591. @obj_count = query.count();
  2592. @obj_pages = Paginator.new @obj_count,limit,params['page']
  2593. @list = query.order("v.updated_on desc").limit(limit).offset(@obj_pages.offset).all();
  2594. @action = 'visitor'
  2595. render :template=>'users/user_fanslist',:layout=>'base_users_new'
  2596. end
  2597. #william
  2598. def update_extensions(user_extensions)
  2599. user_extensions = params[:user_extensions]
  2600. unless user_extensions.nil?
  2601. user_extensions = UserExtensions.find_by_id(user_extensions.user_id)
  2602. # user_extensions.
  2603. end
  2604. end
  2605. def update_score
  2606. @user = User.find(params[:id])
  2607. end
  2608. #修改个人简介
  2609. def edit_brief_introduction
  2610. if @user && @user.extensions
  2611. @user.extensions.update_column("brief_introduction",params[:brief_introduction])
  2612. end
  2613. respond_to do |format|
  2614. format.js
  2615. end
  2616. end
  2617. # 获取公共资源
  2618. def get_public_resources user_course_ids, user_project_ids, order, score
  2619. attachments = Attachment.where("(is_publish = 1 and is_public = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course')) ").order("#{order.nil? ? 'created_on' : order} #{score}")
  2620. end
  2621. # 获取公共资源搜索
  2622. def get_public_resources_search user_course_ids, user_project_ids, order, score, search
  2623. attachments = Attachment.where("is_publish = 1 and is_public = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course') and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}")
  2624. end
  2625. # 获取我的资源
  2626. def get_my_resources author_id, user_course_ids, user_project_ids, order, score
  2627. attachments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('OrgSubfield','Principal','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
  2628. "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" +
  2629. "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)" ).order("#{order.nil? ? 'created_on' : order} #{score}")
  2630. end
  2631. # 获取我的资源查询结果
  2632. def get_my_resources_search (author_id, user_course_ids, user_project_ids, order, score, search)
  2633. @attachments = Attachment.where("((author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
  2634. "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" +
  2635. "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)) and (filename like :p)" ,:p => search).order("#{order.nil? ? 'created_on' : order} #{score}")
  2636. end
  2637. # 获取我的课程资源
  2638. def get_course_resources author_id, user_course_ids, order, score
  2639. attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and container_type = 'Course')"+
  2640. "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')})
  2641. and is_publish = 1 and container_id is not null)" ).order("#{order.nil? ? 'created_on' : order} #{score}")
  2642. end
  2643. # # 获取我的私有资源分享结果
  2644. # def get_my_private_resources apply_ids, resource_type, order, score
  2645. # attachments = Attachment.where("id in (#{apply_ids.empty? ? '0': apply_ids.join(',')}) and container_type in(#{resource_type})").order("#{order.nil? ? 'created_on' : order} #{score}")
  2646. # end
  2647. #
  2648. # # 获取我的私有资源分享搜索结果
  2649. # def get_my_private_resources_search apply_ids, resource_type, order, score, search
  2650. # attachments = Attachment.where("id in (#{apply_ids.empty? ? '0': apply_ids.join(',')}) and container_type in(#{resource_type}) and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}")
  2651. # end
  2652. # 获取我的课程资源中搜索结果
  2653. def get_course_resources_search author_id, user_course_ids, order, score, search
  2654. attchments = Attachment.where("((author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Course')"+
  2655. "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')})
  2656. and is_publish = 1 and container_id is not null)) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}")
  2657. end
  2658. # 获取公共资源中课程资源
  2659. def get_course_resources_public user_course_ids, order, score
  2660. attchments = Attachment.where("(container_type = 'Course'and container_id is not null and is_publish = 1 and is_public =1)").order("#{order.nil? ? 'created_on' : order} #{score}")
  2661. end
  2662. # 获取公共资源中课程资源搜索结果
  2663. def get_course_resources_public_search user_course_ids, order, score, search
  2664. attchments = Attachment.where("(container_type = 'Course'and container_id is not null and is_publish = 1 and is_public =1) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}")
  2665. end
  2666. # 获取我的项目资源
  2667. def get_project_resources author_id, user_project_ids, order, score
  2668. attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Project') "+
  2669. "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')})
  2670. and is_publish = 1 and container_id is not null)").order("#{order.nil? ? 'created_on' : order} #{score}")
  2671. end
  2672. # 获取我的项目资源搜索
  2673. def get_project_resources_search author_id, user_project_ids, order, score, search
  2674. attchments = Attachment.where("((author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Project') "+
  2675. "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')})
  2676. and is_publish = 1 and container_id is not null)) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}")
  2677. end
  2678. # 获取公共资源的项目资源
  2679. def get_project_resources_public user_project_ids, order, score
  2680. attchments = Attachment.where("container_type = 'Project' and container_id is not null and is_public =1").order("#{order.nil? ? 'created_on' : order} #{score}")
  2681. end
  2682. # 获取公共资源的项目资源搜索
  2683. def get_project_resources_public_search user_project_ids, order, score, search
  2684. attchments = Attachment.where("(container_type = 'Project' and container_id is not null and is_public =1) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}")
  2685. end
  2686. # 获取我上传的附件
  2687. def get_attch_resources author_id, order, score
  2688. attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue',
  2689. 'Document','Message','News','StudentWorkScore','HomewCommon'))").order("#{order.nil? ? 'created_on' : order} #{score}")
  2690. end
  2691. # 获取我上传的附件搜索结果
  2692. def get_attch_resources_search author_id, order, score, search
  2693. attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue',
  2694. 'Document','Message','News','StudentWorkScore','HomewCommon')) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}")
  2695. end
  2696. # 获取公共资源中我上传的附件
  2697. def get_attch_resources_public order, score
  2698. attchments = Attachment.where("container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')
  2699. and container_id is not null and is_public =1").order("#{order.nil? ? 'created_on' : order} #{score}")
  2700. end
  2701. # 获取公共资源中我上传的附件
  2702. def get_attch_resources_public_search order, score, search
  2703. attchments = Attachment.where("(container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')
  2704. and container_id is not null and is_public =1) and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}")
  2705. end
  2706. # 获取我的用户类型资源
  2707. def get_principal_resources author_id, order, score
  2708. attchments = Attachment.where("author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Principal'").order("#{order.nil? ? 'created_on' : order} #{score}")
  2709. end
  2710. # 获取我的用户类型资源搜索
  2711. def get_principal_resources_search author_id, order, score, search
  2712. attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Principal') and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}")
  2713. end
  2714. # 获取我的用户类型资源
  2715. def get_principal_resources_public order, score
  2716. attchments = Attachment.where("container_type = 'Principal' and is_public =1 and container_id is not null").order("#{order.nil? ? 'created_on' : order} #{score}")
  2717. end
  2718. # 获取我的用户类型资源
  2719. def get_principal_resources_public_search order, score, search
  2720. attchments = Attachment.where("(container_type = 'Principal'and container_id is not null and is_public =1) and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}")
  2721. end
  2722. # 资源库 分为全部 课程资源 项目资源 附件
  2723. def user_resource
  2724. # 别人的资源库是没有权限去看的
  2725. if User.current.id.to_i != @user.id.to_i
  2726. render_403
  2727. return
  2728. end
  2729. @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc"
  2730. @score = @b_sort == "desc" ? "asc" : "desc"
  2731. user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id}
  2732. user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id }
  2733. # user_org_ids = User.current.organizations.map {|o| o.id}
  2734. if( params[:type] == "1") # 我的资源
  2735. # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
  2736. if params[:status] == "2"
  2737. @attachments = get_course_resources(params[:id], user_course_ids, @order, @score)
  2738. elsif params[:status] == "3"
  2739. @attachments = get_project_resources(params[:id], user_project_ids, @order, @score)
  2740. elsif params[:status] == "4"
  2741. @attachments = get_attch_resources(params[:id], @order, @score)
  2742. elsif params[:status] == "5"
  2743. @attachments = get_principal_resources(params[:id], @order, @score)
  2744. else
  2745. # 公共资源库:所有公开资源或者我上传的私有资源
  2746. @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score)
  2747. end
  2748. elsif (params[:type].blank? || params[:type] == "6") # 公共资源
  2749. if params[:status] == "2"
  2750. @attachments = get_course_resources_public( user_course_ids, @order, @score)
  2751. elsif params[:status] == "3"
  2752. @attachments = get_project_resources_public(user_project_ids, @order, @score)
  2753. elsif params[:status] == "4"
  2754. @attachments = get_attch_resources_public(@order, @score)
  2755. elsif params[:status] == "5"
  2756. @attachments = get_principal_resources_public(@order, @score)
  2757. else
  2758. # 公共资源库:所有公开资源或者我上传的私有资源
  2759. @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score)
  2760. end
  2761. # elsif params[:type] == "2" # 私有资源
  2762. # apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id}
  2763. # if params[:status] == "2"
  2764. # resource_type = "'Course'"
  2765. # elsif params[:status] == "3"
  2766. # resource_type = "'Project'"
  2767. # elsif params[:status] == "5"
  2768. # resource_type = "'Principal'"
  2769. # else
  2770. # resource_type = "'Project','OrgSubfield','Principal','Course'"
  2771. # end
  2772. # @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score)
  2773. end
  2774. @status = params[:status]
  2775. @type = params[:type]
  2776. @limit = 25
  2777. @is_remote = true
  2778. @atta_count = @attachments.count
  2779. @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
  2780. @offset ||= @atta_pages.offset
  2781. #@curse_attachments_all = @all_attachments[@offset, @limit]
  2782. @attachments = paginateHelper @attachments,25
  2783. respond_to do |format|
  2784. format.js
  2785. format.html {render :layout => 'new_base'}
  2786. end
  2787. end
  2788. # 导入资源
  2789. def import_resources
  2790. # 别人的资源库是没有权限去看的
  2791. if User.current.id != params[:id].to_i
  2792. render_403
  2793. return
  2794. end
  2795. @resource_id = params[:project_id].nil? ? (params[:course_id].nil? ? params[:subfield_file_id] : params[:course_id]) : params[:project_id]
  2796. @resource_type = params[:project_id].nil? ? (params[:course_id].nil? ? "SubfieldFile" : "Course") : "Project"
  2797. @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc"
  2798. @score = @b_sort == "desc" ? "asc" : "desc"
  2799. user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id}
  2800. user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id } # user_org_ids = User.current.organizations.map {|o| o.id}
  2801. if(params[:type].blank? || params[:type] == "1") # 我的资源
  2802. # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
  2803. @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score)
  2804. elsif params[:type] == "6" # 公共资源
  2805. # 公共资源库:所有公开资源或者我上传的私有资源
  2806. @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score)
  2807. end
  2808. @status = params[:status]
  2809. @type = params[:type]
  2810. @limit = 10
  2811. @is_remote = true
  2812. @atta_count = @attachments.count
  2813. @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
  2814. @offset ||= @atta_pages.offset
  2815. #@curse_attachments_all = @all_attachments[@offset, @limit]
  2816. @attachments = paginateHelper @attachments,10
  2817. respond_to do |format|
  2818. format.js
  2819. format.html {render :layout => 'new_base'}
  2820. end
  2821. end
  2822. def import_resources_search
  2823. if User.current.id.to_i != params[:id].to_i
  2824. render_403
  2825. return
  2826. end
  2827. @resource_id = params[:mul_id]
  2828. @resource_type = params[:mul_type]
  2829. @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc"
  2830. @score = @b_sort == "desc" ? "asc" : "desc"
  2831. @user = User.current
  2832. @switch_search = params[:name].nil? ? " " : params[:name]
  2833. search = "%#{@switch_search.strip.downcase}%"
  2834. # 别人的资源库是没有权限去看的
  2835. if(params[:type].blank? || params[:type] == "1") # 我的资源
  2836. # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
  2837. user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id}
  2838. user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id }
  2839. # user_org_ids = User.current.organizations.map {|o| o.id}
  2840. @attachments = get_my_resources_search(params[:id], user_course_ids, user_project_ids, @order, @score, search)
  2841. elsif params[:type] == "6" # 公共资源
  2842. # 公共资源库:所有公开资源或者我上传的私有资源
  2843. @attachments = get_public_resources_search(user_course_ids, user_project_ids, @order, @score, search)
  2844. end
  2845. @type = params[:type]
  2846. @limit = 10
  2847. @is_remote = true
  2848. @atta_count = @attachments.count
  2849. @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
  2850. @offset ||= @atta_pages.offset
  2851. #@curse_attachments_all = @all_attachments[@offset, @limit]
  2852. @attachments = paginateHelper @attachments, 10
  2853. respond_to do |format|
  2854. format.js
  2855. # format.html {render :layout => 'new_base'}
  2856. end
  2857. end
  2858. # 内容导入到对象中
  2859. def import_into_container
  2860. send_ids = params[:checkbox1]
  2861. # mul_id为当前课程id、项目id、组织id的多种形态
  2862. mul_id = params[:mul_id]
  2863. if params[:mul_type] == "Course"
  2864. mul_container = Course.find(mul_id)
  2865. elsif params[:mul_type] == "Project"
  2866. mul_container = Project.find(mul_id)
  2867. elsif params[:mul_type] == "SubfieldFile"
  2868. mul_container = OrgSubfield.find(mul_id)
  2869. end
  2870. unless params[:checkbox1].blank?
  2871. send_ids.each do |send_id|
  2872. ori = Attachment.find_by_id(send_id)
  2873. # 如果该附件已经存课程中,则只更新附件创建时间
  2874. mul_container.attachments.each do |att|
  2875. if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from
  2876. att.created_on = Time.now
  2877. att.save
  2878. @exist = true
  2879. break
  2880. end
  2881. end
  2882. next if @exist
  2883. attach_copied_obj = ori.copy
  2884. attach_copied_obj.tag_list.add(ori.tag_list) # tag关联
  2885. attach_copied_obj.container = mul_container
  2886. attach_copied_obj.created_on = Time.now
  2887. attach_copied_obj.author_id = User.current.id
  2888. attach_copied_obj.is_public = 0
  2889. attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from
  2890. if attach_copied_obj.attachtype == nil
  2891. attach_copied_obj.attachtype = 4
  2892. end
  2893. attach_copied_obj.save
  2894. # 附件保存成功后更新项目和课程的统计数
  2895. if params[:mul_type] == "Project"
  2896. mul_container.project_score.update_attribute(:attach_num, mul_container.project_score.attach_num + 1) unless mul_container.project_score.nil?
  2897. end
  2898. @save_message = attach_copied_obj.errors.full_messages
  2899. end
  2900. end
  2901. respond_to do |format|
  2902. format.html {
  2903. if params[:mul_type] == "Course"
  2904. redirect_to course_files_url(mul_container) unless mul_container.nil?
  2905. elsif params[:mul_type] == "Project"
  2906. redirect_to project_files_url(mul_container) unless mul_container.nil?
  2907. elsif params[:mul_type] == "SubfieldFile"
  2908. redirect_to org_subfield_files_url(mul_container) unless mul_container.nil?
  2909. end
  2910. }
  2911. end
  2912. end
  2913. # 根据资源关键字进行搜索
  2914. def resource_search
  2915. @order, @b_sort = params[:order] || "created_on", params[:sort] || "desc"
  2916. @score = @b_sort == "desc" ? "asc" : "desc"
  2917. @user = User.current
  2918. @switch_search = params[:search].nil? ? " " : params[:search]
  2919. search = "%#{@switch_search.strip.downcase}%"
  2920. user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id}
  2921. user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id }
  2922. if(params[:type].nil? || params[:type].blank? || params[:type] == "1" || params[:type] == 'all') # 全部
  2923. if params[:status] == "2"
  2924. @attachments = get_course_resources_search(params[:id], user_course_ids, @order, @score, search)
  2925. elsif params[:status] == "3"
  2926. @attachments = get_project_resources_search(params[:id], user_project_ids, @order, @score, search)
  2927. elsif params[:status] == "4"
  2928. @attachments = get_attch_resources_search(params[:id], @order, @score, search)
  2929. elsif params[:status] == "5"
  2930. @attachments = get_principal_resources_search(params[:id], @order, @score, search)
  2931. else
  2932. # 公共资源库:所有公开资源或者我上传的私有资源
  2933. @attachments = get_my_resources_search(params[:id], user_course_ids, user_project_ids, @order, @score, search)
  2934. end
  2935. elsif params[:type] == "6" # 公共资源
  2936. if params[:status] == "2"
  2937. @attachments = get_course_resources_public_search(user_course_ids, @order, @score, search)
  2938. elsif params[:status] == "3"
  2939. @attachments = get_project_resources_public_search(user_project_ids, @order, @score, search)
  2940. elsif params[:status] == "4"
  2941. @attachments = get_attch_resources_public_search(@order, @score, search)
  2942. elsif params[:status] == "5"
  2943. @attachments = get_principal_resources_public_search(@order, @score, search)
  2944. else
  2945. # 公共资源库:所有公开资源或者我上传的私有资源
  2946. @attachments = get_public_resources_search(user_course_ids, user_project_ids, @order, @score, search)
  2947. end
  2948. # elsif params[:type] == "2" # 私有资源
  2949. # apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id}
  2950. # if params[:status] == "2"
  2951. # resource_type = "'Course'"
  2952. # elsif params[:status] == "3"
  2953. # resource_type = "'Project'"
  2954. # elsif params[:status] == "5"
  2955. # resource_type = "'Principal'"
  2956. # else
  2957. # resource_type = "'Project','OrgSubfield','Principal','Course'"
  2958. # end
  2959. # @attachments = get_my_private_resources_search(apply_ids, resource_type, @order, @score, search)
  2960. # @attachments
  2961. end
  2962. @status = params[:status]
  2963. @type = params[:type]
  2964. @limit = 25
  2965. @is_remote = true
  2966. @atta_count = @attachments.count
  2967. @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
  2968. @offset ||= @atta_pages.offset
  2969. #@curse_attachments_all = @all_attachments[@offset, @limit]
  2970. @attachments = paginateHelper @attachments,25
  2971. respond_to do |format|
  2972. format.js
  2973. end
  2974. end
  2975. def user_organizations
  2976. @user = User.current
  2977. @orgs = @user.organizations
  2978. respond_to do |format|
  2979. format.html {render :layout => 'static_base'}
  2980. end
  2981. end
  2982. def search_user_orgs
  2983. name=""
  2984. if !params[:search_orgs].nil?
  2985. name = params[:search_orgs].strip
  2986. end
  2987. name = "%"+name+"%"
  2988. @orgs = User.current.organizations.where("name like ?", name)
  2989. @user = User.current
  2990. @type = params[:type]
  2991. respond_to do |format|
  2992. format.html {render :layout => 'static_base'}
  2993. format.js
  2994. end
  2995. end
  2996. def search_user_org
  2997. @user = User.current
  2998. if !params[:search].nil? #发送到有栏目类型为资源的组织中
  2999. search = "%#{params[:search].to_s.strip.downcase}%"
  3000. if params[:send_type].present? and (params[:send_type] == 'news' or params[:send_type] == 'message')
  3001. @orgs = @user.organizations.where("name like ?", search).select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Post'").count > 0}
  3002. else
  3003. @orgs = @user.organizations.where("name like ?", search).select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Resource'").count > 0}
  3004. end
  3005. else
  3006. if params[:send_type].present? and (params[:send_type] == 'news' or params[:send_type] == 'message')
  3007. @orgs = @user.organizations.select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Post'").count > 0}
  3008. else
  3009. @orgs = @user.organizations.select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Resource'").count > 0}
  3010. end
  3011. end
  3012. @type = params[:type]
  3013. @search = params[:search]
  3014. #这里仅仅是传递需要发送的资源id
  3015. @send_id = params[:send_id]
  3016. @send_ids = params[:checkbox1] || params[:send_ids]
  3017. respond_to do |format|
  3018. format.js
  3019. end
  3020. end
  3021. def user_courselist
  3022. @order, @c_sort, @type, @list_type = 1, 2, 1, 1
  3023. @my_syllabuses = @user.syllabuses
  3024. sy_courses = @user.courses.visible.where("is_delete =? and tea_id != ?", 0, @user.id)
  3025. syllabus_ids = sy_courses.empty? ? '(-1)' : "(" + sy_courses.map{|course| !course.syllabus_id.nil? && course.syllabus_id}.join(",") + ")"
  3026. @join_syllabuses = Syllabus.where("id in #{syllabus_ids} and user_id != #{@user.id}")
  3027. @my_syllabuses = syllabus_course_list_sort @my_syllabuses
  3028. @join_syllabuses = syllabus_course_list_sort @join_syllabuses
  3029. @my_syllabuses = @my_syllabuses.sort{|x,y| y[:last_update] <=> x[:last_update]}
  3030. @join_syllabuses = @join_syllabuses.sort{|x,y| y[:last_update] <=> x[:last_update]}
  3031. #分页
  3032. # @limit = 10
  3033. # @is_remote = true
  3034. # @atta_count = @syllabus.count
  3035. # @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
  3036. # @offset ||= @atta_pages.offset
  3037. # @syllabus = paginateHelper @syllabus,@limit
  3038. respond_to do |format|
  3039. format.html {render :layout => 'new_base_user'}
  3040. end
  3041. end
  3042. #课程列表的排序
  3043. def sort_syllabus_list
  3044. @order, @c_sort, @type, @list_type = params[:order] || 1, params[:sort] || 1, params[:type] || 1, params[:list_type] || 1
  3045. #确定 sort_type
  3046. if @order.to_i == @type.to_i
  3047. @c_sort = @c_sort.to_i == 1 ? 2 : 1 #1升序 2降序
  3048. else
  3049. @c_sort = 2
  3050. end
  3051. sort_name = "updated_at"
  3052. if @list_type.to_i == 1
  3053. @syllabuses = @user.syllabuses.order("updated_at desc")
  3054. else
  3055. sy_courses = @user.courses.visible.where("is_delete =? and tea_id != ?", 0, @user.id)
  3056. syllabus_ids = sy_courses.empty? ? '(-1)' : "(" + sy_courses.map{|course| !course.syllabus_id.nil? && course.syllabus_id}.join(",") + ")"
  3057. @syllabuses = Syllabus.where("id in #{syllabus_ids} and user_id != #{@user.id}").order("updated_at desc")
  3058. end
  3059. if @order.to_i == 1 #根据 班级更新时间排序
  3060. @syllabuses = syllabus_course_list_sort @syllabuses
  3061. @c_sort == 1 ? (@syllabuses = @syllabuses.sort{|x,y| x[:last_update] <=> y[:last_update] }) : (@syllabuses = @syllabuses.sort{|x,y| y[:last_update] <=> x[:last_update]})
  3062. @type = 1
  3063. elsif @order.to_i == 2 #根据 作业+资源数排序
  3064. @type = 2
  3065. @syllabuses.each do |syllabus|
  3066. count = 0
  3067. courses = syllabus.courses.not_deleted
  3068. courses.each do |c|
  3069. count += (User.current.admin? || User.current.allowed_to?(:as_teacher,c)) ? (c.homework_commons.count + visable_attachemnts_incourse(c).count) : (c.homework_commons.where("publish_time <= '#{Date.today}'").count + visable_attachemnts_incourse(c).count)
  3070. end
  3071. syllabus[:infocount] = count
  3072. end
  3073. @c_sort == 1 ? (@syllabuses = @syllabuses.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@syllabuses = @syllabuses.sort{|x,y| y[:infocount] <=> x[:infocount]})
  3074. @syllabuses = sortby_time_countcommon_nosticky @syllabuses,sort_name
  3075. else
  3076. @type = 1
  3077. end
  3078. respond_to do |format|
  3079. format.js
  3080. end
  3081. end
  3082. #展开课程下的班级
  3083. def expand_courses
  3084. @syllabus = Syllabus.where("id = #{params[:syllabus_id]}").first
  3085. unless @syllabus.nil?
  3086. @courses = @syllabus.courses.not_deleted.select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("updatetime desc")
  3087. respond_to do |format|
  3088. format.js
  3089. end
  3090. end
  3091. end
  3092. def user_projectlist
  3093. @order, @c_sort,@type = params[:order] || 1, params[:sort] || 1, params[:type] || 1
  3094. #确定 sort_type
  3095. if @order.to_i == @type.to_i
  3096. @c_sort = @c_sort.to_i == 1 ? 2 : 1 #1升序 2降序
  3097. else
  3098. @c_sort = 2
  3099. end
  3100. sort_name = "updated_at"
  3101. sort_type = @c_sort == 1 ? "asc" : "desc"
  3102. #@projects = @user.projects.visible.order("#{sort_name} #{sort_type}")
  3103. @projects = @user.projects.visible.select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS #{sort_name} ").order("#{sort_name} #{sort_type}")
  3104. #根据 问题+资源数排序 @project.project_score.issue_num @project.project_score.attach_num
  3105. if @order.to_i == 2
  3106. @type = 2
  3107. @projects.each do |project|
  3108. project[:infocount] = project.project_score.issue_num+project.project_score.attach_num
  3109. if project[:infocount] < 0
  3110. project[:infocount] = 0
  3111. end
  3112. end
  3113. @c_sort == 1 ? (@projects = @projects.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@projects = @projects.sort{|x,y| y[:infocount] <=> x[:infocount] })
  3114. @projects = sortby_time_countcommon_nosticky @projects,sort_name
  3115. else
  3116. @type = 1
  3117. end
  3118. #分页
  3119. @limit = 10
  3120. @is_remote = true
  3121. @atta_count = @projects.count
  3122. @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
  3123. @offset ||= @atta_pages.offset
  3124. @projects = paginateHelper @projects,@limit
  3125. respond_to do |format|
  3126. format.js
  3127. format.html {render :layout => 'new_base_user'}
  3128. end
  3129. end
  3130. def all_journals
  3131. if params[:type].present?
  3132. case params[:type]
  3133. when 'OrgDocumentComment'
  3134. obj = OrgDocumentComment.where('id = ?', params[:id].to_i).first
  3135. @user_activity_id = params[:div_id].to_i if params[:div_id]
  3136. @type = 'OrgDocumentComment'
  3137. comments = []
  3138. @journals = get_all_children(comments, obj)
  3139. when 'Message'
  3140. obj = Message.where('id = ?', params[:id].to_i).first
  3141. @type = 'Message'
  3142. @is_course = params[:is_course]
  3143. @is_board = params[:is_board]
  3144. @user_activity_id = params[:div_id].to_i if params[:div_id]
  3145. comments = []
  3146. @journals = get_all_children(comments, obj)
  3147. when 'News'
  3148. obj = News.where('id = ?', params[:id].to_i).first
  3149. @journals = obj.comments.reorder("created_on desc")
  3150. @type = 'News'
  3151. @user_activity_id = params[:div_id].to_i if params[:div_id]
  3152. when 'Syllabus'
  3153. obj = Syllabus.where('id = ?', params[:id].to_i).first
  3154. @journals = obj.journals_for_messages.reorder("created_on desc")
  3155. @type = 'Syllabus'
  3156. @user_activity_id = params[:div_id].to_i if params[:div_id]
  3157. when 'JournalsForMessage'
  3158. obj = JournalsForMessage.where('id = ?', params[:id].to_i).first
  3159. journals = []
  3160. @journals = get_all_children(journals, obj)
  3161. @type = 'JournalsForMessage'
  3162. @user_activity_id = params[:div_id].to_i if params[:div_id]
  3163. when 'Issue'
  3164. obj = Issue.where('id = ?', params[:id].to_i).first
  3165. @journals = obj.journals.reorder("created_on desc")
  3166. @type = 'Issue'
  3167. @user_activity_id = params[:div_id].to_i if params[:div_id]
  3168. when 'BlogComment'
  3169. obj = BlogComment.where('id = ?', params[:id].to_i).first
  3170. @user_activity_id = params[:div_id].to_i if params[:div_id]
  3171. @homepage = params[:homepage].to_i
  3172. @type = 'BlogComment'
  3173. @user_id = obj.author_id
  3174. comments = []
  3175. @journals = get_all_children(comments, obj)
  3176. when 'HomeworkCommon'
  3177. obj = HomeworkCommon.where('id = ?', params[:id].to_i).first
  3178. @type = 'HomeworkCommon'
  3179. @journals = obj.journals_for_messages.reorder("created_on desc")
  3180. @is_in_course = params[:is_in_course].to_i if params[:is_in_course]
  3181. @course_activity = params[:course_activity].to_i if params[:course_activity]
  3182. @is_teacher = User.current.allowed_to?(:as_teacher,obj.course)
  3183. @user_activity_id = params[:user_activity_id].to_i if params[:user_activity_id]
  3184. end
  3185. end
  3186. end
  3187. private
  3188. def find_user
  3189. if params[:id] == 'current'
  3190. require_login || return
  3191. @user = User.current
  3192. else
  3193. @user = User.find(params[:id])
  3194. end
  3195. rescue ActiveRecord::RecordNotFound
  3196. render_404
  3197. end
  3198. def setting_layout(default_base='base_users_new')
  3199. User.current.admin? ? default_base : default_base
  3200. end
  3201. # 必填自己的工作单位,其实就是学校
  3202. def auth_user_extension
  3203. if @user == User.current && @user.user_extensions.nil?
  3204. flash[:error] = l(:error_complete_occupation)
  3205. redirect_to my_account_url
  3206. end
  3207. end
  3208. #重置用户得分
  3209. def rest_user_score
  3210. memo_num(@user)
  3211. messges_for_issue_num(@user)
  3212. issues_status_num(@user)
  3213. replay_for_memo_num(@user)
  3214. tread_num(@user)
  3215. praise_num(@user)
  3216. changeset_num(@user)
  3217. document_num(@user)
  3218. attachment_num(@user)
  3219. issue_done_ratio_num(@user)
  3220. post_issue_num(@user)
  3221. end
  3222. #验证是否显示课程
  3223. def can_show_course
  3224. @first_page = FirstPage.find_by_page_type('project')
  3225. if @first_page.show_course == 2
  3226. render_404
  3227. end
  3228. end
  3229. def recorded_visitor
  3230. if(User.current.logged? && User.current != @user)
  3231. #impl = Visitor.where('user_id=? and master_id=?',User.current.id,@user.id).find;
  3232. # impl = Visitor.find_by_sql('user_id=? and master_id=?',[User.current.id,@user.id]);
  3233. impl = Visitor.find_by_user_id_and_master_id(User.current.id,@user.id);
  3234. if(impl.nil?)
  3235. impl = Visitor.new
  3236. impl.user_id = User.current.id
  3237. impl.master_id = @user.id
  3238. else
  3239. impl.updated_on = Time.now
  3240. end
  3241. impl.save
  3242. end
  3243. end
  3244. end

软件技术创新是当今国家整体创新能力的重要基础和发展引擎。近年来,大众参与的软件创新与创业活动已经成为网络时代软件开发和应用的新形态,正在快速改变着全球软件创新模式和软件产业格局。 ...