列表人气排序修改
This commit is contained in:
parent
f8abd46ae9
commit
b199a6b8b2
|
@ -27,11 +27,15 @@ class BlogsController < ApplicationController
|
||||||
|
|
||||||
@topics.each do |topic|
|
@topics.each do |topic|
|
||||||
topic[:infocount] = get_praise_num(topic) + (topic.parent ? topic.parent.children.count : topic.children.count)
|
topic[:infocount] = get_praise_num(topic) + (topic.parent ? topic.parent.children.count : topic.children.count)
|
||||||
|
if topic[:infocount] < 0
|
||||||
|
topic[:infocount] = 0
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@b_sort == 1 ? @topics = @topics.sort{|x,y| x[:infocount] <=> y[:infocount] } : @topics = @topics.sort{|x,y| y[:infocount] <=> x[:infocount] }
|
@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 = sort_by_sticky @topics
|
||||||
|
@topics = sortby_time_countcommon_hassticky @topics,sort_name
|
||||||
else
|
else
|
||||||
@type = 1
|
@type = 1
|
||||||
end
|
end
|
||||||
|
|
|
@ -77,7 +77,7 @@ class BoardsController < ApplicationController
|
||||||
@b_sort = 2
|
@b_sort = 2
|
||||||
end
|
end
|
||||||
|
|
||||||
sort_name = "updated_at"
|
sort_name = "updated_on"
|
||||||
|
|
||||||
sort_type = @b_sort == 1 ? "asc" : "desc"
|
sort_type = @b_sort == 1 ? "asc" : "desc"
|
||||||
|
|
||||||
|
@ -126,9 +126,13 @@ class BoardsController < ApplicationController
|
||||||
@type = 2
|
@type = 2
|
||||||
@topics.each do |topic|
|
@topics.each do |topic|
|
||||||
topic[:infocount] = get_praise_num(topic) + (topic.parent ? x.parent.children.count : topic.children.count)
|
topic[:infocount] = get_praise_num(topic) + (topic.parent ? x.parent.children.count : topic.children.count)
|
||||||
|
if topic[:infocount] < 0
|
||||||
|
topic[:infocount] = 0
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@b_sort == 1 ? @topics = @topics.sort{|x,y| x[:infocount] <=> y[:infocount] } : @topics = @topics.sort{|x,y| y[:infocount] <=> x[:infocount] }
|
@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 = sort_by_sticky @topics
|
||||||
|
@topics = sortby_time_countcommon_hassticky @topics,sort_name
|
||||||
else
|
else
|
||||||
@type = 1
|
@type = 1
|
||||||
end
|
end
|
||||||
|
|
|
@ -106,9 +106,13 @@ class NewsController < ApplicationController
|
||||||
@type = 2
|
@type = 2
|
||||||
scope_order.each do |topic|
|
scope_order.each do |topic|
|
||||||
topic[:infocount] = get_praise_num(topic) + topic.comments.count
|
topic[:infocount] = get_praise_num(topic) + topic.comments.count
|
||||||
|
if topic[:infocount] < 0
|
||||||
|
topic[:infocount] = 0
|
||||||
|
end
|
||||||
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] }
|
@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 = sort_by_sticky scope_order
|
||||||
|
scope_order = sortby_time_countcommon_hassticky scope_order,sort_name
|
||||||
else
|
else
|
||||||
@type = 1
|
@type = 1
|
||||||
end
|
end
|
||||||
|
|
|
@ -2870,8 +2870,12 @@ class UsersController < ApplicationController
|
||||||
@type = 2
|
@type = 2
|
||||||
@courses.each do |course|
|
@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)
|
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
|
end
|
||||||
@c_sort == 1 ? (@courses = @courses.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@courses = @courses.sort{|x,y| y[:infocount] <=> x[:infocount]})
|
@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
|
else
|
||||||
@type = 1
|
@type = 1
|
||||||
end
|
end
|
||||||
|
@ -2915,9 +2919,12 @@ class UsersController < ApplicationController
|
||||||
@type = 2
|
@type = 2
|
||||||
@projects.each do |project|
|
@projects.each do |project|
|
||||||
project[:infocount] = project.project_score.issue_num+project.project_score.attach_num
|
project[:infocount] = project.project_score.issue_num+project.project_score.attach_num
|
||||||
|
if project[:infocount] < 0
|
||||||
|
project[:infocount] = 0
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@c_sort == 1 ? (@projects = @projects.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@projects = @projects.sort{|x,y| y[:infocount] <=> x[:infocount] })
|
@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
|
else
|
||||||
@type = 1
|
@type = 1
|
||||||
end
|
end
|
||||||
|
|
|
@ -3065,7 +3065,7 @@ def host_with_protocol
|
||||||
return Setting.protocol + "://" + Setting.host_name
|
return Setting.protocol + "://" + Setting.host_name
|
||||||
end
|
end
|
||||||
|
|
||||||
#将有置顶属性的提到数组前面 #infocount 相同的按时间降序排列
|
#将有置顶属性的提到数组前面
|
||||||
def sort_by_sticky topics
|
def sort_by_sticky topics
|
||||||
tmpTopics = []
|
tmpTopics = []
|
||||||
tmpIndex = 0
|
tmpIndex = 0
|
||||||
|
@ -3082,8 +3082,116 @@ def sort_by_sticky topics
|
||||||
tmpIndex = tmpIndex + 1
|
tmpIndex = tmpIndex + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return tmpTopics
|
||||||
topics = tmpTopics
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue