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 179 kB

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

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