diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb index 7a226f50d..6df683948 100644 --- a/app/controllers/blogs_controller.rb +++ b/app/controllers/blogs_controller.rb @@ -1,9 +1,51 @@ class BlogsController < ApplicationController before_filter :find_blog,:except => [:index,:create,:new,:set_homepage, :cancel_homepage] before_filter :find_user + include PraiseTreadHelper + def index @article = BlogComment.new + + @order, @b_sort,@type = params[:order] || 1, params[:sort] || 1, params[:type] || 1 + + #确定 sort_type 1升序 2 降序 + if @order.to_i == @type.to_i + @b_sort = @b_sort.to_i == 1 ? 2 : 1 + else + @b_sort = 2 + end + + sort_name = "updated_at" + + sort_type = @b_sort == 1 ? "asc" : "desc" + + @topics = @user.blog.articles.reorder("#{BlogComment.table_name}.sticky desc,#{BlogComment.table_name}.#{sort_name} #{sort_type}") + + #根据 赞+回复数排序 + if @order.to_i == 2 + @type = 2 + + @topics.each do |topic| + topic[:infocount] = get_praise_num(topic) + (topic.parent ? topic.parent.children.count : topic.children.count) + end + + @b_sort == 1 ? @topics = @topics.sort{|x,y| x[:infocount] <=> y[:infocount] } : @topics = @topics.sort{|x,y| y[:infocount] <=> x[:infocount] } + + @topics = sort_by_sticky @topics + else + @type = 1 + end + + #分页 + @limit = 10 + @is_remote = true + @atta_count = @topics.count + @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 + @offset ||= @atta_pages.offset + @topics = paginateHelper @topics,@limit + respond_to do |format| + format.js format.html {render :layout=>'new_base_user'} end end diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb index a77346d89..260c28b16 100644 --- a/app/controllers/boards_controller.rb +++ b/app/controllers/boards_controller.rb @@ -28,6 +28,7 @@ class BoardsController < ApplicationController helper :watchers helper :project_score helper :attachments + include PraiseTreadHelper def index #modify by nwb @flag = params[:flag] || false @@ -62,13 +63,24 @@ class BoardsController < ApplicationController else render_403 end - end - end def show # 讨论区消息状态更新(已读和未读) + @order, @b_sort,@type = params[:order] || 1, params[:sort] || 1, params[:type] || 1 + + #确定 sort_type 1升序 2 降序 + if @order.to_i == @type.to_i + @b_sort = @b_sort.to_i == 1 ? 2 : 1 + else + @b_sort = 2 + end + + sort_name = "updated_at" + + sort_type = @b_sort == 1 ? "asc" : "desc" + if @project ForgeMessage.where("user_id =? and project_id =? and viewed =?", User.current.id, @project.id, 0).update_all(:viewed => true) # 更新@消息为已读 @@ -82,63 +94,84 @@ class BoardsController < ApplicationController CourseMessage.where("user_id =? and course_id =? and viewed =?", User.current.id, @course.id, 0).update_all(:viewed => true) end - sort_init 'updated_on', 'desc' - sort_update 'created_on' => "#{Message.table_name}.created_on", - 'replies' => "#{Message.table_name}.replies_count", - 'updated_on' => "COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on)" + # sort_init 'updated_on', 'desc' + # sort_update 'created_on' => "#{Message.table_name}.created_on", + # 'replies' => "#{Message.table_name}.replies_count", + # 'updated_on' => "COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on)" @is_new = params[:is_new] @topic_count = @board ? @board.topics.count : 0 if @project if @board - limit = 10; @topic_count = @board.topics.count(); - @topic_pages = (params[:page] ? params[:page].to_i + 1 : 0) *10 - @topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on) desc"). - limit(limit).offset(@topic_pages).includes(:last_reply). + @topic_pages = 0#(params[:page] ? params[:page].to_i + 1 : 0) *10 + @topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on) #{sort_type}"). + offset(@topic_pages).includes(:last_reply). preload(:author, {:last_reply => :author}).all(); else @topics = []; end elsif @course if (@board) - limit = 10; @topic_count = @board.topics.count(); - @topic_pages = (params[:page] ? params[:page].to_i + 1 : 0) *10 - @topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on) desc"). - limit(limit).offset(@topic_pages).includes(:last_reply). - preload(:author, {:last_reply => :author}).all(); + @topic_pages = 0 #(params[:page] ? params[:page].to_i + 1 : 0) *10 + @topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on) #{sort_type}").offset(@topic_pages).includes(:last_reply).preload(:author, {:last_reply => :author}).all(); else @topics = []; end end + #根据 赞+回复数排序 + if @order.to_i == 2 + @type = 2 + @topics.each do |topic| + topic[:infocount] = get_praise_num(topic) + (topic.parent ? x.parent.children.count : topic.children.count) + end + @b_sort == 1 ? @topics = @topics.sort{|x,y| x[:infocount] <=> y[:infocount] } : @topics = @topics.sort{|x,y| y[:infocount] <=> x[:infocount] } + @topics = sort_by_sticky @topics + else + @type = 1 + end + + #分页 + @limit = 15 + @is_remote = true + @atta_count = @topics.count + @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 + @offset ||= @atta_pages.offset + @topics = paginateHelper @topics,@limit + @page = params[:page] ? params[:page].to_i + 1 : 0 @message = Message.new(:board => @board) #modify by nwb - respond_to do |format| - format.js - format.html { - if @project - render :action => 'show', :layout => 'base_projects' - elsif @course - @params=params - render :action => 'show', :layout => 'base_courses' - end - } - format.atom { - @messages = @board.messages. - reorder('created_on DESC'). - includes(:author, :board). - limit(Setting.feeds_limit.to_i). - all - if @project - render_feed(@messages, :title => "#{@project}: #{@board}") - elsif @course - render_feed(@messages, :title => "#{@course}: #{@board}") - end - - } + if (params[:page] || params[:order]) + respond_to do |format| + format.js{render "show.js.erb"} + end + else + respond_to do |format| + format.js + format.html { + if @project + render :action => 'show', :layout => 'base_projects' + elsif @course + @params=params + render :action => 'show', :layout => 'base_courses' + end + } + format.atom { + @messages = @board.messages. + reorder('created_on DESC'). + includes(:author, :board). + limit(Setting.feeds_limit.to_i). + all + if @project + render_feed(@messages, :title => "#{@project}: #{@board}") + elsif @course + render_feed(@messages, :title => "#{@course}: #{@board}") + end + } + end end end diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index f45e1dbd7..f47471e0f 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -70,25 +70,59 @@ class NewsController < ApplicationController end elsif @course if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course))) + @order, @b_sort,@type = params[:order] || 1, params[:sort] || 1, params[:type] || 1 + + #确定 sort_type 1升序 2 降序 + if @order.to_i == @type.to_i + @b_sort = @b_sort.to_i == 1 ? 2 : 1 + else + @b_sort = 2 + end + + sort_name = "created_on" + + sort_type = @b_sort == 1 ? "asc" : "desc" + scope = @course ? @course.news.course_visible : News.course_visible news_arr = scope.map{|news| news.id} @page = params[:page] ? params[:page].to_i + 1 : 0 - news_page = @page *10 + news_page = 0 #@page *10 @news_count = scope.count @is_new = params[:is_new] @q = params[:subject] if params[:subject].nil? || params[:subject].blank? - scope_order = scope.reorder("#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC").limit(10).offset(news_page).includes(:author,:course).all() + scope_order = scope.reorder("#{News.table_name}.sticky DESC, #{News.table_name}.#{sort_name} #{sort_type}").offset(news_page).includes(:author,:course).all() #all(:include => [:author, :course], #:order => "#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC").limit(10).offset(news_page) else - scope_order = scope.where("#{News.table_name}.title like '#{'%' << params[:subject].to_s << '%'}'").reorder("#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC").limit(10).offset(news_page).includes(:author,:course).all() + scope_order = scope.where("#{News.table_name}.title like '#{'%' << params[:subject].to_s << '%'}'").reorder("#{News.table_name}.sticky DESC, #{News.table_name}.#{sort_name} #{sort_type}").offset(news_page).includes(:author,:course).all() #.all(:include => [:author, :course],:order => "#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC") end + #根据 赞+回复数排序 + if @order.to_i == 2 + @type = 2 + scope_order.each do |topic| + topic[:infocount] = get_praise_num(topic) + topic.comments.count + end + @b_sort == 1 ? scope_order = scope_order.sort{|x,y| x[:infocount] <=> y[:infocount] } : scope_order = scope_order.sort{|x,y| y[:infocount] <=> x[:infocount] } + scope_order = sort_by_sticky scope_order + else + @type = 1 + end + @newss = scope_order + + #分页 + @limit = 15 + @is_remote = true + @atta_count = @newss.count + @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 + @offset ||= @atta_pages.offset + @newss = paginateHelper @newss,@limit + #@newss = paginateHelper scope_order,10 respond_to do |format| format.html { diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index 93e0e9c4b..c22f9e4ab 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -32,6 +32,10 @@ class SettingsController < ApplicationController hidden_non_project = Setting.find_by_name("hidden_non_project") @text = (hidden_non_project && hidden_non_project.value == "0") ? l(:label_show_non_project) : l(:label_hidden_non_project) + #1隐藏了课程信息 0显示了课程信息 + hidden_courses = Setting.find_by_name("hidden_courses") + @text_1 = (hidden_courses && hidden_courses.value == "1") ? l(:label_show_courses) : l(:label_hidden_courses) + @notifiables = Redmine::Notifiable.all if request.post? && params[:settings] && params[:settings].is_a?(Hash) settings = (params[:settings] || {}).dup.symbolize_keys @@ -89,4 +93,22 @@ class SettingsController < ApplicationController redirect_to settings_url end + + #隐藏/显示课程信息 + def hidden_courses + @notifiable = Setting.find_by_name("hidden_courses") + if @notifiable + @notifiable.value == "1" ? @notifiable.value = 0 : @notifiable.value = 1 + @notifiable.save + else + @notifiable = Setting.new() + @notifiable.name = "hidden_courses" + @notifiable.value = 1 + @notifiable.save + end + + redirect_to settings_url + end end + + diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 49658bbd9..e7c10f9eb 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -5,7 +5,7 @@ class StudentWorkController < ApplicationController include ApplicationHelper require 'bigdecimal' require "base64" - before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :program_test,:program_test_ex,:code_repeattest,:work_canrepeat,:set_score_rule,:forbidden_anonymous_comment,:delete_work,:new_student_work_project,:student_work_project,:cancel_relate_project,:search_course_students] + before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :program_test,:program_test_ex,:set_score_rule,:forbidden_anonymous_comment,:delete_work,:new_student_work_project,:student_work_project,:cancel_relate_project,:search_course_students] before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work,:retry_work,:revise_attachment] before_filter :member_of_course, :only => [:new, :create, :show, :add_score, :praise_student_work] before_filter :author_of_work, :only => [:edit, :update, :destroy] @@ -81,8 +81,6 @@ class StudentWorkController < ApplicationController #根据传入的tIndex确定是第几次测试 #之后如果觉得很卡 可以改成将结果传回JS再以参数形式传回来 def program_test_ex - tStarttime = Time.now - is_test = params[:is_test] == 'true' resultObj = {status: 0, results: [], error_msg: '', time: Time.now.strftime('%Y-%m-%d %T'),tseq:1,tcount:1,testid:1} #保存每测试一次返回的结果 @@ -100,17 +98,8 @@ class StudentWorkController < ApplicationController test = @homework.homework_tests[index - 1] #请求测试 - begin - result = test_realtime_ex(test, params[:src]) - rescue Timeout::Error - tEndtime = Time.now - tUsedtime = (tEndtime.to_i-tStarttime.to_i)*1000+(tEndtime.usec - tStarttime.usec)/1000 - logger.debug "program_test_ex user wait time = #{tUsedtime} 毫秒" + result = test_realtime_ex(test, params[:src]) - #status 0:答案正确 -3http超时 -2:编译错误 -1:答案错误 2:程序运行超时 - CodeTests.create(:homework_id=>@homework.id,:language=>@homework.homework_detail_programing.language,:status=>-3,:wait_time=>tUsedtime,:student_work_id=>student_work.id) - - end if result["status"].to_i != -2 #result["results"].first['output'] = result["results"].first['output'].gsub(" ","□") #result["results"].first['result'] = result["results"].first['result'].gsub(" ","□") @@ -125,19 +114,11 @@ class StudentWorkController < ApplicationController resultObj[:results] = result["results"].first #本次测试结果 resultObj[:error_msg] = result["error_msg"] #编译错误时的信息 - #该状态用于存入CodeTests - tmpstatus = -1 if result["status"].to_i == -2 #编译错误 resultObj[:results] = result["error_msg"] resultObj[:status] = -2 - tmpstatus = -2 elsif result["results"][0]["status"].to_i == 2 resultObj[:status] = 2 - tmpstatus = 2 - end - - if result["status"] == 0 - tmpstatus = 0 end unless student_work.save @@ -153,14 +134,6 @@ class StudentWorkController < ApplicationController end #每次从数据库取出上次的结果加上本次的结果再存入数据库 - if result["status"].to_i != -2 - result["results"].first['user_wait'] = tUsedtime - - if result["results"][0]["status"].to_i == 2 - result["status"] = 2 - end - end - status = result["status"] if index == 1 student_work_test = student_work.student_work_tests.build(status: status, @@ -189,19 +162,6 @@ class StudentWorkController < ApplicationController resultObj[:index] = student_work.student_work_tests.count end - #将每次用户等待时间都存起来以便管理界面显示用 - tEndtime = Time.now - tUsedtime = (tEndtime.to_i-tStarttime.to_i)*1000+(tEndtime.usec - tStarttime.usec)/1000 - logger.debug "program_test_ex user wait time = #{tUsedtime} 毫秒" - - time_used = 0 - if result["status"].to_i != -2 - #至少一毫秒 - time_used = result["results"].first['time_used'] == 0 ? 1:result["results"].first['time_used'] - end - #0:答案正确 -3http超时 -2:编译错误 -1:答案错误 2:程序运行超时 - CodeTests.create(:homework_id=>@homework.id,:language=>@homework.homework_detail_programing.language,:status=>tmpstatus,:time_used=>time_used,:wait_time=>tUsedtime,:student_work_id=>student_work.id) - #渲染返回结果 render :json => resultObj end @@ -209,114 +169,6 @@ class StudentWorkController < ApplicationController end end - #找出该作业的所有提交作业 - def find_all_student_work_by_homeid() - all_studentwork = StudentWork.where("homework_common_id =#{@homework.id} and is_test = 0 ") - - all_studentwork - end - - def request_code_repeattest(src) - url = "#{Redmine::Configuration['jplag_server']}api/realtime_test.json" - - factor = [] - src.each do |test| - factor << {work_id: test.id, des: test.description,created_at:test.created_at.to_i} - end - - solutions = { - homeid:@homework.id, - language:@homework.homework_detail_programing.language, - factor: factor - } - uri = URI(url) - body = solutions.to_json - - logger.debug "send body" - logger.debug body - - res = Net::HTTP.new(uri.host, uri.port).start do |client| - request = Net::HTTP::Post.new(uri.path) - request.body = body - request["Content-Type"] = "application/json" - client.request(request) - end - - JSON.parse(res.body) - end - - #点击代码查重按钮 - def work_canrepeat - @homework_id = params[:homework] - @course_id = params[:course_id] - - all_studentwork = find_all_student_work_by_homeid() - - @work_count = all_studentwork.count - end - - #代码查重 status: 0完成 -2不需要查重 -1查重失败不支持该语言 - def code_repeattest - tStarttime = Time.now - logger.debug "code_repeattest start is #{tStarttime}}" - resultObj = {status: -2} - - @homework = HomeworkCommon.find params[:homework] - - all_studentwork = find_all_student_work_by_homeid() - - if all_studentwork == nil - resultObj[:status] = -2 - elsif all_studentwork.count <= 1 - resultObj[:status] = -2 - else - - #@homework.homework_detail_programing.language、id、description - logger.debug "time1 is #{Time.now.usec} " - result = request_code_repeattest(all_studentwork) - logger.debug "time2 is #{Time.now.usec} " - - resultObj[:status] = result['status'].to_i - # resultObj[:results] = result['results'] - - #Time.now, simi_id = simiworkid , simi_value = simivalue - if resultObj[:status] == 0 - @homework.simi_time = Time.now - resultObj[:comparetime] = @homework.simi_time - @homework.update_column('simi_time', @homework.simi_time) - - logger.debug "time3 is #{Time.now.usec} " - result['results'].each do |key,value| - @student_work = StudentWork.where("id =?", key.to_i).first - @student_work.update_column('simi_id', value['simiworkid'].to_i) - @student_work.update_column('simi_value', value['simivalue'].to_i) - # sqlstr = "update student_works set simi_id=#{value['simiworkid']},simi_value=#{value['simivalue']} where id=#{key.to_i} " - # dbh.execute(sqlstr) - end - logger.debug "time4 is #{Time.now.usec} " - end - end - tEndtime = Time.now - logger.debug "code_repeattest end is #{tEndtime}}" - tUsedtime = (tEndtime.to_i-tStarttime.to_i)*1000000+(tEndtime.usec - tStarttime.usec) - logger.debug "code_repeattest userd utime is #{tUsedtime}" - render :json => resultObj - end - - #上次代码查重时间 - def last_codecomparetime - resultObj = {status: 0} - @homework = HomeworkCommon.find params[:homework] - - #转换一下 - if @homework.simi_time != nil - resultObj[:comparetime] = Time.parse(@homework.simi_time.to_s).strftime("%Y-%m-%d %H:%M:%S") - else - resultObj[:comparetime] = 0 - end - - render :json => resultObj - end def index # 作业消息状态更新 @@ -499,8 +351,8 @@ class StudentWorkController < ApplicationController render_403 return end - @student_work_count = (search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").order("#{@order} #{@b_sort}"),@name).count end + end @score = @b_sort == "desc" ? "asc" : "desc" @is_focus = params[:is_focus] ? params[:is_focus].to_i : 0 # 消息传过来的ID diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 7392ed8ff..1744fd9af 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -41,7 +41,7 @@ class UsersController < ApplicationController :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_import_homeworks,:user_search_homeworks,:user_import_resource, :user_system_messages,:choose_user_course,:user_courselist,:user_projectlist] before_filter :auth_user_extension, only: :show #before_filter :rest_user_score, only: :show #before_filter :select_entry, only: :user_projects @@ -288,6 +288,27 @@ class UsersController < ApplicationController end end + #处理引用作业的请求 + #status 1 同意 2 拒绝 + def dealwith_apply_homework + @msg = CourseMessage.find(params[:msg_id]) + case params[:agree] + when 'Y' + ah = ApplyHomework.where("user_id = ? and homework_common_id = ?",@msg.apply_user_id, @msg.course_message_id) + 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=>5,:apply_result=>1) + @msg.update_attributes(:apply_result=>1,:viewed=>1) + end + when 'N' + 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=>5,:apply_result=>2) + @msg.update_attributes(:apply_result=>2,:viewed=>1) + end + respond_to do |format| + format.js + end + end + # added by bai def show_score @@ -372,13 +393,38 @@ class UsersController < ApplicationController 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) + @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") #公共题库 - visible_course = Course.where("is_public = 1 && is_delete = 0") + if(params[:type].blank? || params[:type] == "1") #题库 + 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}") elsif params[:type] == "2" #我的题库 @@ -424,6 +470,14 @@ class UsersController < ApplicationController def choose_user_course homework = HomeworkCommon.find params[:send_id].to_i + if homework.course.is_public == 0 && homework.user_id != User.current.id + 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 == 1 + @status = 1 + 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)} @@ -528,12 +582,18 @@ class UsersController < ApplicationController @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") #公共题库 - visible_course = Course.where("is_public = 1 && is_delete = 0") + if(params[:type].blank? || params[:type] == "1") #题库 + 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}") elsif params[:type] == "2" #我的题库 @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}'").order("#{@order} #{@b_sort}") + 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(",") + ")" + #@homeworks = HomeworkCommon.where("id in #{homework_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} order by ah.created_at desc" + @homeworks = HomeworkCommon.find_by_sql(sql) end if params[:property] && params[:property] == "1" @homeworks = @homeworks.where("homework_type = 1").reorder("#{@order} #{@b_sort}") @@ -571,8 +631,8 @@ class UsersController < ApplicationController @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") #全部 - visible_course = Course.where("is_public = 1 && is_delete = 0") + if(params[:type].blank? || params[:type] == "1") #全部 + visible_course = Course.where("is_delete = 0") 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} @@ -586,7 +646,7 @@ class UsersController < ApplicationController 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] == "2" #课程资源 + elsif params[:type] == "2" #我的题库 if @order == "course_name" sql = "SELECT homework_commons.* FROM homework_commons INNER JOIN courses ON homework_commons.course_id = courses.id where 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) @@ -595,6 +655,17 @@ class UsersController < ApplicationController else @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and (name like '%#{search}%') and homework_type in #{type_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(",") + ")" + if @order == "course_name" + sql = "SELECT homework_commons.* FROM homework_commons INNER JOIN courses ON homework_commons.course_id = courses.id where 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 (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 homework_type in #{type_ids}").order("#{@order} #{@b_sort}") + end end =begin if params[:property] && params[:property] == "1" @@ -2857,6 +2928,97 @@ class UsersController < ApplicationController end end + def user_courselist + @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 = "created_at" + sort_type = @c_sort == 1 ? "asc" : "desc" + + if @user.courses.visible.count > 0 + course_order_ids = "(" + CourseActivity.find_by_sql("SELECT c.course_id, updated_at FROM(SELECT ca.course_id, MAX(ca.updated_at) AS updated_at FROM course_activities ca WHERE ca.course_id IN (" + @user.courses.visible.select('courses.id').map{|c| c.id}.join(',') + ") GROUP BY ca.course_id) AS c ").map {|c| c.course_id}.join(",") + ")" + @courses = Course.where("id in #{course_order_ids}").order("#{sort_name} #{sort_type}") + else + @courses = [] + end + + #根据 作业+资源数排序 + if @order.to_i == 2 + @type = 2 + @courses.each do |course| + course[:infocount] = (User.current.admin? || User.current.allowed_to?(:as_teacher,course)) ? (course.homework_commons.count + visable_attachemnts_incourse(course).count) : (course.homework_commons.where("publish_time <= '#{Date.today}'").count + visable_attachemnts_incourse(course).count) + end + @c_sort == 1 ? (@courses = @courses.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@courses = @courses.sort{|x,y| y[:infocount] <=> x[:infocount]}) + else + @type = 1 + end + + #分页 + @limit = 10 + @is_remote = true + @atta_count = @courses.count + @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 + @offset ||= @atta_pages.offset + @courses = paginateHelper @courses,@limit + + respond_to do |format| + format.js + format.html {render :layout => 'new_base_user'} + 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 = "created_on" + sort_type = @c_sort == 1 ? "asc" : "desc" + + if @user.projects.visible.count > 0 + project_order_ids = "(" +ForgeActivity.find_by_sql("SELECT p.project_id, p.created_at FROM (SELECT fa.project_id, MAX(fa.created_at) AS created_at FROM forge_activities fa WHERE fa.project_id IN (" + @user.projects.visible.select('projects.id').map{|p| p.id}.join(',') + ") GROUP BY fa.project_id) AS p ").map {|p| p.project_id}.join(",") + ")" + @projects = Project.where("projects.id in #{project_order_ids}").order("#{sort_name} #{sort_type}") + else + @projects = [] + end + + #根据 问题+资源数排序 @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 + end + + @c_sort == 1 ? (@projects = @projects.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@projects = @projects.sort{|x,y| y[:infocount] <=> x[:infocount] }) + 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 + private def find_user diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 163e76999..464b4fcc6 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -3065,7 +3065,27 @@ def host_with_protocol return Setting.protocol + "://" + Setting.host_name end -def strip_html(text,len=0,endss="...") +#将有置顶属性的提到数组前面 #infocount 相同的按时间降序排列 +def sort_by_sticky topics + tmpTopics = [] + tmpIndex = 0 + topics.each do |topic| + if topic.sticky == 1 + tmpTopics[tmpIndex] = topic + tmpIndex = tmpIndex + 1 + end + end + + topics.each do |topic| + if topic.sticky == 0 + tmpTopics[tmpIndex] = topic + tmpIndex = tmpIndex + 1 + end + end + + topics = tmpTopics + return topics +enddef strip_html(text,len=0,endss="...") ss = "" if text.length>0 ss=text.gsub(/<\/?.*?>/, '').strip @@ -3078,5 +3098,4 @@ def strip_html(text,len=0,endss="...") end end return ss -end - +end \ No newline at end of file diff --git a/app/helpers/organizations_helper.rb b/app/helpers/organizations_helper.rb index 4faa802a5..b3b014de1 100644 --- a/app/helpers/organizations_helper.rb +++ b/app/helpers/organizations_helper.rb @@ -5,17 +5,17 @@ module OrganizationsHelper def find_user_not_in_current_org_by_name org - if params[:q] && params[:q].lstrip.rstrip != "" - scope = Principal.active.sorted.not_member_of_org(org).like(params[:q]) - else - scope = [] - end - principals = paginateHelper scope,10 - s = content_tag('ul', project_member_check_box_tags_ex('membership[user_ids][]', principals), :class => 'mb5', :id => 'principals') - links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true){|text, parameters, options| - link_to text, org_member_autocomplete_org_member_index_path( parameters.merge(:q => params[:q],:flag => true,:org=>org, :format => 'js')), :remote => true - } - s + content_tag('ul', links,:class => 'wlist',:style=>'float:left !important', :id => "org_member_pagination_links" ) + if params[:q] && params[:q].lstrip.rstrip != "" + scope = Principal.active.sorted.not_member_of_org(org).like(params[:q]) + else + scope = [] + end + principals = paginateHelper scope,10 + s = content_tag('ul', project_member_check_box_tags_ex('membership[user_ids][]', principals), :class => 'mb5', :id => 'principals') + links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true){|text, parameters, options| + link_to text, org_member_autocomplete_org_member_index_path( parameters.merge(:q => params[:q],:flag => true,:org=>org, :format => 'js')), :remote => true + } + s + content_tag('ul', links,:class => 'wlist',:style=>'float:left !important', :id => "org_member_pagination_links" ) end def get_default_name field diff --git a/app/models/apply_homework.rb b/app/models/apply_homework.rb new file mode 100644 index 000000000..c92eccca6 --- /dev/null +++ b/app/models/apply_homework.rb @@ -0,0 +1,6 @@ +class ApplyHomework < ActiveRecord::Base + #status:1. 待审核 2.审核通过 + belongs_to :user + belongs_to :homework_common + attr_accessible :status, :user_id, :homework_common_id +end diff --git a/app/models/course_message.rb b/app/models/course_message.rb index 79d27f3c5..3375aa5ab 100644 --- a/app/models/course_message.rb +++ b/app/models/course_message.rb @@ -1,8 +1,9 @@ class CourseMessage < ActiveRecord::Base # status说明: status在课程不同的类型,区分不同的功能 status = 9 作品的提交记录 # HomeworkCommon:status: - # nil:发布了作业; 1:作业截止时间到了提醒!;2:开启匿评; 3:关闭匿评; 4:匿评开始失败 - attr_accessible :course_id, :course_message_id, :course_message_type, :user_id, :viewed, :content, :status + # nil:发布了作业; 1:作业截止时间到了提醒!;2:开启匿评; 3:关闭匿评; 4:匿评开始失败; 5:申请引用作业 + # apply_user_id: 申请者的用户id + attr_accessible :course_id, :course_message_id, :course_message_type, :user_id, :viewed, :content, :status, :apply_user_id, :apply_result # 多态 虚拟关联 belongs_to :course_message ,:polymorphic => true diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 664e5cfac..8d8fa7085 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -1041,7 +1041,13 @@ class Mailer < ActionMailer::Base :subject => @subject end - + def apply_for_homework_request(homework, user) + @receive = User.find(homework.user_id) + @user = user + @subject = "#{@user.show_name} #{l(:label_apply_for_homework)} #{homework.name} " + mail :to => @receive.mail, + :subject => @subject + end private diff --git a/app/views/blogs/_article.html.erb b/app/views/blogs/_article.html.erb index edbce26d3..ea494d0f9 100644 --- a/app/views/blogs/_article.html.erb +++ b/app/views/blogs/_article.html.erb @@ -1,226 +1,78 @@ -