Merge branch 'yuanke' into develop
This commit is contained in:
commit
5e8ff06140
|
@ -27,11 +27,15 @@ class BlogsController < ApplicationController
|
|||
|
||||
@topics.each do |topic|
|
||||
topic[:infocount] = get_praise_num(topic) + (topic.parent ? topic.parent.children.count : topic.children.count)
|
||||
if topic[:infocount] < 0
|
||||
topic[:infocount] = 0
|
||||
end
|
||||
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
|
||||
@topics = sortby_time_countcommon_hassticky @topics,sort_name
|
||||
else
|
||||
@type = 1
|
||||
end
|
||||
|
|
|
@ -77,7 +77,7 @@ class BoardsController < ApplicationController
|
|||
@b_sort = 2
|
||||
end
|
||||
|
||||
sort_name = "updated_at"
|
||||
sort_name = "updated_on"
|
||||
|
||||
sort_type = @b_sort == 1 ? "asc" : "desc"
|
||||
|
||||
|
@ -126,9 +126,13 @@ class BoardsController < ApplicationController
|
|||
@type = 2
|
||||
@topics.each do |topic|
|
||||
topic[:infocount] = get_praise_num(topic) + (topic.parent ? x.parent.children.count : topic.children.count)
|
||||
if topic[:infocount] < 0
|
||||
topic[:infocount] = 0
|
||||
end
|
||||
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
|
||||
@topics = sortby_time_countcommon_hassticky @topics,sort_name
|
||||
else
|
||||
@type = 1
|
||||
end
|
||||
|
|
|
@ -79,21 +79,20 @@ class NewsController < ApplicationController
|
|||
@b_sort = 2
|
||||
end
|
||||
|
||||
sort_name = "created_on"
|
||||
sort_name = "updated_at"
|
||||
|
||||
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 = 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}.#{sort_name} #{sort_type}").offset(news_page).includes(:author,:course).all()
|
||||
scope_order = scope.reorder("#{News.table_name}.sticky DESC, #{News.table_name}.created_on #{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
|
||||
|
@ -101,16 +100,26 @@ class NewsController < ApplicationController
|
|||
#.all(:include => [:author, :course],:order => "#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC")
|
||||
end
|
||||
|
||||
scope_order.each do |topic|
|
||||
topic[:updated_at] = CourseActivity.where("course_act_type='#{topic.class}' and course_act_id =#{topic.id}").first.updated_at
|
||||
end
|
||||
|
||||
#根据 赞+回复数排序
|
||||
if @order.to_i == 2
|
||||
@type = 2
|
||||
scope_order.each do |topic|
|
||||
topic[:infocount] = get_praise_num(topic) + topic.comments.count
|
||||
if topic[:infocount] < 0
|
||||
topic[:infocount] = 0
|
||||
end
|
||||
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
|
||||
scope_order = sortby_time_countcommon_hassticky scope_order,sort_name
|
||||
else
|
||||
@type = 1
|
||||
@b_sort == 1 ? scope_order = scope_order.sort{|x,y| x[:updated_at] <=> y[:updated_at] } : scope_order = scope_order.sort{|x,y| y[:updated_at] <=> x[:updated_at] }
|
||||
scope_order = sort_by_sticky scope_order
|
||||
end
|
||||
|
||||
@newss = scope_order
|
||||
|
|
|
@ -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,: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,:work_canrepeat]
|
||||
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]
|
||||
|
@ -17,40 +17,40 @@ class StudentWorkController < ApplicationController
|
|||
is_test = params[:is_test] == 'true'
|
||||
resultObj = {status: 0, results: [], error_msg: '', time: Time.now.strftime('%Y-%m-%d %T')}
|
||||
|
||||
student_work = find_or_save_student_work(is_test)
|
||||
student_work = find_or_save_student_work(is_test)
|
||||
|
||||
unless student_work
|
||||
resultObj[:status] = 100
|
||||
else
|
||||
if @homework.homework_type == 2 && @homework.homework_detail_programing
|
||||
result = test_realtime(student_work, params[:src])
|
||||
logger.debug result
|
||||
resultObj[:status] = result["status"]
|
||||
resultObj[:results] = result["results"]
|
||||
resultObj[:error_msg] = result["error_msg"]
|
||||
results = result["results"]
|
||||
if result["status"].to_i == -2 #编译错误
|
||||
results = [result["error_msg"]]
|
||||
end
|
||||
student_work_test = student_work.student_work_tests.build(status: result["status"], results: results,
|
||||
src: params[:src])
|
||||
unless student_work.save
|
||||
resultObj[:status] = 200
|
||||
unless student_work
|
||||
resultObj[:status] = 100
|
||||
else
|
||||
if @homework.homework_type == 2 && @homework.homework_detail_programing
|
||||
result = test_realtime(student_work, params[:src])
|
||||
logger.debug result
|
||||
resultObj[:status] = result["status"]
|
||||
resultObj[:results] = result["results"]
|
||||
resultObj[:error_msg] = result["error_msg"]
|
||||
results = result["results"]
|
||||
if result["status"].to_i == -2 #编译错误
|
||||
results = [result["error_msg"]]
|
||||
end
|
||||
student_work_test = student_work.student_work_tests.build(status: result["status"], results: results,
|
||||
src: params[:src])
|
||||
unless student_work.save
|
||||
resultObj[:status] = 200
|
||||
else
|
||||
student_work.name = params[:title]
|
||||
student_work.description = params[:src]
|
||||
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
|
||||
else
|
||||
student_work.name = params[:title]
|
||||
student_work.description = params[:src]
|
||||
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
|
||||
else
|
||||
student_work.late_penalty = 0
|
||||
end
|
||||
student_work.save
|
||||
resultObj[:status] = result["status"].to_i
|
||||
resultObj[:time] = student_work_test.created_at.to_s(:db)
|
||||
resultObj[:index] = student_work.student_work_tests.count
|
||||
student_work.late_penalty = 0
|
||||
end
|
||||
student_work.save
|
||||
resultObj[:status] = result["status"].to_i
|
||||
resultObj[:time] = student_work_test.created_at.to_s(:db)
|
||||
resultObj[:index] = student_work.student_work_tests.count
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
render :json => resultObj
|
||||
end
|
||||
|
@ -81,6 +81,8 @@ 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} #保存每测试一次返回的结果
|
||||
|
||||
|
@ -92,83 +94,229 @@ class StudentWorkController < ApplicationController
|
|||
resultObj[:status] = 100
|
||||
else
|
||||
if @homework.homework_type == 2 && @homework.homework_detail_programing
|
||||
#找到第index个测试的输入输出
|
||||
index = params[:tIndex].to_i
|
||||
resultObj[:tseq] = index
|
||||
test = @homework.homework_tests[index - 1]
|
||||
#找到第index个测试的输入输出
|
||||
index = params[:tIndex].to_i
|
||||
resultObj[:tseq] = index
|
||||
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} 毫秒"
|
||||
|
||||
if result["status"].to_i != -2
|
||||
#result["results"].first['output'] = result["results"].first['output'].gsub(" ","□")
|
||||
#result["results"].first['result'] = result["results"].first['result'].gsub(" ","□")
|
||||
space_replace_1(result["results"].first['output'])
|
||||
space_replace_1(result["results"].first['result'])
|
||||
end
|
||||
#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)
|
||||
|
||||
logger.debug result
|
||||
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(" ","□")
|
||||
space_replace_1(result["results"].first['output'])
|
||||
space_replace_1(result["results"].first['result'])
|
||||
end
|
||||
|
||||
#-1 默认值 0全部正确并结束 2 超时 -2 编译错误
|
||||
resultObj[:status] = -1
|
||||
resultObj[:results] = result["results"].first #本次测试结果
|
||||
resultObj[:error_msg] = result["error_msg"] #编译错误时的信息
|
||||
logger.debug result
|
||||
|
||||
if result["status"].to_i == -2 #编译错误
|
||||
resultObj[:results] = result["error_msg"]
|
||||
resultObj[:status] = -2
|
||||
elsif result["results"][0]["status"].to_i == 2
|
||||
resultObj[:status] = 2
|
||||
end
|
||||
#-1 默认值 0全部正确并结束 2 超时 -2 编译错误
|
||||
resultObj[:status] = -1
|
||||
resultObj[:results] = result["results"].first #本次测试结果
|
||||
resultObj[:error_msg] = result["error_msg"] #编译错误时的信息
|
||||
|
||||
unless student_work.save
|
||||
resultObj[:status] = 200
|
||||
#该状态用于存入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
|
||||
resultObj[:status] = 200
|
||||
else
|
||||
student_work.name = params[:title]
|
||||
student_work.description = params[:src]
|
||||
|
||||
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
|
||||
else
|
||||
student_work.name = params[:title]
|
||||
student_work.description = params[:src]
|
||||
|
||||
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
|
||||
else
|
||||
student_work.late_penalty = 0
|
||||
end
|
||||
|
||||
#每次从数据库取出上次的结果加上本次的结果再存入数据库
|
||||
status = result["status"]
|
||||
if index == 1
|
||||
student_work_test = student_work.student_work_tests.build(status: status,
|
||||
results: [resultObj[:results]],src: params[:src])
|
||||
student_work_test.save!
|
||||
resultObj[:testid] = student_work_test.id
|
||||
else
|
||||
#先从数据库取出result
|
||||
student_work_test = StudentWorkTest.find(params[:testid])
|
||||
results = student_work_test.results
|
||||
results << resultObj[:results]
|
||||
student_work_test.results = results
|
||||
student_work_test.status = (result["status"] != 0 ? result["status"] : student_work_test.status)
|
||||
student_work_test.save!
|
||||
status = student_work_test.status
|
||||
resultObj[:testid] = student_work_test.id
|
||||
end
|
||||
|
||||
#超时或编译错误则直接返回了并存入数据库
|
||||
if resultObj[:status] == 2 || resultObj[:status] == -2 || index == @homework.homework_tests.size
|
||||
if status == 0
|
||||
resultObj[:status] = 0
|
||||
end
|
||||
student_work.save!
|
||||
resultObj[:time] = student_work_test.created_at.to_s(:db)
|
||||
resultObj[:index] = student_work.student_work_tests.count
|
||||
end
|
||||
|
||||
#渲染返回结果
|
||||
render :json => resultObj
|
||||
student_work.late_penalty = 0
|
||||
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,
|
||||
results: [resultObj[:results]],src: params[:src])
|
||||
student_work_test.save!
|
||||
resultObj[:testid] = student_work_test.id
|
||||
else
|
||||
#先从数据库取出result
|
||||
student_work_test = StudentWorkTest.find(params[:testid])
|
||||
results = student_work_test.results
|
||||
results << resultObj[:results]
|
||||
student_work_test.results = results
|
||||
student_work_test.status = (result["status"] != 0 ? result["status"] : student_work_test.status)
|
||||
student_work_test.save!
|
||||
status = student_work_test.status
|
||||
resultObj[:testid] = student_work_test.id
|
||||
end
|
||||
|
||||
#超时或编译错误则直接返回了并存入数据库
|
||||
if resultObj[:status] == 2 || resultObj[:status] == -2 || index == @homework.homework_tests.size
|
||||
if status == 0
|
||||
resultObj[:status] = 0
|
||||
end
|
||||
student_work.save!
|
||||
resultObj[:time] = student_work_test.created_at.to_s(:db)
|
||||
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
|
||||
end
|
||||
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
|
||||
# 作业消息状态更新
|
||||
|
@ -504,7 +652,7 @@ class StudentWorkController < ApplicationController
|
|||
if @homework.homework_detail_group.base_on_project == 1
|
||||
stu_project.project_id = @student_work_project.project_id
|
||||
else @homework.homework_detail_group.base_on_project == 0
|
||||
stu_project.project_id = -1
|
||||
stu_project.project_id = -1
|
||||
end
|
||||
stu_project.user_id = members[i].to_i
|
||||
stu_project.is_leader = 0
|
||||
|
@ -1095,11 +1243,11 @@ class StudentWorkController < ApplicationController
|
|||
student_work = StudentWork.where(homework_common_id: @homework.id, user_id: User.current.id).first
|
||||
if student_work.nil?
|
||||
@homework.student_works.build(
|
||||
name: params[:title],
|
||||
description: params[:src],
|
||||
user_id: User.current.id,
|
||||
is_test: is_test
|
||||
)
|
||||
name: params[:title],
|
||||
description: params[:src],
|
||||
user_id: User.current.id,
|
||||
is_test: is_test
|
||||
)
|
||||
unless @homework.save
|
||||
logger.debug @homework.errors.full_messages
|
||||
else
|
||||
|
@ -1120,7 +1268,7 @@ class StudentWorkController < ApplicationController
|
|||
src:src,
|
||||
language:@homework.homework_detail_programing.language,
|
||||
factor: factor
|
||||
}
|
||||
}
|
||||
uri = URI(url)
|
||||
body = solutions.to_json
|
||||
res = Net::HTTP.new(uri.host, uri.port).start do |client|
|
||||
|
|
|
@ -2948,20 +2948,19 @@ class UsersController < ApplicationController
|
|||
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
|
||||
@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 #{sort_type}")
|
||||
|
||||
#根据 作业+资源数排序
|
||||
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)
|
||||
if course[:infocount] < 0
|
||||
course[:infocount] = 0
|
||||
end
|
||||
end
|
||||
@c_sort == 1 ? (@courses = @courses.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@courses = @courses.sort{|x,y| y[:infocount] <=> x[:infocount]})
|
||||
@courses = sortby_time_countcommon_nosticky @courses,sort_name
|
||||
else
|
||||
@type = 1
|
||||
end
|
||||
|
@ -2993,21 +2992,19 @@ class UsersController < ApplicationController
|
|||
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
|
||||
@projects = @user.projects.visible.select("projects.*, (SELECT MAX(created_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a #{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
|
||||
|
|
|
@ -3065,7 +3065,7 @@ def host_with_protocol
|
|||
return Setting.protocol + "://" + Setting.host_name
|
||||
end
|
||||
|
||||
#将有置顶属性的提到数组前面 #infocount 相同的按时间降序排列
|
||||
#将有置顶属性的提到数组前面
|
||||
def sort_by_sticky topics
|
||||
tmpTopics = []
|
||||
tmpIndex = 0
|
||||
|
@ -3082,9 +3082,117 @@ def sort_by_sticky topics
|
|||
tmpIndex = tmpIndex + 1
|
||||
end
|
||||
end
|
||||
return tmpTopics
|
||||
end
|
||||
|
||||
topics = tmpTopics
|
||||
return topics
|
||||
#按人气排序的时候 相同的人气必须按某种时间顺序排序 有置顶属性
|
||||
def sortby_time_countcommon_hassticky topics,sortstr
|
||||
tmpTopics = []
|
||||
tmpTopics = topics
|
||||
tStart = -1
|
||||
tEnd = -1
|
||||
|
||||
tmpTopics_1 = []
|
||||
tmpIndex = 0
|
||||
|
||||
tmpTopics.each_with_index do |topic,index|
|
||||
if topic.sticky == 0
|
||||
if tStart == -1
|
||||
if (index != tmpTopics.count-1) && (topic[:infocount] == tmpTopics[index+1][:infocount])
|
||||
tStart = index
|
||||
end
|
||||
else
|
||||
if ((topic[:infocount] == tmpTopics[index-1][:infocount]) && ((index != tmpTopics.count-1) && (topic[:infocount] == tmpTopics[index+1][:infocount])))
|
||||
tEnd = index
|
||||
else
|
||||
if (topic[:infocount] == tmpTopics[index-1][:infocount])
|
||||
tEnd = index
|
||||
end
|
||||
if tEnd > tStart
|
||||
for i in tStart..tEnd
|
||||
tmpTopics_1[tmpIndex] = tmpTopics[i]
|
||||
tmpIndex = tmpIndex + 1
|
||||
end
|
||||
|
||||
if sortstr == "created_at"
|
||||
tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:created_at].to_i <=> x[:created_at].to_i }
|
||||
elsif sortstr == "created_on"
|
||||
tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:created_on].to_i <=> x[:created_on].to_i }
|
||||
elsif sortstr == "updated_at"
|
||||
tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:updated_at].to_i <=> x[:updated_at].to_i }
|
||||
elsif sortstr == "updated_on"
|
||||
tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:updated_on].to_i <=> x[:updated_on].to_i }
|
||||
end
|
||||
|
||||
tmpIndex = 0
|
||||
for i in tStart..tEnd
|
||||
tmpTopics[i] = tmpTopics_1[tmpIndex]
|
||||
tmpIndex = tmpIndex + 1
|
||||
end
|
||||
end
|
||||
tStart = -1
|
||||
tEnd = -1
|
||||
tmpTopics_1 = []
|
||||
tmpIndex = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return tmpTopics
|
||||
end
|
||||
|
||||
#按人气排序的时候 相同的人气必须按某种时间顺序排序 无置顶属性
|
||||
def sortby_time_countcommon_nosticky topics,sortstr
|
||||
tmpTopics = []
|
||||
tmpTopics = topics
|
||||
tStart = -1
|
||||
tEnd = -1
|
||||
|
||||
tmpTopics_1 = []
|
||||
tmpIndex = 0
|
||||
|
||||
tmpTopics.each_with_index do |topic,index|
|
||||
if tStart == -1
|
||||
if (index != tmpTopics.count-1) && (topic[:infocount] == tmpTopics[index+1][:infocount])
|
||||
tStart = index
|
||||
end
|
||||
else
|
||||
if ((topic[:infocount] == tmpTopics[index-1][:infocount]) && ((index != tmpTopics.count-1) && (topic[:infocount] == tmpTopics[index+1][:infocount])))
|
||||
tEnd = index
|
||||
else
|
||||
if (topic[:infocount] == tmpTopics[index-1][:infocount])
|
||||
tEnd = index
|
||||
end
|
||||
if tEnd > tStart
|
||||
for i in tStart..tEnd
|
||||
tmpTopics_1[tmpIndex] = tmpTopics[i]
|
||||
tmpIndex = tmpIndex + 1
|
||||
end
|
||||
|
||||
if sortstr == "created_at"
|
||||
tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:created_at].to_i <=> x[:created_at].to_i }
|
||||
elsif sortstr == "created_on"
|
||||
tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:created_on].to_i <=> x[:created_on].to_i }
|
||||
elsif sortstr == "updated_at"
|
||||
tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:updated_at].to_i <=> x[:updated_at].to_i }
|
||||
elsif sortstr == "updated_on"
|
||||
tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:updated_on].to_i <=> x[:updated_on].to_i }
|
||||
end
|
||||
|
||||
tmpIndex = 0
|
||||
for i in tStart..tEnd
|
||||
tmpTopics[i] = tmpTopics_1[tmpIndex]
|
||||
tmpIndex = tmpIndex + 1
|
||||
end
|
||||
end
|
||||
tStart = -1
|
||||
tEnd = -1
|
||||
tmpTopics_1 = []
|
||||
tmpIndex = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
return tmpTopics
|
||||
end
|
||||
|
||||
def strip_html(text,len=0,endss="...")
|
||||
|
|
|
@ -84,7 +84,7 @@
|
|||
<% end%>
|
||||
|
||||
<script type="text/javascript">
|
||||
var coursecount = <%= @user.courses.visible.count%>;
|
||||
var coursecount = <%= @user.courses.visible.where("is_delete =?", 0).select("courses.* FROM `course_activities` WHERE course_activities.course_id = courses.id) ").count %>;
|
||||
var courseshowcount = document.getElementsByClassName("coursesLineGrey").length;
|
||||
|
||||
if((coursecount == courseshowcount)&&(coursecount > 5) ){
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
<% end%>
|
||||
|
||||
<script type="text/javascript">
|
||||
var projectcount = <%= @user.projects.visible.count%>;
|
||||
var projectcount = <%= @user.projects.visible.select("projects.* FROM `forge_activities` WHERE forge_activities.project_id = projects.id) ").count %>;
|
||||
var projectshowcount = document.getElementsByClassName("projectsLineGrey").length;
|
||||
|
||||
if((projectcount == projectshowcount)&&(projectcount > 5)){
|
||||
|
|
|
@ -1231,3 +1231,4 @@ a.pages-big{ width:50px;}
|
|||
.pages{width:330px; margin:20px auto 10px;}
|
||||
|
||||
.red-cir-btn{ background:#e74c3c; padding:1px 5px; -moz-border-radius:2px; -webkit-border-radius:2px; border-radius:2px; color:#fff; font-weight:normal;font-size:12px;}
|
||||
.green-cir-btn{ background:#28be6c; padding:1px 5px; -moz-border-radius:2px; -webkit-border-radius:2px; border-radius:2px; color:#fff; font-weight:normal;font-size:12px;}
|
Loading…
Reference in New Issue