|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490 |
- #encoding: utf-8
- # Redmine - project management software
- # Copyright (C) 2006-2013 Jean-Philippe Lang
- #
- # This program is free software; you can redistribute it and/or
- # modify it under the terms of the GNU General Public License
- # as published by the Free Software Foundation; either version 2
- # of the License, or (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-
- class UsersController < ApplicationController
-
- layout :setting_layout
- #Added by young
- before_filter :auth_login1, :only => [:show, :user_activities, :user_newfeedback]
- before_filter :logged_user_by_apptoken, :only => [:show,:user_newfeedback]
- menu_item :activity
- menu_item :user_information, :only => :info
- menu_item :user_course, :only => :user_courses
- menu_item :user_homework, :only => :user_homeworks
- menu_item :student_homework, :only => :student_homeworks
- menu_item :user_project, :only => [:user_projects, :watch_projects]
- menu_item :requirement_focus, :only => :watch_contests
- menu_item :user_newfeedback, :only => :user_newfeedback
- menu_item :user_messages, :only => :user_messages
-
-
- #
- before_filter :can_show_course, :only => [:user_courses,:user_homeworks]
- before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :user_courses,
- :user_homeworks,:student_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments,
- :watch_contests, :info, :watch_projects, :show_score, :topic_score_index, :project_score_index,
- :activity_score_index, :influence_score_index, :score_index,:show_new_score, :topic_new_score_index, :project_new_score_index,
- :activity_new_score_index, :influence_new_score_index, :score_new_index,:user_projects_index,:user_resource,
- :user_courses4show,:user_projects4show,:user_course_activities,:user_project_activities,:user_feedback4show,:user_visitorlist,:user_messages,:edit_brief_introduction,
- :user_import_homeworks,:user_search_homeworks,:user_import_resource, :user_system_messages,:choose_user_course,:user_courselist,:user_projectlist,:sort_syllabus_list]
- before_filter :auth_user_extension, only: :show
- #before_filter :rest_user_score, only: :show
- #before_filter :select_entry, only: :user_projects
- accept_api_auth :index, :show, :create, :update, :destroy,:tag_save , :tag_saveEx
-
- #william
- before_filter :require_login, :only => [:tag_save,:tag_saveEx]
- #before_filter :refresh_changests, :only =>[:user_activities,:user_courses,:user_projects,:user_newfeedback]
-
-
- #visitor
- before_filter :recorded_visitor, :only => [:show,:user_fanslist,:user_watchlist,:user_visitorlist]
-
- helper :sort
- helper :attachments
- include SortHelper
- include ApplicationHelper
- helper :custom_fields
- include CustomFieldsHelper
- include AvatarHelper
- include WordsHelper
- include GitlabHelper
- include UserScoreHelper
-
-
- include PollHelper
- helper :user_score
- helper :journals
-
- # added by liuping 关注
-
- helper :watchers
- helper :activities
-
- ### added by william
- include ActsAsTaggableOn::TagsHelper
-
- # fq
- helper :words
- helper :project_score
- helper :issues
- include UsersHelper
-
- #展开所有回复
- def show_all_replies
- case params[:type]
- when 'JournalsForMessage'
- @comment = JournalsForMessage.find params[:comment].to_i
- when 'Message'
- @comment = Message.find params[:comment].to_i
- when 'BlogComment'
- @comment = BlogComment.find params[:comment].to_i
- when 'OrgDocumentComment'
- @comment = OrgDocumentComment.find params[:comment].to_i
- when 'Comment'
- @comment = Comment.find params[:comment].to_i
- when 'Journal'
- @comment = Journal.find params[:comment].to_i
- end
- end
-
- #二级回复
- def reply_to
- case params[:type]
- when 'HomeworkCommon'
- @reply = JournalsForMessage.find params[:reply_id]
- @type = 'HomeworkCommon'
- if params[:user_activity_id]
- @user_activity_id = params[:user_activity_id]
- else
- @user_activity_id = -1
- end
- @is_in_course = params[:is_in_course].to_i
- @course_activity = params[:course_activity].to_i
- when 'JournalsForMessage'
- @reply = JournalsForMessage.find params[:reply_id]
- @user_activity_id = params[:user_activity_id]
- @activity_id = params[:activity_id]
- @type = 'JournalsForMessage'
- when 'Message'
- @reply = Message.find params[:reply_id]
- @user_activity_id = params[:user_activity_id]
- @activity_id = params[:activity_id]
- @is_course = params[:is_course]
- @is_board = params[:is_board]
- @type = 'Message'
- when 'BlogComment'
- @reply = BlogComment.find params[:reply_id]
- @user_activity_id = params[:user_activity_id]
- @activity_id = params[:activity_id]
- @homepage = params[:homepage]
- @user_id = params[:user_id]
- @type = 'BlogComment'
- when 'OrgDocumentComment'
- @reply = OrgDocumentComment.find params[:reply_id]
- @user_activity_id = params[:user_activity_id]
- @activity_id = params[:activity_id]
- @type = 'OrgDocumentComment'
- when 'News'
- @reply = Comment.find params[:reply_id]
- @user_activity_id = params[:user_activity_id]
- @activity_id = params[:activity_id]
- @type = 'News'
- when 'Issue'
- @reply = Journal.find params[:reply_id]
- @user_activity_id = params[:user_activity_id]
- @activity_id = params[:activity_id]
- @type = 'Issue'
- when 'Syllabus'
- @reply = JournalsForMessage.find params[:reply_id]
- @type = 'Syllabus'
- end
- respond_to do |format|
- format.js
- end
- end
-
- def refresh_changests
- if !(@user.nil?) && !(@user.memberships.nil?)
- @user.memberships.each do |member|
- unless member.project.nil?
- member.project.repository.fetch_changesets if Setting.autofetch_changesets?
- end
- end
- end
- end
-
- # 更新issue状态
- def user_act_issue_assign_to
-
- end
-
- #未读消息弹窗
- def user_messages_unviewed
- @message_alls = []
- messages = MessageAll.where("user_id =?", User.current.id).includes(:message).order("created_at desc")
- onclick_time = User.current.onclick_time.onclick_time
- messages.each do |message_all|
- # 未读的消息存放在数组
- mess = message_all.message
- 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)
- unless (message_all.message_type == 'CourseMessage' && mess && mess.course && mess.course.is_delete == 1)
- @message_alls << mess
- end
- break if @message_alls.length == 10
- end
- end
- end
-
- # 用户消息
- # 说明: homework 发布作业;message:讨论区; news:新闻; poll:问卷;works_reviewers:作品评阅;works_reply:作品回复,exercise:课程测验
- # issue:问题;journal:缺陷状态更新; forum:公共贴吧: user_feedback: 用户留言; new_reply:新闻回复(comment)
- def user_messages
- if !User.current.logged?
- redirect_to signin_url
- return
- elsif @user != User.current && !User.current.admin?
- return render_403
- end
- # 初始化/更新 点击按钮时间, 24小时内显示系统消息
- update_onclick_time
- # 全部设为已读
- if params[:viewed] == "all"
- update_message_viewed(@user)
- end
- # @new_message_count = forge_querys.count + forum_querys.count + course_querys.count + user_querys.count
- courses = @user.courses.where("is_delete = 1")
- course_ids = courses.empty? ? "(-1)" : "(" + courses.map{|course| course.id}.join(",") + ")"
- case params[:type]
- when nil
- # 系统消息为管理员发送,我的消息中包含有系统消息
- @message_alls = []
- messages = MessageAll.where("(user_id =? and message_type !=?) or message_type =?" ,@user.id, "SystemMessage", "SystemMessage").includes(:message).order("created_at desc")
- messages.each do |message_all|
- mess = message_all.message
- unless (message_all.message_type == 'CourseMessage' && mess && mess.course && mess.course.is_delete == 1)
- @message_alls << mess
- end
- end
- when 'unviewed'
- @message_alls = []
- messages = MessageAll.where("message_alls.user_id =?", @user.id).includes(:message).order("created_at desc")
- messages.each do |message_all|
- # 在点击或者刷新消息列表后未读的消息存放在数组
- mess = message_all.message
- if message_all.message_type != "SystemMessage"&& !mess.nil? && (mess.viewed == 0 || !mess.viewed)
- unless (message_all.message_type == 'CourseMessage' && mess && mess.course && mess.course.is_delete == 1)
- @message_alls << mess
- end
- end
- end
- #课程相关消息
- when 'homework'
- @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")
- when 'course_message'
- @message_alls = CourseMessage.where("course_message_type =? and user_id =? and course_id NOT IN #{course_ids}", "Message", @user.id).order("created_at desc")
- when 'course_news'
- # 课程通知包含发布的通知和回复的通知
- @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")
- when 'poll'
- @message_alls = CourseMessage.where("course_message_type =? and user_id =? and course_id NOT IN #{course_ids}", "Poll", @user.id).order("created_at desc")
- #项目相关消息
- when 'issue'
- @message_alls = ForgeMessage.where("forge_message_type in ('Issue', 'Journal') and user_id =?" , @user.id).order("created_at desc")
- when 'forge_message'
- @message_alls = ForgeMessage.where("forge_message_type =? and user_id =?", "Message", @user.id).order("created_at desc")
- when 'forge_news'
- @message_alls = ForgeMessage.where("forge_message_type in (?,?) and user_id =?", "News", "Comment", @user.id).order("created_at desc")
- when 'apply'
- @message_alls = ForgeMessage.where("forge_message_type in ('ProjectInvite', 'AppliedProject', 'JoinProject', 'RemoveFromProject') and user_id =?", @user.id).order("created_at desc")
- #贴吧消息
- when 'forum'
- @message_alls = MemoMessage.where("memo_type =? and user_id =?", "Memo", @user.id).order("created_at desc")
- #用户留言
- when 'user_feedback'
- @message_alls = UserFeedbackMessage.where("journals_for_message_type =? and user_id =?", "JournalsForMessage", @user.id).order("created_at desc")
- else
- render_404
- return
- end
- @message_alls = paginateHelper @message_alls,25
- respond_to do |format|
- format.html{render :layout=>'new_base_user'}
- end
- end
-
- # 初始化/更新 点击按钮时间
- def update_onclick_time
- # 记录当前点击按钮的时间
- # 考虑到用户未退出刷新消息页面
- message_time = OnclickTime.where("user_id =?", User.current).first
- if message_time.nil?
- message_new_time = OnclickTime.new
- message_new_time.user_id = User.current.id
- message_new_time.onclick_time = Time.now
- message_new_time.save
- else
- message_time.update_attributes(:onclick_time => Time.now)
- end
- end
-
- # 消息设置为已读
- def update_message_viewed(user)
- if User.current.id == @user.id
- course_querys = CourseMessage.where("user_id =? and viewed =?", user, 0)
- forge_querys = ForgeMessage.where("user_id =? and viewed =?", user, 0)
- user_querys = UserFeedbackMessage.where("user_id =? and viewed =?", user, 0)
- forum_querys = MemoMessage.where("user_id =? and viewed =?", user, 0)
- org_querys = OrgMessage.where("user_id=? and viewed=0", user)
- at_querys = AtMessage.where("user_id=? and viewed=0", user)
- course_querys.update_all(:viewed => true) unless course_querys.nil?
- forge_querys.update_all(:viewed => true) unless forge_querys.nil?
- user_querys.update_all(:viewed => true) unless user_querys.nil?
- forum_querys.update_all(:viewed => true) unless forum_querys.nil?
- org_querys.update_all(:viewed => true) unless org_querys.nil?
- at_querys.update_all(:viewed => true) unless at_querys.nil?
- end
- end
-
- # 系统消息
- def user_system_messages
- @sytem_messages = SystemMessage.order("created_at desc").all
- @sytem_messages = paginateHelper @sytem_messages, 10
- respond_to do |format|
- format.html{render :layout=>'new_base_user'}
- end
- end
-
- def user_projects_index
- if User.current.admin?
- memberships = @user.memberships.all(conditions: "projects.project_type = #{Project::ProjectType_project}").first
- else
- cond = Project.visible_condition(User.current) + " AND projects.project_type <> 1"
- memberships = @user.memberships.all(:conditions => cond).first
- end
- watch_projects = Project.joins(:watchers).where("project_type <>? and watchable_type = ? and `watchers`.user_id = ?", '1','Project', @user.id).first
- if memberships.nil? && watch_projects
- redirect_to(:watch_projects_user) and return
- else
- redirect_to(:user_projects_user) and return
- end
- end
-
- #added by young
- def user_projects
- unless User.current.admin?
- if !@user.active? #|| (@user != User.current && @memberships.empty? && events.empty?)
- render_404
- return
- end
- end
- 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")
- if(params[:status] == '1')
- projects = projects.where("projects.user_id = ?",@user.id)
- elsif(params[:status] == '2')
- projects = projects.where("projects.user_id <> ?",@user.id)
- end
- @list = paginateHelper projects,10
- @params = params[:status]
- respond_to do |format|
- format.html{render :layout=>'base_users_new'}
- format.api
- end
- end
-
- #处理加入课程成为教辅教师的请求
- #status 1 同意 2 拒绝
- def dealwith_apply_request
- @msg = CourseMessage.find(params[:msg_id])
- #CourseMessage content存的是role 7教辅 9 教师
- case params[:agree]
- when 'Y'
- apply_user = User.find(@msg.course_message_id)
- ids = @msg.content.split(",") # [@msg.content] msg content保存的是申请的职位角色
- integer_ids = []
- ids.each do |role_id|
- integer_ids << role_id.to_i
- end
- if apply_user.member_of_course?(Course.find(@msg.course_id))
- #将角色改为老师或者教辅
- member = Course.find(@msg.course_id).members.where(:user_id=>apply_user.id).all[0]
- member.role_ids = integer_ids
- #删除为学生的记录
- unless member.role_ids.include?(10)
- joined = StudentsForCourse.where('student_id = ? and course_id = ?', member.user_id,@msg.course_id)
- joined.each do |join|
- join.delete
- end
- end
-
- member.course_group_id = 0
- member.save
- 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)
- @msg.update_attributes(:status=>1,:viewed=>1)
- else
- members = []
- members << Member.new(:role_ids => integer_ids, :user_id => @msg.course_message_id)
- Course.find(@msg.course_id).members << members
- 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)
- @msg.update_attributes(:status=>1,:viewed=>1)
- end
-
- when 'N'
- CourseMessage.create(:user_id => @msg.course_message_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>User.current.id,:content=>@msg.content,:course_message_type=>'CourseRequestDealResult',:status=>2)
- @msg.update_attributes(:status=>2,:viewed=>1)
- end
- respond_to do |format|
- format.js
- end
- end
-
- # 处理资源引用请求
- # status
- def deal_with_apply_resource
- @msg = CourseMessage.find(params[:msg_id])
- ar = ApplyResource.where("id = ?", @msg.course_message_id).first
- unless ar.nil?
- case params[:agree]
- when 'Y'
- ar.update_column('status', 2)
- @msg.update_attributes(:apply_result => 1, :viewed => 1)
- ar.course_messages << CourseMessage.new(:user_id => ar.user_id, :course_id => -1, :viewed => false, :apply_result => 2, :status => 1)
- when 'N'
- ar.update_column('status', 3)
- @msg.update_attributes(:apply_result => 2, :viewed => 1)
- ar.course_messages << CourseMessage.new(:user_id => ar.user_id, :course_id => -1, :viewed => false, :apply_result => 3, :status => 1)
- end
- end
- respond_to do |format|
- format.js
- end
- end
-
- #处理引用作业的请求
- #status 1 同意 2 拒绝
- def dealwith_apply_homework
- @msg = CourseMessage.find(params[:msg_id])
- ah = ApplyHomework.where("user_id = ? and homework_common_id = ?",@msg.apply_user_id, @msg.course_message_id)
- case params[:agree]
- when 'Y'
- unless ah.empty?
- ah.first.update_column('status', 2)
- CourseMessage.create(:user_id => @msg.apply_user_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>@msg.course_message_id,:content=>@msg.content,:course_message_type=>'HomeworkCommon',:status=>6,:apply_result=>1)
- @msg.update_attributes(:apply_result=>1,:viewed=>1)
- end
- when 'N'
- unless ah.empty?
- ah.first.update_column('status', 3)
- CourseMessage.create(:user_id => @msg.apply_user_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>@msg.course_message_id,:content=>@msg.content,:course_message_type=>'HomeworkCommon',:status=>6,:apply_result=>2)
- @msg.update_attributes(:apply_result=>2,:viewed=>1)
- end
- end
- respond_to do |format|
- format.js
- end
- end
-
- # added by bai
- def show_score
-
- end
-
- def show_new_score
- render :layout => 'users_base'
- end
- # end
-
- ##added by fq
- def watch_bids
- # cond = 'bids.reward_type <> 1'
- # @bids = Bid.watched_by(@user).where('reward_type = ?', 1) # added by huang
- # @offset, @limit = api_offset_and_limit({:limit => 10})
- # @bid_count = @bids.count
- # @bid_pages = Paginator.new @bid_count, @limit, params['page']
- # @offset ||= @bid_pages.reverse_offset
- # unless @offset == 0
- # @bid = @bids.offset(@offset).limit(@limit).all.reverse
- # else
- # limit = @bid_count % @limit
- # @bid = @bids.offset(@offset).limit(limit).all.reverse
- # end
- #
- # respond_to do |format|
- # format.html {
- # render :layout => 'base_users'
- # }
- # format.api
- # end
- end
-
- #new add by linchun
- def watch_contests
- @bids = Contest.watched_by(@user)
- @offset, @limit = api_offset_and_limit({:limit => 10})
- @contest_count = @contests.count
- @contest_pages = Paginator.new @contest_count, @limit, params['page']
- @offset ||= @contest_pages.reverse_offset
- unless @offset == 0
- @contest = @contests.offset(@offset).limit(@limit).all.reverse
- else
- limit = @bid_count % @limit
- @contest = @contests.offset(@offset).limit(limit).all.reverse
- end
-
- respond_to do |format|
- format.html {
- render :layout => 'base_users'
- }
- format.api
- end
- end
-
- # added by fq
- def user_activities
- redirect_to user_url(@user, type: params[:type], page: params[:page])
- return
- # useless abort.
- @watcher = User.watched_by_id(@user)
- events = []
- for user in @watcher
- events << Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 30)
- end
-
-
-
- @events_by_day = events.group_by(&:event_date)
-
- unless User.current.admin?
- if !@user.active? || (@user != User.current && @memberships.empty? && events.empty?)
- render_404
- return
- end
- end
-
- respond_to do |format|
- format.html
- format.api
- end
- end
- # end
-
- # 资源分享请求弹框
- def apply_resource
- @attachment = Attachment.find params[:attachment_id]
- respond_to do |format|
- format.js
- end
- end
-
- #引用作业请求弹框
- def apply_homework
- if User.current.logged?
- @homework = HomeworkCommon.find params[:homework_id]
- @state = 2
- else
- @state = 1
- end
- respond_to do |format|
- format.js
- end
- end
-
- # 申请引用资源
- def apply_for_resource
- if User.current.logged?
- @attachment = Attachment.where("id =?", params[:attachment_id].to_i).first
- unless @attachment.nil?
- ar = ApplyResource.where("user_id = ? and attachment_id = ?", User.current.id, params[:attacment_id].to_i)
- if ar.empty?
- 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)
- @state = 2
- else
- @state = 3
- end
- end
- else
- @state = 1
- end
- respond_to do |format|
- format.js
- end
- end
-
- #申请引用非公开作业
- def apply_for_homework
- if User.current.logged?
- homework = HomeworkCommon.find params[:homework_id]
- unless homework.nil?
- ah = ApplyHomework.where("user_id = ? and homework_common_id = ?", User.current.id, params[:homework_id].to_i)
- if ah.empty?
- ApplyHomework.create(:user_id => params[:id].to_i, :homework_common_id => params[:homework_id].to_i, :status => 1)
- Mailer.run.apply_for_homework_request(homework, User.current)
- 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])
- @state = 2
- @ah = ApplyHomework.where("user_id = ? and homework_common_id = ?", params[:id].to_i, params[:homework_id].to_i).first
- @homework = homework
- else
- @state = 3
- end
- end
- else
- @state = 1
- end
- respond_to do |format|
- format.js
- end
- end
-
- #用户作业列表
- def user_homeworks
- @order,@b_sort = params[:order] || "created_at",params[:sort] || "desc"
- @user = User.current
- @r_sort = @b_sort == "desc" ? "asc" : "desc"
- if(params[:type].blank? || params[:type] == "1") #我的题库
- @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}'").order("#{@order} #{@b_sort}")
- elsif params[:type] == "2" #题库
- visible_course = Course.where("is_delete = 0")
- visible_course_ids = visible_course.empty? ? "(-1)" : "(" + visible_course.map{|course| course.id}.join(",") + ")"
- @homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}'").order("#{@order} #{@b_sort}")
- end
- @type = params[:type]
- @limit = 25
- @is_remote = true
- @hw_count = @homeworks.count
- @hw_pages = Paginator.new @hw_count, @limit, params['page'] || 1
- @offset ||= @hw_pages.offset
- @homeworks = paginateHelper @homeworks,25
- respond_to do |format|
- format.js
- format.html {render :layout => 'static_base'}
- end
- end
-
- def student_homeworks
- if User.current == @user
- @page = params[:page] ? params[:page].to_i + 1 : 0
- user_course_ids = @user.courses.empty? ? "(-1)" :"(" + @user.courses.visible.map{|course| course.id}.join(",") + ")"
-
- #判断当前用户在当前课程的身份
- visibleCourse = @user.courses.empty? ? [] : @user.courses.where("is_delete = 0").visible
- homework_ids = []
- visibleCourse.each do |course|
- homeworks = HomeworkCommon.where("course_id = #{course.id} and publish_time <= '#{Date.today}'")
- homework_ids << homeworks.pluck(:id) unless homeworks.empty?
- end
- visible_homework_ids = homework_ids.size == 0 ? "(-1)" :"(" + homework_ids.join(",") + ")"
- @homework_commons = HomeworkCommon.where("id in #{visible_homework_ids}").order("created_at desc").limit(10).offset(@page * 10)
- @is_teacher = User.current.user_extensions && User.current.user_extensions.identity == 0 && User.current.allowed_to?(:add_course, nil, :global => true)
- @is_in_course = params[:is_in_course].to_i || 0
- respond_to do |format|
- format.js
- format.html {render :layout => 'new_base_user'}
- end
- else
- render_403
- end
- end
-
- def choose_user_course
- homework = HomeworkCommon.find params[:send_id].to_i
- if homework.user != User.current && homework.course.is_public == 0 && !User.current.allowed_to?(:as_teacher,homework.course)
- ah = ApplyHomework.where("user_id = ? and homework_common_id = ?", User.current.id, params[:send_id].to_i)
- if ah.empty?
- @status = 2
- elsif ah.first.status != 2
- @status = ah.first.status
- end
- end
- if !params[:search].nil?
- search = "%#{params[:search].to_s.strip.downcase}%"
- @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)}
- else
- @course = @user.courses.where("is_delete = 0 and #{Course.table_name}.id != #{homework.course_id}").select { |course| @user.allowed_to?(:as_teacher,course)}
- end
- @search = params[:search]
- #这里仅仅是传递需要发送的资源id
- @send_id = params[:send_id]
- respond_to do |format|
- format.js
- end
- end
-
- def send_homework_to_course
- homework = HomeworkCommon.find params[:send_id].to_i
- course_ids = params[:course_ids]
- course_ids.each do |course_id|
- course = Course.find course_id.to_i
- new_homework = HomeworkCommon.new
- new_homework.name = homework.name
- new_homework.user_id = User.current.id
- new_homework.description = homework.description
- new_homework.homework_type = homework.homework_type
- new_homework.late_penalty = homework.late_penalty
- new_homework.course_id = course.id
- new_homework.teacher_priority = homework.teacher_priority
- new_homework.anonymous_comment = homework.anonymous_comment
- new_homework.quotes = 0
- new_homework.is_open = homework.is_open
- homework.attachments.each do |attachment|
- att = attachment.copy
- att.container_id = nil
- att.container_type = nil
- att.copy_from = attachment.id
- att.save
- new_homework.attachments << att
- end
- homework_detail_manual = homework.homework_detail_manual
- homework_detail_programing = homework.homework_detail_programing
- homework_detail_group = homework.homework_detail_group
- if homework_detail_manual
- new_homework.homework_detail_manual = HomeworkDetailManual.new
- new_homework_detail_manual = new_homework.homework_detail_manual
- new_homework_detail_manual.ta_proportion = homework_detail_manual.ta_proportion
- new_homework_detail_manual.comment_status = 0
- new_homework_detail_manual.evaluation_num = homework_detail_manual.evaluation_num
- new_homework_detail_manual.absence_penalty = homework_detail_manual.absence_penalty
- end
- if homework_detail_programing
- new_homework.homework_detail_programing = HomeworkDetailPrograming.new
- new_homework.homework_detail_programing.ta_proportion = homework_detail_programing.ta_proportion
- new_homework.homework_detail_programing.language = homework_detail_programing.language
- homework.homework_tests.each_with_index do |homework_test|
- new_homework.homework_tests << HomeworkTest.new(
- input: homework_test.input,
- output: homework_test.output
- )
- end
- end
-
- if homework_detail_group
- new_homework.homework_detail_group = HomeworkDetailGroup.new
- new_homework.homework_detail_group.min_num = homework_detail_group.min_num
- new_homework.homework_detail_group.max_num = homework_detail_group.max_num
- new_homework.homework_detail_group.base_on_project = homework_detail_group.base_on_project
- end
- if new_homework.save
- new_homework_detail_manual.save if new_homework_detail_manual
- new_homework.homework_detail_programing.save if new_homework.homework_detail_programing
- new_homework.homework_detail_group.save if new_homework.homework_detail_group
- end
- homework.update_column(:quotes, homework.quotes+1)
- end
- @homework = homework
- respond_to do |format|
- format.js
- end
- end
-
- #导入作业
- def user_import_homeworks
- @user = User.current
- @select_course = params[:select_course] ? 1 : 0
- #@user_homeworks = HomeworkCommon.where(:user_id => @user.id).order("created_at desc")
- courses = @user.courses.where("is_delete = 1")
- course_ids = courses.empty? ? "(-1)" : "(" + courses.map{|course| course.id}.join(",") + ")"
- @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and course_id not in #{course_ids}").order("#{@order} #{@b_sort}")
- @type = params[:type]
- @limit = 15
- @is_remote = true
- @hw_count = @homeworks.count
- @hw_pages = Paginator.new @hw_count, @limit, params['page'] || 1
- @offset ||= @hw_pages.offset
- @homeworks = paginateHelper @homeworks,15
- respond_to do |format|
- format.js
- end
- end
-
- def user_homework_type
- @order,@b_sort = params[:order] || "created_at",params[:sort] || "desc"
- @r_sort = @b_sort == "desc" ? "asc" : "desc"
- @user = User.current
- if(params[:type].blank? || params[:type] == "1") #我的题库
- courses = @user.courses.where("is_delete = 1")
- course_ids = courses.empty? ? "(-1)" : "(" + courses.map{|course| course.id}.join(",") + ")"
- @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and course_id not in #{course_ids}").order("#{@order} #{@b_sort}")
- elsif params[:type] == "2" #题库
- if params[:is_import].to_i == 1
- visible_course = Course.where("is_public = 1 && is_delete = 0")
- elsif params[:is_import].to_i == 0
- visible_course = Course.where("is_delete = 0")
- end
- visible_course_ids = visible_course.empty? ? "(-1)" : "(" + visible_course.map{|course| course.id}.join(",") + ")"
- @homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}'").order("#{@order} #{@b_sort}")
- elsif params[:type] == "3" #申请题库
- none_visible_course = Course.where("is_delete = 1")
- none_visible_course_ids = none_visible_course.empty? ? "(-1)" : "(" + none_visible_course.map{|course| course.id}.join(",") + ")"
- #apply_homeworks = ApplyHomework.where("user_id = ?",@user.id).order('created_at desc')
- #homework_ids = apply_homeworks.empty? ? "(-1)" : "(" + apply_homeworks.map{|ah| ah.homework_common_id}.join(",") + ")"
- #@homeworks = HomeworkCommon.where("id in #{homework_ids} and course_id not in #{none_visible_course_ids}")
-
- 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"
- @homeworks = HomeworkCommon.find_by_sql(sql)
- end
- if params[:property]
- all_homework_ids = @homeworks.empty? ? "(-1)" : "(" + @homeworks.map{|h| h.id}.join(",") + ")"
- if params[:property] == "1"
- @homeworks = HomeworkCommon.find_by_sql("select * from homework_commons where id in #{all_homework_ids} and homework_type = 1")
- #@homeworks = @homeworks.where("homework_type = 1").reorder("#{@order} #{@b_sort}")
- elsif params[:property] == "2"
- @homeworks = HomeworkCommon.find_by_sql("select * from homework_commons where id in #{all_homework_ids} and homework_type = 2")
- #@homeworks = @homeworks.where("homework_type = 2").reorder("#{@order} #{@b_sort}")
- elsif params[:property] == "3"
- @homeworks = HomeworkCommon.find_by_sql("select * from homework_commons where id in #{all_homework_ids} and homework_type = 3")
- #@homeworks = @homeworks.where("homework_type = 3").reorder("#{@order} #{@b_sort}")
- end
- end
- @type = params[:type]
- @property = params[:property]
- @is_import = params[:is_import]
- @limit = params[:is_import].to_i == 1 ? 15 : 25
- @is_remote = true
- @hw_count = @homeworks.count
- @hw_pages = Paginator.new @hw_count, @limit, params['page'] || 1
- @offset ||= @hw_pages.offset
- @homeworks = paginateHelper @homeworks,@limit
- respond_to do |format|
- format.js
- end
- end
-
- def show_homework_detail
- @homework = HomeworkCommon.find params[:homework].to_i
- # if homework.course.is_public == 0 && !User.current.allowed_to?(:as_teacher,homework.course) && User.current != homework.user
- # ah = ApplyHomework.where("user_id = ? and homework_common_id = ?", User.current.id, params[:homework].to_i)
- # if ah.empty?
- # @status = 2
- # @homework = nil
- # elsif ah.first.status != 2
- # @status = ah.first.status
- # @homework = nil
- # elsif ah.first.status == 2
- # @homework = homework
- # end
- # else
- # @homework = homework
- # end
- @is_import = params[:is_import]
- respond_to do |format|
- format.js
- end
- end
-
- #用户主页过滤作业
- def user_search_homeworks
- @order,@b_sort = params[:order] || "created_at",params[:sort] || "desc"
- @r_sort = @b_sort == "desc" ? "asc" : "desc"
- @user = User.current
- search = params[:name].to_s.strip.downcase
- type_ids = params[:property]=="" || params[:property].nil? ? "(1, 2, 3)" : "(" + params[:property] + ")"
- if(params[:type].blank? || params[:type] == "1") #我的题库
- courses = @user.courses.where("is_delete = 1")
- course_ids = courses.empty? ? "(-1)" : "(" + courses.map{|course| course.id}.join(",") + ")"
- if @order == "course_name"
- sql = "SELECT homework_commons.* FROM homework_commons INNER JOIN courses ON homework_commons.course_id = courses.id where homework_commons.course_id not in #{course_ids} and homework_commons.user_id = #{@user.id} and homework_type in #{type_ids} and publish_time <= '#{Date.today}' and (homework_commons.name like '%#{search}%') order by CONVERT (courses.name USING gbk) COLLATE gbk_chinese_ci #{@b_sort}"
- @homeworks = HomeworkCommon.find_by_sql(sql)
- elsif @order == "user_name"
- @homeworks = HomeworkCommon.where("user_id = #{@user.id} and course_id not in #{course_ids} and publish_time <= '#{Date.today}' and (name like '%#{search}%') and homework_type in #{type_ids}").joins(:user).order("CONVERT (lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, CONVERT (firstname USING gbk) COLLATE gbk_chinese_ci #{@b_sort},login #{@b_sort}")
- else
- @homeworks = HomeworkCommon.where("user_id = #{@user.id} and course_id not in #{course_ids} and publish_time <= '#{Date.today}' and (name like '%#{search}%') and homework_type in #{type_ids}").order("#{@order} #{@b_sort}")
- end
- elsif params[:type] == "2" #题库
- if params[:is_import].to_i == 1
- visible_course = Course.where("is_public = 1 && is_delete = 0")
- elsif params[:is_import].to_i == 0
- visible_course = Course.where("is_delete = 0")
- end
- visible_course_ids = visible_course.empty? ? "(-1)" : "(" + visible_course.map{|course| course.id}.join(",") + ")"
- all_homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}'")
- all_user_ids = all_homeworks.map{|hw| hw.user_id}
- user_str_ids = search_user_by_name all_user_ids, search
- user_ids = user_str_ids.empty? ? "(-1)" : "(" + user_str_ids.join(",") + ")"
- if @order == "course_name"
- 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}"
- @homeworks = HomeworkCommon.find_by_sql(sql)
- elsif @order == "user_name"
- @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}")
- else
- @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}")
- end
- elsif params[:type] == "3" #申请题库
- apply_homeworks = ApplyHomework.where("user_id = ?",@user.id)
- homework_ids = apply_homeworks.empty? ? "(-1)" : "(" + apply_homeworks.map{|ah| ah.homework_common_id}.join(",") + ")"
- none_visible_course = Course.where("is_delete = 1")
- none_visible_course_ids = none_visible_course.empty? ? "(-1)" : "(" + none_visible_course.map{|course| course.id}.join(",") + ")"
- if @order == "course_name"
- 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}"
- @homeworks = HomeworkCommon.find_by_sql(sql)
- elsif @order == "user_name"
- @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}")
- else
- @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}")
- end
- end
- =begin
- if params[:property] && params[:property] == "1"
- @homeworks = @homeworks.where("homework_type = 1")
- elsif params[:property] && params[:property] == "2"
- @homeworks = @homeworks.where("homework_type = 2")
- elsif params[:property] && params[:property] == "3"
- @homeworks = @homeworks.where("homework_type = 3")
- end
- =end
- @type = params[:type]
- @limit = params[:is_import].to_i == 1 ? 15 : 25
- @is_remote = true
- @hw_count = @homeworks.count
- @hw_pages = Paginator.new @hw_count, @limit, params['page'] || 1
- @offset ||= @hw_pages.offset
- @homeworks = paginateHelper @homeworks,@limit
- @is_import = params[:is_import]
- @property = params[:property]
- @search = search
- respond_to do |format|
- format.js
- end
- end
-
- #导入作业,确定按钮
- def user_select_homework
- homework = HomeworkCommon.find_by_id params[:checkMenu]
- homework_detail_programing = homework.homework_detail_programing
- homework_detail_group = homework.homework_detail_group
- @homework = HomeworkCommon.new
- @select_course = params[:select_course] || 0
- if homework
- @ref_homework = homework
- @homework.name = homework.name
- @homework.description = homework.description
- @homework.end_time = homework.end_time
- @homework.homework_type = homework.homework_type
- @homework.course_id = homework.course_id
- homework.attachments.each do |attachment|
- att = attachment.copy
- att.container_id = nil
- att.container_type = nil
- att.copy_from = attachment.id
- att.save
- @homework.attachments << att
- end
-
- if homework_detail_programing
- @homework.homework_detail_programing = HomeworkDetailPrograming.new
- @homework_detail_programing = @homework.homework_detail_programing
- @homework_detail_programing.ta_proportion = homework_detail_programing.ta_proportion
- @homework_detail_programing.language = homework_detail_programing.language
- homework.homework_tests.each_with_index do |homework_test|
- @homework.homework_tests << HomeworkTest.new(
- input: homework_test.input,
- output: homework_test.output
- )
- end
- end
-
- if homework_detail_group
- @homework.homework_detail_group = HomeworkDetailGroup.new
- @homework_detail_group = @homework.homework_detail_group
- @homework_detail_group.min_num = homework_detail_group.min_num
- @homework_detail_group.max_num = homework_detail_group.max_num
- @homework_detail_group.base_on_project = homework_detail_group.base_on_project
- end
- end
- respond_to do |format|
- format.js
- end
- end
-
- def new_user_commit_homework
- if User.current.logged?
- @user = User.current
- @homework = HomeworkCommon.find(params[:homework_id])
- @is_test = params[:is_test] == 'true'
- @student_work = StudentWork.where(homework_common_id: @homework.id, user_id: User.current.id).first
- if @student_work.nil?
- @student_work = StudentWork.new
- end
- @course = @homework.course
- @left_nav_type = 3
- respond_to do |format|
- format.js
- format.html {render :layout => 'base_courses'}
- end
- else
- render_403
- end
- end
-
- #修改编程作业
- def edit_user_commit_homework
- if User.current.logged?
-
- respond_to do |format|
- format.js
- format.html {render :layout => 'new_base_user'}
- end
- else
- render_403
- end
- end
-
- def user_commit_homework
- homework = HomeworkCommon.find(params[:homework])
- student_work = StudentWork.where(homework_common_id: homework.id, user_id: User.current.id).first
- if student_work
-
- #提交作品时,计算是否迟交
- if Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d")
- student_work.late_penalty = homework.late_penalty
- student_work.work_status = 2
- else
- student_work.late_penalty = 0
- student_work.work_status = 1
- end
-
- student_work.save
- send_message_to_teacher(student_work)
- homework.update_column(:updated_at, Time.now)
- update_course_activity(homework.class,homework.id)
- update_user_activity(homework.class,homework.id)
- update_org_activity(homework.class,homework.id)
-
- flash[:notice] = l(:notice_successful_create)
- redirect_to student_work_index_url(:homework => params[:homework])
- else
- render_403
- end
- end
-
- def user_new_homework
- if User.current.logged?
- if params[:homework_common]
- homework = HomeworkCommon.new
- homework.name = params[:homework_common][:name]
- homework.description = params[:homework_common][:description]
- homework.end_time = params[:homework_common][:end_time] || Date.today
- if params[:homework_common][:publish_time] == ""
- homework.publish_time = Date.today
- else
- homework.publish_time = params[:homework_common][:publish_time]
- end
- homework.anonymous_comment = params[:homework_common][:anonymous_comment] ? params[:homework_common][:anonymous_comment] : 0
- homework.homework_type = params[:homework_type].to_i || 1
- homework.late_penalty = 10
- homework.teacher_priority = 1
- homework.user_id = User.current.id
- homework.course_id = params[:course_id]
-
- homework.save_attachments(params[:attachments])
- render_attachment_warning_if_needed(homework)
-
- homework_detail_manual = HomeworkDetailManual.new
- if homework.anonymous_comment == 1
- homework_detail_manual.ta_proportion = homework.homework_type == 1 ? 1.0 : 0.4
- else
- homework_detail_manual.ta_proportion = homework.homework_type == 1 ? 0.6 : 0.3
- end
- if homework.publish_time > Date.today
- homework_detail_manual.comment_status = 0
- else
- homework_detail_manual.comment_status = 1
- end
- homework_detail_manual.evaluation_start = params[:evaluation_start].blank? ? homework.end_time + 7 : params[:evaluation_start]
- homework_detail_manual.evaluation_end = params[:evaluation_end].blank? ? homework_detail_manual.evaluation_start + 7 : params[:evaluation_end]
- homework_detail_manual.evaluation_num = params[:evaluation_num] || 3
- homework_detail_manual.absence_penalty = 5
- homework.homework_detail_manual = homework_detail_manual
-
- #编程作业相关属性
- if homework.homework_type == 2
- homework_detail_programing = HomeworkDetailPrograming.new
- homework.homework_detail_programing = homework_detail_programing
- if homework.anonymous_comment == 1
- homework_detail_programing.ta_proportion = 0.6
- else
- homework_detail_programing.ta_proportion = 0.5
- end
- homework_detail_programing.language = params[:language_type].to_i
-
- inputs = params[:program][:input]
- if Array === inputs
- inputs.each_with_index do |val, i|
- homework.homework_tests << HomeworkTest.new(
- input: val,
- output: params[:program][:output][i]
- )
- end
- end
- end
-
- #分组作业
- if homework.homework_type == 3
- homework_detail_group = HomeworkDetailGroup.new
- homework.homework_detail_group = homework_detail_group
- homework_detail_group.min_num = params[:min_num].to_i
- homework_detail_group.max_num = params[:max_num].to_i
- homework_detail_group.base_on_project = params[:base_on_project].to_i
- end
-
- if homework.save
- homework_detail_manual.save if homework_detail_manual
- homework_detail_programing.save if homework_detail_programing
- homework_detail_group.save if homework_detail_group
-
- if homework.homework_type != 3
- students = homework.course.student
- if !homework.course.nil? && !students.empty?
- name = homework.name
- name_str = name + "的作品提交"
- str = ""
- students.each do |student|
- if str != ""
- str += ","
- end
- str += "('#{name_str}',#{homework.id},#{student.student_id}, '#{format_time(Time.now)}', '#{format_time(Time.now)}')"
- end
- #('#{name}的作品提交',#{homework.id},#{student.student_id}, '#{format_time(Time.now)}', '#{format_time(Time.now)}')
- sql = "insert into student_works (name, homework_common_id,user_id, created_at, updated_at) values" + str
- #StudentWork.create(:name => "#{name}的作品提交", :homework_common_id => homework.id, :user_id => student.student_id)
- ActiveRecord::Base.connection.execute sql
- end
- end
-
- if params[:quotes] && !params[:quotes].blank?
- quotes_homework = HomeworkCommon.find params[:quotes].to_i
- quotes_homework.update_column(:quotes, quotes_homework.quotes+1)
- end
- if params[:is_in_course] == "1"
- redirect_to homework_common_index_path(:course => homework.course_id)
- else
- redirect_to user_homeworks_user_path(User.current.id)
- end
- end
- end
- else
- render_403
- end
- end
-
- #用户从资源库导入资源到作业
- def user_import_resource
- @user = User.current
- user_course_ids = @user.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
- @attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
- "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").order("created_on desc")
- @type = params[:type]
- @homework_id = params[:homework_id]
- @limit = 7
- @is_remote = true
- @atta_count = @attachments.count
- @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
- @offset ||= @atta_pages.offset
- @seleted_resources = session[:seleted_resource_ids].nil? ? [] : session[:seleted_resource_ids]
- #@curse_attachments_all = @all_attachments[@offset, @limit]
- @attachments = paginateHelper @attachments,7
- respond_to do |format|
- format.js
- end
- end
-
- #引入资源列表根据类型过滤
- def user_resource_type
- if User.current.id.to_i != params[:id].to_i
- render_403
- return
- end
- user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id}
- user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id }
- # user_org_ids = User.current.organizations.map {|o| o.id}
- if(params[:type].blank? || params[:type] == "1") # 我的资源
- # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
- if params[:status] == "2"
- @attachments = get_course_resources(params[:id], user_course_ids, @order, @score)
- elsif params[:status] == "3"
- @attachments = get_project_resources(params[:id], user_project_ids, @order, @score)
- elsif params[:status] == "4"
- @attachments = get_attch_resources(params[:id], @order, @score)
- elsif params[:status] == "5"
- @attachments = get_principal_resources(params[:id], @order, @score)
- else
- # 公共资源库:所有公开资源或者我上传的私有资源
- @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score)
- end
- elsif params[:type] == "6" # 公共资源
- if params[:status] == "2"
- @attachments = get_course_resources_public( user_course_ids, @order, @score)
- elsif params[:status] == "3"
- @attachments = get_project_resources_public(user_project_ids, @order, @score)
- elsif params[:status] == "4"
- @attachments = get_attch_resources_public(@order, @score)
- elsif params[:status] == "5"
- @attachments = get_principal_resources_public(@order, @score)
- else
- # 公共资源库:所有公开资源或者我上传的私有资源
- @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score)
- end
- end
- @type = params[:type]
- @limit = 7
- @is_remote = true
- @atta_count = @attachments.count
- @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
- @offset ||= @atta_pages.offset
- @seleted_resources = session[:seleted_resource_ids].nil? ? [] : session[:seleted_resource_ids]
- #@curse_attachments_all = @all_attachments[@offset, @limit]
- @attachments = paginateHelper @attachments,7
- respond_to do |format|
- format.js
- end
- end
-
-
- #引入资源列表根据关键词过滤
- def user_ref_resource_search
- if User.current.id.to_i != params[:id].to_i
- render_403
- return
- end
- @resource_id = params[:mul_id]
- @resource_type = params[:mul_type]
- @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc"
- @score = @b_sort == "desc" ? "asc" : "desc"
- @user = User.current
- @switch_search = params[:search].nil? ? " " : params[:search]
- search = "%#{@switch_search.strip.downcase}%"
- # 别人的资源库是没有权限去看的
- if(params[:type] == "1") # 我的资源
- # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
- user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id}
- user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id }
- # user_org_ids = User.current.organizations.map {|o| o.id}
- @attachments = get_my_resources_search(params[:id], user_course_ids, user_project_ids, @order, @score, search)
- elsif (params[:type].blank? || params[:type] == "6") # 公共资源
- # 公共资源库:所有公开资源或者我上传的私有资源
- @attachments = get_public_resources_search(user_course_ids, user_project_ids, @order, @score, search)
- end
- @type = params[:type]
- @limit = 7
- @is_remote = true
- @atta_count = @attachments.count
- @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
- @offset ||= @atta_pages.offset
- @seleted_resources = session[:seleted_resource_ids].nil? ? [] : session[:seleted_resource_ids]
- #@curse_attachments_all = @all_attachments[@offset, @limit]
- @attachments = paginateHelper @attachments,7
- respond_to do |format|
- format.js
- end
- end
-
- #将资源批量引入
- def import_resources_to_homework
- @attachments = []
- unless session[:seleted_resource_ids].nil? || session[:seleted_resource_ids].blank?
- session[:seleted_resource_ids].each do |id|
- atta = Attachment.find(id)
- att_copy = atta.copy
- att_copy.container_id = nil
- att_copy.container_type = nil
- att_copy.author_id = User.current.id
- att_copy.copy_from = atta.id
- att_copy.save
- @attachments << att_copy
- end
- end
- session[:seleted_resource_ids] = [] #保存后清空
- respond_to do |format|
- format.js
- end
- end
-
- # ajax 用session保存选择的资源id
- def store_selected_resource
- session[:seleted_resource_ids] = [] if session[:seleted_resource_ids].nil?
- if params[:save] == 'y'
- session[:seleted_resource_ids] << params[:res_id]
- else
- session[:seleted_resource_ids].delete( params[:res_id])
- end
- render :nothing => true
- end
-
-
- include CoursesHelper
- def user_courses
-
- unless User.current.admin?
- if !@user.active?
- render_404
- return
- end
- end
- 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")
- if(params[:status] == '1')
- courses = courses.where("endup_time >= ? or endup_time is null or endup_time=''",Time.now)
- elsif(params[:status] == '2')
- courses = courses.where("endup_time < ?",Time.now)
- end
- @list = paginateHelper courses,10
- @params = params[:status]
- render :layout=>'base_users_new'
- end
-
- # modified by fq
- def user_newfeedback
- unless User.current.logged?
- redirect_to signin_url
- return
- end
- # 自己访问自己的页面才更新消息状态
- UserFeedbackMessage.where("user_id =? and viewed =? and journals_for_message_type =? ", User.current.id, 0, "JournalsForMessage").update_all(:viewed => true)
- # end
- @page = params[:page] ? params[:page].to_i + 1 : 0
- if params[:type].present?
- case params[:type]
- when "public"
- jours = @user.journals_for_messages.where('m_parent_id IS NULL and private = 0').order('updated_on DESC')
- when "private"
- jours = @user.journals_for_messages.where('m_parent_id IS NULL and private = 1').order('updated_on DESC')
- else
- jours = @user.journals_for_messages.where('m_parent_id IS NULL').order('updated_on DESC')
- end
- else
- jours = @user.journals_for_messages.where('m_parent_id IS NULL').order('updated_on DESC')
- end
- @jour_count = jours.count
- @jour = jours.limit(10).offset(@page * 10)
- @type = params[:type]
- if User.current == @user
- jours.update_all(:is_readed => true, :status => false)
- jours.each do |journal|
- fetch_user_leaveWord_reply(journal).update_all(:is_readed => true, :status => false)
- end
- end
- @state = false
- render :layout=>'new_base_user'
- end
-
- #给某人留言
- def feedBackTo
-
-
- end
-
- def user_comments
-
- end
-
- #end
- def index
-
- @status = params[:status] || 1
- sort_init 'login', 'asc'
- sort_update %w(login firstname lastname mail admin created_on last_login_on)
-
- case params[:format]
- when 'xml', 'json'
- @offset, @limit = api_offset_and_limit({:limit => 15})
- else
- @limit = 15
- end
-
- # retrieve all users
- # 先内连一下statuses 保证排序之后数量一致
- scope = User.visible.
- joins("INNER JOIN user_statuses ON users.id = user_statuses.user_id")
-
- # unknow
- scope = scope.in_group(params[:group_id]) if params[:group_id].present?
-
- # pagination
- @user_count = scope.count
- @user_pages = Paginator.new @user_count, @limit, params['page']
-
- # users classify
- case params[:user_sort_type]
- when '0'
- # 创建时间排序
- @s_type = 0
- @users = scope.reorder('users.created_on DESC')
- when '1'
- # 活跃度排序, 就是所谓的得分情况
- @s_type = 1
- @users = scope.
- joins("LEFT JOIN option_numbers ON users.id = option_numbers.user_id and option_numbers.score_type = 1").
- reorder('option_numbers.total_score DESC')
- when '2'
- # 粉丝数排序
- @s_type = 2
- @users = scope.
- #joins("INNER JOIN user_statuses ON users.id = user_statuses.user_id").
- reorder('user_statuses.watchers_count DESC')
-
- else
- # 默认活跃度排序
- @s_type = 1
- @users = scope.
- joins("LEFT JOIN option_numbers ON users.id = option_numbers.user_id and option_numbers.score_type = 1").
- reorder('option_numbers.total_score DESC')
- end
-
- # limit and offset
- @users = @users.limit(@user_pages.per_page).offset(@user_pages.offset)
-
- @user_base_tag = params[:id] ? 'base_users':'users_base'
- respond_to do |format|
- format.html {
- @groups = Group.all.sort
- User.current.admin? ? (render :layout => @user_base_tag) : (render_404)
- }
- format.api
- end
- end
-
- def search
- sort_init 'login', 'asc'
- sort_update %w(login firstname lastname mail admin created_on last_login_on)
- (redirect_to user_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank?
- case params[:format]
- when 'xml', 'json'
- @offset, @limit = api_offset_and_limit({:limit => 15})
- else
- @limit = 15#per_page_option
- end
- #
- #@status = params[:status] || 1
- #has = {
- # "show_changesets" => true
- #}
- # scope = User.logged.status(@status)
- # @search_by = params[:search_by] ? params[:search_by][:id] : 0
- # scope = scope.like(params[:name],@search_by) if params[:name].present?
- @search_by = params[:search_by] ? params[:search_by] : 0
-
- us = UsersService.new
- scope = us.search_user params
- @user_count = scope.count
- @user_pages = Paginator.new @user_count, @limit, params['page']
- @user_base_tag = params[:id] ? 'base_users':'users_base'
- @offset ||= @user_pages.reverse_offset
- unless @offset == 0
- @users = scope.offset(@offset).limit(@limit).all.reverse
- else
- limit = @user_count % @limit
- if limit == 0
- limit = @limit
- end
- @users = scope.offset(@offset).limit(limit).all.reverse
- end
- @name = params[:name]
- @type = 'users'
- respond_to do |format|
- format.html {
- @groups = Group.all.sort
- render :layout => @user_base_tag
- }
- format.api
- end
- end
-
- #显示更多用户课程
- def user_courses4show
- @page = params[:page].to_i + 1
- @type = params[:type]
- if @type == 'User'
- @courses = @user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(5).offset(@page * 5)
- @all_count = @user.courses.visible.where("is_delete =?", 0).count
- elsif @type == 'Syllabus'
- @syllabus = Syllabus.where("id = #{params[:syllabus]}").first
- if User.current == @syllabus.user || User.current.admin?
- all_courses = @syllabus.courses.where("is_delete = 0").select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc")
- else
- all_courses = User.current.courses.visible.where("is_delete =? and syllabus_id =?", 0, @syllabus.id).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc")
- end
- @courses = all_courses.limit(5).offset(@page * 5)
- @all_count = all_courses.count
- end
- end
-
- #显示更多用户项目
- def user_projects4show
- @page = params[:page].to_i + 1
- @projects = @user.projects.visible.select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(5).offset(@page * 5)
- end
-
- def user_course_activities
- lastid = nil
- if params[:lastid]!=nil && !params[:lastid].empty?
- lastid = params[:lastid];
- end
-
- user_ids = []
- if @user == User.current
- watcher = User.watched_by(@user)
- watcher.push(User.current)
- user_ids = watcher.map{|x| x.id}
- else
- user_ids << @user.id
- end
-
- query = Activity.joins("join courses c on c.id=#{Activity.table_name}.activity_container_id and #{Activity.table_name}.activity_container_type='Course'")
- query = query.where("#{Activity.table_name}.user_id in (?)", user_ids)
- if User.current != @user #看别人
- if @user.user_extensions!=nil && @user.user_extensions.identity == 0 #看老师
- query = query.joins("join members m on c.id=m.course_id and m.user_id = #{@user.id}")
- query = query.joins("join member_roles r on m.id = r.member_id")
- query = query.where("r.role_id in(3,7,9)")
- end
- query = query.where("c.is_public=1")
- end
- if(lastid != nil)
- query = query.where("#{Activity.table_name}.id < ?",lastid)
- end
- query = query.order("#{Activity.table_name}.id desc")
- @list = query_activities(query)
-
- render :layout=>nil
- end
-
- def user_project_activities
- lastid = nil
- if params[:lastid]!=nil && !params[:lastid].empty?
- lastid = params[:lastid];
- end
-
- user_ids = []
- if @user == User.current
- watcher = User.watched_by(@user)
- watcher.push(User.current)
- user_ids = watcher.map{|x| x.id}
- else
- user_ids << @user.id
- end
-
- query = Activity.joins("join projects c on c.id=#{Activity.table_name}.activity_container_id and #{Activity.table_name}.activity_container_type='Project'")
- query = query.where(user_id: user_ids)
- if User.current != @user #看别人
- query = query.where("c.is_public=1")
- end
- if(lastid != nil)
- query = query.where("#{Activity.table_name}.id < ?",lastid)
- end
- query = query.order("#{Activity.table_name}.id desc")
- @list = query_activities(query)
-
- render :action=>'user_course_activities',:layout=>nil
- end
-
- def user_feedback4show
- query = @user.journals_for_messages
- if params[:lastid]!=nil && !params[:lastid].empty?
- query = query.where("#{JournalsForMessage.table_name}.id < ?",params[:lastid])
- end
- logger.info('xxoo')
- @list = query.order("#{JournalsForMessage.table_name}.id desc").limit(3).all
- logger.info('aavv')
- render :layout=>nil,:locals => {:feed_list=>@list}
- end
-
- def show
- #更新用户申请成为课程老师或教辅消息的状态
- if params[:course_id] != nil
- join_course_messages = CourseMessage.where("course_id =? and course_message_type =? and user_id =? and course_message_id =? and viewed =?",
- params[:course_id], 'JoinCourseRequest', User.current.id, @user.id, false)
- join_course_messages.update_all(:viewed => true)
- end
- shield_project_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{@user.id} and shield_type='Project'").map(&:shield_id)
- shield_course_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{@user.id} and shield_type='Course'").map(&:shield_id)
- @page = params[:page] ? params[:page].to_i + 1 : 0
- user_project_ids = (@user.projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (@user.projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")"
- user_course_ids = (@user.courses.visible.where("is_delete = 0").map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (@user.courses.visible.where("is_delete = 0").map{|course| course.id}-shield_course_ids).join(",") + ")"
- course_types = "('Message','News','HomeworkCommon','Poll','Course','JournalsForMessage')"
- project_types = "('Message','Issue','Project')"
- principal_types = "JournalsForMessage"
- if params[:type].present?
- case params[:type]
- when "course_homework"
- @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'HomeworkCommon'").order('updated_at desc').limit(10).offset(@page * 10)
- when "course_news"
- @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'News'").order('updated_at desc').limit(10).offset(@page * 10)
- when "course_message"
- @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'Message'").order('updated_at desc').limit(10).offset(@page * 10)
- when "course_poll"
- @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'Poll'").order('updated_at desc').limit(10).offset(@page * 10)
- when "course_journals"
- @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'JournalsForMessage'").order('updated_at desc').limit(10).offset(@page * 10)
- when "project_issue"
- @user_activities = UserActivity.where("container_type = 'Project' and container_id in #{user_project_ids} and act_type = 'Issue'").order('updated_at desc').limit(10).offset(@page * 10)
- when "project_message"
- @user_activities = UserActivity.where("container_type = 'Project' and container_id in #{user_project_ids} and act_type = 'Message'").order('updated_at desc').limit(10).offset(@page * 10)
- when "user_journals"
- @user_activities = UserActivity.where("container_type = 'Principal' and act_type= 'JournalsForMessage' and container_id = #{@user.id}").order('updated_at desc').limit(10).offset(@page * 10)
- when "current_user"
- @user_activities = UserActivity.where("user_id = #{@user.id} and ((container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}))").order('updated_at desc').limit(10).offset(@page * 10)
- else
- if @user == User.current
- 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(','))+")"
- else
- blog_ids = "("+@user.blog.id.to_s+")"
- end
- @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" +
- "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+
- "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " +
- "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(10).offset(@page * 10)
- end
- else
- # @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id})").order('updated_at desc').limit(10).offset(@page * 10)
- # 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(','))+")"
- # 减少数据库交互
- if @user == User.current
- watched_user_ids = User.watched_by(@user.id).count == 0 ? " " : ("," + User.watched_by(@user.id).map{|u| u.id.to_s }.join(','))
- user_ids = "(" + @user.id.to_s + watched_user_ids + ")"
- else
- user_ids = "(" + @user.id.to_s + ")"
- end
- watched_user_blog_ids = Blog.select("id").where("author_id in #{user_ids}")
- blog_ids = watched_user_blog_ids.empty? ? "(-1)" : "(" + watched_user_blog_ids.map { |blog| blog.id}.join(",") + ")"
-
- @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" +
- "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+
- "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " +
- "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(10).offset(@page * 10)
- end
- # @user_activities = paginateHelper @user_activities,500
- @type = params[:type]
- respond_to do |format|
- format.js
- format.html {render :layout => 'new_base_user'}
- end
- end
-
- def show_old
- pre_count = 10 #limit
- # Time 2015-02-04 11:46:34
- # Author lizanle
- # Description type 1 :所有动态包括我关注的人 type 2:我的动态 type 3:关于我的回复
- case params[:type]
- when "1"
- if @user == User.current
- activity = Activity.where('user_id = ?', User.current.id).order('id desc')
- @activity_count = activity.count
- @activity_pages = Paginator.new @activity_count, pre_count, params['page']
- @activity = activity.offset(@activity_pages.offset).limit(@activity_pages.per_page).all
- @state = 1
- end
- when "2"
- message = []
- if @user == User.current
- message = JournalsForMessage.reference_message(@user.id)
- message += Journal.reference_message(@user.id)
- end
- @activity_count = message.size
- @info_pages = Paginator.new @activity_count, pre_count, params['page']
- messages = message.sort {|x,y| y.created_on <=> x.created_on }
- @message = messages[@info_pages.offset, @info_pages.per_page]
- @state = 2
- else
- # Time 2015-02-04 10:50:49
- # Author lizanle
- # Description 所有动态
- where_condition = nil;
- # where_condition = "act_type <> 'JournalsForMessage'"
- user_ids = []
- if @user == User.current
- watcher = User.watched_by(@user)
- watcher.push(User.current)
- user_ids = watcher.map{|x| x.id}
- else
- user_ids << @user.id
- end
- activity = Activity.where(where_condition).where(user_id: user_ids).order('id desc')
-
- permission = !User.current.admin?
- if permission
- #Issue
- act_ids = activity.where(act_type: 'Issue').select('act_id').map{|x| x.act_id}
- project_ids = Issue.where(id: act_ids).select('distinct project_id').map{|x| x.project_id}
- p_ids = []
- Project.where(id: project_ids).each do |x|
- p_ids << x.id unless x.visible?(User.current)
- end
- ids = []
- ids << Issue.where(id: act_ids, project_id: p_ids).map{|x| x.id}
-
- #HomeworkCommon
- act_ids = activity.where(act_type: 'HomeworkCommon').select('act_id').map{|x| x.act_id}
- course_ids = HomeworkCommon.where(id: act_ids).select('distinct course_id').map{|x| x.course_id}
- c_ids = []
- Course.where(id: course_ids).each do |x|
- c_ids << x.id unless x.is_public !=0 && User.current.member_of_course?(x)
- end
- ids << HomeworkCommon.where(id: act_ids, course_id: c_ids).map{|x| x.id}
-
- #Journal
- act_ids = activity.where(act_type: 'Journal').select('act_id').map{|x| x.act_id}
- project_ids = Journal.where(id:act_ids, journalized_type: 'Project').select('distinct journalized_id').map{|x| x.journalized_id}
- p_ids = []
- Project.where(id: project_ids).each do |x|
- p_ids << x.id unless x.visible?(User.current)
- end
- ids << Journal.where(id: act_ids, journalized_id: p_ids, journalized_type: 'Project').map{|x| x.id}
-
- #News
- act_ids = activity.where(act_type: 'News').select('act_id').map{|x| x.act_id}
- project_ids = News.where(id: act_ids).select('distinct project_id').map{|x| x.project_id}
- p_ids = []
- Project.where(id: project_ids).each do |x|
- p_ids << x.id unless x.visible?(User.current)
- end
- ids << News.where(id: act_ids, project_id: p_ids).map{|x| x.id}
-
- project_ids = News.where(id: act_ids).select('distinct course_id').map{|x| x.course_id}
- c_ids = []
- Course.where(id: project_ids).each do |x|
- c_ids << x.id unless x.is_public !=0 && User.current.member_of_course?(x)
- end
- ids << News.where(id: act_ids, course_id: p_ids).map{|x| x.id}
-
- #Message
- act_ids = activity.where(act_type: 'Message').select('act_id').map{|x| x.act_id}
- board_ids = Message.where(id: act_ids).select('distinct board_id').map{|x| x.board_id}
- project_ids = Board.where(id: board_ids).select('distinct project_id').map{|x| x.project_id}
- p_ids = []
- Project.where(id: project_ids).each do |x|
- p_ids << x.id unless x.visible?(User.current)
- end
- ids << Message.where(id: act_ids, board_id: p_ids).map{|x| x.id}
-
- project_ids = Board.where(id: board_ids).select('distinct course_id').map{|x| x.course_id}
- c_ids = []
- Course.where(id: project_ids).each do |x|
- c_ids << x.id unless x.is_public !=0 && User.current.member_of_course?(x)
- end
- ids << Message.where(id: act_ids, board_id: c_ids).map{|x| x.id}
-
- logger.debug "filter ids #{ids}"
-
- activity = activity.where('act_id not in (?)', ids.flatten ).order('id desc') unless ids.flatten.empty?
- end
-
- # activity = activity.reject { |e|
- # e.act.nil? ||
- # (!User.current.admin? && !e.act.nil?
- # (((e.act_type == "Issue") && !e.act.project.visible?(User.current)) ||
- # (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)) ||
- # (e.act_type == "Journal" && e.act.respond_to?("Project") && !e.act.project.visible?(User.current)) ||
- # (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)))) ||
- # (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))))))
- # }
- #
-
- @activity_count = activity.count
- @activity_pages = Paginator.new @activity_count, pre_count, params['page']
- @activity = activity.slice(@activity_pages.offset,@activity_pages.per_page)
- @state = 0
- end
-
- if params[:user].present?
-
- user_temp = User.find_by_sql("select id from users where concat(lastname,firstname) like '%#{params[:user]}%' or lastname like '%#{params[:user]}%'")
-
- if user_temp.size > 1
- activity = Activity.where('user_id in (?)', user_temp).where('user_id in (?)', watcher).order('id desc')
- elsif user_temp.size == 1
- activity = Activity.where('user_id = ?', user_temp).where('user_id in (?)', watcher).order('id desc')
- else
- activity = Activity.where("1 = 0")
- end
- @offset, @limit = api_offset_and_limit({:limit => 10})
- @activity_count = activity.count
- @activity_pages = Paginator.new @activity_count, @limit, params['page']
- @offset ||= @activity_pages.offset
- @activity = activity.offset(@offset).limit(@limit)
- @state = 0
- end
-
-
- #Modified by nie
- unless User.current.admin?
- if !@user.active? #|| (@user != User.current && @memberships.empty? && events.empty?)
- # redirect_to home_path
- render_404
- return
- end
- end
-
- respond_to do |format|
- format.html
- format.api
- end
- end
-
- ##end fq
-
- #### added by fq
- def info
-
- message = []
- if @user == User.current
- message = JournalsForMessage.reference_message(@user.id)
- message += Journal.reference_message(@user.id)
- end
- @offset, @limit = api_offset_and_limit({:limit => 10})
- @info_count = message.size
- @info_pages = Paginator.new @info_count, @limit, params['page']
- @offset ||= @info_pages.offset
-
- messages = message.sort {|x,y| y.created_on <=> x.created_on }
-
- @message = messages[@offset, @limit]
-
- unless User.current.admin?
- if !@user.active?
- render_404
- return
- end
- end
-
- respond_to do |format|
- format.html
- format.api
- end
- end
- #### end
-
-
- def new
- @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option)
- @auth_sources = AuthSource.all
- render :layout => "users_base"
- end
-
- def create
- @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option)
- @user.safe_attributes = params[:user]
- @user.admin = params[:user][:admin] || false
- @user.login = params[:user][:login]
- @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation] unless @user.auth_source_id
-
- if @user.save
- @user.pref.attributes = params[:pref]
- @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
- @user.pref.save
- @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : [])
-
- Mailer.run.account_information(@user, params[:user][:password]) if params[:send_information]
-
- respond_to do |format|
- format.html {
- flash[:notice] = l(:notice_user_successful_create, :id => view_context.link_to(@user.login, user_path(@user)))
- if params[:continue]
- redirect_to new_user_url
- else
- redirect_to edit_user_url(@user)
- end
- }
- format.api { render :action => 'show', :status => :created, :location => user_url(@user) }
- end
- else
- @auth_sources = AuthSource.all
- # Clear password input
- @user.password = @user.password_confirmation = nil
-
- respond_to do |format|
- format.html { render :action => 'new',:layout => "users_base" }
- format.api { render_validation_errors(@user) }
- end
- end
-
- unless @user.id.nil?
- #后台注册的用户默认权限为男性开发员
- ue = UserExtensions.create(:identity => 3,
- :gender => 0,
- :user_id => @user.id)
- ue.save
- end
- end
-
- def edit
- @auth_sources = AuthSource.all
- @membership ||= Member.new
- end
-
- def watch_projects
- @watch_projects = Project.joins(:watchers).where("project_type <>? and watchable_type = ? and `watchers`.user_id = ?", '1','Project', @user.id)
- @state = 1
- respond_to do |format|
- format.html {
- render :layout => 'base_users'
- }
- format.api
- end
- end
-
- def update
- @user.admin = params[:user][:admin] if params[:user][:admin]
- @user.login = params[:user][:login] if params[:user][:login]
- if params[:user][:password].present? && (@user.auth_source_id.nil? || params[:user][:auth_source_id].blank?)
- @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation]
- end
- @user.safe_attributes = params[:user]
- # Was the account actived ? (do it before User#save clears the change)
- was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE])
- # TODO: Similar to My#account
- @user.pref.attributes = params[:pref]
- @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
-
- if @user.save
- @user.pref.save
- @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : [])
-
- if was_activated
- Mailer.run.account_activated(@user)
- elsif @user.active? && params[:send_information] && !params[:user][:password].blank? && @user.auth_source_id.nil?
- Mailer.run.account_information(@user, params[:user][:password])
- end
-
- respond_to do |format|
- format.html {
- flash[:notice] = l(:notice_successful_update)
- redirect_to_referer_or edit_user_url(@user)
- }
- format.api { render_api_ok }
- end
- else
- @auth_sources = AuthSource.all
- @membership ||= Member.new
- # Clear password input
- @user.password = @user.password_confirmation = nil
-
- respond_to do |format|
- format.html { render :action => :edit }
- format.api { render_validation_errors(@user) }
- end
- end
- end
-
- # 上传用户资源
- def user_resource_create
- user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id}
- user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id }
- # user_org_ids = User.current.organizations.map {|o| o.id}
- @user = User.find(params[:id])
- # 保存文件
- attach = Attachment.attach_filesex_public(@user, params[:attachments], params[:attachment_type], is_public = true)
- @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc"
- @score = @b_sort == "desc" ? "asc" : "desc"
- # user_org_ids = User.current.organizations.map {|o| o.id}
- if(params[:type].blank? || params[:type] == "1") # 我的资源
- # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
- if params[:status] == "2"
- @attachments = get_course_resources(params[:id], user_course_ids, @order, @score)
- elsif params[:status] == "3"
- @attachments = get_project_resources(params[:id], user_project_ids, @order, @score)
- elsif params[:status] == "4"
- @attachments = get_attch_resources(params[:id], @order, @score)
- elsif params[:status] == "5"
- @attachments = get_principal_resources(params[:id], @order, @score)
- else
- # 公共资源库:所有公开资源或者我上传的私有资源
- @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score)
- end
- elsif params[:type] == "6" # 公共资源
- if params[:status] == "2"
- @attachments = get_course_resources_public( user_course_ids, @order, @score)
- elsif params[:status] == "3"
- @attachments = get_project_resources_public(user_project_ids, @order, @score)
- elsif params[:status] == "4"
- @attachments = get_attch_resources_public(@order, @score)
- elsif params[:status] == "5"
- @attachments = get_principal_resources_public(@order, @score)
- else
- # 公共资源库:所有公开资源或者我上传的私有资源
- @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score)
- end
- end
-
- @status = params[:status]
- @type = params[:type]
- @path = user_resource_user_path(User.current, :type => @type)
- @limit = 25
- @is_remote = true
- @atta_count = @attachments.count
- @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
- @offset ||= @atta_pages.offset
- #@curse_attachments_all = @all_attachments[@offset, @limit]
- @attachments = paginateHelper @attachments,25
- respond_to do |format|
- format.js
- end
- end
-
- # 删除用户资源,分为批量删除 和 单个删除,只能删除自己上传的资源
- def user_resource_delete
- if params[:resource_id].present?
- Attachment.where("author_id =? and id =?", User.current.id, params[:resource_id]).first.destroy
- elsif params[:checkbox1].present?
- params[:checkbox1].each do |id|
- Attachment.where("author_id =? and id =?", User.current.id, id).first.destroy
- end
- end
- @user = User.current
- @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc"
- @score = @b_sort == "desc" ? "asc" : "desc"
- user_course_ids = User.current.courses.map { |c| c.id}
- user_project_ids = User.current.projects.map {|p| p.id}
- # user_org_ids = User.current.organizations.map {|o| o.id}
- if(params[:type].blank? || params[:type] == "1") # 我的资源
- # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
- if params[:status] == "2"
- @attachments = get_course_resources(params[:id], user_course_ids, @order, @score)
- elsif params[:status] == "3"
- @attachments = get_project_resources(params[:id], user_project_ids, @order, @score)
- elsif params[:status] == "4"
- @attachments = get_attch_resources(params[:id], @order, @score)
- elsif params[:status] == "5"
- @attachments = get_principal_resources(params[:id], @order, @score)
- else
- # 公共资源库:所有公开资源或者我上传的私有资源
- @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score)
- end
- elsif params[:type] == "6" # 公共资源
- if params[:status] == "2"
- @attachments = get_course_resources_public( user_course_ids, @order, @score)
- elsif params[:status] == "3"
- @attachments = get_project_resources_public(user_project_ids, @order, @score)
- elsif params[:status] == "4"
- @attachments = get_attch_resources_public(@order, @score)
- elsif params[:status] == "5"
- @attachments = get_principal_resources_public(@order, @score)
- else
- # 公共资源库:所有公开资源或者我上传的私有资源
- @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score)
- end
- end
- @status = params[:status]
- @type = params[:type]
- @path = user_resource_user_path(User.current, :type => @type)
- @limit = 25
- @is_remote = true
- @atta_count = @attachments.count
- @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
- @offset ||= @atta_pages.offset
- #@curse_attachments_all = @all_attachments[@offset, @limit]
- @attachments = paginateHelper @attachments,25
- respond_to do |format|
- format.js
- end
- end
-
- #根据id或者名称搜索教师或者助教为当前用户的课程
- def search_user_course
- @user = User.current
- if !params[:search].nil?
- search = "%#{params[:search].to_s.strip.downcase}%"
- @course = @user.courses.where(" #{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) and course.is_delete == 0 }
- else
- @course = @user.courses
- .select { |course| @user.allowed_to?(:as_teacher,course) and course.is_delete == 0 }
- end
- @search = params[:search]
- @type = params[:type]
- #这里仅仅是传递需要发送的资源id
- @send_id = params[:send_id]
- @send_ids = params[:checkbox1] || params[:send_ids]
- respond_to do |format|
- format.js
- end
- end
-
- # 根据id或者名称搜索当前用户所在的项目
- def search_user_project
- @user = User.current
- if !params[:search].nil?
- search = "%#{params[:search].to_s.strip.downcase}%"
- @projects = @user.projects.where(" #{Project.table_name}.id = #{params[:search].to_i } or #{Project.table_name}.name like :p",:p=>search)
- else
- @projects = @user.projects.visible
- end
- @search = params[:search]
- @type = params[:type]
- #这里仅仅是传递需要发送的资源id
- @send_id = params[:send_id]
- @send_ids = params[:checkbox1] || params[:send_ids] #搜索的时候 和 直接 用表格提交的时候的send_ids
- respond_to do |format|
- format.js
- end
- end
-
- # 将资源发送到对应的课程,分为发送单个,或者批量发送
- def add_exist_file_to_course
- @flag = true
- if params[:send_id].present?
- rs = ResourcesService.new
- @ori, @flag, @save_message = rs.send_resource_to_course(User.current, params)
- elsif params[:send_ids].present?
- send_ids = params[:send_ids].split(",")
- course_ids = params[:course_ids]
- if course_ids.nil?
- @flag = false
- end
- send_ids.each do |send_id|
- quotes = 0
- @ori = Attachment.find_by_id(send_id)
- unless course_ids.nil?
- course_ids.each do |id|
- quotes = 0
- next if @ori.blank?
- @exist = false
- Course.find(id).attachments.each do |att| #如果课程中包含该资源
- 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
- att.created_on = Time.now
- att.save
- @exist = true
- break
- end
- end
- next if @exist
- attach_copied_obj = @ori.copy
- attach_copied_obj.tag_list.add(@ori.tag_list) # tag关联
- attach_copied_obj.container = Course.find(id)
- attach_copied_obj.created_on = Time.now
- attach_copied_obj.author_id = User.current.id
- attach_copied_obj.is_public = 0
- attach_copied_obj.copy_from = @ori.copy_from.nil? ? @ori.id : @ori.copy_from #发送要添加copy_from
- if attach_copied_obj.attachtype == nil
- attach_copied_obj.attachtype = 4
- end
- if attach_copied_obj.save
- # 更新引用次数
- quotes = @ori.quotes.to_i + 1
- @ori.update_attribute(:quotes, quotes) unless @ori.nil?
- @ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now)
- end
- @save_message = attach_copied_obj.errors.full_messages
- end
- end
- end
- else
- @flag = false
- end
- @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc"
- @score = @b_sort == "desc" ? "asc" : "desc"
- user_project_ids = User.current.projects.map {|p| p.id}
- user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
- if(params[:type] == "1") # 我的资源
- # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
- if params[:status] == "2"
- @attachments = get_course_resources(params[:id], user_course_ids, @order, @score)
- elsif params[:status] == "3"
- @attachments = get_project_resources(params[:id], user_project_ids, @order, @score)
- elsif params[:status] == "4"
- @attachments = get_attch_resources(params[:id], @order, @score)
- elsif params[:status] == "5"
- @attachments = get_principal_resources(params[:id], @order, @score)
- else
- # 公共资源库:所有公开资源或者我上传的私有资源
- @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score)
- end
- elsif (params[:type].blank? || params[:type] == "6") # 公共资源
- if params[:status] == "2"
- @attachments = get_course_resources_public( user_course_ids, @order, @score)
- elsif params[:status] == "3"
- @attachments = get_project_resources_public(user_project_ids, @order, @score)
- elsif params[:status] == "4"
- @attachments = get_attch_resources_public(@order, @score)
- elsif params[:status] == "5"
- @attachments = get_principal_resources_public(@order, @score)
- else
- # 公共资源库:所有公开资源或者我上传的私有资源
- @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score)
- end
- # elsif params[:type] == "2"
- # apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id}
- # if params[:status] == "2"
- # resource_type = "'Course'"
- # elsif params[:status] == "3"
- # resource_type = "'Project'"
- # elsif params[:status] == "5"
- # resource_type = "'Principal'"
- # else
- # resource_type = "'Project','OrgSubfield','Principal','Course'"
- # end
- # @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score)
- end
- @type = params[:type]
- @limit = 25
- @path = user_resource_user_path(User.current, :type => @type)
- @user = User.current
- @is_remote = true
- @atta_count = @attachments.count
- @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
- @offset ||= @atta_pages.offset
- #@curse_attachments_all = @all_attachments[@offset, @limit]
- @attachments = paginateHelper @attachments,25
- respond_to do |format|
- format.js
- end
- end
-
- # 添加资源到对应的项目
- def add_exist_file_to_project
- @flag = true
- # 发送单个资源
- if params[:send_id].present?
- send_id = params[:send_id]
- project_ids = params[:projects_ids]
- if project_ids.nil?
- @flag = false
- end
- ori = Attachment.find_by_id(send_id)
- unless project_ids.nil?
- project_ids.each do |project_id|
- next if ori.blank?
- @exist = false
- # 如果对象中包含该资源
- Project.find(project_id).attachments.each do |att|
- 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
- att.created_on = Time.now
- att.save
- @exist = true
- break
- end
- end
- next if @exist
- attach_copied_obj = ori.copy
- attach_copied_obj.tag_list.add(ori.tag_list) # tag关联
- attach_copied_obj.container = Project.find(project_id)
- attach_copied_obj.created_on = Time.now
- attach_copied_obj.author_id = User.current.id
- attach_copied_obj.is_public = 0
- attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from
- if attach_copied_obj.attachtype == nil
- attach_copied_obj.attachtype = 1
- end
- if attach_copied_obj.save
- # 更新引用次数
- quotes = ori.quotes.to_i + 1
- ori.update_attribute(:quotes, quotes) unless ori.nil?
- ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now)
- # 项目中添加动态
- ForgeActivity.create(:user_id => User.current.id, :project_id => project_id, :forge_act_id => attach_copied_obj.id, :forge_act_type => "Attachment" )
- end
- unless Project.find(project_id).project_score.nil?
- Project.find(project_id).project_score.update_attribute(:attach_num,
- Project.find(project_id).project_score.attach_num + 1)
- end
- end
- @ori = ori
- end
- # 发送多个资源
- elsif params[:send_ids].present?
- send_ids = params[:send_ids].split(",")
- project_ids = params[:projects_ids]
- if project_ids.nil?
- @flag = false
- end
- send_ids.each do |send_id|
- quotes = 0
- ori = Attachment.find_by_id(send_id)
- unless project_ids.nil?
- project_ids.each do |project_id|
- quotes = 0
- next if ori.blank?
- @exist = false
- Project.find(project_id).attachments.each do |att| #如果课程中包含该资源
- 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
- att.created_on = Time.now
- att.save
- @exist = true
- break
- end
- end
- next if @exist
- attach_copied_obj = ori.copy
- attach_copied_obj.tag_list.add(ori.tag_list) # tag关联
- attach_copied_obj.container = Project.find(project_id)
- attach_copied_obj.created_on = Time.now
- attach_copied_obj.author_id = User.current.id
- attach_copied_obj.is_public = 0
- attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from
- if attach_copied_obj.attachtype == nil
- attach_copied_obj.attachtype = 1
- end
- if attach_copied_obj.save
- # 更新引用次数
- quotes = ori.quotes.to_i + 1
- ori.update_attribute(:quotes, quotes) unless ori.nil?
- ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now)
- # 项目中添加动态
- ForgeActivity.create(:user_id => User.current.id, :project_id => project_id, :forge_act_id => attach_copied_obj.id, :forge_act_type => "Attachment" )
- end
- unless Project.find(project_id).project_score.nil?
- Project.find(project_id).project_score.update_attribute(:attach_num, Project.find(project_id).project_score.attach_num + 1)
- end
- end
- end
- end
- else
- @flag=true
- end
- @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc"
- @score = @b_sort == "desc" ? "asc" : "desc"
- user_project_ids = User.current.projects.map {|p| p.id}
- user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
- if(params[:type] == "1") # 我的资源
- # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
- if params[:status] == "2"
- @attachments = get_course_resources(params[:id], user_course_ids, @order, @score)
- elsif params[:status] == "3"
- @attachments = get_project_resources(params[:id], user_project_ids, @order, @score)
- elsif params[:status] == "4"
- @attachments = get_attch_resources(params[:id], @order, @score)
- elsif params[:status] == "5"
- @attachments = get_principal_resources(params[:id], @order, @score)
- else
- # 公共资源库:所有公开资源或者我上传的私有资源
- @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score)
- end
- elsif (params[:type].blank? || params[:type] == "6") # 公共资源
- if params[:status] == "2"
- @attachments = get_course_resources_public( user_course_ids, @order, @score)
- elsif params[:status] == "3"
- @attachments = get_project_resources_public(user_project_ids, @order, @score)
- elsif params[:status] == "4"
- @attachments = get_attch_resources_public(@order, @score)
- elsif params[:status] == "5"
- @attachments = get_principal_resources_public(@order, @score)
- else
- # 公共资源库:所有公开资源或者我上传的私有资源
- @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score)
- end
- # elsif params[:type] == "2"
- # apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id}
- # if params[:status] == "2"
- # resource_type = "'Course'"
- # elsif params[:status] == "3"
- # resource_type = "'Project'"
- # elsif params[:status] == "5"
- # resource_type = "'Principal'"
- # else
- # resource_type = "'Project','OrgSubfield','Principal','Course'"
- # end
- # @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score)
- end
- @status = params[:status]
- @type = params[:type]
- @limit = 25
- @path = user_resource_user_path(User.current, :type => @type)
- @user = User.current
- @is_remote = true
- @atta_count = @attachments.count
- @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
- @offset ||= @atta_pages.offset
- #@curse_attachments_all = @all_attachments[@offset, @limit]
- @attachments = paginateHelper @attachments,25
- respond_to do |format|
- format.js
- end
- end
-
- def add_exist_file_to_org
- @flag = true
- if params[:send_id].present?
- send_id = params[:send_id]
- subfield_id = params[:subfield]
- if subfield_id.nil?
- @flag = false
- end
- ori = Attachment.find_by_id(send_id)
- unless subfield_id.nil?
- attach_copied_obj = ori.copy
- @exist = false
- OrgSubfield.find(subfield_id).attachments.each do |att| #如果课程中包含该资源
- 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
- att.created_on = Time.now
- att.save
- @exist = true
- break
- end
- end
- if @exist == false #如果不存在该资源
- attach_copied_obj.tag_list.add(ori.tag_list) # tag关联
- attach_copied_obj.container = OrgSubfield.find(subfield_id)
- attach_copied_obj.created_on = Time.now
- attach_copied_obj.author_id = User.current.id
- attach_copied_obj.is_public = 0
- attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from
- if attach_copied_obj.attachtype == nil
- attach_copied_obj.attachtype = 1
- end
- if attach_copied_obj.save
- # 更新引用次数
- quotes = ori.quotes.to_i + 1
- ori.update_attribute(:quotes, quotes) unless ori.nil?
- ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now)
- end
- end
- end
- @ori = ori
- elsif params[:send_ids].present?
- send_ids = params[:send_ids].split(",")
- subfield_id = params[:subfield]
- if subfield_id.nil?
- @flag = false
- end
- send_ids.each do |send_id|
- quotes = 0
- ori = Attachment.find_by_id(send_id)
- unless subfield_id.nil?
- next if ori.blank?
- @exist = false
- OrgSubfield.find(subfield_id).attachments.each do |att| #如果课程中包含该资源
- 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
- att.created_on = Time.now
- att.save
- @exist = true
- break
- end
- end
- next if @exist
- attach_copied_obj = ori.copy
- attach_copied_obj.tag_list.add(ori.tag_list) # tag关联
- attach_copied_obj.container = OrgSubfield.find(subfield_id)
- attach_copied_obj.created_on = Time.now
- attach_copied_obj.author_id = User.current.id
- attach_copied_obj.is_public = 0
- attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from
- if attach_copied_obj.attachtype == nil
- attach_copied_obj.attachtype = 1
- end
- if attach_copied_obj.save
- # 更新引用次数
- quotes = ori.quotes.to_i + 1
- ori.update_attribute(:quotes, quotes) unless ori.nil?
- ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now)
- end
- end
- end
- else
- @flag=true
- end
- @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc"
- @score = @b_sort == "desc" ? "asc" : "desc"
- user_project_ids = User.current.projects.map {|p| p.id}
- user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
- if(params[:type] == "1") # 我的资源
- # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
- if params[:status] == "2"
- @attachments = get_course_resources(params[:id], user_course_ids, @order, @score)
- elsif params[:status] == "3"
- @attachments = get_project_resources(params[:id], user_project_ids, @order, @score)
- elsif params[:status] == "4"
- @attachments = get_attch_resources(params[:id], @order, @score)
- elsif params[:status] == "5"
- @attachments = get_principal_resources(params[:id], @order, @score)
- else
- # 公共资源库:所有公开资源或者我上传的私有资源
- @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score)
- end
- elsif (params[:type].blank? || params[:type] == "6") # 公共资源
- if params[:status] == "2"
- @attachments = get_course_resources_public( user_course_ids, @order, @score)
- elsif params[:status] == "3"
- @attachments = get_project_resources_public(user_project_ids, @order, @score)
- elsif params[:status] == "4"
- @attachments = get_attch_resources_public(@order, @score)
- elsif params[:status] == "5"
- @attachments = get_principal_resources_public(@order, @score)
- else
- # 公共资源库:所有公开资源或者我上传的私有资源
- @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score)
- end
- # elsif params[:type] == "2"
- # apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id}
- # if params[:status] == "2"
- # resource_type = "'Course'"
- # elsif params[:status] == "3"
- # resource_type = "'Project'"
- # elsif params[:status] == "5"
- # resource_type = "'Principal'"
- # else
- # resource_type = "'Project','OrgSubfield','Principal','Course'"
- # end
- # @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score)
- end
- @type = params[:type]
- @limit = 25
- @path = user_resource_user_path(User.current, :type => @type)
- @user = User.current
- @is_remote = true
- @atta_count = @attachments.count
- @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
- @offset ||= @atta_pages.offset
- #@curse_attachments_all = @all_attachments[@offset, @limit]
- @attachments = paginateHelper @attachments,25
- respond_to do |format|
- format.js
- end
- end
-
- def share_news_to_course
- news = News.find(params[:send_id])
- course_ids = params[:course_ids]
- course_ids.each do |course_id|
- if Course.find(course_id).news.map(&:id).exclude?(news.id)
- 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)
- #record forward to table forwards if new record is valid
- if course_news.valid?
- news.forwards << Forward.new(:to_type => course_news.class.name, :to_id => course_news.id)
- end
- news.attachments.each do |attach|
- course_news.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest,
- :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype,
- :is_public => attach.is_public, :quotes => 0)
- end
- end
- end
- end
-
- def share_news_to_project
- news = News.find(params[:send_id])
- project_ids = params[:project_ids]
- project_ids.each do |project_id|
- project = Project.find(project_id)
- if project.news.map(&:id).exclude?(news.id)
- message = Message.create(:board_id => project.boards.first.id, :subject => news.title, :content => news.description, :author_id => User.current.id)
- # record forward to table forwards if new record is valid
- if message.valid?
- news.forwards << Forward.new(:to_type => message.class.name, :to_id => message.id)
- end
- news.attachments.each do |attach|
- message.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest,
- :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype,
- :is_public => attach.is_public, :quotes => 0)
- end
- end
- end
- end
-
- def share_news_to_org
- news = News.find(params[:send_id])
- field_id = params[:subfield]
- 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)
- # record forward to table forwards if new record is valid
- if org_news.valid?
- news.forwards << Forward.new(:to_type => org_news.class.name, :to_id => org_news.id)
- end
- news.attachments.each do |attach|
- org_news.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest,
- :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype,
- :is_public => attach.is_public, :quotes => 0)
- end
- 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)
- end
-
- def share_message_to_course
- @message = Message.find(params[:send_id])
- course_ids = params[:course_ids]
- course_ids.each do |course_id|
- course = Course.find(course_id)
- if course.news.map(&:id).exclude?(@message.id)
- message = Message.create(:board_id => course.boards.first.id, :subject => @message.subject, :content => @message.content, :author_id => User.current.id)
- # record forward to table forwards if new record is valid
- if message.valid?
- @message.forwards << Forward.new(:to_type => message.class.name, :to_id => message.id)
- end
- @message.attachments.each do |attach|
- message.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest,
- :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype,
- :is_public => attach.is_public, :quotes => 0)
- end
- end
- end
- end
-
- def share_message_to_project
- @message = Message.find(params[:send_id])
- project_ids = params[:project_ids]
- project_ids.each do |project_id|
- project = Project.find(project_id)
- if project.news.map(&:id).exclude?(@message.id)
- message = Message.create(:board_id => project.boards.first.id, :subject => @message.subject, :content => @message.content, :author_id => User.current.id)
- # record forward to table forwards if new record is valid
- if message.valid?
- @message.forwards << Forward.new(:to_type => message.class.name, :to_id => message.id)
- end
- @message.attachments.each do |attach|
- message.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest,
- :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype,
- :is_public => attach.is_public, :quotes => 0)
- end
- end
- end
- end
-
- def share_message_to_org
- field_id = params[:subfield]
- @message = Message.find(params[:send_id])
- @message.quotes = @message.quotes.nil? ? 1 : (@message.quotes + 1)
- @message.save
- board = OrgSubfield.find(field_id).boards.first
- mes = Message.create(:board_id => board.id, :subject => @message.subject, :content => @message.content, :author_id => User.current.id)
- # record forward to table forwards if new record is valid
- if mes.valid?
- @message.forwards << Forward.new(:to_type => mes.class.name, :to_id => mes.id)
- end
- @message.attachments.each do |attach|
- mes.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest,
- :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype,
- :is_public => attach.is_public, :quotes => 0)
- end
- 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)
- end
-
- def change_org_subfield
-
- end
-
- # 资源预览
- def resource_preview
- preview_id = params[:resource_id]
- @file = Attachment.find(preview_id)
- @preview_able = false;
- if %w(pdf pptx doc docx xls xlsx).any?{|x| @file.filename.downcase.end_with?(x)}
- @preview_able = true;
- end
- respond_to do |format|
- format.js
- end
- end
-
- # 重命名资源
- def rename_resource
- @attachment = Attachment.find(params[:res_id]) if params[:res_id].present?
- if @attachment != nil
- @attachment.filename = params[:res_name]
- @flag = @attachment.save
- end
- # respond_to do |format|
- # format.js
- # end
- if @flag
- render :text=> download_named_attachment_path(@attachment.id, @attachment.filename)
- else
- render :text=>'fail'
- end
- end
-
- def destroy
- @user.destroy
- respond_to do |format|
- format.html { redirect_back_or_default(admin_users_path) }
- format.api { render_api_ok }
- end
- end
-
- def edit_membership
- @membership = Member.edit_membership(params[:membership_id], params[:membership], @user)
- @membership.save
- respond_to do |format|
- format.html { redirect_to edit_user_url(@user, :tab => 'memberships') }
- format.js
- end
- end
-
- def destroy_membership
- @membership = Member.find(params[:membership_id])
- if @membership.deletable?
- @membership.destroy
- end
- respond_to do |format|
- format.html { redirect_to edit_user_url(@user, :tab => 'memberships') }
- format.js
- end
- end
-
- ################# added by william
- def tag_save
- @tags = params[:tag_for_save][:name]
- @obj_id = params[:tag_for_save][:object_id]
- @obj_flag = params[:tag_for_save][:object_flag]
-
- case @obj_flag
- when '1' then
- @obj = User.find_by_id(@obj_id)
- when '2' then
- @obj = Project.find_by_id(@obj_id)
- when '3' then
- @obj = Issue.find_by_id(@obj_id)
- when '4' then
- # @obj = Bid.find_by_id(@obj_id)
- when '5' then
- @obj = Forum.find_by_id(@obj_id)
- when '6'
- @obj = Attachment.find_by_id(@obj_id)
- when '7' then
- @obj = Contest.find_by_id(@obj_id)
- when '8'
- @obj = OpenSourceProject.find_by_id(@obj_id)
- when '9'
- @obj = Course.find_by_id(@obj_id)
- else
- @obj = nil
- end
- unless @obj.nil?
- @obj.tag_list.add(@tags.split(","))
- else
- return
- end
- if @obj.save
- logger.debug "#{__FILE__}:#{__LINE__} ===> #{@obj.to_json}"
- else
- logger.error "#{__FILE__}:#{__LINE__} ===> #{@obj.errors.try(:full_messages)}"
- end
- respond_to do |format|
- format.js
- format.html
- end
- end
-
- def tag_saveEx
- @tags = params[:tag_name]
- @obj_id = params[:obj_id]
- @obj_flag = params[:obj_flag]
-
- case @obj_flag
- when '1' then
- @obj = User.find_by_id(@obj_id)
- when '2' then
- @obj = Project.find_by_id(@obj_id)
- when '3' then
- @obj = Issue.find_by_id(@obj_id)
- when '4' then
- # @obj = Bid.find_by_id(@obj_id)
- when '5' then
- @obj = Forum.find_by_id(@obj_id)
- when '6'
- @obj = Attachment.find_by_id(@obj_id)
- when '7' then
- @obj = Contest.find_by_id(@obj_id)
- when '8'
- @obj = OpenSourceProject.find_by_id(@obj_id)
- when '9'
- @obj = Course.find_by_id(@obj_id)
- else
- @obj = nil
- end
- unless @obj.nil?
- @obj.tag_list.add(@tags.split(","))
- else
- return
- end
- if @obj.save
- ## 执行成功的操作。
- else
- #捕获异常
- end
- respond_to do |format|
- format.js
- format.html
- end
- end
- ###add by huang
- def user_watchlist
- limit = 10;
- query = User.watched_by(@user.id);
- @obj_count = query.count();
- @obj_pages = Paginator.new @obj_count,limit,params['page']
- @list = query.order("#{Watcher.table_name}.id desc").limit(limit).offset(@obj_pages.offset).all();
- @action = 'watch'
- render :template=>'users/user_fanslist',:layout=>'new_base_user'
- end
- ###add by huang
- def user_fanslist
- limit = 10;
- query = @user.watcher_users;
- @obj_count = query.count();
- @obj_pages = Paginator.new @obj_count,limit,params['page']
- @list = query.order("#{Watcher.table_name}.id desc").limit(limit).offset(@obj_pages.offset).all();
- @action = 'fans'
- render :layout=>'new_base_user'
- end
- def user_visitorlist
- limit = 10;
- #query = @user.watcher_users;
- query = User.joins("join visitors v on #{User.table_name}.id=v.user_id")
- query = query.where("v.master_id=?",@user.id)
- @obj_count = query.count();
- @obj_pages = Paginator.new @obj_count,limit,params['page']
- @list = query.order("v.updated_on desc").limit(limit).offset(@obj_pages.offset).all();
- @action = 'visitor'
- render :template=>'users/user_fanslist',:layout=>'base_users_new'
- end
-
- #william
- def update_extensions(user_extensions)
- user_extensions = params[:user_extensions]
- unless user_extensions.nil?
- user_extensions = UserExtensions.find_by_id(user_extensions.user_id)
-
- # user_extensions.
- end
- end
-
- def update_score
- @user = User.find(params[:id])
- end
-
- #修改个人简介
- def edit_brief_introduction
- if @user && @user.extensions
- @user.extensions.update_column("brief_introduction",params[:brief_introduction])
- end
- respond_to do |format|
- format.js
- end
- end
-
- # 获取公共资源
- def get_public_resources user_course_ids, user_project_ids, order, score
- 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}")
- end
-
- # 获取公共资源搜索
- def get_public_resources_search user_course_ids, user_project_ids, order, score, search
- 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}")
- end
-
- # 获取我的资源
- def get_my_resources author_id, user_course_ids, user_project_ids, order, score
- 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')) "+
- "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)" +
- "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}")
- end
-
- # 获取我的资源查询结果
- def get_my_resources_search (author_id, user_course_ids, user_project_ids, order, score, search)
- @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')) "+
- "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)" +
- "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}")
- end
-
- # 获取我的课程资源
- def get_course_resources author_id, user_course_ids, order, score
- 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')"+
- "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)" ).order("#{order.nil? ? 'created_on' : order} #{score}")
- end
-
- # # 获取我的私有资源分享结果
- # def get_my_private_resources apply_ids, resource_type, order, score
- # 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}")
- # end
- #
- # # 获取我的私有资源分享搜索结果
- # def get_my_private_resources_search apply_ids, resource_type, order, score, search
- # 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}")
- # end
-
- # 获取我的课程资源中搜索结果
- def get_course_resources_search author_id, user_course_ids, order, score, search
- attchments = Attachment.where("((author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Course')"+
- "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)) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}")
- end
-
- # 获取公共资源中课程资源
- def get_course_resources_public user_course_ids, order, score
- 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}")
- end
-
- # 获取公共资源中课程资源搜索结果
- def get_course_resources_public_search user_course_ids, order, score, search
- 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}")
- end
-
- # 获取我的项目资源
- def get_project_resources author_id, user_project_ids, order, score
- attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Project') "+
- "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}")
- end
-
- # 获取我的项目资源搜索
- def get_project_resources_search author_id, user_project_ids, order, score, search
- attchments = Attachment.where("((author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Project') "+
- "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}")
- end
-
- # 获取公共资源的项目资源
- def get_project_resources_public user_project_ids, order, score
- attchments = Attachment.where("container_type = 'Project' and container_id is not null and is_public =1").order("#{order.nil? ? 'created_on' : order} #{score}")
- end
-
- # 获取公共资源的项目资源搜索
- def get_project_resources_public_search user_project_ids, order, score, search
- 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}")
- end
-
- # 获取我上传的附件
- def get_attch_resources author_id, order, score
- 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',
- 'Document','Message','News','StudentWorkScore','HomewCommon'))").order("#{order.nil? ? 'created_on' : order} #{score}")
- end
-
- # 获取我上传的附件搜索结果
- def get_attch_resources_search author_id, order, score, search
- 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',
- 'Document','Message','News','StudentWorkScore','HomewCommon')) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}")
- end
-
- # 获取公共资源中我上传的附件
- def get_attch_resources_public order, score
- attchments = Attachment.where("container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')
- and container_id is not null and is_public =1").order("#{order.nil? ? 'created_on' : order} #{score}")
- end
-
- # 获取公共资源中我上传的附件
- def get_attch_resources_public_search order, score, search
- attchments = Attachment.where("(container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')
- and container_id is not null and is_public =1) and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}")
- end
-
- # 获取我的用户类型资源
- def get_principal_resources author_id, order, score
- 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}")
- end
-
- # 获取我的用户类型资源搜索
- def get_principal_resources_search author_id, order, score, search
- 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}")
- end
-
- # 获取我的用户类型资源
- def get_principal_resources_public order, score
- attchments = Attachment.where("container_type = 'Principal' and is_public =1 and container_id is not null").order("#{order.nil? ? 'created_on' : order} #{score}")
- end
-
- # 获取我的用户类型资源
- def get_principal_resources_public_search order, score, search
- 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}")
- end
-
- # 资源库 分为全部 课程资源 项目资源 附件
- def user_resource
- # 别人的资源库是没有权限去看的
- if User.current.id.to_i != @user.id.to_i
- render_403
- return
- end
- @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc"
- @score = @b_sort == "desc" ? "asc" : "desc"
- user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id}
- user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id }
- # user_org_ids = User.current.organizations.map {|o| o.id}
- if( params[:type] == "1") # 我的资源
- # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
- if params[:status] == "2"
- @attachments = get_course_resources(params[:id], user_course_ids, @order, @score)
- elsif params[:status] == "3"
- @attachments = get_project_resources(params[:id], user_project_ids, @order, @score)
- elsif params[:status] == "4"
- @attachments = get_attch_resources(params[:id], @order, @score)
- elsif params[:status] == "5"
- @attachments = get_principal_resources(params[:id], @order, @score)
- else
- # 公共资源库:所有公开资源或者我上传的私有资源
- @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score)
- end
- elsif (params[:type].blank? || params[:type] == "6") # 公共资源
- if params[:status] == "2"
- @attachments = get_course_resources_public( user_course_ids, @order, @score)
- elsif params[:status] == "3"
- @attachments = get_project_resources_public(user_project_ids, @order, @score)
- elsif params[:status] == "4"
- @attachments = get_attch_resources_public(@order, @score)
- elsif params[:status] == "5"
- @attachments = get_principal_resources_public(@order, @score)
- else
- # 公共资源库:所有公开资源或者我上传的私有资源
- @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score)
- end
- # elsif params[:type] == "2" # 私有资源
- # apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id}
- # if params[:status] == "2"
- # resource_type = "'Course'"
- # elsif params[:status] == "3"
- # resource_type = "'Project'"
- # elsif params[:status] == "5"
- # resource_type = "'Principal'"
- # else
- # resource_type = "'Project','OrgSubfield','Principal','Course'"
- # end
- # @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score)
- end
- @status = params[:status]
- @type = params[:type]
- @limit = 25
- @is_remote = true
- @atta_count = @attachments.count
- @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
- @offset ||= @atta_pages.offset
- #@curse_attachments_all = @all_attachments[@offset, @limit]
- @attachments = paginateHelper @attachments,25
- respond_to do |format|
- format.js
- format.html {render :layout => 'new_base'}
- end
- end
-
- # 导入资源
- def import_resources
- # 别人的资源库是没有权限去看的
- if User.current.id != params[:id].to_i
- render_403
- return
- end
- @resource_id = params[:project_id].nil? ? (params[:course_id].nil? ? params[:subfield_file_id] : params[:course_id]) : params[:project_id]
- @resource_type = params[:project_id].nil? ? (params[:course_id].nil? ? "SubfieldFile" : "Course") : "Project"
- @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc"
- @score = @b_sort == "desc" ? "asc" : "desc"
- user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id}
- user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id } # user_org_ids = User.current.organizations.map {|o| o.id}
- if(params[:type].blank? || params[:type] == "1") # 我的资源
- # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
- @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score)
- elsif params[:type] == "6" # 公共资源
- # 公共资源库:所有公开资源或者我上传的私有资源
- @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score)
- end
- @status = params[:status]
- @type = params[:type]
- @limit = 10
- @is_remote = true
- @atta_count = @attachments.count
- @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
- @offset ||= @atta_pages.offset
- #@curse_attachments_all = @all_attachments[@offset, @limit]
- @attachments = paginateHelper @attachments,10
- respond_to do |format|
- format.js
- format.html {render :layout => 'new_base'}
- end
- end
-
- def import_resources_search
- if User.current.id.to_i != params[:id].to_i
- render_403
- return
- end
- @resource_id = params[:mul_id]
- @resource_type = params[:mul_type]
- @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc"
- @score = @b_sort == "desc" ? "asc" : "desc"
- @user = User.current
- @switch_search = params[:name].nil? ? " " : params[:name]
- search = "%#{@switch_search.strip.downcase}%"
- # 别人的资源库是没有权限去看的
- if(params[:type].blank? || params[:type] == "1") # 我的资源
- # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
- user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id}
- user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id }
- # user_org_ids = User.current.organizations.map {|o| o.id}
- @attachments = get_my_resources_search(params[:id], user_course_ids, user_project_ids, @order, @score, search)
- elsif params[:type] == "6" # 公共资源
- # 公共资源库:所有公开资源或者我上传的私有资源
- @attachments = get_public_resources_search(user_course_ids, user_project_ids, @order, @score, search)
- end
- @type = params[:type]
- @limit = 10
- @is_remote = true
- @atta_count = @attachments.count
- @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
- @offset ||= @atta_pages.offset
- #@curse_attachments_all = @all_attachments[@offset, @limit]
- @attachments = paginateHelper @attachments, 10
- respond_to do |format|
- format.js
- # format.html {render :layout => 'new_base'}
- end
- end
-
- # 内容导入到对象中
- def import_into_container
- send_ids = params[:checkbox1]
- # mul_id为当前课程id、项目id、组织id的多种形态
- mul_id = params[:mul_id]
- if params[:mul_type] == "Course"
- mul_container = Course.find(mul_id)
- elsif params[:mul_type] == "Project"
- mul_container = Project.find(mul_id)
- elsif params[:mul_type] == "SubfieldFile"
- mul_container = OrgSubfield.find(mul_id)
- end
- unless params[:checkbox1].blank?
- send_ids.each do |send_id|
- ori = Attachment.find_by_id(send_id)
- # 如果该附件已经存课程中,则只更新附件创建时间
- mul_container.attachments.each do |att|
- 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
- att.created_on = Time.now
- att.save
- @exist = true
- break
- end
- end
- next if @exist
- attach_copied_obj = ori.copy
- attach_copied_obj.tag_list.add(ori.tag_list) # tag关联
- attach_copied_obj.container = mul_container
- attach_copied_obj.created_on = Time.now
- attach_copied_obj.author_id = User.current.id
- attach_copied_obj.is_public = 0
- attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from
- if attach_copied_obj.attachtype == nil
- attach_copied_obj.attachtype = 4
- end
- attach_copied_obj.save
- # 附件保存成功后更新项目和课程的统计数
- if params[:mul_type] == "Project"
- mul_container.project_score.update_attribute(:attach_num, mul_container.project_score.attach_num + 1) unless mul_container.project_score.nil?
- end
- @save_message = attach_copied_obj.errors.full_messages
- end
- end
- respond_to do |format|
- format.html {
- if params[:mul_type] == "Course"
- redirect_to course_files_url(mul_container) unless mul_container.nil?
- elsif params[:mul_type] == "Project"
- redirect_to project_files_url(mul_container) unless mul_container.nil?
- elsif params[:mul_type] == "SubfieldFile"
- redirect_to org_subfield_files_url(mul_container) unless mul_container.nil?
- end
- }
- end
- end
-
- # 根据资源关键字进行搜索
- def resource_search
- @order, @b_sort = params[:order] || "created_on", params[:sort] || "desc"
- @score = @b_sort == "desc" ? "asc" : "desc"
- @user = User.current
- @switch_search = params[:search].nil? ? " " : params[:search]
- search = "%#{@switch_search.strip.downcase}%"
- user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id}
- user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id }
- if(params[:type].nil? || params[:type].blank? || params[:type] == "1" || params[:type] == 'all') # 全部
- if params[:status] == "2"
- @attachments = get_course_resources_search(params[:id], user_course_ids, @order, @score, search)
- elsif params[:status] == "3"
- @attachments = get_project_resources_search(params[:id], user_project_ids, @order, @score, search)
- elsif params[:status] == "4"
- @attachments = get_attch_resources_search(params[:id], @order, @score, search)
- elsif params[:status] == "5"
- @attachments = get_principal_resources_search(params[:id], @order, @score, search)
- else
- # 公共资源库:所有公开资源或者我上传的私有资源
- @attachments = get_my_resources_search(params[:id], user_course_ids, user_project_ids, @order, @score, search)
- end
- elsif params[:type] == "6" # 公共资源
- if params[:status] == "2"
- @attachments = get_course_resources_public_search(user_course_ids, @order, @score, search)
- elsif params[:status] == "3"
- @attachments = get_project_resources_public_search(user_project_ids, @order, @score, search)
- elsif params[:status] == "4"
- @attachments = get_attch_resources_public_search(@order, @score, search)
- elsif params[:status] == "5"
- @attachments = get_principal_resources_public_search(@order, @score, search)
- else
- # 公共资源库:所有公开资源或者我上传的私有资源
- @attachments = get_public_resources_search(user_course_ids, user_project_ids, @order, @score, search)
- end
- # elsif params[:type] == "2" # 私有资源
- # apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id}
- # if params[:status] == "2"
- # resource_type = "'Course'"
- # elsif params[:status] == "3"
- # resource_type = "'Project'"
- # elsif params[:status] == "5"
- # resource_type = "'Principal'"
- # else
- # resource_type = "'Project','OrgSubfield','Principal','Course'"
- # end
- # @attachments = get_my_private_resources_search(apply_ids, resource_type, @order, @score, search)
- # @attachments
- end
- @status = params[:status]
- @type = params[:type]
- @limit = 25
- @is_remote = true
- @atta_count = @attachments.count
- @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
- @offset ||= @atta_pages.offset
- #@curse_attachments_all = @all_attachments[@offset, @limit]
- @attachments = paginateHelper @attachments,25
- respond_to do |format|
- format.js
- end
- end
-
- def user_organizations
- @user = User.current
- @orgs = @user.organizations
- respond_to do |format|
- format.html {render :layout => 'static_base'}
- end
- end
-
- def search_user_orgs
- name=""
- if !params[:search_orgs].nil?
- name = params[:search_orgs].strip
- end
- name = "%"+name+"%"
- @orgs = User.current.organizations.where("name like ?", name)
- @user = User.current
- @type = params[:type]
- respond_to do |format|
- format.html {render :layout => 'static_base'}
- format.js
- end
- end
-
- def search_user_org
- @user = User.current
- if !params[:search].nil? #发送到有栏目类型为资源的组织中
- search = "%#{params[:search].to_s.strip.downcase}%"
- if params[:send_type].present? and (params[:send_type] == 'news' or params[:send_type] == 'message')
- @orgs = @user.organizations.where("name like ?", search).select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Post'").count > 0}
- else
- @orgs = @user.organizations.where("name like ?", search).select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Resource'").count > 0}
- end
- else
- if params[:send_type].present? and (params[:send_type] == 'news' or params[:send_type] == 'message')
- @orgs = @user.organizations.select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Post'").count > 0}
- else
- @orgs = @user.organizations.select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Resource'").count > 0}
- end
- end
- @type = params[:type]
- @search = params[:search]
- #这里仅仅是传递需要发送的资源id
- @send_id = params[:send_id]
- @send_ids = params[:checkbox1] || params[:send_ids]
- respond_to do |format|
- format.js
- end
- end
-
- def user_courselist
- @order, @c_sort, @type, @list_type = 1, 2, 1, 1
-
- @my_syllabuses = @user.syllabuses
-
- sy_courses = @user.courses.visible.where("is_delete =? and tea_id != ?", 0, @user.id)
- syllabus_ids = sy_courses.empty? ? '(-1)' : "(" + sy_courses.map{|course| !course.syllabus_id.nil? && course.syllabus_id}.join(",") + ")"
- @join_syllabuses = Syllabus.where("id in #{syllabus_ids} and user_id != #{@user.id}")
-
- @my_syllabuses = syllabus_course_list_sort @my_syllabuses
- @join_syllabuses = syllabus_course_list_sort @join_syllabuses
- @my_syllabuses = @my_syllabuses.sort{|x,y| y[:last_update] <=> x[:last_update]}
- @join_syllabuses = @join_syllabuses.sort{|x,y| y[:last_update] <=> x[:last_update]}
-
- #分页
- # @limit = 10
- # @is_remote = true
- # @atta_count = @syllabus.count
- # @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
- # @offset ||= @atta_pages.offset
- # @syllabus = paginateHelper @syllabus,@limit
-
- respond_to do |format|
- format.html {render :layout => 'new_base_user'}
- end
- end
-
- #课程列表的排序
- def sort_syllabus_list
- @order, @c_sort, @type, @list_type = params[:order] || 1, params[:sort] || 1, params[:type] || 1, params[:list_type] || 1
-
- #确定 sort_type
- if @order.to_i == @type.to_i
- @c_sort = @c_sort.to_i == 1 ? 2 : 1 #1升序 2降序
- else
- @c_sort = 2
- end
-
- sort_name = "updated_at"
-
- if @list_type.to_i == 1
- @syllabuses = @user.syllabuses.order("updated_at desc")
- else
- sy_courses = @user.courses.visible.where("is_delete =? and tea_id != ?", 0, @user.id)
- syllabus_ids = sy_courses.empty? ? '(-1)' : "(" + sy_courses.map{|course| !course.syllabus_id.nil? && course.syllabus_id}.join(",") + ")"
- @syllabuses = Syllabus.where("id in #{syllabus_ids} and user_id != #{@user.id}").order("updated_at desc")
- end
-
- if @order.to_i == 1 #根据 班级更新时间排序
- @syllabuses = syllabus_course_list_sort @syllabuses
- @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]})
- @type = 1
- elsif @order.to_i == 2 #根据 作业+资源数排序
- @type = 2
- @syllabuses.each do |syllabus|
- count = 0
- courses = syllabus.courses.not_deleted
- courses.each do |c|
- 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)
- end
- syllabus[:infocount] = count
- end
- @c_sort == 1 ? (@syllabuses = @syllabuses.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@syllabuses = @syllabuses.sort{|x,y| y[:infocount] <=> x[:infocount]})
- @syllabuses = sortby_time_countcommon_nosticky @syllabuses,sort_name
- else
- @type = 1
- end
-
- respond_to do |format|
- format.js
- end
- end
-
- #展开课程下的班级
- def expand_courses
- @syllabus = Syllabus.where("id = #{params[:syllabus_id]}").first
- unless @syllabus.nil?
- @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")
- respond_to do |format|
- format.js
- end
- end
- end
-
- def user_projectlist
- @order, @c_sort,@type = params[:order] || 1, params[:sort] || 1, params[:type] || 1
-
- #确定 sort_type
- if @order.to_i == @type.to_i
- @c_sort = @c_sort.to_i == 1 ? 2 : 1 #1升序 2降序
- else
- @c_sort = 2
- end
-
- sort_name = "updated_at"
- sort_type = @c_sort == 1 ? "asc" : "desc"
-
- #@projects = @user.projects.visible.order("#{sort_name} #{sort_type}")
- @projects = @user.projects.visible.select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS #{sort_name} ").order("#{sort_name} #{sort_type}")
-
- #根据 问题+资源数排序 @project.project_score.issue_num @project.project_score.attach_num
- if @order.to_i == 2
- @type = 2
- @projects.each do |project|
- project[:infocount] = project.project_score.issue_num+project.project_score.attach_num
- if project[:infocount] < 0
- project[:infocount] = 0
- end
- end
- @c_sort == 1 ? (@projects = @projects.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@projects = @projects.sort{|x,y| y[:infocount] <=> x[:infocount] })
- @projects = sortby_time_countcommon_nosticky @projects,sort_name
- else
- @type = 1
- end
-
- #分页
- @limit = 10
- @is_remote = true
- @atta_count = @projects.count
- @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
- @offset ||= @atta_pages.offset
- @projects = paginateHelper @projects,@limit
-
- respond_to do |format|
- format.js
- format.html {render :layout => 'new_base_user'}
- end
- end
-
- def all_journals
- if params[:type].present?
- case params[:type]
- when 'OrgDocumentComment'
- obj = OrgDocumentComment.where('id = ?', params[:id].to_i).first
- @user_activity_id = params[:div_id].to_i if params[:div_id]
- @type = 'OrgDocumentComment'
- comments = []
- @journals = get_all_children(comments, obj)
- when 'Message'
- obj = Message.where('id = ?', params[:id].to_i).first
- @type = 'Message'
- @is_course = params[:is_course]
- @is_board = params[:is_board]
- @user_activity_id = params[:div_id].to_i if params[:div_id]
- comments = []
- @journals = get_all_children(comments, obj)
- when 'News'
- obj = News.where('id = ?', params[:id].to_i).first
- @journals = obj.comments.reorder("created_on desc")
- @type = 'News'
- @user_activity_id = params[:div_id].to_i if params[:div_id]
- when 'Syllabus'
- obj = Syllabus.where('id = ?', params[:id].to_i).first
- @journals = obj.journals_for_messages.reorder("created_on desc")
- @type = 'Syllabus'
- @user_activity_id = params[:div_id].to_i if params[:div_id]
- when 'JournalsForMessage'
- obj = JournalsForMessage.where('id = ?', params[:id].to_i).first
- journals = []
- @journals = get_all_children(journals, obj)
- @type = 'JournalsForMessage'
- @user_activity_id = params[:div_id].to_i if params[:div_id]
- when 'Issue'
- obj = Issue.where('id = ?', params[:id].to_i).first
- @journals = obj.journals.reorder("created_on desc")
- @type = 'Issue'
- @user_activity_id = params[:div_id].to_i if params[:div_id]
- when 'BlogComment'
- obj = BlogComment.where('id = ?', params[:id].to_i).first
- @user_activity_id = params[:div_id].to_i if params[:div_id]
- @homepage = params[:homepage].to_i
- @type = 'BlogComment'
- @user_id = obj.author_id
- comments = []
- @journals = get_all_children(comments, obj)
- when 'HomeworkCommon'
- obj = HomeworkCommon.where('id = ?', params[:id].to_i).first
- @type = 'HomeworkCommon'
- @journals = obj.journals_for_messages.reorder("created_on desc")
- @is_in_course = params[:is_in_course].to_i if params[:is_in_course]
- @course_activity = params[:course_activity].to_i if params[:course_activity]
- @is_teacher = User.current.allowed_to?(:as_teacher,obj.course)
- @user_activity_id = params[:user_activity_id].to_i if params[:user_activity_id]
- end
- end
- end
-
- private
-
- def find_user
- if params[:id] == 'current'
- require_login || return
- @user = User.current
- else
- @user = User.find(params[:id])
- end
- rescue ActiveRecord::RecordNotFound
- render_404
- end
-
- def setting_layout(default_base='base_users_new')
- User.current.admin? ? default_base : default_base
- end
-
- # 必填自己的工作单位,其实就是学校
- def auth_user_extension
- if @user == User.current && @user.user_extensions.nil?
- flash[:error] = l(:error_complete_occupation)
- redirect_to my_account_url
- end
- end
-
- #重置用户得分
- def rest_user_score
- memo_num(@user)
- messges_for_issue_num(@user)
- issues_status_num(@user)
- replay_for_memo_num(@user)
- tread_num(@user)
- praise_num(@user)
- changeset_num(@user)
- document_num(@user)
- attachment_num(@user)
- issue_done_ratio_num(@user)
- post_issue_num(@user)
- end
-
- #验证是否显示课程
- def can_show_course
- @first_page = FirstPage.find_by_page_type('project')
- if @first_page.show_course == 2
- render_404
- end
- end
-
- def recorded_visitor
- if(User.current.logged? && User.current != @user)
- #impl = Visitor.where('user_id=? and master_id=?',User.current.id,@user.id).find;
- # impl = Visitor.find_by_sql('user_id=? and master_id=?',[User.current.id,@user.id]);
- impl = Visitor.find_by_user_id_and_master_id(User.current.id,@user.id);
- if(impl.nil?)
- impl = Visitor.new
- impl.user_id = User.current.id
- impl.master_id = @user.id
- else
- impl.updated_on = Time.now
- end
- impl.save
- end
- end
-
-
-
- end
|